mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Text boxes yield two display items, a bg color and a text item
This commit is contained in:
parent
2c0dcbc722
commit
f37897924b
1 changed files with 48 additions and 9 deletions
|
@ -71,10 +71,16 @@ fn box_to_display_items(box: @Box, origin: Point2D<au>) -> [dl::display_item] {
|
||||||
(TextBox(subbox), _, _) {
|
(TextBox(subbox), _, _) {
|
||||||
let run = copy subbox.run;
|
let run = copy subbox.run;
|
||||||
assert run.is_some();
|
assert run.is_some();
|
||||||
items += [dl::display_item({
|
items += [
|
||||||
item_type: dl::display_item_text(run.get()),
|
dl::display_item({
|
||||||
bounds: bounds
|
item_type: dl::display_item_solid_color(255u8, 255u8, 255u8),
|
||||||
})];
|
bounds: bounds
|
||||||
|
}),
|
||||||
|
dl::display_item({
|
||||||
|
item_type: dl::display_item_text(run.get()),
|
||||||
|
bounds: bounds
|
||||||
|
})
|
||||||
|
];
|
||||||
}
|
}
|
||||||
(_, some(image), some(*)) | (_, some(image), none) {
|
(_, some(image), some(*)) | (_, some(image), none) {
|
||||||
items += [dl::display_item({
|
items += [dl::display_item({
|
||||||
|
@ -104,7 +110,8 @@ fn box_to_display_items(box: @Box, origin: Point2D<au>) -> [dl::display_item] {
|
||||||
ret items;
|
ret items;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_convert_text_boxes_to_text_items() {
|
|
||||||
|
fn should_convert_text_boxes_to_solid_color_background_items() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
||||||
let s = Scope();
|
let s = Scope();
|
||||||
|
@ -115,12 +122,29 @@ fn should_convert_text_boxes_to_text_items() {
|
||||||
let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
|
let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
alt di[0].item_type {
|
alt di[0].item_type {
|
||||||
|
dl::display_item_solid_color(*) { }
|
||||||
|
_ { fail }
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
fn should_convert_text_boxes_to_text_items() {
|
||||||
|
#[test];
|
||||||
|
|
||||||
|
let s = Scope();
|
||||||
|
let n = s.new_node(Text("firecracker"));
|
||||||
|
let b = n.construct_boxes();
|
||||||
|
let subbox = alt check b.kind { TextBox(subbox) { subbox } };
|
||||||
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
|
let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
|
alt di[1].item_type {
|
||||||
dl::display_item_text(_) { }
|
dl::display_item_text(_) { }
|
||||||
_ { fail }
|
_ { fail }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn should_calculate_the_bounds_of_the_text_box() {
|
fn should_calculate_the_bounds_of_the_text_box_background_color() {
|
||||||
#[test];
|
#[test];
|
||||||
|
|
||||||
let s = Scope();
|
let s = Scope();
|
||||||
|
@ -135,8 +159,23 @@ fn should_calculate_the_bounds_of_the_text_box() {
|
||||||
Size2D(px_to_au(110), px_to_au(14))
|
Size2D(px_to_au(110), px_to_au(14))
|
||||||
);
|
);
|
||||||
|
|
||||||
#error("%?", di[0].bounds);
|
|
||||||
#error("%?", expected);
|
|
||||||
|
|
||||||
assert di[0].bounds == expected;
|
assert di[0].bounds == expected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn should_calculate_the_bounds_of_the_text_items() {
|
||||||
|
#[test];
|
||||||
|
|
||||||
|
let s = Scope();
|
||||||
|
let n = s.new_node(Text("firecracker"));
|
||||||
|
let b = n.construct_boxes();
|
||||||
|
let subbox = alt check b.kind { TextBox(subbox) { subbox } };
|
||||||
|
b.reflow_text(px_to_au(800), subbox);
|
||||||
|
let di = box_to_display_items(b, Point2D(px_to_au(0), px_to_au(0)));
|
||||||
|
|
||||||
|
let expected = Rect(
|
||||||
|
Point2D(px_to_au(0), px_to_au(0)),
|
||||||
|
Size2D(px_to_au(110), px_to_au(14))
|
||||||
|
);
|
||||||
|
|
||||||
|
assert di[1].bounds == expected;
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue