Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust-geom API changes #6349

Merged
merged 1 commit into from Jun 13, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -29,7 +29,7 @@ impl<'a> CanvasPaintTask<'a> {
fn read_pixels(&self, read_rect: Rect<f64>, canvas_size: Size2D<f64>) -> Vec<u8>{
let read_rect = read_rect.to_i32();
let canvas_size = canvas_size.to_i32();
let canvas_rect = Rect(Point2D(0i32, 0i32), canvas_size);
let canvas_rect = Rect::new(Point2D::new(0i32, 0i32), canvas_size);
let src_read_rect = canvas_rect.intersection(&read_rect).unwrap_or(Rect::zero());

let mut image_data = Vec::new();
@@ -147,7 +147,7 @@ impl<'a> CanvasPaintTask<'a> {
if imagedata.len() == 0 {
return
}
let image_rect = Rect(Point2D(0f64, 0f64), image_size);
let image_rect = Rect::new(Point2D::new(0f64, 0f64), image_size);
// rgba -> bgra
byte_swap(&mut imagedata);
self.write_pixels(&imagedata, image_size, image_rect, dest_rect, smoothing_enabled);
@@ -301,15 +301,15 @@ impl<'a> CanvasPaintTask<'a> {
}

fn fill_rect(&self, rect: &Rect<f32>) {
let draw_rect = Rect(rect.origin,
let draw_rect = Rect::new(rect.origin,
match self.state.fill_style {
Pattern::Surface(ref surface) => {
let surface_size = surface.size();
match (surface.repeat_x, surface.repeat_y) {
(true, true) => rect.size,
(true, false) => Size2D(rect.size.width, surface_size.height as f32),
(false, true) => Size2D(surface_size.width as f32, rect.size.height),
(false, false) => Size2D(surface_size.width as f32, surface_size.height as f32),
(true, false) => Size2D::new(rect.size.width, surface_size.height as f32),
(false, true) => Size2D::new(surface_size.width as f32, rect.size.height),
(false, false) => Size2D::new(surface_size.width as f32, surface_size.height as f32),
}
},
_ => rect.size,
@@ -398,11 +398,11 @@ impl<'a> CanvasPaintTask<'a> {
}

fn rect(&self, rect: &Rect<f32>) {
self.path_builder.move_to(Point2D(rect.origin.x, rect.origin.y));
self.path_builder.line_to(Point2D(rect.origin.x + rect.size.width, rect.origin.y));
self.path_builder.line_to(Point2D(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height));
self.path_builder.line_to(Point2D(rect.origin.x, rect.origin.y + rect.size.height));
self.path_builder.move_to(Point2D::new(rect.origin.x, rect.origin.y));
self.path_builder.line_to(Point2D::new(rect.origin.x + rect.size.width, rect.origin.y));
self.path_builder.line_to(Point2D::new(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height));
self.path_builder.line_to(Point2D::new(rect.origin.x, rect.origin.y + rect.size.height));
self.path_builder.close();
}

@@ -462,12 +462,12 @@ impl<'a> CanvasPaintTask<'a> {
// first tangent point
let anx = (cp1.x - cp0.x) / a2.sqrt();
let any = (cp1.y - cp0.y) / a2.sqrt();
let tp1 = Point2D::<AzFloat>(cp1.x - anx * d, cp1.y - any * d);
let tp1 = Point2D::new(cp1.x - anx * d, cp1.y - any * d);

// second tangent point
let bnx = (cp1.x - cp2.x) / b2.sqrt();
let bny = (cp1.y - cp2.y) / b2.sqrt();
let tp2 = Point2D::<AzFloat>(cp1.x - bnx * d, cp1.y - bny * d);
let tp2 = Point2D::new(cp1.x - bnx * d, cp1.y - bny * d);

// arc center and angles
let anticlockwise = direction < 0.0;
@@ -478,7 +478,7 @@ impl<'a> CanvasPaintTask<'a> {

self.line_to(&tp1);
if [cx, cy, angle_start, angle_end].iter().all(|x| x.is_finite()) {
self.arc(&Point2D::<AzFloat>(cx, cy), radius,
self.arc(&Point2D::new(cx, cy), radius,
angle_start, angle_end, anticlockwise);
}
}
@@ -577,8 +577,8 @@ impl<'a> CanvasPaintTask<'a> {
// rgba -> bgra
byte_swap(&mut imagedata);

let image_rect = Rect(Point2D(0f64, 0f64),
Size2D(image_data_rect.size.width, image_data_rect.size.height));
let image_rect = Rect::new(Point2D::new(0f64, 0f64),
Size2D::new(image_data_rect.size.width, image_data_rect.size.height));

// Dirty rectangle defines the area of the source image to be copied
// on the destination canvas
@@ -602,10 +602,10 @@ impl<'a> CanvasPaintTask<'a> {
// data structure's Canvas Pixel ArrayBuffer to the pixel with coordinate
// (dx+x, dy+y) in the rendering context's scratch bitmap.
// It also clips the destination rectangle to the canvas area
let dest_rect = Rect(
Point2D(image_data_rect.origin.x + source_rect.origin.x,
image_data_rect.origin.y + source_rect.origin.y),
Size2D(source_rect.size.width, source_rect.size.height));
let dest_rect = Rect::new(
Point2D::new(image_data_rect.origin.x + source_rect.origin.x,
image_data_rect.origin.y + source_rect.origin.y),
Size2D::new(source_rect.size.width, source_rect.size.height));

self.write_pixels(&imagedata, image_data_rect.size, source_rect, dest_rect, true)
}
@@ -664,8 +664,8 @@ pub trait SizeToi32 {

impl SizeToi32 for Size2D<f64> {
fn to_i32(&self) -> Size2D<i32> {
Size2D(self.width.to_i32().unwrap(),
self.height.to_i32().unwrap())
Size2D::new(self.width.to_i32().unwrap(),
self.height.to_i32().unwrap())
}
}

@@ -676,17 +676,17 @@ pub trait RectToi32 {

impl RectToi32 for Rect<f64> {
fn to_i32(&self) -> Rect<i32> {
Rect(Point2D(self.origin.x.to_i32().unwrap(),
self.origin.y.to_i32().unwrap()),
Size2D(self.size.width.to_i32().unwrap(),
self.size.height.to_i32().unwrap()))
Rect::new(Point2D::new(self.origin.x.to_i32().unwrap(),
self.origin.y.to_i32().unwrap()),
Size2D::new(self.size.width.to_i32().unwrap(),
self.size.height.to_i32().unwrap()))
}

fn ceil(&self) -> Rect<f64> {
Rect(Point2D(self.origin.x.ceil(),
self.origin.y.ceil()),
Size2D(self.size.width.ceil(),
self.size.height.ceil()))
Rect::new(Point2D::new(self.origin.x.ceil(),
self.origin.y.ceil()),
Size2D::new(self.size.width.ceil(),
self.size.height.ceil()))
}

}
@@ -697,7 +697,7 @@ pub trait ToAzFloat {

impl ToAzFloat for Rect<f64> {
fn to_azfloat(&self) -> Rect<AzFloat> {
Rect(Point2D(self.origin.x as AzFloat, self.origin.y as AzFloat),
Size2D(self.size.width as AzFloat, self.size.height as AzFloat))
Rect::new(Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat),
Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat))
}
}
@@ -224,8 +224,8 @@ impl FillOrStrokeStyle {
}).collect();

Pattern::LinearGradient(LinearGradientPattern::new(
&Point2D(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
&Point2D(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
&Point2D::new(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat),
&Point2D::new(linear_gradient_style.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Matrix2D::identity()))
},
@@ -238,8 +238,8 @@ impl FillOrStrokeStyle {
}).collect();

Pattern::RadialGradient(RadialGradientPattern::new(
&Point2D(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
&Point2D(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
&Point2D::new(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat),
&Point2D::new(radial_gradient_style.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Matrix2D::identity()))
@@ -699,7 +699,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) {
Some(ref layer) => {
if layer.wants_scroll_events() == WantsScrollEventsFlag::WantsScrollEvents {
layer.clamp_scroll_offset_and_scroll_layer(TypedPoint2D(0f32, 0f32) - origin);
layer.clamp_scroll_offset_and_scroll_layer(Point2D::typed(0f32, 0f32) - origin);
}
true
}
@@ -957,14 +957,14 @@ impl<Window: WindowMethods> IOCompositor<Window> {
window_size: &TypedSize2D<LayerPixel, f32>,
new_display_ports: &mut HashMap<PipelineId, Vec<(LayerId, Rect<Au>)>>) {
let visible_rect =
Rect(Point2D::zero(), *window_size).translate(&-*layer.content_offset.borrow())
.intersection(&*layer.bounds.borrow())
.unwrap_or(Rect::zero())
.to_untyped();
let visible_rect = Rect(Point2D(Au::from_f32_px(visible_rect.origin.x),
Au::from_f32_px(visible_rect.origin.y)),
Size2D(Au::from_f32_px(visible_rect.size.width),
Au::from_f32_px(visible_rect.size.height)));
Rect::new(Point2D::zero(), *window_size).translate(&-*layer.content_offset.borrow())
.intersection(&*layer.bounds.borrow())
.unwrap_or(Rect::zero())
.to_untyped();
let visible_rect = Rect::new(Point2D::new(Au::from_f32_px(visible_rect.origin.x),
Au::from_f32_px(visible_rect.origin.y)),
Size2D::new(Au::from_f32_px(visible_rect.size.width),
Au::from_f32_px(visible_rect.size.height)));

let extra_layer_data = layer.extra_data.borrow();
if !new_display_ports.contains_key(&extra_layer_data.pipeline_id) {
@@ -1087,11 +1087,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {

// Scroll as needed
let window_size = self.window_size.as_f32();
let page_delta: TypedPoint2D<LayerPixel, f32> = TypedPoint2D(
let page_delta: TypedPoint2D<LayerPixel, f32> = Point2D::typed(
window_size.width.get() * (viewport_zoom.inv() - old_viewport_zoom.inv()).get() * 0.5,
window_size.height.get() * (viewport_zoom.inv() - old_viewport_zoom.inv()).get() * 0.5);

let cursor = TypedPoint2D(-1f32, -1f32); // Make sure this hits the base layer.
let cursor = Point2D::typed(-1f32, -1f32); // Make sure this hits the base layer.
match self.scene.root {
Some(ref mut layer) => {
layer.handle_scroll_event(page_delta, cursor);
@@ -1167,8 +1167,8 @@ impl<Window: WindowMethods> IOCompositor<Window> {

fn send_viewport_rect_for_layer(&self, layer: Rc<Layer<CompositorData>>) {
if layer.extra_data.borrow().id == LayerId::null() {
let layer_rect = Rect(-layer.extra_data.borrow().scroll_offset.to_untyped(),
layer.bounds.borrow().size.to_untyped());
let layer_rect = Rect::new(-layer.extra_data.borrow().scroll_offset.to_untyped(),
layer.bounds.borrow().size.to_untyped());
let pipeline = self.get_pipeline(layer.pipeline_id());
let ScriptControlChan(ref chan) = pipeline.script_chan;
chan.send(ConstellationControlMsg::Viewport(pipeline.id.clone(), layer_rect)).unwrap();
@@ -1437,7 +1437,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
};

let clip_rect_for_children = if masks_to_bounds {
Rect(Point2D::zero(), clipped_layer_bounds.size)
Rect::new(Point2D::zero(), clipped_layer_bounds.size)
} else {
clipped_layer_bounds.translate(&clip_rect.origin)
};
@@ -7,7 +7,7 @@ use windowing::{MouseWindowEvent, WindowMethods};

use azure::azure_hl;
use geom::length::Length;
use geom::matrix::identity;
use geom::matrix::Matrix4;
use geom::point::{Point2D, TypedPoint2D};
use geom::size::TypedSize2D;
use geom::rect::Rect;
@@ -59,7 +59,7 @@ impl CompositorData {
scroll_policy: layer_properties.scroll_policy,
requested_epoch: Epoch(0),
painted_epoch: Epoch(0),
scroll_offset: TypedPoint2D(0., 0.),
scroll_offset: Point2D::typed(0., 0.),
};

Rc::new(Layer::new(Rect::from_untyped(&layer_properties.rect),
@@ -201,7 +201,7 @@ impl CompositorLayer for Layer<CompositorData> {

// Call scroll for bounds checking if the page shrunk. Use (-1, -1) as the
// cursor position to make sure the scroll isn't propagated downwards.
self.handle_scroll_event(TypedPoint2D(0f32, 0f32), TypedPoint2D(-1f32, -1f32));
self.handle_scroll_event(Point2D::typed(0f32, 0f32), Point2D::typed(-1f32, -1f32));
self.update_layer_except_bounds(layer_properties);
}

@@ -332,8 +332,8 @@ impl CompositorLayer for Layer<CompositorData> {
let min_x = (layer_size.width - content_size.width).get().min(0.0);
let min_y = (layer_size.height - content_size.height).get().min(0.0);
let new_offset : TypedPoint2D<LayerPixel, f32> =
Point2D(Length::new(new_offset.x.get().clamp(&min_x, &0.0)),
Length::new(new_offset.y.get().clamp(&min_y, &0.0)));
Point2D::new(Length::new(new_offset.x.get().clamp(&min_x, &0.0)),
Length::new(new_offset.y.get().clamp(&min_y, &0.0)));

if self.extra_data.borrow().scroll_offset == new_offset {
return ScrollEventResult::ScrollPositionUnchanged;
@@ -392,7 +392,7 @@ impl CompositorLayer for Layer<CompositorData> {
// Only scroll this layer if it's not fixed-positioned.
if self.extra_data.borrow().scroll_policy != ScrollPolicy::FixedPosition {
let new_offset = new_offset.to_untyped();
*self.transform.borrow_mut() = identity().translate(new_offset.x, new_offset.y, 0.0);
*self.transform.borrow_mut() = Matrix4::identity().translate(new_offset.x, new_offset.y, 0.0);
*self.content_offset.borrow_mut() = Point2D::from_untyped(&new_offset);
result = true
}
@@ -534,7 +534,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
}

fn handle_init_load(&mut self, url: Url) {
let window_rect = Rect(Point2D::zero(), self.window_size.visible_viewport);
let window_rect = Rect::new(Point2D::zero(), self.window_size.visible_viewport);
let root_pipeline_id =
self.new_pipeline(None, Some(window_rect), None, LoadData::new(url.clone()));
self.handle_load_start_msg(&root_pipeline_id);
@@ -6,7 +6,7 @@ use compositor_task::{CompositorEventListener, CompositorReceiver, Msg};
use windowing::WindowEvent;

use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D;
use geom::size::Size2D;
use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData};
use profile_traits::mem;
@@ -55,8 +55,8 @@ impl NullCompositor {
{
let ConstellationChan(ref chan) = compositor.constellation_chan;
chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
initial_viewport: TypedSize2D(640_f32, 480_f32),
visible_viewport: TypedSize2D(640_f32, 480_f32),
initial_viewport: Size2D::typed(640_f32, 480_f32),
visible_viewport: Size2D::typed(640_f32, 480_f32),
device_pixel_ratio: ScaleFactor::new(1.0),
})).unwrap();
}
@@ -472,14 +472,13 @@ impl StackingContext {
DisplayItem::BorderClass(ref border) => {
// If the point is inside the border, it didn't hit the border!
let interior_rect =
Rect(Point2D(border.base.bounds.origin.x + border.border_widths.left,
border.base.bounds.origin.y + border.border_widths.top),
Size2D(border.base.bounds.size.width -
(border.border_widths.left +
border.border_widths.right),
border.base.bounds.size.height -
(border.border_widths.top +
border.border_widths.bottom)));
Rect::new(
Point2D::new(border.base.bounds.origin.x + border.border_widths.left,
border.base.bounds.origin.y + border.border_widths.top),
Size2D::new(border.base.bounds.size.width -
(border.border_widths.left + border.border_widths.right),
border.base.bounds.size.height -
(border.border_widths.top + border.border_widths.bottom)));
if geometry::rect_contains_point(interior_rect, point) {
continue
}
@@ -499,9 +498,9 @@ impl StackingContext {
point = point - self.bounds.origin;

debug_assert!(!topmost_only || result.is_empty());
let frac_point = self.transform.transform_point(&Point2D(point.x.to_f32_px(),
let frac_point = self.transform.transform_point(&Point2D::new(point.x.to_f32_px(),
point.y.to_f32_px()));
point = Point2D(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y));
point = Point2D::new(Au::from_f32_px(frac_point.x), Au::from_f32_px(frac_point.y));

// Iterate through display items in reverse stacking order. Steps here refer to the
// painting steps in CSS 2.1 Appendix E.
@@ -228,8 +228,8 @@ pub struct RunMetrics {

impl RunMetrics {
pub fn new(advance: Au, ascent: Au, descent: Au) -> RunMetrics {
let bounds = Rect(Point2D(Au(0), -ascent),
Size2D(advance, ascent + descent));
let bounds = Rect::new(Point2D::new(Au(0), -ascent),
Size2D::new(advance, ascent + descent));

// TODO(Issue #125): support loose and tight bounding boxes; using the
// ascent+descent and advance is sometimes too generous and
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.