Refator 'box-sizing' calculation into a method

The 'box_sizing_boundary()' method return the border_padding width in
certain direction if fragment has property 'box-sizing: border-box'. The
'border_padding' field should be initialized before.
This commit is contained in:
Pu Xingyu 2016-07-25 20:59:04 +08:00
parent 7df5974456
commit 62dd3f4df4
2 changed files with 35 additions and 47 deletions

View file

@ -23,7 +23,7 @@ use inline::{InlineMetrics, LAST_FRAGMENT_OF_ELEMENT};
use ipc_channel::ipc::IpcSender;
#[cfg(debug_assertions)]
use layout_debug;
use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use model::{self, Direction, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, specified};
use msg::constellation_msg::PipelineId;
use net_traits::image::base::{Image, ImageMetadata};
use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder};
@ -39,7 +39,7 @@ use std::fmt;
use std::sync::{Arc, Mutex};
use style::arc_ptr_eq;
use style::computed_values::content::ContentItem;
use style::computed_values::{border_collapse, clear, color, display, mix_blend_mode};
use style::computed_values::{border_collapse, box_sizing, clear, color, display, mix_blend_mode};
use style::computed_values::{overflow_wrap, overflow_x, position, text_decoration};
use style::computed_values::{transform_style, vertical_align, white_space, word_break, z_index};
use style::dom::TRestyleDamage;
@ -1102,6 +1102,18 @@ impl Fragment {
}
}
pub fn box_sizing_boundary(&self, direction: Direction) -> Au {
match (self.style().get_position().box_sizing, direction) {
(box_sizing::T::border_box, Direction::Inline) => {
self.border_padding.inline_start_end()
}
(box_sizing::T::border_box, Direction::Block) => {
self.border_padding.block_start_end()
}
_ => Au(0)
}
}
/// Computes the margins in the inline direction from the containing block inline-size and the
/// style. After this call, the inline direction of the `margin` field will be correct.
///