mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
style: Implement any-hover and any-pointer media queries features.
Differential Revision: https://phabricator.services.mozilla.com/D3609
This commit is contained in:
parent
9354a42fc1
commit
3d909132ba
1 changed files with 53 additions and 13 deletions
|
@ -310,6 +310,18 @@ bitflags! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn primary_pointer_capabilities(device: &Device) -> PointerCapabilities {
|
||||||
|
PointerCapabilities::from_bits_truncate(
|
||||||
|
unsafe { bindings::Gecko_MediaFeatures_PrimaryPointerCapabilities(device.document()) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn all_pointer_capabilities(device: &Device) -> PointerCapabilities {
|
||||||
|
PointerCapabilities::from_bits_truncate(
|
||||||
|
unsafe { bindings::Gecko_MediaFeatures_AllPointerCapabilities(device.document()) }
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, FromPrimitive, ToCss, Parse)]
|
#[derive(Debug, Copy, Clone, FromPrimitive, ToCss, Parse)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
enum Pointer {
|
enum Pointer {
|
||||||
|
@ -318,15 +330,10 @@ enum Pointer {
|
||||||
Fine,
|
Fine,
|
||||||
}
|
}
|
||||||
|
|
||||||
fn primary_pointer_capabilities(device: &Device) -> PointerCapabilities {
|
fn eval_pointer_capabilities(
|
||||||
PointerCapabilities::from_bits_truncate(
|
query_value: Option<Pointer>,
|
||||||
unsafe { bindings::Gecko_MediaFeatures_PrimaryPointerCapabilities(device.document()) }
|
pointer_capabilities: PointerCapabilities,
|
||||||
)
|
) -> bool {
|
||||||
}
|
|
||||||
|
|
||||||
/// https://drafts.csswg.org/mediaqueries-4/#pointer
|
|
||||||
fn eval_pointer(device: &Device, query_value: Option<Pointer>) -> bool {
|
|
||||||
let pointer_capabilities = primary_pointer_capabilities(device);
|
|
||||||
let query_value = match query_value {
|
let query_value = match query_value {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
None => return !pointer_capabilities.is_empty(),
|
None => return !pointer_capabilities.is_empty(),
|
||||||
|
@ -339,6 +346,16 @@ fn eval_pointer(device: &Device, query_value: Option<Pointer>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-4/#pointer
|
||||||
|
fn eval_pointer(device: &Device, query_value: Option<Pointer>) -> bool {
|
||||||
|
eval_pointer_capabilities(query_value, primary_pointer_capabilities(device))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-4/#descdef-media-any-pointer
|
||||||
|
fn eval_any_pointer(device: &Device, query_value: Option<Pointer>) -> bool {
|
||||||
|
eval_pointer_capabilities(query_value, all_pointer_capabilities(device))
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Copy, Clone, FromPrimitive, ToCss, Parse)]
|
#[derive(Debug, Copy, Clone, FromPrimitive, ToCss, Parse)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
enum Hover {
|
enum Hover {
|
||||||
|
@ -346,9 +363,10 @@ enum Hover {
|
||||||
Hover,
|
Hover,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// https://drafts.csswg.org/mediaqueries-4/#hover
|
fn eval_hover_capabilities(
|
||||||
fn eval_hover(device: &Device, query_value: Option<Hover>) -> bool {
|
query_value: Option<Hover>,
|
||||||
let pointer_capabilities = primary_pointer_capabilities(device);
|
pointer_capabilities: PointerCapabilities,
|
||||||
|
) -> bool {
|
||||||
let can_hover = pointer_capabilities.intersects(PointerCapabilities::HOVER);
|
let can_hover = pointer_capabilities.intersects(PointerCapabilities::HOVER);
|
||||||
let query_value = match query_value {
|
let query_value = match query_value {
|
||||||
Some(v) => v,
|
Some(v) => v,
|
||||||
|
@ -361,6 +379,16 @@ fn eval_hover(device: &Device, query_value: Option<Hover>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-4/#hover
|
||||||
|
fn eval_hover(device: &Device, query_value: Option<Hover>) -> bool {
|
||||||
|
eval_hover_capabilities(query_value, primary_pointer_capabilities(device))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// https://drafts.csswg.org/mediaqueries-4/#descdef-media-any-hover
|
||||||
|
fn eval_any_hover(device: &Device, query_value: Option<Hover>) -> bool {
|
||||||
|
eval_hover_capabilities(query_value, all_pointer_capabilities(device))
|
||||||
|
}
|
||||||
|
|
||||||
fn eval_moz_is_glyph(
|
fn eval_moz_is_glyph(
|
||||||
device: &Device,
|
device: &Device,
|
||||||
query_value: Option<bool>,
|
query_value: Option<bool>,
|
||||||
|
@ -451,7 +479,7 @@ lazy_static! {
|
||||||
/// to support new types in these entries and (2) ensuring that either
|
/// to support new types in these entries and (2) ensuring that either
|
||||||
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
/// nsPresContext::MediaFeatureValuesChanged is called when the value that
|
||||||
/// would be returned by the evaluator function could change.
|
/// would be returned by the evaluator function could change.
|
||||||
pub static ref MEDIA_FEATURES: [MediaFeatureDescription; 45] = [
|
pub static ref MEDIA_FEATURES: [MediaFeatureDescription; 47] = [
|
||||||
feature!(
|
feature!(
|
||||||
atom!("width"),
|
atom!("width"),
|
||||||
AllowsRanges::Yes,
|
AllowsRanges::Yes,
|
||||||
|
@ -576,12 +604,24 @@ lazy_static! {
|
||||||
keyword_evaluator!(eval_pointer, Pointer),
|
keyword_evaluator!(eval_pointer, Pointer),
|
||||||
ParsingRequirements::empty(),
|
ParsingRequirements::empty(),
|
||||||
),
|
),
|
||||||
|
feature!(
|
||||||
|
atom!("any-pointer"),
|
||||||
|
AllowsRanges::No,
|
||||||
|
keyword_evaluator!(eval_any_pointer, Pointer),
|
||||||
|
ParsingRequirements::empty(),
|
||||||
|
),
|
||||||
feature!(
|
feature!(
|
||||||
atom!("hover"),
|
atom!("hover"),
|
||||||
AllowsRanges::No,
|
AllowsRanges::No,
|
||||||
keyword_evaluator!(eval_hover, Hover),
|
keyword_evaluator!(eval_hover, Hover),
|
||||||
ParsingRequirements::empty(),
|
ParsingRequirements::empty(),
|
||||||
),
|
),
|
||||||
|
feature!(
|
||||||
|
atom!("any-hover"),
|
||||||
|
AllowsRanges::No,
|
||||||
|
keyword_evaluator!(eval_any_hover, Hover),
|
||||||
|
ParsingRequirements::empty(),
|
||||||
|
),
|
||||||
|
|
||||||
// Internal -moz-is-glyph media feature: applies only inside SVG glyphs.
|
// Internal -moz-is-glyph media feature: applies only inside SVG glyphs.
|
||||||
// Internal because it is really only useful in the user agent anyway
|
// Internal because it is really only useful in the user agent anyway
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue