Bug 1298970 - Move UIEvent.cancelBubble to Event. r=smaug
authorStone Shih <sshih@mozilla.com>
Tue, 29 Nov 2016 10:28:21 +0800
changeset 324935 033d5532cac71ffdc9459fbf21f628448fac3b04
parent 324934 0a3b96cee2eaeeaabd71ce228c25d9d555e2e04a
child 324936 0dff674b449764433e5870121de42178c571825f
push id31023
push userkwierso@gmail.com
push dateThu, 01 Dec 2016 23:32:03 +0000
treeherdermozilla-central@b49684127ce4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs1298970
milestone53.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 1298970 - Move UIEvent.cancelBubble to Event. r=smaug MozReview-Commit-ID: JPc1JwfqpaZ
dom/events/Event.cpp
dom/events/Event.h
dom/events/UIEvent.cpp
dom/events/UIEvent.h
dom/events/test/mochitest.ini
dom/events/test/test_bug1298970.html
dom/interfaces/events/nsIDOMEvent.idl
dom/interfaces/events/nsIDOMUIEvent.idl
dom/webidl/Event.webidl
dom/webidl/UIEvent.webidl
--- a/dom/events/Event.cpp
+++ b/dom/events/Event.cpp
@@ -1250,16 +1250,31 @@ Event::GetShadowRelatedTarget(nsIContent
     }
 
     relatedTarget = ancestorShadow->GetHost();
   }
 
   return nullptr;
 }
 
+NS_IMETHODIMP
+Event::GetCancelBubble(bool* aCancelBubble)
+{
+  NS_ENSURE_ARG_POINTER(aCancelBubble);
+  *aCancelBubble = CancelBubble();
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+Event::SetCancelBubble(bool aCancelBubble)
+{
+  mEvent->mFlags.mPropagationStopped = aCancelBubble;
+  return NS_OK;
+}
+
 } // namespace dom
 } // namespace mozilla
 
 using namespace mozilla;
 using namespace mozilla::dom;
 
 already_AddRefed<Event>
 NS_NewDOMEvent(EventTarget* aOwner,
--- a/dom/events/Event.h
+++ b/dom/events/Event.h
@@ -171,16 +171,21 @@ public:
     return mEvent->mFlags.mCancelable;
   }
 
   bool Composed() const
   {
     return mEvent->mFlags.mComposed;
   }
 
+  bool CancelBubble() const
+  {
+    return mEvent->PropagationStopped();
+  }
+
   // xpidl implementation
   // void PreventDefault();
 
   // You MUST NOT call PreventDefault(JSContext*, CallerType) from C++ code.  A
   // call of this method always sets Event.defaultPrevented true for web
   // contents.  If default action handler calls this, web applications see wrong
   // defaultPrevented value.
   virtual void PreventDefault(JSContext* aCx, CallerType aCallerType);
@@ -378,17 +383,19 @@ private:
   NS_IMETHOD GetExplicitOriginalTarget(nsIDOMEventTarget** aExplicitOriginalTarget) override { return _to GetExplicitOriginalTarget(aExplicitOriginalTarget); } \
   NS_IMETHOD GetPreventDefault(bool* aRetval) override { return _to GetPreventDefault(aRetval); } \
   NS_IMETHOD GetIsTrusted(bool* aIsTrusted) override { return _to GetIsTrusted(aIsTrusted); } \
   NS_IMETHOD SetTarget(nsIDOMEventTarget* aTarget) override { return _to SetTarget(aTarget); } \
   NS_IMETHOD_(bool) IsDispatchStopped(void) override { return _to IsDispatchStopped(); } \
   NS_IMETHOD_(WidgetEvent*) WidgetEventPtr(void) override { return _to WidgetEventPtr(); } \
   NS_IMETHOD_(void) SetTrusted(bool aTrusted) override { _to SetTrusted(aTrusted); } \
   NS_IMETHOD_(void) SetOwner(EventTarget* aOwner) override { _to SetOwner(aOwner); } \
-  NS_IMETHOD_(Event*) InternalDOMEvent() override { return _to InternalDOMEvent(); }
+  NS_IMETHOD_(Event*) InternalDOMEvent() override { return _to InternalDOMEvent(); } \
+  NS_IMETHOD GetCancelBubble(bool* aCancelBubble) override { return _to GetCancelBubble(aCancelBubble); } \
+  NS_IMETHOD SetCancelBubble(bool aCancelBubble) override { return _to SetCancelBubble(aCancelBubble); }
 
 #define NS_FORWARD_TO_EVENT_NO_SERIALIZATION_NO_DUPLICATION \
   NS_FORWARD_NSIDOMEVENT_NO_SERIALIZATION_NO_DUPLICATION(Event::) \
   virtual void PreventDefault(JSContext* aCx, CallerType aCallerType) override { Event::PreventDefault(aCx, aCallerType); }
 
 inline nsISupports*
 ToSupports(mozilla::dom::Event* e)
 {
--- a/dom/events/UIEvent.cpp
+++ b/dom/events/UIEvent.cpp
@@ -283,31 +283,16 @@ UIEvent::RangeOffset() const
     return 0;
   }
 
   nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(mEvent,
                                                             targetFrame);
   return targetFrame->GetContentOffsetsFromPoint(pt).offset;
 }
 
-NS_IMETHODIMP
-UIEvent::GetCancelBubble(bool* aCancelBubble)
-{
-  NS_ENSURE_ARG_POINTER(aCancelBubble);
-  *aCancelBubble = CancelBubble();
-  return NS_OK;
-}
-
-NS_IMETHODIMP
-UIEvent::SetCancelBubble(bool aCancelBubble)
-{
-  mEvent->mFlags.mPropagationStopped = aCancelBubble;
-  return NS_OK;
-}
-
 nsIntPoint
 UIEvent::GetLayerPoint() const
 {
   if (!mEvent ||
       (mEvent->mClass != eMouseEventClass &&
        mEvent->mClass != eMouseScrollEventClass &&
        mEvent->mClass != eWheelEventClass &&
        mEvent->mClass != ePointerEventClass &&
--- a/dom/events/UIEvent.h
+++ b/dom/events/UIEvent.h
@@ -88,21 +88,16 @@ public:
                "Mouse events should override Which()");
     return 0;
   }
 
   already_AddRefed<nsINode> GetRangeParent();
 
   int32_t RangeOffset() const;
 
-  bool CancelBubble() const
-  {
-    return mEvent->PropagationStopped();
-  }
-
   bool IsChar() const;
 
 protected:
   ~UIEvent() {}
 
   // Internal helper functions
   nsIntPoint GetMovementPoint();
   nsIntPoint GetLayerPoint() const;
--- a/dom/events/test/mochitest.ini
+++ b/dom/events/test/mochitest.ini
@@ -179,8 +179,9 @@ skip-if = toolkit == 'android' #CRASH_DU
 [test_moz_mouse_pixel_scroll_event.html]
 [test_offsetxy.html]
 [test_onerror_handler_args.html]
 [test_passive_listeners.html]
 [test_paste_image.html]
 [test_wheel_default_action.html]
 [test_bug687787.html]
 [test_bug1305458.html]
+[test_bug1298970.html]
new file mode 100644
--- /dev/null
+++ b/dom/events/test/test_bug1298970.html
@@ -0,0 +1,33 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1298970
+-->
+<head>
+  <title>Test for Bug 1298970</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1298970">Mozilla Bug 1298970</a>
+<p id="display"></p>
+<div id="inner"></div>
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 1298970 **/
+var target = document.getElementById("inner");
+var event = new Event("test", { bubbles: true, cancelable: true });
+
+is(event.cancelBubble, false, "Event.cancelBubble should be false by default");
+
+target.addEventListener("test", (e) => {
+  e.stopPropagation();
+  is(e.cancelBubble, true, "Event.cancelBubble should be true after stopPropagation");
+}, true);
+
+target.dispatchEvent(event);
+
+</script>
+</body>
+</html>
+
--- a/dom/interfaces/events/nsIDOMEvent.idl
+++ b/dom/interfaces/events/nsIDOMEvent.idl
@@ -200,16 +200,17 @@ interface nsIDOMEvent : nsISupports
 
   /**
    * @deprecated Use nsIDOMEvent::defaultPrevented.
    * To be removed in bug 691151.
    */
   boolean                   getPreventDefault();
 
   readonly attribute boolean isTrusted;
+  attribute boolean cancelBubble;
 
   [noscript] void duplicatePrivateData();
   [noscript] void setTarget(in nsIDOMEventTarget aTarget);
   [notxpcom] boolean IsDispatchStopped();
   [notxpcom] WidgetEvent WidgetEventPtr();
   [noscript,notxpcom] void SetTrusted(in boolean aTrusted);
   [notxpcom] void Serialize(in IPCMessagePtr aMsg,
                             in boolean aSerializeInterfaceType);
--- a/dom/interfaces/events/nsIDOMUIEvent.idl
+++ b/dom/interfaces/events/nsIDOMUIEvent.idl
@@ -44,14 +44,12 @@ interface nsIDOMUIEvent : nsISupports
   readonly attribute long               layerX;
   readonly attribute long               layerY;
   readonly attribute long               pageX;
   readonly attribute long               pageY;
   readonly attribute unsigned long      which;
   readonly attribute nsIDOMNode         rangeParent;
   readonly attribute long               rangeOffset;
 
-           attribute boolean            cancelBubble;
-
   readonly attribute boolean            isChar;
 
   [notxpcom, nostdcall] EventPtr AsEvent();
 };
--- a/dom/webidl/Event.webidl
+++ b/dom/webidl/Event.webidl
@@ -46,31 +46,31 @@ interface Event {
   readonly attribute boolean composed;
 
   [Unforgeable, Pure]
   readonly attribute boolean isTrusted;
   [Pure]
   readonly attribute DOMHighResTimeStamp timeStamp;
 
   void initEvent(DOMString type, boolean bubbles, boolean cancelable);
+  attribute boolean cancelBubble;
 };
 
 // Mozilla specific legacy stuff.
 partial interface Event {
   const long ALT_MASK     = 0x00000001;
   const long CONTROL_MASK = 0x00000002;
   const long SHIFT_MASK   = 0x00000004;
   const long META_MASK    = 0x00000008;
 
   readonly attribute EventTarget? originalTarget;
   readonly attribute EventTarget? explicitOriginalTarget;
   [ChromeOnly] readonly attribute EventTarget? composedTarget;
   [ChromeOnly] readonly attribute boolean multipleActionsPrevented;
   [ChromeOnly] readonly attribute boolean isSynthesized;
-
   boolean getPreventDefault();
 };
 
 dictionary EventInit {
   boolean bubbles = false;
   boolean cancelable = false;
   boolean composed = false;
 };
--- a/dom/webidl/UIEvent.webidl
+++ b/dom/webidl/UIEvent.webidl
@@ -29,17 +29,16 @@ partial interface UIEvent {
 
   readonly attribute long          layerX;
   readonly attribute long          layerY;
   readonly attribute long          pageX;
   readonly attribute long          pageY;
   readonly attribute unsigned long which;
   readonly attribute Node?         rangeParent;
   readonly attribute long          rangeOffset;
-           attribute boolean       cancelBubble;
   readonly attribute boolean       isChar;
 };
 
 dictionary UIEventInit : EventInit
 {
   Window? view = null;
   long    detail = 0;
 };