Bug 822866 Make mozilla::widget::BaseEventFlags which is a POD struct for VC r=smaug

This commit is contained in:
Masayuki Nakano 2012-12-28 23:13:18 +09:00
parent 044f2bca27
commit aef542653e
6 changed files with 36 additions and 28 deletions

View File

@ -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);

View File

@ -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),

View File

@ -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 File

@ -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,29 +543,22 @@ public:
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:
@ -568,17 +566,26 @@ private:
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 @@ protected:
userType(0)
{
MOZ_COUNT_CTOR(nsEvent);
mFlags.Clear();
mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
@ -618,6 +626,7 @@ public:
userType(0)
{
MOZ_COUNT_CTOR(nsEvent);
mFlags.Clear();
mFlags.mIsTrusted = isTrusted;
mFlags.mCancelable = true;
mFlags.mBubbles = true;
@ -646,8 +655,8 @@ public:
// 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 File

@ -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)
{

View File

@ -6761,7 +6761,7 @@ 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);
@ -6769,7 +6769,7 @@ LRESULT nsWindow::OnKeyDown(const MSG &aMsg,
}
} 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) {