Bug 822866 Make mozilla::widget::BaseEventFlags which is a POD struct for VC r=smaug
authorMasayuki Nakano <masayuki@d-toybox.com>
Fri, 28 Dec 2012 23:13:18 +0900
changeset 126264 1faf3072fb8bc8d52fc9b0b1b521913903513dbd
parent 126263 a0bc627d0af77d439c4d3f04c34f0c1c2bbb287f
child 126265 29ce28a490c94e3c2bc4bb74674ed2087dab80aa
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs822866
milestone20.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 822866 Make mozilla::widget::BaseEventFlags which is a POD struct for VC r=smaug
content/base/src/Element.cpp
content/html/content/src/HTMLLabelElement.cpp
widget/gonk/nsAppShell.cpp
widget/nsGUIEvent.h
widget/nsGUIEventIPC.h
widget/windows/nsWindow.cpp
--- a/content/base/src/Element.cpp
+++ b/content/base/src/Element.cpp
@@ -1611,17 +1611,17 @@ Element::DispatchClickEvent(nsPresContex
     inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD;
   }
   event.pressure = pressure;
   event.clickCount = clickCount;
   event.inputSource = inputSource;
   event.modifiers = aSourceEvent->modifiers;
   if (aExtraEventFlags) {
     // Be careful not to overwrite existing flags!
-    event.mFlags |= *aExtraEventFlags;
+    event.mFlags.Union(*aExtraEventFlags);
   }
 
   return DispatchEvent(aPresContext, &event, aTarget, aFullDispatch, aStatus);
 }
 
 nsIFrame*
 Element::GetPrimaryFrame(mozFlushType aType)
 {
--- a/content/html/content/src/HTMLLabelElement.cpp
+++ b/content/html/content/src/HTMLLabelElement.cpp
@@ -198,17 +198,16 @@ HTMLLabelElement::PostHandleEvent(nsEven
           //    we wanted to interpret the HTML spec very narrowly, we
           //    would do nothing.  If we wanted to do something
           //    sensible, we might send more events through like
           //    this.)  See bug 7554, bug 49897, and bug 96813.
           nsEventStatus status = aVisitor.mEventStatus;
           // Ok to use aVisitor.mEvent as parameter because DispatchClickEvent
           // will actually create a new event.
           widget::EventFlags eventFlags;
-          eventFlags.Clear();
           eventFlags.mMultipleActionsPrevented = true;
           DispatchClickEvent(aVisitor.mPresContext,
                              static_cast<nsInputEvent*>(aVisitor.mEvent),
                              content, false, &eventFlags, &status);
           // Do we care about the status this returned?  I don't think we do...
           // Don't run another <label> off of this click
           aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
         }
--- a/widget/gonk/nsAppShell.cpp
+++ b/widget/gonk/nsAppShell.cpp
@@ -202,17 +202,17 @@ sendKeyEventWithMsg(uint32_t keyCode,
                     uint32_t msg,
                     uint64_t timeMs,
                     const EventFlags& flags)
 {
     nsKeyEvent event(true, msg, NULL);
     event.keyCode = keyCode;
     event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
     event.time = timeMs;
-    event.mFlags |= flags;
+    event.mFlags.Union(flags);
     return nsWindow::DispatchInputEvent(event);
 }
 
 static void
 sendKeyEvent(uint32_t keyCode, bool down, uint64_t timeMs)
 {
     EventFlags extraFlags;
     nsEventStatus status =
--- a/widget/nsGUIEvent.h
+++ b/widget/nsGUIEvent.h
@@ -463,17 +463,22 @@ enum nsEventStructType {
 enum nsWindowZ {
   nsWindowZTop = 0,   // on top
   nsWindowZBottom,    // on bottom
   nsWindowZRelative   // just below some specified widget
 };
 
 namespace mozilla {
 namespace widget {
-struct EventFlags
+
+// BaseEventFlags must be a POD struct for safe to use memcpy (including
+// in ParamTraits<BaseEventFlags>).  So don't make virtual methods, constructor,
+// destructor and operators.
+// This is necessary for VC which is NOT C++0x compiler.
+struct BaseEventFlags
 {
 public:
   // If mIsTrusted is true, the event is a trusted event.  Otherwise, it's
   // an untrusted event.
   bool    mIsTrusted : 1;
   // If mInBubblingPhase is true, the event is in bubbling phase or target
   // phase.
   bool    mInBubblingPhase : 1;
@@ -533,57 +538,59 @@ public:
   // window and document object sets it true.  Therefore, web applications
   // can handle the event if they add event listeners to the window or the
   // document.
   bool    mNoContentDispatch : 1;
   // If mOnlyChromeDispatch is true, the event is dispatched to only chrome.
   bool    mOnlyChromeDispatch : 1;
 
   // If the event is being handled in target phase, returns true.
-  bool InTargetPhase() const
+  inline bool InTargetPhase() const
   {
     return (mInBubblingPhase && mInCapturePhase);
   }
 
-  EventFlags()
-  {
-    Clear();
-  }
   inline void Clear()
   {
     SetRawFlags(0);
   }
-  inline EventFlags operator|(const EventFlags& aOther) const
+  // Get if either the instance's bit or the aOther's bit is true, the
+  // instance's bit becomes true.  In other words, this works like:
+  // eventFlags |= aOther;
+  inline void Union(const BaseEventFlags& aOther)
   {
-    EventFlags flags;
-    flags.SetRawFlags(GetRawFlags() | aOther.GetRawFlags());
-    return flags;
-  }
-  inline EventFlags& operator|=(const EventFlags& aOther)
-  {
-    SetRawFlags(GetRawFlags() | aOther.GetRawFlags());
-    return *this;
+    RawFlags rawFlags = GetRawFlags() | aOther.GetRawFlags();
+    SetRawFlags(rawFlags);
   }
 
 private:
   typedef uint32_t RawFlags;
 
   inline void SetRawFlags(RawFlags aRawFlags)
   {
-    MOZ_STATIC_ASSERT(sizeof(EventFlags) <= sizeof(RawFlags),
+    MOZ_STATIC_ASSERT(sizeof(BaseEventFlags) <= sizeof(RawFlags),
       "mozilla::widget::EventFlags must not be bigger than the RawFlags");
-    memcpy(this, &aRawFlags, sizeof(EventFlags));
+    memcpy(this, &aRawFlags, sizeof(BaseEventFlags));
   }
   inline RawFlags GetRawFlags() const
   {
     RawFlags result = 0;
-    memcpy(&result, this, sizeof(EventFlags));
+    memcpy(&result, this, sizeof(BaseEventFlags));
     return result;
   }
 };
+
+struct EventFlags : public BaseEventFlags
+{
+  EventFlags()
+  {
+    Clear();
+  }
+};
+
 } // namespace widget
 } // namespace mozilla
 
 /**
  * General event
  */
 
 class nsEvent
@@ -593,16 +600,17 @@ protected:
     : eventStructType(structType),
       message(msg),
       refPoint(0, 0),
       lastRefPoint(0, 0),
       time(0),
       userType(0)
   {
     MOZ_COUNT_CTOR(nsEvent);
+    mFlags.Clear();
     mFlags.mIsTrusted = isTrusted;
     mFlags.mCancelable = true;
     mFlags.mBubbles = true;
   }
 
   nsEvent()
   {
     MOZ_COUNT_CTOR(nsEvent);
@@ -613,16 +621,17 @@ public:
     : eventStructType(NS_EVENT),
       message(msg),
       refPoint(0, 0),
       lastRefPoint(0, 0),
       time(0),
       userType(0)
   {
     MOZ_COUNT_CTOR(nsEvent);
+    mFlags.Clear();
     mFlags.mIsTrusted = isTrusted;
     mFlags.mCancelable = true;
     mFlags.mBubbles = true;
   }
 
   ~nsEvent()
   {
     MOZ_COUNT_DTOR(nsEvent);
@@ -641,18 +650,18 @@ public:
   // Relative to the widget of the event, or if there is no widget then it is
   // in screen coordinates. Not modified by layout code.
   nsIntPoint  refPoint;
   // The previous refPoint, if known, used to calculate mouse movement deltas.
   nsIntPoint  lastRefPoint;
   // Elapsed time, in milliseconds, from a platform-specific zero time
   // to the time the message was created
   uint64_t    time;
-  // See EventFlags definition for the detail.
-  mozilla::widget::EventFlags mFlags;
+  // See BaseEventFlags definition for the detail.
+  mozilla::widget::BaseEventFlags mFlags;
 
   // Additional type info for user defined events
   nsCOMPtr<nsIAtom>     userType;
   // Event targets, needed by DOM Events
   nsCOMPtr<nsIDOMEventTarget> target;
   nsCOMPtr<nsIDOMEventTarget> currentTarget;
   nsCOMPtr<nsIDOMEventTarget> originalTarget;
 };
--- a/widget/nsGUIEventIPC.h
+++ b/widget/nsGUIEventIPC.h
@@ -9,19 +9,19 @@
 #include "ipc/IPCMessageUtils.h"
 #include "nsDOMTouchEvent.h"
 #include "nsGUIEvent.h"
 
 namespace IPC
 {
 
 template<>
-struct ParamTraits<mozilla::widget::EventFlags>
+struct ParamTraits<mozilla::widget::BaseEventFlags>
 {
-  typedef mozilla::widget::EventFlags paramType;
+  typedef mozilla::widget::BaseEventFlags paramType;
 
   static void Write(Message* aMsg, const paramType& aParam)
   {
     aMsg->WriteBytes(&aParam, sizeof(aParam));
   }
 
   static bool Read(const Message* aMsg, void** aIter, paramType* aResult)
   {
--- a/widget/windows/nsWindow.cpp
+++ b/widget/windows/nsWindow.cpp
@@ -6756,25 +6756,25 @@ LRESULT nsWindow::OnKeyDown(const MSG &a
             charForOEMKeyCode != unshiftedLatinChar &&
             charForOEMKeyCode != shiftedLatinChar) {
           nsAlternativeCharCode OEMChars(charForOEMKeyCode, charForOEMKeyCode);
           altArray.AppendElement(OEMChars);
         }
       }
 
       nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
-      keypressEvent.mFlags |= extraFlags;
+      keypressEvent.mFlags.Union(extraFlags);
       keypressEvent.charCode = uniChar;
       keypressEvent.alternativeCharCodes.AppendElements(altArray);
       InitKeyEvent(keypressEvent, nativeKey, modKeyState);
       DispatchKeyEvent(keypressEvent, nullptr);
     }
   } else {
     nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
-    keypressEvent.mFlags |= extraFlags;
+    keypressEvent.mFlags.Union(extraFlags);
     keypressEvent.keyCode = DOMKeyCode;
     InitKeyEvent(keypressEvent, nativeKey, aModKeyState);
     DispatchKeyEvent(keypressEvent, nullptr);
   }
 
   return noDefault;
 }
 
@@ -6869,17 +6869,17 @@ LRESULT nsWindow::OnChar(const MSG &aMsg
   // pressed too.
   if (!modKeyState.IsShift() &&
       (aModKeyState.IsAlt() || aModKeyState.IsControl())) {
     uniChar = towlower(uniChar);
   }
 
   nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
   if (aExtraFlags) {
-    keypressEvent.mFlags |= *aExtraFlags;
+    keypressEvent.mFlags.Union(*aExtraFlags);
   }
   keypressEvent.charCode = uniChar;
   if (!keypressEvent.charCode) {
     keypressEvent.keyCode = aNativeKey.GetDOMKeyCode();
   }
   InitKeyEvent(keypressEvent, aNativeKey, modKeyState);
   bool result = DispatchKeyEvent(keypressEvent, &aMsg);
   if (aEventDispatched)