mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Implement Window.screen.
This commit is contained in:
parent
800b5e0f4a
commit
27f92239b0
6 changed files with 112 additions and 1 deletions
51
src/components/script/dom/screen.rs
Normal file
51
src/components/script/dom/screen.rs
Normal file
|
@ -0,0 +1,51 @@
|
|||
/* 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;
|
||||
|
||||
use serialize::{Encoder, Encodable};
|
||||
|
||||
#[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_
|
||||
}
|
||||
}
|
14
src/components/script/dom/webidls/Screen.webidl
Normal file
14
src/components/script/dom/webidls/Screen.webidl
Normal file
|
@ -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;
|
||||
};
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
@ -86,6 +87,7 @@ pub struct Window {
|
|||
performance: Cell<Option<JS<Performance>>>,
|
||||
pub navigationStart: u64,
|
||||
pub navigationStartPrecise: f64,
|
||||
screen: Cell<Option<JS<Screen>>>,
|
||||
}
|
||||
|
||||
impl Window {
|
||||
|
@ -142,6 +144,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 +268,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 +444,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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -151,6 +151,7 @@ var interfaceNamesInGlobalScope = [
|
|||
"PerformanceTiming",
|
||||
"ProcessingInstruction",
|
||||
"ProgressEvent",
|
||||
"Screen",
|
||||
"TestBinding", // XXX
|
||||
"Text",
|
||||
"UIEvent",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue