Auto merge of #5980 - pcwalton:table-width-and-center, r=mbrubeck

Improves Hacker News.

r? @mbrubeck

<!-- Reviewable:start -->
[<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5980)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2015-05-11 15:25:42 -05:00
commit c1e15e827e
13 changed files with 160 additions and 36 deletions

View file

@ -55,7 +55,7 @@ use std::cmp::{max, min};
use std::fmt;
use std::sync::Arc;
use style::computed_values::{border_collapse, box_sizing, display, float, overflow_x, overflow_y};
use style::computed_values::{position};
use style::computed_values::{position, text_align};
use style::properties::ComputedValues;
use style::values::computed::{LengthOrPercentage, LengthOrPercentageOrAuto};
use style::values::computed::{LengthOrPercentageOrNone};
@ -1954,6 +1954,7 @@ pub struct ISizeConstraintInput {
pub inline_end_margin: MaybeAuto,
pub inline_start: MaybeAuto,
pub inline_end: MaybeAuto,
pub text_align: text_align::T,
pub available_inline_size: Au,
}
@ -1963,6 +1964,7 @@ impl ISizeConstraintInput {
inline_end_margin: MaybeAuto,
inline_start: MaybeAuto,
inline_end: MaybeAuto,
text_align: text_align::T,
available_inline_size: Au)
-> ISizeConstraintInput {
ISizeConstraintInput {
@ -1971,6 +1973,7 @@ impl ISizeConstraintInput {
inline_end_margin: inline_end_margin,
inline_start: inline_start,
inline_end: inline_end,
text_align: text_align,
available_inline_size: available_inline_size,
}
}
@ -2066,6 +2069,7 @@ pub trait ISizeAndMarginsComputer {
containing_block_inline_size),
MaybeAuto::from_style(position.inline_end,
containing_block_inline_size),
style.get_inheritedtext().text_align,
available_inline_size)
}
@ -2241,18 +2245,28 @@ pub trait ISizeAndMarginsComputer {
// available_inline-size
let (inline_start_margin, mut inline_size, inline_end_margin) =
match (inline_start_margin, computed_inline_size, inline_end_margin) {
// If all have a computed value other than 'auto', the system is
// over-constrained so we discard the end margin.
// If all have a computed value other than 'auto', the system is over-constrained.
(MaybeAuto::Specified(margin_start),
MaybeAuto::Specified(inline_size),
MaybeAuto::Specified(margin_end)) => {
if parent_has_same_direction {
(margin_start, inline_size, available_inline_size -
(margin_start + inline_size))
} else {
(available_inline_size - (margin_end + inline_size),
inline_size,
margin_end)
match (input.text_align, parent_has_same_direction) {
(text_align::T::servo_center, _) => {
// This is used for `<center>` and friends per HTML5 § 14.3.3. Make the
// inline-start and inline-end margins equal per HTML5 § 14.2.
let margin = (available_inline_size - inline_size).scale_by(0.5);
(margin, inline_size, margin)
}
(_, true) => {
// Ignore the end margin.
(margin_start, inline_size, available_inline_size -
(margin_start + inline_size))
}
(_, false) => {
// Ignore the start margin.
(available_inline_size - (margin_end + inline_size),
inline_size,
margin_end)
}
}
}
// If exactly one value is 'auto', solve for it

View file

@ -917,7 +917,7 @@ impl InlineFlow {
InlineFlow::justify_inline_fragments(fragments, line, slack_inline_size)
}
text_align::T::justify | text_align::T::start => {}
text_align::T::center => {
text_align::T::center | text_align::T::servo_center => {
inline_start_position_for_fragment = inline_start_position_for_fragment +
slack_inline_size.scale_by(0.5)
}

View file

@ -75,6 +75,14 @@ pub trait PresentationalHintSynthesis {
E: TElement<'a> +
TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
/// Synthesizes rules for the legacy `width` attribute.
fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list: &mut V,
shareable: &mut bool)
where E: TElement<'a> + TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>;
}
impl PresentationalHintSynthesis for Stylist {
@ -97,27 +105,20 @@ impl PresentationalHintSynthesis for Stylist {
match element.get_local_name() {
name if *name == atom!("td") => {
match element.get_length_attribute(LengthAttribute::Width) {
LengthOrPercentageOrAuto::Auto => {}
LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage);
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
LengthOrPercentageOrAuto::Length(length) => {
let width_value = specified::LengthOrPercentageOrAuto::Length(specified::Length::Absolute(length));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
}
self.synthesize_presentational_hint_for_legacy_width_attribute(
element,
matching_rules_list,
shareable);
self.synthesize_presentational_hint_for_legacy_border_attribute(
element,
matching_rules_list,
shareable);
}
name if *name == atom!("table") => {
self.synthesize_presentational_hint_for_legacy_width_attribute(
element,
matching_rules_list,
shareable);
self.synthesize_presentational_hint_for_legacy_border_attribute(
element,
matching_rules_list,
@ -221,6 +222,31 @@ impl PresentationalHintSynthesis for Stylist {
}
}
}
fn synthesize_presentational_hint_for_legacy_width_attribute<'a,E,V>(
&self,
element: E,
matching_rules_list: &mut V,
shareable: &mut bool)
where E: TElement<'a> + TElementAttributes<'a>,
V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {
match element.get_length_attribute(LengthAttribute::Width) {
LengthOrPercentageOrAuto::Auto => {}
LengthOrPercentageOrAuto::Percentage(percentage) => {
let width_value = specified::LengthOrPercentageOrAuto::Percentage(percentage);
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
LengthOrPercentageOrAuto::Length(length) => {
let width_value = specified::LengthOrPercentageOrAuto::Length(
specified::Length::Absolute(length));
matching_rules_list.push(from_declaration(
PropertyDeclaration::Width(SpecifiedValue(width_value))));
*shareable = false
}
}
}
}

View file

@ -1735,10 +1735,10 @@ pub mod longhands {
impl ComputedValueAsSpecified for SpecifiedValue {}
pub mod computed_value {
macro_rules! define_text_align {
( $( $name: ident => $discriminant: expr, )+ ) => {
( $( $name: ident ( $string: expr ) => $discriminant: expr, )+ ) => {
define_css_keyword_enum! { T:
$(
stringify!($name) => $name,
$string => $name,
)+
}
impl T {
@ -1761,12 +1761,13 @@ pub mod longhands {
}
}
define_text_align! {
start => 0,
end => 1,
left => 2,
right => 3,
center => 4,
justify => 5,
start("start") => 0,
end("end") => 1,
left("left") => 2,
right("right") => 3,
center("center") => 4,
justify("justify") => 5,
servo_center("-servo-center") => 6,
}
}
#[inline] pub fn get_initial_value() -> computed_value::T {