diff --git a/components/layout/block.rs b/components/layout/block.rs index ae1bc242e329..21ddba5d96e3 100644 --- a/components/layout/block.rs +++ b/components/layout/block.rs @@ -25,8 +25,6 @@ //! //! http://dev.w3.org/csswg/css-sizing/ -#![deny(unsafe_code)] - use app_units::{Au, MAX_AU}; use context::LayoutContext; use display_list::{BlockFlowDisplayListBuilding, BorderPaintingMode}; diff --git a/components/layout/construct.rs b/components/layout/construct.rs index ba86416f935a..48727bb3d1a4 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -11,8 +11,6 @@ //! maybe it's an absolute or fixed position thing that hasn't found its containing block yet. //! Construction items bubble up the tree from children to parents until they find their homes. -#![deny(unsafe_code)] - use ServoArc; use block::BlockFlow; use context::{LayoutContext, with_thread_local_font_context}; diff --git a/components/layout/display_list/background.rs b/components/layout/display_list/background.rs index 8b0865955b0b..305b5e5be314 100644 --- a/components/layout/display_list/background.rs +++ b/components/layout/display_list/background.rs @@ -2,8 +2,6 @@ * 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/. */ -#![deny(unsafe_code)] - // FIXME(rust-lang/rust#26264): Remove GenericBackgroundSize. use app_units::Au; @@ -120,6 +118,7 @@ fn compute_background_image_size( } } +/// Compute a rounded clip rect for the background. pub fn clip( bg_clip: BackgroundClip, absolute_bounds: Rect, diff --git a/components/layout/display_list/border.rs b/components/layout/display_list/border.rs index d4694bdfec20..8b34356ca9b0 100644 --- a/components/layout/display_list/border.rs +++ b/components/layout/display_list/border.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + // FIXME(rust-lang/rust#26264): Remove GenericBorderImageSideWidth. use app_units::Au; @@ -22,10 +26,7 @@ use webrender_api::{LayoutSize, LayoutSideOffsets, 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, -) -> Size2D { +fn corner_radius(radius: BorderCornerRadius, containing_size: Size2D) -> Size2D { 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) @@ -76,11 +77,12 @@ fn overlapping_radii(size: LayoutSize, radii: BorderRadius) -> BorderRadius { } } - -pub fn radii( - abs_bounds: Rect, - border_style: &Border, -) -> BorderRadius { +/// Determine the four corner radii of a border. +/// +/// Radii may either be absolute or relative to the absolute bounds. +/// Each corner radius has a width and a height which may differ. +/// Lastly overlapping radii are shrank so they don't collide anymore. +pub fn radii(abs_bounds: Rect, border_style: &Border) -> BorderRadius { // TODO(cgaebel): Support border radii even in the case of multiple border widths. // This is an extension of supporting elliptical radii. For now, all percentage // radii will be relative to the width. @@ -88,22 +90,14 @@ pub fn radii( overlapping_radii( abs_bounds.size.to_layout(), BorderRadius { - top_left: corner_radius( - border_style.border_top_left_radius, - abs_bounds.size, - ).to_layout(), - top_right: corner_radius( - border_style.border_top_right_radius, - abs_bounds.size, - ).to_layout(), - bottom_right: corner_radius( - border_style.border_bottom_right_radius, - abs_bounds.size, - ).to_layout(), - bottom_left: corner_radius( - border_style.border_bottom_left_radius, - abs_bounds.size, - ).to_layout(), + top_left: corner_radius(border_style.border_top_left_radius, abs_bounds.size) + .to_layout(), + top_right: corner_radius(border_style.border_top_right_radius, abs_bounds.size) + .to_layout(), + bottom_right: corner_radius(border_style.border_bottom_right_radius, abs_bounds.size) + .to_layout(), + bottom_left: corner_radius(border_style.border_bottom_left_radius, abs_bounds.size) + .to_layout(), }, ) } @@ -114,10 +108,7 @@ pub fn radii( /// 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, -) -> BorderRadius { +pub fn inner_radii(mut radii: BorderRadius, offsets: SideOffsets2D) -> BorderRadius { fn inner_length(x: f32, offset: Au) -> f32 { 0.0_f32.max(x - offset.to_f32_px()) } @@ -135,7 +126,7 @@ pub fn inner_radii( radii } -/// Creates a four-sided border with uniform color, width and corner radius. +/// Creates a four-sided border with square corners and uniform color and width. pub fn simple(color: ColorF, style: BorderStyle) -> NormalBorder { let side = BorderSide { color, style }; NormalBorder { @@ -155,10 +146,8 @@ fn side_image_outset(outset: LengthOrNumber, border_width: Au) -> Au { } } -pub fn image_outset( - outset: BorderImageOutset, - border: SideOffsets2D, -) -> SideOffsets2D { +/// Compute the additional border-image area. +pub fn image_outset(outset: BorderImageOutset, border: SideOffsets2D) -> SideOffsets2D { SideOffsets2D::new( side_image_outset(outset.0, border.top), side_image_outset(outset.1, border.right), @@ -199,7 +188,11 @@ fn resolve_percentage(value: NumberOrPercentage, length: u32) -> u32 { } } -pub fn image_slice(border_image_slice: &StyleRect, width: u32, height: u32) -> SideOffsets2D { +pub fn image_slice( + border_image_slice: &StyleRect, + width: u32, + height: u32, +) -> SideOffsets2D { SideOffsets2D::new( resolve_percentage(border_image_slice.0, height), resolve_percentage(border_image_slice.1, width), diff --git a/components/layout/display_list/builder.rs b/components/layout/display_list/builder.rs index cda931899b24..8d2354dbb191 100644 --- a/components/layout/display_list/builder.rs +++ b/components/layout/display_list/builder.rs @@ -8,8 +8,6 @@ //! list building, as the actual painting does not happen here—only deciding *what* we're going to //! paint. -#![deny(unsafe_code)] - use app_units::{Au, AU_PER_PX}; use block::BlockFlow; use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg}; @@ -1338,7 +1336,8 @@ impl FragmentDisplayListBuilding for Fragment { bounds, image, border_widths, - ).is_some() + ) + .is_some() { return; } @@ -1519,10 +1518,7 @@ impl FragmentDisplayListBuilding for Fragment { base, webrender_api::BorderDisplayItem { widths: SideOffsets2D::new_all_same(width).to_layout(), - details: BorderDetails::Normal(border::simple( - color, - outline_style.to_layout(), - )), + details: BorderDetails::Normal(border::simple(color, outline_style.to_layout())), }, Vec::new(), ))); @@ -1996,8 +1992,7 @@ impl FragmentDisplayListBuilding for Fragment { } }, SpecificFragmentInfo::Media(ref fragment_info) => { - if let Some((ref image_key, _, _)) = fragment_info.current_frame - { + if let Some((ref image_key, _, _)) = fragment_info.current_frame { let base = create_base_display_item(state); state.add_image_item( base, @@ -2011,7 +2006,7 @@ impl FragmentDisplayListBuilding for Fragment { }, ); } - } + }, SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => { let image_key = match canvas_fragment_info.source { CanvasFragmentSource::WebGL(image_key) => image_key, @@ -2023,7 +2018,8 @@ impl FragmentDisplayListBuilding for Fragment { .send(CanvasMsg::FromLayout( FromLayoutMsg::SendData(sender), canvas_fragment_info.canvas_id.clone(), - )).unwrap(); + )) + .unwrap(); receiver.recv().unwrap().image_key }, None => return, @@ -2140,7 +2136,8 @@ impl FragmentDisplayListBuilding for Fragment { self.style.writing_mode, Au(0), metrics.ascent, - ).to_physical(self.style.writing_mode, container_size) + ) + .to_physical(self.style.writing_mode, container_size) .to_vector(); // Base item for all text/shadows diff --git a/components/layout/display_list/gradient.rs b/components/layout/display_list/gradient.rs index 13ab48d6db95..bb8617968d23 100644 --- a/components/layout/display_list/gradient.rs +++ b/components/layout/display_list/gradient.rs @@ -1,3 +1,7 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + // FIXME(rust-lang/rust#26264): Remove GenericEndingShape and GenericGradientItem. use app_units::Au; @@ -90,7 +94,8 @@ fn convert_gradient_stops( .filter_map(|item| match *item { GenericGradientItem::ColorStop(ref stop) => Some(*stop), _ => None, - }).collect::>(); + }) + .collect::>(); assert!(stop_items.len() >= 2); @@ -273,8 +278,12 @@ pub fn linear( let center = Point2D::new(size.width / 2, size.height / 2); ( - builder.gradient((center - delta).to_layout(), (center + delta).to_layout(), extend_mode(repeating)), - builder.stops().to_vec() + builder.gradient( + (center - delta).to_layout(), + (center + delta).to_layout(), + extend_mode(repeating), + ), + builder.stops().to_vec(), ) } @@ -308,7 +317,11 @@ pub fn radial( let mut builder = convert_gradient_stops(style, stops, radius.width); ( - builder.radial_gradient(center.to_layout(), radius.to_layout(), extend_mode(repeating)), + builder.radial_gradient( + center.to_layout(), + radius.to_layout(), + extend_mode(repeating), + ), builder.stops().to_vec(), ) } diff --git a/components/layout/display_list/webrender_helpers.rs b/components/layout/display_list/webrender_helpers.rs index 0d7b691449e4..4c5fa9df8c29 100644 --- a/components/layout/display_list/webrender_helpers.rs +++ b/components/layout/display_list/webrender_helpers.rs @@ -115,17 +115,20 @@ impl WebRenderDisplayItemConverter for DisplayItem { }, DisplayItem::Border(ref item) => { if !item.data.is_empty() { - builder.push_iter(item.data.iter()); + builder.push_stops(item.data.as_ref()); } builder.push_item(SpecificDisplayItem::Border(item.item), &self.prim_info()); }, DisplayItem::Gradient(ref item) => { - builder.push_iter(item.data.iter()); + builder.push_stops(item.data.as_ref()); builder.push_item(SpecificDisplayItem::Gradient(item.item), &self.prim_info()); }, DisplayItem::RadialGradient(ref item) => { - builder.push_iter(item.data.iter()); - builder.push_item(SpecificDisplayItem::RadialGradient(item.item), &self.prim_info()); + builder.push_stops(item.data.as_ref()); + builder.push_item( + SpecificDisplayItem::RadialGradient(item.item), + &self.prim_info(), + ); }, DisplayItem::Line(ref item) => { builder.push_line( diff --git a/components/layout/flex.rs b/components/layout/flex.rs index e1baa3903829..1f40278e76c2 100644 --- a/components/layout/flex.rs +++ b/components/layout/flex.rs @@ -4,8 +4,6 @@ //! Layout for elements with a CSS `display` property of `flex`. -#![deny(unsafe_code)] - use app_units::{Au, MAX_AU}; use block::{AbsoluteAssignBSizesTraversal, BlockFlow, MarginsMayCollapseFlag}; use context::LayoutContext; diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 486a344989b7..3a57ce71e7d7 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -4,8 +4,6 @@ //! The `Fragment` type, which represents the leaves of the layout tree. -#![deny(unsafe_code)] - use ServoArc; use app_units::Au; use canvas_traits::canvas::{CanvasMsg, CanvasId}; diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 7a66ad84bacb..51d6013a2e93 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -2,8 +2,6 @@ * 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/. */ -#![deny(unsafe_code)] - use ServoArc; use app_units::{Au, MIN_AU}; use block::AbsoluteAssignBSizesTraversal; diff --git a/components/layout/list_item.rs b/components/layout/list_item.rs index 72e87578635b..2b05a5f7dc4e 100644 --- a/components/layout/list_item.rs +++ b/components/layout/list_item.rs @@ -5,8 +5,6 @@ //! Layout for elements with a CSS `display` property of `list-item`. These elements consist of a //! block and an extra inline fragment for the marker. -#![deny(unsafe_code)] - use app_units::Au; use block::BlockFlow; use context::{LayoutContext, with_thread_local_font_context}; diff --git a/components/layout/model.rs b/components/layout/model.rs index 53146fde90cd..b936fb2d8567 100644 --- a/components/layout/model.rs +++ b/components/layout/model.rs @@ -4,8 +4,6 @@ //! Borders, padding, and margins. -#![deny(unsafe_code)] - use app_units::Au; use euclid::SideOffsets2D; use fragment::Fragment; diff --git a/components/layout/multicol.rs b/components/layout/multicol.rs index 082fa1a13670..e689120424f6 100644 --- a/components/layout/multicol.rs +++ b/components/layout/multicol.rs @@ -4,8 +4,6 @@ //! CSS Multi-column layout http://dev.w3.org/csswg/css-multicol/ -#![deny(unsafe_code)] - use ServoArc; use app_units::Au; use block::BlockFlow; diff --git a/components/layout/table.rs b/components/layout/table.rs index cb80850e91e0..b6cf3981cd6c 100644 --- a/components/layout/table.rs +++ b/components/layout/table.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer}; use block::{ISizeConstraintInput, ISizeConstraintSolution}; diff --git a/components/layout/table_caption.rs b/components/layout/table_caption.rs index 51a6078ec319..df93326d5ce6 100644 --- a/components/layout/table_caption.rs +++ b/components/layout/table_caption.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use block::BlockFlow; use context::LayoutContext; diff --git a/components/layout/table_cell.rs b/components/layout/table_cell.rs index 1af32166a5f9..5ce5cf7a3f90 100644 --- a/components/layout/table_cell.rs +++ b/components/layout/table_cell.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag}; use context::LayoutContext; diff --git a/components/layout/table_colgroup.rs b/components/layout/table_colgroup.rs index 7a3b54a2ed0c..6698dc4228c6 100644 --- a/components/layout/table_colgroup.rs +++ b/components/layout/table_colgroup.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use context::LayoutContext; use display_list::{DisplayListBuildState, StackingContextCollectionState}; diff --git a/components/layout/table_row.rs b/components/layout/table_row.rs index 9d5c3a156181..236aeb421109 100644 --- a/components/layout/table_row.rs +++ b/components/layout/table_row.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use block::{BlockFlow, ISizeAndMarginsComputer}; use context::LayoutContext; diff --git a/components/layout/table_rowgroup.rs b/components/layout/table_rowgroup.rs index 3d77aca93823..752ad573a127 100644 --- a/components/layout/table_rowgroup.rs +++ b/components/layout/table_rowgroup.rs @@ -4,8 +4,6 @@ //! CSS table formatting contexts. -#![deny(unsafe_code)] - use app_units::Au; use block::{BlockFlow, ISizeAndMarginsComputer}; use context::LayoutContext; diff --git a/components/layout/table_wrapper.rs b/components/layout/table_wrapper.rs index 65684f8e1651..b7f84908ec25 100644 --- a/components/layout/table_wrapper.rs +++ b/components/layout/table_wrapper.rs @@ -11,8 +11,6 @@ //! //! Hereafter this document is referred to as INTRINSIC. -#![deny(unsafe_code)] - use app_units::Au; use block::{AbsoluteNonReplaced, BlockFlow, FloatNonReplaced, ISizeAndMarginsComputer, ISizeConstraintInput}; use block::{ISizeConstraintSolution, MarginsMayCollapseFlag}; diff --git a/components/layout/text.rs b/components/layout/text.rs index c8321e9a03b9..ab8de4d7ab2e 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -4,8 +4,6 @@ //! Text layout. -#![deny(unsafe_code)] - use app_units::Au; use context::LayoutFontContext; use fragment::{Fragment, ScannedTextFlags};