Bug 1351783 part 2 - Add a KeyboardInput type. r=kats draft
authorRyan Hunt <rhunt@eqrion.net>
Mon, 05 Jun 2017 18:09:40 -0500
changeset 599266 50d92b62f7eb4eef807eec565cb1ad15578ebf01
parent 599265 0b5e61a0dabb018db25339723c51cc5de6502abc
child 599267 2db52d99287df29483ada0edc0fc739dd045d147
push id65466
push userbmo:rhunt@eqrion.net
push dateThu, 22 Jun 2017 22:16:51 +0000
reviewerskats
bugs1351783
milestone56.0a1
Bug 1351783 part 2 - Add a KeyboardInput type. r=kats Every event type handled by APZ needs to have a InputData type. This commit adds a new KeyboardInput type that stores the minimum fields needed to match keyboard shortcuts. MozReview-Commit-ID: 3KUnH4sWrST
widget/InputData.cpp
widget/InputData.h
widget/TextEvents.h
widget/WidgetEventImpl.cpp
widget/nsGUIEventIPC.h
--- a/widget/InputData.cpp
+++ b/widget/InputData.cpp
@@ -780,9 +780,47 @@ ScrollWheelInput::TransformToLocal(const
 
 bool
 ScrollWheelInput::IsCustomizedByUserPrefs() const
 {
   return mUserDeltaMultiplierX != 1.0 ||
          mUserDeltaMultiplierY != 1.0;
 }
 
+KeyboardInput::KeyboardInput(const WidgetKeyboardEvent& aEvent)
+  : InputData(KEYBOARD_INPUT,
+              aEvent.mTime,
+              aEvent.mTimeStamp,
+              aEvent.mModifiers)
+  , mKeyCode(aEvent.mKeyCode)
+  , mCharCode(aEvent.mCharCode)
+  , mHandledByAPZ(false)
+{
+  switch (aEvent.mMessage) {
+    case eKeyPress: {
+      mType = KeyboardInput::KEY_PRESS;
+      break;
+    }
+    case eKeyUp: {
+      mType = KeyboardInput::KEY_UP;
+      break;
+    }
+    case eKeyDown: {
+      mType = KeyboardInput::KEY_DOWN;
+      break;
+    }
+    default:
+      mType = KeyboardInput::KEY_OTHER;
+      break;
+  }
+
+  aEvent.GetShortcutKeyCandidates(mShortcutCandidates);
+}
+
+KeyboardInput::KeyboardInput()
+  : InputData(KEYBOARD_INPUT)
+  , mKeyCode(0)
+  , mCharCode(0)
+  , mHandledByAPZ(false)
+{
+}
+
 } // namespace mozilla
--- a/widget/InputData.h
+++ b/widget/InputData.h
@@ -35,27 +35,29 @@ enum InputType
   // Warning, this enum is serialized and sent over IPC. If you reorder, add,
   // or remove a value, you need to update its ParamTraits<> in nsGUIEventIPC.h
   MULTITOUCH_INPUT,
   MOUSE_INPUT,
   PANGESTURE_INPUT,
   PINCHGESTURE_INPUT,
   TAPGESTURE_INPUT,
   SCROLLWHEEL_INPUT,
+  KEYBOARD_INPUT,
 
   // Used as an upper bound for ContiguousEnumSerializer
   SENTINEL_INPUT,
 };
 
 class MultiTouchInput;
 class MouseInput;
 class PanGestureInput;
 class PinchGestureInput;
 class TapGestureInput;
 class ScrollWheelInput;
+class KeyboardInput;
 
 // This looks unnecessary now, but as we add more and more classes that derive
 // from InputType (eventually probably almost as many as *Events.h has), it
 // will be more and more clear what's going on with a macro that shortens the
 // definition of the RTTI functions.
 #define INPUTDATA_AS_CHILD_TYPE(type, enumID) \
   const type& As##type() const \
   { \
@@ -88,16 +90,17 @@ public:
   Modifiers modifiers;
 
   INPUTDATA_AS_CHILD_TYPE(MultiTouchInput, MULTITOUCH_INPUT)
   INPUTDATA_AS_CHILD_TYPE(MouseInput, MOUSE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(PanGestureInput, PANGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(PinchGestureInput, PINCHGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(TapGestureInput, TAPGESTURE_INPUT)
   INPUTDATA_AS_CHILD_TYPE(ScrollWheelInput, SCROLLWHEEL_INPUT)
+  INPUTDATA_AS_CHILD_TYPE(KeyboardInput, KEYBOARD_INPUT)
 
   virtual ~InputData();
   explicit InputData(InputType aInputType);
 
 protected:
   InputData(InputType aInputType, uint32_t aTime, TimeStamp aTimeStamp,
             Modifiers aModifiers);
 };
@@ -608,11 +611,45 @@ public:
   double mUserDeltaMultiplierX;
   double mUserDeltaMultiplierY;
 
   bool mMayHaveMomentum;
   bool mIsMomentum;
   bool mAllowToOverrideSystemScrollSpeed;
 };
 
+class KeyboardInput : public InputData
+{
+public:
+  enum KeyboardEventType
+  {
+    KEY_DOWN,
+    KEY_PRESS,
+    KEY_UP,
+    // Any other key event such as eKeyDownOnPlugin
+    KEY_OTHER,
+
+    // Used as an upper bound for ContiguousEnumSerializer
+    KEY_SENTINEL,
+  };
+
+  explicit KeyboardInput(const WidgetKeyboardEvent& aEvent);
+
+  // Warning, this class is serialized and sent over IPC. Any change to its
+  // fields must be reflected in its ParamTraits<>, in nsGUIEventIPC.h
+
+  KeyboardEventType mType;
+  uint32_t mKeyCode;
+  uint32_t mCharCode;
+  nsTArray<ShortcutKeyCandidate> mShortcutCandidates;
+
+  bool mHandledByAPZ;
+
+protected:
+  friend mozilla::layers::PAPZCTreeManagerParent;
+  friend mozilla::layers::APZCTreeManagerChild;
+
+  KeyboardInput();
+};
+
 } // namespace mozilla
 
 #endif // InputData_h__
--- a/widget/TextEvents.h
+++ b/widget/TextEvents.h
@@ -83,16 +83,21 @@ struct AlternativeCharCode
 /******************************************************************************
  * mozilla::ShortcutKeyCandidate
  *
  * This stores a candidate of shortcut key combination.
  ******************************************************************************/
 
 struct ShortcutKeyCandidate
 {
+  ShortcutKeyCandidate()
+    : mCharCode(0)
+    , mIgnoreShift(0)
+  {
+  }
   ShortcutKeyCandidate(uint32_t aCharCode, bool aIgnoreShift)
     : mCharCode(aCharCode)
     , mIgnoreShift(aIgnoreShift)
   {
   }
   // The mCharCode value which must match keyboard shortcut definition.
   uint32_t mCharCode;
   // true if Shift state can be ignored.  Otherwise, Shift key state must
@@ -404,25 +409,25 @@ public:
   }
 
   /**
    * Get the candidates for shortcut key.
    *
    * @param aCandidates [out] the candidate shortcut key combination list.
    *                          the first item is most preferred.
    */
-  void GetShortcutKeyCandidates(ShortcutKeyCandidateArray& aCandidates);
+  void GetShortcutKeyCandidates(ShortcutKeyCandidateArray& aCandidates) const;
 
   /**
    * Get the candidates for access key.
    *
    * @param aCandidates [out] the candidate access key list.
    *                          the first item is most preferred.
    */
-  void GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates);
+  void GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates) const;
 
   static void Shutdown();
 
   /**
    * ComputeLocationFromCodeValue() returns one of .mLocation value
    * (eKeyLocation*) which is the most preferred value for the specified code
    * value.
    */
--- a/widget/WidgetEventImpl.cpp
+++ b/widget/WidgetEventImpl.cpp
@@ -727,17 +727,17 @@ IsCaseChangeableChar(uint32_t aChar)
 {
   return IS_IN_BMP(aChar) &&
          ToLowerCase(static_cast<char16_t>(aChar)) !=
            ToUpperCase(static_cast<char16_t>(aChar));
 }
 
 void
 WidgetKeyboardEvent::GetShortcutKeyCandidates(
-                       ShortcutKeyCandidateArray& aCandidates)
+                       ShortcutKeyCandidateArray& aCandidates) const
 {
   MOZ_ASSERT(aCandidates.IsEmpty(), "aCandidates must be empty");
 
   // ShortcutKeyCandidate::mCharCode is a candidate charCode.
   // ShortcutKeyCandidate::mIgnoreShift means the mCharCode should be tried to
   // execute a command with/without shift key state. If this is TRUE, the
   // shifted key state should be ignored. Otherwise, don't ignore the state.
   // the priority of the charCodes are (shift key is not pressed):
@@ -821,17 +821,17 @@ WidgetKeyboardEvent::GetShortcutKeyCandi
   if (mKeyNameIndex == KEY_NAME_INDEX_USE_STRING &&
       mCodeNameIndex == CODE_NAME_INDEX_Space && pseudoCharCode != ' ') {
     ShortcutKeyCandidate spaceKey(' ', false);
     aCandidates.AppendElement(spaceKey);
   }
 }
 
 void
-WidgetKeyboardEvent::GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates)
+WidgetKeyboardEvent::GetAccessKeyCandidates(nsTArray<uint32_t>& aCandidates) const
 {
   MOZ_ASSERT(aCandidates.IsEmpty(), "aCandidates must be empty");
 
   // return the lower cased charCode candidates for access keys.
   // the priority of the charCodes are:
   //   0: charCode, 1: unshiftedCharCodes[0], 2: shiftedCharCodes[0]
   //   3: unshiftedCharCodes[1], 4: shiftedCharCodes[1],...
   if (mCharCode) {
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -397,16 +397,33 @@ struct ParamTraits<mozilla::AlternativeC
 
   static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
   {
     return ReadParam(aMsg, aIter, &aResult->mUnshiftedCharCode) &&
            ReadParam(aMsg, aIter, &aResult->mShiftedCharCode);
   }
 };
 
+template<>
+struct ParamTraits<mozilla::ShortcutKeyCandidate>
+{
+  typedef mozilla::ShortcutKeyCandidate paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    WriteParam(aMsg, aParam.mCharCode);
+    WriteParam(aMsg, aParam.mIgnoreShift);
+  }
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
+  {
+    return ReadParam(aMsg, aIter, &aResult->mCharCode) &&
+           ReadParam(aMsg, aIter, &aResult->mIgnoreShift);
+  }
+};
 
 template<>
 struct ParamTraits<mozilla::WidgetKeyboardEvent>
 {
   typedef mozilla::WidgetKeyboardEvent paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
@@ -1345,11 +1362,45 @@ struct ParamTraits<mozilla::ScrollWheelI
            ReadParam(aMsg, aIter, &aResult->mUserDeltaMultiplierX) &&
            ReadParam(aMsg, aIter, &aResult->mUserDeltaMultiplierY) &&
            ReadParam(aMsg, aIter, &aResult->mMayHaveMomentum) &&
            ReadParam(aMsg, aIter, &aResult->mIsMomentum) &&
            ReadParam(aMsg, aIter, &aResult->mAllowToOverrideSystemScrollSpeed);
   }
 };
 
+template <>
+struct ParamTraits<mozilla::KeyboardInput::KeyboardEventType>
+  : public ContiguousEnumSerializer<
+             mozilla::KeyboardInput::KeyboardEventType,
+             mozilla::KeyboardInput::KeyboardEventType::KEY_DOWN,
+             mozilla::KeyboardInput::KeyboardEventType::KEY_SENTINEL>
+{};
+
+template<>
+struct ParamTraits<mozilla::KeyboardInput>
+{
+  typedef mozilla::KeyboardInput paramType;
+
+  static void Write(Message* aMsg, const paramType& aParam)
+  {
+    WriteParam(aMsg, static_cast<mozilla::InputData>(aParam));
+    WriteParam(aMsg, aParam.mType);
+    WriteParam(aMsg, aParam.mKeyCode);
+    WriteParam(aMsg, aParam.mCharCode);
+    WriteParam(aMsg, aParam.mShortcutCandidates);
+    WriteParam(aMsg, aParam.mHandledByAPZ);
+  }
+
+  static bool Read(const Message* aMsg, PickleIterator* aIter, paramType* aResult)
+  {
+    return ReadParam(aMsg, aIter, static_cast<mozilla::InputData*>(aResult)) &&
+           ReadParam(aMsg, aIter, &aResult->mType) &&
+           ReadParam(aMsg, aIter, &aResult->mKeyCode) &&
+           ReadParam(aMsg, aIter, &aResult->mCharCode) &&
+           ReadParam(aMsg, aIter, &aResult->mShortcutCandidates) &&
+           ReadParam(aMsg, aIter, &aResult->mHandledByAPZ);
+  }
+};
+
 } // namespace IPC
 
 #endif // nsGUIEventIPC_h__