1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/events/CompositionEvent.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,90 @@ 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 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "mozilla/dom/CompositionEvent.h" 1.11 +#include "mozilla/TextEvents.h" 1.12 +#include "prtime.h" 1.13 + 1.14 +namespace mozilla { 1.15 +namespace dom { 1.16 + 1.17 +CompositionEvent::CompositionEvent(EventTarget* aOwner, 1.18 + nsPresContext* aPresContext, 1.19 + WidgetCompositionEvent* aEvent) 1.20 + : UIEvent(aOwner, aPresContext, 1.21 + aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr)) 1.22 +{ 1.23 + NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_EVENT, 1.24 + "event type mismatch"); 1.25 + 1.26 + if (aEvent) { 1.27 + mEventIsInternal = false; 1.28 + } else { 1.29 + mEventIsInternal = true; 1.30 + mEvent->time = PR_Now(); 1.31 + 1.32 + // XXX compositionstart is cancelable in draft of DOM3 Events. 1.33 + // However, it doesn't make sence for us, we cannot cancel composition 1.34 + // when we sends compositionstart event. 1.35 + mEvent->mFlags.mCancelable = false; 1.36 + } 1.37 + 1.38 + mData = mEvent->AsCompositionEvent()->data; 1.39 + // TODO: Native event should have locale information. 1.40 +} 1.41 + 1.42 +NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent) 1.43 +NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent) 1.44 + 1.45 +NS_INTERFACE_MAP_BEGIN(CompositionEvent) 1.46 + NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent) 1.47 +NS_INTERFACE_MAP_END_INHERITING(UIEvent) 1.48 + 1.49 +NS_IMETHODIMP 1.50 +CompositionEvent::GetData(nsAString& aData) 1.51 +{ 1.52 + aData = mData; 1.53 + return NS_OK; 1.54 +} 1.55 + 1.56 +NS_IMETHODIMP 1.57 +CompositionEvent::GetLocale(nsAString& aLocale) 1.58 +{ 1.59 + aLocale = mLocale; 1.60 + return NS_OK; 1.61 +} 1.62 + 1.63 +NS_IMETHODIMP 1.64 +CompositionEvent::InitCompositionEvent(const nsAString& aType, 1.65 + bool aCanBubble, 1.66 + bool aCancelable, 1.67 + nsIDOMWindow* aView, 1.68 + const nsAString& aData, 1.69 + const nsAString& aLocale) 1.70 +{ 1.71 + nsresult rv = UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0); 1.72 + NS_ENSURE_SUCCESS(rv, rv); 1.73 + 1.74 + mData = aData; 1.75 + mLocale = aLocale; 1.76 + return NS_OK; 1.77 +} 1.78 + 1.79 +} // namespace dom 1.80 +} // namespace mozilla 1.81 + 1.82 +using namespace mozilla; 1.83 +using namespace mozilla::dom; 1.84 + 1.85 +nsresult 1.86 +NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult, 1.87 + EventTarget* aOwner, 1.88 + nsPresContext* aPresContext, 1.89 + WidgetCompositionEvent* aEvent) 1.90 +{ 1.91 + CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent); 1.92 + return CallQueryInterface(event, aInstancePtrResult); 1.93 +}