mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-15 22:35:43 +00:00
servo: Merge #18933 - Use WebRender to compute text index on click events (from mrobinson:wr-text-index); r=jdm
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. --> Source-Repo: https://github.com/servo/servo Source-Revision: 4cf2ce66fc4f970a47ab1fb4b9aa1a55282640f7 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : 365f452e9e708080adbbfe4b09ccd2dafeb3eb75
This commit is contained in:
parent
e14412541c
commit
54e8de2b45
@ -702,20 +702,20 @@ impl<Window: WindowMethods> IOCompositor<Window> {
|
|||||||
None => return,
|
None => return,
|
||||||
};
|
};
|
||||||
|
|
||||||
let point = result.point_in_viewport.to_untyped();
|
let (button, event_type) = match mouse_window_event {
|
||||||
let node_address = Some(UntrustedNodeAddress(result.tag.0 as *const c_void));
|
MouseWindowEvent::Click(button, _) => (button, MouseEventType::Click),
|
||||||
let event_to_send = match mouse_window_event {
|
MouseWindowEvent::MouseDown(button, _) => (button, MouseEventType::MouseDown),
|
||||||
MouseWindowEvent::Click(button, _) => {
|
MouseWindowEvent::MouseUp(button, _) => (button, MouseEventType::MouseUp),
|
||||||
MouseButtonEvent(MouseEventType::Click, button, point, node_address)
|
|
||||||
}
|
|
||||||
MouseWindowEvent::MouseDown(button, _) => {
|
|
||||||
MouseButtonEvent(MouseEventType::MouseDown, button, point, node_address)
|
|
||||||
}
|
|
||||||
MouseWindowEvent::MouseUp(button, _) => {
|
|
||||||
MouseButtonEvent(MouseEventType::MouseUp, button, point, node_address)
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let event_to_send = MouseButtonEvent(
|
||||||
|
event_type,
|
||||||
|
button,
|
||||||
|
result.point_in_viewport.to_untyped(),
|
||||||
|
Some(UntrustedNodeAddress(result.tag.0 as *const c_void)),
|
||||||
|
Some(result.point_relative_to_item.to_untyped()),
|
||||||
|
);
|
||||||
|
|
||||||
let pipeline_id = PipelineId::from_webrender(result.pipeline);
|
let pipeline_id = PipelineId::from_webrender(result.pipeline);
|
||||||
let msg = ConstellationMsg::ForwardEvent(pipeline_id, event_to_send);
|
let msg = ConstellationMsg::ForwardEvent(pipeline_id, event_to_send);
|
||||||
if let Err(e) = self.constellation_chan.send(msg) {
|
if let Err(e) = self.constellation_chan.send(msg) {
|
||||||
|
@ -48,74 +48,6 @@ pub struct DisplayList {
|
|||||||
pub list: Vec<DisplayItem>,
|
pub list: Vec<DisplayItem>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ScrollOffsetLookup<'a> {
|
|
||||||
parents: &'a mut HashMap<ClipId, ClipId>,
|
|
||||||
calculated_total_offsets: ScrollOffsetMap,
|
|
||||||
raw_offsets: &'a ScrollOffsetMap,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> ScrollOffsetLookup<'a> {
|
|
||||||
fn new(parents: &'a mut HashMap<ClipId, ClipId>,
|
|
||||||
raw_offsets: &'a ScrollOffsetMap)
|
|
||||||
-> ScrollOffsetLookup<'a> {
|
|
||||||
ScrollOffsetLookup {
|
|
||||||
parents: parents,
|
|
||||||
calculated_total_offsets: HashMap::new(),
|
|
||||||
raw_offsets: raw_offsets,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn new_for_reference_frame(&mut self,
|
|
||||||
clip_id: ClipId,
|
|
||||||
transform: &Transform3D<f32>,
|
|
||||||
point: &mut Point2D<Au>)
|
|
||||||
-> Option<ScrollOffsetLookup> {
|
|
||||||
// If a transform function causes the current transformation matrix of an object
|
|
||||||
// to be non-invertible, the object and its content do not get displayed.
|
|
||||||
let inv_transform = match transform.inverse() {
|
|
||||||
Some(transform) => transform,
|
|
||||||
None => return None,
|
|
||||||
};
|
|
||||||
|
|
||||||
let scroll_offset = self.full_offset_for_clip_scroll_node(&clip_id);
|
|
||||||
*point = Point2D::new(point.x - Au::from_f32_px(scroll_offset.x),
|
|
||||||
point.y - Au::from_f32_px(scroll_offset.y));
|
|
||||||
let frac_point = inv_transform.transform_point2d(&Point2D::new(point.x.to_f32_px(),
|
|
||||||
point.y.to_f32_px()));
|
|
||||||
*point = Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y));
|
|
||||||
|
|
||||||
let mut sublookup = ScrollOffsetLookup {
|
|
||||||
parents: &mut self.parents,
|
|
||||||
calculated_total_offsets: HashMap::new(),
|
|
||||||
raw_offsets: self.raw_offsets,
|
|
||||||
};
|
|
||||||
sublookup.calculated_total_offsets.insert(clip_id, Vector2D::zero());
|
|
||||||
Some(sublookup)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_clip_scroll_node(&mut self, clip_scroll_node: &ClipScrollNode) {
|
|
||||||
self.parents.insert(clip_scroll_node.id, clip_scroll_node.parent_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn full_offset_for_clip_scroll_node(&mut self, id: &ClipId) -> Vector2D<f32> {
|
|
||||||
if let Some(offset) = self.calculated_total_offsets.get(id) {
|
|
||||||
return *offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
let parent_offset = if !id.is_root_scroll_node() {
|
|
||||||
let parent_id = *self.parents.get(id).unwrap();
|
|
||||||
self.full_offset_for_clip_scroll_node(&parent_id)
|
|
||||||
} else {
|
|
||||||
Vector2D::zero()
|
|
||||||
};
|
|
||||||
|
|
||||||
let offset = parent_offset +
|
|
||||||
self.raw_offsets.get(id).cloned().unwrap_or_else(Vector2D::zero);
|
|
||||||
self.calculated_total_offsets.insert(*id, offset);
|
|
||||||
offset
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl DisplayList {
|
impl DisplayList {
|
||||||
/// Return the bounds of this display list based on the dimensions of the root
|
/// Return the bounds of this display list based on the dimensions of the root
|
||||||
/// stacking context.
|
/// stacking context.
|
||||||
@ -128,82 +60,22 @@ impl DisplayList {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the text index within a node for the point of interest.
|
// Returns the text index within a node for the point of interest.
|
||||||
pub fn text_index(&self,
|
pub fn text_index(&self, node: OpaqueNode, point_in_item: &Point2D<Au>) -> Option<usize> {
|
||||||
node: OpaqueNode,
|
for item in &self.list {
|
||||||
client_point: &Point2D<Au>,
|
|
||||||
scroll_offsets: &ScrollOffsetMap)
|
|
||||||
-> Option<usize> {
|
|
||||||
let mut result = Vec::new();
|
|
||||||
let mut traversal = DisplayListTraversal::new(self);
|
|
||||||
self.text_index_contents(node,
|
|
||||||
&mut traversal,
|
|
||||||
client_point,
|
|
||||||
&mut ScrollOffsetLookup::new(&mut HashMap::new(), scroll_offsets),
|
|
||||||
&mut result);
|
|
||||||
result.pop()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn text_index_contents<'a>(&self,
|
|
||||||
node: OpaqueNode,
|
|
||||||
traversal: &mut DisplayListTraversal<'a>,
|
|
||||||
point: &Point2D<Au>,
|
|
||||||
offset_lookup: &mut ScrollOffsetLookup,
|
|
||||||
result: &mut Vec<usize>) {
|
|
||||||
while let Some(item) = traversal.next() {
|
|
||||||
match item {
|
match item {
|
||||||
&DisplayItem::PushStackingContext(ref context_item) => {
|
|
||||||
self.text_index_stacking_context(&context_item.stacking_context,
|
|
||||||
item.scroll_node_id(),
|
|
||||||
node,
|
|
||||||
traversal,
|
|
||||||
point,
|
|
||||||
offset_lookup,
|
|
||||||
result);
|
|
||||||
}
|
|
||||||
&DisplayItem::DefineClipScrollNode(ref item) => {
|
|
||||||
offset_lookup.add_clip_scroll_node(&item.node);
|
|
||||||
}
|
|
||||||
&DisplayItem::PopStackingContext(_) => return,
|
|
||||||
&DisplayItem::Text(ref text) => {
|
&DisplayItem::Text(ref text) => {
|
||||||
let base = item.base();
|
let base = item.base();
|
||||||
if base.metadata.node == node {
|
if base.metadata.node == node {
|
||||||
let offset = *point - text.baseline_origin;
|
let point = *point_in_item + item.base().bounds.origin.to_vector();
|
||||||
let index = text.text_run.range_index_of_advance(&text.range, offset.x);
|
let offset = point - text.baseline_origin;
|
||||||
result.push(index);
|
return Some(text.text_run.range_index_of_advance(&text.range, offset.x));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_ => {},
|
_ => {},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
fn text_index_stacking_context<'a>(&self,
|
None
|
||||||
stacking_context: &StackingContext,
|
|
||||||
clip_id: ClipId,
|
|
||||||
node: OpaqueNode,
|
|
||||||
traversal: &mut DisplayListTraversal<'a>,
|
|
||||||
point: &Point2D<Au>,
|
|
||||||
offset_lookup: &mut ScrollOffsetLookup,
|
|
||||||
result: &mut Vec<usize>) {
|
|
||||||
let mut point = *point - stacking_context.bounds.origin.to_vector();
|
|
||||||
if stacking_context.scroll_policy == ScrollPolicy::Fixed {
|
|
||||||
let old_offset = offset_lookup.calculated_total_offsets.get(&clip_id).cloned();
|
|
||||||
offset_lookup.calculated_total_offsets.insert(clip_id, Vector2D::zero());
|
|
||||||
|
|
||||||
self.text_index_contents(node, traversal, &point, offset_lookup, result);
|
|
||||||
|
|
||||||
match old_offset {
|
|
||||||
Some(offset) => offset_lookup.calculated_total_offsets.insert(clip_id, offset),
|
|
||||||
None => offset_lookup.calculated_total_offsets.remove(&clip_id),
|
|
||||||
};
|
|
||||||
} else if let Some(transform) = stacking_context.transform {
|
|
||||||
if let Some(ref mut sublookup) =
|
|
||||||
offset_lookup.new_for_reference_frame(clip_id, &transform, &mut point) {
|
|
||||||
self.text_index_contents(node, traversal, &point, sublookup, result);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
self.text_index_contents(node, traversal, &point, offset_lookup, result);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print(&self) {
|
pub fn print(&self) {
|
||||||
@ -223,94 +95,6 @@ impl DisplayList {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct DisplayListTraversal<'a> {
|
|
||||||
pub display_list: &'a DisplayList,
|
|
||||||
pub next_item_index: usize,
|
|
||||||
pub first_item_index: usize,
|
|
||||||
pub last_item_index: usize,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> DisplayListTraversal<'a> {
|
|
||||||
pub fn new(display_list: &'a DisplayList) -> DisplayListTraversal {
|
|
||||||
DisplayListTraversal {
|
|
||||||
display_list: display_list,
|
|
||||||
next_item_index: 0,
|
|
||||||
first_item_index: 0,
|
|
||||||
last_item_index: display_list.list.len(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn new_partial(display_list: &'a DisplayList,
|
|
||||||
stacking_context_id: StackingContextId,
|
|
||||||
start: usize,
|
|
||||||
end: usize)
|
|
||||||
-> DisplayListTraversal {
|
|
||||||
debug_assert!(start <= end);
|
|
||||||
debug_assert!(display_list.list.len() > start);
|
|
||||||
debug_assert!(display_list.list.len() > end);
|
|
||||||
|
|
||||||
let stacking_context_start = display_list.list[0..start].iter().rposition(|item|
|
|
||||||
match item {
|
|
||||||
&DisplayItem::PushStackingContext(ref item) =>
|
|
||||||
item.stacking_context.id == stacking_context_id,
|
|
||||||
_ => false,
|
|
||||||
}).unwrap_or(start);
|
|
||||||
debug_assert!(stacking_context_start <= start);
|
|
||||||
|
|
||||||
DisplayListTraversal {
|
|
||||||
display_list: display_list,
|
|
||||||
next_item_index: stacking_context_start,
|
|
||||||
first_item_index: start,
|
|
||||||
last_item_index: end + 1,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn previous_item_id(&self) -> usize {
|
|
||||||
self.next_item_index - 1
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn skip_to_end_of_stacking_context(&mut self, id: StackingContextId) {
|
|
||||||
self.next_item_index = self.display_list.list[self.next_item_index..].iter()
|
|
||||||
.position(|item| {
|
|
||||||
match item {
|
|
||||||
&DisplayItem::PopStackingContext(ref item) => item.stacking_context_id == id,
|
|
||||||
_ => false
|
|
||||||
}
|
|
||||||
}).unwrap_or(self.display_list.list.len());
|
|
||||||
debug_assert!(self.next_item_index < self.last_item_index);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a> Iterator for DisplayListTraversal<'a> {
|
|
||||||
type Item = &'a DisplayItem;
|
|
||||||
|
|
||||||
fn next(&mut self) -> Option<&'a DisplayItem> {
|
|
||||||
while self.next_item_index < self.last_item_index {
|
|
||||||
debug_assert!(self.next_item_index <= self.last_item_index);
|
|
||||||
|
|
||||||
let reached_first_item = self.next_item_index >= self.first_item_index;
|
|
||||||
let item = &self.display_list.list[self.next_item_index];
|
|
||||||
|
|
||||||
self.next_item_index += 1;
|
|
||||||
|
|
||||||
if reached_first_item {
|
|
||||||
return Some(item)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Before we reach the starting item, we only emit stacking context boundaries. This
|
|
||||||
// is to ensure that we properly position items when we are processing a display list
|
|
||||||
// slice that is relative to a certain stacking context.
|
|
||||||
match item {
|
|
||||||
&DisplayItem::PushStackingContext(_) |
|
|
||||||
&DisplayItem::PopStackingContext(_) => return Some(item),
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Display list sections that make up a stacking context. Each section here refers
|
/// Display list sections that make up a stacking context. Each section here refers
|
||||||
/// to the steps in CSS 2.1 Appendix E.
|
/// to the steps in CSS 2.1 Appendix E.
|
||||||
///
|
///
|
||||||
|
@ -10,8 +10,7 @@
|
|||||||
use app_units::Au;
|
use app_units::Au;
|
||||||
use euclid::{Point2D, Vector2D, Rect, SideOffsets2D, Size2D};
|
use euclid::{Point2D, Vector2D, Rect, SideOffsets2D, Size2D};
|
||||||
use gfx::display_list::{BorderDetails, BorderRadii, BoxShadowClipMode, ClipScrollNodeType};
|
use gfx::display_list::{BorderDetails, BorderRadii, BoxShadowClipMode, ClipScrollNodeType};
|
||||||
use gfx::display_list::{ClippingRegion, DisplayItem, DisplayList, DisplayListTraversal};
|
use gfx::display_list::{ClippingRegion, DisplayItem, DisplayList, StackingContextType};
|
||||||
use gfx::display_list::StackingContextType;
|
|
||||||
use msg::constellation_msg::PipelineId;
|
use msg::constellation_msg::PipelineId;
|
||||||
use style::computed_values::{image_rendering, mix_blend_mode, transform_style};
|
use style::computed_values::{image_rendering, mix_blend_mode, transform_style};
|
||||||
use style::values::computed::{BorderStyle, Filter};
|
use style::values::computed::{BorderStyle, Filter};
|
||||||
@ -221,7 +220,6 @@ impl ToTransformStyle for transform_style::T {
|
|||||||
|
|
||||||
impl WebRenderDisplayListConverter for DisplayList {
|
impl WebRenderDisplayListConverter for DisplayList {
|
||||||
fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder {
|
fn convert_to_webrender(&self, pipeline_id: PipelineId) -> DisplayListBuilder {
|
||||||
let traversal = DisplayListTraversal::new(self);
|
|
||||||
let mut builder = DisplayListBuilder::with_capacity(pipeline_id.to_webrender(),
|
let mut builder = DisplayListBuilder::with_capacity(pipeline_id.to_webrender(),
|
||||||
self.bounds().size.to_sizef(),
|
self.bounds().size.to_sizef(),
|
||||||
1024 * 1024); // 1 MB of space
|
1024 * 1024); // 1 MB of space
|
||||||
@ -229,7 +227,7 @@ impl WebRenderDisplayListConverter for DisplayList {
|
|||||||
let mut current_clip_and_scroll_info = pipeline_id.root_clip_and_scroll_info();
|
let mut current_clip_and_scroll_info = pipeline_id.root_clip_and_scroll_info();
|
||||||
builder.push_clip_and_scroll_info(current_clip_and_scroll_info);
|
builder.push_clip_and_scroll_info(current_clip_and_scroll_info);
|
||||||
|
|
||||||
for item in traversal {
|
for item in &self.list {
|
||||||
item.convert_to_webrender(&mut builder, &mut current_clip_and_scroll_info);
|
item.convert_to_webrender(&mut builder, &mut current_clip_and_scroll_info);
|
||||||
}
|
}
|
||||||
builder
|
builder
|
||||||
|
@ -1361,18 +1361,19 @@ impl LayoutThread {
|
|||||||
let node = unsafe { ServoLayoutNode::new(&node) };
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
||||||
rw_data.content_boxes_response = process_content_boxes_request(node, root_flow);
|
rw_data.content_boxes_response = process_content_boxes_request(node, root_flow);
|
||||||
},
|
},
|
||||||
ReflowGoal::TextIndexQuery(node, mouse_x, mouse_y) => {
|
ReflowGoal::TextIndexQuery(node, point_in_node) => {
|
||||||
let node = unsafe { ServoLayoutNode::new(&node) };
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
||||||
let opaque_node = node.opaque();
|
let opaque_node = node.opaque();
|
||||||
let client_point = Point2D::new(Au::from_px(mouse_x),
|
let point_in_node = Point2D::new(
|
||||||
Au::from_px(mouse_y));
|
Au::from_f32_px(point_in_node.x),
|
||||||
rw_data.text_index_response =
|
Au::from_f32_px(point_in_node.y)
|
||||||
TextIndexResponse(rw_data.display_list
|
);
|
||||||
.as_ref()
|
rw_data.text_index_response = TextIndexResponse(
|
||||||
.expect("Tried to hit test with no display list")
|
rw_data.display_list
|
||||||
.text_index(opaque_node,
|
.as_ref()
|
||||||
&client_point,
|
.expect("Tried to hit test with no display list")
|
||||||
&rw_data.scroll_offsets));
|
.text_index(opaque_node, &point_in_node)
|
||||||
|
);
|
||||||
},
|
},
|
||||||
ReflowGoal::NodeGeometryQuery(node) => {
|
ReflowGoal::NodeGeometryQuery(node) => {
|
||||||
let node = unsafe { ServoLayoutNode::new(&node) };
|
let node = unsafe { ServoLayoutNode::new(&node) };
|
||||||
|
@ -93,6 +93,7 @@ pub fn synthetic_click_activation(element: &Element,
|
|||||||
alt_key,
|
alt_key,
|
||||||
meta_key,
|
meta_key,
|
||||||
0,
|
0,
|
||||||
|
None,
|
||||||
None);
|
None);
|
||||||
let event = mouse.upcast::<Event>();
|
let event = mouse.upcast::<Event>();
|
||||||
if source == ActivationSource::FromClick {
|
if source == ActivationSource::FromClick {
|
||||||
|
@ -836,7 +836,8 @@ impl Document {
|
|||||||
_button: MouseButton,
|
_button: MouseButton,
|
||||||
client_point: Point2D<f32>,
|
client_point: Point2D<f32>,
|
||||||
mouse_event_type: MouseEventType,
|
mouse_event_type: MouseEventType,
|
||||||
node_address: Option<UntrustedNodeAddress>
|
node_address: Option<UntrustedNodeAddress>,
|
||||||
|
point_in_node: Option<Point2D<f32>>
|
||||||
) {
|
) {
|
||||||
let mouse_event_type_string = match mouse_event_type {
|
let mouse_event_type_string = match mouse_event_type {
|
||||||
MouseEventType::Click => "click".to_owned(),
|
MouseEventType::Click => "click".to_owned(),
|
||||||
@ -871,22 +872,25 @@ impl Document {
|
|||||||
let client_x = client_point.x as i32;
|
let client_x = client_point.x as i32;
|
||||||
let client_y = client_point.y as i32;
|
let client_y = client_point.y as i32;
|
||||||
let click_count = 1;
|
let click_count = 1;
|
||||||
let event = MouseEvent::new(&self.window,
|
let event = MouseEvent::new(
|
||||||
DOMString::from(mouse_event_type_string),
|
&self.window,
|
||||||
EventBubbles::Bubbles,
|
DOMString::from(mouse_event_type_string),
|
||||||
EventCancelable::Cancelable,
|
EventBubbles::Bubbles,
|
||||||
Some(&self.window),
|
EventCancelable::Cancelable,
|
||||||
click_count,
|
Some(&self.window),
|
||||||
client_x,
|
click_count,
|
||||||
client_y,
|
client_x,
|
||||||
client_x,
|
client_y,
|
||||||
client_y, // TODO: Get real screen coordinates?
|
client_x,
|
||||||
false,
|
client_y, // TODO: Get real screen coordinates?
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
0i16,
|
false,
|
||||||
None);
|
0i16,
|
||||||
|
None,
|
||||||
|
point_in_node,
|
||||||
|
);
|
||||||
let event = event.upcast::<Event>();
|
let event = event.upcast::<Event>();
|
||||||
|
|
||||||
// https://w3c.github.io/uievents/#trusted-events
|
// https://w3c.github.io/uievents/#trusted-events
|
||||||
@ -943,22 +947,25 @@ impl Document {
|
|||||||
let client_x = click_pos.x as i32;
|
let client_x = click_pos.x as i32;
|
||||||
let client_y = click_pos.y as i32;
|
let client_y = click_pos.y as i32;
|
||||||
|
|
||||||
let event = MouseEvent::new(&self.window,
|
let event = MouseEvent::new(
|
||||||
DOMString::from("dblclick"),
|
&self.window,
|
||||||
EventBubbles::Bubbles,
|
DOMString::from("dblclick"),
|
||||||
EventCancelable::Cancelable,
|
EventBubbles::Bubbles,
|
||||||
Some(&self.window),
|
EventCancelable::Cancelable,
|
||||||
click_count,
|
Some(&self.window),
|
||||||
client_x,
|
click_count,
|
||||||
client_y,
|
client_x,
|
||||||
client_x,
|
client_y,
|
||||||
client_y,
|
client_x,
|
||||||
false,
|
client_y,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
0i16,
|
false,
|
||||||
None);
|
0i16,
|
||||||
|
None,
|
||||||
|
None
|
||||||
|
);
|
||||||
event.upcast::<Event>().fire(target.upcast());
|
event.upcast::<Event>().fire(target.upcast());
|
||||||
|
|
||||||
// When a double click occurs, self.last_click_info is left as None so that a
|
// When a double click occurs, self.last_click_info is left as None so that a
|
||||||
@ -1034,22 +1041,25 @@ impl Document {
|
|||||||
let client_x = client_point.x.to_i32().unwrap_or(0);
|
let client_x = client_point.x.to_i32().unwrap_or(0);
|
||||||
let client_y = client_point.y.to_i32().unwrap_or(0);
|
let client_y = client_point.y.to_i32().unwrap_or(0);
|
||||||
|
|
||||||
let mouse_event = MouseEvent::new(&self.window,
|
let mouse_event = MouseEvent::new(
|
||||||
DOMString::from(event_name),
|
&self.window,
|
||||||
EventBubbles::Bubbles,
|
DOMString::from(event_name),
|
||||||
EventCancelable::Cancelable,
|
EventBubbles::Bubbles,
|
||||||
Some(&self.window),
|
EventCancelable::Cancelable,
|
||||||
0i32,
|
Some(&self.window),
|
||||||
client_x,
|
0i32,
|
||||||
client_y,
|
client_x,
|
||||||
client_x,
|
client_y,
|
||||||
client_y,
|
client_x,
|
||||||
false,
|
client_y,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
false,
|
false,
|
||||||
0i16,
|
false,
|
||||||
None);
|
0i16,
|
||||||
|
None,
|
||||||
|
None
|
||||||
|
);
|
||||||
let event = mouse_event.upcast::<Event>();
|
let event = mouse_event.upcast::<Event>();
|
||||||
event.fire(target);
|
event.fire(target);
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,6 @@ use dom::bindings::codegen::Bindings::FileListBinding::FileListMethods;
|
|||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding;
|
||||||
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
use dom::bindings::codegen::Bindings::HTMLInputElementBinding::HTMLInputElementMethods;
|
||||||
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
use dom::bindings::codegen::Bindings::KeyboardEventBinding::KeyboardEventMethods;
|
||||||
use dom::bindings::codegen::Bindings::MouseEventBinding::MouseEventMethods;
|
|
||||||
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
|
|
||||||
use dom::bindings::error::{Error, ErrorResult};
|
use dom::bindings::error::{Error, ErrorResult};
|
||||||
use dom::bindings::inheritance::Castable;
|
use dom::bindings::inheritance::Castable;
|
||||||
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
|
use dom::bindings::root::{Dom, DomRoot, LayoutDom, MutNullableDom, RootedReference};
|
||||||
@ -1106,23 +1104,19 @@ impl VirtualMethods for HTMLInputElement {
|
|||||||
// dispatch_key_event (document.rs) triggers a click event when releasing
|
// dispatch_key_event (document.rs) triggers a click event when releasing
|
||||||
// the space key. There's no nice way to catch this so let's use this for
|
// the space key. There's no nice way to catch this so let's use this for
|
||||||
// now.
|
// now.
|
||||||
if !(mouse_event.ScreenX() == 0 && mouse_event.ScreenY() == 0 &&
|
if let Some(point_in_target) = mouse_event.point_in_target() {
|
||||||
mouse_event.GetRelatedTarget().is_none()) {
|
let window = window_from_node(self);
|
||||||
let window = window_from_node(self);
|
let TextIndexResponse(index) = window.text_index_query(
|
||||||
let translated_x = mouse_event.ClientX() + window.PageXOffset();
|
self.upcast::<Node>().to_trusted_node_address(),
|
||||||
let translated_y = mouse_event.ClientY() + window.PageYOffset();
|
point_in_target
|
||||||
let TextIndexResponse(index) = window.text_index_query(
|
);
|
||||||
self.upcast::<Node>().to_trusted_node_address(),
|
if let Some(i) = index {
|
||||||
translated_x,
|
self.textinput.borrow_mut().set_edit_point_index(i as usize);
|
||||||
translated_y
|
// trigger redraw
|
||||||
);
|
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
||||||
if let Some(i) = index {
|
event.PreventDefault();
|
||||||
self.textinput.borrow_mut().set_edit_point_index(i as usize);
|
|
||||||
// trigger redraw
|
|
||||||
self.upcast::<Node>().dirty(NodeDamage::OtherNodeDamage);
|
|
||||||
event.PreventDefault();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if event.type_() == atom!("keydown") && !event.DefaultPrevented() &&
|
} else if event.type_() == atom!("keydown") && !event.DefaultPrevented() &&
|
||||||
|
@ -15,6 +15,7 @@ use dom::eventtarget::EventTarget;
|
|||||||
use dom::uievent::UIEvent;
|
use dom::uievent::UIEvent;
|
||||||
use dom::window::Window;
|
use dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
use euclid::Point2D;
|
||||||
use servo_config::prefs::PREFS;
|
use servo_config::prefs::PREFS;
|
||||||
use std::cell::Cell;
|
use std::cell::Cell;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
@ -32,6 +33,7 @@ pub struct MouseEvent {
|
|||||||
meta_key: Cell<bool>,
|
meta_key: Cell<bool>,
|
||||||
button: Cell<i16>,
|
button: Cell<i16>,
|
||||||
related_target: MutNullableDom<EventTarget>,
|
related_target: MutNullableDom<EventTarget>,
|
||||||
|
point_in_target: Cell<Option<Point2D<f32>>>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MouseEvent {
|
impl MouseEvent {
|
||||||
@ -48,6 +50,7 @@ impl MouseEvent {
|
|||||||
meta_key: Cell::new(false),
|
meta_key: Cell::new(false),
|
||||||
button: Cell::new(0),
|
button: Cell::new(0),
|
||||||
related_target: Default::default(),
|
related_target: Default::default(),
|
||||||
|
point_in_target: Cell::new(None),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,28 +60,34 @@ impl MouseEvent {
|
|||||||
MouseEventBinding::Wrap)
|
MouseEventBinding::Wrap)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new(window: &Window,
|
pub fn new(
|
||||||
type_: DOMString,
|
window: &Window,
|
||||||
can_bubble: EventBubbles,
|
type_: DOMString,
|
||||||
cancelable: EventCancelable,
|
can_bubble: EventBubbles,
|
||||||
view: Option<&Window>,
|
cancelable: EventCancelable,
|
||||||
detail: i32,
|
view: Option<&Window>,
|
||||||
screen_x: i32,
|
detail: i32,
|
||||||
screen_y: i32,
|
screen_x: i32,
|
||||||
client_x: i32,
|
screen_y: i32,
|
||||||
client_y: i32,
|
client_x: i32,
|
||||||
ctrl_key: bool,
|
client_y: i32,
|
||||||
alt_key: bool,
|
ctrl_key: bool,
|
||||||
shift_key: bool,
|
alt_key: bool,
|
||||||
meta_key: bool,
|
shift_key: bool,
|
||||||
button: i16,
|
meta_key: bool,
|
||||||
related_target: Option<&EventTarget>) -> DomRoot<MouseEvent> {
|
button: i16,
|
||||||
|
related_target: Option<&EventTarget>,
|
||||||
|
point_in_target: Option<Point2D<f32>>
|
||||||
|
) -> DomRoot<MouseEvent> {
|
||||||
let ev = MouseEvent::new_uninitialized(window);
|
let ev = MouseEvent::new_uninitialized(window);
|
||||||
ev.InitMouseEvent(type_, bool::from(can_bubble), bool::from(cancelable),
|
ev.InitMouseEvent(
|
||||||
view, detail,
|
type_, bool::from(can_bubble), bool::from(cancelable),
|
||||||
screen_x, screen_y, client_x, client_y,
|
view, detail,
|
||||||
ctrl_key, alt_key, shift_key, meta_key,
|
screen_x, screen_y, client_x, client_y,
|
||||||
button, related_target);
|
ctrl_key, alt_key, shift_key, meta_key,
|
||||||
|
button, related_target,
|
||||||
|
);
|
||||||
|
ev.point_in_target.set(point_in_target);
|
||||||
ev
|
ev
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,18 +96,24 @@ impl MouseEvent {
|
|||||||
init: &MouseEventBinding::MouseEventInit) -> Fallible<DomRoot<MouseEvent>> {
|
init: &MouseEventBinding::MouseEventInit) -> Fallible<DomRoot<MouseEvent>> {
|
||||||
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
|
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
|
||||||
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
|
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
|
||||||
let event = MouseEvent::new(window,
|
let event = MouseEvent::new(
|
||||||
type_,
|
window,
|
||||||
bubbles,
|
type_,
|
||||||
cancelable,
|
bubbles,
|
||||||
init.parent.parent.view.r(),
|
cancelable,
|
||||||
init.parent.parent.detail,
|
init.parent.parent.view.r(),
|
||||||
init.screenX, init.screenY,
|
init.parent.parent.detail,
|
||||||
init.clientX, init.clientY, init.parent.ctrlKey,
|
init.screenX, init.screenY,
|
||||||
init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
|
init.clientX, init.clientY, init.parent.ctrlKey,
|
||||||
init.button, init.relatedTarget.r());
|
init.parent.altKey, init.parent.shiftKey, init.parent.metaKey,
|
||||||
|
init.button, init.relatedTarget.r(), None
|
||||||
|
);
|
||||||
Ok(event)
|
Ok(event)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn point_in_target(&self) -> Option<Point2D<f32>> {
|
||||||
|
self.point_in_target.get()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MouseEventMethods for MouseEvent {
|
impl MouseEventMethods for MouseEvent {
|
||||||
@ -166,22 +181,24 @@ impl MouseEventMethods for MouseEvent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// https://w3c.github.io/uievents/#widl-MouseEvent-initMouseEvent
|
// https://w3c.github.io/uievents/#widl-MouseEvent-initMouseEvent
|
||||||
fn InitMouseEvent(&self,
|
fn InitMouseEvent(
|
||||||
type_arg: DOMString,
|
&self,
|
||||||
can_bubble_arg: bool,
|
type_arg: DOMString,
|
||||||
cancelable_arg: bool,
|
can_bubble_arg: bool,
|
||||||
view_arg: Option<&Window>,
|
cancelable_arg: bool,
|
||||||
detail_arg: i32,
|
view_arg: Option<&Window>,
|
||||||
screen_x_arg: i32,
|
detail_arg: i32,
|
||||||
screen_y_arg: i32,
|
screen_x_arg: i32,
|
||||||
client_x_arg: i32,
|
screen_y_arg: i32,
|
||||||
client_y_arg: i32,
|
client_x_arg: i32,
|
||||||
ctrl_key_arg: bool,
|
client_y_arg: i32,
|
||||||
alt_key_arg: bool,
|
ctrl_key_arg: bool,
|
||||||
shift_key_arg: bool,
|
alt_key_arg: bool,
|
||||||
meta_key_arg: bool,
|
shift_key_arg: bool,
|
||||||
button_arg: i16,
|
meta_key_arg: bool,
|
||||||
related_target_arg: Option<&EventTarget>) {
|
button_arg: i16,
|
||||||
|
related_target_arg: Option<&EventTarget>,
|
||||||
|
) {
|
||||||
if self.upcast::<Event>().dispatching() {
|
if self.upcast::<Event>().dispatching() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1481,8 +1481,12 @@ impl Window {
|
|||||||
self.layout_rpc.margin_style()
|
self.layout_rpc.margin_style()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_index_query(&self, node: TrustedNodeAddress, mouse_x: i32, mouse_y: i32) -> TextIndexResponse {
|
pub fn text_index_query(
|
||||||
if !self.reflow(ReflowGoal::TextIndexQuery(node, mouse_x, mouse_y), ReflowReason::Query) {
|
&self,
|
||||||
|
node: TrustedNodeAddress,
|
||||||
|
point_in_node: Point2D<f32>
|
||||||
|
) -> TextIndexResponse {
|
||||||
|
if !self.reflow(ReflowGoal::TextIndexQuery(node, point_in_node), ReflowReason::Query) {
|
||||||
return TextIndexResponse(None);
|
return TextIndexResponse(None);
|
||||||
}
|
}
|
||||||
self.layout_rpc.text_index()
|
self.layout_rpc.text_index()
|
||||||
|
@ -2191,8 +2191,15 @@ impl ScriptThread {
|
|||||||
self.handle_resize_event(pipeline_id, new_size, size_type);
|
self.handle_resize_event(pipeline_id, new_size, size_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseButtonEvent(event_type, button, point, node_address) => {
|
MouseButtonEvent(event_type, button, point, node_address, point_in_node) => {
|
||||||
self.handle_mouse_event(pipeline_id, event_type, button, point, node_address);
|
self.handle_mouse_event(
|
||||||
|
pipeline_id,
|
||||||
|
event_type,
|
||||||
|
button,
|
||||||
|
point,
|
||||||
|
node_address,
|
||||||
|
point_in_node
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
MouseMoveEvent(point, node_address) => {
|
MouseMoveEvent(point, node_address) => {
|
||||||
@ -2303,7 +2310,8 @@ impl ScriptThread {
|
|||||||
mouse_event_type: MouseEventType,
|
mouse_event_type: MouseEventType,
|
||||||
button: MouseButton,
|
button: MouseButton,
|
||||||
point: Point2D<f32>,
|
point: Point2D<f32>,
|
||||||
node_address: Option<UntrustedNodeAddress>
|
node_address: Option<UntrustedNodeAddress>,
|
||||||
|
point_in_node: Option<Point2D<f32>>
|
||||||
) {
|
) {
|
||||||
let document = match { self.documents.borrow().find_document(pipeline_id) } {
|
let document = match { self.documents.borrow().find_document(pipeline_id) } {
|
||||||
Some(document) => document,
|
Some(document) => document,
|
||||||
@ -2314,7 +2322,8 @@ impl ScriptThread {
|
|||||||
button,
|
button,
|
||||||
point,
|
point,
|
||||||
mouse_event_type,
|
mouse_event_type,
|
||||||
node_address
|
node_address,
|
||||||
|
point_in_node
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -120,7 +120,7 @@ pub enum ReflowGoal {
|
|||||||
ResolvedStyleQuery(TrustedNodeAddress, Option<PseudoElement>, PropertyId),
|
ResolvedStyleQuery(TrustedNodeAddress, Option<PseudoElement>, PropertyId),
|
||||||
OffsetParentQuery(TrustedNodeAddress),
|
OffsetParentQuery(TrustedNodeAddress),
|
||||||
MarginStyleQuery(TrustedNodeAddress),
|
MarginStyleQuery(TrustedNodeAddress),
|
||||||
TextIndexQuery(TrustedNodeAddress, i32, i32),
|
TextIndexQuery(TrustedNodeAddress, Point2D<f32>),
|
||||||
NodesFromPointQuery(Point2D<f32>, NodesFromPointQueryType),
|
NodesFromPointQuery(Point2D<f32>, NodesFromPointQueryType),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -432,7 +432,13 @@ pub enum CompositorEvent {
|
|||||||
/// The window was resized.
|
/// The window was resized.
|
||||||
ResizeEvent(WindowSizeData, WindowSizeType),
|
ResizeEvent(WindowSizeData, WindowSizeType),
|
||||||
/// A mouse button state changed.
|
/// A mouse button state changed.
|
||||||
MouseButtonEvent(MouseEventType, MouseButton, Point2D<f32>, Option<UntrustedNodeAddress>),
|
MouseButtonEvent(
|
||||||
|
MouseEventType,
|
||||||
|
MouseButton,
|
||||||
|
Point2D<f32>,
|
||||||
|
Option<UntrustedNodeAddress>,
|
||||||
|
Option<Point2D<f32>>
|
||||||
|
),
|
||||||
/// The mouse was moved over a point (or was moved out of the recognizable region).
|
/// The mouse was moved over a point (or was moved out of the recognizable region).
|
||||||
MouseMoveEvent(Option<Point2D<f32>>, Option<UntrustedNodeAddress>),
|
MouseMoveEvent(Option<Point2D<f32>>, Option<UntrustedNodeAddress>),
|
||||||
/// A touch event was generated with a touch ID and location.
|
/// A touch event was generated with a touch ID and location.
|
||||||
|
Loading…
Reference in New Issue
Block a user