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

use Either type for UrlOrNone #14370

Merged
merged 1 commit into from Dec 2, 2016
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

use Either type for UrlOrNone

fix test-tidy errors

fix style unit test

use the Parse trait instead of ParseWithContext

fix stylo test and geckolib build

move all specified url parse code to parse trait and remove refs to unused type
  • Loading branch information
thiagopnts committed Nov 30, 2016
commit 206f4ea5b83dcd7cfdab20b9fb67387ce66f1880
@@ -45,7 +45,7 @@ use std::marker::PhantomData;
use std::mem;
use std::sync::Arc;
use std::sync::atomic::Ordering;
use style::computed_values::{caption_side, display, empty_cells, float, list_style_image, list_style_position};
use style::computed_values::{caption_side, display, empty_cells, float, list_style_position};
use style::computed_values::content::ContentItem;
use style::computed_values::position;
use style::context::SharedStyleContext;
@@ -54,6 +54,7 @@ use style::properties::{self, ServoComputedValues};
use style::selector_parser::{PseudoElement, RestyleDamage};
use style::servo::restyle_damage::{BUBBLE_ISIZES, RECONSTRUCT_FLOW};
use style::stylist::Stylist;
use style::values::Either;
use table::TableFlow;
use table_caption::TableCaptionFlow;
use table_cell::TableCellFlow;
@@ -1205,13 +1206,13 @@ impl<'a, ConcreteThreadSafeLayoutNode: ThreadSafeLayoutNode>
-> ConstructionResult {
let flotation = FloatKind::from_property(flotation);
let marker_fragments = match node.style(self.style_context()).get_list().list_style_image {
list_style_image::T::Url(ref url_value) => {
Either::First(ref url_value) => {
let image_info = box ImageFragmentInfo::new(node,
url_value.url().map(|u| u.clone()),
&self.layout_context.shared);
vec![Fragment::new(node, SpecificFragmentInfo::Image(image_info), self.layout_context)]
}
list_style_image::T::None => {
Either::Second(_none) => {
match ListStyleTypeContent::from_list_style_type(node.style(self.style_context())
.get_list()
.list_style_type) {
@@ -8,7 +8,7 @@

use computed_values::font_family::FontFamily;
use cssparser::{AtRuleParser, DeclarationListParser, DeclarationParser, Parser};
use parser::{ParserContext, log_css_error};
use parser::{ParserContext, log_css_error, Parse};
use properties::longhands::font_family::parse_one_family;
use std::fmt;
use std::iter;
@@ -1089,10 +1089,10 @@ fn static_assert() {

#[allow(non_snake_case)]
pub fn set__moz_binding(&mut self, v: longhands::_moz_binding::computed_value::T) {
use properties::longhands::_moz_binding::computed_value::T as BindingValue;
use values::Either;
match v {
BindingValue::None => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
BindingValue::Url(ref url) => {
Either::Second(_none) => debug_assert!(self.gecko.mBinding.mRawPtr.is_null()),
Either::First(ref url) => {
let extra_data = url.extra_data();
let (ptr, len) = url.as_slice_components();
unsafe {
@@ -1593,14 +1593,14 @@ fn static_assert() {
skip_additionals="*">

pub fn set_list_style_image(&mut self, image: longhands::list_style_image::computed_value::T) {
use values::computed::UrlOrNone;
use values::Either;
match image {
UrlOrNone::None => {
Either::Second(_none) => {
unsafe {
Gecko_SetListStyleImageNone(&mut self.gecko);
}
}
UrlOrNone::Url(ref url) => {
Either::First(ref url) => {
let (ptr, len) = url.as_slice_components();
let extra_data = url.extra_data();
unsafe {
@@ -1551,7 +1551,7 @@ ${helpers.single_keyword("-moz-appearance",
animatable=False)}

// Non-standard: https://developer.mozilla.org/en-US/docs/Web/CSS/-moz-binding
${helpers.predefined_type("-moz-binding", "UrlOrNone", "computed_value::T::None",
${helpers.predefined_type("-moz-binding", "UrlOrNone", "Either::Second(None_)",
products="gecko",
animatable="False",
disable_when_testing="True")}
@@ -26,7 +26,7 @@ ${helpers.single_keyword("list-style-type", """
gecko_constant_prefix="NS_STYLE_LIST_STYLE",
animatable=False)}

${helpers.predefined_type("list-style-image", "UrlOrNone", "computed_value::T::None",
${helpers.predefined_type("list-style-image", "UrlOrNone", "Either::Second(None_)",
animatable="False")}

<%helpers:longhand name="quotes" animatable="False">
@@ -7,6 +7,7 @@
<%helpers:shorthand name="list-style"
sub_properties="list-style-image list-style-position list-style-type">
use properties::longhands::{list_style_image, list_style_position, list_style_type};
use values::{Either, None_};

pub fn parse_value(context: &ParserContext, input: &mut Parser) -> Result<Longhands, ()> {
// `none` is ambiguous until we've finished parsing the shorthands, so we count the number
@@ -56,7 +57,7 @@
(true, 2, None, None) => {
Ok(Longhands {
list_style_position: position,
list_style_image: Some(list_style_image::SpecifiedValue::None),
list_style_image: Some(Either::Second(None_)),
list_style_type: Some(list_style_type::SpecifiedValue::none),
})
}
@@ -70,14 +71,14 @@
(true, 1, Some(list_style_type), None) => {
Ok(Longhands {
list_style_position: position,
list_style_image: Some(list_style_image::SpecifiedValue::None),
list_style_image: Some(Either::Second(None_)),
list_style_type: Some(list_style_type),
})
}
(true, 1, None, None) => {
Ok(Longhands {
list_style_position: position,
list_style_image: Some(list_style_image::SpecifiedValue::None),
list_style_image: Some(Either::Second(None_)),
list_style_type: Some(list_style_type::SpecifiedValue::none),
})
}
@@ -5,14 +5,14 @@
use app_units::Au;
use cssparser::{self, Parser, Token};
use euclid::size::Size2D;
use parser::{Parse, ParserContext};
use parser::{ParserContext, Parse};
use self::url::SpecifiedUrl;
use std::ascii::AsciiExt;
use std::f32::consts::PI;
use std::fmt;
use std::ops::Mul;
use style_traits::ToCss;
use super::{CSSFloat, HasViewportPercentage, NoViewportPercentage};
use super::{CSSFloat, HasViewportPercentage, NoViewportPercentage, Either, None_};
use super::computed::{ComputedValueAsSpecified, Context, ToComputedValue};

pub use self::image::{AngleOrCorner, ColorStop, EndingShape as GradientEndingShape, Gradient};
@@ -515,31 +515,5 @@ impl ToCss for Opacity {
}
}

#[derive(PartialEq, Clone, Debug)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub enum UrlOrNone {
Url(SpecifiedUrl),
None,
}
pub type UrlOrNone = Either<SpecifiedUrl, None_>;

impl ComputedValueAsSpecified for UrlOrNone {}
impl NoViewportPercentage for UrlOrNone {}

impl ToCss for UrlOrNone {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
match *self {
UrlOrNone::Url(ref url) => url.to_css(dest),
UrlOrNone::None => dest.write_str("none"),
}
}
}

impl UrlOrNone {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<UrlOrNone, ()> {
if input.try(|input| input.expect_ident_matching("none")).is_ok() {
return Ok(UrlOrNone::None);
}

Ok(UrlOrNone::Url(try!(SpecifiedUrl::parse(context, input))))
}
}
@@ -7,14 +7,15 @@
use cssparser::{CssStringWriter, Parser};
#[cfg(feature = "gecko")]
use gecko_bindings::sugar::refptr::{GeckoArcPrincipal, GeckoArcURI};
use parser::ParserContext;
use parser::{Parse, ParserContext};
#[cfg(feature = "gecko")]
use parser::ParserContextExtraData;
use servo_url::ServoUrl;
use std::fmt::{self, Write};
use std::ptr;
use std::sync::Arc;
use style_traits::ToCss;
use values::NoViewportPercentage;
use values::computed::ComputedValueAsSpecified;

#[derive(PartialEq, Clone, Debug)]
@@ -72,8 +73,8 @@ pub struct SpecifiedUrl {
extra_data: UrlExtraData,
}

impl SpecifiedUrl {
pub fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
impl Parse for SpecifiedUrl {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
let url = try!(input.expect_url());

let extra_data = match UrlExtraData::make_from(context) {
@@ -95,7 +96,9 @@ impl SpecifiedUrl {
extra_data: extra_data,
})
}
}

impl SpecifiedUrl {
pub fn extra_data(&self) -> &UrlExtraData {
&self.extra_data
}
@@ -171,3 +174,5 @@ impl ToCss for SpecifiedUrl {

// TODO(emilio): Maybe consider ComputedUrl to save a word in style structs?
impl ComputedValueAsSpecified for SpecifiedUrl {}

impl NoViewportPercentage for SpecifiedUrl {}
@@ -418,17 +418,17 @@ mod shorthand_serialization {
}

mod list_style {
use style::properties::longhands::list_style_image::SpecifiedValue as ListStyleImage;
use style::properties::longhands::list_style_position::computed_value::T as ListStylePosition;
use style::properties::longhands::list_style_type::computed_value::T as ListStyleType;
use style::values::Either;
use super::*;

#[test]
fn list_style_should_show_all_properties_when_values_are_set() {
let mut properties = Vec::new();

let position = DeclaredValue::Value(ListStylePosition::inside);
let image = DeclaredValue::Value(ListStyleImage::Url(
let image = DeclaredValue::Value(Either::First(
SpecifiedUrl::new_for_testing("http://servo/test.png")));
let style_type = DeclaredValue::Value(ListStyleType::disc);

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.