Update euclid.

There are a few canvas2d-related dependencies that haven't updated, but they
only use euclid internally so that's not blocking landing the rest of the
changes.

Given the size of this patch, I think it's useful to get this landed as-is.
This commit is contained in:
Emilio Cobos Álvarez 2019-07-22 12:49:39 +02:00
parent 2ff7cb5a37
commit 3d57c22e9c
133 changed files with 686 additions and 596 deletions

View file

@ -19,13 +19,14 @@ bitflags = "1.0"
canvas_traits = {path = "../canvas_traits"}
crossbeam-channel = "0.3"
embedder_traits = {path = "../embedder_traits"}
euclid = "0.19"
euclid = "0.20"
fnv = "1.0"
fxhash = "0.2"
gfx = {path = "../gfx"}
gfx_traits = {path = "../gfx_traits"}
html5ever = "0.23"
ipc-channel = "0.11"
lazy_static = "1"
libc = "0.2"
log = "0.4"
malloc_size_of = { path = "../malloc_size_of" }

View file

@ -50,7 +50,7 @@ use crate::model::{
use crate::sequential;
use crate::traversal::PreorderFlowTraversal;
use app_units::{Au, MAX_AU};
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D};
use gfx_traits::print_tree::PrintTree;
use serde::{Serialize, Serializer};
use servo_geometry::MaxRect;
@ -2610,7 +2610,7 @@ impl Flow for BlockFlow {
.relative_containing_block_mode,
CoordinateSystem::Own,
)
.translate(&stacking_context_position.to_vector()),
.translate(stacking_context_position.to_vector()),
);
}

View file

@ -4,7 +4,7 @@
use crate::display_list::border;
use app_units::Au;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D};
use style::computed_values::background_attachment::single_value::T as BackgroundAttachment;
use style::computed_values::background_clip::single_value::T as BackgroundClip;
use style::computed_values::background_origin::single_value::T as BackgroundOrigin;

View file

@ -4,7 +4,8 @@
use crate::display_list::ToLayout;
use app_units::Au;
use euclid::{Rect, SideOffsets2D, Size2D};
use euclid::default::{Rect, SideOffsets2D as UntypedSideOffsets2D, Size2D as UntypedSize2D};
use euclid::{SideOffsets2D, Size2D};
use style::computed_values::border_image_outset::T as BorderImageOutset;
use style::properties::style_structs::Border;
use style::values::computed::NumberOrPercentage;
@ -23,7 +24,10 @@ use webrender_api::{BorderRadius, BorderSide, BorderStyle, ColorF, NormalBorder}
/// > Percentages: Refer to corresponding dimension of the border box.
///
/// [1]: https://drafts.csswg.org/css-backgrounds-3/#border-radius
fn corner_radius(radius: BorderCornerRadius, containing_size: Size2D<Au>) -> Size2D<Au> {
fn corner_radius(
radius: BorderCornerRadius,
containing_size: UntypedSize2D<Au>,
) -> UntypedSize2D<Au> {
let w = radius.0.width().to_used_value(containing_size.width);
let h = radius.0.height().to_used_value(containing_size.height);
Size2D::new(w, h)
@ -105,7 +109,7 @@ pub fn radii(abs_bounds: Rect<Au>, border_style: &Border) -> BorderRadius {
/// the inner radii need to be smaller depending on the line width.
///
/// This is used to determine clipping areas.
pub fn inner_radii(mut radii: BorderRadius, offsets: SideOffsets2D<Au>) -> BorderRadius {
pub fn inner_radii(mut radii: BorderRadius, offsets: UntypedSideOffsets2D<Au>) -> BorderRadius {
fn inner_length(x: f32, offset: Au) -> f32 {
0.0_f32.max(x - offset.to_f32_px())
}
@ -144,7 +148,10 @@ fn side_image_outset(outset: NonNegativeLengthOrNumber, border_width: Au) -> Au
}
/// Compute the additional border-image area.
pub fn image_outset(outset: BorderImageOutset, border: SideOffsets2D<Au>) -> SideOffsets2D<Au> {
pub fn image_outset(
outset: BorderImageOutset,
border: UntypedSideOffsets2D<Au>,
) -> UntypedSideOffsets2D<Au> {
SideOffsets2D::new(
side_image_outset(outset.0, border.top),
side_image_outset(outset.1, border.right),
@ -168,7 +175,7 @@ fn side_image_width(
pub fn image_width(
width: &BorderImageWidth,
border: LayoutSideOffsets,
border_area: Size2D<Au>,
border_area: UntypedSize2D<Au>,
) -> LayoutSideOffsets {
LayoutSideOffsets::new(
side_image_width(width.0, border.top, border_area.height),
@ -185,15 +192,14 @@ fn resolve_percentage(value: NonNegative<NumberOrPercentage>, length: i32) -> i3
}
}
pub fn image_slice(
pub fn image_slice<U>(
border_image_slice: &StyleRect<NonNegative<NumberOrPercentage>>,
width: i32,
height: i32,
) -> SideOffsets2D<i32> {
size: Size2D<i32, U>,
) -> SideOffsets2D<i32, U> {
SideOffsets2D::new(
resolve_percentage(border_image_slice.0, height),
resolve_percentage(border_image_slice.1, width),
resolve_percentage(border_image_slice.2, height),
resolve_percentage(border_image_slice.3, width),
resolve_percentage(border_image_slice.0, size.height),
resolve_percentage(border_image_slice.1, size.width),
resolve_percentage(border_image_slice.2, size.height),
resolve_percentage(border_image_slice.3, size.width),
)
}

View file

@ -32,7 +32,10 @@ use crate::table_cell::CollapsedBordersForCell;
use app_units::{Au, AU_PER_PX};
use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg};
use embedder_traits::Cursor;
use euclid::{rect, Point2D, Rect, SideOffsets2D, Size2D, TypedRect, TypedSize2D};
use euclid::{
default::{Point2D, Rect, SideOffsets2D as UntypedSideOffsets2D, Size2D},
rect, SideOffsets2D,
};
use fnv::FnvHashMap;
use gfx::text::glyph::ByteIndex;
use gfx::text::TextRun;
@ -874,7 +877,7 @@ impl Fragment {
) -> Option<WebRenderImageInfo> {
let device_pixel_ratio = state.layout_context.style_context.device_pixel_ratio();
let size_in_px =
TypedSize2D::new(size_in_au.width.to_f32_px(), size_in_au.height.to_f32_px());
euclid::Size2D::new(size_in_au.width.to_f32_px(), size_in_au.height.to_f32_px());
// TODO: less copying.
let name = paint_worklet.name.clone();
@ -1169,7 +1172,7 @@ impl Fragment {
base: BaseDisplayItem,
bounds: Rect<Au>,
image: &Image,
border_width: SideOffsets2D<Au>,
border_width: UntypedSideOffsets2D<Au>,
) -> Option<()> {
let border_style_struct = style.get_border();
let border_image_outset =
@ -1238,11 +1241,13 @@ impl Fragment {
_ => return None,
};
// FIXME(emilio): WR expects device pixels here... somehow?
let size = euclid::Size2D::new(width as i32, height as i32);
let details = BorderDetails::NinePatch(NinePatchBorder {
source,
width: width as i32,
height: height as i32,
slice: border::image_slice(border_image_slice, width as i32, height as i32),
slice: border::image_slice(border_image_slice, size),
fill: border_image_fill,
repeat_horizontal: border_image_repeat.0.to_layout(),
repeat_vertical: border_image_repeat.1.to_layout(),
@ -1660,7 +1665,7 @@ impl Fragment {
// of this fragment's background but behind its content. This ensures that any
// hit tests inside the content box but not on actual content target the current
// scrollable ancestor.
let content_size = TypedRect::new(stacking_relative_border_box.origin, content_size);
let content_size = Rect::new(stacking_relative_border_box.origin, content_size);
let base = state.create_base_display_item_with_clipping_and_scrolling(
content_size,
self.node,
@ -1810,10 +1815,9 @@ impl Fragment {
// XXXjdm: This sleight-of-hand to convert LayoutRect -> Size2D<CSSPixel>
// looks bogus.
let size = Size2D::new(bounds.size.width, bounds.size.height);
state.iframe_sizes.push(IFrameSize {
id: browsing_context_id,
size: TypedSize2D::from_untyped(&size),
size: euclid::Size2D::new(bounds.size.width, bounds.size.height),
});
state.add_display_item(item);
@ -1926,13 +1930,13 @@ impl Fragment {
// First, compute the offset of our border box (including relative positioning)
// from our flow origin, since that is what `BaseFlow::overflow` is relative to.
let border_box_offset = border_box
.translate(&-base_flow.stacking_relative_position)
.translate(-base_flow.stacking_relative_position)
.origin;
// Then, using that, compute our overflow region relative to our border box.
let overflow = base_flow
.overflow
.paint
.translate(&-border_box_offset.to_vector());
.translate(-border_box_offset.to_vector());
// Create the filter pipeline.
let effects = self.style().get_effects();
@ -2269,7 +2273,7 @@ impl BlockFlow {
.fragment
.perspective_matrix(&border_box)
.unwrap_or(LayoutTransform::identity());
let transform = transform.pre_mul(&perspective).inverse();
let transform = transform.pre_transform(&perspective).inverse();
let origin = border_box.origin;
let transform_clip = |clip: Rect<Au>| {
@ -3016,7 +3020,7 @@ trait ToF32Px {
fn to_f32_px(&self) -> Self::Output;
}
impl ToF32Px for TypedRect<Au> {
impl ToF32Px for Rect<Au> {
type Output = LayoutRect;
fn to_f32_px(&self) -> LayoutRect {
LayoutRect::from_untyped(&servo_geometry::au_rect_to_f32_rect(*self))

View file

@ -3,7 +3,7 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
use app_units::Au;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D, Vector2D};
use style::computed_values::image_rendering::T as ImageRendering;
use style::computed_values::mix_blend_mode::T as MixBlendMode;
use style::computed_values::transform_style::T as TransformStyle;

View file

@ -4,7 +4,7 @@
use crate::display_list::ToLayout;
use app_units::Au;
use euclid::{Point2D, Size2D, Vector2D};
use euclid::default::{Point2D, Size2D, Vector2D};
use style::properties::ComputedValues;
use style::values::computed::image::{EndingShape, LineDirection};
use style::values::computed::{Angle, GradientItem, LengthPercentage, Percentage, Position};

View file

@ -24,7 +24,7 @@ use std::f32;
use std::fmt;
use style::computed_values::_servo_top_layer::T as InTopLayer;
use webrender_api as wr;
use webrender_api::units::{LayoutPoint, LayoutRect, LayoutSize, LayoutTransform};
use webrender_api::units::{LayoutPixel, LayoutPoint, LayoutRect, LayoutSize, LayoutTransform};
use webrender_api::{BorderRadius, ClipId, ClipMode, CommonItemProperties, ComplexClipRegion};
use webrender_api::{ExternalScrollId, FilterOp, GlyphInstance, GradientStop, ImageKey};
use webrender_api::{MixBlendMode, ScrollSensitivity, Shadow, SpatialId};
@ -343,7 +343,7 @@ impl fmt::Debug for StackingContext {
#[derive(Clone, Debug, PartialEq, Serialize)]
pub struct StickyFrameData {
pub margins: SideOffsets2D<Option<f32>>,
pub margins: SideOffsets2D<Option<f32>, LayoutPixel>,
pub vertical_offset_bounds: StickyOffsetBounds,
pub horizontal_offset_bounds: StickyOffsetBounds,
}
@ -792,4 +792,4 @@ impl WebRenderImageInfo {
}
/// The type of the scroll offset list. This is only populated if WebRender is in use.
pub type ScrollOffsetMap = HashMap<ExternalScrollId, Vector2D<f32>>;
pub type ScrollOffsetMap = HashMap<ExternalScrollId, Vector2D<f32, LayoutPixel>>;

View file

@ -189,7 +189,7 @@ impl WebRenderDisplayItemConverter for DisplayItem {
),
(Some(t), None) => (t, ReferenceFrameKind::Transform),
(Some(t), Some(p)) => (
t.pre_mul(&p),
t.pre_transform(&p),
ReferenceFrameKind::Perspective {
scrolling_relative_to: None,
},

View file

@ -17,7 +17,7 @@ use crate::model::{self, AdjoiningMargins, CollapsibleMargins};
use crate::model::{IntrinsicISizes, MaybeAuto, SizeConstraint};
use crate::traversal::PreorderFlowTraversal;
use app_units::{Au, MAX_AU};
use euclid::Point2D;
use euclid::default::Point2D;
use std::cmp::{max, min};
use std::ops::Range;
use style::computed_values::align_content::T as AlignContent;

View file

@ -44,7 +44,7 @@ use crate::table_row::TableRowFlow;
use crate::table_rowgroup::TableRowGroupFlow;
use crate::table_wrapper::TableWrapperFlow;
use app_units::Au;
use euclid::{Point2D, Rect, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use gfx_traits::print_tree::PrintTree;
use gfx_traits::StackingContextId;
use num_traits::cast::FromPrimitive;

View file

@ -22,7 +22,7 @@ use crate::wrapper::ThreadSafeLayoutNodeHelpers;
use crate::ServoArc;
use app_units::Au;
use canvas_traits::canvas::{CanvasId, CanvasMsg};
use euclid::{Point2D, Rect, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use gfx::text::glyph::ByteIndex;
use gfx::text::text_run::{TextRun, TextRunSlice};
use gfx_traits::StackingContextId;
@ -2671,8 +2671,12 @@ impl Fragment {
// this.
let relative_position = self.relative_position(relative_containing_block_size);
border_box
.translate_by_size(&relative_position.to_physical(self.style.writing_mode))
.translate(&stacking_relative_flow_origin)
.translate(
relative_position
.to_physical(self.style.writing_mode)
.to_vector(),
)
.translate(*stacking_relative_flow_origin)
}
/// Given the stacking-context-relative border box, returns the stacking-context-relative
@ -2789,8 +2793,11 @@ impl Fragment {
// FIXME(pcwalton): I'm not a fan of the way this makes us crawl though so many styles all
// the time. Can't we handle relative positioning by just adjusting `border_box`?
let relative_position = self.relative_position(relative_containing_block_size);
border_box =
border_box.translate_by_size(&relative_position.to_physical(self.style.writing_mode));
border_box = border_box.translate(
relative_position
.to_physical(self.style.writing_mode)
.to_vector(),
);
let mut overflow = Overflow::from_rect(&border_box);
// Box shadows cause us to draw outside our border box.
@ -2803,7 +2810,7 @@ impl Fragment {
Au::from(box_shadow.base.blur) * BLUR_INFLATION_FACTOR;
overflow.paint = overflow
.paint
.union(&border_box.translate(&offset).inflate(inflation, inflation))
.union(&border_box.translate(offset).inflate(inflation, inflation))
}
// Outlines cause us to draw outside our border box.
@ -3172,7 +3179,11 @@ impl Fragment {
-transform_origin_z,
);
Some(pre_transform.pre_mul(&transform).pre_mul(&post_transform))
Some(
pre_transform
.pre_transform(&transform)
.pre_transform(&post_transform),
)
}
/// Returns the 4D matrix representing this fragment's perspective.
@ -3210,8 +3221,8 @@ impl Fragment {
Some(
pre_transform
.pre_mul(&perspective_matrix)
.pre_mul(&post_transform),
.pre_transform(&perspective_matrix)
.pre_transform(&post_transform),
)
},
Perspective::None => None,
@ -3378,8 +3389,8 @@ impl Overflow {
}
pub fn translate(&mut self, by: &Vector2D<Au>) {
self.scroll = self.scroll.translate(by);
self.paint = self.paint.translate(by);
self.scroll = self.scroll.translate(*by);
self.paint = self.paint.translate(*by);
}
}

View file

@ -25,6 +25,23 @@ use style::properties::ComputedValues;
use style::selector_parser::RestyleDamage;
use style::servo::restyle_damage::ServoRestyleDamage;
use style::values::generics::counters::ContentItem;
use style::values::specified::list::{QuotePair, Quotes};
lazy_static! {
static ref INITIAL_QUOTES: style::ArcSlice<QuotePair> = style::ArcSlice::from_iter_leaked(
vec![
QuotePair {
opening: "\u{201c}".to_owned().into(),
closing: "\u{201d}".to_owned().into(),
},
QuotePair {
opening: "\u{2018}".to_owned().into(),
closing: "\u{2019}".to_owned().into(),
},
]
.into_iter()
);
}
// Decimal styles per CSS-COUNTER-STYLES § 6.1:
static DECIMAL: [char; 10] = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9'];
@ -326,14 +343,17 @@ impl<'a, 'b> ResolveGeneratedContentFragmentMutator<'a, 'b> {
}
fn quote(&self, style: &ComputedValues, close: bool) -> String {
let quotes = &style.get_list().quotes;
if quotes.0.is_empty() {
let quotes = match style.get_list().quotes {
Quotes::Auto => &*INITIAL_QUOTES,
Quotes::QuoteList(ref list) => &list.0,
};
if quotes.is_empty() {
return String::new();
}
let pair = if self.traversal.quote as usize >= quotes.0.len() {
quotes.0.last().unwrap()
let pair = if self.traversal.quote as usize >= quotes.len() {
quotes.last().unwrap()
} else {
&quotes.0[self.traversal.quote as usize]
&quotes[self.traversal.quote as usize]
};
if close {
pair.closing.to_string()

View file

@ -21,7 +21,7 @@ use crate::text;
use crate::traversal::PreorderFlowTraversal;
use crate::ServoArc;
use app_units::{Au, MIN_AU};
use euclid::{Point2D, Rect, Size2D};
use euclid::default::{Point2D, Rect, Size2D};
use gfx::font::FontMetrics;
use gfx_traits::print_tree::PrintTree;
use range::{Range, RangeIndex};
@ -1977,7 +1977,7 @@ impl Flow for InlineFlow {
relative_containing_block_mode,
CoordinateSystem::Own,
)
.translate(&stacking_context_position.to_vector()),
.translate(stacking_context_position.to_vector()),
)
}
}

View file

@ -9,6 +9,8 @@ extern crate bitflags;
#[macro_use]
extern crate html5ever;
#[macro_use]
extern crate lazy_static;
#[macro_use]
extern crate log;
#[macro_use]
extern crate range;

View file

@ -20,7 +20,7 @@ use crate::fragment::{
use crate::generated_content;
use crate::inline::InlineFlow;
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use style::computed_values::list_style_type::T as ListStyleType;
use style::computed_values::position::T as Position;
use style::logical_geometry::LogicalSize;
@ -280,7 +280,7 @@ impl Flow for ListItemFlow {
.relative_containing_block_mode,
CoordinateSystem::Own,
)
.translate(&stacking_context_position.to_vector()),
.translate(stacking_context_position.to_vector()),
);
}
}

View file

@ -12,7 +12,7 @@ use crate::flow::{Flow, FlowClass, FragmentationContext, GetBaseFlow, OpaqueFlow
use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::ServoArc;
use app_units::Au;
use euclid::{Point2D, Vector2D};
use euclid::default::{Point2D, Vector2D};
use gfx_traits::print_tree::PrintTree;
use std::cmp::{max, min};
use std::fmt;

View file

@ -15,7 +15,7 @@ use crate::opaque_node::OpaqueNodeMethods;
use crate::sequential;
use crate::wrapper::LayoutNodeLayoutData;
use app_units::Au;
use euclid::{Point2D, Rect, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use ipc_channel::ipc::IpcSender;
use msg::constellation_msg::PipelineId;
use script_layout_interface::rpc::TextIndexResponse;

View file

@ -15,7 +15,7 @@ use crate::incremental::RelayoutMode;
use crate::traversal::{AssignBSizes, AssignISizes, BubbleISizes, BuildDisplayList};
use crate::traversal::{InorderFlowTraversal, PostorderFlowTraversal, PreorderFlowTraversal};
use app_units::Au;
use euclid::{Point2D, Rect, Size2D, Vector2D};
use euclid::default::{Point2D, Rect, Size2D, Vector2D};
use servo_config::opts;
use style::servo::restyle_damage::ServoRestyleDamage;
use webrender_api::units::LayoutPoint;
@ -125,7 +125,7 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(
.as_block()
.stacking_relative_border_box(CoordinateSystem::Own);
if let Some(matrix) = kid.as_block().fragment.transform_matrix(&relative_position) {
let transform_matrix = matrix.transform_point2d(&LayoutPoint::zero()).unwrap();
let transform_matrix = matrix.transform_point2d(LayoutPoint::zero()).unwrap();
stacking_context_position = stacking_context_position +
Vector2D::new(
Au::from_f32_px(transform_matrix.x),

View file

@ -24,7 +24,7 @@ use crate::table_row::{self, CellIntrinsicInlineSize, CollapsedBorder, Collapsed
use crate::table_row::{TableRowFlow, TableRowSizeData};
use crate::table_wrapper::TableLayout;
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use gfx_traits::print_tree::PrintTree;
use std::{cmp, fmt};
use style::computed_values::{border_collapse, border_spacing, table_layout};

View file

@ -12,7 +12,7 @@ use crate::display_list::{
use crate::flow::{Flow, FlowClass, OpaqueFlow};
use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use gfx_traits::print_tree::PrintTree;
use std::fmt;
use style::logical_geometry::LogicalSize;

View file

@ -15,7 +15,7 @@ use crate::layout_debug;
use crate::table::InternalTable;
use crate::table_row::{CollapsedBorder, CollapsedBorderProvenance};
use app_units::Au;
use euclid::{Point2D, Rect, SideOffsets2D, Size2D};
use euclid::default::{Point2D, Rect, SideOffsets2D, Size2D};
use gfx_traits::print_tree::PrintTree;
use script_layout_interface::wrapper_traits::ThreadSafeLayoutNode;
use std::fmt;

View file

@ -10,7 +10,7 @@ use crate::flow::{BaseFlow, Flow, FlowClass, ForceNonfloatedFlag, OpaqueFlow};
use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::layout_debug;
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use std::fmt;
use style::logical_geometry::LogicalSize;
use style::properties::ComputedValues;

View file

@ -18,7 +18,7 @@ use crate::layout_debug;
use crate::table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize, InternalTable, VecExt};
use crate::table_cell::{CollapsedBordersForCell, TableCellFlow};
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use gfx_traits::print_tree::PrintTree;
use serde::{Serialize, Serializer};
use std::cmp::max;

View file

@ -14,7 +14,7 @@ use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::layout_debug;
use crate::table::{ColumnIntrinsicInlineSize, InternalTable, TableLikeFlow};
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use gfx_traits::print_tree::PrintTree;
use serde::{Serialize, Serializer};
use std::fmt;

View file

@ -24,7 +24,7 @@ use crate::fragment::{Fragment, FragmentBorderBoxIterator, Overflow};
use crate::model::MaybeAuto;
use crate::table::{ColumnComputedInlineSize, ColumnIntrinsicInlineSize};
use app_units::Au;
use euclid::Point2D;
use euclid::default::Point2D;
use gfx_traits::print_tree::PrintTree;
use std::cmp::{max, min};
use std::fmt;