Skip to content

Commit

Permalink
Layout: Remove redundant deny unsafe and format
Browse files Browse the repository at this point in the history
Add license to two files.

Bypass DisplayListBuilder for some items.
  • Loading branch information
pyfisch committed Oct 22, 2018
1 parent 2ff330a commit d9b1950
Show file tree
Hide file tree
Showing 21 changed files with 62 additions and 89 deletions.
2 changes: 0 additions & 2 deletions components/layout/block.rs
Expand Up @@ -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};
Expand Down
2 changes: 0 additions & 2 deletions components/layout/construct.rs
Expand Up @@ -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};
Expand Down
3 changes: 1 addition & 2 deletions components/layout/display_list/background.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Au>,
Expand Down
63 changes: 28 additions & 35 deletions 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;
Expand All @@ -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<Au>,
) -> Size2D<Au> {
fn corner_radius(radius: BorderCornerRadius, containing_size: Size2D<Au>) -> Size2D<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)
Expand Down Expand Up @@ -76,34 +77,27 @@ fn overlapping_radii(size: LayoutSize, radii: BorderRadius) -> BorderRadius {
}
}


pub fn radii(
abs_bounds: Rect<Au>,
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<Au>, 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.

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(),
},
)
}
Expand All @@ -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<Au>,
) -> BorderRadius {
pub fn inner_radii(mut radii: BorderRadius, offsets: SideOffsets2D<Au>) -> BorderRadius {
fn inner_length(x: f32, offset: Au) -> f32 {
0.0_f32.max(x - offset.to_f32_px())
}
Expand All @@ -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 {
Expand All @@ -155,10 +146,8 @@ fn side_image_outset(outset: LengthOrNumber, border_width: Au) -> Au {
}
}

pub fn image_outset(
outset: BorderImageOutset,
border: SideOffsets2D<Au>,
) -> SideOffsets2D<Au> {
/// Compute the additional border-image area.
pub fn image_outset(outset: BorderImageOutset, border: SideOffsets2D<Au>) -> SideOffsets2D<Au> {
SideOffsets2D::new(
side_image_outset(outset.0, border.top),
side_image_outset(outset.1, border.right),
Expand Down Expand Up @@ -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(
resolve_percentage(border_image_slice.0, height),
resolve_percentage(border_image_slice.1, width),
Expand Down
21 changes: 9 additions & 12 deletions components/layout/display_list/builder.rs
Expand Up @@ -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};
Expand Down Expand Up @@ -1338,7 +1336,8 @@ impl FragmentDisplayListBuilding for Fragment {
bounds,
image,
border_widths,
).is_some()
)
.is_some()
{
return;
}
Expand Down Expand Up @@ -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(),
)));
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions 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;
Expand Down Expand Up @@ -90,7 +94,8 @@ fn convert_gradient_stops(
.filter_map(|item| match *item {
GenericGradientItem::ColorStop(ref stop) => Some(*stop),
_ => None,
}).collect::<Vec<_>>();
})
.collect::<Vec<_>>();

assert!(stop_items.len() >= 2);

Expand Down Expand Up @@ -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(),
)
}

Expand Down Expand Up @@ -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(),
)
}
11 changes: 7 additions & 4 deletions components/layout/display_list/webrender_helpers.rs
Expand Up @@ -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(
Expand Down
2 changes: 0 additions & 2 deletions components/layout/flex.rs
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/fragment.rs
Expand Up @@ -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};
Expand Down
2 changes: 0 additions & 2 deletions components/layout/inline.rs
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/list_item.rs
Expand Up @@ -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};
Expand Down
2 changes: 0 additions & 2 deletions components/layout/model.rs
Expand Up @@ -4,8 +4,6 @@

//! Borders, padding, and margins.

#![deny(unsafe_code)]

use app_units::Au;
use euclid::SideOffsets2D;
use fragment::Fragment;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/multicol.rs
Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use block::{BlockFlow, CandidateBSizeIterator, ISizeAndMarginsComputer};
use block::{ISizeConstraintInput, ISizeConstraintSolution};
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table_caption.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use block::BlockFlow;
use context::LayoutContext;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table_cell.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer, MarginsMayCollapseFlag};
use context::LayoutContext;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table_colgroup.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use context::LayoutContext;
use display_list::{DisplayListBuildState, StackingContextCollectionState};
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table_row.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer};
use context::LayoutContext;
Expand Down
2 changes: 0 additions & 2 deletions components/layout/table_rowgroup.rs
Expand Up @@ -4,8 +4,6 @@

//! CSS table formatting contexts.

#![deny(unsafe_code)]

use app_units::Au;
use block::{BlockFlow, ISizeAndMarginsComputer};
use context::LayoutContext;
Expand Down

0 comments on commit d9b1950

Please sign in to comment.