This commit is contained in:
Bogdan Cuza 2015-07-21 15:41:15 +03:00
parent 488f3b65a1
commit e10a524c81
2 changed files with 18 additions and 19 deletions

View file

@ -15,7 +15,7 @@ use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods; use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLBodyElementCast}; use dom::bindings::codegen::InheritTypes::{DocumentDerived, EventCast, HTMLBodyElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLHeadElementCast, ElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLHeadElementCast, ElementCast, HTMLIFrameElementCast};
use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{DocumentTypeCast, HTMLHtmlElementCast, NodeCast};
use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLAnchorElementCast}; use dom::bindings::codegen::InheritTypes::{EventTargetCast, HTMLAnchorElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLAppletElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLAppletElementDerived};
@ -49,6 +49,7 @@ use dom::htmlcollection::{HTMLCollection, CollectionFilter};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlheadelement::HTMLHeadElement; use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement; use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlscriptelement::HTMLScriptElement; use dom::htmlscriptelement::HTMLScriptElement;
use dom::location::Location; use dom::location::Location;
use dom::mouseevent::MouseEvent; use dom::mouseevent::MouseEvent;
@ -69,7 +70,7 @@ use layout_interface::{HitTestResponse, MouseOverResponse};
use msg::compositor_msg::ScriptListener; use msg::compositor_msg::ScriptListener;
use msg::constellation_msg::AnimationState; use msg::constellation_msg::AnimationState;
use msg::constellation_msg::Msg as ConstellationMsg; use msg::constellation_msg::Msg as ConstellationMsg;
use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyState, KeyModifiers, MozBrowserEvent}; use msg::constellation_msg::{ConstellationChan, FocusType, Key, KeyState, KeyModifiers, MozBrowserEvent, SubpageId};
use msg::constellation_msg::{SUPER, ALT, SHIFT, CONTROL}; use msg::constellation_msg::{SUPER, ALT, SHIFT, CONTROL};
use net_traits::CookieSource::NonHTTP; use net_traits::CookieSource::NonHTTP;
use net_traits::ControlMsg::{SetCookiesForUrl, GetCookiesForUrl}; use net_traits::ControlMsg::{SetCookiesForUrl, GetCookiesForUrl};
@ -287,6 +288,7 @@ pub trait DocumentHelpers<'a> {
fn finish_load(self, load: LoadType); fn finish_load(self, load: LoadType);
fn set_current_parser(self, script: Option<&ServoHTMLParser>); fn set_current_parser(self, script: Option<&ServoHTMLParser>);
fn get_current_parser(self) -> Option<Root<ServoHTMLParser>>; fn get_current_parser(self) -> Option<Root<ServoHTMLParser>>;
fn find_iframe(self, subpage_id: SubpageId) -> Option<Root<HTMLIFrameElement>>;
} }
impl<'a> DocumentHelpers<'a> for &'a Document { impl<'a> DocumentHelpers<'a> for &'a Document {
@ -989,6 +991,13 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
fn get_current_parser(self) -> Option<Root<ServoHTMLParser>> { fn get_current_parser(self) -> Option<Root<ServoHTMLParser>> {
self.current_parser.get().map(Root::from_rooted) self.current_parser.get().map(Root::from_rooted)
} }
/// Find an iframe element in the document.
fn find_iframe(self, subpage_id: SubpageId) -> Option<Root<HTMLIFrameElement>> {
NodeCast::from_ref(self).traverse_preorder()
.filter_map(HTMLIFrameElementCast::to_root)
.find(|node| node.r().subpage_id() == Some(subpage_id))
}
} }
pub enum MouseEventType { pub enum MouseEventType {

View file

@ -22,7 +22,7 @@
use document_loader::{LoadType, DocumentLoader, NotifierData}; use document_loader::{LoadType, DocumentLoader, NotifierData};
use dom::bindings::cell::DOMRefCell; use dom::bindings::cell::DOMRefCell;
use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState};
use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLIFrameElementCast, NodeCast, EventCast}; use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, NodeCast, EventCast};
use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::FromJSValConvertible;
use dom::bindings::conversions::StringificationBehavior; use dom::bindings::conversions::StringificationBehavior;
use dom::bindings::js::{JS, RootCollection, trace_roots}; use dom::bindings::js::{JS, RootCollection, trace_roots};
@ -35,7 +35,7 @@ use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressH
DocumentProgressTask, DocumentSource, MouseEventType}; DocumentProgressTask, DocumentSource, MouseEventType};
use dom::element::{Element, AttributeHandlers}; use dom::element::{Element, AttributeHandlers};
use dom::event::{EventHelpers, EventBubbles, EventCancelable}; use dom::event::{EventHelpers, EventBubbles, EventCancelable};
use dom::htmliframeelement::{HTMLIFrameElement, HTMLIFrameElementHelpers}; use dom::htmliframeelement::HTMLIFrameElementHelpers;
use dom::uievent::UIEvent; use dom::uievent::UIEvent;
use dom::node::{Node, NodeHelpers, NodeDamage, window_from_node}; use dom::node::{Node, NodeHelpers, NodeDamage, window_from_node};
use dom::servohtmlparser::{ServoHTMLParser, ParserContext}; use dom::servohtmlparser::{ServoHTMLParser, ParserContext};
@ -1103,7 +1103,7 @@ impl ScriptTask {
let page = borrowed_page.find(parent_pipeline_id).unwrap(); let page = borrowed_page.find(parent_pipeline_id).unwrap();
let doc = page.document(); let doc = page.document();
let frame_element = self.find_iframe(doc.r(), subpage_id); let frame_element = doc.find_iframe(subpage_id);
if let Some(ref frame_element) = frame_element { if let Some(ref frame_element) = frame_element {
let element = ElementCast::from_ref(frame_element.r()); let element = ElementCast::from_ref(frame_element.r());
@ -1123,7 +1123,7 @@ impl ScriptTask {
let frame_element = borrowed_page.find(parent_pipeline_id).and_then(|page| { let frame_element = borrowed_page.find(parent_pipeline_id).and_then(|page| {
let doc = page.document(); let doc = page.document();
self.find_iframe(doc.r(), subpage_id) doc.find_iframe(subpage_id)
}); });
if let Some(ref frame_element) = frame_element { if let Some(ref frame_element) = frame_element {
@ -1139,7 +1139,7 @@ impl ScriptTask {
let frame_element = borrowed_page.find(containing_pipeline_id).and_then(|page| { let frame_element = borrowed_page.find(containing_pipeline_id).and_then(|page| {
let doc = page.document(); let doc = page.document();
self.find_iframe(doc.r(), old_subpage_id) doc.find_iframe(old_subpage_id)
}); });
frame_element.r().unwrap().update_subpage_id(new_subpage_id); frame_element.r().unwrap().update_subpage_id(new_subpage_id);
@ -1290,7 +1290,7 @@ impl ScriptTask {
borrowed_page.as_ref().and_then(|borrowed_page| { borrowed_page.as_ref().and_then(|borrowed_page| {
borrowed_page.find(parent_id).and_then(|page| { borrowed_page.find(parent_id).and_then(|page| {
let doc = page.document(); let doc = page.document();
self.find_iframe(doc.r(), subpage_id) doc.find_iframe(subpage_id)
}) })
}) })
}); });
@ -1457,16 +1457,6 @@ impl ScriptTask {
window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, reason); window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, reason);
} }
/// Find an iframe element in a provided document.
fn find_iframe(&self, doc: &Document, subpage_id: SubpageId)
-> Option<Root<HTMLIFrameElement>> {
let doc = NodeCast::from_ref(doc);
doc.traverse_preorder()
.filter_map(HTMLIFrameElementCast::to_root)
.find(|node| node.r().subpage_id() == Some(subpage_id))
}
/// This is the main entry point for receiving and dispatching DOM events. /// This is the main entry point for receiving and dispatching DOM events.
/// ///
/// TODO: Actually perform DOM event dispatch. /// TODO: Actually perform DOM event dispatch.
@ -1545,7 +1535,7 @@ impl ScriptTask {
let borrowed_page = self.root_page(); let borrowed_page = self.root_page();
let iframe = borrowed_page.find(pipeline_id).and_then(|page| { let iframe = borrowed_page.find(pipeline_id).and_then(|page| {
let doc = page.document(); let doc = page.document();
self.find_iframe(doc.r(), subpage_id) doc.find_iframe(subpage_id)
}); });
if let Some(iframe) = iframe.r() { if let Some(iframe) = iframe.r() {
iframe.navigate_child_browsing_context(load_data.url); iframe.navigate_child_browsing_context(load_data.url);