aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/mouseevent.rs
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-10-19 02:36:32 -0500
committerGitHub <noreply@github.com>2017-10-19 02:36:32 -0500
commit4cf2ce66fc4f970a47ab1fb4b9aa1a55282640f7 (patch)
tree5a2b8abbb10747ede96a7d7f234569bf9c9fec8c /components/script/dom/mouseevent.rs
parent77a47171563fdb3a38dd75f8c58909c9647cb708 (diff)
parent2e2ed444d597904ed0b6d7f4eade2747d75021a6 (diff)
downloadservo-4cf2ce66fc4f970a47ab1fb4b9aa1a55282640f7.tar.gz
servo-4cf2ce66fc4f970a47ab1fb4b9aa1a55282640f7.zip
Auto merge of #18933 - mrobinson:wr-text-index, r=jdm
Use WebRender to compute text index on click events This is the second half of switching over to WebRender for hit testing. Now that WebRender gives us the location of the hit tested point in the display item, we can use that to calculate text index. <!-- Please describe your changes on the following line: --> --- <!-- 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 #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [x] These changes do not require tests because they shouldn't change behavior. <!-- 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. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/18933) <!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/mouseevent.rs')
-rw-r--r--components/script/dom/mouseevent.rs111
1 files changed, 64 insertions, 47 deletions
diff --git a/components/script/dom/mouseevent.rs b/components/script/dom/mouseevent.rs
index 7e6fbd52eb8..62ec6f16ed3 100644
--- a/components/script/dom/mouseevent.rs
+++ b/components/script/dom/mouseevent.rs
@@ -15,6 +15,7 @@ use dom::eventtarget::EventTarget;
use dom::uievent::UIEvent;
use dom::window::Window;
use dom_struct::dom_struct;
+use euclid::Point2D;
use servo_config::prefs::PREFS;
use std::cell::Cell;
use std::default::Default;
@@ -32,6 +33,7 @@ pub struct MouseEvent {
meta_key: Cell<bool>,
button: Cell<i16>,
related_target: MutNullableDom<EventTarget>,
+ point_in_target: Cell<Option<Point2D<f32>>>
}
impl MouseEvent {
@@ -48,6 +50,7 @@ impl MouseEvent {
meta_key: Cell::new(false),
button: Cell::new(0),
related_target: Default::default(),
+ point_in_target: Cell::new(None),
}
}
@@ -57,28 +60,34 @@ impl MouseEvent {
MouseEventBinding::Wrap)
}
- pub fn new(window: &Window,
- type_: DOMString,
- can_bubble: EventBubbles,
- cancelable: EventCancelable,
- view: Option<&Window>,
- detail: i32,
- screen_x: i32,
- screen_y: i32,
- client_x: i32,
- client_y: i32,
- ctrl_key: bool,
- alt_key: bool,
- shift_key: bool,
- meta_key: bool,
- button: i16,
- related_target: Option<&EventTarget>) -> DomRoot<MouseEvent> {
+ pub fn new(
+ window: &Window,
+ type_: DOMString,
+ can_bubble: EventBubbles,
+ cancelable: EventCancelable,
+ view: Option<&Window>,
+ detail: i32,
+ screen_x: i32,
+ screen_y: i32,
+ client_x: i32,
+ client_y: i32,
+ ctrl_key: bool,
+ alt_key: bool,
+ shift_key: bool,
+ meta_key: bool,
+ button: i16,
+ related_target: Option<&EventTarget>,
+ point_in_target: Option<Point2D<f32>>
+ ) -> DomRoot<MouseEvent> {
let ev = MouseEvent::new_uninitialized(window);
- ev.InitMouseEvent(type_, bool::from(can_bubble), bool::from(cancelable),
- view, detail,
- screen_x, screen_y, client_x, client_y,
- ctrl_key, alt_key, shift_key, meta_key,
- button, related_target);
+ ev.InitMouseEvent(
+ type_, bool::from(can_bubble), bool::from(cancelable),
+ view, detail,
+ screen_x, screen_y, client_x, client_y,
+ ctrl_key, alt_key, shift_key, meta_key,
+ button, related_target,
+ );
+ ev.point_in_target.set(point_in_target);
ev
}
@@ -87,18 +96,24 @@ impl MouseEvent {
init: &MouseEventBinding::MouseEventInit) -> Fallible<DomRoot<MouseEvent>> {
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
- let event = MouseEvent::new(window,
- type_,
- bubbles,
- cancelable,
- init.parent.parent.view.r(),
- init.parent.parent.detail,
- init.screenX, init.screenY,
- init.clientX, init.clientY, init.parent.ctrlKey,
- init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
- init.button, init.relatedTarget.r());
+ let event = MouseEvent::new(
+ window,
+ type_,
+ bubbles,
+ cancelable,
+ init.parent.parent.view.r(),
+ init.parent.parent.detail,
+ init.screenX, init.screenY,
+ init.clientX, init.clientY, init.parent.ctrlKey,
+ init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
+ init.button, init.relatedTarget.r(), None
+ );
Ok(event)
}
+
+ pub fn point_in_target(&self) -> Option<Point2D<f32>> {
+ self.point_in_target.get()
+ }
}
impl MouseEventMethods for MouseEvent {
@@ -166,22 +181,24 @@ impl MouseEventMethods for MouseEvent {
}
// https://w3c.github.io/uievents/#widl-MouseEvent-initMouseEvent
- fn InitMouseEvent(&self,
- type_arg: DOMString,
- can_bubble_arg: bool,
- cancelable_arg: bool,
- view_arg: Option<&Window>,
- detail_arg: i32,
- screen_x_arg: i32,
- screen_y_arg: i32,
- client_x_arg: i32,
- client_y_arg: i32,
- ctrl_key_arg: bool,
- alt_key_arg: bool,
- shift_key_arg: bool,
- meta_key_arg: bool,
- button_arg: i16,
- related_target_arg: Option<&EventTarget>) {
+ fn InitMouseEvent(
+ &self,
+ type_arg: DOMString,
+ can_bubble_arg: bool,
+ cancelable_arg: bool,
+ view_arg: Option<&Window>,
+ detail_arg: i32,
+ screen_x_arg: i32,
+ screen_y_arg: i32,
+ client_x_arg: i32,
+ client_y_arg: i32,
+ ctrl_key_arg: bool,
+ alt_key_arg: bool,
+ shift_key_arg: bool,
+ meta_key_arg: bool,
+ button_arg: i16,
+ related_target_arg: Option<&EventTarget>,
+ ) {
if self.upcast::<Event>().dispatching() {
return;
}