mirror of
https://github.com/servo/servo.git
synced 2025-08-05 13:40:08 +01:00
Use Finite<T> for our dom code (excluding CanvasRenderingContext2D)
This commit is contained in:
parent
4c96732077
commit
9cd1b2c158
4 changed files with 24 additions and 17 deletions
|
@ -87,7 +87,9 @@ pub fn handle_get_layout(page: &Rc<Page>, pipeline: PipelineId, node_id: String,
|
|||
let node = find_node_by_unique_id(&*page, pipeline, node_id).root();
|
||||
let elem: JSRef<Element> = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
|
||||
let rect = elem.GetBoundingClientRect().root();
|
||||
reply.send((rect.r().Width(), rect.r().Height())).unwrap();
|
||||
let width = *rect.r().Width();
|
||||
let height = *rect.r().Height();
|
||||
reply.send((width, height)).unwrap();
|
||||
}
|
||||
|
||||
pub fn handle_modify_attribute(page: &Rc<Page>, pipeline: PipelineId, node_id: String, modifications: Vec<Modification>) {
|
||||
|
|
|
@ -259,7 +259,7 @@ impl FromJSValConvertible for f32 {
|
|||
|
||||
impl ToJSValConvertible for Finite<f32> {
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = self.clone().unwrap();
|
||||
let value = **self;
|
||||
value.to_jsval(cx)
|
||||
}
|
||||
}
|
||||
|
@ -293,7 +293,7 @@ impl FromJSValConvertible for f64 {
|
|||
impl ToJSValConvertible for Finite<f64> {
|
||||
#[inline]
|
||||
fn to_jsval(&self, cx: *mut JSContext) -> JSVal {
|
||||
let value = self.clone().unwrap();
|
||||
let value = **self;
|
||||
value.to_jsval(cx)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ use dom::bindings::codegen::Bindings::DOMRectBinding;
|
|||
use dom::bindings::codegen::Bindings::DOMRectBinding::DOMRectMethods;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JSRef, Temporary};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::window::Window;
|
||||
use util::geometry::Au;
|
||||
|
@ -41,28 +42,30 @@ impl DOMRect {
|
|||
}
|
||||
|
||||
impl<'a> DOMRectMethods for JSRef<'a, DOMRect> {
|
||||
fn Top(self) -> f32 {
|
||||
self.top
|
||||
fn Top(self) -> Finite<f32> {
|
||||
Finite::wrap(self.top)
|
||||
}
|
||||
|
||||
fn Bottom(self) -> f32 {
|
||||
self.bottom
|
||||
fn Bottom(self) -> Finite<f32> {
|
||||
Finite::wrap(self.bottom)
|
||||
}
|
||||
|
||||
fn Left(self) -> f32 {
|
||||
self.left
|
||||
fn Left(self) -> Finite<f32> {
|
||||
Finite::wrap(self.left)
|
||||
}
|
||||
|
||||
fn Right(self) -> f32 {
|
||||
self.right
|
||||
fn Right(self) -> Finite<f32> {
|
||||
Finite::wrap(self.right)
|
||||
}
|
||||
|
||||
fn Width(self) -> f32 {
|
||||
(self.right - self.left).abs()
|
||||
fn Width(self) -> Finite<f32> {
|
||||
let result = (self.right - self.left).abs();
|
||||
Finite::wrap(result)
|
||||
}
|
||||
|
||||
fn Height(self) -> f32 {
|
||||
(self.bottom - self.top).abs()
|
||||
fn Height(self) -> Finite<f32> {
|
||||
let result = (self.bottom - self.top).abs();
|
||||
Finite::wrap(result)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,12 +6,13 @@ use dom::bindings::codegen::Bindings::PerformanceBinding;
|
|||
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
|
||||
use dom::bindings::global::GlobalRef;
|
||||
use dom::bindings::js::{JS, JSRef, Temporary};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::utils::{Reflector, reflect_dom_object};
|
||||
use dom::performancetiming::{PerformanceTiming, PerformanceTimingHelpers};
|
||||
use dom::window::Window;
|
||||
use time;
|
||||
|
||||
pub type DOMHighResTimeStamp = f64;
|
||||
pub type DOMHighResTimeStamp = Finite<f64>;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct Performance {
|
||||
|
@ -50,7 +51,8 @@ impl<'a> PerformanceMethods for JSRef<'a, Performance> {
|
|||
// https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/HighResolutionTime/Overview.html#dom-performance-now
|
||||
fn Now(self) -> DOMHighResTimeStamp {
|
||||
let navStart = self.timing.root().r().NavigationStartPrecise();
|
||||
(time::precise_time_ns() as f64 - navStart) * 1000000u as DOMHighResTimeStamp
|
||||
let now = (time::precise_time_ns() as f64 - navStart) * 1000000u as f64;
|
||||
Finite::wrap(now)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue