dom/events/CompositionEvent.cpp

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     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
     5  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     7 #include "mozilla/dom/CompositionEvent.h"
     8 #include "mozilla/TextEvents.h"
     9 #include "prtime.h"
    11 namespace mozilla {
    12 namespace dom {
    14 CompositionEvent::CompositionEvent(EventTarget* aOwner,
    15                                    nsPresContext* aPresContext,
    16                                    WidgetCompositionEvent* aEvent)
    17   : UIEvent(aOwner, aPresContext,
    18             aEvent ? aEvent : new WidgetCompositionEvent(false, 0, nullptr))
    19 {
    20   NS_ASSERTION(mEvent->eventStructType == NS_COMPOSITION_EVENT,
    21                "event type mismatch");
    23   if (aEvent) {
    24     mEventIsInternal = false;
    25   } else {
    26     mEventIsInternal = true;
    27     mEvent->time = PR_Now();
    29     // XXX compositionstart is cancelable in draft of DOM3 Events.
    30     //     However, it doesn't make sence for us, we cannot cancel composition
    31     //     when we sends compositionstart event.
    32     mEvent->mFlags.mCancelable = false;
    33   }
    35   mData = mEvent->AsCompositionEvent()->data;
    36   // TODO: Native event should have locale information.
    37 }
    39 NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent)
    40 NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent)
    42 NS_INTERFACE_MAP_BEGIN(CompositionEvent)
    43   NS_INTERFACE_MAP_ENTRY(nsIDOMCompositionEvent)
    44 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
    46 NS_IMETHODIMP
    47 CompositionEvent::GetData(nsAString& aData)
    48 {
    49   aData = mData;
    50   return NS_OK;
    51 }
    53 NS_IMETHODIMP
    54 CompositionEvent::GetLocale(nsAString& aLocale)
    55 {
    56   aLocale = mLocale;
    57   return NS_OK;
    58 }
    60 NS_IMETHODIMP
    61 CompositionEvent::InitCompositionEvent(const nsAString& aType,
    62                                        bool aCanBubble,
    63                                        bool aCancelable,
    64                                        nsIDOMWindow* aView,
    65                                        const nsAString& aData,
    66                                        const nsAString& aLocale)
    67 {
    68   nsresult rv = UIEvent::InitUIEvent(aType, aCanBubble, aCancelable, aView, 0);
    69   NS_ENSURE_SUCCESS(rv, rv);
    71   mData = aData;
    72   mLocale = aLocale;
    73   return NS_OK;
    74 }
    76 } // namespace dom
    77 } // namespace mozilla
    79 using namespace mozilla;
    80 using namespace mozilla::dom;
    82 nsresult
    83 NS_NewDOMCompositionEvent(nsIDOMEvent** aInstancePtrResult,
    84                           EventTarget* aOwner,
    85                           nsPresContext* aPresContext,
    86                           WidgetCompositionEvent* aEvent)
    87 {
    88   CompositionEvent* event = new CompositionEvent(aOwner, aPresContext, aEvent);
    89   return CallQueryInterface(event, aInstancePtrResult);
    90 }

mercurial