Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert layout code to use logical directions #2797

Closed
wants to merge 4 commits into from
Closed
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Next

Move CSS Writing Modes properties behind a new command-line flag.

  • Loading branch information
SimonSapin committed Jul 11, 2014
commit 92971fbd653879471477d3dde6c419c91fa31e8c
@@ -94,6 +94,7 @@ pub extern "C" fn android_start(argc: int, argv: **u8) -> int {

#[cfg(not(test))]
pub fn run(opts: opts::Opts) {
::servo_util::opts::set_experimental_enabled(opts.enable_experimental);
let mut pool_config = green::PoolConfig::new();
pool_config.event_loop_factory = rustuv::event_loop;
let mut pool = green::SchedPool::new(pool_config);
@@ -35,14 +35,15 @@ def to_rust_ident(name):
return name
class Longhand(object):
def __init__(self, name, derived_from=None):
def __init__(self, name, derived_from=None, experimental=False):
self.name = name
self.ident = to_rust_ident(name)
self.camel_case, _ = re.subn(
"_([a-z])",
lambda m: m.group(1).upper(),
self.ident.strip("_").capitalize())
self.style_struct = THIS_STYLE_STRUCT
self.experimental = experimental
if derived_from is None:
self.derived_from = None
else:
@@ -94,12 +95,12 @@ pub mod longhands {
value
}

<%def name="raw_longhand(name, no_super=False, derived_from=None)">
<%def name="raw_longhand(name, no_super=False, derived_from=None, experimental=False)">
<%
if derived_from is not None:
derived_from = derived_from.split()
property = Longhand(name, derived_from=derived_from)
property = Longhand(name, derived_from=derived_from, experimental=experimental)
THIS_STYLE_STRUCT.longhands.append(property)
LONGHANDS.append(property)
LONGHANDS_BY_NAME[name] = property
@@ -128,8 +129,9 @@ pub mod longhands {
}
</%def>

<%def name="longhand(name, no_super=False, derived_from=None)">
<%self:raw_longhand name="${name}" derived_from="${derived_from}">
<%def name="longhand(name, no_super=False, derived_from=None, experimental=False)">
<%self:raw_longhand name="${name}" derived_from="${derived_from}"
experimental="${experimental}">
${caller.body()}
% if derived_from is None:
pub fn parse_specified(_input: &[ComponentValue], _base_url: &Url)
@@ -140,17 +142,18 @@ pub mod longhands {
</%self:raw_longhand>
</%def>

<%def name="single_component_value(name, derived_from=None)">
<%self:longhand name="${name}" derived_from="${derived_from}">
<%def name="single_component_value(name, derived_from=None, experimental=False)">
<%self:longhand name="${name}" derived_from="${derived_from}"
experimental="${experimental}">
${caller.body()}
pub fn parse(input: &[ComponentValue], base_url: &Url) -> Option<SpecifiedValue> {
one_component_value(input).and_then(|c| from_component_value(c, base_url))
}
</%self:longhand>
</%def>

<%def name="single_keyword_computed(name, values)">
<%self:single_component_value name="${name}">
<%def name="single_keyword_computed(name, values, experimental=False)">
<%self:single_component_value name="${name}" experimental="${experimental}">
${caller.body()}
pub mod computed_value {
#[allow(non_camel_case_types)]
@@ -179,9 +182,10 @@ pub mod longhands {
</%self:single_component_value>
</%def>

<%def name="single_keyword(name, values)">
<%def name="single_keyword(name, values, experimental=False)">
<%self:single_keyword_computed name="${name}"
values="${values}">
values="${values}"
experimental="${experimental}">
// The computed value is the same as the specified value.
pub use to_computed_value = super::computed_as_specified;
</%self:single_keyword_computed>
@@ -323,7 +327,7 @@ pub mod longhands {

${new_style_struct("InheritedBox", is_inherited=True)}

${single_keyword("direction", "ltr rtl")}
${single_keyword("direction", "ltr rtl", experimental=True)}

// CSS 2.1, Section 10 - Visual formatting model details

@@ -1041,11 +1045,11 @@ pub mod longhands {
// http://dev.w3.org/csswg/css-writing-modes/
${switch_to_style_struct("InheritedBox")}

${single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr")}
${single_keyword("writing-mode", "horizontal-tb vertical-rl vertical-lr", experimental=True)}

// FIXME(SimonSapin): Add 'mixed' and 'upright' (needs vertical text support)
// FIXME(SimonSapin): initial (first) value should be 'mixed', when that's implemented
${single_keyword("text-orientation", "sideways sideways-left sideways-right")}
${single_keyword("text-orientation", "sideways sideways-left sideways-right", experimental=True)}
}


@@ -1436,6 +1440,10 @@ pub fn parse_property_declaration_list<I: Iterator<Node>>(input: I, base_url: &U
match PropertyDeclaration::parse(n.as_slice(), v.as_slice(), list, base_url, seen) {
UnknownProperty => log_css_error(l, format!(
"Unsupported property: {}:{}", n, v.iter().to_css()).as_slice()),
ExperimentalProperty => log_css_error(l, format!(
"Experimental property, use `servo --enable_experimental` \
or `servo -e` to enable: {}:{}",
n, v.iter().to_css()).as_slice()),
InvalidValue => log_css_error(l, format!(
"Invalid value: {}:{}", n, v.iter().to_css()).as_slice()),
ValidOrIgnoredDeclaration => (),
@@ -1486,6 +1494,7 @@ pub enum PropertyDeclaration {

pub enum PropertyDeclarationParseResult {
UnknownProperty,
ExperimentalProperty,
InvalidValue,
ValidOrIgnoredDeclaration,
}
@@ -1502,6 +1511,11 @@ impl PropertyDeclaration {
% for property in LONGHANDS:
% if property.derived_from is None:
"${property.name}" => {
% if property.experimental:
if !::servo_util::opts::experimental_enabled() {
return ExperimentalProperty
}
% endif
if seen.get_${property.ident}() {
return ValidOrIgnoredDeclaration
}
@@ -45,10 +45,13 @@ pub struct Opts {
/// cause it to produce output on that interval (`-p`).
pub time_profiler_period: Option<f64>,

/// `None` to disable the memory profiler or `Some` with an interval in seconds to enable it
/// `None` to disable the memory profiler or `Some` with an interval in seconds to enable it
/// and cause it to produce output on that interval (`-m`).
pub memory_profiler_period: Option<f64>,

/// Enable experimental web features (`-e`).
pub enable_experimental: bool,

/// The number of threads to use for layout (`-y`). Defaults to 1, which results in a recursive
/// sequential algorithm.
pub layout_threads: uint,
@@ -87,6 +90,7 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
getopts::optopt("r", "rendering", "Rendering backend", "direct2d|core-graphics|core-graphics-accelerated|cairo|skia."),
getopts::optopt("s", "size", "Size of tiles", "512"),
getopts::optopt("", "device-pixel-ratio", "Device pixels per px", ""),
getopts::optflag("e", "experimental", "Enable experimental web features"),
getopts::optopt("t", "threads", "Number of render threads", "1"),
getopts::optflagopt("p", "profile", "Profiler flag and output interval", "10"),
getopts::optflagopt("m", "memory-profile", "Memory profiler flag and output interval", "10"),
@@ -176,6 +180,7 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
device_pixels_per_px: device_pixels_per_px,
time_profiler_period: time_profiler_period,
memory_profiler_period: memory_profiler_period,
enable_experimental: opt_match.opt_present("e"),
layout_threads: layout_threads,
exit_after_load: opt_match.opt_present("x"),
output_file: opt_match.opt_str("o"),
@@ -184,3 +189,17 @@ pub fn from_cmdline_args(args: &[String]) -> Option<Opts> {
bubble_widths_separately: opt_match.opt_present("b"),
})
}

static mut EXPERIMENTAL_ENABLED: bool = false;

pub fn set_experimental_enabled(new_value: bool) {
unsafe {
EXPERIMENTAL_ENABLED = new_value;
}
}

pub fn experimental_enabled() -> bool {
unsafe {
EXPERIMENTAL_ENABLED
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.