diff options
Diffstat (limited to 'components/script/script_task.rs')
-rw-r--r-- | components/script/script_task.rs | 118 |
1 files changed, 15 insertions, 103 deletions
diff --git a/components/script/script_task.rs b/components/script/script_task.rs index b59bef57468..fd608fe4284 100644 --- a/components/script/script_task.rs +++ b/components/script/script_task.rs @@ -9,9 +9,6 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; -use dom::bindings::codegen::Bindings::EventBinding::EventMethods; -use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; -use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, EventTargetCast, HTMLIFrameElementCast, NodeCast, EventCast}; use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::StringificationBehavior; @@ -22,11 +19,10 @@ use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{wrap_for_same_compartment, pre_wrap}; use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressHandler, DocumentProgressTask, DocumentSource}; -use dom::element::{Element, ActivationElementHelpers}; +use dom::element::{Element, AttributeHandlers}; use dom::event::{Event, EventHelpers}; use dom::uievent::UIEvent; use dom::eventtarget::EventTarget; -use dom::keyboardevent::KeyboardEvent; use dom::mouseevent::MouseEvent; use dom::node::{self, Node, NodeHelpers, NodeDamage}; use dom::window::{Window, WindowHelpers, ScriptHelpers}; @@ -50,15 +46,14 @@ use script_traits::ScriptTaskFactory; use msg::compositor_msg::ReadyState::{FinishedLoading, Loading, PerformingLayout}; use msg::compositor_msg::{LayerId, ScriptListener}; use msg::constellation_msg::{ConstellationChan}; -use msg::constellation_msg::{LoadData, NavigationDirection, PipelineId, SubpageId}; -use msg::constellation_msg::{Failure, Msg, WindowSizeData, Key, KeyState}; -use msg::constellation_msg::{KeyModifiers, SUPER, SHIFT, CONTROL, ALT}; -use msg::constellation_msg::{PipelineExitType}; +use msg::constellation_msg::{LoadData, PipelineId, SubpageId}; +use msg::constellation_msg::{Failure, Msg, WindowSizeData, PipelineExitType}; use msg::constellation_msg::Msg as ConstellationMsg; use net::image_cache_task::ImageCacheTask; use net::resource_task::{ResourceTask, ControlMsg}; use net::resource_task::LoadData as NetLoadData; use net::storage_task::StorageTask; +use string_cache::Atom; use util::geometry::to_frac_px; use util::smallvec::SmallVec; use util::str::DOMString; @@ -108,9 +103,6 @@ pub enum ScriptMsg { /// Begins a content-initiated load on the specified pipeline (only /// dispatched to ScriptTask). TriggerLoad(PipelineId, LoadData), - /// Instructs the script task to send a navigate message to - /// the constellation (only dispatched to ScriptTask). - Navigate(NavigationDirection), /// Fires a JavaScript timeout /// TimerSource must be FromWindow when dispatched to ScriptTask and /// must be FromWorker when dispatched to a DedicatedGlobalWorkerScope @@ -597,8 +589,6 @@ impl ScriptTask { self.handle_fire_timer_msg(id, timer_id), ScriptMsg::FireTimer(TimerSource::FromWorker, _) => panic!("Worker timeouts must not be sent to script task"), - ScriptMsg::Navigate(direction) => - self.handle_navigate_msg(direction), ScriptMsg::ExitWindow(id) => self.handle_exit_window_msg(id), ScriptMsg::DOMMessage(..) => @@ -700,14 +690,13 @@ impl ScriptTask { *layout_join_port = None; } - self.compositor.borrow_mut().set_ready_state(pipeline_id, FinishedLoading); - } + let doc = page.frame().as_ref().unwrap().document.root(); + let html_element = doc.r().GetDocumentElement().root(); + let reftest_wait = html_element.r().map_or(false, |elem| elem.has_class(&Atom::from_slice("reftest-wait"))); - /// Handles a navigate forward or backward message. - /// TODO(tkuehn): is it ever possible to navigate only on a subframe? - fn handle_navigate_msg(&self, direction: NavigationDirection) { - let ConstellationChan(ref chan) = self.constellation_chan; - chan.send(ConstellationMsg::Navigate(direction)).unwrap(); + if !reftest_wait { + self.compositor.borrow_mut().set_ready_state(pipeline_id, FinishedLoading); + } } /// Window was resized, but this script was not active, so don't reflow yet @@ -1014,90 +1003,13 @@ impl ScriptTask { } KeyEvent(key, state, modifiers) => { - self.dispatch_key_event(key, state, modifiers, pipeline_id); - } - } - } - - /// The entry point for all key processing for web content - fn dispatch_key_event(&self, key: Key, - state: KeyState, - modifiers: KeyModifiers, - pipeline_id: PipelineId) { - let page = get_page(&*self.page.borrow(), pipeline_id); - let frame = page.frame(); - let window = frame.as_ref().unwrap().window.root(); - let doc = window.r().Document().root(); - let focused = doc.r().get_focused_element().root(); - let body = doc.r().GetBody().root(); - - let target: JSRef<EventTarget> = match (&focused, &body) { - (&Some(ref focused), _) => EventTargetCast::from_ref(focused.r()), - (&None, &Some(ref body)) => EventTargetCast::from_ref(body.r()), - (&None, &None) => EventTargetCast::from_ref(window.r()), - }; - - let ctrl = modifiers.contains(CONTROL); - let alt = modifiers.contains(ALT); - let shift = modifiers.contains(SHIFT); - let meta = modifiers.contains(SUPER); - - let is_composing = false; - let is_repeating = state == KeyState::Repeated; - let ev_type = match state { - KeyState::Pressed | KeyState::Repeated => "keydown", - KeyState::Released => "keyup", - }.to_owned(); - - let props = KeyboardEvent::key_properties(key, modifiers); - - let keyevent = KeyboardEvent::new(window.r(), ev_type, true, true, - Some(window.r()), 0, - props.key.to_owned(), props.code.to_owned(), - props.location, is_repeating, is_composing, - ctrl, alt, shift, meta, - None, props.key_code).root(); - let event = EventCast::from_ref(keyevent.r()); - let _ = target.DispatchEvent(event); - let mut prevented = event.DefaultPrevented(); - - // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keys-cancelable-keys - if state != KeyState::Released && props.is_printable() && !prevented { - // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#keypress-event-order - let event = KeyboardEvent::new(window.r(), "keypress".to_owned(), - true, true, Some(window.r()), - 0, props.key.to_owned(), props.code.to_owned(), - props.location, is_repeating, is_composing, - ctrl, alt, shift, meta, - props.char_code, 0).root(); - let ev = EventCast::from_ref(event.r()); - let _ = target.DispatchEvent(ev); - prevented = ev.DefaultPrevented(); - // TODO: if keypress event is canceled, prevent firing input events - } - - if !prevented { - self.compositor.borrow_mut().send_key_event(key, state, modifiers); - } - - // This behavior is unspecced - // We are supposed to dispatch synthetic click activation for Space and/or Return, - // however *when* we do it is up to us - // I'm dispatching it after the key event so the script has a chance to cancel it - // https://www.w3.org/Bugs/Public/show_bug.cgi?id=27337 - match key { - Key::Space if !prevented && state == KeyState::Released => { - let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(target); - maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.synthetic_click_activation(ctrl, alt, shift, meta))); - } - Key::Enter if !prevented && state == KeyState::Released => { - let maybe_elem: Option<JSRef<Element>> = ElementCast::to_ref(target); - maybe_elem.map(|el| el.as_maybe_activatable().map(|a| a.implicit_submission(ctrl, alt, shift, meta))); + let page = get_page(&*self.page.borrow(), pipeline_id); + let frame = page.frame(); + let document = frame.as_ref().unwrap().document.root(); + document.r().dispatch_key_event( + key, state, modifiers, &mut *self.compositor.borrow_mut()); } - _ => () } - - window.r().flush_layout(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery); } /// The entry point for content to notify that a new load has been requested |