From d9d3b687b7c892b400e781dd5c57897efd7173aa Mon Sep 17 00:00:00 2001 From: janekptacijarabaci Date: Mon, 23 Apr 2018 11:54:06 +0200 Subject: moebius#195: DOM - PointerEvent - improvements https://github.com/MoonchildProductions/moebius/pull/195 --- dom/events/Event.cpp | 19 ++++++ dom/events/test/pointerevents/mochitest.ini | 18 ++--- .../test_trigger_fullscreen_by_pointer_events.html | 57 ++++++++++++++++ .../test_trigger_popup_by_pointer_events.html | 76 ++++++++++++++++++++++ layout/base/nsPresShell.cpp | 2 + modules/libpref/init/all.js | 2 +- testing/marionette/element.js | 16 ++++- testing/marionette/error.js | 21 ++++-- .../marionette_harness/tests/unit/test_click.py | 17 +++++ testing/marionette/test_error.js | 20 ++++-- 10 files changed, 228 insertions(+), 20 deletions(-) create mode 100644 dom/events/test/pointerevents/test_trigger_fullscreen_by_pointer_events.html create mode 100644 dom/events/test/pointerevents/test_trigger_popup_by_pointer_events.html diff --git a/dom/events/Event.cpp b/dom/events/Event.cpp index 2546a81adc..7e19cd74d8 100755 --- a/dom/events/Event.cpp +++ b/dom/events/Event.cpp @@ -855,6 +855,25 @@ Event::GetEventPopupControlState(WidgetEvent* aEvent, nsIDOMEvent* aDOMEvent) } } break; + case ePointerEventClass: + if (aEvent->IsTrusted() && + aEvent->AsPointerEvent()->button == WidgetMouseEvent::eLeftButton) { + switch(aEvent->mMessage) { + case ePointerUp: + if (PopupAllowedForEvent("pointerup")) { + abuse = openControlled; + } + break; + case ePointerDown: + if (PopupAllowedForEvent("pointerdown")) { + abuse = openControlled; + } + break; + default: + break; + } + } + break; case eFormEventClass: // For these following events only allow popups if they're // triggered while handling user input. See diff --git a/dom/events/test/pointerevents/mochitest.ini b/dom/events/test/pointerevents/mochitest.ini index 5de7f27ea1..af762feb2c 100644 --- a/dom/events/test/pointerevents/mochitest.ini +++ b/dom/events/test/pointerevents/mochitest.ini @@ -6,6 +6,14 @@ support-files = pointerevent_styles.css pointerevent_support.js +[test_bug1285128.html] +[test_bug1293174_implicit_pointer_capture_for_touch_1.html] + support-files = bug1293174_implicit_pointer_capture_for_touch_1.html +[test_bug1293174_implicit_pointer_capture_for_touch_2.html] + support-files = bug1293174_implicit_pointer_capture_for_touch_2.html +[test_bug1323158.html] +[test_empty_file.html] + disabled = disabled # Bug 1150091 - Issue with support-files [test_pointerevent_attributes_mouse-manual.html] support-files = pointerevent_attributes_mouse-manual.html [test_pointerevent_capture_mouse-manual.html] @@ -143,11 +151,5 @@ support-files = pointerevent_touch-action-span-test_touch-manual.html pointerevent_touch-action-svg-test_touch-manual.html pointerevent_touch-action-table-test_touch-manual.html -[test_bug1285128.html] -[test_bug1293174_implicit_pointer_capture_for_touch_1.html] - support-files = bug1293174_implicit_pointer_capture_for_touch_1.html -[test_bug1293174_implicit_pointer_capture_for_touch_2.html] - support-files = bug1293174_implicit_pointer_capture_for_touch_2.html -[test_bug1323158.html] -[test_empty_file.html] - disabled = disabled # Bug 1150091 - Issue with support-files +[test_trigger_fullscreen_by_pointer_events.html] +[test_trigger_popup_by_pointer_events.html] diff --git a/dom/events/test/pointerevents/test_trigger_fullscreen_by_pointer_events.html b/dom/events/test/pointerevents/test_trigger_fullscreen_by_pointer_events.html new file mode 100644 index 0000000000..53d3909965 --- /dev/null +++ b/dom/events/test/pointerevents/test_trigger_fullscreen_by_pointer_events.html @@ -0,0 +1,57 @@ + + + + + Test for triggering Fullscreen by pointer events + + + + + + + + diff --git a/dom/events/test/pointerevents/test_trigger_popup_by_pointer_events.html b/dom/events/test/pointerevents/test_trigger_popup_by_pointer_events.html new file mode 100644 index 0000000000..cda279e265 --- /dev/null +++ b/dom/events/test/pointerevents/test_trigger_popup_by_pointer_events.html @@ -0,0 +1,76 @@ + + + + + Test for triggering popup by pointer events + + + + + +
+ + + diff --git a/layout/base/nsPresShell.cpp b/layout/base/nsPresShell.cpp index 63dfbd8a39..42b39c8607 100644 --- a/layout/base/nsPresShell.cpp +++ b/layout/base/nsPresShell.cpp @@ -8191,6 +8191,8 @@ PresShell::HandleEventInternal(WidgetEvent* aEvent, } case eMouseDown: case eMouseUp: + case ePointerDown: + case ePointerUp: isHandlingUserInput = true; break; diff --git a/modules/libpref/init/all.js b/modules/libpref/init/all.js index ccc59269b4..f2f628324f 100644 --- a/modules/libpref/init/all.js +++ b/modules/libpref/init/all.js @@ -1161,7 +1161,7 @@ pref("dom.require_user_interaction_for_beforeunload", true); pref("dom.disable_open_during_load", false); pref("dom.popup_maximum", 20); -pref("dom.popup_allowed_events", "change click dblclick mouseup notificationclick reset submit touchend"); +pref("dom.popup_allowed_events", "change click dblclick mouseup pointerup notificationclick reset submit touchend"); pref("dom.disable_open_click_delay", 1000); pref("dom.storage.enabled", true); diff --git a/testing/marionette/element.js b/testing/marionette/element.js index 8e66ee6df9..9687fb27d4 100644 --- a/testing/marionette/element.js +++ b/testing/marionette/element.js @@ -953,6 +953,12 @@ element.getContainer = function (el) { * pointer-interactable, if it is found somewhere in the * |elementsFromPoint| list at |el|'s in-view centre coordinates. * + * Before running the check, we change |el|'s pointerEvents style property + * to "auto", since elements without pointer events enabled do not turn + * up in the paint tree we get from document.elementsFromPoint. This is + * a specialisation that is only relevant when checking if the element is + * in view. + * * @param {Element} el * Element to check if is in view. * @@ -960,8 +966,14 @@ element.getContainer = function (el) { * True if |el| is inside the viewport, or false otherwise. */ element.isInView = function (el) { - let tree = element.getPointerInteractablePaintTree(el); - return tree.includes(el); + let originalPointerEvents = el.style.pointerEvents; + try { + el.style.pointerEvents = "auto"; + const tree = element.getPointerInteractablePaintTree(el); + return tree.includes(el); + } finally { + el.style.pointerEvents = originalPointerEvents; + } }; /** diff --git a/testing/marionette/error.js b/testing/marionette/error.js index 97cc3fb258..c36dace256 100644 --- a/testing/marionette/error.js +++ b/testing/marionette/error.js @@ -260,10 +260,23 @@ class ElementClickInterceptedError extends WebDriverError { if (obscuredEl && coords) { const doc = obscuredEl.ownerDocument; const overlayingEl = doc.elementFromPoint(coords.x, coords.y); - msg = error.pprint`Element ${obscuredEl} is not clickable ` + - `at point (${coords.x},${coords.y}) ` + - error.pprint`because another element ${overlayingEl} ` + - `obscures it`; + + switch (obscuredEl.style.pointerEvents) { + case "none": + msg = error.pprint`Element ${obscuredEl} is not clickable ` + + `at point (${coords.x},${coords.y}) ` + + `because it does not have pointer events enabled, ` + + error.pprint`and element ${overlayingEl} ` + + `would receive the click instead`; + break; + + default: + msg = error.pprint`Element ${obscuredEl} is not clickable ` + + `at point (${coords.x},${coords.y}) ` + + error.pprint`because another element ${overlayingEl} ` + + `obscures it`; + break; + } } super(msg); diff --git a/testing/marionette/harness/marionette_harness/tests/unit/test_click.py b/testing/marionette/harness/marionette_harness/tests/unit/test_click.py index d03062e85f..06019834a3 100644 --- a/testing/marionette/harness/marionette_harness/tests/unit/test_click.py +++ b/testing/marionette/harness/marionette_harness/tests/unit/test_click.py @@ -252,3 +252,20 @@ class TestClick(TestLegacyClick): with self.assertRaises(errors.ElementClickInterceptedException): obscured.click() self.assertFalse(self.marionette.execute_script("return window.clicked", sandbox=None)) + + def test_pointer_events_none(self): + self.marionette.navigate(inline(""" + + + """)) + button = self.marionette.find_element(By.TAG_NAME, "button") + self.assertEqual("none", button.value_of_css_property("pointer-events")) + + with self.assertRaisesRegexp(errors.ElementClickInterceptedException, + "does not have pointer events enabled"): + button.click() + self.assertFalse(self.marionette.execute_script("return window.clicked", sandbox=None)) diff --git a/testing/marionette/test_error.js b/testing/marionette/test_error.js index f272126373..a905f02f06 100644 --- a/testing/marionette/test_error.js +++ b/testing/marionette/test_error.js @@ -209,15 +209,25 @@ add_test(function test_ElementClickInterceptedError() { return otherEl; }, }, + style: { + pointerEvents: "auto", + } }; - let err = new ElementClickInterceptedError(obscuredEl, {x: 1, y: 2}); - equal("ElementClickInterceptedError", err.name); + let err1 = new ElementClickInterceptedError(obscuredEl, {x: 1, y: 2}); + equal("ElementClickInterceptedError", err1.name); equal("Element is not clickable at point (1,2) " + "because another element obscures it", - err.message); - equal("element click intercepted", err.status); - ok(err instanceof WebDriverError); + err1.message); + equal("element click intercepted", err1.status); + ok(err1 instanceof WebDriverError); + + obscuredEl.style.pointerEvents = "none"; + let err2 = new ElementClickInterceptedError(obscuredEl, {x: 1, y: 2}); + equal("Element is not clickable at point (1,2) " + + "because it does not have pointer events enabled, " + + "and element would receive the click instead", + err2.message); run_next_test(); }); -- cgit v1.2.3