rust-geom API changes

https://github.com/servo/rust-geom/pull/81
This commit is contained in:
Corey Farwell 2015-06-11 20:51:07 -07:00
parent a9aa50683f
commit 5c408d2be9
39 changed files with 397 additions and 377 deletions

View file

@ -29,7 +29,7 @@ impl<'a> CanvasPaintTask<'a> {
fn read_pixels(&self, read_rect: Rect<f64>, canvas_size: Size2D<f64>) -> Vec<u8>{ fn read_pixels(&self, read_rect: Rect<f64>, canvas_size: Size2D<f64>) -> Vec<u8>{
let read_rect = read_rect.to_i32(); let read_rect = read_rect.to_i32();
let canvas_size = canvas_size.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 src_read_rect = canvas_rect.intersection(&read_rect).unwrap_or(Rect::zero());
let mut image_data = Vec::new(); let mut image_data = Vec::new();
@ -147,7 +147,7 @@ impl<'a> CanvasPaintTask<'a> {
if imagedata.len() == 0 { if imagedata.len() == 0 {
return return
} }
let image_rect = Rect(Point2D(0f64, 0f64), image_size); let image_rect = Rect::new(Point2D::new(0f64, 0f64), image_size);
// rgba -> bgra // rgba -> bgra
byte_swap(&mut imagedata); byte_swap(&mut imagedata);
self.write_pixels(&imagedata, image_size, image_rect, dest_rect, smoothing_enabled); 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>) { 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 { match self.state.fill_style {
Pattern::Surface(ref surface) => { Pattern::Surface(ref surface) => {
let surface_size = surface.size(); let surface_size = surface.size();
match (surface.repeat_x, surface.repeat_y) { match (surface.repeat_x, surface.repeat_y) {
(true, true) => rect.size, (true, true) => rect.size,
(true, false) => Size2D(rect.size.width, surface_size.height as f32), (true, false) => Size2D::new(rect.size.width, surface_size.height as f32),
(false, true) => Size2D(surface_size.width as f32, rect.size.height), (false, true) => Size2D::new(surface_size.width as f32, rect.size.height),
(false, false) => Size2D(surface_size.width as f32, surface_size.height as f32), (false, false) => Size2D::new(surface_size.width as f32, surface_size.height as f32),
} }
}, },
_ => rect.size, _ => rect.size,
@ -398,11 +398,11 @@ impl<'a> CanvasPaintTask<'a> {
} }
fn rect(&self, rect: &Rect<f32>) { fn rect(&self, rect: &Rect<f32>) {
self.path_builder.move_to(Point2D(rect.origin.x, rect.origin.y)); self.path_builder.move_to(Point2D::new(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::new(rect.origin.x + rect.size.width, rect.origin.y));
self.path_builder.line_to(Point2D(rect.origin.x + rect.size.width, self.path_builder.line_to(Point2D::new(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height)); rect.origin.y + rect.size.height));
self.path_builder.line_to(Point2D(rect.origin.x, 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(); self.path_builder.close();
} }
@ -462,12 +462,12 @@ impl<'a> CanvasPaintTask<'a> {
// first tangent point // first tangent point
let anx = (cp1.x - cp0.x) / a2.sqrt(); let anx = (cp1.x - cp0.x) / a2.sqrt();
let any = (cp1.y - cp0.y) / 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 // second tangent point
let bnx = (cp1.x - cp2.x) / b2.sqrt(); let bnx = (cp1.x - cp2.x) / b2.sqrt();
let bny = (cp1.y - cp2.y) / 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 // arc center and angles
let anticlockwise = direction < 0.0; let anticlockwise = direction < 0.0;
@ -478,7 +478,7 @@ impl<'a> CanvasPaintTask<'a> {
self.line_to(&tp1); self.line_to(&tp1);
if [cx, cy, angle_start, angle_end].iter().all(|x| x.is_finite()) { 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); angle_start, angle_end, anticlockwise);
} }
} }
@ -577,8 +577,8 @@ impl<'a> CanvasPaintTask<'a> {
// rgba -> bgra // rgba -> bgra
byte_swap(&mut imagedata); byte_swap(&mut imagedata);
let image_rect = Rect(Point2D(0f64, 0f64), let image_rect = Rect::new(Point2D::new(0f64, 0f64),
Size2D(image_data_rect.size.width, image_data_rect.size.height)); Size2D::new(image_data_rect.size.width, image_data_rect.size.height));
// Dirty rectangle defines the area of the source image to be copied // Dirty rectangle defines the area of the source image to be copied
// on the destination canvas // on the destination canvas
@ -602,10 +602,10 @@ impl<'a> CanvasPaintTask<'a> {
// data structure's Canvas Pixel ArrayBuffer to the pixel with coordinate // data structure's Canvas Pixel ArrayBuffer to the pixel with coordinate
// (dx+x, dy+y) in the rendering context's scratch bitmap. // (dx+x, dy+y) in the rendering context's scratch bitmap.
// It also clips the destination rectangle to the canvas area // It also clips the destination rectangle to the canvas area
let dest_rect = Rect( let dest_rect = Rect::new(
Point2D(image_data_rect.origin.x + source_rect.origin.x, Point2D::new(image_data_rect.origin.x + source_rect.origin.x,
image_data_rect.origin.y + source_rect.origin.y), image_data_rect.origin.y + source_rect.origin.y),
Size2D(source_rect.size.width, source_rect.size.height)); Size2D::new(source_rect.size.width, source_rect.size.height));
self.write_pixels(&imagedata, image_data_rect.size, source_rect, dest_rect, true) 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> { impl SizeToi32 for Size2D<f64> {
fn to_i32(&self) -> Size2D<i32> { fn to_i32(&self) -> Size2D<i32> {
Size2D(self.width.to_i32().unwrap(), Size2D::new(self.width.to_i32().unwrap(),
self.height.to_i32().unwrap()) self.height.to_i32().unwrap())
} }
} }
@ -676,17 +676,17 @@ pub trait RectToi32 {
impl RectToi32 for Rect<f64> { impl RectToi32 for Rect<f64> {
fn to_i32(&self) -> Rect<i32> { fn to_i32(&self) -> Rect<i32> {
Rect(Point2D(self.origin.x.to_i32().unwrap(), Rect::new(Point2D::new(self.origin.x.to_i32().unwrap(),
self.origin.y.to_i32().unwrap()), self.origin.y.to_i32().unwrap()),
Size2D(self.size.width.to_i32().unwrap(), Size2D::new(self.size.width.to_i32().unwrap(),
self.size.height.to_i32().unwrap())) self.size.height.to_i32().unwrap()))
} }
fn ceil(&self) -> Rect<f64> { fn ceil(&self) -> Rect<f64> {
Rect(Point2D(self.origin.x.ceil(), Rect::new(Point2D::new(self.origin.x.ceil(),
self.origin.y.ceil()), self.origin.y.ceil()),
Size2D(self.size.width.ceil(), Size2D::new(self.size.width.ceil(),
self.size.height.ceil())) self.size.height.ceil()))
} }
} }
@ -697,7 +697,7 @@ pub trait ToAzFloat {
impl ToAzFloat for Rect<f64> { impl ToAzFloat for Rect<f64> {
fn to_azfloat(&self) -> Rect<AzFloat> { fn to_azfloat(&self) -> Rect<AzFloat> {
Rect(Point2D(self.origin.x as AzFloat, self.origin.y as AzFloat), Rect::new(Point2D::new(self.origin.x as AzFloat, self.origin.y as AzFloat),
Size2D(self.size.width as AzFloat, self.size.height as AzFloat)) Size2D::new(self.size.width as AzFloat, self.size.height as AzFloat))
} }
} }

View file

@ -224,8 +224,8 @@ impl FillOrStrokeStyle {
}).collect(); }).collect();
Pattern::LinearGradient(LinearGradientPattern::new( Pattern::LinearGradient(LinearGradientPattern::new(
&Point2D(linear_gradient_style.x0 as AzFloat, linear_gradient_style.y0 as AzFloat), &Point2D::new(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.x1 as AzFloat, linear_gradient_style.y1 as AzFloat),
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Matrix2D::identity())) &Matrix2D::identity()))
}, },
@ -238,8 +238,8 @@ impl FillOrStrokeStyle {
}).collect(); }).collect();
Pattern::RadialGradient(RadialGradientPattern::new( Pattern::RadialGradient(RadialGradientPattern::new(
&Point2D(radial_gradient_style.x0 as AzFloat, radial_gradient_style.y0 as AzFloat), &Point2D::new(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.x1 as AzFloat, radial_gradient_style.y1 as AzFloat),
radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat, radial_gradient_style.r0 as AzFloat, radial_gradient_style.r1 as AzFloat,
drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp), drawtarget.create_gradient_stops(&gradient_stops, ExtendMode::Clamp),
&Matrix2D::identity())) &Matrix2D::identity()))

View file

@ -699,7 +699,7 @@ impl<Window: WindowMethods> IOCompositor<Window> {
match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) { match self.find_layer_with_pipeline_and_layer_id(pipeline_id, layer_id) {
Some(ref layer) => { Some(ref layer) => {
if layer.wants_scroll_events() == WantsScrollEventsFlag::WantsScrollEvents { 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 true
} }
@ -957,14 +957,14 @@ impl<Window: WindowMethods> IOCompositor<Window> {
window_size: &TypedSize2D<LayerPixel, f32>, window_size: &TypedSize2D<LayerPixel, f32>,
new_display_ports: &mut HashMap<PipelineId, Vec<(LayerId, Rect<Au>)>>) { new_display_ports: &mut HashMap<PipelineId, Vec<(LayerId, Rect<Au>)>>) {
let visible_rect = let visible_rect =
Rect(Point2D::zero(), *window_size).translate(&-*layer.content_offset.borrow()) Rect::new(Point2D::zero(), *window_size).translate(&-*layer.content_offset.borrow())
.intersection(&*layer.bounds.borrow()) .intersection(&*layer.bounds.borrow())
.unwrap_or(Rect::zero()) .unwrap_or(Rect::zero())
.to_untyped(); .to_untyped();
let visible_rect = Rect(Point2D(Au::from_f32_px(visible_rect.origin.x), let visible_rect = Rect::new(Point2D::new(Au::from_f32_px(visible_rect.origin.x),
Au::from_f32_px(visible_rect.origin.y)), Au::from_f32_px(visible_rect.origin.y)),
Size2D(Au::from_f32_px(visible_rect.size.width), Size2D::new(Au::from_f32_px(visible_rect.size.width),
Au::from_f32_px(visible_rect.size.height))); Au::from_f32_px(visible_rect.size.height)));
let extra_layer_data = layer.extra_data.borrow(); let extra_layer_data = layer.extra_data.borrow();
if !new_display_ports.contains_key(&extra_layer_data.pipeline_id) { if !new_display_ports.contains_key(&extra_layer_data.pipeline_id) {
@ -1087,11 +1087,11 @@ impl<Window: WindowMethods> IOCompositor<Window> {
// Scroll as needed // Scroll as needed
let window_size = self.window_size.as_f32(); 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.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); 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 { match self.scene.root {
Some(ref mut layer) => { Some(ref mut layer) => {
layer.handle_scroll_event(page_delta, cursor); 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>>) { fn send_viewport_rect_for_layer(&self, layer: Rc<Layer<CompositorData>>) {
if layer.extra_data.borrow().id == LayerId::null() { if layer.extra_data.borrow().id == LayerId::null() {
let layer_rect = Rect(-layer.extra_data.borrow().scroll_offset.to_untyped(), let layer_rect = Rect::new(-layer.extra_data.borrow().scroll_offset.to_untyped(),
layer.bounds.borrow().size.to_untyped()); layer.bounds.borrow().size.to_untyped());
let pipeline = self.get_pipeline(layer.pipeline_id()); let pipeline = self.get_pipeline(layer.pipeline_id());
let ScriptControlChan(ref chan) = pipeline.script_chan; let ScriptControlChan(ref chan) = pipeline.script_chan;
chan.send(ConstellationControlMsg::Viewport(pipeline.id.clone(), layer_rect)).unwrap(); 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 { 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 { } else {
clipped_layer_bounds.translate(&clip_rect.origin) clipped_layer_bounds.translate(&clip_rect.origin)
}; };

View file

@ -7,7 +7,7 @@ use windowing::{MouseWindowEvent, WindowMethods};
use azure::azure_hl; use azure::azure_hl;
use geom::length::Length; use geom::length::Length;
use geom::matrix::identity; use geom::matrix::Matrix4;
use geom::point::{Point2D, TypedPoint2D}; use geom::point::{Point2D, TypedPoint2D};
use geom::size::TypedSize2D; use geom::size::TypedSize2D;
use geom::rect::Rect; use geom::rect::Rect;
@ -59,7 +59,7 @@ impl CompositorData {
scroll_policy: layer_properties.scroll_policy, scroll_policy: layer_properties.scroll_policy,
requested_epoch: Epoch(0), requested_epoch: Epoch(0),
painted_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), 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 // 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. // 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); 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_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 min_y = (layer_size.height - content_size.height).get().min(0.0);
let new_offset : TypedPoint2D<LayerPixel, f32> = let new_offset : TypedPoint2D<LayerPixel, f32> =
Point2D(Length::new(new_offset.x.get().clamp(&min_x, &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))); Length::new(new_offset.y.get().clamp(&min_y, &0.0)));
if self.extra_data.borrow().scroll_offset == new_offset { if self.extra_data.borrow().scroll_offset == new_offset {
return ScrollEventResult::ScrollPositionUnchanged; return ScrollEventResult::ScrollPositionUnchanged;
@ -392,7 +392,7 @@ impl CompositorLayer for Layer<CompositorData> {
// Only scroll this layer if it's not fixed-positioned. // Only scroll this layer if it's not fixed-positioned.
if self.extra_data.borrow().scroll_policy != ScrollPolicy::FixedPosition { if self.extra_data.borrow().scroll_policy != ScrollPolicy::FixedPosition {
let new_offset = new_offset.to_untyped(); 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); *self.content_offset.borrow_mut() = Point2D::from_untyped(&new_offset);
result = true result = true
} }

View file

@ -534,7 +534,7 @@ impl<LTF: LayoutTaskFactory, STF: ScriptTaskFactory> Constellation<LTF, STF> {
} }
fn handle_init_load(&mut self, url: Url) { 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 = let root_pipeline_id =
self.new_pipeline(None, Some(window_rect), None, LoadData::new(url.clone())); self.new_pipeline(None, Some(window_rect), None, LoadData::new(url.clone()));
self.handle_load_start_msg(&root_pipeline_id); self.handle_load_start_msg(&root_pipeline_id);

View file

@ -6,7 +6,7 @@ use compositor_task::{CompositorEventListener, CompositorReceiver, Msg};
use windowing::WindowEvent; use windowing::WindowEvent;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::Size2D;
use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, WindowSizeData}; use msg::constellation_msg::{ConstellationChan, WindowSizeData};
use profile_traits::mem; use profile_traits::mem;
@ -55,8 +55,8 @@ impl NullCompositor {
{ {
let ConstellationChan(ref chan) = compositor.constellation_chan; let ConstellationChan(ref chan) = compositor.constellation_chan;
chan.send(ConstellationMsg::ResizedWindow(WindowSizeData { chan.send(ConstellationMsg::ResizedWindow(WindowSizeData {
initial_viewport: TypedSize2D(640_f32, 480_f32), initial_viewport: Size2D::typed(640_f32, 480_f32),
visible_viewport: TypedSize2D(640_f32, 480_f32), visible_viewport: Size2D::typed(640_f32, 480_f32),
device_pixel_ratio: ScaleFactor::new(1.0), device_pixel_ratio: ScaleFactor::new(1.0),
})).unwrap(); })).unwrap();
} }

View file

@ -472,14 +472,13 @@ impl StackingContext {
DisplayItem::BorderClass(ref border) => { DisplayItem::BorderClass(ref border) => {
// If the point is inside the border, it didn't hit the border! // If the point is inside the border, it didn't hit the border!
let interior_rect = let interior_rect =
Rect(Point2D(border.base.bounds.origin.x + border.border_widths.left, Rect::new(
border.base.bounds.origin.y + border.border_widths.top), Point2D::new(border.base.bounds.origin.x + border.border_widths.left,
Size2D(border.base.bounds.size.width - border.base.bounds.origin.y + border.border_widths.top),
(border.border_widths.left + Size2D::new(border.base.bounds.size.width -
border.border_widths.right), (border.border_widths.left + border.border_widths.right),
border.base.bounds.size.height - border.base.bounds.size.height -
(border.border_widths.top + (border.border_widths.top + border.border_widths.bottom)));
border.border_widths.bottom)));
if geometry::rect_contains_point(interior_rect, point) { if geometry::rect_contains_point(interior_rect, point) {
continue continue
} }
@ -499,9 +498,9 @@ impl StackingContext {
point = point - self.bounds.origin; point = point - self.bounds.origin;
debug_assert!(!topmost_only || result.is_empty()); 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.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 // Iterate through display items in reverse stacking order. Steps here refer to the
// painting steps in CSS 2.1 Appendix E. // painting steps in CSS 2.1 Appendix E.

View file

@ -228,8 +228,8 @@ pub struct RunMetrics {
impl RunMetrics { impl RunMetrics {
pub fn new(advance: Au, ascent: Au, descent: Au) -> RunMetrics { pub fn new(advance: Au, ascent: Au, descent: Au) -> RunMetrics {
let bounds = Rect(Point2D(Au(0), -ascent), let bounds = Rect::new(Point2D::new(Au(0), -ascent),
Size2D(advance, ascent + descent)); Size2D::new(advance, ascent + descent));
// TODO(Issue #125): support loose and tight bounding boxes; using the // TODO(Issue #125): support loose and tight bounding boxes; using the
// ascent+descent and advance is sometimes too generous and // ascent+descent and advance is sometimes too generous and

View file

@ -107,11 +107,11 @@ impl<'a> PaintContext<'a> {
let rect = bounds.to_nearest_azure_rect(); let rect = bounds.to_nearest_azure_rect();
let path_builder = self.draw_target.create_path_builder(); let path_builder = self.draw_target.create_path_builder();
let left_top = Point2D(rect.origin.x, rect.origin.y); let left_top = Point2D::new(rect.origin.x, rect.origin.y);
let right_top = Point2D(rect.origin.x + rect.size.width, rect.origin.y); let right_top = Point2D::new(rect.origin.x + rect.size.width, rect.origin.y);
let left_bottom = Point2D(rect.origin.x, rect.origin.y + rect.size.height); let left_bottom = Point2D::new(rect.origin.x, rect.origin.y + rect.size.height);
let right_bottom = Point2D(rect.origin.x + rect.size.width, let right_bottom = Point2D::new(rect.origin.x + rect.size.width,
rect.origin.y + rect.size.height); rect.origin.y + rect.size.height);
path_builder.move_to(left_top); path_builder.move_to(left_top);
path_builder.line_to(right_top); path_builder.line_to(right_top);
@ -130,7 +130,7 @@ impl<'a> PaintContext<'a> {
bounds: &Rect<Au>, bounds: &Rect<Au>,
image: Arc<Image>, image: Arc<Image>,
image_rendering: image_rendering::T) { image_rendering: image_rendering::T) {
let size = Size2D(image.width as i32, image.height as i32); let size = Size2D::new(image.width as i32, image.height as i32);
let (pixel_width, pixels, source_format) = match image.pixels { let (pixel_width, pixels, source_format) = match image.pixels {
PixelsByColorType::RGBA8(ref pixels) => (4, pixels, SurfaceFormat::B8G8R8A8), PixelsByColorType::RGBA8(ref pixels) => (4, pixels, SurfaceFormat::B8G8R8A8),
PixelsByColorType::K8(ref pixels) => (1, pixels, SurfaceFormat::A8), PixelsByColorType::K8(ref pixels) => (1, pixels, SurfaceFormat::A8),
@ -145,8 +145,8 @@ impl<'a> PaintContext<'a> {
size, size,
stride as i32, stride as i32,
source_format); source_format);
let source_rect = Rect(Point2D(0.0, 0.0), let source_rect = Rect::new(Point2D::new(0.0, 0.0),
Size2D(image.width as AzFloat, image.height as AzFloat)); Size2D::new(image.width as AzFloat, image.height as AzFloat));
let dest_rect = bounds.to_nearest_azure_rect(); let dest_rect = bounds.to_nearest_azure_rect();
// TODO(pcwalton): According to CSS-IMAGES-3 § 5.3, nearest-neighbor interpolation is a // TODO(pcwalton): According to CSS-IMAGES-3 § 5.3, nearest-neighbor interpolation is a
@ -169,10 +169,10 @@ impl<'a> PaintContext<'a> {
pub fn clear(&self) { pub fn clear(&self) {
let pattern = ColorPattern::new(color::transparent()); let pattern = ColorPattern::new(color::transparent());
let rect = Rect(Point2D(self.page_rect.origin.x as AzFloat, let rect = Rect::new(Point2D::new(self.page_rect.origin.x as AzFloat,
self.page_rect.origin.y as AzFloat), self.page_rect.origin.y as AzFloat),
Size2D(self.screen_rect.size.width as AzFloat, Size2D::new(self.screen_rect.size.width as AzFloat,
self.screen_rect.size.height as AzFloat)); self.screen_rect.size.height as AzFloat));
let mut draw_options = DrawOptions::new(1.0, CompositionOp::Over, AntialiasMode::None); let mut draw_options = DrawOptions::new(1.0, CompositionOp::Over, AntialiasMode::None);
draw_options.set_composition_op(CompositionOp::Source); draw_options.set_composition_op(CompositionOp::Source);
self.draw_target.make_current(); self.draw_target.make_current();
@ -390,9 +390,9 @@ impl<'a> PaintContext<'a> {
// T = top, B = bottom, L = left, R = right // T = top, B = bottom, L = left, R = right
let box_TL = bounds.origin; let box_TL = bounds.origin;
let box_TR = box_TL + Point2D(bounds.size.width, 0.0); let box_TR = box_TL + Point2D::new(bounds.size.width, 0.0);
let box_BL = box_TL + Point2D(0.0, bounds.size.height); let box_BL = box_TL + Point2D::new(0.0, bounds.size.height);
let box_BR = box_TL + Point2D(bounds.size.width, bounds.size.height); let box_BR = box_TL + Point2D::new(bounds.size.width, bounds.size.height);
let rad_R: AzFloat = 0.; let rad_R: AzFloat = 0.;
let rad_BR = rad_R + f32::consts::FRAC_PI_4; let rad_BR = rad_R + f32::consts::FRAC_PI_4;
@ -404,19 +404,19 @@ impl<'a> PaintContext<'a> {
let rad_TR = rad_T + f32::consts::FRAC_PI_4; let rad_TR = rad_T + f32::consts::FRAC_PI_4;
fn dx(x: AzFloat) -> Point2D<AzFloat> { fn dx(x: AzFloat) -> Point2D<AzFloat> {
Point2D(x, 0.) Point2D::new(x, 0.)
} }
fn dy(y: AzFloat) -> Point2D<AzFloat> { fn dy(y: AzFloat) -> Point2D<AzFloat> {
Point2D(0., y) Point2D::new(0., y)
} }
fn dx_if(cond: bool, dx: AzFloat) -> Point2D<AzFloat> { fn dx_if(cond: bool, dx: AzFloat) -> Point2D<AzFloat> {
Point2D(if cond { dx } else { 0. }, 0.) Point2D::new(if cond { dx } else { 0. }, 0.)
} }
fn dy_if(cond: bool, dy: AzFloat) -> Point2D<AzFloat> { fn dy_if(cond: bool, dy: AzFloat) -> Point2D<AzFloat> {
Point2D(0., if cond { dy } else { 0. }) Point2D::new(0., if cond { dy } else { 0. })
} }
match direction { match direction {
@ -434,8 +434,8 @@ impl<'a> PaintContext<'a> {
if radius.top_right != 0. { if radius.top_right != 0. {
// the origin is the center of the arcs we're about to draw. // the origin is the center of the arcs we're about to draw.
let origin = edge_TR + Point2D((border.right - radius.top_right).max(0.), let origin = edge_TR + Point2D::new((border.right - radius.top_right).max(0.),
radius.top_right); radius.top_right);
// the elbow is the inside of the border's curve. // the elbow is the inside of the border's curve.
let distance_to_elbow = (radius.top_right - border.top).max(0.); let distance_to_elbow = (radius.top_right - border.top).max(0.);
@ -447,7 +447,7 @@ impl<'a> PaintContext<'a> {
path_builder.line_to(edge_BL); path_builder.line_to(edge_BL);
if radius.top_left != 0. { if radius.top_left != 0. {
let origin = edge_TL + Point2D(-(border.left - radius.top_left).max(0.), let origin = edge_TL + Point2D::new(-(border.left - radius.top_left).max(0.),
radius.top_left); radius.top_left);
let distance_to_elbow = (radius.top_left - border.top).max(0.); let distance_to_elbow = (radius.top_left - border.top).max(0.);
@ -468,7 +468,7 @@ impl<'a> PaintContext<'a> {
path_builder.line_to(corner_TL); path_builder.line_to(corner_TL);
if radius.top_left != 0. { if radius.top_left != 0. {
let origin = edge_TL + Point2D(radius.top_left, let origin = edge_TL + Point2D::new(radius.top_left,
-(border.top - radius.top_left).max(0.)); -(border.top - radius.top_left).max(0.));
let distance_to_elbow = (radius.top_left - border.left).max(0.); let distance_to_elbow = (radius.top_left - border.left).max(0.);
@ -481,7 +481,7 @@ impl<'a> PaintContext<'a> {
if radius.bottom_left != 0. { if radius.bottom_left != 0. {
let origin = edge_BL + let origin = edge_BL +
Point2D(radius.bottom_left, Point2D::new(radius.bottom_left,
(border.bottom - radius.bottom_left).max(0.)); (border.bottom - radius.bottom_left).max(0.));
let distance_to_elbow = (radius.bottom_left - border.left).max(0.); let distance_to_elbow = (radius.bottom_left - border.left).max(0.);
@ -502,8 +502,8 @@ impl<'a> PaintContext<'a> {
path_builder.line_to(edge_TL); path_builder.line_to(edge_TL);
if radius.top_right != 0. { if radius.top_right != 0. {
let origin = edge_TR + Point2D(-radius.top_right, let origin = edge_TR + Point2D::new(-radius.top_right,
-(border.top - radius.top_right).max(0.)); -(border.top - radius.top_right).max(0.));
let distance_to_elbow = (radius.top_right - border.right).max(0.); let distance_to_elbow = (radius.top_right - border.right).max(0.);
path_builder.arc(origin, distance_to_elbow, rad_R, rad_TR, true); path_builder.arc(origin, distance_to_elbow, rad_R, rad_TR, true);
@ -515,7 +515,7 @@ impl<'a> PaintContext<'a> {
if radius.bottom_right != 0. { if radius.bottom_right != 0. {
let origin = edge_BR + let origin = edge_BR +
Point2D(-radius.bottom_right, Point2D::new(-radius.bottom_right,
(border.bottom - radius.bottom_right).max(0.)); (border.bottom - radius.bottom_right).max(0.));
let distance_to_elbow = (radius.bottom_right - border.right).max(0.); let distance_to_elbow = (radius.bottom_right - border.right).max(0.);
@ -536,8 +536,8 @@ impl<'a> PaintContext<'a> {
path_builder.line_to(edge_TR); path_builder.line_to(edge_TR);
if radius.bottom_right != 0. { if radius.bottom_right != 0. {
let origin = edge_BR + Point2D((border.right - radius.bottom_right).max(0.), let origin = edge_BR + Point2D::new((border.right - radius.bottom_right).max(0.),
-radius.bottom_right); -radius.bottom_right);
let distance_to_elbow = (radius.bottom_right - border.bottom).max(0.); let distance_to_elbow = (radius.bottom_right - border.bottom).max(0.);
path_builder.arc(origin, distance_to_elbow, rad_B, rad_BR, true); path_builder.arc(origin, distance_to_elbow, rad_B, rad_BR, true);
@ -548,7 +548,7 @@ impl<'a> PaintContext<'a> {
path_builder.line_to(corner_BL); path_builder.line_to(corner_BL);
if radius.bottom_left != 0. { if radius.bottom_left != 0. {
let origin = edge_BL - Point2D((border.left - radius.bottom_left).max(0.), let origin = edge_BL - Point2D::new((border.left - radius.bottom_left).max(0.),
radius.bottom_left); radius.bottom_left);
let distance_to_elbow = (radius.bottom_left - border.bottom).max(0.); let distance_to_elbow = (radius.bottom_left - border.bottom).max(0.);
@ -579,35 +579,35 @@ impl<'a> PaintContext<'a> {
// \ 6 5 / // \ 6 5 /
// +----------+ // +----------+
path_builder.move_to(Point2D(bounds.origin.x + radii.top_left, bounds.origin.y)); // 1 path_builder.move_to(Point2D::new(bounds.origin.x + radii.top_left, bounds.origin.y)); // 1
path_builder.line_to(Point2D(bounds.max_x() - radii.top_right, bounds.origin.y)); // 2 path_builder.line_to(Point2D::new(bounds.max_x() - radii.top_right, bounds.origin.y)); // 2
path_builder.arc(Point2D(bounds.max_x() - radii.top_right, path_builder.arc(Point2D::new(bounds.max_x() - radii.top_right,
bounds.origin.y + radii.top_right), bounds.origin.y + radii.top_right),
radii.top_right, radii.top_right,
1.5f32 * f32::consts::FRAC_PI_2, 1.5f32 * f32::consts::FRAC_PI_2,
f32::consts::PI_2, f32::consts::PI_2,
false); // 3 false); // 3
path_builder.line_to(Point2D(bounds.max_x(), bounds.max_y() - radii.bottom_right)); // 4 path_builder.line_to(Point2D::new(bounds.max_x(), bounds.max_y() - radii.bottom_right)); // 4
path_builder.arc(Point2D(bounds.max_x() - radii.bottom_right, path_builder.arc(Point2D::new(bounds.max_x() - radii.bottom_right,
bounds.max_y() - radii.bottom_right), bounds.max_y() - radii.bottom_right),
radii.bottom_right, radii.bottom_right,
0.0, 0.0,
f32::consts::FRAC_PI_2, f32::consts::FRAC_PI_2,
false); // 5 false); // 5
path_builder.line_to(Point2D(bounds.origin.x + radii.bottom_left, bounds.max_y())); // 6 path_builder.line_to(Point2D::new(bounds.origin.x + radii.bottom_left, bounds.max_y())); // 6
path_builder.arc(Point2D(bounds.origin.x + radii.bottom_left, path_builder.arc(Point2D::new(bounds.origin.x + radii.bottom_left,
bounds.max_y() - radii.bottom_left), bounds.max_y() - radii.bottom_left),
radii.bottom_left, radii.bottom_left,
f32::consts::FRAC_PI_2, f32::consts::FRAC_PI_2,
f32::consts::PI, f32::consts::PI,
false); // 7 false); // 7
path_builder.line_to(Point2D(bounds.origin.x, bounds.origin.y + radii.top_left)); // 8 path_builder.line_to(Point2D::new(bounds.origin.x, bounds.origin.y + radii.top_left)); // 8
path_builder.arc(Point2D(bounds.origin.x + radii.top_left, path_builder.arc(Point2D::new(bounds.origin.x + radii.top_left,
bounds.origin.y + radii.top_left), bounds.origin.y + radii.top_left),
radii.top_left, radii.top_left,
f32::consts::PI, f32::consts::PI,
1.5f32 * f32::consts::FRAC_PI_2, 1.5f32 * f32::consts::FRAC_PI_2,
false); // 1 false); // 1
} }
fn draw_dashed_border_segment(&self, fn draw_dashed_border_segment(&self,
@ -634,26 +634,26 @@ impl<'a> PaintContext<'a> {
let (start, end) = match direction { let (start, end) = match direction {
Direction::Top => { Direction::Top => {
let y = rect.origin.y + border.top * 0.5; let y = rect.origin.y + border.top * 0.5;
let start = Point2D(rect.origin.x, y); let start = Point2D::new(rect.origin.x, y);
let end = Point2D(rect.origin.x + rect.size.width, y); let end = Point2D::new(rect.origin.x + rect.size.width, y);
(start, end) (start, end)
} }
Direction::Left => { Direction::Left => {
let x = rect.origin.x + border.left * 0.5; let x = rect.origin.x + border.left * 0.5;
let start = Point2D(x, rect.origin.y + rect.size.height); let start = Point2D::new(x, rect.origin.y + rect.size.height);
let end = Point2D(x, rect.origin.y + border.top); let end = Point2D::new(x, rect.origin.y + border.top);
(start, end) (start, end)
} }
Direction::Right => { Direction::Right => {
let x = rect.origin.x + rect.size.width - border.right * 0.5; let x = rect.origin.x + rect.size.width - border.right * 0.5;
let start = Point2D(x, rect.origin.y); let start = Point2D::new(x, rect.origin.y);
let end = Point2D(x, rect.origin.y + rect.size.height); let end = Point2D::new(x, rect.origin.y + rect.size.height);
(start, end) (start, end)
} }
Direction::Bottom => { Direction::Bottom => {
let y = rect.origin.y + rect.size.height - border.bottom * 0.5; let y = rect.origin.y + rect.size.height - border.bottom * 0.5;
let start = Point2D(rect.origin.x + rect.size.width, y); let start = Point2D::new(rect.origin.x + rect.size.width, y);
let end = Point2D(rect.origin.x + border.left, y); let end = Point2D::new(rect.origin.x + border.left, y);
(start, end) (start, end)
} }
}; };
@ -684,12 +684,12 @@ impl<'a> PaintContext<'a> {
shrink_factor * border.right, shrink_factor * border.right,
shrink_factor * border.bottom, shrink_factor * border.bottom,
shrink_factor * border.left); shrink_factor * border.left);
let left_top = Point2D(rect.origin.x, rect.origin.y); let left_top = Point2D::new(rect.origin.x, rect.origin.y);
let scaled_left_top = left_top + Point2D(scaled_border.left, let scaled_left_top = left_top + Point2D::new(scaled_border.left,
scaled_border.top); scaled_border.top);
return Rect(scaled_left_top, return Rect::new(scaled_left_top,
Size2D(rect.size.width - 2.0 * scaled_border.right, Size2D::new(rect.size.width - 2.0 * scaled_border.right,
rect.size.height - 2.0 * scaled_border.bottom)); rect.size.height - 2.0 * scaled_border.bottom));
} }
fn scale_color(&self, color: Color, scale_factor: f32) -> Color { fn scale_color(&self, color: Color, scale_factor: f32) -> Color {
@ -906,7 +906,7 @@ impl<'a> PaintContext<'a> {
// FIXME(pcwalton): This surface might be bigger than necessary and waste memory. // FIXME(pcwalton): This surface might be bigger than necessary and waste memory.
let size = self.draw_target.get_size(); //Az size. let size = self.draw_target.get_size(); //Az size.
let mut size = Size2D(size.width, size.height); //Geom::Size. let mut size = Size2D::new(size.width, size.height); //Geom::Size.
// Pre-calculate if there is a blur expansion need. // Pre-calculate if there is a blur expansion need.
let accum_blur = filters::calculate_accumulated_blur(filters); let accum_blur = filters::calculate_accumulated_blur(filters);
@ -914,13 +914,13 @@ impl<'a> PaintContext<'a> {
if accum_blur > Au(0) { if accum_blur > Au(0) {
// Set the correct size. // Set the correct size.
let side_inflation = accum_blur * BLUR_INFLATION_FACTOR; let side_inflation = accum_blur * BLUR_INFLATION_FACTOR;
size = Size2D(size.width + (side_inflation.to_nearest_px() * 2) as i32, size = Size2D::new(size.width + (side_inflation.to_nearest_px() * 2) as i32,
size.height + (side_inflation.to_nearest_px() * 2) as i32); size.height + (side_inflation.to_nearest_px() * 2) as i32);
// Calculate the transform matrix. // Calculate the transform matrix.
let old_transform = self.draw_target.get_transform(); let old_transform = self.draw_target.get_transform();
let inflated_size = Rect(Point2D(0.0, 0.0), Size2D(size.width as AzFloat, let inflated_size = Rect::new(Point2D::new(0.0, 0.0), Size2D::new(size.width as AzFloat,
size.height as AzFloat)); size.height as AzFloat));
let temporary_draw_target_bounds = old_transform.transform_rect(&inflated_size); let temporary_draw_target_bounds = old_transform.transform_rect(&inflated_size);
matrix = Matrix2D::identity().translate( matrix = Matrix2D::identity().translate(
-temporary_draw_target_bounds.origin.x as AzFloat, -temporary_draw_target_bounds.origin.x as AzFloat,
@ -948,9 +948,9 @@ impl<'a> PaintContext<'a> {
// Set up transforms. // Set up transforms.
let old_transform = self.draw_target.get_transform(); let old_transform = self.draw_target.get_transform();
self.draw_target.set_transform(&Matrix2D::identity()); self.draw_target.set_transform(&Matrix2D::identity());
let rect = Rect(Point2D(0.0, 0.0), self.draw_target.get_size().to_azure_size()); let rect = Rect::new(Point2D::new(0.0, 0.0), self.draw_target.get_size().to_azure_size());
let rect_temporary = Rect(Point2D(0.0, 0.0), temporary_draw_target.get_size().to_azure_size()); let rect_temporary = Rect::new(Point2D::new(0.0, 0.0), temporary_draw_target.get_size().to_azure_size());
// Create the Azure filter pipeline. // Create the Azure filter pipeline.
let mut accum_blur = Au(0); let mut accum_blur = Au(0);
@ -1111,10 +1111,10 @@ pub trait ToAzurePoint {
impl ToAzurePoint for Point2D<Au> { impl ToAzurePoint for Point2D<Au> {
fn to_nearest_azure_point(&self) -> Point2D<AzFloat> { fn to_nearest_azure_point(&self) -> Point2D<AzFloat> {
Point2D(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat) Point2D::new(self.x.to_nearest_px() as AzFloat, self.y.to_nearest_px() as AzFloat)
} }
fn to_azure_point(&self) -> Point2D<AzFloat> { fn to_azure_point(&self) -> Point2D<AzFloat> {
Point2D(self.x.to_f32_px(), self.y.to_f32_px()) Point2D::new(self.x.to_f32_px(), self.y.to_f32_px())
} }
} }
@ -1125,13 +1125,13 @@ pub trait ToAzureRect {
impl ToAzureRect for Rect<Au> { impl ToAzureRect for Rect<Au> {
fn to_nearest_azure_rect(&self) -> Rect<AzFloat> { fn to_nearest_azure_rect(&self) -> Rect<AzFloat> {
Rect(self.origin.to_nearest_azure_point(), Size2D(self.size.width.to_nearest_px() as AzFloat, Rect::new(self.origin.to_nearest_azure_point(), Size2D::new(self.size.width.to_nearest_px() as AzFloat,
self.size.height.to_nearest_px() as AzFloat)) self.size.height.to_nearest_px() as AzFloat))
} }
fn to_azure_rect(&self) -> Rect<AzFloat> { fn to_azure_rect(&self) -> Rect<AzFloat> {
Rect(self.origin.to_azure_point(), Size2D(self.size.width.to_f32_px(), Rect::new(self.origin.to_azure_point(), Size2D::new(self.size.width.to_f32_px(),
self.size.height.to_f32_px())) self.size.height.to_f32_px()))
} }
} }
@ -1141,7 +1141,7 @@ pub trait ToAzureSize {
impl ToAzureSize for AzIntSize { impl ToAzureSize for AzIntSize {
fn to_azure_size(&self) -> Size2D<AzFloat> { fn to_azure_size(&self) -> Size2D<AzFloat> {
Size2D(self.width as AzFloat, self.height as AzFloat) Size2D::new(self.width as AzFloat, self.height as AzFloat)
} }
} }
@ -1151,19 +1151,19 @@ trait ToAzureIntSize {
impl ToAzureIntSize for Size2D<Au> { impl ToAzureIntSize for Size2D<Au> {
fn to_azure_int_size(&self) -> Size2D<i32> { fn to_azure_int_size(&self) -> Size2D<i32> {
Size2D(self.width.to_nearest_px() as i32, self.height.to_nearest_px() as i32) Size2D::new(self.width.to_nearest_px() as i32, self.height.to_nearest_px() as i32)
} }
} }
impl ToAzureIntSize for Size2D<AzFloat> { impl ToAzureIntSize for Size2D<AzFloat> {
fn to_azure_int_size(&self) -> Size2D<i32> { fn to_azure_int_size(&self) -> Size2D<i32> {
Size2D(self.width as i32, self.height as i32) Size2D::new(self.width as i32, self.height as i32)
} }
} }
impl ToAzureIntSize for Size2D<i32> { impl ToAzureIntSize for Size2D<i32> {
fn to_azure_int_size(&self) -> Size2D<i32> { fn to_azure_int_size(&self) -> Size2D<i32> {
Size2D(self.width, self.height) Size2D::new(self.width, self.height)
} }
} }
@ -1243,7 +1243,7 @@ impl ScaledFontExtensionMethods for ScaledFont {
y: (origin.y + glyph_offset.y).to_f32_px(), y: (origin.y + glyph_offset.y).to_f32_px(),
} }
}; };
origin = Point2D(origin.x + glyph_advance, origin.y); origin = Point2D::new(origin.x + glyph_advance, origin.y);
azglyphs.push(azglyph) azglyphs.push(azglyph)
}; };
} }
@ -1306,25 +1306,25 @@ impl DrawTargetExtensions for DrawTarget {
let (outer_rect, inner_rect) = (outer_rect.to_nearest_azure_rect(), inner_rect.to_nearest_azure_rect()); let (outer_rect, inner_rect) = (outer_rect.to_nearest_azure_rect(), inner_rect.to_nearest_azure_rect());
let path_builder = self.create_path_builder(); let path_builder = self.create_path_builder();
path_builder.move_to(Point2D(outer_rect.max_x(), outer_rect.origin.y)); // 1 path_builder.move_to(Point2D::new(outer_rect.max_x(), outer_rect.origin.y)); // 1
path_builder.line_to(Point2D(outer_rect.origin.x, outer_rect.origin.y)); // 2 path_builder.line_to(Point2D::new(outer_rect.origin.x, outer_rect.origin.y)); // 2
path_builder.line_to(Point2D(outer_rect.origin.x, outer_rect.max_y())); // 3 path_builder.line_to(Point2D::new(outer_rect.origin.x, outer_rect.max_y())); // 3
path_builder.line_to(Point2D(outer_rect.max_x(), outer_rect.max_y())); // 4 path_builder.line_to(Point2D::new(outer_rect.max_x(), outer_rect.max_y())); // 4
path_builder.line_to(Point2D(outer_rect.max_x(), inner_rect.origin.y)); // 5 path_builder.line_to(Point2D::new(outer_rect.max_x(), inner_rect.origin.y)); // 5
path_builder.line_to(Point2D(inner_rect.max_x(), inner_rect.origin.y)); // 6 path_builder.line_to(Point2D::new(inner_rect.max_x(), inner_rect.origin.y)); // 6
path_builder.line_to(Point2D(inner_rect.max_x(), inner_rect.max_y())); // 7 path_builder.line_to(Point2D::new(inner_rect.max_x(), inner_rect.max_y())); // 7
path_builder.line_to(Point2D(inner_rect.origin.x, inner_rect.max_y())); // 8 path_builder.line_to(Point2D::new(inner_rect.origin.x, inner_rect.max_y())); // 8
path_builder.line_to(inner_rect.origin); // 9 path_builder.line_to(inner_rect.origin); // 9
path_builder.line_to(Point2D(outer_rect.max_x(), inner_rect.origin.y)); // 10 path_builder.line_to(Point2D::new(outer_rect.max_x(), inner_rect.origin.y)); // 10
path_builder.finish() path_builder.finish()
} }
fn create_rectangular_path(&self, rect: &Rect<Au>) -> Path { fn create_rectangular_path(&self, rect: &Rect<Au>) -> Path {
let path_builder = self.create_path_builder(); let path_builder = self.create_path_builder();
path_builder.move_to(rect.origin.to_nearest_azure_point()); path_builder.move_to(rect.origin.to_nearest_azure_point());
path_builder.line_to(Point2D(rect.max_x(), rect.origin.y).to_nearest_azure_point()); path_builder.line_to(Point2D::new(rect.max_x(), rect.origin.y).to_nearest_azure_point());
path_builder.line_to(Point2D(rect.max_x(), rect.max_y()).to_nearest_azure_point()); path_builder.line_to(Point2D::new(rect.max_x(), rect.max_y()).to_nearest_azure_point());
path_builder.line_to(Point2D(rect.origin.x, rect.max_y()).to_nearest_azure_point()); path_builder.line_to(Point2D::new(rect.origin.x, rect.max_y()).to_nearest_azure_point());
path_builder.finish() path_builder.finish()
} }
} }
@ -1373,7 +1373,7 @@ impl TemporaryDrawTarget {
fn from_main_draw_target(main_draw_target: &DrawTarget) -> TemporaryDrawTarget { fn from_main_draw_target(main_draw_target: &DrawTarget) -> TemporaryDrawTarget {
TemporaryDrawTarget { TemporaryDrawTarget {
draw_target: main_draw_target.clone(), draw_target: main_draw_target.clone(),
offset: Point2D(0.0, 0.0), offset: Point2D::new(0.0, 0.0),
} }
} }
@ -1385,8 +1385,8 @@ impl TemporaryDrawTarget {
let temporary_draw_target_bounds = let temporary_draw_target_bounds =
draw_target_transform.transform_rect(&bounds.to_azure_rect()); draw_target_transform.transform_rect(&bounds.to_azure_rect());
let temporary_draw_target_size = let temporary_draw_target_size =
Size2D(temporary_draw_target_bounds.size.width.ceil() as i32, Size2D::new(temporary_draw_target_bounds.size.width.ceil() as i32,
temporary_draw_target_bounds.size.height.ceil() as i32); temporary_draw_target_bounds.size.height.ceil() as i32);
let temporary_draw_target = let temporary_draw_target =
main_draw_target.create_similar_draw_target(&temporary_draw_target_size, main_draw_target.create_similar_draw_target(&temporary_draw_target_size,
main_draw_target.get_format()); main_draw_target.get_format());
@ -1405,14 +1405,14 @@ impl TemporaryDrawTarget {
fn draw_filter(self, main_draw_target: &DrawTarget, filter: FilterNode) { fn draw_filter(self, main_draw_target: &DrawTarget, filter: FilterNode) {
let main_draw_target_transform = main_draw_target.get_transform(); let main_draw_target_transform = main_draw_target.get_transform();
let temporary_draw_target_size = self.draw_target.get_size(); let temporary_draw_target_size = self.draw_target.get_size();
let temporary_draw_target_size = Size2D(temporary_draw_target_size.width as AzFloat, let temporary_draw_target_size = Size2D::new(temporary_draw_target_size.width as AzFloat,
temporary_draw_target_size.height as AzFloat); temporary_draw_target_size.height as AzFloat);
// Blit the blur onto the tile. We undo the transforms here because we want to directly // Blit the blur onto the tile. We undo the transforms here because we want to directly
// stack the temporary draw target onto the tile. // stack the temporary draw target onto the tile.
main_draw_target.set_transform(&Matrix2D::identity()); main_draw_target.set_transform(&Matrix2D::identity());
main_draw_target.draw_filter(&filter, main_draw_target.draw_filter(&filter,
&Rect(Point2D(0.0, 0.0), temporary_draw_target_size), &Rect::new(Point2D::new(0.0, 0.0), temporary_draw_target_size),
&self.offset, &self.offset,
DrawOptions::new(1.0, CompositionOp::Over, AntialiasMode::None)); DrawOptions::new(1.0, CompositionOp::Over, AntialiasMode::None));
main_draw_target.set_transform(&main_draw_target_transform); main_draw_target.set_transform(&main_draw_target_transform);

View file

@ -13,7 +13,6 @@ use paint_context::PaintContext;
use azure::azure_hl::{SurfaceFormat, Color, DrawTarget, BackendType}; use azure::azure_hl::{SurfaceFormat, Color, DrawTarget, BackendType};
use azure::AzFloat; use azure::AzFloat;
use geom::Matrix4; use geom::Matrix4;
use geom::matrix::identity;
use geom::point::Point2D; use geom::point::Point2D;
use geom::rect::Rect; use geom::rect::Rect;
use geom::size::Size2D; use geom::size::Size2D;
@ -386,7 +385,7 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
// in case it dies in transit to the compositor task. // in case it dies in transit to the compositor task.
let mut native_surface: NativeSurface = let mut native_surface: NativeSurface =
layers::platform::surface::NativeSurface::new(native_graphics_context!(self), layers::platform::surface::NativeSurface::new(native_graphics_context!(self),
Size2D(width as i32, height as i32), Size2D::new(width as i32, height as i32),
width as i32 * 4); width as i32 * 4);
native_surface.mark_wont_leak(); native_surface.mark_wont_leak();
@ -463,10 +462,10 @@ impl<C> PaintTask<C> where C: PaintListener + Send + 'static {
// the compositor is concerned. // the compositor is concerned.
let overflow_relative_page_position = page_position + stacking_context.overflow.origin; let overflow_relative_page_position = page_position + stacking_context.overflow.origin;
let layer_position = let layer_position =
Rect(Point2D(overflow_relative_page_position.x.to_nearest_px() as f32, Rect::new(Point2D::new(overflow_relative_page_position.x.to_nearest_px() as f32,
overflow_relative_page_position.y.to_nearest_px() as f32), overflow_relative_page_position.y.to_nearest_px() as f32),
Size2D(stacking_context.overflow.size.width.to_nearest_px() as f32, Size2D::new(stacking_context.overflow.size.width.to_nearest_px() as f32,
stacking_context.overflow.size.height.to_nearest_px() as f32)); stacking_context.overflow.size.height.to_nearest_px() as f32));
properties.push(LayerProperties { properties.push(LayerProperties {
id: paint_layer.id, id: paint_layer.id,
rect: layer_position, rect: layer_position,
@ -587,7 +586,7 @@ impl WorkerThread {
stacking_context: Arc<StackingContext>, stacking_context: Arc<StackingContext>,
scale: f32) scale: f32)
-> DrawTarget { -> DrawTarget {
let size = Size2D(tile.screen_rect.size.width as i32, tile.screen_rect.size.height as i32); let size = Size2D::new(tile.screen_rect.size.width as i32, tile.screen_rect.size.height as i32);
let draw_target = if !opts::get().gpu_painting { let draw_target = if !opts::get().gpu_painting {
DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8) DrawTarget::new(BackendType::Skia, size, SurfaceFormat::B8G8R8A8)
} else { } else {
@ -618,11 +617,11 @@ impl WorkerThread {
// Apply a translation to start at the boundaries of the stacking context, since the // Apply a translation to start at the boundaries of the stacking context, since the
// layer's origin starts at its overflow rect's origin. // layer's origin starts at its overflow rect's origin.
let tile_bounds = tile.page_rect.translate( let tile_bounds = tile.page_rect.translate(
&Point2D(stacking_context.overflow.origin.x.to_f32_px(), &Point2D::new(stacking_context.overflow.origin.x.to_f32_px(),
stacking_context.overflow.origin.y.to_f32_px())); stacking_context.overflow.origin.y.to_f32_px()));
// Apply the translation to paint the tile we want. // Apply the translation to paint the tile we want.
let matrix: Matrix4 = identity(); let matrix = Matrix4::identity();
let matrix = matrix.scale(scale as AzFloat, scale as AzFloat, 1.0); let matrix = matrix.scale(scale as AzFloat, scale as AzFloat, 1.0);
let matrix = matrix.translate(-tile_bounds.origin.x as AzFloat, let matrix = matrix.translate(-tile_bounds.origin.x as AzFloat,
-tile_bounds.origin.y as AzFloat, -tile_bounds.origin.y as AzFloat,
@ -647,17 +646,17 @@ impl WorkerThread {
// Overlay a transparent solid color to identify the thread that // Overlay a transparent solid color to identify the thread that
// painted this tile. // painted this tile.
let color = THREAD_TINT_COLORS[thread_id % THREAD_TINT_COLORS.len()]; let color = THREAD_TINT_COLORS[thread_id % THREAD_TINT_COLORS.len()];
paint_context.draw_solid_color(&Rect(Point2D(Au(0), Au(0)), paint_context.draw_solid_color(&Rect::new(Point2D::new(Au(0), Au(0)),
Size2D(Au::from_px(size.width), Size2D::new(Au::from_px(size.width),
Au::from_px(size.height))), Au::from_px(size.height))),
color); color);
} }
if opts::get().paint_flashing { if opts::get().paint_flashing {
// Overlay a random transparent color. // Overlay a random transparent color.
let color = *rand::thread_rng().choose(&THREAD_TINT_COLORS[..]).unwrap(); let color = *rand::thread_rng().choose(&THREAD_TINT_COLORS[..]).unwrap();
paint_context.draw_solid_color(&Rect(Point2D(Au(0), Au(0)), paint_context.draw_solid_color(&Rect::new(Point2D::new(Au(0), Au(0)),
Size2D(Au::from_px(size.width), Size2D::new(Au::from_px(size.width),
Au::from_px(size.height))), Au::from_px(size.height))),
color); color);
} }
} }

View file

@ -130,7 +130,7 @@ impl ShapedGlyphData {
*y_pos = *y_pos - y_advance; *y_pos = *y_pos - y_advance;
} }
Some(Point2D(x_offset, *y_pos - y_offset)) Some(Point2D::new(x_offset, *y_pos - y_offset))
}; };
ShapedGlyphEntry { ShapedGlyphEntry {

View file

@ -1047,7 +1047,7 @@ impl BlockFlow {
self.base.floats.add_float(&info); self.base.floats.add_float(&info);
// FIXME (mbrubeck) Get the correct container size for self.base.floats; // FIXME (mbrubeck) Get the correct container size for self.base.floats;
let container_size = Size2D(self.base.block_container_inline_size, Au(0)); let container_size = Size2D::new(self.base.block_container_inline_size, Au(0));
// Move in from the margin edge, as per CSS 2.1 § 9.5, floats may not overlap anything on // Move in from the margin edge, as per CSS 2.1 § 9.5, floats may not overlap anything on
// their margin edges. // their margin edges.
@ -1669,7 +1669,7 @@ impl Flow for BlockFlow {
fn compute_absolute_position(&mut self, layout_context: &LayoutContext) { fn compute_absolute_position(&mut self, layout_context: &LayoutContext) {
// FIXME (mbrubeck): Get the real container size, taking the container writing mode into // FIXME (mbrubeck): Get the real container size, taking the container writing mode into
// account. Must handle vertical writing modes. // account. Must handle vertical writing modes.
let container_size = Size2D(self.base.block_container_inline_size, Au(0)); let container_size = Size2D::new(self.base.block_container_inline_size, Au(0));
if self.is_root() { if self.is_root() {
self.base.clip = ClippingRegion::max(); self.base.clip = ClippingRegion::max();
@ -1776,7 +1776,7 @@ impl Flow for BlockFlow {
// //
// FIXME(pcwalton): Is this vertical-writing-direction-safe? // FIXME(pcwalton): Is this vertical-writing-direction-safe?
let margin = self.fragment.margin.to_physical(self.base.writing_mode); let margin = self.fragment.margin.to_physical(self.base.writing_mode);
origin_for_children = Point2D(-margin.left, Au(0)) + relative_offset; origin_for_children = Point2D::new(-margin.left, Au(0)) + relative_offset;
clip_in_child_coordinate_system = clip_in_child_coordinate_system =
self.base.clip.translate(&-self.base.stacking_relative_position); self.base.clip.translate(&-self.base.stacking_relative_position);
} else { } else {
@ -1789,7 +1789,7 @@ impl Flow for BlockFlow {
let visible_rect = let visible_rect =
match layout_context.shared.visible_rects.get(&self.layer_id(0)) { match layout_context.shared.visible_rects.get(&self.layer_id(0)) {
Some(visible_rect) => *visible_rect, Some(visible_rect) => *visible_rect,
None => Rect(Point2D::zero(), layout_context.shared.screen_size), None => Rect::new(Point2D::zero(), layout_context.shared.screen_size),
}; };
let screen_size = layout_context.shared.screen_size; let screen_size = layout_context.shared.screen_size;

View file

@ -22,7 +22,6 @@ use model::{self, MaybeAuto, ToGfxMatrix, ToAu};
use table_cell::CollapsedBordersForCell; use table_cell::CollapsedBordersForCell;
use geom::{Point2D, Rect, Size2D, SideOffsets2D}; use geom::{Point2D, Rect, Size2D, SideOffsets2D};
use geom::matrix::identity;
use geom::Matrix4; use geom::Matrix4;
use gfx_traits::color; use gfx_traits::color;
use gfx::display_list::{BLUR_INFLATION_FACTOR, BaseDisplayItem, BorderDisplayItem}; use gfx::display_list::{BLUR_INFLATION_FACTOR, BaseDisplayItem, BorderDisplayItem};
@ -392,18 +391,18 @@ impl FragmentDisplayListBuilding for Fragment {
// wide. // wide.
let image_aspect_ratio = (image.width as f64) / (image.height as f64); let image_aspect_ratio = (image.width as f64) / (image.height as f64);
let bounds_aspect_ratio = bounds.size.width.to_f64_px() / bounds.size.height.to_f64_px(); let bounds_aspect_ratio = bounds.size.width.to_f64_px() / bounds.size.height.to_f64_px();
let intrinsic_size = Size2D(Au::from_px(image.width as i32), let intrinsic_size = Size2D::new(Au::from_px(image.width as i32),
Au::from_px(image.height as i32)); Au::from_px(image.height as i32));
match (style.get_background().background_size.clone(), match (style.get_background().background_size.clone(),
image_aspect_ratio < bounds_aspect_ratio) { image_aspect_ratio < bounds_aspect_ratio) {
(background_size::T::Contain, false) | (background_size::T::Cover, true) => { (background_size::T::Contain, false) | (background_size::T::Cover, true) => {
Size2D(bounds.size.width, Size2D::new(bounds.size.width,
Au::from_f64_px(bounds.size.width.to_f64_px() / image_aspect_ratio)) Au::from_f64_px(bounds.size.width.to_f64_px() / image_aspect_ratio))
} }
(background_size::T::Contain, true) | (background_size::T::Cover, false) => { (background_size::T::Contain, true) | (background_size::T::Cover, false) => {
Size2D(Au::from_f64_px(bounds.size.height.to_f64_px() * image_aspect_ratio), Size2D::new(Au::from_f64_px(bounds.size.height.to_f64_px() * image_aspect_ratio),
bounds.size.height) bounds.size.height)
} }
(background_size::T::Explicit(background_size::ExplicitSize { (background_size::T::Explicit(background_size::ExplicitSize {
@ -412,7 +411,7 @@ impl FragmentDisplayListBuilding for Fragment {
}), _) => { }), _) => {
let width = MaybeAuto::from_style(width, bounds.size.width) let width = MaybeAuto::from_style(width, bounds.size.width)
.specified_or_default(intrinsic_size.width); .specified_or_default(intrinsic_size.width);
Size2D(width, Au::from_f64_px(width.to_f64_px() / image_aspect_ratio)) Size2D::new(width, Au::from_f64_px(width.to_f64_px() / image_aspect_ratio))
} }
(background_size::T::Explicit(background_size::ExplicitSize { (background_size::T::Explicit(background_size::ExplicitSize {
@ -421,14 +420,14 @@ impl FragmentDisplayListBuilding for Fragment {
}), _) => { }), _) => {
let height = MaybeAuto::from_style(height, bounds.size.height) let height = MaybeAuto::from_style(height, bounds.size.height)
.specified_or_default(intrinsic_size.height); .specified_or_default(intrinsic_size.height);
Size2D(Au::from_f64_px(height.to_f64_px() * image_aspect_ratio), height) Size2D::new(Au::from_f64_px(height.to_f64_px() * image_aspect_ratio), height)
} }
(background_size::T::Explicit(background_size::ExplicitSize { (background_size::T::Explicit(background_size::ExplicitSize {
width, width,
height height
}), _) => { }), _) => {
Size2D(MaybeAuto::from_style(width, bounds.size.width) Size2D::new(MaybeAuto::from_style(width, bounds.size.width)
.specified_or_default(intrinsic_size.width), .specified_or_default(intrinsic_size.width),
MaybeAuto::from_style(height, bounds.size.height) MaybeAuto::from_style(height, bounds.size.height)
.specified_or_default(intrinsic_size.height)) .specified_or_default(intrinsic_size.height))
@ -542,7 +541,7 @@ impl FragmentDisplayListBuilding for Fragment {
Cursor::DefaultCursor), Cursor::DefaultCursor),
clip), clip),
image: image.clone(), image: image.clone(),
stretch_size: Size2D(image_size.width, image_size.height), stretch_size: Size2D::new(image_size.width, image_size.height),
image_rendering: style.get_effects().image_rendering.clone(), image_rendering: style.get_effects().image_rendering.clone(),
}), level); }), level);
} }
@ -561,10 +560,10 @@ impl FragmentDisplayListBuilding for Fragment {
// between the starting point and the ending point. // between the starting point and the ending point.
let delta = match gradient.angle_or_corner { let delta = match gradient.angle_or_corner {
AngleOrCorner::Angle(angle) => { AngleOrCorner::Angle(angle) => {
Point2D(Au::from_f32_px(angle.radians().sin() * Point2D::new(Au::from_f32_px(angle.radians().sin() *
absolute_bounds.size.width.to_f32_px() / 2.0), absolute_bounds.size.width.to_f32_px() / 2.0),
Au::from_f32_px(-angle.radians().cos() * Au::from_f32_px(-angle.radians().cos() *
absolute_bounds.size.height.to_f32_px() / 2.0)) absolute_bounds.size.height.to_f32_px() / 2.0))
} }
AngleOrCorner::Corner(horizontal, vertical) => { AngleOrCorner::Corner(horizontal, vertical) => {
let x_factor = match horizontal { let x_factor = match horizontal {
@ -575,8 +574,8 @@ impl FragmentDisplayListBuilding for Fragment {
VerticalDirection::Top => -1, VerticalDirection::Top => -1,
VerticalDirection::Bottom => 1, VerticalDirection::Bottom => 1,
}; };
Point2D(absolute_bounds.size.width * x_factor / 2, Point2D::new(absolute_bounds.size.width * x_factor / 2,
absolute_bounds.size.height * y_factor / 2) absolute_bounds.size.height * y_factor / 2)
} }
}; };
@ -643,8 +642,8 @@ impl FragmentDisplayListBuilding for Fragment {
}) })
} }
let center = Point2D(absolute_bounds.origin.x + absolute_bounds.size.width / 2, let center = Point2D::new(absolute_bounds.origin.x + absolute_bounds.size.width / 2,
absolute_bounds.origin.y + absolute_bounds.size.height / 2); absolute_bounds.origin.y + absolute_bounds.size.height / 2);
let gradient_display_item = DisplayItem::GradientClass(box GradientDisplayItem { let gradient_display_item = DisplayItem::GradientClass(box GradientDisplayItem {
base: BaseDisplayItem::new(*absolute_bounds, base: BaseDisplayItem::new(*absolute_bounds,
@ -669,8 +668,8 @@ impl FragmentDisplayListBuilding for Fragment {
clip: &ClippingRegion) { clip: &ClippingRegion) {
// NB: According to CSS-BACKGROUNDS, box shadows render in *reverse* order (front to back). // NB: According to CSS-BACKGROUNDS, box shadows render in *reverse* order (front to back).
for box_shadow in style.get_effects().box_shadow.iter().rev() { for box_shadow in style.get_effects().box_shadow.iter().rev() {
let bounds = shadow_bounds(&absolute_bounds.translate(&Point2D(box_shadow.offset_x, let bounds = shadow_bounds(&absolute_bounds.translate(&Point2D::new(box_shadow.offset_x,
box_shadow.offset_y)), box_shadow.offset_y)),
box_shadow.blur_radius, box_shadow.blur_radius,
box_shadow.spread_radius); box_shadow.spread_radius);
list.push(DisplayItem::BoxShadowClass(box BoxShadowDisplayItem { list.push(DisplayItem::BoxShadowClass(box BoxShadowDisplayItem {
@ -681,7 +680,7 @@ impl FragmentDisplayListBuilding for Fragment {
(*clip).clone()), (*clip).clone()),
box_bounds: *absolute_bounds, box_bounds: *absolute_bounds,
color: style.resolve_color(box_shadow.color).to_gfx_color(), color: style.resolve_color(box_shadow.color).to_gfx_color(),
offset: Point2D(box_shadow.offset_x, box_shadow.offset_y), offset: Point2D::new(box_shadow.offset_x, box_shadow.offset_y),
blur_radius: box_shadow.blur_radius, blur_radius: box_shadow.blur_radius,
spread_radius: box_shadow.spread_radius, spread_radius: box_shadow.spread_radius,
clip_mode: if box_shadow.inset { clip_mode: if box_shadow.inset {
@ -867,12 +866,12 @@ impl FragmentDisplayListBuilding for Fragment {
}; };
// FIXME(pcwalton, #2795): Get the real container size. // FIXME(pcwalton, #2795): Get the real container size.
let clip_origin = Point2D(stacking_relative_border_box.origin.x + style_clip_rect.left, let clip_origin = Point2D::new(stacking_relative_border_box.origin.x + style_clip_rect.left,
stacking_relative_border_box.origin.y + style_clip_rect.top); stacking_relative_border_box.origin.y + style_clip_rect.top);
let right = style_clip_rect.right.unwrap_or(stacking_relative_border_box.size.width); let right = style_clip_rect.right.unwrap_or(stacking_relative_border_box.size.width);
let bottom = style_clip_rect.bottom.unwrap_or(stacking_relative_border_box.size.height); let bottom = style_clip_rect.bottom.unwrap_or(stacking_relative_border_box.size.height);
let clip_size = Size2D(right - clip_origin.x, bottom - clip_origin.y); let clip_size = Size2D::new(right - clip_origin.x, bottom - clip_origin.y);
(*parent_clip).clone().intersect_rect(&Rect(clip_origin, clip_size)) (*parent_clip).clone().intersect_rect(&Rect::new(clip_origin, clip_size))
} }
fn build_display_list(&mut self, fn build_display_list(&mut self,
@ -1030,7 +1029,7 @@ impl FragmentDisplayListBuilding for Fragment {
// to back). // to back).
let text_color = self.style().get_color().color; let text_color = self.style().get_color().color;
for text_shadow in self.style.get_effects().text_shadow.0.iter().rev() { for text_shadow in self.style.get_effects().text_shadow.0.iter().rev() {
let offset = &Point2D(text_shadow.offset_x, text_shadow.offset_y); let offset = &Point2D::new(text_shadow.offset_x, text_shadow.offset_y);
let color = self.style().resolve_color(text_shadow.color); let color = self.style().resolve_color(text_shadow.color);
self.build_display_list_for_text_fragment(display_list, self.build_display_list_for_text_fragment(display_list,
&**text_fragment, &**text_fragment,
@ -1047,7 +1046,7 @@ impl FragmentDisplayListBuilding for Fragment {
text_color, text_color,
&stacking_relative_content_box, &stacking_relative_content_box,
None, None,
&Point2D(Au(0), Au(0)), &Point2D::new(Au(0), Au(0)),
clip); clip);
if opts::get().show_debug_fragment_borders { if opts::get().show_debug_fragment_borders {
@ -1142,15 +1141,15 @@ impl FragmentDisplayListBuilding for Fragment {
.relative_containing_block_mode, .relative_containing_block_mode,
CoordinateSystem::Parent); CoordinateSystem::Parent);
let mut transform = identity(); let mut transform = Matrix4::identity();
if let Some(ref operations) = self.style().get_effects().transform { if let Some(ref operations) = self.style().get_effects().transform {
let transform_origin = self.style().get_effects().transform_origin; let transform_origin = self.style().get_effects().transform_origin;
let transform_origin = let transform_origin =
Point2D(model::specified(transform_origin.horizontal, Point2D::new(model::specified(transform_origin.horizontal,
border_box.size.width).to_f32_px(), border_box.size.width).to_f32_px(),
model::specified(transform_origin.vertical, model::specified(transform_origin.vertical,
border_box.size.height).to_f32_px()); border_box.size.height).to_f32_px());
let pre_transform = Matrix4::create_translation(transform_origin.x, let pre_transform = Matrix4::create_translation(transform_origin.x,
transform_origin.y, transform_origin.y,
@ -1193,7 +1192,7 @@ impl FragmentDisplayListBuilding for Fragment {
// FIXME(pcwalton): Is this vertical-writing-direction-safe? // FIXME(pcwalton): Is this vertical-writing-direction-safe?
let margin = self.margin.to_physical(base_flow.writing_mode); let margin = self.margin.to_physical(base_flow.writing_mode);
let overflow = base_flow.overflow.translate(&-Point2D(margin.left, Au(0))); let overflow = base_flow.overflow.translate(&-Point2D::new(margin.left, Au(0)));
// Create the filter pipeline. // Create the filter pipeline.
let effects = self.style().get_effects(); let effects = self.style().get_effects();
@ -1241,10 +1240,10 @@ impl FragmentDisplayListBuilding for Fragment {
layout_context: &LayoutContext) { layout_context: &LayoutContext) {
let border_padding = (self.border_padding).to_physical(self.style.writing_mode); let border_padding = (self.border_padding).to_physical(self.style.writing_mode);
let content_size = self.content_box().size.to_physical(self.style.writing_mode); let content_size = self.content_box().size.to_physical(self.style.writing_mode);
let iframe_rect = Rect(Point2D((offset.x + border_padding.left).to_f32_px(), let iframe_rect = Rect::new(Point2D::new((offset.x + border_padding.left).to_f32_px(),
(offset.y + border_padding.top).to_f32_px()), (offset.y + border_padding.top).to_f32_px()),
Size2D(content_size.width.to_f32_px(), Size2D::new(content_size.width.to_f32_px(),
content_size.height.to_f32_px())); content_size.height.to_f32_px()));
debug!("finalizing position and size of iframe for {:?},{:?}", debug!("finalizing position and size of iframe for {:?},{:?}",
iframe_fragment.pipeline_id, iframe_fragment.pipeline_id,
@ -1726,8 +1725,8 @@ impl BaseFlowDisplayListBuilding for BaseFlow {
let thread_id = self.thread_id; let thread_id = self.thread_id;
let stacking_context_relative_bounds = let stacking_context_relative_bounds =
Rect(self.stacking_relative_position, Rect::new(self.stacking_relative_position,
self.position.size.to_physical(self.writing_mode)); self.position.size.to_physical(self.writing_mode));
let mut color = THREAD_TINT_COLORS[thread_id as usize % THREAD_TINT_COLORS.len()]; let mut color = THREAD_TINT_COLORS[thread_id as usize % THREAD_TINT_COLORS.len()];
color.a = 1.0; color.a = 1.0;

View file

@ -1072,7 +1072,7 @@ impl BaseFlow {
let position_with_overflow = self.position let position_with_overflow = self.position
.to_physical(self.writing_mode, container_size) .to_physical(self.writing_mode, container_size)
.union(&self.overflow); .union(&self.overflow);
let bounds = Rect(self.stacking_relative_position, position_with_overflow.size); let bounds = Rect::new(self.stacking_relative_position, position_with_overflow.size);
let all_items = match self.display_list_building_result { let all_items = match self.display_list_building_result {
DisplayListBuildingResult::None => Vec::new(), DisplayListBuildingResult::None => Vec::new(),

View file

@ -1957,7 +1957,7 @@ impl Fragment {
relative_containing_block_size.to_physical(relative_containing_block_mode); relative_containing_block_size.to_physical(relative_containing_block_mode);
let border_box = self.border_box.to_physical(self.style.writing_mode, container_size); let border_box = self.border_box.to_physical(self.style.writing_mode, container_size);
if coordinate_system == CoordinateSystem::Own && self.establishes_stacking_context() { if coordinate_system == CoordinateSystem::Own && self.establishes_stacking_context() {
return Rect(ZERO_POINT, border_box.size) return Rect::new(ZERO_POINT, border_box.size)
} }
// FIXME(pcwalton): This can double-count relative position sometimes for inlines (e.g. // FIXME(pcwalton): This can double-count relative position sometimes for inlines (e.g.
@ -1974,10 +1974,10 @@ impl Fragment {
pub fn stacking_relative_content_box(&self, stacking_relative_border_box: &Rect<Au>) pub fn stacking_relative_content_box(&self, stacking_relative_border_box: &Rect<Au>)
-> Rect<Au> { -> Rect<Au> {
let border_padding = self.border_padding.to_physical(self.style.writing_mode); let border_padding = self.border_padding.to_physical(self.style.writing_mode);
Rect(Point2D(stacking_relative_border_box.origin.x + border_padding.left, Rect::new(Point2D::new(stacking_relative_border_box.origin.x + border_padding.left,
stacking_relative_border_box.origin.y + border_padding.top), stacking_relative_border_box.origin.y + border_padding.top),
Size2D(stacking_relative_border_box.size.width - border_padding.horizontal(), Size2D::new(stacking_relative_border_box.size.width - border_padding.horizontal(),
stacking_relative_border_box.size.height - border_padding.vertical())) stacking_relative_border_box.size.height - border_padding.vertical()))
} }
/// Returns true if this fragment establishes a new stacking context and false otherwise. /// Returns true if this fragment establishes a new stacking context and false otherwise.
@ -2033,7 +2033,7 @@ impl Fragment {
// Box shadows cause us to draw outside our border box. // Box shadows cause us to draw outside our border box.
for box_shadow in self.style().get_effects().box_shadow.iter() { for box_shadow in self.style().get_effects().box_shadow.iter() {
let offset = Point2D(box_shadow.offset_x, box_shadow.offset_y); let offset = Point2D::new(box_shadow.offset_x, box_shadow.offset_y);
let inflation = box_shadow.spread_radius + box_shadow.blur_radius * let inflation = box_shadow.spread_radius + box_shadow.blur_radius *
BLUR_INFLATION_FACTOR; BLUR_INFLATION_FACTOR;
overflow = overflow.union(&border_box.translate(&offset).inflate(inflation, inflation)) overflow = overflow.union(&border_box.translate(&offset).inflate(inflation, inflation))

View file

@ -1467,7 +1467,7 @@ impl Flow for InlineFlow {
fn compute_absolute_position(&mut self, _: &LayoutContext) { fn compute_absolute_position(&mut self, _: &LayoutContext) {
// First, gather up the positions of all the containing blocks (if any). // First, gather up the positions of all the containing blocks (if any).
let mut containing_block_positions = Vec::new(); let mut containing_block_positions = Vec::new();
let container_size = Size2D(self.base.block_container_inline_size, Au(0)); let container_size = Size2D::new(self.base.block_container_inline_size, Au(0));
for (fragment_index, fragment) in self.fragments.fragments.iter().enumerate() { for (fragment_index, fragment) in self.fragments.fragments.iter().enumerate() {
if let SpecificFragmentInfo::InlineAbsolute(_) = fragment.specific { if let SpecificFragmentInfo::InlineAbsolute(_) = fragment.specific {
let containing_block_range = let containing_block_range =

View file

@ -28,7 +28,7 @@ use canvas_traits::CanvasMsg;
use encoding::EncodingRef; use encoding::EncodingRef;
use encoding::all::UTF_8; use encoding::all::UTF_8;
use fnv::FnvHasher; use fnv::FnvHasher;
use geom::matrix; use geom::Matrix4;
use geom::point::Point2D; use geom::point::Point2D;
use geom::rect::Rect; use geom::rect::Rect;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
@ -295,7 +295,7 @@ impl LayoutTask {
time_profiler_chan: time::ProfilerChan, time_profiler_chan: time::ProfilerChan,
mem_profiler_chan: mem::ProfilerChan) mem_profiler_chan: mem::ProfilerChan)
-> LayoutTask { -> LayoutTask {
let screen_size = Size2D(Au(0), Au(0)); let screen_size = Size2D::new(Au(0), Au(0));
let device = Device::new( let device = Device::new(
MediaType::Screen, MediaType::Screen,
opts::get().initial_window_size.as_f32() * ScaleFactor::new(1.0)); opts::get().initial_window_size.as_f32() * ScaleFactor::new(1.0));
@ -867,13 +867,13 @@ impl LayoutTask {
let paint_layer = Arc::new(PaintLayer::new(layout_root.layer_id(0), let paint_layer = Arc::new(PaintLayer::new(layout_root.layer_id(0),
root_background_color, root_background_color,
ScrollPolicy::Scrollable)); ScrollPolicy::Scrollable));
let origin = Rect(Point2D(Au(0), Au(0)), root_size); let origin = Rect::new(Point2D::new(Au(0), Au(0)), root_size);
let stacking_context = Arc::new(StackingContext::new(display_list, let stacking_context = Arc::new(StackingContext::new(display_list,
&origin, &origin,
&origin, &origin,
0, 0,
&matrix::identity(), &Matrix4::identity(),
filter::T::new(Vec::new()), filter::T::new(Vec::new()),
mix_blend_mode::T::normal, mix_blend_mode::T::normal,
Some(paint_layer))); Some(paint_layer)));
@ -916,8 +916,8 @@ impl LayoutTask {
let initial_viewport = data.window_size.initial_viewport; let initial_viewport = data.window_size.initial_viewport;
let old_screen_size = rw_data.screen_size; let old_screen_size = rw_data.screen_size;
let current_screen_size = Size2D(Au::from_f32_px(initial_viewport.width.get()), let current_screen_size = Size2D::new(Au::from_f32_px(initial_viewport.width.get()),
Au::from_f32_px(initial_viewport.height.get())); Au::from_f32_px(initial_viewport.height.get()));
rw_data.screen_size = current_screen_size; rw_data.screen_size = current_screen_size;
// Handle conditions where the entire flow tree is invalid. // Handle conditions where the entire flow tree is invalid.
@ -931,8 +931,8 @@ impl LayoutTask {
debug!("Viewport constraints: {:?}", constraints); debug!("Viewport constraints: {:?}", constraints);
// other rules are evaluated against the actual viewport // other rules are evaluated against the actual viewport
rw_data.screen_size = Size2D(Au::from_f32_px(constraints.size.width.get()), rw_data.screen_size = Size2D::new(Au::from_f32_px(constraints.size.width.get()),
Au::from_f32_px(constraints.size.height.get())); Au::from_f32_px(constraints.size.height.get()));
let device = Device::new(MediaType::Screen, constraints.size); let device = Device::new(MediaType::Screen, constraints.size);
rw_data.stylist.set_device(device); rw_data.stylist.set_device(device);
@ -1035,8 +1035,8 @@ impl LayoutTask {
let mut must_regenerate_display_lists = false; let mut must_regenerate_display_lists = false;
let mut old_visible_rects = HashMap::with_hash_state(Default::default()); let mut old_visible_rects = HashMap::with_hash_state(Default::default());
let inflation_amount = let inflation_amount =
Size2D(rw_data.screen_size.width * DISPLAY_PORT_THRESHOLD_SIZE_FACTOR, Size2D::new(rw_data.screen_size.width * DISPLAY_PORT_THRESHOLD_SIZE_FACTOR,
rw_data.screen_size.height * DISPLAY_PORT_THRESHOLD_SIZE_FACTOR); rw_data.screen_size.height * DISPLAY_PORT_THRESHOLD_SIZE_FACTOR);
for &(ref layer_id, ref new_visible_rect) in new_visible_rects.iter() { for &(ref layer_id, ref new_visible_rect) in new_visible_rects.iter() {
match rw_data.visible_rects.get(layer_id) { match rw_data.visible_rects.get(layer_id) {
None => { None => {
@ -1251,7 +1251,7 @@ impl LayoutRPC for LayoutRPCImpl {
/// Requests the node containing the point of interest. /// Requests the node containing the point of interest.
fn hit_test(&self, _: TrustedNodeAddress, point: Point2D<f32>) -> Result<HitTestResponse, ()> { fn hit_test(&self, _: TrustedNodeAddress, point: Point2D<f32>) -> Result<HitTestResponse, ()> {
let point = Point2D(Au::from_f32_px(point.x), Au::from_f32_px(point.y)); let point = Point2D::new(Au::from_f32_px(point.x), Au::from_f32_px(point.y));
let resp = { let resp = {
let &LayoutRPCImpl(ref rw_data) = self; let &LayoutRPCImpl(ref rw_data) = self;
let rw_data = rw_data.lock().unwrap(); let rw_data = rw_data.lock().unwrap();
@ -1278,7 +1278,7 @@ impl LayoutRPC for LayoutRPCImpl {
fn mouse_over(&self, _: TrustedNodeAddress, point: Point2D<f32>) fn mouse_over(&self, _: TrustedNodeAddress, point: Point2D<f32>)
-> Result<MouseOverResponse, ()> { -> Result<MouseOverResponse, ()> {
let mut mouse_over_list: Vec<DisplayItemMetadata> = vec!(); let mut mouse_over_list: Vec<DisplayItemMetadata> = vec!();
let point = Point2D(Au::from_f32_px(point.x), Au::from_f32_px(point.y)); let point = Point2D::new(Au::from_f32_px(point.x), Au::from_f32_px(point.y));
{ {
let &LayoutRPCImpl(ref rw_data) = self; let &LayoutRPCImpl(ref rw_data) = self;
let rw_data = rw_data.lock().unwrap(); let rw_data = rw_data.lock().unwrap();

View file

@ -324,14 +324,14 @@ impl CollapsedBordersForCell {
// FIXME(pcwalton): Get the real container size. // FIXME(pcwalton): Get the real container size.
let mut logical_bounds = let mut logical_bounds =
LogicalRect::from_physical(writing_mode, *border_bounds, Size2D(Au(0), Au(0))); LogicalRect::from_physical(writing_mode, *border_bounds, Size2D::new(Au(0), Au(0)));
logical_bounds.start.i = logical_bounds.start.i - inline_start_offset; logical_bounds.start.i = logical_bounds.start.i - inline_start_offset;
logical_bounds.start.b = logical_bounds.start.b - block_start_offset; logical_bounds.start.b = logical_bounds.start.b - block_start_offset;
logical_bounds.size.inline = logical_bounds.size.inline + inline_start_offset + logical_bounds.size.inline = logical_bounds.size.inline + inline_start_offset +
inline_end_offset; inline_end_offset;
logical_bounds.size.block = logical_bounds.size.block + block_start_offset + logical_bounds.size.block = logical_bounds.size.block + block_start_offset +
block_end_offset; block_end_offset;
*border_bounds = logical_bounds.to_physical(writing_mode, Size2D(Au(0), Au(0))) *border_bounds = logical_bounds.to_physical(writing_mode, Size2D::new(Au(0), Au(0)))
} }
pub fn adjust_border_colors_and_styles_for_painting( pub fn adjust_border_colors_and_styles_for_painting(

View file

@ -155,13 +155,13 @@ impl CanvasRenderingContext2D {
image_size: Size2D<f64>, image_size: Size2D<f64>,
sx: f64, sy: f64, sw: f64, sh: f64, sx: f64, sy: f64, sw: f64, sh: f64,
dx: f64, dy: f64, dw: f64, dh: f64) -> (Rect<f64>, Rect<f64>) { dx: f64, dy: f64, dw: f64, dh: f64) -> (Rect<f64>, Rect<f64>) {
let image_rect = Rect(Point2D(0f64, 0f64), let image_rect = Rect::new(Point2D::new(0f64, 0f64),
Size2D(image_size.width as f64, image_size.height as f64)); Size2D::new(image_size.width as f64, image_size.height as f64));
// The source rectangle is the rectangle whose corners are the four points (sx, sy), // The source rectangle is the rectangle whose corners are the four points (sx, sy),
// (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh). // (sx+sw, sy), (sx+sw, sy+sh), (sx, sy+sh).
let source_rect = Rect(Point2D(sx.min(sx+sw), sy.min(sy+sh)), let source_rect = Rect::new(Point2D::new(sx.min(sx+sw), sy.min(sy+sh)),
Size2D(sw.abs(), sh.abs())); Size2D::new(sw.abs(), sh.abs()));
// When the source rectangle is outside the source image, // When the source rectangle is outside the source image,
// the source rectangle must be clipped to the source image // the source rectangle must be clipped to the source image
@ -178,13 +178,13 @@ impl CanvasRenderingContext2D {
// The destination rectangle is the rectangle whose corners are the four points (dx, dy), // The destination rectangle is the rectangle whose corners are the four points (dx, dy),
// (dx+dw, dy), (dx+dw, dy+dh), (dx, dy+dh). // (dx+dw, dy), (dx+dw, dy+dh), (dx, dy+dh).
let dest_rect = Rect(Point2D(dx.min(dx+dest_rect_width_scaled), dy.min(dy+dest_rect_height_scaled)), let dest_rect = Rect::new(Point2D::new(dx.min(dx+dest_rect_width_scaled), dy.min(dy+dest_rect_height_scaled)),
Size2D(dest_rect_width_scaled.abs(), dest_rect_height_scaled.abs())); Size2D::new(dest_rect_width_scaled.abs(), dest_rect_height_scaled.abs()));
let source_rect = Rect(Point2D(source_rect_clipped.origin.x, let source_rect = Rect::new(Point2D::new(source_rect_clipped.origin.x,
source_rect_clipped.origin.y), source_rect_clipped.origin.y),
Size2D(source_rect_clipped.size.width, Size2D::new(source_rect_clipped.size.width,
source_rect_clipped.size.height)); source_rect_clipped.size.height));
return (source_rect, dest_rect) return (source_rect, dest_rect)
} }
@ -220,7 +220,7 @@ impl CanvasRenderingContext2D {
} }
let canvas_size = canvas.get_size(); let canvas_size = canvas.get_size();
let image_size = Size2D(canvas_size.width as f64, canvas_size.height as f64); let image_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64);
// 2. Establish the source and destination rectangles // 2. Establish the source and destination rectangles
let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh); let (source_rect, dest_rect) = self.adjust_source_dest_rects(image_size, sx, sy, sw, sh, dx, dy, dw, dh);
@ -287,7 +287,7 @@ impl CanvasRenderingContext2D {
ImageResponse::PlaceholderLoaded(_) | ImageResponse::None => return None, ImageResponse::PlaceholderLoaded(_) | ImageResponse::None => return None,
}; };
let image_size = Size2D(img.width as f64, img.height as f64); let image_size = Size2D::new(img.width as f64, img.height as f64);
let mut image_data = match img.pixels { let mut image_data = match img.pixels {
PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(), PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(),
PixelsByColorType::K8(_) => panic!("K8 color type not supported"), PixelsByColorType::K8(_) => panic!("K8 color type not supported"),
@ -320,7 +320,7 @@ impl CanvasRenderingContext2D {
return None; return None;
} }
Some(Rect(Point2D(x as f32, y as f32), Size2D(w as f32, h as f32))) Some(Rect::new(Point2D::new(x as f32, y as f32), Size2D::new(w as f32, h as f32)))
} }
} }
@ -703,7 +703,10 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
return; return;
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::MoveTo(Point2D(x as f32, y as f32)))).unwrap(); let msg = CanvasMsg::Canvas2d(
Canvas2dMsg::MoveTo(
Point2D::new(x as f32, y as f32)));
self.renderer.send(msg).unwrap();
} }
// https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto // https://html.spec.whatwg.org/multipage/#dom-context-2d-lineto
@ -712,15 +715,19 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
return; return;
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::LineTo(Point2D(x as f32, y as f32)))).unwrap(); let msg = CanvasMsg::Canvas2d(
Canvas2dMsg::LineTo(
Point2D::new(x as f32, y as f32)));
self.renderer.send(msg).unwrap();
} }
// https://html.spec.whatwg.org/multipage/#dom-context-2d-rect // https://html.spec.whatwg.org/multipage/#dom-context-2d-rect
fn Rect(self, x: f64, y: f64, width: f64, height: f64) { fn Rect(self, x: f64, y: f64, width: f64, height: f64) {
if [x, y, width, height].iter().all(|val| val.is_finite()) { if [x, y, width, height].iter().all(|val| val.is_finite()) {
let rect = Rect(Point2D(x as f32, y as f32), let rect = Rect::new(Point2D::new(x as f32, y as f32),
Size2D(width as f32, height as f32)); Size2D::new(width as f32, height as f32));
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Rect(rect))).unwrap(); let msg = CanvasMsg::Canvas2d(Canvas2dMsg::Rect(rect));
self.renderer.send(msg).unwrap();
} }
} }
@ -731,8 +738,11 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
return; return;
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::QuadraticCurveTo(Point2D(cpx as f32, cpy as f32), let msg = CanvasMsg::Canvas2d(
Point2D(x as f32, y as f32)))).unwrap(); Canvas2dMsg::QuadraticCurveTo(
Point2D::new(cpx as f32, cpy as f32),
Point2D::new(x as f32, y as f32)));
self.renderer.send(msg).unwrap();
} }
// https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto // https://html.spec.whatwg.org/multipage/#dom-context-2d-beziercurveto
@ -742,9 +752,12 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
return; return;
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::BezierCurveTo(Point2D(cp1x as f32, cp1y as f32), let msg = CanvasMsg::Canvas2d(
Point2D(cp2x as f32, cp2y as f32), Canvas2dMsg::BezierCurveTo(
Point2D(x as f32, y as f32)))).unwrap(); Point2D::new(cp1x as f32, cp1y as f32),
Point2D::new(cp2x as f32, cp2y as f32),
Point2D::new(x as f32, y as f32)));
self.renderer.send(msg).unwrap();
} }
// https://html.spec.whatwg.org/multipage/#dom-context-2d-arc // https://html.spec.whatwg.org/multipage/#dom-context-2d-arc
@ -760,8 +773,12 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
return Err(IndexSize); return Err(IndexSize);
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::Arc(Point2D(x as f32, y as f32), r as f32, let msg = CanvasMsg::Canvas2d(
start as f32, end as f32, ccw))).unwrap(); Canvas2dMsg::Arc(
Point2D::new(x as f32, y as f32), r as f32,
start as f32, end as f32, ccw));
self.renderer.send(msg).unwrap();
Ok(()) Ok(())
} }
@ -773,9 +790,13 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
if r < 0.0 { if r < 0.0 {
return Err(IndexSize); return Err(IndexSize);
} }
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::ArcTo(Point2D(cp1x as f32, cp1y as f32),
Point2D(cp2x as f32, cp2y as f32), let msg = CanvasMsg::Canvas2d(
r as f32))).unwrap(); Canvas2dMsg::ArcTo(
Point2D::new(cp1x as f32, cp1y as f32),
Point2D::new(cp2x as f32, cp2y as f32),
r as f32));
self.renderer.send(msg).unwrap();
Ok(()) Ok(())
} }
@ -907,9 +928,10 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
} }
let (sender, receiver) = channel::<Vec<u8>>(); let (sender, receiver) = channel::<Vec<u8>>();
let dest_rect = Rect(Point2D(sx as f64, sy as f64), Size2D(sw as f64, sh as f64)); let dest_rect = Rect::new(Point2D::new(sx as f64, sy as f64),
Size2D::new(sw as f64, sh as f64));
let canvas_size = self.canvas.root().r().get_size(); let canvas_size = self.canvas.root().r().get_size();
let canvas_size = Size2D(canvas_size.width as f64, canvas_size.height as f64); let canvas_size = Size2D::new(canvas_size.width as f64, canvas_size.height as f64);
self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender))).unwrap(); self.renderer.send(CanvasMsg::Canvas2d(Canvas2dMsg::GetImageData(dest_rect, canvas_size, sender))).unwrap();
let data = receiver.recv().unwrap(); let data = receiver.recv().unwrap();
Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data))) Ok(ImageData::new(self.global.root().r(), sw.abs().to_u32().unwrap(), sh.abs().to_u32().unwrap(), Some(data)))
@ -929,8 +951,8 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
let data = imagedata.get_data_array(&self.global.root().r()); let data = imagedata.get_data_array(&self.global.root().r());
let image_data_size = imagedata.get_size(); let image_data_size = imagedata.get_size();
let image_data_size = Size2D(image_data_size.width as f64, image_data_size.height as f64); let image_data_size = Size2D::new(image_data_size.width as f64, image_data_size.height as f64);
let image_data_rect = Rect(Point2D(dx, dy), image_data_size); let image_data_rect = Rect::new(Point2D::new(dx, dy), image_data_size);
let dirty_rect = None; let dirty_rect = None;
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect)); let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect));
self.renderer.send(msg).unwrap(); self.renderer.send(msg).unwrap();
@ -955,11 +977,11 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
// they will be TypeError by WebIDL spec before call this methods. // they will be TypeError by WebIDL spec before call this methods.
let data = imagedata.get_data_array(&self.global.root().r()); let data = imagedata.get_data_array(&self.global.root().r());
let image_data_rect = Rect(Point2D(dx, dy), let image_data_rect = Rect::new(Point2D::new(dx, dy),
Size2D(imagedata.Width() as f64, Size2D::new(imagedata.Width() as f64,
imagedata.Height() as f64)); imagedata.Height() as f64));
let dirty_rect = Some(Rect(Point2D(dirtyX, dirtyY), let dirty_rect = Some(Rect::new(Point2D::new(dirtyX, dirtyY),
Size2D(dirtyWidth, dirtyHeight))); Size2D::new(dirtyWidth, dirtyHeight)));
let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect)); let msg = CanvasMsg::Canvas2d(Canvas2dMsg::PutImageData(data, image_data_rect, dirty_rect));
self.renderer.send(msg).unwrap(); self.renderer.send(msg).unwrap();
self.mark_as_dirty(); self.mark_as_dirty();
@ -1019,7 +1041,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
ImageResponse::PlaceholderLoaded(_) | ImageResponse::None => return Err(InvalidState), ImageResponse::PlaceholderLoaded(_) | ImageResponse::None => return Err(InvalidState),
}; };
let image_size = Size2D(img.width as f64, img.height as f64); let image_size = Size2D::new(img.width as f64, img.height as f64);
let image_data = match img.pixels { let image_data = match img.pixels {
PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(), PixelsByColorType::RGBA8(ref pixels) => pixels.to_vec(),
PixelsByColorType::K8(_) => panic!("K8 color type not supported"), PixelsByColorType::K8(_) => panic!("K8 color type not supported"),
@ -1030,7 +1052,7 @@ impl<'a> CanvasRenderingContext2DMethods for JSRef<'a, CanvasRenderingContext2D>
if let Some(rep) = RepetitionStyle::from_str(&repetition) { if let Some(rep) = RepetitionStyle::from_str(&repetition) {
return Ok(CanvasPattern::new(self.global.root().r(), return Ok(CanvasPattern::new(self.global.root().r(),
image_data, image_data,
Size2D(image_size.width as i32, image_size.height as i32), Size2D::new(image_size.width as i32, image_size.height as i32),
rep)); rep));
} }
return Err(Syntax); return Err(Syntax);

View file

@ -98,7 +98,7 @@ impl HTMLCanvasElement {
} }
pub fn get_size(&self) -> Size2D<i32> { pub fn get_size(&self) -> Size2D<i32> {
Size2D(self.width.get() as i32, self.height.get() as i32) Size2D::new(self.width.get() as i32, self.height.get() as i32)
} }
} }

View file

@ -68,7 +68,7 @@ impl<'a> ImageDataHelpers for JSRef<'a, ImageData> {
} }
fn get_size(&self) -> Size2D<i32> { fn get_size(&self) -> Size2D<i32> {
Size2D(self.Width() as i32, self.Height() as i32) Size2D::new(self.Width() as i32, self.Height() as i32)
} }
} }

View file

@ -1020,10 +1020,10 @@ impl Window {
} }
fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool{ fn should_move_clip_rect(clip_rect: Rect<Au>, new_viewport: Rect<f32>) -> bool{
let clip_rect = Rect(Point2D(clip_rect.origin.x.to_f32_px(), let clip_rect = Rect::new(Point2D::new(clip_rect.origin.x.to_f32_px(),
clip_rect.origin.y.to_f32_px()), clip_rect.origin.y.to_f32_px()),
Size2D(clip_rect.size.width.to_f32_px(), Size2D::new(clip_rect.size.width.to_f32_px(),
clip_rect.size.height.to_f32_px())); clip_rect.size.height.to_f32_px()));
// We only need to move the clip rect if the viewport is getting near the edge of // We only need to move the clip rect if the viewport is getting near the edge of
// our preexisting clip rect. We use half of the size of the viewport as a heuristic // our preexisting clip rect. We use half of the size of the viewport as a heuristic

View file

@ -1340,7 +1340,7 @@ impl ScriptTask {
fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef<Element>) { fn scroll_fragment_point(&self, pipeline_id: PipelineId, node: JSRef<Element>) {
let node: JSRef<Node> = NodeCast::from_ref(node); let node: JSRef<Node> = NodeCast::from_ref(node);
let rect = node.get_bounding_content_box(); let rect = node.get_bounding_content_box();
let point = Point2D(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()); let point = Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px());
// FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved. // FIXME(#2003, pcwalton): This is pretty bogus when multiple layers are involved.
// Really what needs to happen is that this needs to go through layout to ask which // Really what needs to happen is that this needs to go through layout to ask which
// layer the element belongs to, and have it send the scroll message to the // layer the element belongs to, and have it send the scroll message to the

View file

@ -385,7 +385,7 @@ dependencies = [
[[package]] [[package]]
name = "geom" name = "geom"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-geom#1b49f8ce1c4e8ade720dd940d1964c657a96817f" source = "git+https://github.com/servo/rust-geom#16b91afc0b9b532f2fb56879069bc381f2143df1"
dependencies = [ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@ -624,7 +624,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "layers" name = "layers"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ca37ca2949c46f91e37f28fa31ad6c1e8036f2d0" source = "git+https://github.com/servo/rust-layers#e566d3fc6ec80fe3aaf8ce67785683c99c46a015"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
@ -856,7 +856,7 @@ dependencies = [
[[package]] [[package]]
name = "offscreen_gl_context" name = "offscreen_gl_context"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#0fd217b95d806bdcb6d381cf092ca8776de273c8" source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#c402c86f8d4472785e04e59505feb28638101700"
dependencies = [ dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -203,8 +203,8 @@ pub fn parse_media_query_list(input: &mut Parser) -> MediaQueryList {
impl MediaQueryList { impl MediaQueryList {
pub fn evaluate(&self, device: &Device) -> bool { pub fn evaluate(&self, device: &Device) -> bool {
let viewport_size = Size2D(Au::from_f32_px(device.viewport_size.width.get()), let viewport_size = Size2D::new(Au::from_f32_px(device.viewport_size.width.get()),
Au::from_f32_px(device.viewport_size.height.get())); Au::from_f32_px(device.viewport_size.height.get()));
// Check if any queries match (OR condition) // Check if any queries match (OR condition)
self.media_queries.iter().any(|mq| { self.media_queries.iter().any(|mq| {

View file

@ -3896,7 +3896,7 @@ pub mod longhands {
p2y = try!(input.expect_number()); p2y = try!(input.expect_number());
Ok(()) Ok(())
})); }));
let (p1, p2) = (Point2D(p1x, p1y), Point2D(p2x, p2y)); let (p1, p2) = (Point2D::new(p1x, p1y), Point2D::new(p2x, p2y));
Ok(TransitionTimingFunction::CubicBezier(p1, p2)) Ok(TransitionTimingFunction::CubicBezier(p1, p2))
}, },
"steps" => { "steps" => {

View file

@ -417,8 +417,8 @@ impl ViewportConstraints {
// //
// Note: DEVICE-ADAPT § 5. states that relative length values are // Note: DEVICE-ADAPT § 5. states that relative length values are
// resolved against initial values // resolved against initial values
let initial_viewport = Size2D(Au::from_f32_px(initial_viewport.width.get()), let initial_viewport = Size2D::new(Au::from_f32_px(initial_viewport.width.get()),
Au::from_f32_px(initial_viewport.height.get())); Au::from_f32_px(initial_viewport.height.get()));
macro_rules! to_pixel_length { macro_rules! to_pixel_length {
($value:ident, $dimension:ident) => { ($value:ident, $dimension:ident) => {
@ -496,7 +496,7 @@ impl ViewportConstraints {
}); });
Some(ViewportConstraints { Some(ViewportConstraints {
size: TypedSize2D(width.to_f32_px(), height.to_f32_px()), size: Size2D::typed(width.to_f32_px(), height.to_f32_px()),
// TODO: compute a zoom factor for 'auto' as suggested by DEVICE-ADAPT § 10. // TODO: compute a zoom factor for 'auto' as suggested by DEVICE-ADAPT § 10.
initial_zoom: ScaleFactor::new(initial_zoom.unwrap_or(1.)), initial_zoom: ScaleFactor::new(initial_zoom.unwrap_or(1.)),

View file

@ -277,7 +277,7 @@ pub fn rect_contains_point<T:PartialOrd + Add<T, Output=T>>(rect: Rect<T>, point
/// A helper function to convert a rect of `f32` pixels to a rect of app units. /// A helper function to convert a rect of `f32` pixels to a rect of app units.
pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> { pub fn f32_rect_to_au_rect(rect: Rect<f32>) -> Rect<Au> {
Rect(Point2D(Au::from_f32_px(rect.origin.x), Au::from_f32_px(rect.origin.y)), Rect::new(Point2D::new(Au::from_f32_px(rect.origin.x), Au::from_f32_px(rect.origin.y)),
Size2D(Au::from_f32_px(rect.size.width), Au::from_f32_px(rect.size.height))) Size2D::new(Au::from_f32_px(rect.size.width), Au::from_f32_px(rect.size.height)))
} }

View file

@ -8,7 +8,7 @@
use geometry::ScreenPx; use geometry::ScreenPx;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::{Size2D, TypedSize2D};
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use getopts; use getopts;
use num_cpus; use num_cpus;
@ -230,7 +230,7 @@ pub fn default_opts() -> Opts {
trace_layout: false, trace_layout: false,
devtools_port: None, devtools_port: None,
webdriver_port: None, webdriver_port: None,
initial_window_size: TypedSize2D(800, 600), initial_window_size: Size2D::typed(800, 600),
user_agent: None, user_agent: None,
dump_flow_tree: false, dump_flow_tree: false,
dump_display_list: false, dump_display_list: false,
@ -375,10 +375,10 @@ pub fn from_cmdline_args(args: &[String]) -> bool {
let initial_window_size = match opt_match.opt_str("resolution") { let initial_window_size = match opt_match.opt_str("resolution") {
Some(res_string) => { Some(res_string) => {
let res: Vec<u32> = res_string.split('x').map(|r| r.parse().unwrap()).collect(); let res: Vec<u32> = res_string.split('x').map(|r| r.parse().unwrap()).collect();
TypedSize2D(res[0], res[1]) Size2D::typed(res[0], res[1])
} }
None => { None => {
TypedSize2D(800, 600) Size2D::typed(800, 600)
} }
}; };

6
ports/cef/Cargo.lock generated
View file

@ -384,7 +384,7 @@ dependencies = [
[[package]] [[package]]
name = "geom" name = "geom"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-geom#1b49f8ce1c4e8ade720dd940d1964c657a96817f" source = "git+https://github.com/servo/rust-geom#16b91afc0b9b532f2fb56879069bc381f2143df1"
dependencies = [ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@ -616,7 +616,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "layers" name = "layers"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ca37ca2949c46f91e37f28fa31ad6c1e8036f2d0" source = "git+https://github.com/servo/rust-layers#e566d3fc6ec80fe3aaf8ce67785683c99c46a015"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
@ -836,7 +836,7 @@ dependencies = [
[[package]] [[package]]
name = "offscreen_gl_context" name = "offscreen_gl_context"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#0fd217b95d806bdcb6d381cf092ca8776de273c8" source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#c402c86f8d4472785e04e59505feb28638101700"
dependencies = [ dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -11,8 +11,8 @@ use browser::{self, ServoCefBrowserExtensions};
use wrappers::CefWrap; use wrappers::CefWrap;
use compositing::windowing::{WindowEvent, MouseWindowEvent}; use compositing::windowing::{WindowEvent, MouseWindowEvent};
use geom::point::TypedPoint2D; use geom::point::Point2D;
use geom::size::TypedSize2D; use geom::size::Size2D;
use libc::{c_double, c_int}; use libc::{c_double, c_int};
use msg::constellation_msg::{self, KeyModifiers, KeyState}; use msg::constellation_msg::{self, KeyModifiers, KeyState};
use script_traits::MouseButton; use script_traits::MouseButton;
@ -385,7 +385,7 @@ full_cef_class_impl! {
.get_render_handler() .get_render_handler()
.get_view_rect(this.downcast().browser.borrow().clone().unwrap(), &mut rect); .get_view_rect(this.downcast().browser.borrow().clone().unwrap(), &mut rect);
} }
let size = TypedSize2D(rect.width as u32, rect.height as u32); let size = Size2D::typed(rect.width as u32, rect.height as u32);
this.downcast().send_window_event(WindowEvent::Resize(size)); this.downcast().send_window_event(WindowEvent::Resize(size));
}} }}
@ -443,7 +443,7 @@ full_cef_class_impl! {
cef_mouse_button_type_t::MBT_MIDDLE => MouseButton::Middle, cef_mouse_button_type_t::MBT_MIDDLE => MouseButton::Middle,
cef_mouse_button_type_t::MBT_RIGHT => MouseButton::Right, cef_mouse_button_type_t::MBT_RIGHT => MouseButton::Right,
}; };
let point = TypedPoint2D((*event).x as f32, (*event).y as f32); let point = Point2D::typed((*event).x as f32, (*event).y as f32);
if mouse_up != 0 { if mouse_up != 0 {
this.downcast().send_window_event(WindowEvent::MouseWindowEventClass( this.downcast().send_window_event(WindowEvent::MouseWindowEventClass(
MouseWindowEvent::Click(button_type, point))) MouseWindowEvent::Click(button_type, point)))
@ -457,7 +457,7 @@ full_cef_class_impl! {
_mouse_exited: c_int [c_int],) _mouse_exited: c_int [c_int],)
-> () {{ -> () {{
let event: &cef_mouse_event = event; let event: &cef_mouse_event = event;
let point = TypedPoint2D((*event).x as f32, (*event).y as f32); let point = Point2D::typed((*event).x as f32, (*event).y as f32);
this.downcast().send_window_event(WindowEvent::MouseWindowMoveEventClass(point)) this.downcast().send_window_event(WindowEvent::MouseWindowMoveEventClass(point))
}} }}
@ -469,8 +469,8 @@ full_cef_class_impl! {
let event: &cef_mouse_event = event; let event: &cef_mouse_event = event;
let delta_x: c_int = delta_x; let delta_x: c_int = delta_x;
let delta_y: c_int = delta_y; let delta_y: c_int = delta_y;
let delta = TypedPoint2D(delta_x as f32, delta_y as f32); let delta = Point2D::typed(delta_x as f32, delta_y as f32);
let origin = TypedPoint2D((*event).x as i32, (*event).y as i32); let origin = Point2D::typed((*event).x as i32, (*event).y as i32);
this.downcast().send_window_event(WindowEvent::Scroll(delta, origin)) this.downcast().send_window_event(WindowEvent::Scroll(delta, origin))
}} }}

View file

@ -18,7 +18,7 @@ use wrappers::CefWrap;
use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods}; use compositing::windowing::{WindowEvent, WindowMethods};
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::{Size2D, TypedSize2D};
use gleam::gl; use gleam::gl;
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata; use layers::platform::surface::NativeGraphicsMetadata;
@ -86,7 +86,7 @@ impl Window {
Rc::new(Window { Rc::new(Window {
cef_browser: RefCell::new(None), cef_browser: RefCell::new(None),
size: TypedSize2D(width, height) size: Size2D::typed(width, height)
}) })
} }
@ -199,7 +199,7 @@ impl WindowMethods for Window {
} }
} }
TypedSize2D(rect.width as u32, rect.height as u32) Size2D::typed(rect.width as u32, rect.height as u32)
} }
} }
} }
@ -208,14 +208,14 @@ impl WindowMethods for Window {
fn size(&self) -> TypedSize2D<ScreenPx,f32> { fn size(&self) -> TypedSize2D<ScreenPx,f32> {
let browser = self.cef_browser.borrow(); let browser = self.cef_browser.borrow();
match *browser { match *browser {
None => TypedSize2D(400.0, 300.0), None => Size2D::typed(400.0, 300.0),
Some(ref browser) => { Some(ref browser) => {
let mut rect = cef_rect_t::zero(); let mut rect = cef_rect_t::zero();
browser.get_host() browser.get_host()
.get_client() .get_client()
.get_render_handler() .get_render_handler()
.get_view_rect((*browser).clone(), &mut rect); .get_view_rect((*browser).clone(), &mut rect);
TypedSize2D(rect.width as f32, rect.height as f32) Size2D::typed(rect.width as f32, rect.height as f32)
} }
} }
} }

View file

@ -7,7 +7,7 @@
use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods}; use compositing::windowing::{WindowEvent, WindowMethods};
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::{Size2D, TypedSize2D};
use gleam::gl; use gleam::gl;
use glutin; use glutin;
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
@ -26,7 +26,7 @@ use NestedEventLoopListener;
#[cfg(feature = "window")] #[cfg(feature = "window")]
use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg}; use compositing::windowing::{MouseWindowEvent, WindowNavigateMsg};
#[cfg(feature = "window")] #[cfg(feature = "window")]
use geom::point::{Point2D, TypedPoint2D}; use geom::point::Point2D;
#[cfg(feature = "window")] #[cfg(feature = "window")]
use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode}; use glutin::{Api, ElementState, Event, GlRequest, MouseButton, VirtualKeyCode};
#[cfg(feature = "window")] #[cfg(feature = "window")]
@ -90,9 +90,9 @@ impl Window {
window: glutin_window, window: glutin_window,
event_queue: RefCell::new(vec!()), event_queue: RefCell::new(vec!()),
mouse_down_button: Cell::new(None), mouse_down_button: Cell::new(None),
mouse_down_point: Cell::new(Point2D(0, 0)), mouse_down_point: Cell::new(Point2D::new(0, 0)),
mouse_pos: Cell::new(Point2D(0, 0)), mouse_pos: Cell::new(Point2D::new(0, 0)),
key_modifiers: Cell::new(KeyModifiers::empty()), key_modifiers: Cell::new(KeyModifiers::empty()),
}; };
@ -113,7 +113,8 @@ impl Window {
match g_nested_event_loop_listener { match g_nested_event_loop_listener {
None => {} None => {}
Some(listener) => { Some(listener) => {
(*listener).handle_event_from_nested_event_loop(WindowEvent::Resize(TypedSize2D(width, height))); (*listener).handle_event_from_nested_event_loop(
WindowEvent::Resize(Size2D::typed(width, height)));
} }
} }
} }
@ -169,7 +170,7 @@ impl Window {
} }
} }
Event::Resized(width, height) => { Event::Resized(width, height) => {
self.event_queue.borrow_mut().push(WindowEvent::Resize(TypedSize2D(width, height))); self.event_queue.borrow_mut().push(WindowEvent::Resize(Size2D::typed(width, height)));
} }
Event::MouseInput(element_state, mouse_button) => { Event::MouseInput(element_state, mouse_button) => {
if mouse_button == MouseButton::Left || if mouse_button == MouseButton::Left ||
@ -179,9 +180,9 @@ impl Window {
} }
} }
Event::MouseMoved((x, y)) => { Event::MouseMoved((x, y)) => {
self.mouse_pos.set(Point2D(x, y)); self.mouse_pos.set(Point2D::new(x, y));
self.event_queue.borrow_mut().push( self.event_queue.borrow_mut().push(
WindowEvent::MouseWindowMoveEventClass(TypedPoint2D(x as f32, y as f32))); WindowEvent::MouseWindowMoveEventClass(Point2D::typed(x as f32, y as f32)));
} }
Event::MouseWheel(delta) => { Event::MouseWheel(delta) => {
if self.ctrl_pressed() { if self.ctrl_pressed() {
@ -220,8 +221,8 @@ impl Window {
/// Helper function to send a scroll event. /// Helper function to send a scroll event.
fn scroll_window(&self, dx: f32, dy: f32) { fn scroll_window(&self, dx: f32, dy: f32) {
let mouse_pos = self.mouse_pos.get(); let mouse_pos = self.mouse_pos.get();
let event = WindowEvent::Scroll(TypedPoint2D(dx as f32, dy as f32), let event = WindowEvent::Scroll(Point2D::typed(dx as f32, dy as f32),
TypedPoint2D(mouse_pos.x as i32, mouse_pos.y as i32)); Point2D::typed(mouse_pos.x as i32, mouse_pos.y as i32));
self.event_queue.borrow_mut().push(event); self.event_queue.borrow_mut().push(event);
} }
@ -233,21 +234,21 @@ impl Window {
let max_pixel_dist = 10f64; let max_pixel_dist = 10f64;
let event = match action { let event = match action {
ElementState::Pressed => { ElementState::Pressed => {
self.mouse_down_point.set(Point2D(x, y)); self.mouse_down_point.set(Point2D::new(x, y));
self.mouse_down_button.set(Some(button)); self.mouse_down_button.set(Some(button));
MouseWindowEvent::MouseDown(MouseButton::Left, TypedPoint2D(x as f32, y as f32)) MouseWindowEvent::MouseDown(MouseButton::Left, Point2D::typed(x as f32, y as f32))
} }
ElementState::Released => { ElementState::Released => {
let mouse_up_event = MouseWindowEvent::MouseUp(MouseButton::Left, TypedPoint2D(x as f32, y as f32)); let mouse_up_event = MouseWindowEvent::MouseUp(MouseButton::Left, Point2D::typed(x as f32, y as f32));
match self.mouse_down_button.get() { match self.mouse_down_button.get() {
None => mouse_up_event, None => mouse_up_event,
Some(but) if button == but => { Some(but) if button == but => {
let pixel_dist = self.mouse_down_point.get() - Point2D(x, y); let pixel_dist = self.mouse_down_point.get() - Point2D::new(x, y);
let pixel_dist = ((pixel_dist.x * pixel_dist.x + let pixel_dist = ((pixel_dist.x * pixel_dist.x +
pixel_dist.y * pixel_dist.y) as f64).sqrt(); pixel_dist.y * pixel_dist.y) as f64).sqrt();
if pixel_dist < max_pixel_dist { if pixel_dist < max_pixel_dist {
self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(mouse_up_event)); self.event_queue.borrow_mut().push(WindowEvent::MouseWindowEventClass(mouse_up_event));
MouseWindowEvent::Click(MouseButton::Left, TypedPoint2D(x as f32, y as f32)) MouseWindowEvent::Click(MouseButton::Left, Point2D::typed(x as f32, y as f32))
} else { } else {
mouse_up_event mouse_up_event
} }
@ -462,12 +463,12 @@ impl WindowMethods for Window {
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> { fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> {
let scale_factor = self.window.hidpi_factor() as u32; let scale_factor = self.window.hidpi_factor() as u32;
let (width, height) = self.window.get_inner_size().unwrap(); let (width, height) = self.window.get_inner_size().unwrap();
TypedSize2D(width * scale_factor, height * scale_factor) Size2D::typed(width * scale_factor, height * scale_factor)
} }
fn size(&self) -> TypedSize2D<ScreenPx, f32> { fn size(&self) -> TypedSize2D<ScreenPx, f32> {
let (width, height) = self.window.get_inner_size().unwrap(); let (width, height) = self.window.get_inner_size().unwrap();
TypedSize2D(width as f32, height as f32) Size2D::typed(width as f32, height as f32)
} }
fn present(&self) { fn present(&self) {
@ -672,11 +673,11 @@ impl Window {
#[cfg(feature = "headless")] #[cfg(feature = "headless")]
impl WindowMethods for Window { impl WindowMethods for Window {
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> { fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> {
TypedSize2D(self.width, self.height) Size2D::typed(self.width, self.height)
} }
fn size(&self) -> TypedSize2D<ScreenPx, f32> { fn size(&self) -> TypedSize2D<ScreenPx, f32> {
TypedSize2D(self.width as f32, self.height as f32) Size2D::typed(self.width as f32, self.height as f32)
} }
fn present(&self) { fn present(&self) {

6
ports/gonk/Cargo.lock generated
View file

@ -363,7 +363,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "geom" name = "geom"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-geom#1b49f8ce1c4e8ade720dd940d1964c657a96817f" source = "git+https://github.com/servo/rust-geom#16b91afc0b9b532f2fb56879069bc381f2143df1"
dependencies = [ dependencies = [
"log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "num 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
@ -550,7 +550,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]] [[package]]
name = "layers" name = "layers"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/servo/rust-layers#ca37ca2949c46f91e37f28fa31ad6c1e8036f2d0" source = "git+https://github.com/servo/rust-layers#e566d3fc6ec80fe3aaf8ce67785683c99c46a015"
dependencies = [ dependencies = [
"azure 0.1.0 (git+https://github.com/servo/rust-azure)", "azure 0.1.0 (git+https://github.com/servo/rust-azure)",
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
@ -753,7 +753,7 @@ dependencies = [
[[package]] [[package]]
name = "offscreen_gl_context" name = "offscreen_gl_context"
version = "0.0.1" version = "0.0.1"
source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#0fd217b95d806bdcb6d381cf092ca8776de273c8" source = "git+https://github.com/ecoal95/rust-offscreen-rendering-context#c402c86f8d4472785e04e59505feb28638101700"
dependencies = [ dependencies = [
"cgl 0.0.1 (git+https://github.com/servo/cgl-rs)", "cgl 0.0.1 (git+https://github.com/servo/cgl-rs)",
"core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",

View file

@ -14,7 +14,7 @@ use std::thread;
use std::sync::mpsc::Sender; use std::sync::mpsc::Sender;
use std::io::Read; use std::io::Read;
use geom::point::TypedPoint2D; use geom::point::Point2D;
use errno::errno; use errno::errno;
use libc::c_int; use libc::c_int;
@ -167,7 +167,7 @@ fn read_input_device(device_path: &Path,
let delta_y = slotA.y - first_y; let delta_y = slotA.y - first_y;
let dist = delta_x * delta_x + delta_y * delta_y; let dist = delta_x * delta_x + delta_y * delta_y;
if dist < 16 { if dist < 16 {
let click_pt = TypedPoint2D(slotA.x as f32, slotA.y as f32); let click_pt = Point2D::typed(slotA.x as f32, slotA.y as f32);
println!("Dispatching click!"); println!("Dispatching click!");
sender.send( sender.send(
WindowEvent::MouseWindowEventClass( WindowEvent::MouseWindowEventClass(
@ -193,8 +193,8 @@ fn read_input_device(device_path: &Path,
} else { } else {
println!("Touch move x: {}, y: {}", slotA.x, slotA.y); println!("Touch move x: {}, y: {}", slotA.x, slotA.y);
sender.send( sender.send(
WindowEvent::Scroll(TypedPoint2D((slotA.x - last_x) as f32, (slotA.y - last_y) as f32), WindowEvent::Scroll(Point2D::typed((slotA.x - last_x) as f32, (slotA.y - last_y) as f32),
TypedPoint2D(slotA.x, slotA.y))).ok().unwrap(); Point2D::typed(slotA.x, slotA.y))).ok().unwrap();
last_x = slotA.x; last_x = slotA.x;
last_y = slotA.y; last_y = slotA.y;
if touch_count >= 2 { if touch_count >= 2 {

View file

@ -7,7 +7,7 @@
use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver}; use compositing::compositor_task::{self, CompositorProxy, CompositorReceiver};
use compositing::windowing::{WindowEvent, WindowMethods}; use compositing::windowing::{WindowEvent, WindowMethods};
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use geom::size::TypedSize2D; use geom::size::{Size2D, TypedSize2D};
use layers::geometry::DevicePixel; use layers::geometry::DevicePixel;
use layers::platform::surface::NativeGraphicsMetadata; use layers::platform::surface::NativeGraphicsMetadata;
use libc::c_int; use libc::c_int;
@ -784,12 +784,12 @@ impl Drop for Window {
impl WindowMethods for Window { impl WindowMethods for Window {
/// Returns the size of the window in hardware pixels. /// Returns the size of the window in hardware pixels.
fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> { fn framebuffer_size(&self) -> TypedSize2D<DevicePixel, u32> {
TypedSize2D(self.width as u32, self.height as u32) Size2D::typed(self.width as u32, self.height as u32)
} }
/// Returns the size of the window in density-independent "px" units. /// Returns the size of the window in density-independent "px" units.
fn size(&self) -> TypedSize2D<ScreenPx, f32> { fn size(&self) -> TypedSize2D<ScreenPx, f32> {
TypedSize2D(self.width as f32, self.height as f32) Size2D::typed(self.width as f32, self.height as f32)
} }
/// Presents the window to the screen (perhaps by page flipping). /// Presents the window to the screen (perhaps by page flipping).

View file

@ -2,7 +2,7 @@
* 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/. */
use geom::size::TypedSize2D; use geom::size::Size2D;
use style::stylesheets::{Stylesheet, CSSRuleIteratorExt}; use style::stylesheets::{Stylesheet, CSSRuleIteratorExt};
use style::stylesheets::Origin; use style::stylesheets::Origin;
use style::media_queries::*; use style::media_queries::*;
@ -349,7 +349,7 @@ fn test_mq_malformed_expressions() {
fn test_matching_simple() { fn test_matching_simple() {
let device = Device { let device = Device {
media_type: MediaType::Screen, media_type: MediaType::Screen,
viewport_size: TypedSize2D(200.0, 100.0), viewport_size: Size2D::typed(200.0, 100.0),
}; };
media_query_test(&device, "@media not all { a { color: red; } }", 0); media_query_test(&device, "@media not all { a { color: red; } }", 0);
@ -368,7 +368,7 @@ fn test_matching_simple() {
fn test_matching_width() { fn test_matching_width() {
let device = Device { let device = Device {
media_type: MediaType::Screen, media_type: MediaType::Screen,
viewport_size: TypedSize2D(200.0, 100.0), viewport_size: Size2D::typed(200.0, 100.0),
}; };
media_query_test(&device, "@media { a { color: red; } }", 1); media_query_test(&device, "@media { a { color: red; } }", 1);
@ -412,7 +412,7 @@ fn test_matching_width() {
fn test_matching_invalid() { fn test_matching_invalid() {
let device = Device { let device = Device {
media_type: MediaType::Screen, media_type: MediaType::Screen,
viewport_size: TypedSize2D(200.0, 100.0), viewport_size: Size2D::typed(200.0, 100.0),
}; };
media_query_test(&device, "@media fridge { a { color: red; } }", 0); media_query_test(&device, "@media fridge { a { color: red; } }", 0);

View file

@ -3,7 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
use cssparser::Parser; use cssparser::Parser;
use geom::size::TypedSize2D; use geom::size::Size2D;
use geom::scale_factor::ScaleFactor; use geom::scale_factor::ScaleFactor;
use style::media_queries::{Device, MediaType}; use style::media_queries::{Device, MediaType};
use style::parser::ParserContext; use style::parser::ParserContext;
@ -51,7 +51,7 @@ macro_rules! assert_decl_len {
#[test] #[test]
fn empty_viewport_rule() { fn empty_viewport_rule() {
let device = Device::new(MediaType::Screen, TypedSize2D(800., 600.)); let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
test_viewport_rule("@viewport {}", &device, |declarations, css| { test_viewport_rule("@viewport {}", &device, |declarations, css| {
println!("{}", css); println!("{}", css);
@ -74,7 +74,7 @@ macro_rules! assert_decl_eq {
#[test] #[test]
fn simple_viewport_rules() { fn simple_viewport_rules() {
let device = Device::new(MediaType::Screen, TypedSize2D(800., 600.)); let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
test_viewport_rule("@viewport { width: auto; height: auto;\ test_viewport_rule("@viewport { width: auto; height: auto;\
zoom: auto; min-zoom: 0; max-zoom: 200%;\ zoom: auto; min-zoom: 0; max-zoom: 200%;\
@ -107,7 +107,7 @@ fn simple_viewport_rules() {
#[test] #[test]
fn cascading_within_viewport_rule() { fn cascading_within_viewport_rule() {
let device = Device::new(MediaType::Screen, TypedSize2D(800., 600.)); let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
// normal order of appearance // normal order of appearance
test_viewport_rule("@viewport { min-width: 200px; min-width: auto; }", test_viewport_rule("@viewport { min-width: 200px; min-width: auto; }",
@ -172,7 +172,7 @@ fn cascading_within_viewport_rule() {
#[test] #[test]
fn multiple_stylesheets_cascading() { fn multiple_stylesheets_cascading() {
let device = Device::new(MediaType::Screen, TypedSize2D(800., 600.)); let device = Device::new(MediaType::Screen, Size2D::typed(800., 600.));
let stylesheets = vec![ let stylesheets = vec![
stylesheet!("@viewport { min-width: 100px; min-height: 100px; zoom: 1; }", UserAgent), stylesheet!("@viewport { min-width: 100px; min-height: 100px; zoom: 1; }", UserAgent),
@ -217,11 +217,11 @@ fn constrain_viewport() {
} }
} }
let initial_viewport = TypedSize2D(800., 600.); let initial_viewport = Size2D::typed(800., 600.);
assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("")), assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("")),
None); None);
let initial_viewport = TypedSize2D(800., 600.); let initial_viewport = Size2D::typed(800., 600.);
assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")),
Some(ViewportConstraints { Some(ViewportConstraints {
size: initial_viewport, size: initial_viewport,
@ -234,10 +234,10 @@ fn constrain_viewport() {
orientation: Orientation::Auto orientation: Orientation::Auto
})); }));
let initial_viewport = TypedSize2D(200., 150.); let initial_viewport = Size2D::typed(200., 150.);
assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")),
Some(ViewportConstraints { Some(ViewportConstraints {
size: TypedSize2D(320., 240.), size: Size2D::typed(320., 240.),
initial_zoom: ScaleFactor::new(1.), initial_zoom: ScaleFactor::new(1.),
min_zoom: None, min_zoom: None,
@ -247,7 +247,7 @@ fn constrain_viewport() {
orientation: Orientation::Auto orientation: Orientation::Auto
})); }));
let initial_viewport = TypedSize2D(800., 600.); let initial_viewport = Size2D::typed(800., 600.);
assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")), assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 320px auto")),
Some(ViewportConstraints { Some(ViewportConstraints {
size: initial_viewport, size: initial_viewport,
@ -260,7 +260,7 @@ fn constrain_viewport() {
orientation: Orientation::Auto orientation: Orientation::Auto
})); }));
let initial_viewport = TypedSize2D(800., 600.); let initial_viewport = Size2D::typed(800., 600.);
assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 800px; height: 600px;\ assert_eq!(ViewportConstraints::maybe_new(initial_viewport, from_css!("width: 800px; height: 600px;\
zoom: 1;\ zoom: 1;\
user-zoom: zoom;\ user-zoom: zoom;\

View file

@ -24,7 +24,7 @@ fn modes() -> [WritingMode; 10] {
#[test] #[test]
fn test_size_round_trip() { fn test_size_round_trip() {
let physical = Size2D(1u32, 2u32); let physical = Size2D::new(1u32, 2u32);
for &mode in modes().iter() { for &mode in modes().iter() {
let logical = LogicalSize::from_physical(mode, physical); let logical = LogicalSize::from_physical(mode, physical);
assert!(logical.to_physical(mode) == physical); assert!(logical.to_physical(mode) == physical);
@ -35,8 +35,8 @@ fn test_size_round_trip() {
#[test] #[test]
fn test_point_round_trip() { fn test_point_round_trip() {
let physical = Point2D(1u32, 2u32); let physical = Point2D::new(1u32, 2u32);
let container = Size2D(100, 200); let container = Size2D::new(100, 200);
for &mode in modes().iter() { for &mode in modes().iter() {
let logical = LogicalPoint::from_physical(mode, physical, container); let logical = LogicalPoint::from_physical(mode, physical, container);
assert!(logical.to_physical(mode, container) == physical); assert!(logical.to_physical(mode, container) == physical);
@ -60,8 +60,8 @@ fn test_margin_round_trip() {
#[test] #[test]
fn test_rect_round_trip() { fn test_rect_round_trip() {
let physical = Rect(Point2D(1u32, 2u32), Size2D(3u32, 4u32)); let physical = Rect::new(Point2D::new(1u32, 2u32), Size2D::new(3u32, 4u32));
let container = Size2D(100, 200); let container = Size2D::new(100, 200);
for &mode in modes().iter() { for &mode in modes().iter() {
let logical = LogicalRect::from_physical(mode, physical, container); let logical = LogicalRect::from_physical(mode, physical, container);
assert!(logical.to_physical(mode, container) == physical); assert!(logical.to_physical(mode, container) == physical);