style: Move cursor to cbindgen.

The only reason it was on style_traits is so that they could use it from some
other crates, but Servo eventually ends up getting the value from an integer, so
may as well pass it around and do that in the end of the process anyway.

Differential Revision: https://phabricator.services.mozilla.com/D16557
This commit is contained in:
Emilio Cobos Álvarez 2019-01-15 15:05:45 +01:00
parent 88fd730775
commit 92b58ade2f
8 changed files with 66 additions and 222 deletions

View file

@ -48,6 +48,7 @@ include = [
"ComputedFontStyleDescriptor",
"ComputedFontWeightRange",
"ComputedTimingFunction",
"CursorKind",
"Display",
"DisplayMode",
"ExtremumLength",

View file

@ -5162,52 +5162,7 @@ clip-path
<%self:impl_trait style_struct_name="InheritedUI"
skip_longhands="cursor scrollbar-color">
pub fn set_cursor(&mut self, v: longhands::cursor::computed_value::T) {
use style_traits::cursor::CursorKind;
self.gecko.mCursor = match v.keyword {
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;
self.gecko.mCursor = v.keyword;
unsafe {
Gecko_SetCursorArrayLength(&mut self.gecko, v.images.len());
}
@ -5246,47 +5201,8 @@ clip-path
pub fn clone_cursor(&self) -> longhands::cursor::computed_value::T {
use crate::values::computed::ui::CursorImage;
use crate::values::computed::url::ComputedImageUrl;
use style_traits::cursor::CursorKind;
let keyword = match self.gecko.mCursor as u32 {
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"),
};
let keyword = self.gecko.mCursor;
let images = self.gecko.mCursorImages.iter().map(|gecko_cursor_image| {
let url = unsafe {

View file

@ -28,7 +28,6 @@ use std::cell::RefCell;
use std::cmp;
use std::f32;
use std::fmt::{self, Write};
use style_traits::cursor::CursorKind;
use style_traits::{CssWriter, ToCss};
#[cfg(feature = "gecko")]
@ -452,7 +451,6 @@ trivial_to_computed_value!(u8);
trivial_to_computed_value!(u16);
trivial_to_computed_value!(u32);
trivial_to_computed_value!(Atom);
trivial_to_computed_value!(CursorKind);
#[cfg(feature = "servo")]
trivial_to_computed_value!(Prefix);
trivial_to_computed_value!(String);

View file

@ -10,6 +10,7 @@ use crate::values::computed::Number;
use crate::values::generics::ui as generics;
use crate::values::{Auto, Either};
pub use crate::values::specified::ui::CursorKind;
pub use crate::values::specified::ui::{MozForceBrokenImageIcon, UserSelect};
/// auto | <color>

View file

@ -5,7 +5,7 @@
//! Generic values for UI properties.
use std::fmt::{self, Write};
use style_traits::cursor::CursorKind;
use values::specified::ui::CursorKind;
use style_traits::{CssWriter, ToCss};
/// A generic value for the `cursor` property.

View file

@ -12,7 +12,6 @@ use crate::values::specified::Number;
use crate::values::{Auto, Either};
use cssparser::Parser;
use std::fmt::{self, Write};
use style_traits::cursor::CursorKind;
use style_traits::{CssWriter, ParseError, StyleParseErrorKind, ToCss};
/// auto | <color>
@ -40,23 +39,11 @@ impl Parse for Cursor {
}
Ok(Self {
images: images.into_boxed_slice(),
keyword: CursorKind::parse(context, input)?,
keyword: CursorKind::parse(input)?,
})
}
}
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(StyleParseErrorKind::UnspecifiedError))
}
}
impl Parse for CursorImage {
fn parse<'i, 't>(
context: &ParserContext,
@ -166,3 +153,63 @@ pub enum UserSelect {
/// Force selection of all children.
All,
}
/// The keywords allowed in the Cursor property.
///
/// https://drafts.csswg.org/css-ui-4/#propdef-cursor
#[allow(missing_docs)]
#[derive(
Clone,
Copy,
Debug,
Eq,
MallocSizeOf,
Parse,
PartialEq,
SpecifiedValueInfo,
ToComputedValue,
ToCss,
)]
#[repr(u8)]
pub enum CursorKind {
None,
Default,
Pointer,
ContextMenu,
Help,
Progress,
Wait,
Cell,
Crosshair,
Text,
VerticalText,
Alias,
Copy,
Move,
NoDrop,
NotAllowed,
Grab,
Grabbing,
EResize,
NResize,
NeResize,
NwResize,
SResize,
SeResize,
SwResize,
WResize,
EwResize,
NsResize,
NeswResize,
NwseResize,
ColResize,
RowResize,
AllScroll,
ZoomIn,
ZoomOut,
Auto,
MozGrab,
MozGrabbing,
MozZoomIn,
MozZoomOut,
}

View file

@ -1,118 +0,0 @@
/* 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 https://mozilla.org/MPL/2.0/. */
//! A list of common mouse cursors per CSS3-UI § 8.1.1.
use super::{CssWriter, KeywordsCollectFn, SpecifiedValueInfo, ToCss};
macro_rules! define_cursor {
(
common properties = [
$( $c_css: expr => $c_variant: ident = $c_value: expr, )+
]
gecko properties = [
$( $g_css: expr => $g_variant: ident = $g_value: expr, )+
]
) => {
/// <https://drafts.csswg.org/css-ui/#cursor>
#[derive(Clone, Copy, Debug, Eq, MallocSizeOf, PartialEq)]
#[cfg_attr(feature = "servo", derive(Deserialize, Serialize))]
#[repr(u8)]
#[allow(missing_docs)]
pub enum CursorKind {
$( $c_variant = $c_value, )+
$( #[cfg(feature = "gecko")] $g_variant = $g_value, )+
}
impl CursorKind {
/// Given a CSS keyword, get the corresponding cursor enum.
pub fn from_css_keyword(keyword: &str) -> Result<Self, ()> {
match_ignore_ascii_case! { &keyword,
$( $c_css => Ok(CursorKind::$c_variant), )+
$( #[cfg(feature = "gecko")] $g_css => Ok(CursorKind::$g_variant), )+
_ => Err(())
}
}
/// From the C u8 value, get the corresponding Cursor enum.
pub fn from_u8(value: u8) -> Result<Self, ()> {
match value {
$( $c_value => Ok(CursorKind::$c_variant), )+
$( #[cfg(feature = "gecko")] $g_value => Ok(CursorKind::$g_variant), )+
_ => Err(())
}
}
}
impl ToCss for CursorKind {
fn to_css<W>(&self, dest: &mut CssWriter<W>) -> ::std::fmt::Result where W: ::std::fmt::Write {
match *self {
$(CursorKind::$c_variant => {
::std::fmt::Write::write_str(dest, $c_css)
})+
$(#[cfg(feature = "gecko")] CursorKind::$g_variant => {
::std::fmt::Write::write_str(dest, $g_css)
})+
}
}
}
impl SpecifiedValueInfo for CursorKind {
fn collect_completion_keywords(f: KeywordsCollectFn) {
f(&[
$($c_css,)+
$($g_css,)+
]);
}
}
}
}
define_cursor! {
common properties = [
"none" => None = 0,
"default" => Default = 1,
"pointer" => Pointer = 2,
"context-menu" => ContextMenu = 3,
"help" => Help = 4,
"progress" => Progress = 5,
"wait" => Wait = 6,
"cell" => Cell = 7,
"crosshair" => Crosshair = 8,
"text" => Text = 9,
"vertical-text" => VerticalText = 10,
"alias" => Alias = 11,
"copy" => Copy = 12,
"move" => Move = 13,
"no-drop" => NoDrop = 14,
"not-allowed" => NotAllowed = 15,
"grab" => Grab = 16,
"grabbing" => Grabbing = 17,
"e-resize" => EResize = 18,
"n-resize" => NResize = 19,
"ne-resize" => NeResize = 20,
"nw-resize" => NwResize = 21,
"s-resize" => SResize = 22,
"se-resize" => SeResize = 23,
"sw-resize" => SwResize = 24,
"w-resize" => WResize = 25,
"ew-resize" => EwResize = 26,
"ns-resize" => NsResize = 27,
"nesw-resize" => NeswResize = 28,
"nwse-resize" => NwseResize = 29,
"col-resize" => ColResize = 30,
"row-resize" => RowResize = 31,
"all-scroll" => AllScroll = 32,
"zoom-in" => ZoomIn = 33,
"zoom-out" => ZoomOut = 34,
"auto" => Auto = 35,
]
// gecko only properties
gecko properties = [
"-moz-grab" => MozGrab = 36,
"-moz-grabbing" => MozGrabbing = 37,
"-moz-zoom-in" => MozZoomIn = 38,
"-moz-zoom-out" => MozZoomOut = 39,
]
}

View file

@ -81,7 +81,6 @@ pub enum CSSPixel {}
// / hidpi_ratio => DeviceIndependentPixel
// / desktop_zoom => CSSPixel
pub mod cursor;
pub mod specified_value_info;
#[macro_use]
pub mod values;