mirror of
https://github.com/servo/servo.git
synced 2025-08-07 14:35:33 +01:00
stylo: System font support for keyword font longhands
This commit is contained in:
parent
c1c4c8fa59
commit
b0dcb72722
7 changed files with 193 additions and 75 deletions
|
@ -2,7 +2,10 @@
|
|||
* 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/. */
|
||||
|
||||
<%! from data import Keyword, to_rust_ident, to_camel_case, LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES %>
|
||||
<%!
|
||||
from data import Keyword, to_rust_ident, to_camel_case
|
||||
from data import LOGICAL_SIDES, PHYSICAL_SIDES, LOGICAL_SIZES, SYSTEM_FONT_LONGHANDS
|
||||
%>
|
||||
|
||||
<%def name="predefined_type(name, type, initial_value, parse_method='parse',
|
||||
needs_context=True, vector=False, initial_specified_value=None, **kwargs)">
|
||||
|
@ -212,7 +215,6 @@
|
|||
% endif
|
||||
</%call>
|
||||
</%def>
|
||||
|
||||
<%def name="longhand(*args, **kwargs)">
|
||||
<%
|
||||
property = data.declare_longhand(*args, **kwargs)
|
||||
|
@ -278,7 +280,7 @@
|
|||
<% maybe_wm = ", wm" if property.logical else "" %>
|
||||
match *value {
|
||||
DeclaredValue::Value(ref specified_value) => {
|
||||
% if property.ident in "font_size font_family".split() and product == "gecko":
|
||||
% if property.ident in SYSTEM_FONT_LONGHANDS and product == "gecko":
|
||||
if let Some(sf) = specified_value.get_system() {
|
||||
longhands::system_font::resolve_system_font(sf, context);
|
||||
}
|
||||
|
@ -393,6 +395,110 @@
|
|||
}
|
||||
</%def>
|
||||
|
||||
<%def name="single_keyword_system(name, values, **kwargs)">
|
||||
<%
|
||||
keyword_kwargs = {a: kwargs.pop(a, None) for a in [
|
||||
'gecko_constant_prefix', 'gecko_enum_prefix',
|
||||
'extra_gecko_values', 'extra_servo_values',
|
||||
'custom_consts', 'gecko_inexhaustive',
|
||||
]}
|
||||
keyword = keyword=Keyword(name, values, **keyword_kwargs)
|
||||
%>
|
||||
<%call expr="longhand(name, keyword=Keyword(name, values, **keyword_kwargs), **kwargs)">
|
||||
use values::HasViewportPercentage;
|
||||
use properties::longhands::system_font::SystemFont;
|
||||
use std::fmt;
|
||||
use style_traits::ToCss;
|
||||
no_viewport_percentage!(SpecifiedValue);
|
||||
|
||||
pub mod computed_value {
|
||||
use cssparser::Parser;
|
||||
use parser::{Parse, ParserContext};
|
||||
|
||||
use style_traits::ToCss;
|
||||
define_css_keyword_enum! { T:
|
||||
% for value in keyword.values_for(product):
|
||||
"${value}" => ${to_rust_ident(value)},
|
||||
% endfor
|
||||
}
|
||||
|
||||
impl Parse for T {
|
||||
fn parse(_: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
|
||||
T::parse(input)
|
||||
}
|
||||
}
|
||||
|
||||
${gecko_keyword_conversion(keyword, keyword.values_for(product), type="T", cast_to="i32")}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Copy)]
|
||||
pub enum SpecifiedValue {
|
||||
Keyword(computed_value::T),
|
||||
System(SystemFont),
|
||||
}
|
||||
|
||||
impl ToCss for SpecifiedValue {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
match *self {
|
||||
SpecifiedValue::Keyword(k) => k.to_css(dest),
|
||||
SpecifiedValue::System(_) => Ok(())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parse(_: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
|
||||
Ok(SpecifiedValue::Keyword(computed_value::T::parse(input)?))
|
||||
}
|
||||
|
||||
impl ToComputedValue for SpecifiedValue {
|
||||
type ComputedValue = computed_value::T;
|
||||
fn to_computed_value(&self, _cx: &Context) -> Self::ComputedValue {
|
||||
match *self {
|
||||
SpecifiedValue::Keyword(v) => v,
|
||||
SpecifiedValue::System(_) => {
|
||||
% if product == "gecko":
|
||||
_cx.style.cached_system_font.as_ref().unwrap().${to_rust_ident(name)}
|
||||
% else:
|
||||
unreachable!()
|
||||
% endif
|
||||
}
|
||||
}
|
||||
}
|
||||
fn from_computed_value(other: &computed_value::T) -> Self {
|
||||
SpecifiedValue::Keyword(*other)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<computed_value::T> for SpecifiedValue {
|
||||
fn from(other: computed_value::T) -> Self {
|
||||
SpecifiedValue::Keyword(other)
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_initial_value() -> computed_value::T {
|
||||
computed_value::T::${to_rust_ident(values.split()[0])}
|
||||
}
|
||||
#[inline]
|
||||
pub fn get_initial_specified_value() -> SpecifiedValue {
|
||||
SpecifiedValue::Keyword(computed_value::T::${to_rust_ident(values.split()[0])})
|
||||
}
|
||||
|
||||
impl SpecifiedValue {
|
||||
pub fn system_font(f: SystemFont) -> Self {
|
||||
SpecifiedValue::System(f)
|
||||
}
|
||||
pub fn get_system(&self) -> Option<SystemFont> {
|
||||
if let SpecifiedValue::System(s) = *self {
|
||||
Some(s)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
</%call>
|
||||
</%def>
|
||||
|
||||
<%def name="single_keyword(name, values, vector=False, **kwargs)">
|
||||
<%call expr="single_keyword_computed(name, values, vector, **kwargs)">
|
||||
% if not "extra_specified" in kwargs and ("aliases" in kwargs or (("extra_%s_aliases" % product) in kwargs)):
|
||||
|
@ -426,10 +532,12 @@
|
|||
</%call>
|
||||
</%def>
|
||||
|
||||
<%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue')">
|
||||
<%def name="gecko_keyword_conversion(keyword, values=None, type='SpecifiedValue', cast_to=None)">
|
||||
<%
|
||||
if not values:
|
||||
values = keyword.values_for(product)
|
||||
maybe_cast = "as %s" % cast_to if cast_to else ""
|
||||
const_type = cast_to if cast_to else "u32"
|
||||
%>
|
||||
#[cfg(feature = "gecko")]
|
||||
impl ${type} {
|
||||
|
@ -438,26 +546,17 @@
|
|||
/// Intended for use with presentation attributes, not style structs
|
||||
pub fn from_gecko_keyword(kw: u32) -> Self {
|
||||
use gecko_bindings::structs;
|
||||
% if keyword.gecko_enum_prefix:
|
||||
% for value in values:
|
||||
// We can't match on enum values if we're matching on a u32
|
||||
const ${to_rust_ident(value).upper()}: ${const_type}
|
||||
= structs::${keyword.gecko_constant(value)} as ${const_type};
|
||||
% endfor
|
||||
match kw ${maybe_cast} {
|
||||
% for value in values:
|
||||
// We can't match on enum values if we're matching on a u32
|
||||
const ${to_rust_ident(value).upper()}: u32
|
||||
= structs::${keyword.gecko_enum_prefix}::${to_camel_case(value)} as u32;
|
||||
${to_rust_ident(value).upper()} => ${type}::${to_rust_ident(value)},
|
||||
% endfor
|
||||
match kw {
|
||||
% for value in values:
|
||||
${to_rust_ident(value).upper()} => ${type}::${to_rust_ident(value)},
|
||||
% endfor
|
||||
x => panic!("Found unexpected value in style struct for ${keyword.name} property: {:?}", x),
|
||||
}
|
||||
% else:
|
||||
match kw {
|
||||
% for value in values:
|
||||
structs::${keyword.gecko_constant(value)} => ${type}::${to_rust_ident(value)},
|
||||
% endfor
|
||||
x => panic!("Found unexpected value in style struct for ${keyword.name} property: {:?}", x),
|
||||
}
|
||||
% endif
|
||||
x => panic!("Found unexpected value in style struct for ${keyword.name} property: {:?}", x),
|
||||
}
|
||||
}
|
||||
}
|
||||
</%def>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue