mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
style: Move cursor property out of mako
This commit is contained in:
parent
671b69c0b7
commit
4ee9eb8563
17 changed files with 413 additions and 360 deletions
|
@ -5302,53 +5302,50 @@ clip-path
|
|||
<%self:impl_trait style_struct_name="Pointing"
|
||||
skip_longhands="cursor caret-color">
|
||||
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
|
||||
use properties::longhands::cursor::computed_value::Keyword;
|
||||
use style_traits::cursor::Cursor;
|
||||
use style_traits::cursor::CursorKind;
|
||||
|
||||
self.gecko.mCursor = match v.keyword {
|
||||
Keyword::Auto => structs::NS_STYLE_CURSOR_AUTO,
|
||||
Keyword::Cursor(cursor) => match cursor {
|
||||
Cursor::None => structs::NS_STYLE_CURSOR_NONE,
|
||||
Cursor::Default => structs::NS_STYLE_CURSOR_DEFAULT,
|
||||
Cursor::Pointer => structs::NS_STYLE_CURSOR_POINTER,
|
||||
Cursor::ContextMenu => structs::NS_STYLE_CURSOR_CONTEXT_MENU,
|
||||
Cursor::Help => structs::NS_STYLE_CURSOR_HELP,
|
||||
Cursor::Progress => structs::NS_STYLE_CURSOR_SPINNING,
|
||||
Cursor::Wait => structs::NS_STYLE_CURSOR_WAIT,
|
||||
Cursor::Cell => structs::NS_STYLE_CURSOR_CELL,
|
||||
Cursor::Crosshair => structs::NS_STYLE_CURSOR_CROSSHAIR,
|
||||
Cursor::Text => structs::NS_STYLE_CURSOR_TEXT,
|
||||
Cursor::VerticalText => structs::NS_STYLE_CURSOR_VERTICAL_TEXT,
|
||||
Cursor::Alias => structs::NS_STYLE_CURSOR_ALIAS,
|
||||
Cursor::Copy => structs::NS_STYLE_CURSOR_COPY,
|
||||
Cursor::Move => structs::NS_STYLE_CURSOR_MOVE,
|
||||
Cursor::NoDrop => structs::NS_STYLE_CURSOR_NO_DROP,
|
||||
Cursor::NotAllowed => structs::NS_STYLE_CURSOR_NOT_ALLOWED,
|
||||
Cursor::Grab => structs::NS_STYLE_CURSOR_GRAB,
|
||||
Cursor::Grabbing => structs::NS_STYLE_CURSOR_GRABBING,
|
||||
Cursor::EResize => structs::NS_STYLE_CURSOR_E_RESIZE,
|
||||
Cursor::NResize => structs::NS_STYLE_CURSOR_N_RESIZE,
|
||||
Cursor::NeResize => structs::NS_STYLE_CURSOR_NE_RESIZE,
|
||||
Cursor::NwResize => structs::NS_STYLE_CURSOR_NW_RESIZE,
|
||||
Cursor::SResize => structs::NS_STYLE_CURSOR_S_RESIZE,
|
||||
Cursor::SeResize => structs::NS_STYLE_CURSOR_SE_RESIZE,
|
||||
Cursor::SwResize => structs::NS_STYLE_CURSOR_SW_RESIZE,
|
||||
Cursor::WResize => structs::NS_STYLE_CURSOR_W_RESIZE,
|
||||
Cursor::EwResize => structs::NS_STYLE_CURSOR_EW_RESIZE,
|
||||
Cursor::NsResize => structs::NS_STYLE_CURSOR_NS_RESIZE,
|
||||
Cursor::NeswResize => structs::NS_STYLE_CURSOR_NESW_RESIZE,
|
||||
Cursor::NwseResize => structs::NS_STYLE_CURSOR_NWSE_RESIZE,
|
||||
Cursor::ColResize => structs::NS_STYLE_CURSOR_COL_RESIZE,
|
||||
Cursor::RowResize => structs::NS_STYLE_CURSOR_ROW_RESIZE,
|
||||
Cursor::AllScroll => structs::NS_STYLE_CURSOR_ALL_SCROLL,
|
||||
Cursor::ZoomIn => structs::NS_STYLE_CURSOR_ZOOM_IN,
|
||||
Cursor::ZoomOut => structs::NS_STYLE_CURSOR_ZOOM_OUT,
|
||||
// note: the following properties are gecko-only.
|
||||
Cursor::MozGrab => structs::NS_STYLE_CURSOR_GRAB,
|
||||
Cursor::MozGrabbing => structs::NS_STYLE_CURSOR_GRABBING,
|
||||
Cursor::MozZoomIn => structs::NS_STYLE_CURSOR_ZOOM_IN,
|
||||
Cursor::MozZoomOut => structs::NS_STYLE_CURSOR_ZOOM_OUT,
|
||||
}
|
||||
CursorKind::Auto => structs::NS_STYLE_CURSOR_AUTO,
|
||||
CursorKind::None => structs::NS_STYLE_CURSOR_NONE,
|
||||
CursorKind::Default => structs::NS_STYLE_CURSOR_DEFAULT,
|
||||
CursorKind::Pointer => structs::NS_STYLE_CURSOR_POINTER,
|
||||
CursorKind::ContextMenu => structs::NS_STYLE_CURSOR_CONTEXT_MENU,
|
||||
CursorKind::Help => structs::NS_STYLE_CURSOR_HELP,
|
||||
CursorKind::Progress => structs::NS_STYLE_CURSOR_SPINNING,
|
||||
CursorKind::Wait => structs::NS_STYLE_CURSOR_WAIT,
|
||||
CursorKind::Cell => structs::NS_STYLE_CURSOR_CELL,
|
||||
CursorKind::Crosshair => structs::NS_STYLE_CURSOR_CROSSHAIR,
|
||||
CursorKind::Text => structs::NS_STYLE_CURSOR_TEXT,
|
||||
CursorKind::VerticalText => structs::NS_STYLE_CURSOR_VERTICAL_TEXT,
|
||||
CursorKind::Alias => structs::NS_STYLE_CURSOR_ALIAS,
|
||||
CursorKind::Copy => structs::NS_STYLE_CURSOR_COPY,
|
||||
CursorKind::Move => structs::NS_STYLE_CURSOR_MOVE,
|
||||
CursorKind::NoDrop => structs::NS_STYLE_CURSOR_NO_DROP,
|
||||
CursorKind::NotAllowed => structs::NS_STYLE_CURSOR_NOT_ALLOWED,
|
||||
CursorKind::Grab => structs::NS_STYLE_CURSOR_GRAB,
|
||||
CursorKind::Grabbing => structs::NS_STYLE_CURSOR_GRABBING,
|
||||
CursorKind::EResize => structs::NS_STYLE_CURSOR_E_RESIZE,
|
||||
CursorKind::NResize => structs::NS_STYLE_CURSOR_N_RESIZE,
|
||||
CursorKind::NeResize => structs::NS_STYLE_CURSOR_NE_RESIZE,
|
||||
CursorKind::NwResize => structs::NS_STYLE_CURSOR_NW_RESIZE,
|
||||
CursorKind::SResize => structs::NS_STYLE_CURSOR_S_RESIZE,
|
||||
CursorKind::SeResize => structs::NS_STYLE_CURSOR_SE_RESIZE,
|
||||
CursorKind::SwResize => structs::NS_STYLE_CURSOR_SW_RESIZE,
|
||||
CursorKind::WResize => structs::NS_STYLE_CURSOR_W_RESIZE,
|
||||
CursorKind::EwResize => structs::NS_STYLE_CURSOR_EW_RESIZE,
|
||||
CursorKind::NsResize => structs::NS_STYLE_CURSOR_NS_RESIZE,
|
||||
CursorKind::NeswResize => structs::NS_STYLE_CURSOR_NESW_RESIZE,
|
||||
CursorKind::NwseResize => structs::NS_STYLE_CURSOR_NWSE_RESIZE,
|
||||
CursorKind::ColResize => structs::NS_STYLE_CURSOR_COL_RESIZE,
|
||||
CursorKind::RowResize => structs::NS_STYLE_CURSOR_ROW_RESIZE,
|
||||
CursorKind::AllScroll => structs::NS_STYLE_CURSOR_ALL_SCROLL,
|
||||
CursorKind::ZoomIn => structs::NS_STYLE_CURSOR_ZOOM_IN,
|
||||
CursorKind::ZoomOut => structs::NS_STYLE_CURSOR_ZOOM_OUT,
|
||||
// note: the following properties are gecko-only.
|
||||
CursorKind::MozGrab => structs::NS_STYLE_CURSOR_GRAB,
|
||||
CursorKind::MozGrabbing => structs::NS_STYLE_CURSOR_GRABBING,
|
||||
CursorKind::MozZoomIn => structs::NS_STYLE_CURSOR_ZOOM_IN,
|
||||
CursorKind::MozZoomOut => structs::NS_STYLE_CURSOR_ZOOM_OUT,
|
||||
} as u8;
|
||||
|
||||
unsafe {
|
||||
|
@ -5390,47 +5387,47 @@ clip-path
|
|||
}
|
||||
|
||||
pub fn clone_cursor(&self) -> longhands::cursor::computed_value::T {
|
||||
use properties::longhands::cursor::computed_value::{Keyword, Image};
|
||||
use style_traits::cursor::Cursor;
|
||||
use values::computed::pointing::CursorImage;
|
||||
use style_traits::cursor::CursorKind;
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
let keyword = match self.gecko.mCursor as u32 {
|
||||
structs::NS_STYLE_CURSOR_AUTO => Keyword::Auto,
|
||||
structs::NS_STYLE_CURSOR_NONE => Keyword::Cursor(Cursor::None),
|
||||
structs::NS_STYLE_CURSOR_DEFAULT => Keyword::Cursor(Cursor::Default),
|
||||
structs::NS_STYLE_CURSOR_POINTER => Keyword::Cursor(Cursor::Pointer),
|
||||
structs::NS_STYLE_CURSOR_CONTEXT_MENU => Keyword::Cursor(Cursor::ContextMenu),
|
||||
structs::NS_STYLE_CURSOR_HELP => Keyword::Cursor(Cursor::Help),
|
||||
structs::NS_STYLE_CURSOR_SPINNING => Keyword::Cursor(Cursor::Progress),
|
||||
structs::NS_STYLE_CURSOR_WAIT => Keyword::Cursor(Cursor::Wait),
|
||||
structs::NS_STYLE_CURSOR_CELL => Keyword::Cursor(Cursor::Cell),
|
||||
structs::NS_STYLE_CURSOR_CROSSHAIR => Keyword::Cursor(Cursor::Crosshair),
|
||||
structs::NS_STYLE_CURSOR_TEXT => Keyword::Cursor(Cursor::Text),
|
||||
structs::NS_STYLE_CURSOR_VERTICAL_TEXT => Keyword::Cursor(Cursor::VerticalText),
|
||||
structs::NS_STYLE_CURSOR_ALIAS => Keyword::Cursor(Cursor::Alias),
|
||||
structs::NS_STYLE_CURSOR_COPY => Keyword::Cursor(Cursor::Copy),
|
||||
structs::NS_STYLE_CURSOR_MOVE => Keyword::Cursor(Cursor::Move),
|
||||
structs::NS_STYLE_CURSOR_NO_DROP => Keyword::Cursor(Cursor::NoDrop),
|
||||
structs::NS_STYLE_CURSOR_NOT_ALLOWED => Keyword::Cursor(Cursor::NotAllowed),
|
||||
structs::NS_STYLE_CURSOR_GRAB => Keyword::Cursor(Cursor::Grab),
|
||||
structs::NS_STYLE_CURSOR_GRABBING => Keyword::Cursor(Cursor::Grabbing),
|
||||
structs::NS_STYLE_CURSOR_E_RESIZE => Keyword::Cursor(Cursor::EResize),
|
||||
structs::NS_STYLE_CURSOR_N_RESIZE => Keyword::Cursor(Cursor::NResize),
|
||||
structs::NS_STYLE_CURSOR_NE_RESIZE => Keyword::Cursor(Cursor::NeResize),
|
||||
structs::NS_STYLE_CURSOR_NW_RESIZE => Keyword::Cursor(Cursor::NwResize),
|
||||
structs::NS_STYLE_CURSOR_S_RESIZE => Keyword::Cursor(Cursor::SResize),
|
||||
structs::NS_STYLE_CURSOR_SE_RESIZE => Keyword::Cursor(Cursor::SeResize),
|
||||
structs::NS_STYLE_CURSOR_SW_RESIZE => Keyword::Cursor(Cursor::SwResize),
|
||||
structs::NS_STYLE_CURSOR_W_RESIZE => Keyword::Cursor(Cursor::WResize),
|
||||
structs::NS_STYLE_CURSOR_EW_RESIZE => Keyword::Cursor(Cursor::EwResize),
|
||||
structs::NS_STYLE_CURSOR_NS_RESIZE => Keyword::Cursor(Cursor::NsResize),
|
||||
structs::NS_STYLE_CURSOR_NESW_RESIZE => Keyword::Cursor(Cursor::NeswResize),
|
||||
structs::NS_STYLE_CURSOR_NWSE_RESIZE => Keyword::Cursor(Cursor::NwseResize),
|
||||
structs::NS_STYLE_CURSOR_COL_RESIZE => Keyword::Cursor(Cursor::ColResize),
|
||||
structs::NS_STYLE_CURSOR_ROW_RESIZE => Keyword::Cursor(Cursor::RowResize),
|
||||
structs::NS_STYLE_CURSOR_ALL_SCROLL => Keyword::Cursor(Cursor::AllScroll),
|
||||
structs::NS_STYLE_CURSOR_ZOOM_IN => Keyword::Cursor(Cursor::ZoomIn),
|
||||
structs::NS_STYLE_CURSOR_ZOOM_OUT => Keyword::Cursor(Cursor::ZoomOut),
|
||||
structs::NS_STYLE_CURSOR_AUTO => CursorKind::Auto,
|
||||
structs::NS_STYLE_CURSOR_NONE => CursorKind::None,
|
||||
structs::NS_STYLE_CURSOR_DEFAULT => CursorKind::Default,
|
||||
structs::NS_STYLE_CURSOR_POINTER => CursorKind::Pointer,
|
||||
structs::NS_STYLE_CURSOR_CONTEXT_MENU => CursorKind::ContextMenu,
|
||||
structs::NS_STYLE_CURSOR_HELP => CursorKind::Help,
|
||||
structs::NS_STYLE_CURSOR_SPINNING => CursorKind::Progress,
|
||||
structs::NS_STYLE_CURSOR_WAIT => CursorKind::Wait,
|
||||
structs::NS_STYLE_CURSOR_CELL => CursorKind::Cell,
|
||||
structs::NS_STYLE_CURSOR_CROSSHAIR => CursorKind::Crosshair,
|
||||
structs::NS_STYLE_CURSOR_TEXT => CursorKind::Text,
|
||||
structs::NS_STYLE_CURSOR_VERTICAL_TEXT => CursorKind::VerticalText,
|
||||
structs::NS_STYLE_CURSOR_ALIAS => CursorKind::Alias,
|
||||
structs::NS_STYLE_CURSOR_COPY => CursorKind::Copy,
|
||||
structs::NS_STYLE_CURSOR_MOVE => CursorKind::Move,
|
||||
structs::NS_STYLE_CURSOR_NO_DROP => CursorKind::NoDrop,
|
||||
structs::NS_STYLE_CURSOR_NOT_ALLOWED => CursorKind::NotAllowed,
|
||||
structs::NS_STYLE_CURSOR_GRAB => CursorKind::Grab,
|
||||
structs::NS_STYLE_CURSOR_GRABBING => CursorKind::Grabbing,
|
||||
structs::NS_STYLE_CURSOR_E_RESIZE => CursorKind::EResize,
|
||||
structs::NS_STYLE_CURSOR_N_RESIZE => CursorKind::NResize,
|
||||
structs::NS_STYLE_CURSOR_NE_RESIZE => CursorKind::NeResize,
|
||||
structs::NS_STYLE_CURSOR_NW_RESIZE => CursorKind::NwResize,
|
||||
structs::NS_STYLE_CURSOR_S_RESIZE => CursorKind::SResize,
|
||||
structs::NS_STYLE_CURSOR_SE_RESIZE => CursorKind::SeResize,
|
||||
structs::NS_STYLE_CURSOR_SW_RESIZE => CursorKind::SwResize,
|
||||
structs::NS_STYLE_CURSOR_W_RESIZE => CursorKind::WResize,
|
||||
structs::NS_STYLE_CURSOR_EW_RESIZE => CursorKind::EwResize,
|
||||
structs::NS_STYLE_CURSOR_NS_RESIZE => CursorKind::NsResize,
|
||||
structs::NS_STYLE_CURSOR_NESW_RESIZE => CursorKind::NeswResize,
|
||||
structs::NS_STYLE_CURSOR_NWSE_RESIZE => CursorKind::NwseResize,
|
||||
structs::NS_STYLE_CURSOR_COL_RESIZE => CursorKind::ColResize,
|
||||
structs::NS_STYLE_CURSOR_ROW_RESIZE => CursorKind::RowResize,
|
||||
structs::NS_STYLE_CURSOR_ALL_SCROLL => CursorKind::AllScroll,
|
||||
structs::NS_STYLE_CURSOR_ZOOM_IN => CursorKind::ZoomIn,
|
||||
structs::NS_STYLE_CURSOR_ZOOM_OUT => CursorKind::ZoomOut,
|
||||
_ => panic!("Found unexpected value in style struct for cursor property"),
|
||||
};
|
||||
|
||||
|
@ -5448,8 +5445,8 @@ clip-path
|
|||
None
|
||||
};
|
||||
|
||||
Image { url, hotspot }
|
||||
}).collect();
|
||||
CursorImage { url, hotspot }
|
||||
}).collect::<Vec<_>>().into_boxed_slice();
|
||||
|
||||
longhands::cursor::computed_value::T { images, keyword }
|
||||
}
|
||||
|
|
|
@ -6,142 +6,12 @@
|
|||
|
||||
<% data.new_style_struct("Pointing", inherited=True, gecko_name="UserInterface") %>
|
||||
|
||||
<%helpers:longhand name="cursor" boxed="${product == 'gecko'}" animation_value_type="discrete"
|
||||
spec="https://drafts.csswg.org/css-ui/#cursor">
|
||||
pub use self::computed_value::T as SpecifiedValue;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
pub mod computed_value {
|
||||
#[cfg(feature = "gecko")]
|
||||
use std::fmt;
|
||||
#[cfg(feature = "gecko")]
|
||||
use style_traits::ToCss;
|
||||
use style_traits::cursor::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub enum Keyword {
|
||||
Auto,
|
||||
Cursor(Cursor),
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub type T = Keyword;
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct Image {
|
||||
pub url: SpecifiedUrl,
|
||||
pub hotspot: Option<(f32, f32)>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct T {
|
||||
pub images: Vec<Image>,
|
||||
pub keyword: Keyword,
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToCss for Image {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.url.to_css(dest)?;
|
||||
if let Some((x, y)) = self.hotspot {
|
||||
dest.write_str(" ")?;
|
||||
x.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
y.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToCss for T {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
for url in &self.images {
|
||||
url.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
}
|
||||
self.keyword.to_css(dest)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::Keyword::Auto
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T {
|
||||
images: vec![],
|
||||
keyword: computed_value::Keyword::Auto
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for computed_value::Keyword {
|
||||
fn parse<'i, 't>(_context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<computed_value::Keyword, ParseError<'i>> {
|
||||
#[allow(unused_imports)] use std::ascii::AsciiExt;
|
||||
use style_traits::cursor::Cursor;
|
||||
let location = input.current_source_location();
|
||||
let ident = input.expect_ident()?;
|
||||
if ident.eq_ignore_ascii_case("auto") {
|
||||
Ok(computed_value::Keyword::Auto)
|
||||
} else {
|
||||
Cursor::from_css_keyword(&ident)
|
||||
.map(computed_value::Keyword::Cursor)
|
||||
.map_err(|()| location.new_custom_error(SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
fn parse_image<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<computed_value::Image, ParseError<'i>> {
|
||||
Ok(computed_value::Image {
|
||||
url: SpecifiedUrl::parse(context, input)?,
|
||||
hotspot: match input.try(|input| input.expect_number()) {
|
||||
Ok(number) => Some((number, input.expect_number()?)),
|
||||
Err(_) => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "gecko"))]
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
computed_value::Keyword::parse(context, input)
|
||||
}
|
||||
|
||||
/// cursor: [<url> [<number> <number>]?]# [auto | default | ...]
|
||||
#[cfg(feature = "gecko")]
|
||||
pub fn parse<'i, 't>(context: &ParserContext, input: &mut Parser<'i, 't>)
|
||||
-> Result<SpecifiedValue, ParseError<'i>> {
|
||||
let mut images = vec![];
|
||||
loop {
|
||||
match input.try(|input| parse_image(context, input)) {
|
||||
Ok(mut image) => {
|
||||
image.url.build_image_value();
|
||||
images.push(image)
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
input.expect_comma()?;
|
||||
}
|
||||
|
||||
Ok(computed_value::T {
|
||||
images: images,
|
||||
keyword: computed_value::Keyword::parse(context, input)?,
|
||||
})
|
||||
}
|
||||
</%helpers:longhand>
|
||||
${helpers.predefined_type("cursor",
|
||||
"Cursor",
|
||||
"computed::Cursor::auto()",
|
||||
initial_specified_value="specified::Cursor::auto()",
|
||||
animation_value_type="discrete",
|
||||
spec="https://drafts.csswg.org/css-ui/#cursor")}
|
||||
|
||||
// NB: `pointer-events: auto` (and use of `pointer-events` in anything that isn't SVG, in fact)
|
||||
// is nonstandard, slated for CSS4-UI.
|
||||
|
|
|
@ -20,7 +20,7 @@ use std::cell::RefCell;
|
|||
#[cfg(feature = "servo")]
|
||||
use std::sync::Arc;
|
||||
use style_traits::ToCss;
|
||||
use style_traits::cursor::Cursor;
|
||||
use style_traits::cursor::CursorKind;
|
||||
use super::{CSSFloat, CSSInteger};
|
||||
use super::generics::{GreaterThanOrEqualToOne, NonNegative};
|
||||
use super::generics::grid::{GridLine as GenericGridLine, TrackBreadth as GenericTrackBreadth};
|
||||
|
@ -61,6 +61,9 @@ pub use self::list::ListStyleType;
|
|||
pub use self::outline::OutlineStyle;
|
||||
pub use self::percentage::Percentage;
|
||||
pub use self::position::{Position, GridAutoFlow, GridTemplateAreas};
|
||||
pub use self::pointing::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::pointing::CursorImage;
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::svg::MozContextProperties;
|
||||
|
@ -90,6 +93,7 @@ pub mod length;
|
|||
pub mod list;
|
||||
pub mod outline;
|
||||
pub mod percentage;
|
||||
pub mod pointing;
|
||||
pub mod position;
|
||||
pub mod rect;
|
||||
pub mod svg;
|
||||
|
@ -404,7 +408,7 @@ trivial_to_computed_value!(u16);
|
|||
trivial_to_computed_value!(u32);
|
||||
trivial_to_computed_value!(Atom);
|
||||
trivial_to_computed_value!(BorderStyle);
|
||||
trivial_to_computed_value!(Cursor);
|
||||
trivial_to_computed_value!(CursorKind);
|
||||
trivial_to_computed_value!(Namespace);
|
||||
trivial_to_computed_value!(String);
|
||||
trivial_to_computed_value!(Box<str>);
|
||||
|
|
138
components/style/values/computed/pointing.rs
Normal file
138
components/style/values/computed/pointing.rs
Normal file
|
@ -0,0 +1,138 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Computed values for Pointing properties.
|
||||
//!
|
||||
//! https://drafts.csswg.org/css-ui/#pointing-keyboard
|
||||
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
use selectors::parser::SelectorParseErrorKind;
|
||||
#[cfg(feature = "gecko")]
|
||||
use std::fmt;
|
||||
use style_traits::ParseError;
|
||||
#[cfg(feature = "gecko")]
|
||||
use style_traits::ToCss;
|
||||
use style_traits::cursor::CursorKind;
|
||||
|
||||
/// The computed value for the `cursor` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-ui/#cursor
|
||||
pub use values::specified::pointing::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use values::specified::pointing::CursorImage;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
impl Cursor {
|
||||
/// Set `cursor` to `auto`
|
||||
#[cfg(feature = "servo")]
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
Cursor(CursorKind::Auto)
|
||||
}
|
||||
|
||||
/// Set `cursor` to `auto`
|
||||
#[cfg(feature = "gecko")]
|
||||
#[inline]
|
||||
pub fn auto() -> Self {
|
||||
Self {
|
||||
images: vec![].into_boxed_slice(),
|
||||
keyword: CursorKind::Auto
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for Cursor {
|
||||
/// cursor: [auto | default | ...]
|
||||
#[cfg(feature = "servo")]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(Cursor(CursorKind::parse(context, input)?))
|
||||
}
|
||||
|
||||
/// cursor: [<url> [<number> <number>]?]# [auto | default | ...]
|
||||
#[cfg(feature = "gecko")]
|
||||
fn parse<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let mut images = vec![];
|
||||
loop {
|
||||
match input.try(|input| CursorImage::parse_image(context, input)) {
|
||||
Ok(mut image) => {
|
||||
image.url.build_image_value();
|
||||
images.push(image)
|
||||
}
|
||||
Err(_) => break,
|
||||
}
|
||||
input.expect_comma()?;
|
||||
}
|
||||
Ok(Self {
|
||||
images: images.into_boxed_slice(),
|
||||
keyword: CursorKind::parse(context, input)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToCss for Cursor {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write
|
||||
{
|
||||
for url in &*self.images {
|
||||
url.to_css(dest)?;
|
||||
dest.write_str(", ")?;
|
||||
}
|
||||
self.keyword.to_css(dest)
|
||||
}
|
||||
}
|
||||
|
||||
impl Parse for CursorKind {
|
||||
fn parse<'i, 't>(
|
||||
_context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
let location = input.current_source_location();
|
||||
let ident = input.expect_ident()?;
|
||||
CursorKind::from_css_keyword(&ident)
|
||||
.map_err(|_| location.new_custom_error(
|
||||
SelectorParseErrorKind::UnexpectedIdent(ident.clone())))
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl CursorImage {
|
||||
fn parse_image<'i, 't>(
|
||||
context: &ParserContext,
|
||||
input: &mut Parser<'i, 't>
|
||||
) -> Result<Self, ParseError<'i>> {
|
||||
Ok(Self {
|
||||
url: SpecifiedUrl::parse(context, input)?,
|
||||
// FIXME(emilio): Should use Number::parse to handle calc() correctly.
|
||||
hotspot: match input.try(|input| input.expect_number()) {
|
||||
Ok(number) => Some((number, input.expect_number()?)),
|
||||
Err(_) => None,
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ToCss for CursorImage {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
|
||||
where W: fmt::Write
|
||||
{
|
||||
self.url.to_css(dest)?;
|
||||
if let Some((x, y)) = self.hotspot {
|
||||
dest.write_str(" ")?;
|
||||
x.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
y.to_css(dest)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
|
@ -57,6 +57,9 @@ pub use self::outline::OutlineStyle;
|
|||
pub use self::rect::LengthOrNumberRect;
|
||||
pub use self::percentage::Percentage;
|
||||
pub use self::position::{Position, PositionComponent, GridAutoFlow, GridTemplateAreas};
|
||||
pub use self::pointing::Cursor;
|
||||
#[cfg(feature = "gecko")]
|
||||
pub use self::pointing::CursorImage;
|
||||
pub use self::svg::{SVGLength, SVGOpacity, SVGPaint, SVGPaintKind};
|
||||
pub use self::svg::{SVGPaintOrder, SVGStrokeDashArray, SVGWidth};
|
||||
pub use self::svg::MozContextProperties;
|
||||
|
@ -90,6 +93,7 @@ pub mod length;
|
|||
pub mod list;
|
||||
pub mod outline;
|
||||
pub mod percentage;
|
||||
pub mod pointing;
|
||||
pub mod position;
|
||||
pub mod rect;
|
||||
pub mod source_size_list;
|
||||
|
|
40
components/style/values/specified/pointing.rs
Normal file
40
components/style/values/specified/pointing.rs
Normal file
|
@ -0,0 +1,40 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
//! Specified values for Pointing properties.
|
||||
//!
|
||||
//! https://drafts.csswg.org/css-ui/#pointing-keyboard
|
||||
|
||||
use style_traits::cursor::CursorKind;
|
||||
#[cfg(feature = "gecko")]
|
||||
use values::specified::url::SpecifiedUrl;
|
||||
|
||||
/// The specified value for the `cursor` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-ui/#cursor
|
||||
#[cfg(feature = "servo")]
|
||||
#[derive(Clone, Copy, Debug, MallocSizeOf, PartialEq, ToComputedValue, ToCss)]
|
||||
pub struct Cursor(pub CursorKind);
|
||||
|
||||
/// The specified value for the `cursor` property.
|
||||
///
|
||||
/// https://drafts.csswg.org/css-ui/#cursor
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct Cursor {
|
||||
/// The parsed images for the cursor.
|
||||
pub images: Box<[CursorImage]>,
|
||||
/// The kind of the cursor [default | help | ...].
|
||||
pub keyword: CursorKind,
|
||||
}
|
||||
|
||||
/// The specified value for the `image cursors`.
|
||||
#[cfg(feature = "gecko")]
|
||||
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToComputedValue)]
|
||||
pub struct CursorImage {
|
||||
/// The url to parse images from.
|
||||
pub url: SpecifiedUrl,
|
||||
/// The <x> and <y> coordinates.
|
||||
pub hotspot: Option<(f32, f32)>,
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue