aboutsummaryrefslogtreecommitdiffstats
path: root/components/geometry
diff options
context:
space:
mode:
authorAlan Jeffrey <ajeffrey@mozilla.com>2016-12-14 10:37:58 -0600
committerAlan Jeffrey <ajeffrey@mozilla.com>2016-12-14 18:04:37 -0600
commit9be4fd56ce5467ce6d0e48c6efda9eb26f40eb7a (patch)
tree93d46ce512414914439920505f41467ffbc17e95 /components/geometry
parent01b6ad55bd435bc4f58e5eab2e8adb7e4febb50a (diff)
downloadservo-9be4fd56ce5467ce6d0e48c6efda9eb26f40eb7a.tar.gz
servo-9be4fd56ce5467ce6d0e48c6efda9eb26f40eb7a.zip
Removed util.
Diffstat (limited to 'components/geometry')
-rw-r--r--components/geometry/Cargo.toml19
-rw-r--r--components/geometry/lib.rs54
2 files changed, 73 insertions, 0 deletions
diff --git a/components/geometry/Cargo.toml b/components/geometry/Cargo.toml
new file mode 100644
index 00000000000..28480439060
--- /dev/null
+++ b/components/geometry/Cargo.toml
@@ -0,0 +1,19 @@
+[package]
+name = "servo_geometry"
+version = "0.0.1"
+authors = ["The Servo Project Developers"]
+license = "MPL-2.0"
+publish = false
+
+[lib]
+name = "servo_geometry"
+path = "lib.rs"
+
+[features]
+# servo as opposed to geckolib
+servo = ["app_units/plugins", "euclid/unstable"]
+
+[dependencies]
+app_units = "0.3"
+euclid = "0.10.1"
+heapsize = "0.3.0"
diff --git a/components/geometry/lib.rs b/components/geometry/lib.rs
new file mode 100644
index 00000000000..52fcd420c0e
--- /dev/null
+++ b/components/geometry/lib.rs
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+extern crate app_units;
+#[macro_use] extern crate euclid;
+#[macro_use] extern crate heapsize;
+
+use app_units::{Au, MAX_AU};
+use euclid::point::Point2D;
+use euclid::rect::Rect;
+use euclid::size::Size2D;
+use std::i32;
+
+// Units for use with euclid::length and euclid::scale_factor.
+
+/// A normalized "pixel" at the default resolution for the display.
+///
+/// Like the CSS "px" unit, the exact physical size of this unit may vary between devices, but it
+/// should approximate a device-independent reference length. This unit corresponds to Android's
+/// "density-independent pixel" (dip), Mac OS X's "point", and Windows "device-independent pixel."
+///
+/// The relationship between DevicePixel and ScreenPx is defined by the OS. On most low-dpi
+/// screens, one ScreenPx is equal to one DevicePixel. But on high-density screens it can be
+/// some larger number. For example, by default on Apple "retina" displays, one ScreenPx equals
+/// two DevicePixels. On Android "MDPI" displays, one ScreenPx equals 1.5 device pixels.
+///
+/// The ratio between ScreenPx and DevicePixel for a given display be found by calling
+/// `servo::windowing::WindowMethods::hidpi_factor`.
+#[derive(Clone, Copy, Debug)]
+pub enum ScreenPx {}
+
+known_heap_size!(0, ScreenPx);
+
+// An Au is an "App Unit" and represents 1/60th of a CSS pixel. It was
+// originally proposed in 2002 as a standard unit of measure in Gecko.
+// See https://bugzilla.mozilla.org/show_bug.cgi?id=177805 for more info.
+
+#[inline(always)]
+pub fn max_rect() -> Rect<Au> {
+ Rect::new(Point2D::new(Au(i32::MIN / 2), Au(i32::MIN / 2)), Size2D::new(MAX_AU, MAX_AU))
+}
+
+/// 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> {
+ Rect::new(Point2D::new(Au::from_f32_px(rect.origin.x), Au::from_f32_px(rect.origin.y)),
+ Size2D::new(Au::from_f32_px(rect.size.width), Au::from_f32_px(rect.size.height)))
+}
+
+/// A helper function to convert a rect of `Au` pixels to a rect of f32 units.
+pub fn au_rect_to_f32_rect(rect: Rect<Au>) -> Rect<f32> {
+ Rect::new(Point2D::new(rect.origin.x.to_f32_px(), rect.origin.y.to_f32_px()),
+ Size2D::new(rect.size.width.to_f32_px(), rect.size.height.to_f32_px()))
+}