mirror of
https://github.com/servo/servo.git
synced 2025-08-05 05:30:08 +01:00
gfx: Refactor the border drawing code and split out fragment display
list building into multiple functions. This should have no functional changes; it's just code cleanup.
This commit is contained in:
parent
20b961493a
commit
dea8375613
8 changed files with 519 additions and 372 deletions
|
@ -6,8 +6,8 @@
|
||||||
//! perform. Using a list instead of painting elements in immediate mode allows transforms, hit
|
//! perform. Using a list instead of painting elements in immediate mode allows transforms, hit
|
||||||
//! testing, and invalidation to be performed using the same primitives as painting. It also allows
|
//! testing, and invalidation to be performed using the same primitives as painting. It also allows
|
||||||
//! Servo to aggressively cull invisible and out-of-bounds painting elements, to reduce overdraw.
|
//! Servo to aggressively cull invisible and out-of-bounds painting elements, to reduce overdraw.
|
||||||
//! Finally, display lists allow tiles to be farmed out onto multiple CPUs and painted in
|
//! Finally, display lists allow tiles to be farmed out onto multiple CPUs and painted in parallel
|
||||||
//! parallel (although this benefit does not apply to GPU-based painting).
|
//! (although this benefit does not apply to GPU-based painting).
|
||||||
//!
|
//!
|
||||||
//! Display items describe relatively high-level drawing operations (for example, entire borders
|
//! Display items describe relatively high-level drawing operations (for example, entire borders
|
||||||
//! and shadows instead of lines and blur operations), to reduce the amount of allocation required.
|
//! and shadows instead of lines and blur operations), to reduce the amount of allocation required.
|
||||||
|
@ -610,7 +610,7 @@ pub struct BorderDisplayItem {
|
||||||
/// Information about the border radii.
|
/// Information about the border radii.
|
||||||
///
|
///
|
||||||
/// TODO(pcwalton): Elliptical radii.
|
/// TODO(pcwalton): Elliptical radii.
|
||||||
#[deriving(Clone, Default, Show)]
|
#[deriving(Clone, Default, PartialEq, Show)]
|
||||||
pub struct BorderRadii<T> {
|
pub struct BorderRadii<T> {
|
||||||
pub top_left: T,
|
pub top_left: T,
|
||||||
pub top_right: T,
|
pub top_right: T,
|
||||||
|
@ -693,6 +693,8 @@ impl DisplayItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayItem::ImageClass(ref image_item) => {
|
DisplayItem::ImageClass(ref image_item) => {
|
||||||
|
// FIXME(pcwalton): This is a really inefficient way to draw a tiled image; use a
|
||||||
|
// brush instead.
|
||||||
debug!("Drawing image at {}.", image_item.base.bounds);
|
debug!("Drawing image at {}.", image_item.base.bounds);
|
||||||
|
|
||||||
let mut y_offset = Au(0);
|
let mut y_offset = Au(0);
|
||||||
|
@ -715,10 +717,10 @@ impl DisplayItem {
|
||||||
|
|
||||||
DisplayItem::BorderClass(ref border) => {
|
DisplayItem::BorderClass(ref border) => {
|
||||||
paint_context.draw_border(&border.base.bounds,
|
paint_context.draw_border(&border.base.bounds,
|
||||||
border.border_widths,
|
&border.border_widths,
|
||||||
&border.radius,
|
&border.radius,
|
||||||
border.color,
|
&border.color,
|
||||||
border.style)
|
&border.style)
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayItem::GradientClass(ref gradient) => {
|
DisplayItem::GradientClass(ref gradient) => {
|
||||||
|
@ -729,9 +731,7 @@ impl DisplayItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayItem::LineClass(ref line) => {
|
DisplayItem::LineClass(ref line) => {
|
||||||
paint_context.draw_line(&line.base.bounds,
|
paint_context.draw_line(&line.base.bounds, line.color, line.style)
|
||||||
line.color,
|
|
||||||
line.style)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DisplayItem::BoxShadowClass(ref box_shadow) => {
|
DisplayItem::BoxShadowClass(ref box_shadow) => {
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||||
|
|
||||||
#![feature(globs, macro_rules, phase, unsafe_destructor, default_type_params)]
|
#![feature(globs, macro_rules, phase, unsafe_destructor, default_type_params, if_let)]
|
||||||
|
|
||||||
#![deny(unused_imports)]
|
#![deny(unused_imports)]
|
||||||
#![deny(unused_variables)]
|
#![deny(unused_variables)]
|
||||||
|
|
|
@ -77,25 +77,20 @@ impl<'a> PaintContext<'a> {
|
||||||
|
|
||||||
pub fn draw_border(&self,
|
pub fn draw_border(&self,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<Au>,
|
border: &SideOffsets2D<Au>,
|
||||||
radius: &BorderRadii<Au>,
|
radius: &BorderRadii<Au>,
|
||||||
color: SideOffsets2D<Color>,
|
color: &SideOffsets2D<Color>,
|
||||||
style: SideOffsets2D<border_style::T>) {
|
style: &SideOffsets2D<border_style::T>) {
|
||||||
let border = border.to_float_px();
|
let border = border.to_float_px();
|
||||||
let radius = radius.to_radii_px();
|
let radius = radius.to_radii_px();
|
||||||
|
|
||||||
self.draw_target.make_current();
|
self.draw_border_segment(Direction::Top, bounds, &border, &radius, color, style);
|
||||||
|
self.draw_border_segment(Direction::Right, bounds, &border, &radius, color, style);
|
||||||
self.draw_border_segment(Direction::Top, bounds, border, &radius, color, style);
|
self.draw_border_segment(Direction::Bottom, bounds, &border, &radius, color, style);
|
||||||
self.draw_border_segment(Direction::Right, bounds, border, &radius, color, style);
|
self.draw_border_segment(Direction::Left, bounds, &border, &radius, color, style);
|
||||||
self.draw_border_segment(Direction::Bottom, bounds, border, &radius, color, style);
|
|
||||||
self.draw_border_segment(Direction::Left, bounds, border, &radius, color, style);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn draw_line(&self,
|
pub fn draw_line(&self, bounds: &Rect<Au>, color: Color, style: border_style::T) {
|
||||||
bounds: &Rect<Au>,
|
|
||||||
color: Color,
|
|
||||||
style: border_style::T) {
|
|
||||||
self.draw_target.make_current();
|
self.draw_target.make_current();
|
||||||
|
|
||||||
self.draw_line_segment(bounds, &Default::default(), color, style);
|
self.draw_line_segment(bounds, &Default::default(), color, style);
|
||||||
|
@ -108,7 +103,8 @@ impl<'a> PaintContext<'a> {
|
||||||
let left_top = Point2D(rect.origin.x, rect.origin.y);
|
let left_top = Point2D(rect.origin.x, rect.origin.y);
|
||||||
let right_top = Point2D(rect.origin.x + rect.size.width, rect.origin.y);
|
let right_top = Point2D(rect.origin.x + rect.size.width, rect.origin.y);
|
||||||
let left_bottom = Point2D(rect.origin.x, rect.origin.y + rect.size.height);
|
let left_bottom = Point2D(rect.origin.x, rect.origin.y + rect.size.height);
|
||||||
let right_bottom = Point2D(rect.origin.x + rect.size.width, rect.origin.y + rect.size.height);
|
let right_bottom = Point2D(rect.origin.x + rect.size.width,
|
||||||
|
rect.origin.y + rect.size.height);
|
||||||
|
|
||||||
path_builder.move_to(left_top);
|
path_builder.move_to(left_top);
|
||||||
path_builder.line_to(right_top);
|
path_builder.line_to(right_top);
|
||||||
|
@ -166,10 +162,10 @@ impl<'a> PaintContext<'a> {
|
||||||
fn draw_border_segment(&self,
|
fn draw_border_segment(&self,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
radius: &BorderRadii<AzFloat>,
|
radius: &BorderRadii<AzFloat>,
|
||||||
color: SideOffsets2D<Color>,
|
color: &SideOffsets2D<Color>,
|
||||||
style: SideOffsets2D<border_style::T>) {
|
style: &SideOffsets2D<border_style::T>) {
|
||||||
let (style_select, color_select) = match direction {
|
let (style_select, color_select) = match direction {
|
||||||
Direction::Top => (style.top, color.top),
|
Direction::Top => (style.top, color.top),
|
||||||
Direction::Left => (style.left, color.left),
|
Direction::Left => (style.left, color.left),
|
||||||
|
@ -177,59 +173,111 @@ impl<'a> PaintContext<'a> {
|
||||||
Direction::Bottom => (style.bottom, color.bottom)
|
Direction::Bottom => (style.bottom, color.bottom)
|
||||||
};
|
};
|
||||||
|
|
||||||
match style_select{
|
match style_select {
|
||||||
border_style::none => {
|
border_style::none | border_style::hidden => {}
|
||||||
}
|
|
||||||
border_style::hidden => {
|
|
||||||
}
|
|
||||||
//FIXME(sammykim): This doesn't work with dash_pattern and cap_style well. I referred firefox code.
|
|
||||||
border_style::dotted => {
|
border_style::dotted => {
|
||||||
self.draw_dashed_border_segment(direction, bounds, border, color_select, DashSize::DottedBorder);
|
// FIXME(sammykim): This doesn't work well with dash_pattern and cap_style.
|
||||||
|
self.draw_dashed_border_segment(direction,
|
||||||
|
bounds,
|
||||||
|
border,
|
||||||
|
color_select,
|
||||||
|
DashSize::DottedBorder);
|
||||||
}
|
}
|
||||||
border_style::dashed => {
|
border_style::dashed => {
|
||||||
self.draw_dashed_border_segment(direction, bounds, border, color_select, DashSize::DashedBorder);
|
self.draw_dashed_border_segment(direction,
|
||||||
|
bounds,
|
||||||
|
border,
|
||||||
|
color_select,
|
||||||
|
DashSize::DashedBorder);
|
||||||
}
|
}
|
||||||
border_style::solid => {
|
border_style::solid => {
|
||||||
self.draw_solid_border_segment(direction,bounds,border,radius,color_select);
|
self.draw_solid_border_segment(direction, bounds, border, radius, color_select);
|
||||||
}
|
}
|
||||||
border_style::double => {
|
border_style::double => {
|
||||||
self.draw_double_border_segment(direction, bounds, border, radius, color_select);
|
self.draw_double_border_segment(direction, bounds, border, radius, color_select);
|
||||||
}
|
}
|
||||||
border_style::groove | border_style::ridge => {
|
border_style::groove | border_style::ridge => {
|
||||||
self.draw_groove_ridge_border_segment(direction, bounds, border, radius, color_select, style_select);
|
self.draw_groove_ridge_border_segment(direction,
|
||||||
|
bounds,
|
||||||
|
border,
|
||||||
|
radius,
|
||||||
|
color_select,
|
||||||
|
style_select);
|
||||||
}
|
}
|
||||||
border_style::inset | border_style::outset => {
|
border_style::inset | border_style::outset => {
|
||||||
self.draw_inset_outset_border_segment(direction, bounds, border, radius, color_select, style_select);
|
self.draw_inset_outset_border_segment(direction,
|
||||||
|
bounds,
|
||||||
|
border,
|
||||||
|
radius,
|
||||||
|
color_select,
|
||||||
|
style_select);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_line_segment(&self, bounds: &Rect<Au>, radius: &BorderRadii<AzFloat>, color: Color, style: border_style::T) {
|
fn draw_line_segment(&self,
|
||||||
|
bounds: &Rect<Au>,
|
||||||
|
radius: &BorderRadii<AzFloat>,
|
||||||
|
color: Color,
|
||||||
|
style: border_style::T) {
|
||||||
let border = SideOffsets2D::new_all_same(bounds.size.width).to_float_px();
|
let border = SideOffsets2D::new_all_same(bounds.size.width).to_float_px();
|
||||||
|
|
||||||
match style {
|
match style {
|
||||||
border_style::none | border_style::hidden => {}
|
border_style::none | border_style::hidden => {}
|
||||||
border_style::dotted => {
|
border_style::dotted => {
|
||||||
self.draw_dashed_border_segment(Direction::Right, bounds, border, color, DashSize::DottedBorder);
|
self.draw_dashed_border_segment(Direction::Right,
|
||||||
|
bounds,
|
||||||
|
&border,
|
||||||
|
color,
|
||||||
|
DashSize::DottedBorder);
|
||||||
}
|
}
|
||||||
border_style::dashed => {
|
border_style::dashed => {
|
||||||
self.draw_dashed_border_segment(Direction::Right, bounds, border, color, DashSize::DashedBorder);
|
self.draw_dashed_border_segment(Direction::Right,
|
||||||
|
bounds,
|
||||||
|
&border,
|
||||||
|
color,
|
||||||
|
DashSize::DashedBorder);
|
||||||
}
|
}
|
||||||
border_style::solid => {
|
border_style::solid => {
|
||||||
self.draw_solid_border_segment(Direction::Right, bounds, border, radius, color);
|
self.draw_solid_border_segment(Direction::Right, bounds, &border, radius, color)
|
||||||
}
|
}
|
||||||
border_style::double => {
|
border_style::double => {
|
||||||
self.draw_double_border_segment(Direction::Right, bounds, border, radius, color);
|
self.draw_double_border_segment(Direction::Right, bounds, &border, radius, color)
|
||||||
}
|
}
|
||||||
border_style::groove | border_style::ridge => {
|
border_style::groove | border_style::ridge => {
|
||||||
self.draw_groove_ridge_border_segment(Direction::Right, bounds, border, radius, color, style);
|
self.draw_groove_ridge_border_segment(Direction::Right,
|
||||||
|
bounds,
|
||||||
|
&border,
|
||||||
|
radius,
|
||||||
|
color,
|
||||||
|
style);
|
||||||
}
|
}
|
||||||
border_style::inset | border_style::outset => {
|
border_style::inset | border_style::outset => {
|
||||||
self.draw_inset_outset_border_segment(Direction::Right, bounds, border, radius, color, style);
|
self.draw_inset_outset_border_segment(Direction::Right,
|
||||||
|
bounds,
|
||||||
|
&border,
|
||||||
|
radius,
|
||||||
|
color,
|
||||||
|
style);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn draw_border_path(&self,
|
||||||
|
bounds: &Rect<f32>,
|
||||||
|
direction: Direction,
|
||||||
|
border: &SideOffsets2D<f32>,
|
||||||
|
radii: &BorderRadii<AzFloat>,
|
||||||
|
color: Color) {
|
||||||
|
let mut path_builder = self.draw_target.create_path_builder();
|
||||||
|
self.create_border_path_segment(&mut path_builder,
|
||||||
|
bounds,
|
||||||
|
direction,
|
||||||
|
border,
|
||||||
|
radii);
|
||||||
|
let draw_options = DrawOptions::new(1.0, 0);
|
||||||
|
self.draw_target.fill(&path_builder.finish(), &ColorPattern::new(color), &draw_options);
|
||||||
|
}
|
||||||
|
|
||||||
// The following comment is wonderful, and stolen from
|
// The following comment is wonderful, and stolen from
|
||||||
// gecko:gfx/thebes/gfxContext.cpp:RoundedRectangle for reference.
|
// gecko:gfx/thebes/gfxContext.cpp:RoundedRectangle for reference.
|
||||||
//
|
//
|
||||||
|
@ -310,14 +358,13 @@ impl<'a> PaintContext<'a> {
|
||||||
// For the various corners and for each axis, the sign of this
|
// For the various corners and for each axis, the sign of this
|
||||||
// constant changes, or it might be 0 -- it's multiplied by the
|
// constant changes, or it might be 0 -- it's multiplied by the
|
||||||
// appropriate multiplier from the list before using.
|
// appropriate multiplier from the list before using.
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
fn draw_border_path(&self,
|
fn create_border_path_segment(&self,
|
||||||
|
path_builder: &mut PathBuilder,
|
||||||
bounds: &Rect<f32>,
|
bounds: &Rect<f32>,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
radius: &BorderRadii<AzFloat>,
|
radius: &BorderRadii<AzFloat>) {
|
||||||
color: Color) {
|
|
||||||
// T = top, B = bottom, L = left, R = right
|
// T = top, B = bottom, L = left, R = right
|
||||||
|
|
||||||
let box_TL = bounds.origin;
|
let box_TL = bounds.origin;
|
||||||
|
@ -325,9 +372,6 @@ impl<'a> PaintContext<'a> {
|
||||||
let box_BL = box_TL + Point2D(0.0, bounds.size.height);
|
let box_BL = box_TL + Point2D(0.0, bounds.size.height);
|
||||||
let box_BR = box_TL + Point2D(bounds.size.width, bounds.size.height);
|
let box_BR = box_TL + Point2D(bounds.size.width, bounds.size.height);
|
||||||
|
|
||||||
let draw_opts = DrawOptions::new(1.0, 0);
|
|
||||||
let path_builder = self.draw_target.create_path_builder();
|
|
||||||
|
|
||||||
let rad_R: AzFloat = 0.;
|
let rad_R: AzFloat = 0.;
|
||||||
let rad_BR = rad_R + Float::frac_pi_4();
|
let rad_BR = rad_R + Float::frac_pi_4();
|
||||||
let rad_B = rad_BR + Float::frac_pi_4();
|
let rad_B = rad_BR + Float::frac_pi_4();
|
||||||
|
@ -368,7 +412,8 @@ impl<'a> PaintContext<'a> {
|
||||||
|
|
||||||
if radius.top_right != 0. {
|
if radius.top_right != 0. {
|
||||||
// the origin is the center of the arcs we're about to draw.
|
// the origin is the center of the arcs we're about to draw.
|
||||||
let origin = edge_TR + Point2D((border.right - radius.top_right).max(0.), radius.top_right);
|
let origin = edge_TR + Point2D((border.right - radius.top_right).max(0.),
|
||||||
|
radius.top_right);
|
||||||
// the elbow is the inside of the border's curve.
|
// the elbow is the inside of the border's curve.
|
||||||
let distance_to_elbow = (radius.top_right - border.top).max(0.);
|
let distance_to_elbow = (radius.top_right - border.top).max(0.);
|
||||||
|
|
||||||
|
@ -380,7 +425,8 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(edge_BL);
|
path_builder.line_to(edge_BL);
|
||||||
|
|
||||||
if radius.top_left != 0. {
|
if radius.top_left != 0. {
|
||||||
let origin = edge_TL + Point2D(-(border.left - radius.top_left).max(0.), radius.top_left);
|
let origin = edge_TL + Point2D(-(border.left - radius.top_left).max(0.),
|
||||||
|
radius.top_left);
|
||||||
let distance_to_elbow = (radius.top_left - border.top).max(0.);
|
let distance_to_elbow = (radius.top_left - border.top).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, distance_to_elbow, rad_T, rad_TL, true);
|
path_builder.arc(origin, distance_to_elbow, rad_T, rad_TL, true);
|
||||||
|
@ -400,7 +446,8 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(corner_TL);
|
path_builder.line_to(corner_TL);
|
||||||
|
|
||||||
if radius.top_left != 0. {
|
if radius.top_left != 0. {
|
||||||
let origin = edge_TL + Point2D(radius.top_left, -(border.top - radius.top_left).max(0.));
|
let origin = edge_TL + Point2D(radius.top_left,
|
||||||
|
-(border.top - radius.top_left).max(0.));
|
||||||
let distance_to_elbow = (radius.top_left - border.left).max(0.);
|
let distance_to_elbow = (radius.top_left - border.left).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, radius.top_left, rad_L, rad_TL, false);
|
path_builder.arc(origin, radius.top_left, rad_L, rad_TL, false);
|
||||||
|
@ -411,7 +458,9 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(edge_BR);
|
path_builder.line_to(edge_BR);
|
||||||
|
|
||||||
if radius.bottom_left != 0. {
|
if radius.bottom_left != 0. {
|
||||||
let origin = edge_BL + Point2D(radius.bottom_left, (border.bottom - radius.bottom_left).max(0.));
|
let origin = edge_BL +
|
||||||
|
Point2D(radius.bottom_left,
|
||||||
|
(border.bottom - radius.bottom_left).max(0.));
|
||||||
let distance_to_elbow = (radius.bottom_left - border.left).max(0.);
|
let distance_to_elbow = (radius.bottom_left - border.left).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, distance_to_elbow, rad_L, rad_BL, true);
|
path_builder.arc(origin, distance_to_elbow, rad_L, rad_BL, true);
|
||||||
|
@ -431,7 +480,8 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(edge_TL);
|
path_builder.line_to(edge_TL);
|
||||||
|
|
||||||
if radius.top_right != 0. {
|
if radius.top_right != 0. {
|
||||||
let origin = edge_TR + Point2D(-radius.top_right, -(border.top - radius.top_right).max(0.));
|
let origin = edge_TR + Point2D(-radius.top_right,
|
||||||
|
-(border.top - radius.top_right).max(0.));
|
||||||
let distance_to_elbow = (radius.top_right - border.right).max(0.);
|
let distance_to_elbow = (radius.top_right - border.right).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, distance_to_elbow, rad_R, rad_TR, true);
|
path_builder.arc(origin, distance_to_elbow, rad_R, rad_TR, true);
|
||||||
|
@ -442,7 +492,9 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(corner_BR);
|
path_builder.line_to(corner_BR);
|
||||||
|
|
||||||
if radius.bottom_right != 0. {
|
if radius.bottom_right != 0. {
|
||||||
let origin = edge_BR + Point2D(-radius.bottom_right, (border.bottom - radius.bottom_right).max(0.));
|
let origin = edge_BR +
|
||||||
|
Point2D(-radius.bottom_right,
|
||||||
|
(border.bottom - radius.bottom_right).max(0.));
|
||||||
let distance_to_elbow = (radius.bottom_right - border.right).max(0.);
|
let distance_to_elbow = (radius.bottom_right - border.right).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, radius.bottom_right, rad_R, rad_BR, false);
|
path_builder.arc(origin, radius.bottom_right, rad_R, rad_BR, false);
|
||||||
|
@ -462,7 +514,8 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(edge_TR);
|
path_builder.line_to(edge_TR);
|
||||||
|
|
||||||
if radius.bottom_right != 0. {
|
if radius.bottom_right != 0. {
|
||||||
let origin = edge_BR + Point2D((border.right - radius.bottom_right).max(0.), -radius.bottom_right);
|
let origin = edge_BR + Point2D((border.right - radius.bottom_right).max(0.),
|
||||||
|
-radius.bottom_right);
|
||||||
let distance_to_elbow = (radius.bottom_right - border.bottom).max(0.);
|
let distance_to_elbow = (radius.bottom_right - border.bottom).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, distance_to_elbow, rad_B, rad_BR, true);
|
path_builder.arc(origin, distance_to_elbow, rad_B, rad_BR, true);
|
||||||
|
@ -473,7 +526,8 @@ impl<'a> PaintContext<'a> {
|
||||||
path_builder.line_to(corner_BL);
|
path_builder.line_to(corner_BL);
|
||||||
|
|
||||||
if radius.bottom_left != 0. {
|
if radius.bottom_left != 0. {
|
||||||
let origin = edge_BL - Point2D((border.left - radius.bottom_left).max(0.), radius.bottom_left);
|
let origin = edge_BL - Point2D((border.left - radius.bottom_left).max(0.),
|
||||||
|
radius.bottom_left);
|
||||||
let distance_to_elbow = (radius.bottom_left - border.bottom).max(0.);
|
let distance_to_elbow = (radius.bottom_left - border.bottom).max(0.);
|
||||||
|
|
||||||
path_builder.arc(origin, radius.bottom_left, rad_B, rad_BL, false);
|
path_builder.arc(origin, radius.bottom_left, rad_B, rad_BL, false);
|
||||||
|
@ -481,6 +535,7 @@ impl<'a> PaintContext<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let path = path_builder.finish();
|
let path = path_builder.finish();
|
||||||
self.draw_target.fill(&path, &ColorPattern::new(color), &draw_opts);
|
self.draw_target.fill(&path, &ColorPattern::new(color), &draw_opts);
|
||||||
|
@ -489,7 +544,7 @@ impl<'a> PaintContext<'a> {
|
||||||
fn draw_dashed_border_segment(&self,
|
fn draw_dashed_border_segment(&self,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
color: Color,
|
color: Color,
|
||||||
dash_size: DashSize) {
|
dash_size: DashSize) {
|
||||||
let rect = bounds.to_azure_rect();
|
let rect = bounds.to_azure_rect();
|
||||||
|
@ -546,14 +601,19 @@ impl<'a> PaintContext<'a> {
|
||||||
&draw_opts);
|
&draw_opts);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_solid_border_segment(&self, direction: Direction, bounds: &Rect<Au>, border: SideOffsets2D<f32>, radius: &BorderRadii<AzFloat>, color: Color) {
|
fn draw_solid_border_segment(&self,
|
||||||
|
direction: Direction,
|
||||||
|
bounds: &Rect<Au>,
|
||||||
|
border: &SideOffsets2D<f32>,
|
||||||
|
radius: &BorderRadii<AzFloat>,
|
||||||
|
color: Color) {
|
||||||
let rect = bounds.to_azure_rect();
|
let rect = bounds.to_azure_rect();
|
||||||
self.draw_border_path(&rect, direction, border, radius, color);
|
self.draw_border_path(&rect, direction, border, radius, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_scaled_bounds(&self,
|
fn get_scaled_bounds(&self,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
shrink_factor: f32) -> Rect<f32> {
|
shrink_factor: f32) -> Rect<f32> {
|
||||||
let rect = bounds.to_azure_rect();
|
let rect = bounds.to_azure_rect();
|
||||||
let scaled_border = SideOffsets2D::new(shrink_factor * border.top,
|
let scaled_border = SideOffsets2D::new(shrink_factor * border.top,
|
||||||
|
@ -571,22 +631,27 @@ impl<'a> PaintContext<'a> {
|
||||||
return Color::new(color.r * scale_factor, color.g * scale_factor, color.b * scale_factor, color.a);
|
return Color::new(color.r * scale_factor, color.g * scale_factor, color.b * scale_factor, color.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_double_border_segment(&self, direction: Direction, bounds: &Rect<Au>, border: SideOffsets2D<f32>, radius: &BorderRadii<AzFloat>, color: Color) {
|
fn draw_double_border_segment(&self,
|
||||||
|
direction: Direction,
|
||||||
|
bounds: &Rect<Au>,
|
||||||
|
border: &SideOffsets2D<f32>,
|
||||||
|
radius: &BorderRadii<AzFloat>,
|
||||||
|
color: Color) {
|
||||||
let scaled_border = SideOffsets2D::new((1.0/3.0) * border.top,
|
let scaled_border = SideOffsets2D::new((1.0/3.0) * border.top,
|
||||||
(1.0/3.0) * border.right,
|
(1.0/3.0) * border.right,
|
||||||
(1.0/3.0) * border.bottom,
|
(1.0/3.0) * border.bottom,
|
||||||
(1.0/3.0) * border.left);
|
(1.0/3.0) * border.left);
|
||||||
let inner_scaled_bounds = self.get_scaled_bounds(bounds, border, 2.0/3.0);
|
let inner_scaled_bounds = self.get_scaled_bounds(bounds, border, 2.0/3.0);
|
||||||
// draw the outer portion of the double border.
|
// draw the outer portion of the double border.
|
||||||
self.draw_solid_border_segment(direction, bounds, scaled_border, radius, color);
|
self.draw_solid_border_segment(direction, bounds, &scaled_border, radius, color);
|
||||||
// draw the inner portion of the double border.
|
// draw the inner portion of the double border.
|
||||||
self.draw_border_path(&inner_scaled_bounds, direction, scaled_border, radius, color);
|
self.draw_border_path(&inner_scaled_bounds, direction, &scaled_border, radius, color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_groove_ridge_border_segment(&self,
|
fn draw_groove_ridge_border_segment(&self,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
radius: &BorderRadii<AzFloat>,
|
radius: &BorderRadii<AzFloat>,
|
||||||
color: Color,
|
color: Color,
|
||||||
style: border_style::T) {
|
style: border_style::T) {
|
||||||
|
@ -618,20 +683,26 @@ impl<'a> PaintContext<'a> {
|
||||||
|
|
||||||
let (outer_color, inner_color) = match (direction, is_groove) {
|
let (outer_color, inner_color) = match (direction, is_groove) {
|
||||||
(Direction::Top, true) | (Direction::Left, true) |
|
(Direction::Top, true) | (Direction::Left, true) |
|
||||||
(Direction::Right, false) | (Direction::Bottom, false) => (darker_color, lighter_color),
|
(Direction::Right, false) | (Direction::Bottom, false) => {
|
||||||
|
(darker_color, lighter_color)
|
||||||
|
}
|
||||||
(Direction::Top, false) | (Direction::Left, false) |
|
(Direction::Top, false) | (Direction::Left, false) |
|
||||||
(Direction::Right, true) | (Direction::Bottom, true) => (lighter_color, darker_color)
|
(Direction::Right, true) | (Direction::Bottom, true) => (lighter_color, darker_color),
|
||||||
};
|
};
|
||||||
// outer portion of the border
|
// outer portion of the border
|
||||||
self.draw_border_path(&original_bounds, direction, scaled_border, radius, outer_color);
|
self.draw_border_path(&original_bounds, direction, &scaled_border, radius, outer_color);
|
||||||
// inner portion of the border
|
// inner portion of the border
|
||||||
self.draw_border_path(&inner_scaled_bounds, direction, scaled_border, radius, inner_color);
|
self.draw_border_path(&inner_scaled_bounds,
|
||||||
|
direction,
|
||||||
|
&scaled_border,
|
||||||
|
radius,
|
||||||
|
inner_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw_inset_outset_border_segment(&self,
|
fn draw_inset_outset_border_segment(&self,
|
||||||
direction: Direction,
|
direction: Direction,
|
||||||
bounds: &Rect<Au>,
|
bounds: &Rect<Au>,
|
||||||
border: SideOffsets2D<f32>,
|
border: &SideOffsets2D<f32>,
|
||||||
radius: &BorderRadii<AzFloat>,
|
radius: &BorderRadii<AzFloat>,
|
||||||
color: Color,
|
color: Color,
|
||||||
style: border_style::T) {
|
style: border_style::T) {
|
||||||
|
@ -643,18 +714,33 @@ impl<'a> PaintContext<'a> {
|
||||||
// original bounds as a Rect<f32>
|
// original bounds as a Rect<f32>
|
||||||
let original_bounds = self.get_scaled_bounds(bounds, border, 0.0);
|
let original_bounds = self.get_scaled_bounds(bounds, border, 0.0);
|
||||||
|
|
||||||
let mut scaled_color;
|
|
||||||
|
|
||||||
// You can't scale black color (i.e. 'scaled = 0 * scale', equals black).
|
// You can't scale black color (i.e. 'scaled = 0 * scale', equals black).
|
||||||
|
let mut scaled_color;
|
||||||
if color.r != 0.0 || color.g != 0.0 || color.b != 0.0 {
|
if color.r != 0.0 || color.g != 0.0 || color.b != 0.0 {
|
||||||
scaled_color = match direction {
|
scaled_color = match direction {
|
||||||
Direction::Top | Direction::Left => self.scale_color(color, if is_inset { 2.0/3.0 } else { 1.0 }),
|
Direction::Top | Direction::Left => {
|
||||||
Direction::Right | Direction::Bottom => self.scale_color(color, if is_inset { 1.0 } else { 2.0/3.0 })
|
self.scale_color(color, if is_inset { 2.0/3.0 } else { 1.0 })
|
||||||
|
}
|
||||||
|
Direction::Right | Direction::Bottom => {
|
||||||
|
self.scale_color(color, if is_inset { 1.0 } else { 2.0/3.0 })
|
||||||
|
}
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
scaled_color = match direction {
|
scaled_color = match direction {
|
||||||
Direction::Top | Direction::Left => if is_inset { Color::new(0.3, 0.3, 0.3, color.a) } else { Color::new(0.7, 0.7, 0.7, color.a) },
|
Direction::Top | Direction::Left => {
|
||||||
Direction::Right | Direction::Bottom => if is_inset { Color::new(0.7, 0.7, 0.7, color.a) } else { Color::new(0.3, 0.3, 0.3, color.a) }
|
if is_inset {
|
||||||
|
Color::new(0.3, 0.3, 0.3, color.a)
|
||||||
|
} else {
|
||||||
|
Color::new(0.7, 0.7, 0.7, color.a)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Direction::Right | Direction::Bottom => {
|
||||||
|
if is_inset {
|
||||||
|
Color::new(0.7, 0.7, 0.7, color.a)
|
||||||
|
} else {
|
||||||
|
Color::new(0.3, 0.3, 0.3, color.a)
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -852,9 +938,8 @@ impl<'a> PaintContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn push_clip_if_applicable(&self) {
|
pub fn push_clip_if_applicable(&self) {
|
||||||
match self.clip_rect {
|
if let Some(ref clip_rect) = self.clip_rect {
|
||||||
None => {}
|
self.draw_push_clip(clip_rect)
|
||||||
Some(ref clip_rect) => self.draw_push_clip(clip_rect),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -167,25 +167,53 @@ pub trait FragmentDisplayListBuilding {
|
||||||
offset: Point2D<Au>,
|
offset: Point2D<Au>,
|
||||||
layout_context: &LayoutContext);
|
layout_context: &LayoutContext);
|
||||||
|
|
||||||
fn clip_rect_for_children(&self, current_clip_rect: &Rect<Au>, flow_origin: &Point2D<Au>)
|
fn clipping_region_for_children(&self, current_clip: ClippingRegion, flow_origin: Point2D<Au>)
|
||||||
-> Rect<Au>;
|
-> ClippingRegion;
|
||||||
|
|
||||||
/// Calculates the clipping rectangle for a fragment, taking the `clip` property into account
|
/// Calculates the clipping rectangle for a fragment, taking the `clip` property into account
|
||||||
/// per CSS 2.1 § 11.1.2.
|
/// per CSS 2.1 § 11.1.2.
|
||||||
fn calculate_style_specified_clip(&self, parent_clip_rect: &Rect<Au>, origin: &Point2D<Au>)
|
fn calculate_style_specified_clip(&self, parent_clip_rect: &Rect<Au>, origin: &Point2D<Au>)
|
||||||
-> Rect<Au>;
|
-> Rect<Au>;
|
||||||
|
|
||||||
|
/// Creates the text display item for one text fragment.
|
||||||
|
fn build_display_list_for_text_fragment(&self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
text_fragment: &ScannedTextFragmentInfo,
|
||||||
|
text_color: RGBA,
|
||||||
|
offset: &Point2D<Au>,
|
||||||
|
flow_origin: &Point2D<Au>,
|
||||||
|
clip: &ClippingRegion);
|
||||||
|
|
||||||
|
/// Creates the display item for a text decoration: underline, overline, or line-through.
|
||||||
|
fn build_display_list_for_text_decoration(&self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
color: RGBA,
|
||||||
|
flow_origin: &Point2D<Au>,
|
||||||
|
clip: &ClippingRegion,
|
||||||
|
logical_bounds: &LogicalRect<Au>,
|
||||||
|
offset: &Point2D<Au>);
|
||||||
|
|
||||||
|
/// A helper method that `build_display_list` calls to create per-fragment-type display items.
|
||||||
|
fn build_fragment_type_specific_display_items(&mut self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
flow_origin: Point2D<Au>,
|
||||||
|
clip: &ClippingRegion);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_border_radius(abs_bounds: &Rect<Au>, border_style: &Border) -> BorderRadii<Au> {
|
fn build_border_radius(abs_bounds: &Rect<Au>, border_style: &Border) -> BorderRadii<Au> {
|
||||||
// TODO(cgaebel): Support border radii even in the case of multiple border widths.
|
// TODO(cgaebel): Support border radii even in the case of multiple border widths.
|
||||||
// This is an extennsion of supporting elliptical radii. For now, all percentage
|
// This is an extension of supporting elliptical radii. For now, all percentage
|
||||||
// radii will be relative to the width.
|
// radii will be relative to the width.
|
||||||
|
|
||||||
BorderRadii {
|
BorderRadii {
|
||||||
top_left: model::specified(border_style.border_top_left_radius.radius, abs_bounds.size.width),
|
top_left: model::specified(border_style.border_top_left_radius.radius,
|
||||||
top_right: model::specified(border_style.border_top_right_radius.radius, abs_bounds.size.width),
|
abs_bounds.size.width),
|
||||||
bottom_right: model::specified(border_style.border_bottom_right_radius.radius, abs_bounds.size.width),
|
top_right: model::specified(border_style.border_top_right_radius.radius,
|
||||||
bottom_left: model::specified(border_style.border_bottom_left_radius.radius, abs_bounds.size.width),
|
abs_bounds.size.width),
|
||||||
|
bottom_right: model::specified(border_style.border_bottom_right_radius.radius,
|
||||||
|
abs_bounds.size.width),
|
||||||
|
bottom_left: model::specified(border_style.border_bottom_left_radius.radius,
|
||||||
|
abs_bounds.size.width),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -645,13 +673,6 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
let absolute_fragment_bounds =
|
let absolute_fragment_bounds =
|
||||||
self.stacking_relative_bounds(&stacking_relative_flow_origin);
|
self.stacking_relative_bounds(&stacking_relative_flow_origin);
|
||||||
|
|
||||||
// FIXME(#2795): Get the real container size
|
|
||||||
let container_size = Size2D::zero();
|
|
||||||
let rect_to_absolute = |writing_mode: WritingMode, logical_rect: LogicalRect<Au>| {
|
|
||||||
let physical_rect = logical_rect.to_physical(writing_mode, container_size);
|
|
||||||
Rect(physical_rect.origin + stacking_relative_flow_origin, physical_rect.size)
|
|
||||||
};
|
|
||||||
|
|
||||||
debug!("Fragment::build_display_list at rel={}, abs={}: {}",
|
debug!("Fragment::build_display_list at rel={}, abs={}: {}",
|
||||||
self.border_box,
|
self.border_box,
|
||||||
absolute_fragment_bounds,
|
absolute_fragment_bounds,
|
||||||
|
@ -684,230 +705,77 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
StackingLevel::from_background_and_border_level(background_and_border_level);
|
StackingLevel::from_background_and_border_level(background_and_border_level);
|
||||||
|
|
||||||
// Add a shadow to the list, if applicable.
|
// Add a shadow to the list, if applicable.
|
||||||
match self.inline_context {
|
if let Some(ref inline_context) = self.inline_context {
|
||||||
Some(ref inline_context) => {
|
|
||||||
for style in inline_context.styles.iter().rev() {
|
for style in inline_context.styles.iter().rev() {
|
||||||
self.build_display_list_for_box_shadow_if_applicable(
|
self.build_display_list_for_box_shadow_if_applicable(&**style,
|
||||||
&**style,
|
|
||||||
display_list,
|
display_list,
|
||||||
layout_context,
|
layout_context,
|
||||||
level,
|
level,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
if !self.is_scanned_text_fragment() {
|
||||||
}
|
self.build_display_list_for_box_shadow_if_applicable(&*self.style,
|
||||||
match self.specific {
|
|
||||||
SpecificFragmentInfo::ScannedText(_) => {},
|
|
||||||
_ => {
|
|
||||||
self.build_display_list_for_box_shadow_if_applicable(
|
|
||||||
&*self.style,
|
|
||||||
display_list,
|
display_list,
|
||||||
layout_context,
|
layout_context,
|
||||||
level,
|
level,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the background to the list, if applicable.
|
// Add the background to the list, if applicable.
|
||||||
match self.inline_context {
|
if let Some(ref inline_context) = self.inline_context {
|
||||||
Some(ref inline_context) => {
|
|
||||||
for style in inline_context.styles.iter().rev() {
|
for style in inline_context.styles.iter().rev() {
|
||||||
self.build_display_list_for_background_if_applicable(
|
self.build_display_list_for_background_if_applicable(&**style,
|
||||||
&**style,
|
|
||||||
display_list,
|
display_list,
|
||||||
layout_context,
|
layout_context,
|
||||||
level,
|
level,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
if !self.is_scanned_text_fragment() {
|
||||||
}
|
self.build_display_list_for_background_if_applicable(&*self.style,
|
||||||
match self.specific {
|
|
||||||
SpecificFragmentInfo::ScannedText(_) => {},
|
|
||||||
_ => {
|
|
||||||
self.build_display_list_for_background_if_applicable(
|
|
||||||
&*self.style,
|
|
||||||
display_list,
|
display_list,
|
||||||
layout_context,
|
layout_context,
|
||||||
level,
|
level,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add a border and outlines, if applicable.
|
// Add a border and outlines, if applicable.
|
||||||
match self.inline_context {
|
if let Some(ref inline_context) = self.inline_context {
|
||||||
Some(ref inline_context) => {
|
|
||||||
for style in inline_context.styles.iter().rev() {
|
for style in inline_context.styles.iter().rev() {
|
||||||
self.build_display_list_for_borders_if_applicable(
|
self.build_display_list_for_borders_if_applicable(&**style,
|
||||||
&**style,
|
|
||||||
display_list,
|
display_list,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
level,
|
level,
|
||||||
&clip_rect);
|
clip);
|
||||||
self.build_display_list_for_outline_if_applicable(
|
self.build_display_list_for_outline_if_applicable(&**style,
|
||||||
&**style,
|
|
||||||
display_list,
|
display_list,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => {}
|
if !self.is_scanned_text_fragment() {
|
||||||
}
|
self.build_display_list_for_borders_if_applicable(&*self.style,
|
||||||
match self.specific {
|
|
||||||
SpecificFragmentInfo::ScannedText(_) => {},
|
|
||||||
_ => {
|
|
||||||
self.build_display_list_for_borders_if_applicable(
|
|
||||||
&*self.style,
|
|
||||||
display_list,
|
display_list,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
level,
|
level,
|
||||||
&clip_rect);
|
clip);
|
||||||
self.build_display_list_for_outline_if_applicable(
|
self.build_display_list_for_outline_if_applicable(&*self.style,
|
||||||
&*self.style,
|
|
||||||
display_list,
|
display_list,
|
||||||
&absolute_fragment_bounds,
|
&absolute_fragment_bounds,
|
||||||
&clip_rect);
|
clip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
let content_box = self.content_box();
|
|
||||||
let absolute_content_box = rect_to_absolute(self.style.writing_mode, content_box);
|
|
||||||
|
|
||||||
// Create special per-fragment-type display items.
|
// Create special per-fragment-type display items.
|
||||||
match self.specific {
|
self.build_fragment_type_specific_display_items(display_list, flow_origin, clip);
|
||||||
SpecificFragmentInfo::UnscannedText(_) => panic!("Shouldn't see unscanned fragments here."),
|
|
||||||
SpecificFragmentInfo::TableColumn(_) => panic!("Shouldn't see table column fragments here."),
|
|
||||||
SpecificFragmentInfo::ScannedText(ref text_fragment) => {
|
|
||||||
// Create the text display item.
|
|
||||||
let (orientation, cursor) = if self.style.writing_mode.is_vertical() {
|
|
||||||
if self.style.writing_mode.is_sideways_left() {
|
|
||||||
(SidewaysLeft, VerticalTextCursor)
|
|
||||||
} else {
|
|
||||||
(SidewaysRight, VerticalTextCursor)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
(Upright, TextCursor)
|
|
||||||
};
|
|
||||||
|
|
||||||
let metrics = &text_fragment.run.font_metrics;
|
|
||||||
let baseline_origin = {
|
|
||||||
let mut content_box_start = content_box.start;
|
|
||||||
content_box_start.b = content_box_start.b + metrics.ascent;
|
|
||||||
content_box_start.to_physical(self.style.writing_mode, container_size)
|
|
||||||
+ flow_origin
|
|
||||||
};
|
|
||||||
|
|
||||||
display_list.content.push_back(DisplayItem::TextClass(box TextDisplayItem {
|
|
||||||
base: BaseDisplayItem::new(absolute_content_box,
|
|
||||||
DisplayItemMetadata::new(self.node,
|
|
||||||
self.style(),
|
|
||||||
cursor),
|
|
||||||
clip_rect),
|
|
||||||
text_run: text_fragment.run.clone(),
|
|
||||||
range: text_fragment.range,
|
|
||||||
text_color: self.style().get_color().color.to_gfx_color(),
|
|
||||||
orientation: orientation,
|
|
||||||
baseline_origin: baseline_origin,
|
|
||||||
}));
|
|
||||||
|
|
||||||
// Create display items for text decoration
|
|
||||||
{
|
|
||||||
let line = |maybe_color: Option<RGBA>,
|
|
||||||
style: &ComputedValues,
|
|
||||||
rect: || -> LogicalRect<Au>| {
|
|
||||||
match maybe_color {
|
|
||||||
None => {}
|
|
||||||
Some(color) => {
|
|
||||||
let bounds = rect_to_absolute(self.style.writing_mode, rect());
|
|
||||||
display_list.content.push_back(DisplayItem::SolidColorClass(
|
|
||||||
box SolidColorDisplayItem {
|
|
||||||
base: BaseDisplayItem::new(
|
|
||||||
bounds,
|
|
||||||
DisplayItemMetadata::new(self.node,
|
|
||||||
style,
|
|
||||||
DefaultCursor),
|
|
||||||
clip_rect),
|
|
||||||
color: color.to_gfx_color(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let text_decorations =
|
|
||||||
self.style().get_inheritedtext()._servo_text_decorations_in_effect;
|
|
||||||
line(text_decorations.underline, self.style(), || {
|
|
||||||
let mut rect = content_box.clone();
|
|
||||||
rect.start.b = rect.start.b + metrics.ascent - metrics.underline_offset;
|
|
||||||
rect.size.block = metrics.underline_size;
|
|
||||||
rect
|
|
||||||
});
|
|
||||||
|
|
||||||
line(text_decorations.overline, self.style(), || {
|
|
||||||
let mut rect = content_box.clone();
|
|
||||||
rect.size.block = metrics.underline_size;
|
|
||||||
rect
|
|
||||||
});
|
|
||||||
|
|
||||||
line(text_decorations.line_through, self.style(), || {
|
|
||||||
let mut rect = content_box.clone();
|
|
||||||
rect.start.b = rect.start.b + metrics.ascent - metrics.strikeout_offset;
|
|
||||||
rect.size.block = metrics.strikeout_size;
|
|
||||||
rect
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts::get().show_debug_fragment_borders {
|
if opts::get().show_debug_fragment_borders {
|
||||||
self.build_debug_borders_around_text_fragments(self.style(),
|
self.build_debug_borders_around_fragment(display_list, flow_origin, clip)
|
||||||
display_list,
|
|
||||||
flow_origin,
|
|
||||||
&**text_fragment,
|
|
||||||
&clip_rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SpecificFragmentInfo::Generic | SpecificFragmentInfo::Iframe(..) | SpecificFragmentInfo::Table | SpecificFragmentInfo::TableCell |
|
|
||||||
SpecificFragmentInfo::TableRow | SpecificFragmentInfo::TableWrapper | SpecificFragmentInfo::InlineBlock(_) |
|
|
||||||
SpecificFragmentInfo::InlineAbsoluteHypothetical(_) => {
|
|
||||||
if opts::get().show_debug_fragment_borders {
|
|
||||||
self.build_debug_borders_around_fragment(display_list,
|
|
||||||
flow_origin,
|
|
||||||
&clip_rect);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SpecificFragmentInfo::Image(ref mut image_fragment) => {
|
|
||||||
let image_ref = &mut image_fragment.image;
|
|
||||||
match image_ref.get_image(self.node.to_untrusted_node_address()) {
|
|
||||||
Some(image) => {
|
|
||||||
debug!("(building display list) building image fragment");
|
|
||||||
|
|
||||||
// Place the image into the display list.
|
|
||||||
display_list.content.push_back(DisplayItem::ImageClass(box ImageDisplayItem {
|
|
||||||
base: BaseDisplayItem::new(absolute_content_box,
|
|
||||||
DisplayItemMetadata::new(self.node,
|
|
||||||
&*self.style,
|
|
||||||
DefaultCursor),
|
|
||||||
clip_rect),
|
|
||||||
image: image.clone(),
|
|
||||||
stretch_size: absolute_content_box.size,
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
// No image data at all? Do nothing.
|
|
||||||
//
|
|
||||||
// TODO: Add some kind of placeholder image.
|
|
||||||
debug!("(building display list) no image :(");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if opts::get().show_debug_fragment_borders {
|
|
||||||
self.build_debug_borders_around_fragment(display_list, flow_origin, &clip_rect)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If this is an iframe, then send its position and size up to the constellation.
|
// If this is an iframe, then send its position and size up to the constellation.
|
||||||
|
@ -920,13 +788,95 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
// origin to the constellation here during display list construction. This should work
|
// origin to the constellation here during display list construction. This should work
|
||||||
// because layout for the iframe only needs to know size, and origin is only relevant if
|
// because layout for the iframe only needs to know size, and origin is only relevant if
|
||||||
// the iframe is actually going to be displayed.
|
// the iframe is actually going to be displayed.
|
||||||
match self.specific {
|
if let SpecificFragmentInfo::Iframe(ref iframe_fragment) = self.specific {
|
||||||
SpecificFragmentInfo::Iframe(ref iframe_fragment) => {
|
|
||||||
self.finalize_position_and_size_of_iframe(&**iframe_fragment,
|
self.finalize_position_and_size_of_iframe(&**iframe_fragment,
|
||||||
absolute_fragment_bounds.origin,
|
absolute_fragment_bounds.origin,
|
||||||
layout_context)
|
layout_context)
|
||||||
}
|
}
|
||||||
_ => {}
|
}
|
||||||
|
|
||||||
|
fn build_fragment_type_specific_display_items(&mut self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
flow_origin: Point2D<Au>,
|
||||||
|
clip: &ClippingRegion) {
|
||||||
|
// Compute the fragment position relative to the parent stacking context. If the fragment
|
||||||
|
// itself establishes a stacking context, then the origin of its position will be (0, 0)
|
||||||
|
// for the purposes of this computation.
|
||||||
|
let stacking_relative_flow_origin = if self.establishes_stacking_context() {
|
||||||
|
ZERO_POINT
|
||||||
|
} else {
|
||||||
|
flow_origin
|
||||||
|
};
|
||||||
|
|
||||||
|
// FIXME(#2795): Get the real container size.
|
||||||
|
let content_box = self.content_box();
|
||||||
|
let container_size = Size2D::zero();
|
||||||
|
let rect_to_absolute = |writing_mode: WritingMode, logical_rect: LogicalRect<Au>| {
|
||||||
|
let physical_rect = logical_rect.to_physical(writing_mode, container_size);
|
||||||
|
Rect(physical_rect.origin + stacking_relative_flow_origin, physical_rect.size)
|
||||||
|
};
|
||||||
|
|
||||||
|
match self.specific {
|
||||||
|
SpecificFragmentInfo::UnscannedText(_) => {
|
||||||
|
panic!("Shouldn't see unscanned fragments here.")
|
||||||
|
}
|
||||||
|
SpecificFragmentInfo::TableColumn(_) => {
|
||||||
|
panic!("Shouldn't see table column fragments here.")
|
||||||
|
}
|
||||||
|
SpecificFragmentInfo::ScannedText(ref text_fragment) => {
|
||||||
|
// Create the main text display item.
|
||||||
|
let text_color = self.style().get_color().color;
|
||||||
|
self.build_display_list_for_text_fragment(display_list,
|
||||||
|
&**text_fragment,
|
||||||
|
text_color,
|
||||||
|
&flow_origin,
|
||||||
|
&Point2D(Au(0), Au(0)),
|
||||||
|
clip);
|
||||||
|
|
||||||
|
if opts::get().show_debug_fragment_borders {
|
||||||
|
self.build_debug_borders_around_text_fragments(self.style(),
|
||||||
|
display_list,
|
||||||
|
flow_origin,
|
||||||
|
&**text_fragment,
|
||||||
|
clip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SpecificFragmentInfo::Generic |
|
||||||
|
SpecificFragmentInfo::Iframe(..) |
|
||||||
|
SpecificFragmentInfo::Table |
|
||||||
|
SpecificFragmentInfo::TableCell |
|
||||||
|
SpecificFragmentInfo::TableRow |
|
||||||
|
SpecificFragmentInfo::TableWrapper |
|
||||||
|
SpecificFragmentInfo::InlineBlock(_) |
|
||||||
|
SpecificFragmentInfo::InlineAbsoluteHypothetical(_) => {
|
||||||
|
if opts::get().show_debug_fragment_borders {
|
||||||
|
self.build_debug_borders_around_fragment(display_list, flow_origin, clip);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
SpecificFragmentInfo::Image(ref mut image_fragment) => {
|
||||||
|
let image_ref = &mut image_fragment.image;
|
||||||
|
if let Some(image) = image_ref.get_image(self.node.to_untrusted_node_address()) {
|
||||||
|
debug!("(building display list) building image fragment");
|
||||||
|
let absolute_content_box = rect_to_absolute(self.style.writing_mode,
|
||||||
|
content_box);
|
||||||
|
|
||||||
|
// Place the image into the display list.
|
||||||
|
display_list.content.push_back(DisplayItem::ImageClass(box ImageDisplayItem {
|
||||||
|
base: BaseDisplayItem::new(absolute_content_box,
|
||||||
|
DisplayItemMetadata::new(self.node,
|
||||||
|
&*self.style,
|
||||||
|
DefaultCursor),
|
||||||
|
(*clip).clone()),
|
||||||
|
image: image.clone(),
|
||||||
|
stretch_size: absolute_content_box.size,
|
||||||
|
}));
|
||||||
|
} else {
|
||||||
|
// No image data at all? Do nothing.
|
||||||
|
//
|
||||||
|
// TODO: Add some kind of placeholder image.
|
||||||
|
debug!("(building display list) no image :(");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -951,12 +901,11 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
iframe_rect));
|
iframe_rect));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn clip_rect_for_children(&self, current_clip_rect: &Rect<Au>, origin: &Point2D<Au>)
|
fn clipping_region_for_children(&self, current_clip: ClippingRegion, flow_origin: Point2D<Au>)
|
||||||
-> Rect<Au> {
|
-> ClippingRegion {
|
||||||
// Don't clip if we're text.
|
// Don't clip if we're text.
|
||||||
match self.specific {
|
if self.is_scanned_text_fragment() {
|
||||||
SpecificFragmentInfo::ScannedText(_) => return *current_clip_rect,
|
return current_clip
|
||||||
_ => {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Account for style-specified `clip`.
|
// Account for style-specified `clip`.
|
||||||
|
@ -965,16 +914,131 @@ impl FragmentDisplayListBuilding for Fragment {
|
||||||
// Only clip if `overflow` tells us to.
|
// Only clip if `overflow` tells us to.
|
||||||
match self.style.get_box().overflow {
|
match self.style.get_box().overflow {
|
||||||
overflow::hidden | overflow::auto | overflow::scroll => {}
|
overflow::hidden | overflow::auto | overflow::scroll => {}
|
||||||
_ => return current_clip_rect,
|
_ => return current_clip,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a new clip rect.
|
// Create a new clip rect.
|
||||||
//
|
//
|
||||||
// FIXME(#2795): Get the real container size.
|
// FIXME(#2795): Get the real container size.
|
||||||
let physical_rect = self.border_box.to_physical(self.style.writing_mode, Size2D::zero());
|
let physical_rect = self.border_box.to_physical(self.style.writing_mode, Size2D::zero());
|
||||||
current_clip_rect.intersection(&Rect(Point2D(physical_rect.origin.x + origin.x,
|
current_clip.intersect_rect(&Rect(physical_rect.origin + flow_origin, physical_rect.size))
|
||||||
physical_rect.origin.y + origin.y),
|
}
|
||||||
physical_rect.size)).unwrap_or(ZERO_RECT)
|
|
||||||
|
fn build_display_list_for_text_fragment(&self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
text_fragment: &ScannedTextFragmentInfo,
|
||||||
|
text_color: RGBA,
|
||||||
|
flow_origin: &Point2D<Au>,
|
||||||
|
offset: &Point2D<Au>,
|
||||||
|
clip: &ClippingRegion) {
|
||||||
|
// Determine the orientation and cursor to use.
|
||||||
|
let (orientation, cursor) = if self.style.writing_mode.is_vertical() {
|
||||||
|
if self.style.writing_mode.is_sideways_left() {
|
||||||
|
(SidewaysLeft, VerticalTextCursor)
|
||||||
|
} else {
|
||||||
|
(SidewaysRight, VerticalTextCursor)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
(Upright, TextCursor)
|
||||||
|
};
|
||||||
|
|
||||||
|
// Compute location of the baseline.
|
||||||
|
//
|
||||||
|
// FIXME(pcwalton): Get the real container size.
|
||||||
|
let container_size = Size2D::zero();
|
||||||
|
let content_box = self.content_box();
|
||||||
|
let metrics = &text_fragment.run.font_metrics;
|
||||||
|
let baseline_origin = {
|
||||||
|
let mut content_box_start = content_box.start;
|
||||||
|
content_box_start.b = content_box_start.b + metrics.ascent;
|
||||||
|
content_box_start.to_physical(self.style.writing_mode, container_size) + *flow_origin +
|
||||||
|
*offset
|
||||||
|
};
|
||||||
|
let stacking_relative_flow_origin = if self.establishes_stacking_context() {
|
||||||
|
ZERO_POINT
|
||||||
|
} else {
|
||||||
|
*flow_origin
|
||||||
|
};
|
||||||
|
let rect_to_absolute = |writing_mode: WritingMode, logical_rect: LogicalRect<Au>| {
|
||||||
|
let physical_rect = logical_rect.to_physical(writing_mode, container_size);
|
||||||
|
Rect(physical_rect.origin + stacking_relative_flow_origin, physical_rect.size)
|
||||||
|
};
|
||||||
|
let content_rect = rect_to_absolute(self.style.writing_mode,
|
||||||
|
content_box).translate(offset);
|
||||||
|
|
||||||
|
// Create the text display item.
|
||||||
|
display_list.content.push_back(DisplayItem::TextClass(box TextDisplayItem {
|
||||||
|
base: BaseDisplayItem::new(content_rect,
|
||||||
|
DisplayItemMetadata::new(self.node, self.style(), cursor),
|
||||||
|
(*clip).clone()),
|
||||||
|
text_run: text_fragment.run.clone(),
|
||||||
|
range: text_fragment.range,
|
||||||
|
text_color: text_color.to_gfx_color(),
|
||||||
|
orientation: orientation,
|
||||||
|
baseline_origin: baseline_origin,
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Create display items for text decorations.
|
||||||
|
let text_decorations = self.style().get_inheritedtext()._servo_text_decorations_in_effect;
|
||||||
|
if let Some(underline_color) = text_decorations.underline {
|
||||||
|
let mut rect = content_box.clone();
|
||||||
|
rect.start.b = rect.start.b + metrics.ascent - metrics.underline_offset;
|
||||||
|
rect.size.block = metrics.underline_size;
|
||||||
|
self.build_display_list_for_text_decoration(display_list,
|
||||||
|
underline_color,
|
||||||
|
flow_origin,
|
||||||
|
clip,
|
||||||
|
&rect,
|
||||||
|
offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(overline_color) = text_decorations.overline {
|
||||||
|
let mut rect = content_box.clone();
|
||||||
|
rect.size.block = metrics.underline_size;
|
||||||
|
self.build_display_list_for_text_decoration(display_list,
|
||||||
|
overline_color,
|
||||||
|
flow_origin,
|
||||||
|
clip,
|
||||||
|
&rect,
|
||||||
|
offset)
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(line_through_color) = text_decorations.line_through {
|
||||||
|
let mut rect = content_box.clone();
|
||||||
|
rect.start.b = rect.start.b + metrics.ascent - metrics.strikeout_offset;
|
||||||
|
rect.size.block = metrics.strikeout_size;
|
||||||
|
self.build_display_list_for_text_decoration(display_list,
|
||||||
|
line_through_color,
|
||||||
|
flow_origin,
|
||||||
|
clip,
|
||||||
|
&rect,
|
||||||
|
offset)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn build_display_list_for_text_decoration(&self,
|
||||||
|
display_list: &mut DisplayList,
|
||||||
|
color: RGBA,
|
||||||
|
flow_origin: &Point2D<Au>,
|
||||||
|
clip: &ClippingRegion,
|
||||||
|
logical_bounds: &LogicalRect<Au>,
|
||||||
|
offset: &Point2D<Au>) {
|
||||||
|
// FIXME(pcwalton): Get the real container size.
|
||||||
|
let container_size = Size2D::zero();
|
||||||
|
let stacking_relative_flow_origin = if self.establishes_stacking_context() {
|
||||||
|
ZERO_POINT
|
||||||
|
} else {
|
||||||
|
*flow_origin
|
||||||
|
};
|
||||||
|
let physical_rect = logical_bounds.to_physical(self.style.writing_mode, container_size);
|
||||||
|
|
||||||
|
let bounds = Rect(physical_rect.origin + stacking_relative_flow_origin,
|
||||||
|
physical_rect.size).translate(offset);
|
||||||
|
let metadata = DisplayItemMetadata::new(self.node, &*self.style, DefaultCursor);
|
||||||
|
display_list.content.push_back(DisplayItem::SolidColorClass(box SolidColorDisplayItem {
|
||||||
|
base: BaseDisplayItem::new(bounds, metadata, (*clip).clone()),
|
||||||
|
color: color.to_gfx_color(),
|
||||||
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,8 +50,7 @@ use geom::{Point2D, Rect, Size2D};
|
||||||
use serialize::{Encoder, Encodable};
|
use serialize::{Encoder, Encodable};
|
||||||
use servo_msg::compositor_msg::LayerId;
|
use servo_msg::compositor_msg::LayerId;
|
||||||
use servo_util::geometry::Au;
|
use servo_util::geometry::Au;
|
||||||
use servo_util::logical_geometry::WritingMode;
|
use servo_util::logical_geometry::{LogicalRect, LogicalSize, WritingMode};
|
||||||
use servo_util::logical_geometry::{LogicalRect, LogicalSize};
|
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::iter::Zip;
|
use std::iter::Zip;
|
||||||
|
@ -290,7 +289,7 @@ pub trait Flow: fmt::Show + ToString + Sync {
|
||||||
/// NB: Do not change this `&self` to `&mut self` under any circumstances! It has security
|
/// NB: Do not change this `&self` to `&mut self` under any circumstances! It has security
|
||||||
/// implications because this can be called on parents concurrently from descendants!
|
/// implications because this can be called on parents concurrently from descendants!
|
||||||
fn generated_containing_block_rect(&self) -> LogicalRect<Au> {
|
fn generated_containing_block_rect(&self) -> LogicalRect<Au> {
|
||||||
panic!("generated_containing_block_position not yet implemented for this flow")
|
panic!("generated_containing_block_rect not yet implemented for this flow")
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a layer ID for the given fragment.
|
/// Returns a layer ID for the given fragment.
|
||||||
|
|
|
@ -954,7 +954,7 @@ impl Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if and only if this is a scanned text fragment.
|
/// Returns true if and only if this is a scanned text fragment.
|
||||||
fn is_scanned_text_fragment(&self) -> bool {
|
pub fn is_scanned_text_fragment(&self) -> bool {
|
||||||
match self.specific {
|
match self.specific {
|
||||||
SpecificFragmentInfo::ScannedText(..) => true,
|
SpecificFragmentInfo::ScannedText(..) => true,
|
||||||
_ => false,
|
_ => false,
|
||||||
|
|
|
@ -28,8 +28,7 @@ use gfx::color;
|
||||||
use gfx::display_list::{DisplayItemMetadata, DisplayList, OpaqueNode, StackingContext};
|
use gfx::display_list::{DisplayItemMetadata, DisplayList, OpaqueNode, StackingContext};
|
||||||
use gfx::font_cache_task::FontCacheTask;
|
use gfx::font_cache_task::FontCacheTask;
|
||||||
use gfx::paint_task::{mod, PaintInitMsg, PaintChan, PaintLayer};
|
use gfx::paint_task::{mod, PaintInitMsg, PaintChan, PaintLayer};
|
||||||
use layout_traits;
|
use layout_traits::{mod, LayoutControlMsg, LayoutTaskFactory};
|
||||||
use layout_traits::{LayoutControlMsg, LayoutTaskFactory};
|
|
||||||
use log;
|
use log;
|
||||||
use script::dom::bindings::js::JS;
|
use script::dom::bindings::js::JS;
|
||||||
use script::dom::node::{LayoutDataRef, Node, NodeTypeId};
|
use script::dom::node::{LayoutDataRef, Node, NodeTypeId};
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub enum PagePx {}
|
||||||
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
|
// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
|
||||||
//
|
//
|
||||||
// FIXME: Implement Au using Length and ScaleFactor instead of a custom type.
|
// FIXME: Implement Au using Length and ScaleFactor instead of a custom type.
|
||||||
#[deriving(Clone, Hash, PartialEq, PartialOrd, Eq, Ord)]
|
#[deriving(Clone, Hash, PartialEq, PartialOrd, Eq, Ord, Zero)]
|
||||||
pub struct Au(pub i32);
|
pub struct Au(pub i32);
|
||||||
|
|
||||||
impl Default for Au {
|
impl Default for Au {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue