Bug 1110030 - part5 - Expose KeyboardEventInit dictionary. r=masayuki, r=smaug
authorchunminchang <cchang@mozilla.com>
Tue, 15 Mar 2016 13:46:29 +0800
changeset 291024 2f19708ce61927455c743b30d3389602919c7e7c
parent 291023 d16d8002bf472b54be1993ca030e52139c588afa
child 291025 ebbd79395164168a51c850dc80c7daf156dfa99b
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmasayuki, smaug
bugs1110030
milestone48.0a1
Bug 1110030 - part5 - Expose KeyboardEventInit dictionary. r=masayuki, r=smaug
dom/events/KeyboardEvent.cpp
dom/events/KeyboardEvent.h
dom/webidl/KeyboardEvent.webidl
--- a/dom/events/KeyboardEvent.cpp
+++ b/dom/events/KeyboardEvent.cpp
@@ -131,16 +131,51 @@ KeyboardEvent::GetKey(nsAString& aKeyNam
 }
 
 void
 KeyboardEvent::GetCode(nsAString& aCodeName)
 {
   mEvent->AsKeyboardEvent()->GetDOMCodeName(aCodeName);
 }
 
+void KeyboardEvent::GetInitDict(KeyboardEventInit& aParam)
+{
+  GetKey(aParam.mKey);
+  GetCode(aParam.mCode);
+  aParam.mLocation = Location();
+  aParam.mRepeat = Repeat();
+  aParam.mIsComposing = IsComposing();
+
+  // legacy attributes
+  aParam.mKeyCode = KeyCode();
+  aParam.mCharCode = CharCode();
+  aParam.mWhich = Which();
+
+  // modifiers from EventModifierInit
+  aParam.mCtrlKey = CtrlKey();
+  aParam.mShiftKey = ShiftKey();
+  aParam.mAltKey = AltKey();
+  aParam.mMetaKey = MetaKey();
+
+  WidgetKeyboardEvent* internalEvent = mEvent->AsKeyboardEvent();
+  aParam.mModifierAltGraph = internalEvent->IsAltGraph();
+  aParam.mModifierCapsLock = internalEvent->IsCapsLocked();
+  aParam.mModifierFn = internalEvent->IsFn();
+  aParam.mModifierFnLock = internalEvent->IsFnLocked();
+  aParam.mModifierNumLock = internalEvent->IsNumLocked();
+  aParam.mModifierOS = internalEvent->IsOS();
+  aParam.mModifierScrollLock = internalEvent->IsScrollLocked();
+  aParam.mModifierSymbol = internalEvent->IsSymbol();
+  aParam.mModifierSymbolLock = internalEvent->IsSymbolLocked();
+
+  // EventInit
+  aParam.mBubbles =  internalEvent->mFlags.mBubbles;
+  aParam.mCancelable = internalEvent->mFlags.mCancelable;
+}
+
 NS_IMETHODIMP
 KeyboardEvent::GetCharCode(uint32_t* aCharCode)
 {
   NS_ENSURE_ARG_POINTER(aCharCode);
   *aCharCode = CharCode();
   return NS_OK;
 }
 
--- a/dom/events/KeyboardEvent.h
+++ b/dom/events/KeyboardEvent.h
@@ -55,16 +55,17 @@ public:
   bool Repeat();
   bool IsComposing();
   uint32_t CharCode();
   uint32_t KeyCode();
   virtual uint32_t Which() override;
   uint32_t Location();
 
   void GetCode(nsAString& aCode);
+  void GetInitDict(KeyboardEventInit& aParam);
 
   void InitKeyEvent(const nsAString& aType, bool aCanBubble, bool aCancelable,
                     nsGlobalWindow* aView, bool aCtrlKey, bool aAltKey,
                     bool aShiftKey, bool aMetaKey,
                     uint32_t aKeyCode, uint32_t aCharCode)
   {
     auto* view = aView ? aView->AsInner() : nullptr;
     InitKeyEvent(aType, aCanBubble, aCancelable, view, aCtrlKey, aAltKey,
--- a/dom/webidl/KeyboardEvent.webidl
+++ b/dom/webidl/KeyboardEvent.webidl
@@ -24,16 +24,21 @@ interface KeyboardEvent : UIEvent
 
   readonly attribute unsigned long location;
   readonly attribute boolean       repeat;
   readonly attribute boolean       isComposing;
 
   readonly attribute DOMString key;
   [Pref="dom.keyboardevent.code.enabled"]
   readonly attribute DOMString code;
+
+  // This returns the initialized dictionary for generating a
+  // same-type keyboard event
+  [Cached, ChromeOnly, Constant]
+  readonly attribute KeyboardEventInit initDict;
 };
 
 dictionary KeyboardEventInit : EventModifierInit
 {
   DOMString      key           = "";
   DOMString      code          = "";
   unsigned long  location      = 0;
   boolean        repeat        = false;