-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
pub mod activation_behavior; | ||
pub mod api; | ||
pub mod event; | ||
pub mod window; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//! This is a DOM Window object. | ||
//! https://html.spec.whatwg.org/multipage/nav-history-apis.html#window | ||
use crate::browser::Browser; | ||
use crate::renderer::html::dom::Node; | ||
use crate::renderer::html::dom::NodeKind; | ||
use crate::renderer::page::Page; | ||
use alloc::rc::Rc; | ||
use alloc::rc::Weak; | ||
use core::cell::RefCell; | ||
|
||
/// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window | ||
/// | ||
/// https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/frame/dom_window.h | ||
#[derive(Debug, Clone)] | ||
pub struct Window { | ||
_browser: Weak<RefCell<Browser>>, | ||
_page: Weak<RefCell<Page>>, | ||
pub document: Rc<RefCell<Node>>, | ||
} | ||
|
||
impl Window { | ||
pub fn new(browser: Weak<RefCell<Browser>>) -> Self { | ||
let window = Self { | ||
_browser: browser, | ||
_page: Weak::new(), | ||
document: Rc::new(RefCell::new(Node::new(NodeKind::Document))), | ||
}; | ||
|
||
window | ||
.document | ||
.borrow_mut() | ||
.set_window(Rc::downgrade(&Rc::new(RefCell::new(window.clone())))); | ||
|
||
window | ||
} | ||
|
||
pub fn document(&self) -> Rc<RefCell<Node>> { | ||
self.document.clone() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters