Bug 1002256 - Support CompositionEvent constructor; r?bkelly draft
authorAryeh Gregor <ayg@aryeh.name>
Tue, 01 Nov 2016 17:15:16 +0200
changeset 432296 7d0311691c2ba7963d28a063249d6c89eec15fb7
parent 431499 950739a54a07f38d8659da430429892a65967983
child 535584 e92c294b112c69427f60219332794ba90258e0ce
push id34242
push userayg@aryeh.name
push dateTue, 01 Nov 2016 15:18:05 +0000
reviewersbkelly
bugs1002256
milestone52.0a1
Bug 1002256 - Support CompositionEvent constructor; r?bkelly All other browsers support a constructor here. Per current spec, the constructor does not support .locale, although initCompositionEvent does. If we ever decide to standardize .locale, the constructor can be updated at that point. (Edge also supports .locale in initCompositionEvent but not the constructor. Chrome doesn't support .locale at all.) MozReview-Commit-ID: 59a0fOcIQCA
dom/events/CompositionEvent.cpp
dom/events/CompositionEvent.h
dom/webidl/CompositionEvent.webidl
testing/web-platform/meta/dom/events/Event-subclasses-constructors.html.ini
--- a/dom/events/CompositionEvent.cpp
+++ b/dom/events/CompositionEvent.cpp
@@ -33,16 +33,34 @@ CompositionEvent::CompositionEvent(Event
     mEvent->mFlags.mCancelable = false;
   }
 
   // XXX Do we really need to duplicate the data value?
   mData = mEvent->AsCompositionEvent()->mData;
   // TODO: Native event should have locale information.
 }
 
+// static
+already_AddRefed<CompositionEvent>
+CompositionEvent::Constructor(const GlobalObject& aGlobal,
+                     const nsAString& aType,
+                     const CompositionEventInit& aParam,
+                     ErrorResult& aRv)
+{
+  nsCOMPtr<EventTarget> t = do_QueryInterface(aGlobal.GetAsSupports());
+  RefPtr<CompositionEvent> e = new CompositionEvent(t, nullptr, nullptr);
+  bool trusted = e->Init(t);
+  e->InitCompositionEvent(aType, aParam.mBubbles, aParam.mCancelable,
+                          aParam.mView, aParam.mData, EmptyString());
+  e->mDetail = aParam.mDetail;
+  e->SetTrusted(trusted);
+  e->SetComposed(aParam.mComposed);
+  return e.forget();
+}
+
 NS_IMPL_ADDREF_INHERITED(CompositionEvent, UIEvent)
 NS_IMPL_RELEASE_INHERITED(CompositionEvent, UIEvent)
 
 NS_INTERFACE_MAP_BEGIN(CompositionEvent)
 NS_INTERFACE_MAP_END_INHERITING(UIEvent)
 
 void
 CompositionEvent::GetData(nsAString& aData) const
--- a/dom/events/CompositionEvent.h
+++ b/dom/events/CompositionEvent.h
@@ -23,16 +23,21 @@ class CompositionEvent : public UIEvent
 public:
   CompositionEvent(EventTarget* aOwner,
                    nsPresContext* aPresContext,
                    WidgetCompositionEvent* aEvent);
 
   NS_DECL_ISUPPORTS_INHERITED
   NS_FORWARD_TO_UIEVENT
 
+  static already_AddRefed<CompositionEvent> Constructor(const GlobalObject& aGlobal,
+                                                        const nsAString& aType,
+                                                        const CompositionEventInit& aParam,
+                                                        ErrorResult& aRv);
+
   virtual JSObject* WrapObjectInternal(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
   {
     return CompositionEventBinding::Wrap(aCx, this, aGivenProto);
   }
 
   void InitCompositionEvent(const nsAString& aType,
                             bool aCanBubble,
                             bool aCancelable,
--- a/dom/webidl/CompositionEvent.webidl
+++ b/dom/webidl/CompositionEvent.webidl
@@ -4,29 +4,34 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/.
  *
  * http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-CompositionEvent
  *
  * Copyright © 2012 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C
  * liability, trademark and document use rules apply.
  */
 
+[Constructor(DOMString type, optional CompositionEventInit eventInitDict)]
 interface CompositionEvent : UIEvent
 {
   readonly attribute DOMString? data;
   readonly attribute DOMString  locale;
 
  /**
   * ranges is trying to expose TextRangeArray in Gecko so a
   * js-plugin couble be able to know the clauses information
   */
   [ChromeOnly,Cached,Pure]
   readonly attribute sequence<TextClause> ranges;
 };
 
+dictionary CompositionEventInit : UIEventInit {
+  DOMString data = "";
+};
+
 partial interface CompositionEvent
 {
   void initCompositionEvent(DOMString typeArg,
                             boolean canBubbleArg,
                             boolean cancelableArg,
                             Window? viewArg,
                             DOMString? dataArg,
                             DOMString localeArg);
deleted file mode 100644
--- a/testing/web-platform/meta/dom/events/Event-subclasses-constructors.html.ini
+++ /dev/null
@@ -1,20 +0,0 @@
-[Event-subclasses-constructors.html]
-  type: testharness
-  [CompositionEvent constructor (no argument)]
-    expected: FAIL
-
-  [CompositionEvent constructor (undefined argument)]
-    expected: FAIL
-
-  [CompositionEvent constructor (null argument)]
-    expected: FAIL
-
-  [CompositionEvent constructor (empty argument)]
-    expected: FAIL
-
-  [CompositionEvent constructor (argument with default values)]
-    expected: FAIL
-
-  [CompositionEvent constructor (argument with non-default values)]
-    expected: FAIL
-