diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-12-09 09:52:34 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-09 09:52:34 -0800 |
commit | 8b69e73594647319e95bd0fd36c2addabcee1e5d (patch) | |
tree | fb8f23cab824af1e9731c3bc1acb754ee443c77b /components/script/dom/document.rs | |
parent | c3c086e521b73d191d5de9239a6748691b0f96a3 (diff) | |
parent | 55f0e56224be03dcbd17d5cba1c45f8b0c6bb390 (diff) | |
download | servo-8b69e73594647319e95bd0fd36c2addabcee1e5d.tar.gz servo-8b69e73594647319e95bd0fd36c2addabcee1e5d.zip |
Auto merge of #13489 - farodin91:fullscreen, r=jdm
Add support for fullscreen #10102
<!-- Please describe your changes on the following line: -->
I'm start working on fullscreen support.
@jdm Should be the entry_point in ScriptReflow a Option if fullscreen is enabled or point on the entry_node? For example the RootNode.
---
<!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: -->
- [x] `./mach build -d` does not report any errors
- [x] `./mach test-tidy` does not report any errors
- [x] These changes fix #10102 (github issue number if applicable).
<!-- Either: -->
- [x] There are tests for these changes OR
- [ ] These changes do not require tests because _____
<!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/13489)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/document.rs')
-rw-r--r-- | components/script/dom/document.rs | 141 |
1 files changed, 139 insertions, 2 deletions
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index d0dbe75ebd3..0e16ca16f81 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -27,7 +27,7 @@ use dom::bindings::inheritance::{Castable, ElementTypeId, HTMLElementTypeId, Nod use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, Root}; use dom::bindings::js::RootedReference; use dom::bindings::num::Finite; -use dom::bindings::refcounted::Trusted; +use dom::bindings::refcounted::{Trusted, TrustedPromise}; use dom::bindings::reflector::{DomObject, reflect_dom_object}; use dom::bindings::str::{DOMString, USVString}; use dom::bindings::xmlname::{namespace_from_domstring, validate_and_extract, xml_name_type}; @@ -39,7 +39,7 @@ use dom::customevent::CustomEvent; use dom::documentfragment::DocumentFragment; use dom::documenttype::DocumentType; use dom::domimplementation::DOMImplementation; -use dom::element::{Element, ElementCreator}; +use dom::element::{Element, ElementCreator, ElementPerformFullscreenEnter, ElementPerformFullscreenExit}; use dom::errorevent::ErrorEvent; use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventdispatcher::EventStatus; @@ -74,6 +74,7 @@ use dom::pagetransitionevent::PageTransitionEvent; use dom::popstateevent::PopStateEvent; use dom::processinginstruction::ProcessingInstruction; use dom::progressevent::ProgressEvent; +use dom::promise::Promise; use dom::range::Range; use dom::servoparser::ServoParser; use dom::storageevent::StorageEvent; @@ -105,6 +106,7 @@ use net_traits::response::HttpsState; use num_traits::ToPrimitive; use origin::Origin; use script_layout_interface::message::{Msg, ReflowQueryType}; +use script_runtime::{CommonScriptMsg, ScriptThreadEventCategory}; use script_thread::{MainThreadScriptMsg, Runnable}; use script_traits::{AnimationState, CompositorEvent, MouseButton, MouseEventType, MozBrowserEvent}; use script_traits::{ScriptMsg as ConstellationMsg, TouchpadPressurePhase}; @@ -290,6 +292,8 @@ pub struct Document { /// /// See also: https://github.com/servo/servo/issues/10110 dom_count: Cell<u32>, + /// Entry node for fullscreen. + fullscreen_element: MutNullableHeap<JS<Element>>, } #[derive(JSTraceable, HeapSizeOf)] @@ -1907,6 +1911,7 @@ impl Document { last_click_info: DOMRefCell::new(None), ignore_destructive_writes_counter: Default::default(), dom_count: Cell::new(1), + fullscreen_element: MutNullableHeap::new(None), } } @@ -2092,6 +2097,110 @@ impl Document { self.ignore_destructive_writes_counter.set( self.ignore_destructive_writes_counter.get() - 1); } + + // https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen + #[allow(unrooted_must_root)] + pub fn enter_fullscreen(&self, pending: &Element) -> Rc<Promise> { + // Step 1 + let promise = Promise::new(self.global().r()); + let mut error = false; + + // Step 4 + // check namespace + match *pending.namespace() { + ns!(mathml) => { + if pending.local_name().as_ref() != "math" { + error = true; + } + } + ns!(svg) => { + if pending.local_name().as_ref() != "svg" { + error = true; + } + } + ns!(html) => (), + _ => error = true, + } + // fullscreen element ready check + if !pending.fullscreen_element_ready_check() { + error = true; + } + // TODO fullscreen is supported + // TODO This algorithm is allowed to request fullscreen. + + // Step 5 Parallel start + + let window = self.window(); + // Step 6 + if !error { + let event = ConstellationMsg::SetFullscreenState(true); + window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); + } + + // Step 7 + let trusted_pending = Trusted::new(pending); + let trusted_promise = TrustedPromise::new(promise.clone()); + let handler = ElementPerformFullscreenEnter::new(trusted_pending, trusted_promise, error); + let script_msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::EnterFullscreen, handler); + let msg = MainThreadScriptMsg::Common(script_msg); + window.main_thread_script_chan().send(msg).unwrap(); + + promise + } + + // https://fullscreen.spec.whatwg.org/#exit-fullscreen + #[allow(unrooted_must_root)] + pub fn exit_fullscreen(&self) -> Rc<Promise> { + let global = self.global(); + // Step 1 + let promise = Promise::new(global.r()); + // Step 2 + if self.fullscreen_element.get().is_none() { + promise.reject_error(global.get_cx(), Error::Type(String::from("fullscreen is null"))); + return promise + } + // TODO Step 3-6 + let element = self.fullscreen_element.get().unwrap(); + + // Step 7 Parallel start + + let window = self.window(); + // Step 8 + let event = ConstellationMsg::SetFullscreenState(false); + window.upcast::<GlobalScope>().constellation_chan().send(event).unwrap(); + + // Step 9 + let trusted_element = Trusted::new(element.r()); + let trusted_promise = TrustedPromise::new(promise.clone()); + let handler = ElementPerformFullscreenExit::new(trusted_element, trusted_promise); + let script_msg = CommonScriptMsg::RunnableMsg(ScriptThreadEventCategory::ExitFullscreen, handler); + let msg = MainThreadScriptMsg::Common(script_msg); + window.main_thread_script_chan().send(msg).unwrap(); + + promise + } + + pub fn set_fullscreen_element(&self, element: Option<&Element>) { + self.fullscreen_element.set(element); + } + + pub fn get_allow_fullscreen(&self) -> bool { + // https://html.spec.whatwg.org/multipage/#allowed-to-use + match self.browsing_context() { + // Step 1 + None => false, + Some(_) => { + // Step 2 + let window = self.window(); + if window.is_top_level() { + true + } else { + // Step 3 + window.GetFrameElement().map_or(false, |el| el.has_attribute(&local_name!("allowfullscreen"))) + } + } + } + } } @@ -3109,6 +3218,34 @@ impl DocumentMethods for Document { // https://html.spec.whatwg.org/multipage/#documentandelementeventhandlers document_and_element_event_handlers!(); + + // https://fullscreen.spec.whatwg.org/#handler-document-onfullscreenerror + event_handler!(fullscreenerror, GetOnfullscreenerror, SetOnfullscreenerror); + + // https://fullscreen.spec.whatwg.org/#handler-document-onfullscreenchange + event_handler!(fullscreenchange, GetOnfullscreenchange, SetOnfullscreenchange); + + // https://fullscreen.spec.whatwg.org/#dom-document-fullscreenenabled + fn FullscreenEnabled(&self) -> bool { + self.get_allow_fullscreen() + } + + // https://fullscreen.spec.whatwg.org/#dom-document-fullscreen + fn Fullscreen(&self) -> bool { + self.fullscreen_element.get().is_some() + } + + // https://fullscreen.spec.whatwg.org/#dom-document-fullscreenelement + fn GetFullscreenElement(&self) -> Option<Root<Element>> { + // TODO ShadowRoot + self.fullscreen_element.get() + } + + #[allow(unrooted_must_root)] + // https://fullscreen.spec.whatwg.org/#dom-document-exitfullscreen + fn ExitFullscreen(&self) -> Rc<Promise> { + self.exit_fullscreen() + } } fn update_with_current_time_ms(marker: &Cell<u64>) { |