Skip to content

Commit

Permalink
Fix #6676
Browse files Browse the repository at this point in the history
  • Loading branch information
bgdncz committed Jul 22, 2015
1 parent 488f3b6 commit e10a524
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
13 changes: 11 additions & 2 deletions components/script/dom/document.rs
Expand Up @@ -15,7 +15,7 @@ use dom::bindings::codegen::Bindings::NodeFilterBinding::NodeFilter;
use dom::bindings::codegen::Bindings::PerformanceBinding::PerformanceMethods;
use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods;
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::{EventTargetCast, HTMLAnchorElementCast};
use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLAppletElementDerived};
Expand Down Expand Up @@ -49,6 +49,7 @@ use dom::htmlcollection::{HTMLCollection, CollectionFilter};
use dom::htmlelement::{HTMLElement, HTMLElementTypeId};
use dom::htmlheadelement::HTMLHeadElement;
use dom::htmlhtmlelement::HTMLHtmlElement;
use dom::htmliframeelement::HTMLIFrameElement;
use dom::htmlscriptelement::HTMLScriptElement;
use dom::location::Location;
use dom::mouseevent::MouseEvent;
Expand All @@ -69,7 +70,7 @@ use layout_interface::{HitTestResponse, MouseOverResponse};
use msg::compositor_msg::ScriptListener;
use msg::constellation_msg::AnimationState;
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 net_traits::CookieSource::NonHTTP;
use net_traits::ControlMsg::{SetCookiesForUrl, GetCookiesForUrl};
Expand Down Expand Up @@ -287,6 +288,7 @@ pub trait DocumentHelpers<'a> {
fn finish_load(self, load: LoadType);
fn set_current_parser(self, script: Option<&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 {
Expand Down Expand Up @@ -989,6 +991,13 @@ impl<'a> DocumentHelpers<'a> for &'a Document {
fn get_current_parser(self) -> Option<Root<ServoHTMLParser>> {
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 {
Expand Down
24 changes: 7 additions & 17 deletions components/script/script_task.rs
Expand Up @@ -22,7 +22,7 @@
use document_loader::{LoadType, DocumentLoader, NotifierData};
use dom::bindings::cell::DOMRefCell;
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::StringificationBehavior;
use dom::bindings::js::{JS, RootCollection, trace_roots};
Expand All @@ -35,7 +35,7 @@ use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressH
DocumentProgressTask, DocumentSource, MouseEventType};
use dom::element::{Element, AttributeHandlers};
use dom::event::{EventHelpers, EventBubbles, EventCancelable};
use dom::htmliframeelement::{HTMLIFrameElement, HTMLIFrameElementHelpers};
use dom::htmliframeelement::HTMLIFrameElementHelpers;
use dom::uievent::UIEvent;
use dom::node::{Node, NodeHelpers, NodeDamage, window_from_node};
use dom::servohtmlparser::{ServoHTMLParser, ParserContext};
Expand Down Expand Up @@ -1103,7 +1103,7 @@ impl ScriptTask {
let page = borrowed_page.find(parent_pipeline_id).unwrap();

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 {
let element = ElementCast::from_ref(frame_element.r());
Expand All @@ -1123,7 +1123,7 @@ impl ScriptTask {

let frame_element = borrowed_page.find(parent_pipeline_id).and_then(|page| {
let doc = page.document();
self.find_iframe(doc.r(), subpage_id)
doc.find_iframe(subpage_id)
});

if let Some(ref frame_element) = frame_element {
Expand All @@ -1139,7 +1139,7 @@ impl ScriptTask {

let frame_element = borrowed_page.find(containing_pipeline_id).and_then(|page| {
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);
Expand Down Expand Up @@ -1290,7 +1290,7 @@ impl ScriptTask {
borrowed_page.as_ref().and_then(|borrowed_page| {
borrowed_page.find(parent_id).and_then(|page| {
let doc = page.document();
self.find_iframe(doc.r(), subpage_id)
doc.find_iframe(subpage_id)
})
})
});
Expand Down Expand Up @@ -1457,16 +1457,6 @@ impl ScriptTask {
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.
///
/// TODO: Actually perform DOM event dispatch.
Expand Down Expand Up @@ -1545,7 +1535,7 @@ impl ScriptTask {
let borrowed_page = self.root_page();
let iframe = borrowed_page.find(pipeline_id).and_then(|page| {
let doc = page.document();
self.find_iframe(doc.r(), subpage_id)
doc.find_iframe(subpage_id)
});
if let Some(iframe) = iframe.r() {
iframe.navigate_child_browsing_context(load_data.url);
Expand Down

0 comments on commit e10a524

Please sign in to comment.