michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "DOMCursor.h" michael@0: #include "mozilla/dom/DOMCursorBinding.h" michael@0: michael@0: namespace mozilla { michael@0: namespace dom { michael@0: michael@0: NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMCursor, DOMRequest, michael@0: mCallback) michael@0: michael@0: NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMCursor) michael@0: NS_INTERFACE_MAP_ENTRY(nsIDOMDOMCursor) michael@0: NS_INTERFACE_MAP_END_INHERITING(DOMRequest) michael@0: michael@0: NS_IMPL_ADDREF_INHERITED(DOMCursor, DOMRequest) michael@0: NS_IMPL_RELEASE_INHERITED(DOMCursor, DOMRequest) michael@0: michael@0: DOMCursor::DOMCursor(nsPIDOMWindow* aWindow, nsICursorContinueCallback* aCallback) michael@0: : DOMRequest(aWindow) michael@0: , mCallback(aCallback) michael@0: , mFinished(false) michael@0: { michael@0: } michael@0: michael@0: void michael@0: DOMCursor::Reset() michael@0: { michael@0: MOZ_ASSERT(!mFinished); michael@0: michael@0: // Reset the request state so we can FireSuccess() again. michael@0: mResult = JSVAL_VOID; michael@0: mDone = false; michael@0: } michael@0: michael@0: void michael@0: DOMCursor::FireDone() michael@0: { michael@0: Reset(); michael@0: mFinished = true; michael@0: FireSuccess(JS::UndefinedHandleValue); michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DOMCursor::GetDone(bool *aDone) michael@0: { michael@0: *aDone = Done(); michael@0: return NS_OK; michael@0: } michael@0: michael@0: NS_IMETHODIMP michael@0: DOMCursor::Continue() michael@0: { michael@0: ErrorResult rv; michael@0: Continue(rv); michael@0: return rv.ErrorCode(); michael@0: } michael@0: michael@0: void michael@0: DOMCursor::Continue(ErrorResult& aRv) michael@0: { michael@0: MOZ_ASSERT(mCallback, "If you're creating your own cursor class with no callback, you should override Continue()"); michael@0: michael@0: // We need to have a result here because we must be in a 'success' state. michael@0: if (mResult == JSVAL_VOID) { michael@0: aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); michael@0: return; michael@0: } michael@0: michael@0: Reset(); michael@0: mCallback->HandleContinue(); michael@0: } michael@0: michael@0: /* virtual */ JSObject* michael@0: DOMCursor::WrapObject(JSContext* aCx) michael@0: { michael@0: return DOMCursorBinding::Wrap(aCx, this); michael@0: } michael@0: michael@0: } // namespace dom michael@0: } // namespace mozilla