Permalink
Browse files

Bug 822866 Make mozilla::widget::BaseEventFlags which is a POD struct…

… for VC r=smaug
  • Loading branch information...
1 parent 7edd5df commit 7502bbe310db93cec6d3993e0b83bed38d174bf1 @masayuki-nakano masayuki-nakano committed Dec 28, 2012
@@ -1616,7 +1616,7 @@ Element::DispatchClickEvent(nsPresContext* aPresContext,
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);
@@ -203,7 +203,6 @@ HTMLLabelElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
// 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),
@@ -207,7 +207,7 @@ sendKeyEventWithMsg(uint32_t keyCode,
event.keyCode = keyCode;
event.location = nsIDOMKeyEvent::DOM_KEY_LOCATION_MOBILE;
event.time = timeMs;
- event.mFlags |= flags;
+ event.mFlags.Union(flags);
return nsWindow::DispatchInputEvent(event);
}
View
@@ -468,7 +468,12 @@ enum nsWindowZ {
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
@@ -538,47 +543,49 @@ struct EventFlags
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
- {
- EventFlags flags;
- flags.SetRawFlags(GetRawFlags() | aOther.GetRawFlags());
- return flags;
- }
- inline EventFlags& operator|=(const EventFlags& aOther)
+ // 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)
{
- 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
@@ -598,6 +605,7 @@ class nsEvent
userType(0)
{
MOZ_COUNT_CTOR(nsEvent);
+ mFlags.Clear();
mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
@@ -618,6 +626,7 @@ class nsEvent
userType(0)
{
MOZ_COUNT_CTOR(nsEvent);
+ mFlags.Clear();
mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
@@ -646,8 +655,8 @@ class nsEvent
// 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;
View
@@ -14,9 +14,9 @@ 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)
{
@@ -6761,15 +6761,15 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
}
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);
@@ -6874,7 +6874,7 @@ LRESULT nsWindow::OnChar(const MSG &aMsg,
nsKeyEvent keypressEvent(true, NS_KEY_PRESS, this);
if (aExtraFlags) {
- keypressEvent.mFlags |= *aExtraFlags;
+ keypressEvent.mFlags.Union(*aExtraFlags);
}
keypressEvent.charCode = uniChar;
if (!keypressEvent.charCode) {

0 comments on commit 7502bbe

Please sign in to comment.