1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/InputEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,75 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +#include "mozilla/dom/InputEvent.h" 1.10 +#include "mozilla/TextEvents.h" 1.11 +#include "prtime.h" 1.12 + 1.13 +namespace mozilla { 1.14 +namespace dom { 1.15 + 1.16 +InputEvent::InputEvent(EventTarget* aOwner, 1.17 + nsPresContext* aPresContext, 1.18 + InternalEditorInputEvent* aEvent) 1.19 + : UIEvent(aOwner, aPresContext, 1.20 + aEvent ? aEvent : new InternalEditorInputEvent(false, 0, nullptr)) 1.21 +{ 1.22 + NS_ASSERTION(mEvent->eventStructType == NS_EDITOR_INPUT_EVENT, 1.23 + "event type mismatch"); 1.24 + 1.25 + if (aEvent) { 1.26 + mEventIsInternal = false; 1.27 + } else { 1.28 + mEventIsInternal = true; 1.29 + mEvent->time = PR_Now(); 1.30 + } 1.31 +} 1.32 + 1.33 +NS_IMPL_ADDREF_INHERITED(InputEvent, UIEvent) 1.34 +NS_IMPL_RELEASE_INHERITED(InputEvent, UIEvent) 1.35 + 1.36 +NS_INTERFACE_MAP_BEGIN(InputEvent) 1.37 +NS_INTERFACE_MAP_END_INHERITING(UIEvent) 1.38 + 1.39 +bool 1.40 +InputEvent::IsComposing() 1.41 +{ 1.42 + return mEvent->AsEditorInputEvent()->mIsComposing; 1.43 +} 1.44 + 1.45 +already_AddRefed<InputEvent> 1.46 +InputEvent::Constructor(const GlobalObject& aGlobal, 1.47 + const nsAString& aType, 1.48 + const InputEventInit& aParam, 1.49 + ErrorResult& aRv) 1.50 +{ 1.51 + nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports()); 1.52 + nsRefPtr<InputEvent> e = new InputEvent(t, nullptr, nullptr); 1.53 + bool trusted = e->Init(t); 1.54 + aRv = e->InitUIEvent(aType, aParam.mBubbles, aParam.mCancelable, 1.55 + aParam.mView, aParam.mDetail); 1.56 + InternalEditorInputEvent* internalEvent = e->mEvent->AsEditorInputEvent(); 1.57 + internalEvent->mIsComposing = aParam.mIsComposing; 1.58 + e->SetTrusted(trusted); 1.59 + return e.forget(); 1.60 +} 1.61 + 1.62 +} // namespace dom 1.63 +} // namespace mozilla 1.64 + 1.65 +using namespace mozilla; 1.66 +using namespace mozilla::dom; 1.67 + 1.68 +nsresult 1.69 +NS_NewDOMInputEvent(nsIDOMEvent** aInstancePtrResult, 1.70 + EventTarget* aOwner, 1.71 + nsPresContext* aPresContext, 1.72 + InternalEditorInputEvent* aEvent) 1.73 +{ 1.74 + InputEvent* it = new InputEvent(aOwner, aPresContext, aEvent); 1.75 + NS_ADDREF(it); 1.76 + *aInstancePtrResult = static_cast<Event*>(it); 1.77 + return NS_OK; 1.78 +}