|
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
|
2 /* vim: set ts=2 et sw=2 tw=80: */ |
|
3 /* This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
|
5 * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 #include "DOMCursor.h" |
|
8 #include "mozilla/dom/DOMCursorBinding.h" |
|
9 |
|
10 namespace mozilla { |
|
11 namespace dom { |
|
12 |
|
13 NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMCursor, DOMRequest, |
|
14 mCallback) |
|
15 |
|
16 NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMCursor) |
|
17 NS_INTERFACE_MAP_ENTRY(nsIDOMDOMCursor) |
|
18 NS_INTERFACE_MAP_END_INHERITING(DOMRequest) |
|
19 |
|
20 NS_IMPL_ADDREF_INHERITED(DOMCursor, DOMRequest) |
|
21 NS_IMPL_RELEASE_INHERITED(DOMCursor, DOMRequest) |
|
22 |
|
23 DOMCursor::DOMCursor(nsPIDOMWindow* aWindow, nsICursorContinueCallback* aCallback) |
|
24 : DOMRequest(aWindow) |
|
25 , mCallback(aCallback) |
|
26 , mFinished(false) |
|
27 { |
|
28 } |
|
29 |
|
30 void |
|
31 DOMCursor::Reset() |
|
32 { |
|
33 MOZ_ASSERT(!mFinished); |
|
34 |
|
35 // Reset the request state so we can FireSuccess() again. |
|
36 mResult = JSVAL_VOID; |
|
37 mDone = false; |
|
38 } |
|
39 |
|
40 void |
|
41 DOMCursor::FireDone() |
|
42 { |
|
43 Reset(); |
|
44 mFinished = true; |
|
45 FireSuccess(JS::UndefinedHandleValue); |
|
46 } |
|
47 |
|
48 NS_IMETHODIMP |
|
49 DOMCursor::GetDone(bool *aDone) |
|
50 { |
|
51 *aDone = Done(); |
|
52 return NS_OK; |
|
53 } |
|
54 |
|
55 NS_IMETHODIMP |
|
56 DOMCursor::Continue() |
|
57 { |
|
58 ErrorResult rv; |
|
59 Continue(rv); |
|
60 return rv.ErrorCode(); |
|
61 } |
|
62 |
|
63 void |
|
64 DOMCursor::Continue(ErrorResult& aRv) |
|
65 { |
|
66 MOZ_ASSERT(mCallback, "If you're creating your own cursor class with no callback, you should override Continue()"); |
|
67 |
|
68 // We need to have a result here because we must be in a 'success' state. |
|
69 if (mResult == JSVAL_VOID) { |
|
70 aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); |
|
71 return; |
|
72 } |
|
73 |
|
74 Reset(); |
|
75 mCallback->HandleContinue(); |
|
76 } |
|
77 |
|
78 /* virtual */ JSObject* |
|
79 DOMCursor::WrapObject(JSContext* aCx) |
|
80 { |
|
81 return DOMCursorBinding::Wrap(aCx, this); |
|
82 } |
|
83 |
|
84 } // namespace dom |
|
85 } // namespace mozilla |