mirror of
https://github.com/servo/servo.git
synced 2025-09-30 00:29:14 +01:00
script/compositor: Handle cursor updates from script (#38518)
Instead of using WebRender hit testing to update the cursor, base it on layout hit tests. This allows removing the majority of WebRender hit test items and finally opens up the possibility of adding support for custom cursors. In addition, this change fixes an issue where cursors were not set properly on areas of the viewport that extended past the page content. Testing: This is difficult to test as verifying that the cursor changed properly is beyond the capabilities of Servo's test harnesses. Signed-off-by: Martin Robinson <mrobinson@igalia.com> Co-authored-by: Oriol Brufau <obrufau@igalia.com>
This commit is contained in:
parent
87538282db
commit
6651f37c05
21 changed files with 279 additions and 259 deletions
|
@ -9,7 +9,6 @@ use app_units::{AU_PER_PX, Au};
|
|||
use base::id::ScrollTreeNodeId;
|
||||
use clip::{Clip, ClipId};
|
||||
use compositing_traits::display_list::{CompositorDisplayListInfo, SpatialTreeNodeInfo};
|
||||
use embedder_traits::Cursor;
|
||||
use euclid::{Point2D, Scale, SideOffsets2D, Size2D, UnknownUnit, Vector2D};
|
||||
use fonts::GlyphStore;
|
||||
use gradient::WebRenderGradient;
|
||||
|
@ -36,13 +35,12 @@ use style::values::computed::{
|
|||
use style::values::generics::NonNegative;
|
||||
use style::values::generics::rect::Rect;
|
||||
use style::values::specified::text::TextDecorationLine;
|
||||
use style::values::specified::ui::CursorKind;
|
||||
use style_traits::{CSSPixel as StyloCSSPixel, DevicePixel as StyloDevicePixel};
|
||||
use webrender_api::units::{DeviceIntSize, DevicePixel, LayoutPixel, LayoutRect, LayoutSize};
|
||||
use webrender_api::{
|
||||
self as wr, BorderDetails, BorderRadius, BoxShadowClipMode, BuiltDisplayList, ClipChainId,
|
||||
ClipMode, CommonItemProperties, ComplexClipRegion, NinePatchBorder, NinePatchBorderSource,
|
||||
PropertyBinding, SpatialId, SpatialTreeItemKey, units,
|
||||
PrimitiveFlags, PropertyBinding, SpatialId, SpatialTreeItemKey, units,
|
||||
};
|
||||
use wr::units::LayoutVector2D;
|
||||
|
||||
|
@ -164,8 +162,9 @@ impl DisplayListBuilder<'_> {
|
|||
) -> BuiltDisplayList {
|
||||
// Build the rest of the display list which inclues all of the WebRender primitives.
|
||||
let compositor_info = &mut stacking_context_tree.compositor_info;
|
||||
let pipeline_id = compositor_info.pipeline_id;
|
||||
let mut webrender_display_list_builder =
|
||||
webrender_api::DisplayListBuilder::new(compositor_info.pipeline_id);
|
||||
webrender_api::DisplayListBuilder::new(pipeline_id);
|
||||
webrender_display_list_builder.begin();
|
||||
|
||||
// `dump_serialized_display_list` doesn't actually print anything. It sets up
|
||||
|
@ -200,6 +199,8 @@ impl DisplayListBuilder<'_> {
|
|||
builder.add_clip_to_display_list(clip);
|
||||
}
|
||||
|
||||
builder.push_hit_tests_for_scrollable_areas(&stacking_context_tree.hit_test_items);
|
||||
|
||||
// Paint the canvas’ background (if any) before/under everything else
|
||||
stacking_context_tree
|
||||
.root_stacking_context
|
||||
|
@ -309,6 +310,39 @@ impl DisplayListBuilder<'_> {
|
|||
self.compositor_info.scroll_tree = scroll_tree;
|
||||
}
|
||||
|
||||
fn push_hit_tests_for_scrollable_areas(
|
||||
&mut self,
|
||||
scroll_frame_hit_test_items: &[ScrollFrameHitTestItem],
|
||||
) {
|
||||
// Add a single hit test that covers the entire viewport, so that WebRender knows
|
||||
// which pipeline it hits when doing hit testing.
|
||||
let pipeline_id = self.compositor_info.pipeline_id;
|
||||
let viewport_size = self.compositor_info.viewport_details.size;
|
||||
let viewport_rect = LayoutRect::from_size(viewport_size.cast_unit());
|
||||
self.wr().push_hit_test(
|
||||
viewport_rect,
|
||||
ClipChainId::INVALID,
|
||||
SpatialId::root_reference_frame(pipeline_id),
|
||||
PrimitiveFlags::default(),
|
||||
(0, 0), /* tag */
|
||||
);
|
||||
|
||||
for item in scroll_frame_hit_test_items {
|
||||
let spatial_id = self
|
||||
.compositor_info
|
||||
.scroll_tree
|
||||
.webrender_id(&item.scroll_node_id);
|
||||
let clip_chain_id = self.clip_chain_id(item.clip_id);
|
||||
self.wr().push_hit_test(
|
||||
item.rect,
|
||||
clip_chain_id,
|
||||
spatial_id,
|
||||
PrimitiveFlags::default(),
|
||||
(item.external_scroll_id.0, 0), /* tag */
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Add the given [`Clip`] to the WebRender display list and create a mapping from
|
||||
/// its [`ClipId`] to a WebRender [`ClipChainId`]. This happens:
|
||||
/// - When WebRender display list construction starts: All clips created during the
|
||||
|
@ -548,7 +582,6 @@ impl Fragment {
|
|||
builder: &mut DisplayListBuilder,
|
||||
containing_block: &PhysicalRect<Au>,
|
||||
section: StackingContextSection,
|
||||
is_hit_test_for_scrollable_overflow: bool,
|
||||
is_collapsed_table_borders: bool,
|
||||
text_decorations: &Arc<Vec<FragmentTextDecoration>>,
|
||||
) {
|
||||
|
@ -572,7 +605,6 @@ impl Fragment {
|
|||
Visibility::Visible => BuilderForBoxFragment::new(
|
||||
box_fragment,
|
||||
containing_block,
|
||||
is_hit_test_for_scrollable_overflow,
|
||||
is_collapsed_table_borders,
|
||||
)
|
||||
.build(builder, section),
|
||||
|
@ -580,19 +612,7 @@ impl Fragment {
|
|||
Visibility::Collapse => (),
|
||||
}
|
||||
},
|
||||
Fragment::AbsoluteOrFixedPositioned(_) => {},
|
||||
Fragment::Positioning(positioning_fragment) => {
|
||||
let positioning_fragment = positioning_fragment.borrow();
|
||||
let rect = positioning_fragment
|
||||
.rect
|
||||
.translate(containing_block.origin.to_vector());
|
||||
self.maybe_push_hit_test_for_style_and_tag(
|
||||
builder,
|
||||
&positioning_fragment.style,
|
||||
rect,
|
||||
Cursor::Default,
|
||||
);
|
||||
},
|
||||
Fragment::AbsoluteOrFixedPositioned(_) | Fragment::Positioning(_) => {},
|
||||
Fragment::Image(image) => {
|
||||
let image = image.borrow();
|
||||
match image.style.get_inherited_box().visibility {
|
||||
|
@ -674,27 +694,6 @@ impl Fragment {
|
|||
}
|
||||
}
|
||||
|
||||
fn maybe_push_hit_test_for_style_and_tag(
|
||||
&self,
|
||||
builder: &mut DisplayListBuilder,
|
||||
style: &ComputedValues,
|
||||
rect: PhysicalRect<Au>,
|
||||
cursor: Cursor,
|
||||
) {
|
||||
let clip_chain_id = builder.clip_chain_id(builder.current_clip_id);
|
||||
let spatial_id = builder.spatial_id(builder.current_scroll_node_id);
|
||||
let external_scroll_id = builder
|
||||
.compositor_info
|
||||
.external_scroll_id_for_scroll_tree_node(builder.current_scroll_node_id);
|
||||
builder.wr().push_hit_test(
|
||||
rect.to_webrender(),
|
||||
clip_chain_id,
|
||||
spatial_id,
|
||||
style.get_webrender_primitive_flags(),
|
||||
(external_scroll_id.0, cursor as u16), /* tag */
|
||||
);
|
||||
}
|
||||
|
||||
fn build_display_list_for_text_fragment(
|
||||
&self,
|
||||
fragment: &TextFragment,
|
||||
|
@ -724,8 +723,6 @@ impl Fragment {
|
|||
}
|
||||
|
||||
let parent_style = fragment.inline_styles.style.borrow();
|
||||
self.maybe_push_hit_test_for_style_and_tag(builder, &parent_style, rect, Cursor::Text);
|
||||
|
||||
let color = parent_style.clone_color();
|
||||
let font_metrics = &fragment.font_metrics;
|
||||
let dppx = builder.device_pixel_ratio.get();
|
||||
|
@ -939,7 +936,6 @@ struct BuilderForBoxFragment<'a> {
|
|||
border_edge_clip_chain_id: RefCell<Option<ClipChainId>>,
|
||||
padding_edge_clip_chain_id: RefCell<Option<ClipChainId>>,
|
||||
content_edge_clip_chain_id: RefCell<Option<ClipChainId>>,
|
||||
is_hit_test_for_scrollable_overflow: bool,
|
||||
is_collapsed_table_borders: bool,
|
||||
}
|
||||
|
||||
|
@ -947,7 +943,6 @@ impl<'a> BuilderForBoxFragment<'a> {
|
|||
fn new(
|
||||
fragment: &'a BoxFragment,
|
||||
containing_block: &'a PhysicalRect<Au>,
|
||||
is_hit_test_for_scrollable_overflow: bool,
|
||||
is_collapsed_table_borders: bool,
|
||||
) -> Self {
|
||||
let border_rect = fragment
|
||||
|
@ -964,7 +959,6 @@ impl<'a> BuilderForBoxFragment<'a> {
|
|||
border_edge_clip_chain_id: RefCell::new(None),
|
||||
padding_edge_clip_chain_id: RefCell::new(None),
|
||||
content_edge_clip_chain_id: RefCell::new(None),
|
||||
is_hit_test_for_scrollable_overflow,
|
||||
is_collapsed_table_borders,
|
||||
}
|
||||
}
|
||||
|
@ -1047,11 +1041,6 @@ impl<'a> BuilderForBoxFragment<'a> {
|
|||
}
|
||||
|
||||
fn build(&mut self, builder: &mut DisplayListBuilder, section: StackingContextSection) {
|
||||
if self.is_hit_test_for_scrollable_overflow {
|
||||
self.build_hit_test(builder, self.fragment.scrollable_overflow().to_webrender());
|
||||
return;
|
||||
}
|
||||
|
||||
if self.is_collapsed_table_borders {
|
||||
self.build_collapsed_table_borders(builder);
|
||||
return;
|
||||
|
@ -1062,7 +1051,6 @@ impl<'a> BuilderForBoxFragment<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
self.build_hit_test(builder, self.border_rect);
|
||||
if self
|
||||
.fragment
|
||||
.base
|
||||
|
@ -1077,28 +1065,6 @@ impl<'a> BuilderForBoxFragment<'a> {
|
|||
self.build_border(builder);
|
||||
}
|
||||
|
||||
fn build_hit_test(&self, builder: &mut DisplayListBuilder, rect: LayoutRect) {
|
||||
let cursor = cursor(
|
||||
self.fragment.style.get_inherited_ui().cursor.keyword,
|
||||
Cursor::Default,
|
||||
);
|
||||
let external_scroll_node_id = builder
|
||||
.compositor_info
|
||||
.external_scroll_id_for_scroll_tree_node(builder.current_scroll_node_id);
|
||||
|
||||
let mut common = builder.common_properties(rect, &self.fragment.style);
|
||||
if let Some(clip_chain_id) = self.border_edge_clip(builder, false) {
|
||||
common.clip_chain_id = clip_chain_id;
|
||||
}
|
||||
builder.wr().push_hit_test(
|
||||
common.clip_rect,
|
||||
common.clip_chain_id,
|
||||
common.spatial_id,
|
||||
common.flags,
|
||||
(external_scroll_node_id.0, cursor as u16), /* tag */
|
||||
);
|
||||
}
|
||||
|
||||
fn build_background_for_painter(
|
||||
&mut self,
|
||||
builder: &mut DisplayListBuilder,
|
||||
|
@ -1623,47 +1589,6 @@ fn glyphs_advance_by_index(
|
|||
point
|
||||
}
|
||||
|
||||
fn cursor(kind: CursorKind, auto_cursor: Cursor) -> Cursor {
|
||||
match kind {
|
||||
CursorKind::Auto => auto_cursor,
|
||||
CursorKind::None => Cursor::None,
|
||||
CursorKind::Default => Cursor::Default,
|
||||
CursorKind::Pointer => Cursor::Pointer,
|
||||
CursorKind::ContextMenu => Cursor::ContextMenu,
|
||||
CursorKind::Help => Cursor::Help,
|
||||
CursorKind::Progress => Cursor::Progress,
|
||||
CursorKind::Wait => Cursor::Wait,
|
||||
CursorKind::Cell => Cursor::Cell,
|
||||
CursorKind::Crosshair => Cursor::Crosshair,
|
||||
CursorKind::Text => Cursor::Text,
|
||||
CursorKind::VerticalText => Cursor::VerticalText,
|
||||
CursorKind::Alias => Cursor::Alias,
|
||||
CursorKind::Copy => Cursor::Copy,
|
||||
CursorKind::Move => Cursor::Move,
|
||||
CursorKind::NoDrop => Cursor::NoDrop,
|
||||
CursorKind::NotAllowed => Cursor::NotAllowed,
|
||||
CursorKind::Grab => Cursor::Grab,
|
||||
CursorKind::Grabbing => Cursor::Grabbing,
|
||||
CursorKind::EResize => Cursor::EResize,
|
||||
CursorKind::NResize => Cursor::NResize,
|
||||
CursorKind::NeResize => Cursor::NeResize,
|
||||
CursorKind::NwResize => Cursor::NwResize,
|
||||
CursorKind::SResize => Cursor::SResize,
|
||||
CursorKind::SeResize => Cursor::SeResize,
|
||||
CursorKind::SwResize => Cursor::SwResize,
|
||||
CursorKind::WResize => Cursor::WResize,
|
||||
CursorKind::EwResize => Cursor::EwResize,
|
||||
CursorKind::NsResize => Cursor::NsResize,
|
||||
CursorKind::NeswResize => Cursor::NeswResize,
|
||||
CursorKind::NwseResize => Cursor::NwseResize,
|
||||
CursorKind::ColResize => Cursor::ColResize,
|
||||
CursorKind::RowResize => Cursor::RowResize,
|
||||
CursorKind::AllScroll => Cursor::AllScroll,
|
||||
CursorKind::ZoomIn => Cursor::ZoomIn,
|
||||
CursorKind::ZoomOut => Cursor::ZoomOut,
|
||||
}
|
||||
}
|
||||
|
||||
/// Radii for the padding edge or content edge
|
||||
fn inner_radii(mut radii: wr::BorderRadius, insets: units::LayoutSideOffsets) -> wr::BorderRadius {
|
||||
assert!(insets.left >= 0.0, "left inset must not be negative");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue