зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #2914 - Implement Window.screen; r=jdm (from Ms2ger:screen)
Source-Repo: https://github.com/servo/servo Source-Revision: 88027a95fddcef142f6b2600cf888b16b9557a77
This commit is contained in:
Родитель
cde33d1aab
Коммит
581314623b
|
@ -11,7 +11,6 @@ use page::Page;
|
|||
|
||||
use servo_util::str::DOMString;
|
||||
|
||||
use serialize::{Encoder, Encodable};
|
||||
use std::rc::Rc;
|
||||
|
||||
#[deriving(Encodable)]
|
||||
|
|
|
@ -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_
|
||||
}
|
||||
}
|
|
@ -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)]
|
||||
|
|
|
@ -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;
|
||||
|
@ -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)
|
||||
|
|
|
@ -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",
|
||||
|
|
Загрузка…
Ссылка в новой задаче