mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Handle cursor and hit testing in 2020
This commit is contained in:
parent
abc2c15c28
commit
ace052ddbb
3 changed files with 57 additions and 3 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -2721,6 +2721,7 @@ dependencies = [
|
||||||
"app_units",
|
"app_units",
|
||||||
"atomic_refcell",
|
"atomic_refcell",
|
||||||
"cssparser",
|
"cssparser",
|
||||||
|
"embedder_traits",
|
||||||
"euclid",
|
"euclid",
|
||||||
"gfx",
|
"gfx",
|
||||||
"gfx_traits",
|
"gfx_traits",
|
||||||
|
|
|
@ -16,6 +16,7 @@ doctest = false
|
||||||
app_units = "0.7"
|
app_units = "0.7"
|
||||||
atomic_refcell = "0.1"
|
atomic_refcell = "0.1"
|
||||||
cssparser = "0.27"
|
cssparser = "0.27"
|
||||||
|
embedder_traits = {path = "../embedder_traits"}
|
||||||
euclid = "0.20"
|
euclid = "0.20"
|
||||||
gfx = {path = "../gfx"}
|
gfx = {path = "../gfx"}
|
||||||
gfx_traits = {path = "../gfx_traits"}
|
gfx_traits = {path = "../gfx_traits"}
|
||||||
|
|
|
@ -4,9 +4,11 @@
|
||||||
|
|
||||||
use crate::fragments::{BoxFragment, Fragment};
|
use crate::fragments::{BoxFragment, Fragment};
|
||||||
use crate::geom::physical::{Rect, Vec2};
|
use crate::geom::physical::{Rect, Vec2};
|
||||||
|
use embedder_traits::Cursor;
|
||||||
use euclid::{Point2D, SideOffsets2D};
|
use euclid::{Point2D, SideOffsets2D};
|
||||||
use gfx::text::glyph::GlyphStore;
|
use gfx::text::glyph::GlyphStore;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use style::properties::ComputedValues;
|
||||||
use style::values::computed::{BorderStyle, Length};
|
use style::values::computed::{BorderStyle, Length};
|
||||||
use webrender_api::{self as wr, units, CommonItemProperties, PrimitiveFlags};
|
use webrender_api::{self as wr, units, CommonItemProperties, PrimitiveFlags};
|
||||||
|
|
||||||
|
@ -58,11 +60,12 @@ impl Fragment {
|
||||||
.translate(&containing_block.top_left);
|
.translate(&containing_block.top_left);
|
||||||
let mut baseline_origin = rect.top_left.clone();
|
let mut baseline_origin = rect.top_left.clone();
|
||||||
baseline_origin.y += t.ascent;
|
baseline_origin.y += t.ascent;
|
||||||
|
let cursor = cursor(&t.parent_style, Cursor::Text);
|
||||||
let common = CommonItemProperties {
|
let common = CommonItemProperties {
|
||||||
clip_rect: rect.clone().into(),
|
clip_rect: rect.clone().into(),
|
||||||
clip_id: wr::ClipId::root(builder.pipeline_id),
|
clip_id: wr::ClipId::root(builder.pipeline_id),
|
||||||
spatial_id: wr::SpatialId::root_scroll_node(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.
|
// TODO(gw): Make use of the WR backface visibility functionality.
|
||||||
flags: PrimitiveFlags::default(),
|
flags: PrimitiveFlags::default(),
|
||||||
};
|
};
|
||||||
|
@ -119,11 +122,12 @@ impl BoxFragment {
|
||||||
.to_physical(self.style.writing_mode, containing_block)
|
.to_physical(self.style.writing_mode, containing_block)
|
||||||
.translate(&containing_block.top_left)
|
.translate(&containing_block.top_left)
|
||||||
.into();
|
.into();
|
||||||
|
let cursor = cursor(&self.style, Cursor::Default);
|
||||||
let common = CommonItemProperties {
|
let common = CommonItemProperties {
|
||||||
clip_rect: border_rect,
|
clip_rect: border_rect,
|
||||||
clip_id: wr::ClipId::root(builder.pipeline_id),
|
clip_id: wr::ClipId::root(builder.pipeline_id),
|
||||||
spatial_id: wr::SpatialId::root_scroll_node(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.
|
// TODO(gw): Make use of the WR backface visibility functionality.
|
||||||
flags: PrimitiveFlags::default(),
|
flags: PrimitiveFlags::default(),
|
||||||
};
|
};
|
||||||
|
@ -147,7 +151,7 @@ impl BoxFragment {
|
||||||
let background_color = self
|
let background_color = self
|
||||||
.style
|
.style
|
||||||
.resolve_color(self.style.clone_background_color());
|
.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))
|
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
|
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,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue