1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/base/DOMCursor.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,85 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "DOMCursor.h" 1.11 +#include "mozilla/dom/DOMCursorBinding.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +NS_IMPL_CYCLE_COLLECTION_INHERITED(DOMCursor, DOMRequest, 1.17 + mCallback) 1.18 + 1.19 +NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(DOMCursor) 1.20 + NS_INTERFACE_MAP_ENTRY(nsIDOMDOMCursor) 1.21 +NS_INTERFACE_MAP_END_INHERITING(DOMRequest) 1.22 + 1.23 +NS_IMPL_ADDREF_INHERITED(DOMCursor, DOMRequest) 1.24 +NS_IMPL_RELEASE_INHERITED(DOMCursor, DOMRequest) 1.25 + 1.26 +DOMCursor::DOMCursor(nsPIDOMWindow* aWindow, nsICursorContinueCallback* aCallback) 1.27 + : DOMRequest(aWindow) 1.28 + , mCallback(aCallback) 1.29 + , mFinished(false) 1.30 +{ 1.31 +} 1.32 + 1.33 +void 1.34 +DOMCursor::Reset() 1.35 +{ 1.36 + MOZ_ASSERT(!mFinished); 1.37 + 1.38 + // Reset the request state so we can FireSuccess() again. 1.39 + mResult = JSVAL_VOID; 1.40 + mDone = false; 1.41 +} 1.42 + 1.43 +void 1.44 +DOMCursor::FireDone() 1.45 +{ 1.46 + Reset(); 1.47 + mFinished = true; 1.48 + FireSuccess(JS::UndefinedHandleValue); 1.49 +} 1.50 + 1.51 +NS_IMETHODIMP 1.52 +DOMCursor::GetDone(bool *aDone) 1.53 +{ 1.54 + *aDone = Done(); 1.55 + return NS_OK; 1.56 +} 1.57 + 1.58 +NS_IMETHODIMP 1.59 +DOMCursor::Continue() 1.60 +{ 1.61 + ErrorResult rv; 1.62 + Continue(rv); 1.63 + return rv.ErrorCode(); 1.64 +} 1.65 + 1.66 +void 1.67 +DOMCursor::Continue(ErrorResult& aRv) 1.68 +{ 1.69 + MOZ_ASSERT(mCallback, "If you're creating your own cursor class with no callback, you should override Continue()"); 1.70 + 1.71 + // We need to have a result here because we must be in a 'success' state. 1.72 + if (mResult == JSVAL_VOID) { 1.73 + aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR); 1.74 + return; 1.75 + } 1.76 + 1.77 + Reset(); 1.78 + mCallback->HandleContinue(); 1.79 +} 1.80 + 1.81 +/* virtual */ JSObject* 1.82 +DOMCursor::WrapObject(JSContext* aCx) 1.83 +{ 1.84 + return DOMCursorBinding::Wrap(aCx, this); 1.85 +} 1.86 + 1.87 +} // namespace dom 1.88 +} // namespace mozilla