mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Implement CSS text-align
This commit is contained in:
parent
fbd3bf0c8e
commit
5317939b64
2 changed files with 23 additions and 12 deletions
|
@ -29,7 +29,7 @@ use newcss::values::{CSSBackgroundColorColor, CSSBackgroundColorTransparent, CSS
|
||||||
use newcss::values::{CSSBorderWidthLength, CSSBorderWidthMedium, CSSDisplay};
|
use newcss::values::{CSSBorderWidthLength, CSSBorderWidthMedium, CSSDisplay};
|
||||||
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily, CSSPositionAbsolute};
|
use newcss::values::{CSSFontFamilyFamilyName, CSSFontFamilyGenericFamily, CSSPositionAbsolute};
|
||||||
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
|
use newcss::values::{CSSFontSizeLength, CSSFontStyleItalic, CSSFontStyleNormal};
|
||||||
use newcss::values::{CSSFontStyleOblique, Specified};
|
use newcss::values::{CSSFontStyleOblique, CSSTextAlign, Specified};
|
||||||
use std::arc::ARC;
|
use std::arc::ARC;
|
||||||
use std::net::url::Url;
|
use std::net::url::Url;
|
||||||
|
|
||||||
|
@ -561,6 +561,13 @@ impl RenderBox : RenderBoxMethods {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Converts this node's ComputedStyle to a text alignment used in the inline layout code.
|
||||||
|
fn text_align(@self) -> CSSTextAlign {
|
||||||
|
do self.with_style_of_nearest_element |my_style| {
|
||||||
|
my_style.text_align()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RenderBox : BoxedDebugMethods {
|
impl RenderBox : BoxedDebugMethods {
|
||||||
|
|
|
@ -13,6 +13,7 @@ use gfx::font::FontStyle;
|
||||||
use gfx::geometry::Au;
|
use gfx::geometry::Au;
|
||||||
use gfx::text::util::*;
|
use gfx::text::util::*;
|
||||||
use gfx::util::range::{MutableRange, Range};
|
use gfx::util::range::{MutableRange, Range};
|
||||||
|
use newcss::values::{CSSTextAlignCenter, CSSTextAlignJustify, CSSTextAlignLeft, CSSTextAlignRight};
|
||||||
use newcss::units::{BoxAuto, BoxLength, Px};
|
use newcss::units::{BoxAuto, BoxLength, Px};
|
||||||
use std::arc;
|
use std::arc;
|
||||||
|
|
||||||
|
@ -417,26 +418,29 @@ impl LineboxScanner {
|
||||||
debug!("LineboxScanner: Setting horizontal offsets for boxes in line %u range: %?",
|
debug!("LineboxScanner: Setting horizontal offsets for boxes in line %u range: %?",
|
||||||
self.line_spans.len(), line_range);
|
self.line_spans.len(), line_range);
|
||||||
|
|
||||||
// TODO: use actual text align from box.style
|
// Get the text alignment.
|
||||||
enum CSSTextAlign {
|
let linebox_align;
|
||||||
AlignLeft,
|
if self.pending_line.range.begin() < self.new_boxes.len() {
|
||||||
AlignCenter,
|
let first_box = self.new_boxes[self.pending_line.range.begin()];
|
||||||
AlignRight,
|
linebox_align = first_box.text_align();
|
||||||
AlignJustify,
|
} else {
|
||||||
};
|
// Nothing to lay out, so assume left alignment.
|
||||||
let linebox_align = AlignRight;
|
// TODO: Is this a necessary check? --pcwalton
|
||||||
|
linebox_align = CSSTextAlignLeft;
|
||||||
|
}
|
||||||
|
|
||||||
let slack_width = self.flow.d().position.size.width - self.pending_line.width;
|
let slack_width = self.flow.d().position.size.width - self.pending_line.width;
|
||||||
match linebox_align {
|
match linebox_align {
|
||||||
// So sorry, but justified text is more complicated than shuffling linebox coordinates.
|
// So sorry, but justified text is more complicated than shuffling linebox coordinates.
|
||||||
// TODO(Issue #213): implement `text-align: justify`
|
// TODO(Issue #213): implement `text-align: justify`
|
||||||
AlignLeft | AlignJustify => {
|
CSSTextAlignLeft | CSSTextAlignJustify => {
|
||||||
for line_range.eachi |i| {
|
for line_range.eachi |i| {
|
||||||
let box_data = &self.new_boxes[i].d();
|
let box_data = &self.new_boxes[i].d();
|
||||||
box_data.position.origin.x = offset_x;
|
box_data.position.origin.x = offset_x;
|
||||||
offset_x += box_data.position.size.width;
|
offset_x += box_data.position.size.width;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AlignCenter => {
|
CSSTextAlignCenter => {
|
||||||
offset_x = slack_width.scale_by(0.5f);
|
offset_x = slack_width.scale_by(0.5f);
|
||||||
for line_range.eachi |i| {
|
for line_range.eachi |i| {
|
||||||
let box_data = &self.new_boxes[i].d();
|
let box_data = &self.new_boxes[i].d();
|
||||||
|
@ -444,7 +448,7 @@ impl LineboxScanner {
|
||||||
offset_x += box_data.position.size.width;
|
offset_x += box_data.position.size.width;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AlignRight => {
|
CSSTextAlignRight => {
|
||||||
offset_x = slack_width;
|
offset_x = slack_width;
|
||||||
for line_range.eachi |i| {
|
for line_range.eachi |i| {
|
||||||
let box_data = &self.new_boxes[i].d();
|
let box_data = &self.new_boxes[i].d();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue