Bug 602787 part.9 Don't implement methods which need BasicEvents.h or TextEvents.h in windows/KeyboardLayout.h r=jimm
☠☠ backed out by 3c5efc154d58 ☠ ☠
authorMasayuki Nakano <masayuki@d-toybox.com>
Tue, 22 Oct 2013 22:27:36 +0900
changeset 166461 70606b9b1e4200eff4239bb224f64d38d1cf8cd7
parent 166460 57ca2861ea307d39f596cd3e06d4f168c028119f
child 166462 1730bcae2c4508df2610db74e45e38207fbd8687
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs602787
milestone27.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 602787 part.9 Don't implement methods which need BasicEvents.h or TextEvents.h in windows/KeyboardLayout.h r=jimm
widget/windows/KeyboardLayout.cpp
widget/windows/KeyboardLayout.h
--- a/widget/windows/KeyboardLayout.cpp
+++ b/widget/windows/KeyboardLayout.cpp
@@ -90,16 +90,48 @@ public:
   PRUnichar GetCompositeChar(PRUnichar aBaseChar) const;
 };
 
 
 /*****************************************************************************
  * mozilla::widget::ModifierKeyState
  *****************************************************************************/
 
+ModifierKeyState::ModifierKeyState()
+{
+  Update();
+}
+
+ModifierKeyState::ModifierKeyState(bool aIsShiftDown,
+                                   bool aIsControlDown,
+                                   bool aIsAltDown)
+{
+  Update();
+  Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
+  Modifiers modifiers = 0;
+  if (aIsShiftDown) {
+    modifiers |= MODIFIER_SHIFT;
+  }
+  if (aIsControlDown) {
+    modifiers |= MODIFIER_CONTROL;
+  }
+  if (aIsAltDown) {
+    modifiers |= MODIFIER_ALT;
+  }
+  if (modifiers) {
+    Set(modifiers);
+  }
+}
+
+ModifierKeyState::ModifierKeyState(Modifiers aModifiers) :
+  mModifiers(aModifiers)
+{
+  EnsureAltGr();
+}
+
 void
 ModifierKeyState::Update()
 {
   mModifiers = 0;
   if (IS_VK_DOWN(VK_SHIFT)) {
     mModifiers |= MODIFIER_SHIFT;
   }
   if (IS_VK_DOWN(VK_CONTROL)) {
@@ -120,16 +152,32 @@ ModifierKeyState::Update()
   if (::GetKeyState(VK_SCROLL) & 1) {
     mModifiers |= MODIFIER_SCROLLLOCK;
   }
 
   EnsureAltGr();
 }
 
 void
+ModifierKeyState::Unset(Modifiers aRemovingModifiers)
+{
+  mModifiers &= ~aRemovingModifiers;
+  // Note that we don't need to unset AltGr flag here automatically.
+  // For nsEditor, we need to remove Alt and Control flags but AltGr isn't
+  // checked in nsEditor, so, it can be kept.
+}
+
+void
+ModifierKeyState::Set(Modifiers aAddingModifiers)
+{
+  mModifiers |= aAddingModifiers;
+  EnsureAltGr();
+}
+
+void
 ModifierKeyState::InitInputEvent(WidgetInputEvent& aInputEvent) const
 {
   aInputEvent.modifiers = mModifiers;
 
   switch(aInputEvent.eventStructType) {
     case NS_MOUSE_EVENT:
     case NS_MOUSE_SCROLL_EVENT:
     case NS_WHEEL_EVENT:
@@ -165,16 +213,82 @@ ModifierKeyState::InitMouseEvent(WidgetI
   if (::GetKeyState(VK_XBUTTON1) < 0) {
     mouseEvent.buttons |= WidgetMouseEvent::e4thButtonFlag;
   }
   if (::GetKeyState(VK_XBUTTON2) < 0) {
     mouseEvent.buttons |= WidgetMouseEvent::e5thButtonFlag;
   }
 }
 
+bool
+ModifierKeyState::IsShift() const
+{
+  return (mModifiers & MODIFIER_SHIFT) != 0;
+}
+
+bool
+ModifierKeyState::IsControl() const
+{
+  return (mModifiers & MODIFIER_CONTROL) != 0;
+}
+
+bool
+ModifierKeyState::IsAlt() const
+{
+  return (mModifiers & MODIFIER_ALT) != 0;
+}
+
+bool
+ModifierKeyState::IsAltGr() const
+{
+  return IsControl() && IsAlt();
+}
+
+bool
+ModifierKeyState::IsWin() const
+{
+  return (mModifiers & MODIFIER_OS) != 0;
+}
+
+bool
+ModifierKeyState::IsCapsLocked() const
+{
+  return (mModifiers & MODIFIER_CAPSLOCK) != 0;
+}
+
+bool
+ModifierKeyState::IsNumLocked() const
+{
+  return (mModifiers & MODIFIER_NUMLOCK) != 0;
+}
+
+bool
+ModifierKeyState::IsScrollLocked() const
+{
+  return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
+}
+
+Modifiers
+ModifierKeyState::GetModifiers() const
+{
+  return mModifiers;
+}
+
+void
+ModifierKeyState::EnsureAltGr()
+{
+  // If both Control key and Alt key are pressed, it means AltGr is pressed.
+  // Ideally, we should check whether the current keyboard layout has AltGr
+  // or not.  However, setting AltGr flags for keyboard which doesn't have
+  // AltGr must not be serious bug.  So, it should be OK for now.
+  if (IsAltGr()) {
+    mModifiers |= MODIFIER_ALTGRAPH;
+  }
+}
+
 /*****************************************************************************
  * mozilla::widget::UniCharsAndModifiers
  *****************************************************************************/
 
 void
 UniCharsAndModifiers::Append(PRUnichar aUniChar, Modifiers aModifiers)
 {
   MOZ_ASSERT(mLength < 5);
@@ -231,16 +345,60 @@ UniCharsAndModifiers::operator+(const Un
   result += aOther;
   return result;
 }
 
 /*****************************************************************************
  * mozilla::widget::VirtualKey
  *****************************************************************************/
 
+// static
+VirtualKey::ShiftState
+VirtualKey::ModifiersToShiftState(Modifiers aModifiers)
+{
+  ShiftState state = 0;
+  if (aModifiers & MODIFIER_SHIFT) {
+    state |= STATE_SHIFT;
+  }
+  if (aModifiers & MODIFIER_CONTROL) {
+    state |= STATE_CONTROL;
+  }
+  if (aModifiers & MODIFIER_ALT) {
+    state |= STATE_ALT;
+  }
+  if (aModifiers & MODIFIER_CAPSLOCK) {
+    state |= STATE_CAPSLOCK;
+  }
+  return state;
+}
+
+// static
+Modifiers
+VirtualKey::ShiftStateToModifiers(ShiftState aShiftState)
+{
+  Modifiers modifiers = 0;
+  if (aShiftState & STATE_SHIFT) {
+    modifiers |= MODIFIER_SHIFT;
+  }
+  if (aShiftState & STATE_CONTROL) {
+    modifiers |= MODIFIER_CONTROL;
+  }
+  if (aShiftState & STATE_ALT) {
+    modifiers |= MODIFIER_ALT;
+  }
+  if (aShiftState & STATE_CAPSLOCK) {
+    modifiers |= MODIFIER_CAPSLOCK;
+  }
+  if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
+         (MODIFIER_ALT | MODIFIER_CONTROL)) {
+    modifiers |= MODIFIER_ALTGRAPH;
+  }
+  return modifiers;
+}
+
 inline PRUnichar
 VirtualKey::GetCompositeChar(ShiftState aShiftState, PRUnichar aBaseChar) const
 {
   return mShiftStates[aShiftState].DeadKey.Table->GetCompositeChar(aBaseChar);
 }
 
 const DeadKeyTable*
 VirtualKey::MatchingDeadKeyTable(const DeadKeyEntry* aDeadKeyArray,
@@ -748,16 +906,22 @@ PRUnichar
 NativeKey::ComputeUnicharFromScanCode() const
 {
   return static_cast<PRUnichar>(
            ::MapVirtualKeyEx(ComputeVirtualKeyCodeFromScanCode(),
                              MAPVK_VK_TO_CHAR, mKeyboardLayout));
 }
 
 void
+NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
+{
+  InitKeyEvent(aKeyEvent, mModKeyState);
+}
+
+void
 NativeKey::InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const ModifierKeyState& aModKeyState) const
 {
   nsIntPoint point(0, 0);
   mWidget->InitEvent(aKeyEvent, &point);
 
   switch (aKeyEvent.message) {
     case NS_KEY_DOWN:
--- a/widget/windows/KeyboardLayout.h
+++ b/widget/windows/KeyboardLayout.h
@@ -6,17 +6,18 @@
 #ifndef KeyboardLayout_h__
 #define KeyboardLayout_h__
 
 #include "nscore.h"
 #include "nsAutoPtr.h"
 #include "nsString.h"
 #include "nsWindowBase.h"
 #include "nsWindowDefs.h"
-#include "mozilla/BasicEvents.h"
+#include "mozilla/Attributes.h"
+#include "mozilla/EventForwards.h"
 #include <windows.h>
 
 #define NS_NUM_OF_KEYS          70
 
 #define VK_OEM_1                0xBA   // ';:' for US
 #define VK_OEM_PLUS             0xBB   // '+' any country
 #define VK_OEM_COMMA            0xBC
 #define VK_OEM_MINUS            0xBD   // '-' any country
@@ -49,94 +50,46 @@ static const uint32_t sModifierKeyMap[][
   { nsIWidget::CTRL_L,    VK_CONTROL, VK_LCONTROL },
   { nsIWidget::CTRL_R,    VK_CONTROL, VK_RCONTROL },
   { nsIWidget::ALT_L,     VK_MENU,    VK_LMENU },
   { nsIWidget::ALT_R,     VK_MENU,    VK_RMENU }
 };
 
 class KeyboardLayout;
 
-class ModifierKeyState {
+class ModifierKeyState
+{
 public:
-  ModifierKeyState()
-  {
-    Update();
-  }
+  ModifierKeyState();
+  ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown);
+  ModifierKeyState(Modifiers aModifiers);
 
-  ModifierKeyState(bool aIsShiftDown, bool aIsControlDown, bool aIsAltDown)
-  {
-    Update();
-    Unset(MODIFIER_SHIFT | MODIFIER_CONTROL | MODIFIER_ALT | MODIFIER_ALTGRAPH);
-    Modifiers modifiers = 0;
-    if (aIsShiftDown) {
-      modifiers |= MODIFIER_SHIFT;
-    }
-    if (aIsControlDown) {
-      modifiers |= MODIFIER_CONTROL;
-    }
-    if (aIsAltDown) {
-      modifiers |= MODIFIER_ALT;
-    }
-    if (modifiers) {
-      Set(modifiers);
-    }
-  }
+  MOZ_ALWAYS_INLINE void Update();
 
-  ModifierKeyState(Modifiers aModifiers) :
-    mModifiers(aModifiers)
-  {
-    EnsureAltGr();
-  }
-
-  void Update();
-
-  void Unset(Modifiers aRemovingModifiers)
-  {
-    mModifiers &= ~aRemovingModifiers;
-    // Note that we don't need to unset AltGr flag here automatically.
-    // For nsEditor, we need to remove Alt and Control flags but AltGr isn't
-    // checked in nsEditor, so, it can be kept.
-  }
-
-  void Set(Modifiers aAddingModifiers)
-  {
-    mModifiers |= aAddingModifiers;
-    EnsureAltGr();
-  }
+  MOZ_ALWAYS_INLINE void Unset(Modifiers aRemovingModifiers);
+  MOZ_ALWAYS_INLINE void Set(Modifiers aAddingModifiers);
 
   void InitInputEvent(WidgetInputEvent& aInputEvent) const;
 
-  bool IsShift() const { return (mModifiers & MODIFIER_SHIFT) != 0; }
-  bool IsControl() const { return (mModifiers & MODIFIER_CONTROL) != 0; }
-  bool IsAlt() const { return (mModifiers & MODIFIER_ALT) != 0; }
-  bool IsAltGr() const { return IsControl() && IsAlt(); }
-  bool IsWin() const { return (mModifiers & MODIFIER_OS) != 0; }
+  MOZ_ALWAYS_INLINE bool IsShift() const;
+  MOZ_ALWAYS_INLINE bool IsControl() const;
+  MOZ_ALWAYS_INLINE bool IsAlt() const;
+  MOZ_ALWAYS_INLINE bool IsAltGr() const;
+  MOZ_ALWAYS_INLINE bool IsWin() const;
 
-  bool IsCapsLocked() const { return (mModifiers & MODIFIER_CAPSLOCK) != 0; }
-  bool IsNumLocked() const { return (mModifiers & MODIFIER_NUMLOCK) != 0; }
-  bool IsScrollLocked() const
-  {
-    return (mModifiers & MODIFIER_SCROLLLOCK) != 0;
-  }
+  MOZ_ALWAYS_INLINE bool IsCapsLocked() const;
+  MOZ_ALWAYS_INLINE bool IsNumLocked() const;
+  MOZ_ALWAYS_INLINE bool IsScrollLocked() const;
 
-  Modifiers GetModifiers() const { return mModifiers; }
+  MOZ_ALWAYS_INLINE Modifiers GetModifiers() const;
 
 private:
   Modifiers mModifiers;
 
-  void EnsureAltGr()
-  {
-    // If both Control key and Alt key are pressed, it means AltGr is pressed.
-    // Ideally, we should check whether the current keyboard layout has AltGr
-    // or not.  However, setting AltGr flags for keyboard which doesn't have
-    // AltGr must not be serious bug.  So, it should be OK for now.
-    if (IsAltGr()) {
-      mModifiers |= MODIFIER_ALTGRAPH;
-    }
-  }
+  MOZ_ALWAYS_INLINE void EnsureAltGr();
 
   void InitMouseEvent(WidgetInputEvent& aMouseEvent) const;
 };
 
 struct UniCharsAndModifiers
 {
   // Dead-key + up to 4 characters
   PRUnichar mChars[5];
@@ -191,55 +144,18 @@ public:
     STATE_SHIFT    = 0x01,
     STATE_CONTROL  = 0x02,
     STATE_ALT      = 0x04,
     STATE_CAPSLOCK = 0x08
   };
 
   typedef uint8_t ShiftState;
 
-  static ShiftState ModifiersToShiftState(Modifiers aModifiers)
-  {
-    ShiftState state = 0;
-    if (aModifiers & MODIFIER_SHIFT) {
-      state |= STATE_SHIFT;
-    }
-    if (aModifiers & MODIFIER_CONTROL) {
-      state |= STATE_CONTROL;
-    }
-    if (aModifiers & MODIFIER_ALT) {
-      state |= STATE_ALT;
-    }
-    if (aModifiers & MODIFIER_CAPSLOCK) {
-      state |= STATE_CAPSLOCK;
-    }
-    return state;
-  }
-
-  static Modifiers ShiftStateToModifiers(ShiftState aShiftState)
-  {
-    Modifiers modifiers = 0;
-    if (aShiftState & STATE_SHIFT) {
-      modifiers |= MODIFIER_SHIFT;
-    }
-    if (aShiftState & STATE_CONTROL) {
-      modifiers |= MODIFIER_CONTROL;
-    }
-    if (aShiftState & STATE_ALT) {
-      modifiers |= MODIFIER_ALT;
-    }
-    if (aShiftState & STATE_CAPSLOCK) {
-      modifiers |= MODIFIER_CAPSLOCK;
-    }
-    if ((modifiers & (MODIFIER_ALT | MODIFIER_CONTROL)) ==
-           (MODIFIER_ALT | MODIFIER_CONTROL)) {
-      modifiers |= MODIFIER_ALTGRAPH;
-    }
-    return modifiers;
-  }
+  static ShiftState ModifiersToShiftState(Modifiers aModifiers);
+  static Modifiers ShiftStateToModifiers(ShiftState aShiftState);
 
 private:
   union KeyShiftState
   {
     struct
     {
       PRUnichar Chars[4];
     } Normal;
@@ -423,20 +339,17 @@ private:
    */
   PRUnichar ComputeUnicharFromScanCode() const;
 
   /**
    * Initializes the aKeyEvent with the information stored in the instance.
    */
   void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                     const ModifierKeyState& aModKeyState) const;
-  void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const
-  {
-    InitKeyEvent(aKeyEvent, mModKeyState);
-  }
+  void InitKeyEvent(WidgetKeyboardEvent& aKeyEvent) const;
 
   /**
    * Dispatches the key event.  Returns true if the event is consumed.
    * Otherwise, false.
    */
   bool DispatchKeyEvent(WidgetKeyboardEvent& aKeyEvent,
                         const MSG* aMsgSentToPlugin = nullptr) const;