Layout: Remove redundant deny unsafe and format

Add license to two files.

Bypass DisplayListBuilder for some items.
This commit is contained in:
Pyfisch 2018-10-17 11:23:18 +02:00
parent 2ff330a5c9
commit d9b1950d74
21 changed files with 62 additions and 89 deletions

View file

@ -25,8 +25,6 @@
//! //!
//! http://dev.w3.org/csswg/css-sizing/ //! http://dev.w3.org/csswg/css-sizing/
#![deny(unsafe_code)]
use app_units::{Au, MAX_AU}; use app_units::{Au, MAX_AU};
use context::LayoutContext; use context::LayoutContext;
use display_list::{BlockFlowDisplayListBuilding, BorderPaintingMode}; use display_list::{BlockFlowDisplayListBuilding, BorderPaintingMode};

View file

@ -11,8 +11,6 @@
//! maybe it's an absolute or fixed position thing that hasn't found its containing block yet. //! 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. //! Construction items bubble up the tree from children to parents until they find their homes.
#![deny(unsafe_code)]
use ServoArc; use ServoArc;
use block::BlockFlow; use block::BlockFlow;
use context::{LayoutContext, with_thread_local_font_context}; use context::{LayoutContext, with_thread_local_font_context};

View file

@ -2,8 +2,6 @@
* 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/. */
#![deny(unsafe_code)]
// FIXME(rust-lang/rust#26264): Remove GenericBackgroundSize. // FIXME(rust-lang/rust#26264): Remove GenericBackgroundSize.
use app_units::Au; use app_units::Au;
@ -120,6 +118,7 @@ fn compute_background_image_size(
} }
} }
/// Compute a rounded clip rect for the background.
pub fn clip( pub fn clip(
bg_clip: BackgroundClip, bg_clip: BackgroundClip,
absolute_bounds: Rect<Au>, absolute_bounds: Rect<Au>,

View file

@ -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. // FIXME(rust-lang/rust#26264): Remove GenericBorderImageSideWidth.
use app_units::Au; use app_units::Au;
@ -22,10 +26,7 @@ use webrender_api::{LayoutSize, LayoutSideOffsets, NormalBorder};
/// > Percentages: Refer to corresponding dimension of the border box. /// > Percentages: Refer to corresponding dimension of the border box.
/// ///
/// [1]: https://drafts.csswg.org/css-backgrounds-3/#border-radius /// [1]: https://drafts.csswg.org/css-backgrounds-3/#border-radius
fn corner_radius( fn corner_radius(radius: BorderCornerRadius, containing_size: Size2D<Au>) -> Size2D<Au> {
radius: BorderCornerRadius,
containing_size: Size2D<Au>,
) -> Size2D<Au> {
let w = radius.0.width().to_used_value(containing_size.width); let w = radius.0.width().to_used_value(containing_size.width);
let h = radius.0.height().to_used_value(containing_size.height); let h = radius.0.height().to_used_value(containing_size.height);
Size2D::new(w, h) Size2D::new(w, h)
@ -76,11 +77,12 @@ fn overlapping_radii(size: LayoutSize, radii: BorderRadius) -> BorderRadius {
} }
} }
/// Determine the four corner radii of a border.
pub fn radii( ///
abs_bounds: Rect<Au>, /// Radii may either be absolute or relative to the absolute bounds.
border_style: &Border, /// Each corner radius has a width and a height which may differ.
) -> BorderRadius { /// Lastly overlapping radii are shrank so they don't collide anymore.
pub fn radii(abs_bounds: Rect<Au>, border_style: &Border) -> BorderRadius {
// 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 extension 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.
@ -88,22 +90,14 @@ pub fn radii(
overlapping_radii( overlapping_radii(
abs_bounds.size.to_layout(), abs_bounds.size.to_layout(),
BorderRadius { BorderRadius {
top_left: corner_radius( top_left: corner_radius(border_style.border_top_left_radius, abs_bounds.size)
border_style.border_top_left_radius, .to_layout(),
abs_bounds.size, top_right: corner_radius(border_style.border_top_right_radius, abs_bounds.size)
).to_layout(), .to_layout(),
top_right: corner_radius( bottom_right: corner_radius(border_style.border_bottom_right_radius, abs_bounds.size)
border_style.border_top_right_radius, .to_layout(),
abs_bounds.size, bottom_left: corner_radius(border_style.border_bottom_left_radius, abs_bounds.size)
).to_layout(), .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. /// the inner radii need to be smaller depending on the line width.
/// ///
/// This is used to determine clipping areas. /// This is used to determine clipping areas.
pub fn inner_radii( pub fn inner_radii(mut radii: BorderRadius, offsets: SideOffsets2D<Au>) -> BorderRadius {
mut radii: BorderRadius,
offsets: SideOffsets2D<Au>,
) -> BorderRadius {
fn inner_length(x: f32, offset: Au) -> f32 { fn inner_length(x: f32, offset: Au) -> f32 {
0.0_f32.max(x - offset.to_f32_px()) 0.0_f32.max(x - offset.to_f32_px())
} }
@ -135,7 +126,7 @@ pub fn inner_radii(
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 { pub fn simple(color: ColorF, style: BorderStyle) -> NormalBorder {
let side = BorderSide { color, style }; let side = BorderSide { color, style };
NormalBorder { NormalBorder {
@ -155,10 +146,8 @@ fn side_image_outset(outset: LengthOrNumber, border_width: Au) -> Au {
} }
} }
pub fn image_outset( /// Compute the additional border-image area.
outset: BorderImageOutset, pub fn image_outset(outset: BorderImageOutset, border: SideOffsets2D<Au>) -> SideOffsets2D<Au> {
border: SideOffsets2D<Au>,
) -> SideOffsets2D<Au> {
SideOffsets2D::new( SideOffsets2D::new(
side_image_outset(outset.0, border.top), side_image_outset(outset.0, border.top),
side_image_outset(outset.1, border.right), 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<NumberOrPercentage>, width: u32, height: u32) -> SideOffsets2D<u32> { pub fn image_slice(
border_image_slice: &StyleRect<NumberOrPercentage>,
width: u32,
height: u32,
) -> SideOffsets2D<u32> {
SideOffsets2D::new( SideOffsets2D::new(
resolve_percentage(border_image_slice.0, height), resolve_percentage(border_image_slice.0, height),
resolve_percentage(border_image_slice.1, width), resolve_percentage(border_image_slice.1, width),

View file

@ -8,8 +8,6 @@
//! list building, as the actual painting does not happen here—only deciding *what* we're going to //! list building, as the actual painting does not happen here—only deciding *what* we're going to
//! paint. //! paint.
#![deny(unsafe_code)]
use app_units::{Au, AU_PER_PX}; use app_units::{Au, AU_PER_PX};
use block::BlockFlow; use block::BlockFlow;
use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg}; use canvas_traits::canvas::{CanvasMsg, FromLayoutMsg};
@ -1338,7 +1336,8 @@ impl FragmentDisplayListBuilding for Fragment {
bounds, bounds,
image, image,
border_widths, border_widths,
).is_some() )
.is_some()
{ {
return; return;
} }
@ -1519,10 +1518,7 @@ impl FragmentDisplayListBuilding for Fragment {
base, base,
webrender_api::BorderDisplayItem { webrender_api::BorderDisplayItem {
widths: SideOffsets2D::new_all_same(width).to_layout(), widths: SideOffsets2D::new_all_same(width).to_layout(),
details: BorderDetails::Normal(border::simple( details: BorderDetails::Normal(border::simple(color, outline_style.to_layout())),
color,
outline_style.to_layout(),
)),
}, },
Vec::new(), Vec::new(),
))); )));
@ -1996,8 +1992,7 @@ impl FragmentDisplayListBuilding for Fragment {
} }
}, },
SpecificFragmentInfo::Media(ref fragment_info) => { 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); let base = create_base_display_item(state);
state.add_image_item( state.add_image_item(
base, base,
@ -2011,7 +2006,7 @@ impl FragmentDisplayListBuilding for Fragment {
}, },
); );
} }
} },
SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => { SpecificFragmentInfo::Canvas(ref canvas_fragment_info) => {
let image_key = match canvas_fragment_info.source { let image_key = match canvas_fragment_info.source {
CanvasFragmentSource::WebGL(image_key) => image_key, CanvasFragmentSource::WebGL(image_key) => image_key,
@ -2023,7 +2018,8 @@ impl FragmentDisplayListBuilding for Fragment {
.send(CanvasMsg::FromLayout( .send(CanvasMsg::FromLayout(
FromLayoutMsg::SendData(sender), FromLayoutMsg::SendData(sender),
canvas_fragment_info.canvas_id.clone(), canvas_fragment_info.canvas_id.clone(),
)).unwrap(); ))
.unwrap();
receiver.recv().unwrap().image_key receiver.recv().unwrap().image_key
}, },
None => return, None => return,
@ -2140,7 +2136,8 @@ impl FragmentDisplayListBuilding for Fragment {
self.style.writing_mode, self.style.writing_mode,
Au(0), Au(0),
metrics.ascent, metrics.ascent,
).to_physical(self.style.writing_mode, container_size) )
.to_physical(self.style.writing_mode, container_size)
.to_vector(); .to_vector();
// Base item for all text/shadows // Base item for all text/shadows

View file

@ -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. // FIXME(rust-lang/rust#26264): Remove GenericEndingShape and GenericGradientItem.
use app_units::Au; use app_units::Au;
@ -90,7 +94,8 @@ fn convert_gradient_stops(
.filter_map(|item| match *item { .filter_map(|item| match *item {
GenericGradientItem::ColorStop(ref stop) => Some(*stop), GenericGradientItem::ColorStop(ref stop) => Some(*stop),
_ => None, _ => None,
}).collect::<Vec<_>>(); })
.collect::<Vec<_>>();
assert!(stop_items.len() >= 2); assert!(stop_items.len() >= 2);
@ -273,8 +278,12 @@ pub fn linear(
let center = Point2D::new(size.width / 2, size.height / 2); let center = Point2D::new(size.width / 2, size.height / 2);
( (
builder.gradient((center - delta).to_layout(), (center + delta).to_layout(), extend_mode(repeating)), builder.gradient(
builder.stops().to_vec() (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); 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(), builder.stops().to_vec(),
) )
} }

View file

@ -115,17 +115,20 @@ impl WebRenderDisplayItemConverter for DisplayItem {
}, },
DisplayItem::Border(ref item) => { DisplayItem::Border(ref item) => {
if !item.data.is_empty() { 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()); builder.push_item(SpecificDisplayItem::Border(item.item), &self.prim_info());
}, },
DisplayItem::Gradient(ref item) => { 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()); builder.push_item(SpecificDisplayItem::Gradient(item.item), &self.prim_info());
}, },
DisplayItem::RadialGradient(ref item) => { DisplayItem::RadialGradient(ref item) => {
builder.push_iter(item.data.iter()); builder.push_stops(item.data.as_ref());
builder.push_item(SpecificDisplayItem::RadialGradient(item.item), &self.prim_info()); builder.push_item(
SpecificDisplayItem::RadialGradient(item.item),
&self.prim_info(),
);
}, },
DisplayItem::Line(ref item) => { DisplayItem::Line(ref item) => {
builder.push_line( builder.push_line(

View file

@ -4,8 +4,6 @@
//! Layout for elements with a CSS `display` property of `flex`. //! Layout for elements with a CSS `display` property of `flex`.
#![deny(unsafe_code)]
use app_units::{Au, MAX_AU}; use app_units::{Au, MAX_AU};
use block::{AbsoluteAssignBSizesTraversal, BlockFlow, MarginsMayCollapseFlag}; use block::{AbsoluteAssignBSizesTraversal, BlockFlow, MarginsMayCollapseFlag};
use context::LayoutContext; use context::LayoutContext;

View file

@ -4,8 +4,6 @@
//! The `Fragment` type, which represents the leaves of the layout tree. //! The `Fragment` type, which represents the leaves of the layout tree.
#![deny(unsafe_code)]
use ServoArc; use ServoArc;
use app_units::Au; use app_units::Au;
use canvas_traits::canvas::{CanvasMsg, CanvasId}; use canvas_traits::canvas::{CanvasMsg, CanvasId};

View file

@ -2,8 +2,6 @@
* 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/. */
#![deny(unsafe_code)]
use ServoArc; use ServoArc;
use app_units::{Au, MIN_AU}; use app_units::{Au, MIN_AU};
use block::AbsoluteAssignBSizesTraversal; use block::AbsoluteAssignBSizesTraversal;

View file

@ -5,8 +5,6 @@
//! Layout for elements with a CSS `display` property of `list-item`. These elements consist of a //! 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. //! block and an extra inline fragment for the marker.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::BlockFlow; use block::BlockFlow;
use context::{LayoutContext, with_thread_local_font_context}; use context::{LayoutContext, with_thread_local_font_context};

View file

@ -4,8 +4,6 @@
//! Borders, padding, and margins. //! Borders, padding, and margins.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use euclid::SideOffsets2D; use euclid::SideOffsets2D;
use fragment::Fragment; use fragment::Fragment;

View file

@ -4,8 +4,6 @@
//! CSS Multi-column layout http://dev.w3.org/csswg/css-multicol/ //! CSS Multi-column layout http://dev.w3.org/csswg/css-multicol/
#![deny(unsafe_code)]
use ServoArc; use ServoArc;
use app_units::Au; use app_units::Au;
use block::BlockFlow; use block::BlockFlow;

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer}; use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer};
use block::{ISizeConstraintInput, ISizeConstraintSolution}; use block::{ISizeConstraintInput, ISizeConstraintSolution};

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::BlockFlow; use block::BlockFlow;
use context::LayoutContext; use context::LayoutContext;

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag}; use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag};
use context::LayoutContext; use context::LayoutContext;

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use context::LayoutContext; use context::LayoutContext;
use display_list::{DisplayListBuildState, StackingContextCollectionState}; use display_list::{DisplayListBuildState, StackingContextCollectionState};

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer}; use block::{BlockFlow, ISizeAndMarginsComputer};
use context::LayoutContext; use context::LayoutContext;

View file

@ -4,8 +4,6 @@
//! CSS table formatting contexts. //! CSS table formatting contexts.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer}; use block::{BlockFlow, ISizeAndMarginsComputer};
use context::LayoutContext; use context::LayoutContext;

View file

@ -11,8 +11,6 @@
//! //!
//! Hereafter this document is referred to as INTRINSIC. //! Hereafter this document is referred to as INTRINSIC.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use block::{AbsoluteNonReplaced, BlockFlow, FloatNonReplaced, ISizeAndMarginsComputer, ISizeConstraintInput}; use block::{AbsoluteNonReplaced, BlockFlow, FloatNonReplaced, ISizeAndMarginsComputer, ISizeConstraintInput};
use block::{ISizeConstraintSolution, MarginsMayCollapseFlag}; use block::{ISizeConstraintSolution, MarginsMayCollapseFlag};

View file

@ -4,8 +4,6 @@
//! Text layout. //! Text layout.
#![deny(unsafe_code)]
use app_units::Au; use app_units::Au;
use context::LayoutFontContext; use context::LayoutFontContext;
use fragment::{Fragment, ScannedTextFlags}; use fragment::{Fragment, ScannedTextFlags};