Skip to content
Permalink
Browse files

Handle cursor and hit testing in 2020

  • Loading branch information
nox committed Dec 13, 2019
1 parent abc2c15 commit ace052ddbbf9aa077482e3136035f2ebdf0c0234
Showing with 57 additions and 3 deletions.
  1. +1 −0 Cargo.lock
  2. +1 −0 components/layout_2020/Cargo.toml
  3. +55 −3 components/layout_2020/display_list.rs

Some generated files are not rendered by default. Learn more.

@@ -16,6 +16,7 @@ doctest = false
app_units = "0.7"
atomic_refcell = "0.1"
cssparser = "0.27"
embedder_traits = {path = "../embedder_traits"}
euclid = "0.20"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
@@ -4,9 +4,11 @@

use crate::fragments::{BoxFragment, Fragment};
use crate::geom::physical::{Rect, Vec2};
use embedder_traits::Cursor;
use euclid::{Point2D, SideOffsets2D};
use gfx::text::glyph::GlyphStore;
use std::sync::Arc;
use style::properties::ComputedValues;
use style::values::computed::{BorderStyle, Length};
use webrender_api::{self as wr, units, CommonItemProperties, PrimitiveFlags};

@@ -58,11 +60,12 @@ impl Fragment {
.translate(&containing_block.top_left);
let mut baseline_origin = rect.top_left.clone();
baseline_origin.y += t.ascent;
let cursor = cursor(&t.parent_style, Cursor::Text);
let common = CommonItemProperties {
clip_rect: rect.clone().into(),
clip_id: wr::ClipId::root(builder.pipeline_id),
spatial_id: wr::SpatialId::root_scroll_node(builder.pipeline_id),
hit_info: None,
hit_info: cursor.map(|cursor| (t.tag.0 as u64, cursor as u16)),
// TODO(gw): Make use of the WR backface visibility functionality.
flags: PrimitiveFlags::default(),
};
@@ -119,11 +122,12 @@ impl BoxFragment {
.to_physical(self.style.writing_mode, containing_block)
.translate(&containing_block.top_left)
.into();
let cursor = cursor(&self.style, Cursor::Default);
let common = CommonItemProperties {
clip_rect: border_rect,
clip_id: wr::ClipId::root(builder.pipeline_id),
spatial_id: wr::SpatialId::root_scroll_node(builder.pipeline_id),
hit_info: None,
hit_info: cursor.map(|cursor| (self.tag.0 as u64, cursor as u16)),
// TODO(gw): Make use of the WR backface visibility functionality.
flags: PrimitiveFlags::default(),
};
@@ -147,7 +151,7 @@ impl BoxFragment {
let background_color = self
.style
.resolve_color(self.style.clone_background_color());
if background_color.alpha > 0 {
if background_color.alpha > 0 || common.hit_info.is_some() {
builder.wr.push_rect(common, rgba(background_color))
}
}
@@ -228,3 +232,51 @@ fn glyphs(glyph_runs: &[Arc<GlyphStore>], mut origin: Vec2<Length>) -> Vec<wr::G
}
glyphs
}

fn cursor(values: &ComputedValues, default: Cursor) -> Option<Cursor> {
use style::computed_values::pointer_events::T as PointerEvents;
use style::values::specified::ui::CursorKind;

let inherited_ui = values.get_inherited_ui();
if inherited_ui.pointer_events == PointerEvents::None {
return None;
}
Some(match inherited_ui.cursor.keyword {
CursorKind::Auto => default,
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,
})
}

0 comments on commit ace052d

Please sign in to comment.
You can’t perform that action at this time.