diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2019-11-05 02:43:19 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-11-05 02:43:19 -0500 |
commit | 28dbbda5bb0736b4f8f6c5c08a8bc268496f5422 (patch) | |
tree | 85d73ed4f475e74965a29370aec97cbd68c9d750 | |
parent | 2aca5c82e475b41da24adc7899423bbcb0966b32 (diff) | |
parent | 38b91c3501ce460dad52432a3cb2d4a859b04662 (diff) | |
download | servo-28dbbda5bb0736b4f8f6c5c08a8bc268496f5422.tar.gz servo-28dbbda5bb0736b4f8f6c5c08a8bc268496f5422.zip |
Auto merge of #24521 - tigleym:missing_cssom_attributes, r=jdm
Implement MouseEvent's x/y and offsetX/offsetY attributes
<!-- Please describe your changes on the following line: -->
Implement MouseEvent's x/y and offsetX/offsetY attributes
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: -->
- [X] `./mach build -d` does not report any errors
- [X] `./mach test-tidy` does not report any errors
- [ ] These changes fix #24248 (GitHub issue number if applicable)
<!-- Either: -->
- [X] There are tests for these changes OR
- [ ] These changes do not require tests because ___
<!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.-->
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
-rw-r--r-- | components/script/dom/mouseevent.rs | 60 | ||||
-rw-r--r-- | components/script/dom/webidls/MouseEvent.webidl | 4 | ||||
-rw-r--r-- | tests/wpt/metadata/MANIFEST.json | 2 | ||||
-rw-r--r-- | tests/wpt/metadata/css/cssom-view/idlharness.html.ini | 24 | ||||
-rw-r--r-- | tests/wpt/metadata/css/cssom-view/mouseEvent.html.ini | 4 | ||||
-rw-r--r-- | tests/wpt/web-platform-tests/css/cssom-view/mouseEvent.html | 9 |
6 files changed, 74 insertions, 29 deletions
diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs index 48600f1155e..b6ba307af52 100644 --- a/components/script/dom/mouseevent.rs +++ b/components/script/dom/mouseevent.rs @@ -2,6 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use crate::dom::bindings::codegen::Bindings::EventBinding::EventBinding::EventMethods; use crate::dom::bindings::codegen::Bindings::MouseEventBinding; use crate::dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods; use crate::dom::bindings::codegen::Bindings::UIEventBinding::UIEventMethods; @@ -12,6 +13,7 @@ use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::bindings::str::DOMString; use crate::dom::event::{Event, EventBubbles, EventCancelable}; use crate::dom::eventtarget::EventTarget; +use crate::dom::node::Node; use crate::dom::uievent::UIEvent; use crate::dom::window::Window; use dom_struct::dom_struct; @@ -29,6 +31,10 @@ pub struct MouseEvent { client_y: Cell<i32>, page_x: Cell<i32>, page_y: Cell<i32>, + x: Cell<i32>, + y: Cell<i32>, + offset_x: Cell<i32>, + offset_y: Cell<i32>, ctrl_key: Cell<bool>, shift_key: Cell<bool>, alt_key: Cell<bool>, @@ -49,6 +55,10 @@ impl MouseEvent { client_y: Cell::new(0), page_x: Cell::new(0), page_y: Cell::new(0), + x: Cell::new(0), + y: Cell::new(0), + offset_x: Cell::new(0), + offset_y: Cell::new(0), ctrl_key: Cell::new(false), shift_key: Cell::new(false), alt_key: Cell::new(false), @@ -192,6 +202,56 @@ impl MouseEventMethods for MouseEvent { } } + // https://drafts.csswg.org/cssom-view/#dom-mouseevent-x + fn X(&self) -> i32 { + self.client_x.get() + } + + // https://drafts.csswg.org/cssom-view/#dom-mouseevent-y + fn Y(&self) -> i32 { + self.client_y.get() + } + + // https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsetx + fn OffsetX(&self) -> i32 { + let event = self.upcast::<Event>(); + if event.dispatching() { + match event.GetTarget() { + Some(target) => { + if let Some(node) = target.downcast::<Node>() { + let rect = node.client_rect(); + self.client_x.get() - rect.origin.x + } else { + self.offset_x.get() + } + }, + None => self.offset_x.get(), + } + } else { + self.PageX() + } + } + + // https://drafts.csswg.org/cssom-view/#dom-mouseevent-offsety + fn OffsetY(&self) -> i32 { + let event = self.upcast::<Event>(); + if event.dispatching() { + match event.GetTarget() { + Some(target) => { + if let Some(node) = target.downcast::<Node>() { + let rect = node.client_rect(); + self.client_y.get() - rect.origin.y + } else { + self.offset_y.get() + } + }, + None => self.offset_y.get(), + } + } else { + self.PageY() + } + } + // https://w3c.github.io/uievents/#widl-MouseEvent-ctrlKey fn CtrlKey(&self) -> bool { self.ctrl_key.get() diff --git a/components/script/dom/webidls/MouseEvent.webidl b/components/script/dom/webidls/MouseEvent.webidl index 253463e7eae..0b7cb644368 100644 --- a/components/script/dom/webidls/MouseEvent.webidl +++ b/components/script/dom/webidls/MouseEvent.webidl @@ -12,6 +12,10 @@ interface MouseEvent : UIEvent { readonly attribute long clientY; readonly attribute long pageX; readonly attribute long pageY; + readonly attribute long x; + readonly attribute long y; + readonly attribute long offsetX; + readonly attribute long offsetY; readonly attribute boolean ctrlKey; readonly attribute boolean shiftKey; readonly attribute boolean altKey; diff --git a/tests/wpt/metadata/MANIFEST.json b/tests/wpt/metadata/MANIFEST.json index 99a4907821f..fe263de0516 100644 --- a/tests/wpt/metadata/MANIFEST.json +++ b/tests/wpt/metadata/MANIFEST.json @@ -616088,7 +616088,7 @@ "testharness" ], "css/cssom-view/mouseEvent.html": [ - "7e194b8909317806ff80e300cd480b31680a397e", + "d50959729239599ff057a71143553b4a53f88975", "testharness" ], "css/cssom-view/negativeMargins.html": [ diff --git a/tests/wpt/metadata/css/cssom-view/idlharness.html.ini b/tests/wpt/metadata/css/cssom-view/idlharness.html.ini index 0b7ddfcc064..e62f2ff3e12 100644 --- a/tests/wpt/metadata/css/cssom-view/idlharness.html.ini +++ b/tests/wpt/metadata/css/cssom-view/idlharness.html.ini @@ -128,12 +128,6 @@ [Range interface: operation getClientRects()] expected: FAIL - [MouseEvent interface: attribute y] - expected: FAIL - - [MouseEvent interface: attribute x] - expected: FAIL - [Element interface: calling scrollIntoView([object Object\],[object Object\]) on document.createElement("img") with too few arguments must throw TypeError] expected: FAIL @@ -251,12 +245,6 @@ [Element interface: calling convertRectFromNode(DOMRectReadOnly, GeometryNode, ConvertCoordinateOptions) on document.createElement("div") with too few arguments must throw TypeError] expected: FAIL - [MouseEvent interface: attribute offsetX] - expected: FAIL - - [MouseEvent interface: attribute offsetY] - expected: FAIL - [CSSPseudoElement interface: operation convertRectFromNode(DOMRectReadOnly, GeometryNode, ConvertCoordinateOptions)] expected: FAIL @@ -298,15 +286,3 @@ [Partial dictionary MouseEventInit: member names are unique] expected: FAIL - - [MouseEvent interface: new MouseEvent("foo") must inherit property "offsetY" with the proper type] - expected: FAIL - - [MouseEvent interface: new MouseEvent("foo") must inherit property "y" with the proper type] - expected: FAIL - - [MouseEvent interface: new MouseEvent("foo") must inherit property "x" with the proper type] - expected: FAIL - - [MouseEvent interface: new MouseEvent("foo") must inherit property "offsetX" with the proper type] - expected: FAIL diff --git a/tests/wpt/metadata/css/cssom-view/mouseEvent.html.ini b/tests/wpt/metadata/css/cssom-view/mouseEvent.html.ini deleted file mode 100644 index 4ed417f91fa..00000000000 --- a/tests/wpt/metadata/css/cssom-view/mouseEvent.html.ini +++ /dev/null @@ -1,4 +0,0 @@ -[mouseEvent.html] - [MouseEvent's x and y must be equal to clientX and clientY.] - expected: FAIL - diff --git a/tests/wpt/web-platform-tests/css/cssom-view/mouseEvent.html b/tests/wpt/web-platform-tests/css/cssom-view/mouseEvent.html index 7e194b89093..d5095972923 100644 --- a/tests/wpt/web-platform-tests/css/cssom-view/mouseEvent.html +++ b/tests/wpt/web-platform-tests/css/cssom-view/mouseEvent.html @@ -29,5 +29,14 @@ test(function () { assert_equals(mouseEvent2.pageX, 10); assert_equals(mouseEvent2.pageY, 5020); }, 'MouseEvent\'s pageX and pageY attributes should be the sum of the scroll offset and clientX/clientY'); + +test(function () { + var mouseEvent = new MouseEvent('mousedown', {clientX: 10, clientY: 20}); + assert_equals(mouseEvent.offsetX, mouseEvent.pageX); + assert_equals(mouseEvent.offsetY, mouseEvent.pageY); + scrollBy(0, 5000); + assert_equals(mouseEvent.offsetX, mouseEvent.pageX); + assert_equals(mouseEvent.offsetY, mouseEvent.pageY); +}, 'MouseEvent\'s offsetX/offsetY attributes should be the same value as its pageX/pageY attributes.'); </script> </head> |