diff options
-rw-r--r-- | src/components/script/dom/location.rs | 1 | ||||
-rw-r--r-- | src/components/script/dom/screen.rs | 49 | ||||
-rw-r--r-- | src/components/script/dom/uievent.rs | 1 | ||||
-rw-r--r-- | src/components/script/dom/webidls/Screen.webidl | 14 | ||||
-rw-r--r-- | src/components/script/dom/webidls/Window.webidl | 32 | ||||
-rw-r--r-- | src/components/script/dom/window.rs | 19 | ||||
-rw-r--r-- | src/components/script/script.rs | 1 | ||||
-rw-r--r-- | src/test/content/test_interfaces.html | 1 |
8 files changed, 111 insertions, 7 deletions
diff --git a/src/components/script/dom/location.rs b/src/components/script/dom/location.rs index a622f1aac1f..4427fb32e40 100644 --- a/src/components/script/dom/location.rs +++ b/src/components/script/dom/location.rs @@ -11,7 +11,6 @@ use page::Page; use servo_util::str::DOMString; -use serialize::{Encoder, Encodable}; use std::rc::Rc; #[deriving(Encodable)] diff --git a/src/components/script/dom/screen.rs b/src/components/script/dom/screen.rs new file mode 100644 index 00000000000..34eb8f55461 --- /dev/null +++ b/src/components/script/dom/screen.rs @@ -0,0 +1,49 @@ +/* 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/. */ + +use dom::bindings::codegen::Bindings::ScreenBinding; +use dom::bindings::global::Window; +use dom::bindings::js::{JSRef, Temporary}; +use dom::bindings::utils::{Reflectable, Reflector, reflect_dom_object}; +use dom::window::Window; + +#[deriving(Encodable)] +pub struct Screen { + reflector_: Reflector, +} + +impl Screen { + pub fn new_inherited() -> Screen { + Screen { + reflector_: Reflector::new(), + } + } + + pub fn new(window: &JSRef<Window>) -> Temporary<Screen> { + reflect_dom_object(box Screen::new_inherited(), + &Window(*window), + ScreenBinding::Wrap) + } +} + +pub trait ScreenMethods { + fn ColorDepth(&self) -> u32; + fn PixelDepth(&self) -> u32; +} + +impl<'a> ScreenMethods for JSRef<'a, Screen> { + fn ColorDepth(&self) -> u32 { + 24 + } + + fn PixelDepth(&self) -> u32 { + 24 + } +} + +impl Reflectable for Screen { + fn reflector<'a>(&'a self) -> &'a Reflector { + &self.reflector_ + } +} diff --git a/src/components/script/dom/uievent.rs b/src/components/script/dom/uievent.rs index 026e6045747..0718d60fe68 100644 --- a/src/components/script/dom/uievent.rs +++ b/src/components/script/dom/uievent.rs @@ -13,7 +13,6 @@ use dom::event::{Event, EventMethods, EventTypeId, UIEventTypeId}; use dom::window::Window; use servo_util::str::DOMString; -use serialize::{Encoder, Encodable}; use std::cell::Cell; #[deriving(Encodable)] diff --git a/src/components/script/dom/webidls/Screen.webidl b/src/components/script/dom/webidls/Screen.webidl new file mode 100644 index 00000000000..3065c113b96 --- /dev/null +++ b/src/components/script/dom/webidls/Screen.webidl @@ -0,0 +1,14 @@ +/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* 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/. */ + +// http://dev.w3.org/csswg/cssom-view/#the-screen-interface +interface Screen { + //readonly attribute double availWidth; + //readonly attribute double availHeight; + //readonly attribute double width; + //readonly attribute double height; + readonly attribute unsigned long colorDepth; + readonly attribute unsigned long pixelDepth; +}; diff --git a/src/components/script/dom/webidls/Window.webidl b/src/components/script/dom/webidls/Window.webidl index a5b001d81b0..d96083a8aa8 100644 --- a/src/components/script/dom/webidls/Window.webidl +++ b/src/components/script/dom/webidls/Window.webidl @@ -78,6 +78,38 @@ partial interface Window { /*[Replaceable]*/ readonly attribute Performance performance; }; +// http://dev.w3.org/csswg/cssom-view/#extensions-to-the-window-interface +partial interface Window { + //MediaQueryList matchMedia(DOMString query); + [SameObject] readonly attribute Screen screen; + + // browsing context + //void moveTo(double x, double y); + //void moveBy(double x, double y); + //void resizeTo(double x, double y); + //void resizeBy(double x, double y); + + // viewport + //readonly attribute double innerWidth; + //readonly attribute double innerHeight; + + // viewport scrolling + //readonly attribute double scrollX; + //readonly attribute double pageXOffset; + //readonly attribute double scrollY; + //readonly attribute double pageYOffset; + //void scroll(double x, double y, optional ScrollOptions options); + //void scrollTo(double x, double y, optional ScrollOptions options); + //void scrollBy(double x, double y, optional ScrollOptions options); + + // client + //readonly attribute double screenX; + //readonly attribute double screenY; + //readonly attribute double outerWidth; + //readonly attribute double outerHeight; + //readonly attribute double devicePixelRatio; +}; + // Proprietary extensions. partial interface Window { readonly attribute Console console; diff --git a/src/components/script/dom/window.rs b/src/components/script/dom/window.rs index ee1cce1a22e..e5f867c436b 100644 --- a/src/components/script/dom/window.rs +++ b/src/components/script/dom/window.rs @@ -16,10 +16,11 @@ use dom::eventtarget::{EventTarget, WindowTypeId, EventTargetHelpers}; use dom::location::Location; use dom::navigator::Navigator; use dom::performance::Performance; - +use dom::screen::Screen; use layout_interface::{ReflowForDisplay, DocumentDamageLevel}; use page::Page; use script_task::{ExitWindowMsg, FireTimerMsg, ScriptChan, TriggerLoadMsg, TriggerFragmentMsg}; + use servo_msg::compositor_msg::ScriptListener; use servo_net::image_cache_task::ImageCacheTask; use servo_util::str::DOMString; @@ -31,6 +32,7 @@ use js::jsapi::{JS_GC, JS_GetRuntime}; use js::jsval::JSVal; use js::jsval::NullValue; use js::rust::with_compartment; +use url::{Url, UrlParser}; use std::collections::hashmap::HashMap; use std::cell::{Cell, RefCell}; @@ -41,12 +43,8 @@ use std::hash::{Hash, sip}; use std::io::timer::Timer; use std::ptr; use std::rc::Rc; - use time; -use serialize::{Encoder, Encodable}; -use url::{Url, UrlParser}; - #[deriving(PartialEq, Encodable, Eq)] pub struct TimerId(i32); @@ -86,6 +84,7 @@ pub struct Window { performance: Cell<Option<JS<Performance>>>, pub navigationStart: u64, pub navigationStartPrecise: f64, + screen: Cell<Option<JS<Screen>>>, } impl Window { @@ -142,6 +141,7 @@ pub trait WindowMethods { fn SetOnunload(&self, listener: Option<EventHandlerNonNull>); fn GetOnerror(&self) -> Option<OnErrorEventHandlerNonNull>; fn SetOnerror(&self, listener: Option<OnErrorEventHandlerNonNull>); + fn Screen(&self) -> Temporary<Screen>; fn Debug(&self, message: DOMString); fn Gc(&self); } @@ -265,6 +265,14 @@ impl<'a> WindowMethods for JSRef<'a, Window> { eventtarget.set_event_handler_common("error", listener) } + fn Screen(&self) -> Temporary<Screen> { + if self.screen.get().is_none() { + let screen = Screen::new(self); + self.screen.assign(Some(screen)); + } + Temporary::new(self.screen.get().get_ref().clone()) + } + fn Debug(&self, message: DOMString) { debug!("{:s}", message); } @@ -433,6 +441,7 @@ impl Window { performance: Cell::new(None), navigationStart: time::get_time().sec as u64, navigationStartPrecise: time::precise_time_s(), + screen: Cell::new(None), }; WindowBinding::Wrap(cx, win) diff --git a/src/components/script/script.rs b/src/components/script/script.rs index 9e852930744..9354ccaab15 100644 --- a/src/components/script/script.rs +++ b/src/components/script/script.rs @@ -170,6 +170,7 @@ pub mod dom { pub mod performance; pub mod performancetiming; pub mod progressevent; + pub mod screen; pub mod text; pub mod uievent; pub mod urlsearchparams; diff --git a/src/test/content/test_interfaces.html b/src/test/content/test_interfaces.html index c26c9322278..dd64d84bb84 100644 --- a/src/test/content/test_interfaces.html +++ b/src/test/content/test_interfaces.html @@ -151,6 +151,7 @@ var interfaceNamesInGlobalScope = [ "PerformanceTiming", "ProcessingInstruction", "ProgressEvent", + "Screen", "TestBinding", // XXX "Text", "UIEvent", |