mirror of
https://github.com/servo/servo.git
synced 2025-06-06 16:45:39 +00:00
Introduce GlobalScope::as_window
This commit is contained in:
parent
2f54022761
commit
766010379e
22 changed files with 30 additions and 43 deletions
|
@ -68,15 +68,6 @@ impl<'a> GlobalRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Extract a `Window`, causing thread failure if the global object is not
|
||||
/// a `Window`.
|
||||
pub fn as_window(&self) -> &window::Window {
|
||||
match *self {
|
||||
GlobalRef::Window(window) => window,
|
||||
GlobalRef::Worker(_) => panic!("expected a Window scope"),
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the `ResourceThreads` for this global scope.
|
||||
pub fn resource_threads(&self) -> ResourceThreads {
|
||||
match *self {
|
||||
|
|
|
@ -60,9 +60,7 @@ impl Bluetooth {
|
|||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
self.global_scope().as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
fn request_device(&self, option: &RequestDeviceOptions) -> Fallible<Root<BluetoothDevice>> {
|
||||
|
|
|
@ -74,9 +74,7 @@ impl BluetoothRemoteGATTCharacteristic {
|
|||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
self.global_scope().as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
fn get_instance_id(&self) -> String {
|
||||
|
|
|
@ -61,9 +61,7 @@ impl BluetoothRemoteGATTDescriptor {
|
|||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
self.global_scope().as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
fn get_instance_id(&self) -> String {
|
||||
|
|
|
@ -46,9 +46,7 @@ impl BluetoothRemoteGATTServer {
|
|||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
self.global_scope().as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
// https://webbluetoothcg.github.io/web-bluetooth/#dom-bluetoothremotegattserver-connect
|
||||
|
|
|
@ -61,9 +61,7 @@ impl BluetoothRemoteGATTService {
|
|||
}
|
||||
|
||||
fn get_bluetooth_thread(&self) -> IpcSender<BluetoothMethodMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().bluetooth_thread()
|
||||
self.global_scope().as_window().bluetooth_thread()
|
||||
}
|
||||
|
||||
fn get_instance_id(&self) -> String {
|
||||
|
|
|
@ -32,7 +32,7 @@ impl Comment {
|
|||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef, data: DOMString) -> Fallible<Root<Comment>> {
|
||||
let document = global.as_window().Document();
|
||||
let document = global.as_global_scope().as_window().Document();
|
||||
Ok(Comment::new(data, document.r()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1820,7 +1820,7 @@ impl Document {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-document
|
||||
pub fn Constructor(global: GlobalRef) -> Fallible<Root<Document>> {
|
||||
let win = global.as_window();
|
||||
let win = global.as_global_scope().as_window();
|
||||
let doc = win.Document();
|
||||
let doc = doc.r();
|
||||
let docloader = DocumentLoader::new(&*doc.loader());
|
||||
|
|
|
@ -39,7 +39,7 @@ impl DocumentFragment {
|
|||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef) -> Fallible<Root<DocumentFragment>> {
|
||||
let document = global.as_window().Document();
|
||||
let document = global.as_global_scope().as_window().Document();
|
||||
|
||||
Ok(DocumentFragment::new(document.r()))
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ impl DOMParser {
|
|||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef) -> Fallible<Root<DOMParser>> {
|
||||
Ok(DOMParser::new(global.as_window()))
|
||||
Ok(DOMParser::new(global.as_global_scope().as_window()))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,8 @@ impl FocusEvent {
|
|||
init: &FocusEventBinding::FocusEventInit) -> Fallible<Root<FocusEvent>> {
|
||||
let bubbles = EventBubbles::from(init.parent.parent.bubbles);
|
||||
let cancelable = EventCancelable::from(init.parent.parent.cancelable);
|
||||
let event = FocusEvent::new(global.as_window(), type_,
|
||||
let event = FocusEvent::new(global.as_global_scope().as_window(),
|
||||
type_,
|
||||
bubbles,
|
||||
cancelable,
|
||||
init.parent.view.r(),
|
||||
|
|
|
@ -190,6 +190,11 @@ impl GlobalScope {
|
|||
}
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
/// Extract a `Window`, panic if the global object is not a `Window`.
|
||||
pub fn as_window(&self) -> &Window {
|
||||
self.downcast::<Window>().expect("expected a Window scope")
|
||||
}
|
||||
}
|
||||
|
||||
fn timestamp_in_ms(time: Timespec) -> u64 {
|
||||
|
|
|
@ -65,8 +65,7 @@ impl HTMLFormControlsCollectionMethods for HTMLFormControlsCollection {
|
|||
// Step 4-5
|
||||
let once = iter::once(Root::upcast::<Node>(elem));
|
||||
let list = once.chain(peekable.map(Root::upcast));
|
||||
let global = self.global();
|
||||
let global = global.r();
|
||||
let global = self.global_scope();
|
||||
let window = global.as_window();
|
||||
Some(RadioNodeListOrElement::RadioNodeList(RadioNodeList::new_simple_list(window, list)))
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ impl HTMLImageElement {
|
|||
pub fn Image(global: GlobalRef,
|
||||
width: Option<u32>,
|
||||
height: Option<u32>) -> Fallible<Root<HTMLImageElement>> {
|
||||
let document = global.as_window().Document();
|
||||
let document = global.as_global_scope().as_window().Document();
|
||||
let image = HTMLImageElement::new(atom!("img"), None, document.r());
|
||||
if let Some(w) = width {
|
||||
image.SetWidth(w);
|
||||
|
|
|
@ -104,7 +104,8 @@ impl KeyboardEvent {
|
|||
pub fn Constructor(global: GlobalRef,
|
||||
type_: DOMString,
|
||||
init: &KeyboardEventBinding::KeyboardEventInit) -> Fallible<Root<KeyboardEvent>> {
|
||||
let event = KeyboardEvent::new(global.as_window(), type_,
|
||||
let event = KeyboardEvent::new(global.as_global_scope().as_window(),
|
||||
type_,
|
||||
init.parent.parent.parent.bubbles,
|
||||
init.parent.parent.parent.cancelable,
|
||||
init.parent.parent.view.r(),
|
||||
|
|
|
@ -87,7 +87,8 @@ impl MouseEvent {
|
|||
init: &MouseEventBinding::MouseEventInit) -> Fallible<Root<MouseEvent>> {
|
||||
let bubbles = EventBubbles::from(init.parent.parent.parent.bubbles);
|
||||
let cancelable = EventCancelable::from(init.parent.parent.parent.cancelable);
|
||||
let event = MouseEvent::new(global.as_window(), type_,
|
||||
let event = MouseEvent::new(global.as_global_scope().as_window(),
|
||||
type_,
|
||||
bubbles,
|
||||
cancelable,
|
||||
init.parent.parent.view.r(),
|
||||
|
|
|
@ -71,7 +71,7 @@ impl Range {
|
|||
|
||||
// https://dom.spec.whatwg.org/#dom-range
|
||||
pub fn Constructor(global: GlobalRef) -> Fallible<Root<Range>> {
|
||||
let document = global.as_window().Document();
|
||||
let document = global.as_global_scope().as_window().Document();
|
||||
Ok(Range::new_with_doc(document.r()))
|
||||
}
|
||||
|
||||
|
|
|
@ -44,9 +44,7 @@ impl Storage {
|
|||
}
|
||||
|
||||
fn get_storage_thread(&self) -> IpcSender<StorageThreadMsg> {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
global_ref.as_window().resource_threads().sender()
|
||||
self.global_scope().as_window().resource_threads().sender()
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -154,7 +152,7 @@ impl Storage {
|
|||
new_value: Option<String>) {
|
||||
let global_root = self.global();
|
||||
let global_ref = global_root.r();
|
||||
let window = global_ref.as_window();
|
||||
let window = global_ref.as_global_scope().as_window();
|
||||
let task_source = window.dom_manipulation_task_source();
|
||||
let trusted_storage = Trusted::new(self);
|
||||
task_source.queue(box StorageEventRunnable::new(trusted_storage, key, old_value, new_value),
|
||||
|
|
|
@ -750,7 +750,7 @@ impl TestBindingMethods for TestBinding {
|
|||
}
|
||||
|
||||
fn AdvanceClock(&self, ms: i32, tick: bool) {
|
||||
self.global().r().as_window().advance_animation_clock(ms, tick);
|
||||
self.global_scope().as_window().advance_animation_clock(ms, tick);
|
||||
}
|
||||
|
||||
fn Panic(&self) { panic!("explicit panic from script") }
|
||||
|
|
|
@ -36,7 +36,7 @@ impl Text {
|
|||
}
|
||||
|
||||
pub fn Constructor(global: GlobalRef, text: DOMString) -> Fallible<Root<Text>> {
|
||||
let document = global.as_window().Document();
|
||||
let document = global.as_global_scope().as_window().Document();
|
||||
Ok(Text::new(text, document.r()))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,7 +57,8 @@ impl UIEvent {
|
|||
init: &UIEventBinding::UIEventInit) -> Fallible<Root<UIEvent>> {
|
||||
let bubbles = EventBubbles::from(init.parent.bubbles);
|
||||
let cancelable = EventCancelable::from(init.parent.cancelable);
|
||||
let event = UIEvent::new(global.as_window(), type_,
|
||||
let event = UIEvent::new(global.as_global_scope().as_window(),
|
||||
type_,
|
||||
bubbles, cancelable,
|
||||
init.view.r(), init.detail);
|
||||
Ok(event)
|
||||
|
|
|
@ -1224,7 +1224,7 @@ impl XMLHttpRequest {
|
|||
fn new_doc(&self, is_html_document: IsHTMLDocument) -> Root<Document> {
|
||||
let wr = self.global();
|
||||
let wr = wr.r();
|
||||
let win = wr.as_window();
|
||||
let win = wr.as_global_scope().as_window();
|
||||
let doc = win.Document();
|
||||
let doc = doc.r();
|
||||
let docloader = DocumentLoader::new(&*doc.loader());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue