diff --git a/servo/components/script/devtools.rs b/servo/components/script/devtools.rs index d2feb56674e8..6c843e9e9eb5 100644 --- a/servo/components/script/devtools.rs +++ b/servo/components/script/devtools.rs @@ -13,9 +13,7 @@ use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::jsstring_to_str; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; -use dom::document::DocumentHelpers; -use dom::node::{Node, NodeHelpers}; -use dom::window::{WindowHelpers, ScriptHelpers}; +use dom::node::Node; use ipc_channel::ipc::IpcSender; use js::jsapi::{ObjectClassName, RootedObject, RootedValue}; use js::jsval::UndefinedValue; diff --git a/servo/components/script/dom/activation.rs b/servo/components/script/dom/activation.rs index 67dc0f1b7313..441871f9abe9 100644 --- a/servo/components/script/dom/activation.rs +++ b/servo/components/script/dom/activation.rs @@ -4,8 +4,8 @@ use dom::bindings::codegen::Bindings::EventBinding::EventMethods; use dom::bindings::codegen::InheritTypes::{EventCast, EventTargetCast}; -use dom::element::{Element, ActivationElementHelpers}; -use dom::event::{Event, EventHelpers, EventBubbles, EventCancelable}; +use dom::element::Element; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::EventTarget; use dom::mouseevent::MouseEvent; use dom::node::window_from_node; diff --git a/servo/components/script/dom/attr.rs b/servo/components/script/dom/attr.rs index fcc577b7cd50..29648286c2c1 100644 --- a/servo/components/script/dom/attr.rs +++ b/servo/components/script/dom/attr.rs @@ -9,7 +9,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap}; use dom::bindings::js::{Root, RootedReference, LayoutJS}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::element::{Element, AttributeHandlers}; +use dom::element::Element; use dom::virtualmethods::vtable_for; use dom::window::Window; @@ -234,17 +234,9 @@ impl<'a> AttrMethods for &'a Attr { } } -pub trait AttrHelpers<'a> { - fn set_value(self, set_type: AttrSettingType, value: AttrValue, owner: &Element); - fn value(self) -> Ref<'a, AttrValue>; - fn local_name(self) -> &'a Atom; - fn set_owner(self, owner: Option<&Element>); - fn owner(self) -> Option>; - fn summarize(self) -> AttrInfo; -} -impl<'a> AttrHelpers<'a> for &'a Attr { - fn set_value(self, set_type: AttrSettingType, value: AttrValue, owner: &Element) { +impl Attr { + pub fn set_value(&self, set_type: AttrSettingType, value: AttrValue, owner: &Element) { assert!(Some(owner) == self.owner().r()); let node = NodeCast::from_ref(owner); @@ -263,17 +255,17 @@ impl<'a> AttrHelpers<'a> for &'a Attr { } } - fn value(self) -> Ref<'a, AttrValue> { + pub fn value(&self) -> Ref { self.value.borrow() } - fn local_name(self) -> &'a Atom { + pub fn local_name(&self) -> &Atom { &self.local_name } /// Sets the owner element. Should be called after the attribute is added /// or removed from its older parent. - fn set_owner(self, owner: Option<&Element>) { + pub fn set_owner(&self, owner: Option<&Element>) { let ref ns = self.namespace; match (self.owner().r(), owner) { (None, Some(new)) => { @@ -289,11 +281,11 @@ impl<'a> AttrHelpers<'a> for &'a Attr { self.owner.set(owner.map(JS::from_ref)) } - fn owner(self) -> Option> { + pub fn owner(&self) -> Option> { self.owner.get().map(Root::from_rooted) } - fn summarize(self) -> AttrInfo { + pub fn summarize(&self) -> AttrInfo { let Namespace(ref ns) = self.namespace; AttrInfo { namespace: (**ns).to_owned(), diff --git a/servo/components/script/dom/bindings/global.rs b/servo/components/script/dom/bindings/global.rs index 2a9ee12e3a20..ef9e8ef82c92 100644 --- a/servo/components/script/dom/bindings/global.rs +++ b/servo/components/script/dom/bindings/global.rs @@ -12,9 +12,8 @@ use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; use dom::bindings::conversions::native_from_reflector_jsmanaged; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflectable, Reflector}; -use dom::document::DocumentHelpers; -use dom::window::{self, WindowHelpers, ScriptHelpers}; -use dom::workerglobalscope::{WorkerGlobalScope, WorkerGlobalScopeHelpers}; +use dom::window::{self, ScriptHelpers}; +use dom::workerglobalscope::WorkerGlobalScope; use script_task::{ScriptChan, ScriptPort, CommonScriptMsg, ScriptTask}; use msg::constellation_msg::{ConstellationChan, PipelineId, WorkerId}; diff --git a/servo/components/script/dom/blob.rs b/servo/components/script/dom/blob.rs index f30eaa80a90a..4c3cda4715ef 100644 --- a/servo/components/script/dom/blob.rs +++ b/servo/components/script/dom/blob.rs @@ -79,12 +79,9 @@ impl Blob { } } -pub trait BlobHelpers { - fn read_out_buffer(self, send: Sender>); -} -impl<'a> BlobHelpers for &'a Blob { - fn read_out_buffer(self, send: Sender>) { +impl Blob { + pub fn read_out_buffer(&self, send: Sender>) { send.send(self.bytes.clone().unwrap_or(vec![])).unwrap(); } } diff --git a/servo/components/script/dom/browsercontext.rs b/servo/components/script/dom/browsercontext.rs index cdd34ac7c711..3f6f1c0ebfbe 100644 --- a/servo/components/script/dom/browsercontext.rs +++ b/servo/components/script/dom/browsercontext.rs @@ -8,10 +8,9 @@ use dom::bindings::js::{JS, Root}; use dom::bindings::proxyhandler::{get_property_descriptor, fill_property_descriptor}; use dom::bindings::utils::get_array_index_from_id; use dom::bindings::utils::{Reflectable, WindowProxyHandler}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::element::Element; use dom::window::Window; -use dom::window::WindowHelpers; use js::glue::{GetProxyPrivate}; use js::glue::{WrapperNew, CreateWrapperProxyHandler, ProxyTraps}; diff --git a/servo/components/script/dom/canvasrenderingcontext2d.rs b/servo/components/script/dom/canvasrenderingcontext2d.rs index 4b8a08833a2f..1f8bb91a55c2 100644 --- a/servo/components/script/dom/canvasrenderingcontext2d.rs +++ b/servo/components/script/dom/canvasrenderingcontext2d.rs @@ -17,11 +17,11 @@ use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::canvasgradient::{CanvasGradient, CanvasGradientStyle, ToFillOrStrokeStyle}; use dom::canvaspattern::CanvasPattern; +use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlcanvaselement::utils as canvas_utils; -use dom::htmlcanvaselement::{HTMLCanvasElement, HTMLCanvasElementHelpers}; -use dom::htmlimageelement::{HTMLImageElement, HTMLImageElementHelpers}; -use dom::imagedata::{ImageData, ImageDataHelpers}; -use dom::node::{window_from_node, NodeHelpers, NodeDamage}; +use dom::htmlimageelement::HTMLImageElement; +use dom::imagedata::ImageData; +use dom::node::{window_from_node, NodeDamage}; use msg::constellation_msg::Msg as ConstellationMsg; use net_traits::image::base::PixelFormat; @@ -409,16 +409,12 @@ impl CanvasRenderingContext2D { } } -pub trait CanvasRenderingContext2DHelpers { - fn get_renderer_id(self) -> usize; - fn get_ipc_renderer(self) -> IpcSender; -} -impl<'a> CanvasRenderingContext2DHelpers for &'a CanvasRenderingContext2D { - fn get_renderer_id(self) -> usize { +impl CanvasRenderingContext2D { + pub fn get_renderer_id(&self) -> usize { self.renderer_id } - fn get_ipc_renderer(self) -> IpcSender { + pub fn get_ipc_renderer(&self) -> IpcSender { self.ipc_renderer.clone() } } diff --git a/servo/components/script/dom/characterdata.rs b/servo/components/script/dom/characterdata.rs index 1d6f8f87d743..c9e7dca7039b 100644 --- a/servo/components/script/dom/characterdata.rs +++ b/servo/components/script/dom/characterdata.rs @@ -15,7 +15,7 @@ use dom::bindings::js::{LayoutJS, Root}; use dom::document::Document; use dom::element::Element; use dom::eventtarget::{EventTarget, EventTargetTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use util::str::{DOMString, slice_chars}; @@ -157,18 +157,14 @@ pub enum CharacterDataTypeId { ProcessingInstruction, } -pub trait CharacterDataHelpers<'a> { - fn data(self) -> Ref<'a, DOMString>; - fn append_data(self, data: &str); -} -impl<'a> CharacterDataHelpers<'a> for &'a CharacterData { +impl CharacterData { #[inline] - fn data(self) -> Ref<'a, DOMString> { + pub fn data(&self) -> Ref { self.data.borrow() } #[inline] - fn append_data(self, data: &str) { + pub fn append_data(&self, data: &str) { self.data.borrow_mut().push_str(data) } } diff --git a/servo/components/script/dom/console.rs b/servo/components/script/dom/console.rs index 5b60c2deb40b..4dd5055b5359 100644 --- a/servo/components/script/dom/console.rs +++ b/servo/components/script/dom/console.rs @@ -8,7 +8,6 @@ use dom::bindings::codegen::Bindings::ConsoleBinding::ConsoleMethods; use dom::bindings::global::{GlobalRef, GlobalField}; use dom::bindings::js::Root; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::window::WindowHelpers; use util::str::DOMString; // https://developer.mozilla.org/en-US/docs/Web/API/Console diff --git a/servo/components/script/dom/cssstyledeclaration.rs b/servo/components/script/dom/cssstyledeclaration.rs index c72eaaed8eff..32d351d31066 100644 --- a/servo/components/script/dom/cssstyledeclaration.rs +++ b/servo/components/script/dom/cssstyledeclaration.rs @@ -8,10 +8,9 @@ use dom::bindings::error::{Error, ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::document::DocumentHelpers; -use dom::element::{ElementHelpers, StylePriority, Element}; -use dom::node::{window_from_node, document_from_node, NodeDamage, NodeHelpers}; -use dom::window::{Window, WindowHelpers}; +use dom::element::{StylePriority, Element}; +use dom::node::{window_from_node, document_from_node, NodeDamage}; +use dom::window::Window; use selectors::parser::PseudoElement; use string_cache::Atom; use style::properties::PropertyDeclaration; diff --git a/servo/components/script/dom/dedicatedworkerglobalscope.rs b/servo/components/script/dom/dedicatedworkerglobalscope.rs index 5e724f951411..e9c32f7f2cd1 100644 --- a/servo/components/script/dom/dedicatedworkerglobalscope.rs +++ b/servo/components/script/dom/dedicatedworkerglobalscope.rs @@ -6,7 +6,6 @@ use devtools; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding; use dom::bindings::codegen::Bindings::DedicatedWorkerGlobalScopeBinding::DedicatedWorkerGlobalScopeMethods; -use dom::bindings::codegen::Bindings::ErrorEventBinding::ErrorEventMethods; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::InheritTypes::DedicatedWorkerGlobalScopeDerived; use dom::bindings::codegen::InheritTypes::{EventTargetCast, WorkerGlobalScopeCast}; @@ -16,11 +15,10 @@ use dom::bindings::js::{RootCollection, Root}; use dom::bindings::refcounted::LiveDOMReferences; use dom::bindings::structuredclone::StructuredCloneData; use dom::bindings::utils::Reflectable; -use dom::errorevent::ErrorEvent; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::messageevent::MessageEvent; -use dom::worker::{TrustedWorkerAddress, WorkerMessageHandler, WorkerEventHandler, WorkerErrorHandler}; -use dom::workerglobalscope::{WorkerGlobalScope, WorkerGlobalScopeHelpers}; +use dom::worker::{TrustedWorkerAddress, WorkerMessageHandler, WorkerEventHandler}; +use dom::workerglobalscope::WorkerGlobalScope; use dom::workerglobalscope::{WorkerGlobalScopeTypeId, WorkerGlobalScopeInit}; use script_task::{ScriptTask, ScriptChan, TimerSource, ScriptPort, StackRootTLS, CommonScriptMsg}; @@ -245,26 +243,20 @@ impl DedicatedWorkerGlobalScope { } } -pub trait DedicatedWorkerGlobalScopeHelpers { - fn script_chan(self) -> Box; - fn pipeline(self) -> PipelineId; - fn new_script_pair(self) -> (Box, Box); - fn process_event(self, msg: CommonScriptMsg); -} -impl<'a> DedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope { - fn script_chan(self) -> Box { +impl DedicatedWorkerGlobalScope { + pub fn script_chan(&self) -> Box { box WorkerThreadWorkerChan { sender: self.own_sender.clone(), worker: self.worker.borrow().as_ref().unwrap().clone(), } } - fn pipeline(self) -> PipelineId { + pub fn pipeline(&self) -> PipelineId { self.id } - fn new_script_pair(self) -> (Box, Box) { + pub fn new_script_pair(&self) -> (Box, Box) { let (tx, rx) = channel(); let chan = box SendableWorkerScriptChan { sender: tx, @@ -273,21 +265,15 @@ impl<'a> DedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope { (chan, box rx) } - fn process_event(self, msg: CommonScriptMsg) { + pub fn process_event(&self, msg: CommonScriptMsg) { self.handle_script_event(WorkerScriptMsg::Common(msg)); } } -trait PrivateDedicatedWorkerGlobalScopeHelpers { - fn handle_script_event(self, msg: WorkerScriptMsg); - fn dispatch_error_to_worker(self, &ErrorEvent); - fn receive_event(self) -> Result; - fn handle_event(self, event: MixedMessage); -} -impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalScope { +impl DedicatedWorkerGlobalScope { #[allow(unsafe_code)] - fn receive_event(self) -> Result { + fn receive_event(&self) -> Result { let scope = WorkerGlobalScopeCast::from_ref(self); let worker_port = &self.receiver; let devtools_port = scope.from_devtools_receiver(); @@ -311,7 +297,7 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS } } - fn handle_script_event(self, msg: WorkerScriptMsg) { + fn handle_script_event(&self, msg: WorkerScriptMsg) { match msg { WorkerScriptMsg::DOMMessage(data) => { let scope = WorkerGlobalScopeCast::from_ref(self); @@ -346,7 +332,7 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS } } - fn handle_event(self, event: MixedMessage) { + fn handle_event(&self, event: MixedMessage) { match event { MixedMessage::FromDevtools(msg) => { let global_ref = GlobalRef::Worker(WorkerGlobalScopeCast::from_ref(self)); @@ -366,16 +352,6 @@ impl<'a> PrivateDedicatedWorkerGlobalScopeHelpers for &'a DedicatedWorkerGlobalS }, } } - - fn dispatch_error_to_worker(self, errorevent: &ErrorEvent) { - let msg = errorevent.Message(); - let file_name = errorevent.Filename(); - let line_num = errorevent.Lineno(); - let col_num = errorevent.Colno(); - let worker = self.worker.borrow().as_ref().unwrap().clone(); - self.parent_sender.send(CommonScriptMsg::RunnableMsg( - box WorkerErrorHandler::new(worker, msg, file_name, line_num, col_num))).unwrap(); - } } impl<'a> DedicatedWorkerGlobalScopeMethods for &'a DedicatedWorkerGlobalScope { diff --git a/servo/components/script/dom/document.rs b/servo/components/script/dom/document.rs index a3b8c56dd9f4..03a9d69fae73 100644 --- a/servo/components/script/dom/document.rs +++ b/servo/components/script/dom/document.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use document_loader::{DocumentLoader, LoadType}; -use dom::attr::{Attr, AttrHelpers, AttrValue}; +use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::DocumentBinding; use dom::bindings::codegen::Bindings::DocumentBinding::{DocumentMethods, DocumentReadyState}; @@ -41,10 +41,9 @@ use dom::customevent::CustomEvent; use dom::documentfragment::DocumentFragment; use dom::documenttype::DocumentType; use dom::domimplementation::DOMImplementation; -use dom::element::{Element, ElementCreator, ElementHelpers, AttributeHandlers}; -use dom::element::{ElementTypeId, ActivationElementHelpers, FocusElementHelpers}; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; -use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers}; +use dom::element::{Element, ElementCreator, ElementTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlanchorelement::HTMLAnchorElement; use dom::htmlbaseelement::HTMLBaseElement; use dom::htmlcollection::{HTMLCollection, CollectionFilter}; @@ -57,7 +56,7 @@ use dom::keyboardevent::KeyboardEvent; use dom::location::Location; use dom::messageevent::MessageEvent; use dom::mouseevent::MouseEvent; -use dom::node::{self, Node, NodeHelpers, NodeTypeId, CloneChildrenFlag, NodeDamage, window_from_node}; +use dom::node::{self, Node, NodeTypeId, CloneChildrenFlag, NodeDamage, window_from_node}; use dom::nodeiterator::NodeIterator; use dom::nodelist::NodeList; use dom::processinginstruction::ProcessingInstruction; @@ -66,7 +65,7 @@ use dom::servohtmlparser::ServoHTMLParser; use dom::text::Text; use dom::treewalker::TreeWalker; use dom::uievent::UIEvent; -use dom::window::{Window, WindowHelpers, ReflowReason}; +use dom::window::{Window, ReflowReason}; use layout_interface::{HitTestResponse, MouseOverResponse}; use layout_interface::{ReflowGoal, ReflowQueryType}; @@ -228,113 +227,35 @@ impl CollectionFilter for AppletsFilter { } } -pub trait DocumentHelpers<'a> { - fn loader(&self) -> Ref; - fn mut_loader(&self) -> RefMut; - fn window(self) -> Root; - fn encoding_name(self) -> Ref<'a, DOMString>; - fn is_html_document(self) -> bool; - fn is_fully_active(self) -> bool; - /// https://dom.spec.whatwg.org/#concept-document-url - fn url(self) -> Url; - /// https://html.spec.whatwg.org/multipage/#fallback-base-url - fn fallback_base_url(self) -> Url; - /// https://html.spec.whatwg.org/multipage/#document-base-url - fn base_url(self) -> Url; - /// Returns the first `base` element in the DOM that has an `href` attribute. - fn base_element(self) -> Option>; - /// Refresh the cached first base element in the DOM. - fn refresh_base_element(self); - fn quirks_mode(self) -> QuirksMode; - fn set_quirks_mode(self, mode: QuirksMode); - fn set_encoding_name(self, name: DOMString); - fn content_changed(self, node: &Node, damage: NodeDamage); - fn content_and_heritage_changed(self, node: &Node, damage: NodeDamage); - fn reflow_if_reflow_timer_expired(self); - fn set_reflow_timeout(self, timeout: u64); - fn disarm_reflow_timeout(self); - fn unregister_named_element(self, to_unregister: &Element, id: Atom); - fn register_named_element(self, element: &Element, id: Atom); - fn find_fragment_node(self, fragid: &str) -> Option>; - fn hit_test(self, point: &Point2D) -> Option; - fn get_nodes_under_mouse(self, point: &Point2D) -> Vec; - fn set_ready_state(self, state: DocumentReadyState); - fn get_focused_element(self) -> Option>; - fn is_scripting_enabled(self) -> bool; - fn begin_focus_transaction(self); - fn request_focus(self, elem: &Element); - fn commit_focus_transaction(self, focus_type: FocusType); - fn title_changed(self); - fn send_title_to_compositor(self); - fn dirty_all_nodes(self); - fn dispatch_key_event(self, - key: Key, - state: KeyState, - modifiers: KeyModifiers, - compositor: &mut IpcSender); - fn node_from_nodes_and_strings(self, nodes: Vec) - -> Fallible>; - fn get_body_attribute(self, local_name: &Atom) -> DOMString; - fn set_body_attribute(self, local_name: &Atom, value: DOMString); - fn fire_mouse_event(self, point: Point2D, - target: &EventTarget, - event_name: String); - fn handle_mouse_event(self, js_runtime: *mut JSRuntime, - button: MouseButton, point: Point2D, - mouse_event_type: MouseEventType); - /// Handles a mouse-move event coming from the compositor. - fn handle_mouse_move_event(self, - js_runtime: *mut JSRuntime, - point: Point2D, - prev_mouse_over_targets: &mut RootedVec>); - - fn set_current_script(self, script: Option<&HTMLScriptElement>); - fn trigger_mozbrowser_event(self, event: MozBrowserEvent); - /// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe - fn request_animation_frame(self, callback: Box) -> i32; - /// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe - fn cancel_animation_frame(self, ident: i32); - /// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks - fn run_the_animation_frame_callbacks(self); - fn prepare_async_load(self, load: LoadType) -> PendingAsyncLoad; - fn load_async(self, load: LoadType, listener: AsyncResponseTarget); - fn load_sync(self, load: LoadType) -> Result<(Metadata, Vec), String>; - fn finish_load(self, load: LoadType); - fn notify_constellation_load(self); - fn set_current_parser(self, script: Option<&ServoHTMLParser>); - fn get_current_parser(self) -> Option>; - fn find_iframe(self, subpage_id: SubpageId) -> Option>; -} - -impl<'a> DocumentHelpers<'a> for &'a Document { +impl Document { #[inline] - fn loader(&self) -> Ref { + pub fn loader(&self) -> Ref { self.loader.borrow() } #[inline] - fn mut_loader(&self) -> RefMut { + pub fn mut_loader(&self) -> RefMut { self.loader.borrow_mut() } #[inline] - fn window(self) -> Root { + pub fn window(&self) -> Root { self.window.root() } #[inline] - fn encoding_name(self) -> Ref<'a, DOMString> { + pub fn encoding_name(&self) -> Ref { self.encoding_name.borrow() } #[inline] - fn is_html_document(self) -> bool { + pub fn is_html_document(&self) -> bool { self.is_html_document } // https://html.spec.whatwg.org/multipage/#fully-active - fn is_fully_active(self) -> bool { + pub fn is_fully_active(&self) -> bool { let window = self.window.root(); let window = window.r(); let browsing_context = window.browsing_context(); @@ -349,12 +270,12 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } // https://dom.spec.whatwg.org/#concept-document-url - fn url(self) -> Url { + pub fn url(&self) -> Url { self.url.clone() } // https://html.spec.whatwg.org/multipage/#fallback-base-url - fn fallback_base_url(self) -> Url { + pub fn fallback_base_url(&self) -> Url { // Step 1: iframe srcdoc (#4767). // Step 2: about:blank with a creator browsing context. // Step 3. @@ -362,7 +283,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } // https://html.spec.whatwg.org/multipage/#document-base-url - fn base_url(self) -> Url { + pub fn base_url(&self) -> Url { match self.base_element() { // Step 1. None => self.fallback_base_url(), @@ -372,12 +293,12 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Returns the first `base` element in the DOM that has an `href` attribute. - fn base_element(self) -> Option> { + pub fn base_element(&self) -> Option> { self.base_element.get().map(Root::from_rooted) } /// Refresh the cached first base element in the DOM. - fn refresh_base_element(self) { + pub fn refresh_base_element(&self) { let base = NodeCast::from_ref(self) .traverse_preorder() .filter_map(HTMLBaseElementCast::to_root) @@ -386,11 +307,11 @@ impl<'a> DocumentHelpers<'a> for &'a Document { self.base_element.set(base.map(|element| JS::from_ref(&*element))); } - fn quirks_mode(self) -> QuirksMode { + pub fn quirks_mode(&self) -> QuirksMode { self.quirks_mode.get() } - fn set_quirks_mode(self, mode: QuirksMode) { + pub fn set_quirks_mode(&self, mode: QuirksMode) { self.quirks_mode.set(mode); if mode == Quirks { @@ -401,21 +322,21 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } } - fn set_encoding_name(self, name: DOMString) { + pub fn set_encoding_name(&self, name: DOMString) { *self.encoding_name.borrow_mut() = name; } - fn content_changed(self, node: &Node, damage: NodeDamage) { + pub fn content_changed(&self, node: &Node, damage: NodeDamage) { node.dirty(damage); } - fn content_and_heritage_changed(self, node: &Node, damage: NodeDamage) { + pub fn content_and_heritage_changed(&self, node: &Node, damage: NodeDamage) { node.force_dirty_ancestors(damage); node.dirty(damage); } /// Reflows and disarms the timer if the reflow timer has expired. - fn reflow_if_reflow_timer_expired(self) { + pub fn reflow_if_reflow_timer_expired(&self) { if let Some(reflow_timeout) = self.reflow_timeout.get() { if time::precise_time_ns() < reflow_timeout { return @@ -432,7 +353,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { /// Schedules a reflow to be kicked off at the given `timeout` (in `time::precise_time_ns()` /// units). This reflow happens even if the event loop is busy. This is used to display initial /// page content during parsing. - fn set_reflow_timeout(self, timeout: u64) { + pub fn set_reflow_timeout(&self, timeout: u64) { if let Some(existing_timeout) = self.reflow_timeout.get() { if existing_timeout < timeout { return @@ -442,12 +363,12 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Disables any pending reflow timeouts. - fn disarm_reflow_timeout(self) { + pub fn disarm_reflow_timeout(&self) { self.reflow_timeout.set(None) } /// Remove any existing association between the provided id and any elements in this document. - fn unregister_named_element(self, + pub fn unregister_named_element(&self, to_unregister: &Element, id: Atom) { debug!("Removing named element from document {:p}: {:p} id={}", self, to_unregister, id); @@ -469,7 +390,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Associate an element present in this document with the provided id. - fn register_named_element(self, + pub fn register_named_element(&self, element: &Element, id: Atom) { debug!("Adding named element to document {:p}: {:p} id={}", self, element, id); @@ -512,7 +433,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { /// Attempt to find a named element in this page's document. /// https://html.spec.whatwg.org/multipage/#the-indicated-part-of-the-document - fn find_fragment_node(self, fragid: &str) -> Option> { + pub fn find_fragment_node(&self, fragid: &str) -> Option> { self.GetElementById(fragid.to_owned()).or_else(|| { let check_anchor = |&node: &&HTMLAnchorElement| { let elem = ElementCast::from_ref(node); @@ -528,7 +449,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { }) } - fn hit_test(self, point: &Point2D) -> Option { + pub fn hit_test(&self, point: &Point2D) -> Option { let root = self.GetDocumentElement(); let root = match root.r() { Some(root) => root, @@ -546,7 +467,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { address } - fn get_nodes_under_mouse(self, point: &Point2D) -> Vec { + pub fn get_nodes_under_mouse(&self, point: &Point2D) -> Vec { let root = self.GetDocumentElement(); let root = match root.r() { Some(root) => root, @@ -561,7 +482,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } // https://html.spec.whatwg.org/multipage/#current-document-readiness - fn set_ready_state(self, state: DocumentReadyState) { + pub fn set_ready_state(&self, state: DocumentReadyState) { self.ready_state.set(state); let window = self.window.root(); @@ -573,24 +494,24 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Return whether scripting is enabled or not - fn is_scripting_enabled(self) -> bool { + pub fn is_scripting_enabled(&self) -> bool { self.scripting_enabled.get() } /// Return the element that currently has focus. // https://dvcs.w3.org/hg/dom3events/raw-file/tip/html/DOM3-Events.html#events-focusevent-doc-focus - fn get_focused_element(self) -> Option> { + pub fn get_focused_element(&self) -> Option> { self.focused.get().map(Root::from_rooted) } /// Initiate a new round of checking for elements requesting focus. The last element to call /// `request_focus` before `commit_focus_transaction` is called will receive focus. - fn begin_focus_transaction(self) { + pub fn begin_focus_transaction(&self) { self.possibly_focused.set(None); } /// Request that the given element receive focus once the current transaction is complete. - fn request_focus(self, elem: &Element) { + pub fn request_focus(&self, elem: &Element) { if elem.is_focusable_area() { self.possibly_focused.set(Some(JS::from_ref(elem))) } @@ -598,7 +519,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { /// Reassign the focus context to the element that last requested focus during this /// transaction, or none if no elements requested it. - fn commit_focus_transaction(self, focus_type: FocusType) { + pub fn commit_focus_transaction(&self, focus_type: FocusType) { //TODO: dispatch blur, focus, focusout, and focusin events if let Some(ref elem) = self.focused.get().map(|t| t.root()) { @@ -624,7 +545,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Handles any updates when the document's title has changed. - fn title_changed(self) { + pub fn title_changed(&self) { // https://developer.mozilla.org/en-US/docs/Web/Events/mozbrowsertitlechange self.trigger_mozbrowser_event(MozBrowserEvent::TitleChange(self.Title())); @@ -632,7 +553,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// Sends this document's title to the compositor. - fn send_title_to_compositor(self) { + pub fn send_title_to_compositor(&self) { let window = self.window(); // FIXME(https://github.com/rust-lang/rust/issues/23338) let window = window.r(); @@ -640,14 +561,14 @@ impl<'a> DocumentHelpers<'a> for &'a Document { compositor.send(ScriptToCompositorMsg::SetTitle(window.pipeline(), Some(self.Title()))).unwrap(); } - fn dirty_all_nodes(self) { + pub fn dirty_all_nodes(&self) { let root = NodeCast::from_ref(self); for node in root.traverse_preorder() { node.r().dirty(NodeDamage::OtherNodeDamage) } } - fn handle_mouse_event(self, js_runtime: *mut JSRuntime, + pub fn handle_mouse_event(&self, js_runtime: *mut JSRuntime, _button: MouseButton, point: Point2D, mouse_event_type: MouseEventType) { let mouse_event_type_string = match mouse_event_type { @@ -721,7 +642,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::MouseEvent); } - fn fire_mouse_event(self, + pub fn fire_mouse_event(&self, point: Point2D, target: &EventTarget, event_name: String) { @@ -744,7 +665,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { event.fire(target); } - fn handle_mouse_move_event(self, + pub fn handle_mouse_move_event(&self, js_runtime: *mut JSRuntime, point: Point2D, prev_mouse_over_targets: &mut RootedVec>) { @@ -808,7 +729,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// The entry point for all key processing for web content - fn dispatch_key_event(self, + pub fn dispatch_key_event(&self, key: Key, state: KeyState, modifiers: KeyModifiers, @@ -887,7 +808,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { window.r().reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::KeyEvent); } - fn node_from_nodes_and_strings(self, nodes: Vec) + pub fn node_from_nodes_and_strings(&self, nodes: Vec) -> Fallible> { if nodes.len() == 1 { match nodes.into_iter().next().unwrap() { @@ -915,7 +836,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } } - fn get_body_attribute(self, local_name: &Atom) -> DOMString { + pub fn get_body_attribute(&self, local_name: &Atom) -> DOMString { match self.GetBody().and_then(HTMLBodyElementCast::to_root) { Some(ref body) => { ElementCast::from_ref(body.r()).get_string_attribute(local_name) @@ -924,17 +845,17 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } } - fn set_body_attribute(self, local_name: &Atom, value: DOMString) { + pub fn set_body_attribute(&self, local_name: &Atom, value: DOMString) { if let Some(ref body) = self.GetBody().and_then(HTMLBodyElementCast::to_root) { ElementCast::from_ref(body.r()).set_string_attribute(local_name, value); } } - fn set_current_script(self, script: Option<&HTMLScriptElement>) { + pub fn set_current_script(&self, script: Option<&HTMLScriptElement>) { self.current_script.set(script.map(JS::from_ref)); } - fn trigger_mozbrowser_event(self, event: MozBrowserEvent) { + pub fn trigger_mozbrowser_event(&self, event: MozBrowserEvent) { if opts::experimental_enabled() { let window = self.window.root(); @@ -949,7 +870,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// https://html.spec.whatwg.org/multipage/#dom-window-requestanimationframe - fn request_animation_frame(self, callback: Box) -> i32 { + pub fn request_animation_frame(&self, callback: Box) -> i32 { let window = self.window.root(); let window = window.r(); let ident = self.animation_frame_ident.get() + 1; @@ -967,7 +888,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// https://html.spec.whatwg.org/multipage/#dom-window-cancelanimationframe - fn cancel_animation_frame(self, ident: i32) { + pub fn cancel_animation_frame(&self, ident: i32) { self.animation_frame_list.borrow_mut().remove(&ident); if self.animation_frame_list.borrow().is_empty() { let window = self.window.root(); @@ -980,7 +901,7 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } /// https://html.spec.whatwg.org/multipage/#run-the-animation-frame-callbacks - fn run_the_animation_frame_callbacks(self) { + pub fn run_the_animation_frame_callbacks(&self) { let animation_frame_list; { let mut list = self.animation_frame_list.borrow_mut(); @@ -1008,27 +929,27 @@ impl<'a> DocumentHelpers<'a> for &'a Document { ReflowReason::RequestAnimationFrame); } - fn prepare_async_load(self, load: LoadType) -> PendingAsyncLoad { + pub fn prepare_async_load(&self, load: LoadType) -> PendingAsyncLoad { let mut loader = self.loader.borrow_mut(); loader.prepare_async_load(load) } - fn load_async(self, load: LoadType, listener: AsyncResponseTarget) { + pub fn load_async(&self, load: LoadType, listener: AsyncResponseTarget) { let mut loader = self.loader.borrow_mut(); loader.load_async(load, listener) } - fn load_sync(self, load: LoadType) -> Result<(Metadata, Vec), String> { + pub fn load_sync(&self, load: LoadType) -> Result<(Metadata, Vec), String> { let mut loader = self.loader.borrow_mut(); loader.load_sync(load) } - fn finish_load(self, load: LoadType) { + pub fn finish_load(&self, load: LoadType) { let mut loader = self.loader.borrow_mut(); loader.finish_load(load); } - fn notify_constellation_load(self) { + pub fn notify_constellation_load(&self) { let window = self.window.root(); let pipeline_id = window.r().pipeline(); let ConstellationChan(ref chan) = window.r().constellation_chan(); @@ -1037,16 +958,16 @@ impl<'a> DocumentHelpers<'a> for &'a Document { } - fn set_current_parser(self, script: Option<&ServoHTMLParser>) { + pub fn set_current_parser(&self, script: Option<&ServoHTMLParser>) { self.current_parser.set(script.map(JS::from_ref)); } - fn get_current_parser(self) -> Option> { + pub fn get_current_parser(&self) -> Option> { self.current_parser.get().map(Root::from_rooted) } /// Find an iframe element in the document. - fn find_iframe(self, subpage_id: SubpageId) -> Option> { + pub fn find_iframe(&self, subpage_id: SubpageId) -> Option> { NodeCast::from_ref(self).traverse_preorder() .filter_map(HTMLIFrameElementCast::to_root) .find(|node| node.r().subpage_id() == Some(subpage_id)) @@ -1171,13 +1092,9 @@ impl Document { } } -trait PrivateDocumentHelpers { - fn create_node_list bool>(self, callback: F) -> Root; - fn get_html_element(self) -> Option>; -} -impl<'a> PrivateDocumentHelpers for &'a Document { - fn create_node_list bool>(self, callback: F) -> Root { +impl Document { + fn create_node_list bool>(&self, callback: F) -> Root { let window = self.window.root(); let doc = self.GetDocumentElement(); let maybe_node = doc.r().map(NodeCast::from_ref); @@ -1186,7 +1103,7 @@ impl<'a> PrivateDocumentHelpers for &'a Document { NodeList::new_simple_list(window.r(), iter) } - fn get_html_element(self) -> Option> { + fn get_html_element(&self) -> Option> { self.GetDocumentElement() .r() .and_then(HTMLHtmlElementCast::to_ref) @@ -1194,12 +1111,9 @@ impl<'a> PrivateDocumentHelpers for &'a Document { } } -trait PrivateClickEventHelpers { - fn click_event_filter_by_disabled_state(self) -> bool; -} -impl<'a> PrivateClickEventHelpers for &'a Node { - fn click_event_filter_by_disabled_state(self) -> bool { +impl Node { + fn click_event_filter_by_disabled_state(&self) -> bool { match self.type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) | NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) | diff --git a/servo/components/script/dom/documentfragment.rs b/servo/components/script/dom/documentfragment.rs index e5e1d81ef395..367628b669f7 100644 --- a/servo/components/script/dom/documentfragment.rs +++ b/servo/components/script/dom/documentfragment.rs @@ -15,7 +15,7 @@ use dom::document::Document; use dom::element::Element; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlcollection::HTMLCollection; -use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::nodelist::NodeList; use util::str::DOMString; diff --git a/servo/components/script/dom/documenttype.rs b/servo/components/script/dom/documenttype.rs index d835dfaccb32..c7f7aa9af93c 100644 --- a/servo/components/script/dom/documenttype.rs +++ b/servo/components/script/dom/documenttype.rs @@ -10,7 +10,7 @@ use dom::bindings::error::ErrorResult; use dom::bindings::js::Root; use dom::document::Document; use dom::eventtarget::{EventTarget, EventTargetTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use util::str::DOMString; use std::borrow::ToOwned; diff --git a/servo/components/script/dom/domimplementation.rs b/servo/components/script/dom/domimplementation.rs index 5cd21c2a780c..cd4b59c7d620 100644 --- a/servo/components/script/dom/domimplementation.rs +++ b/servo/components/script/dom/domimplementation.rs @@ -14,7 +14,7 @@ use dom::bindings::js::{JS, Root}; use dom::bindings::utils::validate_qualified_name; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::document::DocumentSource; -use dom::document::{Document, DocumentHelpers, IsHTMLDocument}; +use dom::document::{Document, IsHTMLDocument}; use dom::documenttype::DocumentType; use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlheadelement::HTMLHeadElement; diff --git a/servo/components/script/dom/domparser.rs b/servo/components/script/dom/domparser.rs index 9b50973d91e9..4c7b1c826307 100644 --- a/servo/components/script/dom/domparser.rs +++ b/servo/components/script/dom/domparser.rs @@ -13,8 +13,8 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::document::DocumentSource; -use dom::document::{Document, DocumentHelpers, IsHTMLDocument}; -use dom::window::{Window, WindowHelpers}; +use dom::document::{Document, IsHTMLDocument}; +use dom::window::Window; use parse::html::{ParseContext, parse_html}; use util::str::DOMString; diff --git a/servo/components/script/dom/domstringmap.rs b/servo/components/script/dom/domstringmap.rs index 8bdff569174e..a26ef3f9bbc5 100644 --- a/servo/components/script/dom/domstringmap.rs +++ b/servo/components/script/dom/domstringmap.rs @@ -8,7 +8,7 @@ use dom::bindings::error::ErrorResult; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::htmlelement::{HTMLElement, HTMLElementCustomAttributeHelpers}; +use dom::htmlelement::HTMLElement; use dom::node::window_from_node; use util::str::DOMString; diff --git a/servo/components/script/dom/domtokenlist.rs b/servo/components/script/dom/domtokenlist.rs index 182bdbe29ce3..5fb08697302f 100644 --- a/servo/components/script/dom/domtokenlist.rs +++ b/servo/components/script/dom/domtokenlist.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::DOMTokenListBinding; use dom::bindings::codegen::Bindings::DOMTokenListBinding::DOMTokenListMethods; use dom::bindings::error::Error::{InvalidCharacter, Syntax}; @@ -10,7 +10,7 @@ use dom::bindings::error::{ErrorResult, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::element::{Element, AttributeHandlers}; +use dom::element::Element; use dom::node::window_from_node; use string_cache::Atom; @@ -42,18 +42,14 @@ impl DOMTokenList { } } -trait PrivateDOMTokenListHelpers { - fn attribute(self) -> Option>; - fn check_token_exceptions(self, token: &str) -> Fallible; -} -impl<'a> PrivateDOMTokenListHelpers for &'a DOMTokenList { - fn attribute(self) -> Option> { +impl DOMTokenList { + fn attribute(&self) -> Option> { let element = self.element.root(); element.r().get_attribute(&ns!(""), &self.local_name) } - fn check_token_exceptions(self, token: &str) -> Fallible { + fn check_token_exceptions(&self, token: &str) -> Fallible { match token { "" => Err(Syntax), slice if slice.find(HTML_SPACE_CHARACTERS).is_some() => Err(InvalidCharacter), diff --git a/servo/components/script/dom/element.rs b/servo/components/script/dom/element.rs index d9a42fc37c7b..21d0a5490cb2 100644 --- a/servo/components/script/dom/element.rs +++ b/servo/components/script/dom/element.rs @@ -6,7 +6,7 @@ use dom::activation::Activatable; use dom::attr::AttrValue; -use dom::attr::{Attr, AttrSettingType, AttrHelpers, AttrHelpersForLayout}; +use dom::attr::{Attr, AttrSettingType, AttrHelpersForLayout}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::ElementBinding; @@ -35,27 +35,26 @@ use dom::bindings::js::{Root, RootedReference}; use dom::bindings::trace::RootedVec; use dom::bindings::utils::XMLName::InvalidXMLName; use dom::bindings::utils::{namespace_from_domstring, xml_name_type, validate_and_extract}; -use dom::characterdata::CharacterDataHelpers; use dom::create::create_element; -use dom::document::{Document, DocumentHelpers, LayoutDocumentHelpers}; +use dom::document::{Document, LayoutDocumentHelpers}; use dom::domrect::DOMRect; use dom::domrectlist::DOMRectList; use dom::domtokenlist::DOMTokenList; -use dom::event::{Event, EventHelpers}; +use dom::event::Event; use dom::eventtarget::{EventTarget, EventTargetTypeId}; -use dom::htmlbodyelement::{HTMLBodyElement, HTMLBodyElementHelpers}; +use dom::htmlbodyelement::HTMLBodyElement; use dom::htmlcollection::HTMLCollection; use dom::htmlelement::HTMLElementTypeId; -use dom::htmlfontelement::{HTMLFontElement, HTMLFontElementHelpers}; -use dom::htmliframeelement::{HTMLIFrameElement, RawHTMLIFrameElementHelpers}; -use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers, HTMLInputElementHelpers}; -use dom::htmltablecellelement::{HTMLTableCellElement, HTMLTableCellElementHelpers}; -use dom::htmltableelement::{HTMLTableElement, HTMLTableElementHelpers}; -use dom::htmltablerowelement::{HTMLTableRowElement, HTMLTableRowElementHelpers}; -use dom::htmltablesectionelement::{HTMLTableSectionElement, HTMLTableSectionElementHelpers}; +use dom::htmlfontelement::HTMLFontElement; +use dom::htmliframeelement::HTMLIFrameElement; +use dom::htmlinputelement::{HTMLInputElement, RawLayoutHTMLInputElementHelpers}; +use dom::htmltablecellelement::HTMLTableCellElement; +use dom::htmltableelement::HTMLTableElement; +use dom::htmltablerowelement::HTMLTableRowElement; +use dom::htmltablesectionelement::HTMLTableSectionElement; use dom::htmltextareaelement::{HTMLTextAreaElement, RawLayoutHTMLTextAreaElementHelpers}; use dom::namednodemap::NamedNodeMap; -use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node, NodeHelpers, NodeTypeId, SEQUENTIALLY_FOCUSABLE}; +use dom::node::{CLICK_IN_PROGRESS, LayoutNodeHelpers, Node, NodeTypeId, SEQUENTIALLY_FOCUSABLE}; use dom::node::{document_from_node, NodeDamage}; use dom::node::{window_from_node}; use dom::nodelist::NodeList; @@ -568,38 +567,18 @@ pub enum StylePriority { Normal, } -pub trait ElementHelpers<'a> { - fn html_element_in_html_document(self) -> bool; - fn local_name(self) -> &'a Atom; - fn parsed_name(self, name: DOMString) -> Atom; - fn namespace(self) -> &'a Namespace; - fn prefix(self) -> &'a Option; - fn attrs(&self) -> Ref>>; - fn attrs_mut(&self) -> RefMut>>; - fn style_attribute(self) -> &'a DOMRefCell>; - fn summarize(self) -> Vec; - fn is_void(self) -> bool; - fn remove_inline_style_property(self, property: &str); - fn update_inline_style(self, property_decl: PropertyDeclaration, style_priority: StylePriority); - fn set_inline_style_property_priority(self, properties: &[&str], style_priority: StylePriority); - fn get_inline_style_declaration(self, property: &Atom) -> Option>; - fn get_important_inline_style_declaration(self, property: &Atom) -> Option>; - fn serialize(self, traversal_scope: TraversalScope) -> Fallible; - fn get_root_element(self) -> Root; - fn lookup_prefix(self, namespace: Namespace) -> Option; -} -impl<'a> ElementHelpers<'a> for &'a Element { - fn html_element_in_html_document(self) -> bool { +impl Element { + pub fn html_element_in_html_document(&self) -> bool { let node = NodeCast::from_ref(self); self.namespace == ns!(HTML) && node.is_in_html_doc() } - fn local_name(self) -> &'a Atom { + pub fn local_name(&self) -> &Atom { &self.local_name } - fn parsed_name(self, name: DOMString) -> Atom { + pub fn parsed_name(&self, name: DOMString) -> Atom { if self.html_element_in_html_document() { Atom::from_slice(&name.to_ascii_lowercase()) } else { @@ -607,27 +586,27 @@ impl<'a> ElementHelpers<'a> for &'a Element { } } - fn namespace(self) -> &'a Namespace { + pub fn namespace(&self) -> &Namespace { &self.namespace } - fn prefix(self) -> &'a Option { + pub fn prefix(&self) -> &Option { &self.prefix } - fn attrs(&self) -> Ref>> { + pub fn attrs(&self) -> Ref>> { self.attrs.borrow() } - fn attrs_mut(&self) -> RefMut>> { + pub fn attrs_mut(&self) -> RefMut>> { self.attrs.borrow_mut() } - fn style_attribute(self) -> &'a DOMRefCell> { + pub fn style_attribute(&self) -> &DOMRefCell> { &self.style_attribute } - fn summarize(self) -> Vec { + pub fn summarize(&self) -> Vec { let attrs = self.Attributes(); let mut summarized = vec!(); for i in 0..attrs.r().Length() { @@ -637,7 +616,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { summarized } - fn is_void(self) -> bool { + pub fn is_void(&self) -> bool { if self.namespace != ns!(HTML) { return false } @@ -651,7 +630,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { } } - fn remove_inline_style_property(self, property: &str) { + pub fn remove_inline_style_property(&self, property: &str) { let mut inline_declarations = self.style_attribute.borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let index = declarations.normal @@ -672,7 +651,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { } } - fn update_inline_style(self, property_decl: PropertyDeclaration, style_priority: StylePriority) { + pub fn update_inline_style(&self, property_decl: PropertyDeclaration, style_priority: StylePriority) { let mut inline_declarations = self.style_attribute().borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let existing_declarations = if style_priority == StylePriority::Important { @@ -706,7 +685,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { }); } - fn set_inline_style_property_priority(self, properties: &[&str], style_priority: StylePriority) { + pub fn set_inline_style_property_priority(&self, properties: &[&str], style_priority: StylePriority) { let mut inline_declarations = self.style_attribute().borrow_mut(); if let &mut Some(ref mut declarations) = &mut *inline_declarations { let (from, to) = if style_priority == StylePriority::Important { @@ -731,7 +710,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { } } - fn get_inline_style_declaration(self, property: &Atom) -> Option> { + pub fn get_inline_style_declaration(&self, property: &Atom) -> Option> { Ref::filter_map(self.style_attribute.borrow(), |inline_declarations| { inline_declarations.as_ref().and_then(|declarations| { declarations.normal @@ -742,7 +721,8 @@ impl<'a> ElementHelpers<'a> for &'a Element { }) } - fn get_important_inline_style_declaration(self, property: &Atom) -> Option> { + pub fn get_important_inline_style_declaration(&self, property: &Atom) + -> Option> { Ref::filter_map(self.style_attribute.borrow(), |inline_declarations| { inline_declarations.as_ref().and_then(|declarations| { declarations.important @@ -752,7 +732,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { }) } - fn serialize(self, traversal_scope: TraversalScope) -> Fallible { + pub fn serialize(&self, traversal_scope: TraversalScope) -> Fallible { let node = NodeCast::from_ref(self); let mut writer = vec![]; match serialize(&mut writer, &node, @@ -766,7 +746,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { } // https://html.spec.whatwg.org/multipage/#root-element - fn get_root_element(self) -> Root { + pub fn get_root_element(&self) -> Root { let node = NodeCast::from_ref(self); node.inclusive_ancestors() .filter_map(ElementCast::to_root) @@ -775,7 +755,7 @@ impl<'a> ElementHelpers<'a> for &'a Element { } // https://dom.spec.whatwg.org/#locate-a-namespace-prefix - fn lookup_prefix(self, namespace: Namespace) -> Option { + pub fn lookup_prefix(&self, namespace: Namespace) -> Option { for node in NodeCast::from_ref(self).inclusive_ancestors() { match ElementCast::to_ref(node.r()) { Some(element) => { @@ -803,16 +783,9 @@ impl<'a> ElementHelpers<'a> for &'a Element { } } -pub trait FocusElementHelpers { - /// https://html.spec.whatwg.org/multipage/#focusable-area - fn is_focusable_area(self) -> bool; - /// https://html.spec.whatwg.org/multipage/#concept-element-disabled - fn is_actually_disabled(self) -> bool; -} - -impl<'a> FocusElementHelpers for &'a Element { - fn is_focusable_area(self) -> bool { +impl Element { + pub fn is_focusable_area(&self) -> bool { if self.is_actually_disabled() { return false; } @@ -833,7 +806,7 @@ impl<'a> FocusElementHelpers for &'a Element { } } - fn is_actually_disabled(self) -> bool { + pub fn is_actually_disabled(&self) -> bool { let node = NodeCast::from_ref(self); match node.type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLButtonElement)) | @@ -852,58 +825,9 @@ impl<'a> FocusElementHelpers for &'a Element { } } -pub trait AttributeHandlers { - /// Returns the attribute with given namespace and case-sensitive local - /// name, if any. - fn get_attribute(self, namespace: &Namespace, local_name: &Atom) - -> Option>; - /// Returns the first attribute with any namespace and given case-sensitive - /// name, if any. - fn get_attribute_by_name(self, name: DOMString) -> Option>; - fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec>); - fn set_attribute_from_parser(self, - name: QualName, - value: DOMString, - prefix: Option); - fn set_attribute(self, name: &Atom, value: AttrValue); - fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult; - fn do_set_attribute(self, local_name: Atom, value: AttrValue, - name: Atom, namespace: Namespace, - prefix: Option, cb: F) - where F: Fn(&Attr) -> bool; - fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, - value: DOMString) -> AttrValue; - /// Removes the first attribute with any given namespace and case-sensitive local - /// name, if any. - fn remove_attribute(self, namespace: &Namespace, local_name: &Atom) - -> Option>; - /// Removes the first attribute with any namespace and given case-sensitive name. - fn remove_attribute_by_name(self, name: &Atom) -> Option>; - /// Removes the first attribute that satisfies `find`. - fn do_remove_attribute(self, find: F) -> Option> - where F: Fn(&Attr) -> bool; - - fn has_class(self, name: &Atom) -> bool; - - fn set_atomic_attribute(self, local_name: &Atom, value: DOMString); - - // https://www.whatwg.org/html/#reflecting-content-attributes-in-idl-attributes - fn has_attribute(self, local_name: &Atom) -> bool; - fn set_bool_attribute(self, local_name: &Atom, value: bool); - fn get_url_attribute(self, local_name: &Atom) -> DOMString; - fn set_url_attribute(self, local_name: &Atom, value: DOMString); - fn get_string_attribute(self, local_name: &Atom) -> DOMString; - fn set_string_attribute(self, local_name: &Atom, value: DOMString); - fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec; - fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString); - fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec); - fn get_uint_attribute(self, local_name: &Atom, default: u32) -> u32; - fn set_uint_attribute(self, local_name: &Atom, value: u32); -} - -impl<'a> AttributeHandlers for &'a Element { - fn get_attribute(self, namespace: &Namespace, local_name: &Atom) -> Option> { +impl Element { + pub fn get_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option> { let mut attributes = RootedVec::new(); self.get_attributes(local_name, &mut attributes); attributes.r().iter() @@ -912,14 +836,14 @@ impl<'a> AttributeHandlers for &'a Element { } // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name - fn get_attribute_by_name(self, name: DOMString) -> Option> { + pub fn get_attribute_by_name(&self, name: DOMString) -> Option> { let name = &self.parsed_name(name); self.attrs.borrow().iter().map(|attr| attr.root()) .find(|a| a.r().name() == name) } // https://dom.spec.whatwg.org/#concept-element-attributes-get-by-name - fn get_attributes(self, local_name: &Atom, attributes: &mut RootedVec>) { + pub fn get_attributes(&self, local_name: &Atom, attributes: &mut RootedVec>) { for ref attr in self.attrs.borrow().iter() { let attr = attr.root(); if attr.r().local_name() == local_name { @@ -928,7 +852,7 @@ impl<'a> AttributeHandlers for &'a Element { } } - fn set_attribute_from_parser(self, + pub fn set_attribute_from_parser(&self, qname: QualName, value: DOMString, prefix: Option) { @@ -949,7 +873,7 @@ impl<'a> AttributeHandlers for &'a Element { self.do_set_attribute(qname.local, value, name, qname.ns, prefix, |_| false) } - fn set_attribute(self, name: &Atom, value: AttrValue) { + pub fn set_attribute(&self, name: &Atom, value: AttrValue) { assert!(&**name == name.to_ascii_lowercase()); assert!(!name.contains(":")); @@ -958,7 +882,7 @@ impl<'a> AttributeHandlers for &'a Element { } // https://html.spec.whatwg.org/multipage/#attr-data-* - fn set_custom_attribute(self, name: DOMString, value: DOMString) -> ErrorResult { + pub fn set_custom_attribute(&self, name: DOMString, value: DOMString) -> ErrorResult { // Step 1. match xml_name_type(&name) { InvalidXMLName => return Err(InvalidCharacter), @@ -974,7 +898,7 @@ impl<'a> AttributeHandlers for &'a Element { Ok(()) } - fn do_set_attribute(self, + pub fn do_set_attribute(&self, local_name: Atom, value: AttrValue, name: Atom, @@ -1000,7 +924,7 @@ impl<'a> AttributeHandlers for &'a Element { (*self.attrs.borrow())[idx].root().r().set_value(set_type, value, self); } - fn parse_attribute(self, namespace: &Namespace, local_name: &Atom, + pub fn parse_attribute(&self, namespace: &Namespace, local_name: &Atom, value: DOMString) -> AttrValue { if *namespace == ns!("") { vtable_for(&NodeCast::from_ref(self)) @@ -1010,18 +934,18 @@ impl<'a> AttributeHandlers for &'a Element { } } - fn remove_attribute(self, namespace: &Namespace, local_name: &Atom) + pub fn remove_attribute(&self, namespace: &Namespace, local_name: &Atom) -> Option> { self.do_remove_attribute(|attr| { attr.namespace() == namespace && attr.local_name() == local_name }) } - fn remove_attribute_by_name(self, name: &Atom) -> Option> { + pub fn remove_attribute_by_name(&self, name: &Atom) -> Option> { self.do_remove_attribute(|attr| attr.name() == name) } - fn do_remove_attribute(self, find: F) -> Option> + pub fn do_remove_attribute(&self, find: F) -> Option> where F: Fn(&Attr) -> bool { let idx = self.attrs.borrow().iter() @@ -1054,7 +978,7 @@ impl<'a> AttributeHandlers for &'a Element { }) } - fn has_class(self, name: &Atom) -> bool { + pub fn has_class(&self, name: &Atom) -> bool { let quirks_mode = { let node = NodeCast::from_ref(self); let owner_doc = node.owner_doc(); @@ -1071,20 +995,20 @@ impl<'a> AttributeHandlers for &'a Element { }).unwrap_or(false) } - fn set_atomic_attribute(self, local_name: &Atom, value: DOMString) { + pub fn set_atomic_attribute(&self, local_name: &Atom, value: DOMString) { assert!(&**local_name == local_name.to_ascii_lowercase()); let value = AttrValue::from_atomic(value); self.set_attribute(local_name, value); } - fn has_attribute(self, local_name: &Atom) -> bool { + pub fn has_attribute(&self, local_name: &Atom) -> bool { assert!(local_name.bytes().all(|b| b.to_ascii_lowercase() == b)); self.attrs.borrow().iter().map(|attr| attr.root()).any(|attr| { attr.r().local_name() == local_name && attr.r().namespace() == &ns!("") }) } - fn set_bool_attribute(self, local_name: &Atom, value: bool) { + pub fn set_bool_attribute(&self, local_name: &Atom, value: bool) { if self.has_attribute(local_name) == value { return; } if value { self.set_string_attribute(local_name, String::new()); @@ -1093,7 +1017,7 @@ impl<'a> AttributeHandlers for &'a Element { } } - fn get_url_attribute(self, local_name: &Atom) -> DOMString { + pub fn get_url_attribute(&self, local_name: &Atom) -> DOMString { assert!(&**local_name == local_name.to_ascii_lowercase()); if !self.has_attribute(local_name) { return "".to_owned(); @@ -1108,22 +1032,22 @@ impl<'a> AttributeHandlers for &'a Element { Err(_) => "".to_owned() } } - fn set_url_attribute(self, local_name: &Atom, value: DOMString) { + pub fn set_url_attribute(&self, local_name: &Atom, value: DOMString) { self.set_string_attribute(local_name, value); } - fn get_string_attribute(self, local_name: &Atom) -> DOMString { + pub fn get_string_attribute(&self, local_name: &Atom) -> DOMString { match self.get_attribute(&ns!(""), local_name) { Some(x) => x.r().Value(), None => "".to_owned() } } - fn set_string_attribute(self, local_name: &Atom, value: DOMString) { + pub fn set_string_attribute(&self, local_name: &Atom, value: DOMString) { assert!(&**local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::String(value)); } - fn get_tokenlist_attribute(self, local_name: &Atom) -> Vec { + pub fn get_tokenlist_attribute(&self, local_name: &Atom) -> Vec { self.get_attribute(&ns!(""), local_name).map(|attr| { attr.r() .value() @@ -1133,17 +1057,17 @@ impl<'a> AttributeHandlers for &'a Element { }).unwrap_or(vec!()) } - fn set_tokenlist_attribute(self, local_name: &Atom, value: DOMString) { + pub fn set_tokenlist_attribute(&self, local_name: &Atom, value: DOMString) { assert!(&**local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::from_serialized_tokenlist(value)); } - fn set_atomic_tokenlist_attribute(self, local_name: &Atom, tokens: Vec) { + pub fn set_atomic_tokenlist_attribute(&self, local_name: &Atom, tokens: Vec) { assert!(&**local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::from_atomic_tokens(tokens)); } - fn get_uint_attribute(self, local_name: &Atom, default: u32) -> u32 { + pub fn get_uint_attribute(&self, local_name: &Atom, default: u32) -> u32 { assert!(local_name.chars().all(|ch| { !ch.is_ascii() || ch.to_ascii_lowercase() == ch })); @@ -1159,7 +1083,7 @@ impl<'a> AttributeHandlers for &'a Element { None => default, } } - fn set_uint_attribute(self, local_name: &Atom, value: u32) { + pub fn set_uint_attribute(&self, local_name: &Atom, value: u32) { assert!(&**local_name == local_name.to_ascii_lowercase()); self.set_attribute(local_name, AttrValue::UInt(value.to_string(), value)); } @@ -1744,7 +1668,7 @@ impl<'a> ::selectors::Element for Root { } fn get_local_name<'b>(&'b self) -> &'b Atom { - ElementHelpers::local_name(&**self) + self.local_name() } fn get_namespace<'b>(&'b self) -> &'b Namespace { self.namespace() @@ -1795,7 +1719,7 @@ impl<'a> ::selectors::Element for Root { } } fn has_class(&self, name: &Atom) -> bool { - AttributeHandlers::has_class(&**self, name) + Element::has_class(&**self, name) } fn each_class(&self, mut callback: F) where F: FnMut(&Atom) @@ -1856,16 +1780,9 @@ impl<'a> ::selectors::Element for Root { } } -pub trait ActivationElementHelpers<'a> { - fn as_maybe_activatable(self) -> Option<&'a (Activatable + 'a)>; - fn click_in_progress(self) -> bool; - fn set_click_in_progress(self, click: bool); - fn nearest_activable_element(self) -> Option>; - fn authentic_click_activation<'b>(self, event: &'b Event); -} -impl<'a> ActivationElementHelpers<'a> for &'a Element { - fn as_maybe_activatable(self) -> Option<&'a (Activatable + 'a)> { +impl Element { + pub fn as_maybe_activatable<'a>(&'a self) -> Option<&'a (Activatable + 'a)> { let node = NodeCast::from_ref(self); let element = match node.type_id() { NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLInputElement)) => { @@ -1889,18 +1806,18 @@ impl<'a> ActivationElementHelpers<'a> for &'a Element { }) } - fn click_in_progress(self) -> bool { + pub fn click_in_progress(&self) -> bool { let node = NodeCast::from_ref(self); node.get_flag(CLICK_IN_PROGRESS) } - fn set_click_in_progress(self, click: bool) { + pub fn set_click_in_progress(&self, click: bool) { let node = NodeCast::from_ref(self); node.set_flag(CLICK_IN_PROGRESS, click) } // https://html.spec.whatwg.org/multipage/#nearest-activatable-element - fn nearest_activable_element(self) -> Option> { + pub fn nearest_activable_element(&self) -> Option> { match self.as_maybe_activatable() { Some(el) => Some(Root::from_ref(el.as_element())), None => { @@ -1923,7 +1840,7 @@ impl<'a> ActivationElementHelpers<'a> for &'a Element { /// /// Use an element's synthetic click activation (or handle_event) for any script-triggered clicks. /// If the spec says otherwise, check with Manishearth first - fn authentic_click_activation<'b>(self, event: &'b Event) { + pub fn authentic_click_activation<'b>(&self, event: &'b Event) { // Not explicitly part of the spec, however this helps enforce the invariants // required to save state between pre-activation and post-activation // since we cannot nest authentic clicks (unlike synthetic click activation, where diff --git a/servo/components/script/dom/event.rs b/servo/components/script/dom/event.rs index aa2f856bf308..320486cf1db3 100644 --- a/servo/components/script/dom/event.rs +++ b/servo/components/script/dom/event.rs @@ -9,7 +9,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::eventtarget::{EventTarget, EventTargetHelpers}; +use dom::eventtarget::EventTarget; use dom::uievent::{UIEventTypeId}; use util::str::DOMString; @@ -257,18 +257,14 @@ impl<'a> EventMethods for &'a Event { } } -pub trait EventHelpers { - fn set_trusted(self, trusted: bool); - fn fire(self, target: &EventTarget) -> bool; -} -impl<'a> EventHelpers for &'a Event { - fn set_trusted(self, trusted: bool) { +impl Event { + pub fn set_trusted(&self, trusted: bool) { self.trusted.set(trusted); } // https://html.spec.whatwg.org/multipage/#fire-a-simple-event - fn fire(self, target: &EventTarget) -> bool { + pub fn fire(&self, target: &EventTarget) -> bool { self.set_trusted(true); target.dispatch_event(self) } diff --git a/servo/components/script/dom/eventdispatcher.rs b/servo/components/script/dom/eventdispatcher.rs index 0f6f5bda40ea..024ba6a13504 100644 --- a/servo/components/script/dom/eventdispatcher.rs +++ b/servo/components/script/dom/eventdispatcher.rs @@ -9,7 +9,7 @@ use dom::bindings::js::JS; use dom::bindings::trace::RootedVec; use dom::event::{Event, EventPhase}; use dom::eventtarget::{EventTarget, ListenerPhase}; -use dom::node::{Node, NodeHelpers}; +use dom::node::Node; use dom::virtualmethods::vtable_for; // See https://dom.spec.whatwg.org/#concept-event-dispatch for the full dispatch algorithm diff --git a/servo/components/script/dom/eventtarget.rs b/servo/components/script/dom/eventtarget.rs index c492919da829..ed50a6b0fa93 100644 --- a/servo/components/script/dom/eventtarget.rs +++ b/servo/components/script/dom/eventtarget.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::Bindings::EventTargetBinding::EventTargetMethods; use dom::bindings::error::Error::InvalidState; use dom::bindings::error::{Fallible, report_pending_exception}; use dom::bindings::utils::{Reflectable, Reflector}; -use dom::event::{Event, EventHelpers}; +use dom::event::Event; use dom::eventdispatcher::dispatch_event; use dom::node::NodeTypeId; use dom::virtualmethods::VirtualMethods; @@ -165,40 +165,19 @@ impl EventTarget { } } -pub trait EventTargetHelpers { - fn dispatch_event_with_target(self, - target: &EventTarget, - event: &Event) -> bool; - fn dispatch_event(self, event: &Event) -> bool; - fn set_inline_event_listener(self, - ty: DOMString, - listener: Option>); - fn get_inline_event_listener(self, ty: DOMString) -> Option>; - fn set_event_handler_uncompiled(self, - cx: *mut JSContext, - url: Url, - scope: HandleObject, - ty: &str, - source: DOMString); - fn set_event_handler_common(self, ty: &str, - listener: Option>); - fn get_event_handler_common(self, ty: &str) -> Option>; - fn has_handlers(self) -> bool; -} - -impl<'a> EventTargetHelpers for &'a EventTarget { - fn dispatch_event_with_target(self, +impl EventTarget { + pub fn dispatch_event_with_target(&self, target: &EventTarget, event: &Event) -> bool { dispatch_event(self, Some(target), event) } - fn dispatch_event(self, event: &Event) -> bool { + pub fn dispatch_event(&self, event: &Event) -> bool { dispatch_event(self, None, event) } - fn set_inline_event_listener(self, + pub fn set_inline_event_listener(&self, ty: DOMString, listener: Option>) { let mut handlers = self.handlers.borrow_mut(); @@ -234,7 +213,7 @@ impl<'a> EventTargetHelpers for &'a EventTarget { } } - fn get_inline_event_listener(self, ty: DOMString) -> Option> { + pub fn get_inline_event_listener(&self, ty: DOMString) -> Option> { let handlers = self.handlers.borrow(); let entries = handlers.get(&ty); entries.and_then(|entries| entries.iter().filter_map(|entry| { @@ -246,7 +225,7 @@ impl<'a> EventTargetHelpers for &'a EventTarget { } #[allow(unsafe_code)] - fn set_event_handler_uncompiled(self, + pub fn set_event_handler_uncompiled(&self, cx: *mut JSContext, url: Url, scope: HandleObject, @@ -287,20 +266,20 @@ impl<'a> EventTargetHelpers for &'a EventTarget { self.set_event_handler_common(ty, Some(EventHandlerNonNull::new(funobj))); } - fn set_event_handler_common( - self, ty: &str, listener: Option>) + pub fn set_event_handler_common( + &self, ty: &str, listener: Option>) { let event_listener = listener.map(|listener| EventHandlerNonNull::new(listener.callback())); self.set_inline_event_listener(ty.to_owned(), event_listener); } - fn get_event_handler_common(self, ty: &str) -> Option> { + pub fn get_event_handler_common(&self, ty: &str) -> Option> { let listener = self.get_inline_event_listener(ty.to_owned()); listener.map(|listener| CallbackContainer::new(listener.parent.callback())) } - fn has_handlers(self) -> bool { + pub fn has_handlers(&self) -> bool { !self.handlers.borrow().is_empty() } } diff --git a/servo/components/script/dom/filereader.rs b/servo/components/script/dom/filereader.rs index b50752b85696..327b75c9b998 100644 --- a/servo/components/script/dom/filereader.rs +++ b/servo/components/script/dom/filereader.rs @@ -12,10 +12,10 @@ use dom::bindings::global::{GlobalRef, GlobalField}; use dom::bindings::js::{Root, JS, MutNullableHeap}; use dom::bindings::refcounted::Trusted; use dom::bindings::utils::{reflect_dom_object, Reflectable}; -use dom::blob::{Blob, BlobHelpers}; +use dom::blob::Blob; use dom::domexception::{DOMException, DOMErrorName}; -use dom::event::{EventHelpers, EventCancelable, EventBubbles}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::event::{EventCancelable, EventBubbles}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::progressevent::ProgressEvent; use encoding::all::UTF_8; use encoding::label::encoding_from_whatwg_label; @@ -305,15 +305,9 @@ impl<'a> FileReaderMethods for &'a FileReader { } } -trait PrivateFileReaderHelpers { - fn dispatch_progress_event(self, type_: DOMString, loaded: u64, total: Option); - fn terminate_ongoing_reading(self); - fn read(self, function: FileReaderFunction, blob: &Blob, label: Option) -> ErrorResult; - fn change_ready_state(self, state: FileReaderReadyState); -} -impl<'a> PrivateFileReaderHelpers for &'a FileReader { - fn dispatch_progress_event(self, type_: DOMString, loaded: u64, total: Option) { +impl FileReader { + fn dispatch_progress_event(&self, type_: DOMString, loaded: u64, total: Option) { let global = self.global.root(); let progressevent = ProgressEvent::new(global.r(), @@ -325,12 +319,12 @@ impl<'a> PrivateFileReaderHelpers for &'a FileReader { event.fire(target); } - fn terminate_ongoing_reading(self) { + fn terminate_ongoing_reading(&self) { let GenerationId(prev_id) = self.generation_id.get(); self.generation_id.set(GenerationId(prev_id + 1)); } - fn read(self, function: FileReaderFunction, blob: &Blob, label: Option) -> ErrorResult { + fn read(&self, function: FileReaderFunction, blob: &Blob, label: Option) -> ErrorResult { let root = self.global.root(); let global = root.r(); // Step 1 @@ -368,7 +362,7 @@ impl<'a> PrivateFileReaderHelpers for &'a FileReader { Ok(()) } - fn change_ready_state(self, state: FileReaderReadyState) { + fn change_ready_state(&self, state: FileReaderReadyState) { self.ready_state.set(state); } } diff --git a/servo/components/script/dom/formdata.rs b/servo/components/script/dom/formdata.rs index 35fafb8400c4..c2b144f911e1 100644 --- a/servo/components/script/dom/formdata.rs +++ b/servo/components/script/dom/formdata.rs @@ -120,12 +120,9 @@ impl<'a> FormDataMethods for &'a FormData { } } -trait PrivateFormDataHelpers { - fn get_file_from_blob(self, value: &Blob, filename: Option) -> Root; -} -impl<'a> PrivateFormDataHelpers for &'a FormData { - fn get_file_from_blob(self, value: &Blob, filename: Option) -> Root { +impl FormData { + fn get_file_from_blob(&self, value: &Blob, filename: Option) -> Root { let global = self.global.root(); let f: Option<&File> = FileCast::to_ref(value); let name = filename.unwrap_or(f.map(|inner| inner.name().clone()).unwrap_or("blob".to_owned())); diff --git a/servo/components/script/dom/htmlanchorelement.rs b/servo/components/script/dom/htmlanchorelement.rs index ea564d341c9b..83cf873e7e9d 100644 --- a/servo/components/script/dom/htmlanchorelement.rs +++ b/servo/components/script/dom/htmlanchorelement.rs @@ -14,15 +14,14 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLAnchorElementDerived, HTMLImageElementDerived}; use dom::bindings::codegen::InheritTypes::{MouseEventCast, NodeCast}; use dom::bindings::js::{JS, MutNullableHeap, Root}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::domtokenlist::DOMTokenList; -use dom::element::{Element, AttributeHandlers, ElementTypeId}; +use dom::element::{Element, ElementTypeId}; use dom::event::Event; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::node::{Node, NodeTypeId, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use util::str::DOMString; diff --git a/servo/components/script/dom/htmlappletelement.rs b/servo/components/script/dom/htmlappletelement.rs index 1c108c0b9c0f..ddc718477b31 100644 --- a/servo/components/script/dom/htmlappletelement.rs +++ b/servo/components/script/dom/htmlappletelement.rs @@ -10,7 +10,7 @@ use dom::bindings::codegen::InheritTypes::HTMLAppletElementDerived; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::{AttributeHandlers, ElementTypeId}; +use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId}; diff --git a/servo/components/script/dom/htmlareaelement.rs b/servo/components/script/dom/htmlareaelement.rs index 6befbed67434..ea5d255cf203 100644 --- a/servo/components/script/dom/htmlareaelement.rs +++ b/servo/components/script/dom/htmlareaelement.rs @@ -14,7 +14,7 @@ use dom::domtokenlist::DOMTokenList; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use std::default::Default; diff --git a/servo/components/script/dom/htmlbaseelement.rs b/servo/components/script/dom/htmlbaseelement.rs index ed1c1b86cf72..0a6e0ed8d0a3 100644 --- a/servo/components/script/dom/htmlbaseelement.rs +++ b/servo/components/script/dom/htmlbaseelement.rs @@ -2,14 +2,14 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLBaseElementBinding; use dom::bindings::codegen::InheritTypes::ElementCast; use dom::bindings::codegen::InheritTypes::HTMLBaseElementDerived; use dom::bindings::codegen::InheritTypes::HTMLElementCast; use dom::bindings::js::Root; -use dom::document::{Document, DocumentHelpers}; -use dom::element::{ElementTypeId, AttributeHandlers}; +use dom::document::Document; +use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId, document_from_node}; diff --git a/servo/components/script/dom/htmlbodyelement.rs b/servo/components/script/dom/htmlbodyelement.rs index 03766c06ecc8..b63e7428e8a3 100644 --- a/servo/components/script/dom/htmlbodyelement.rs +++ b/servo/components/script/dom/htmlbodyelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLBodyElementBinding::{self, HTMLBodyElementMethods}; @@ -11,13 +11,12 @@ use dom::bindings::codegen::InheritTypes::{EventTargetCast}; use dom::bindings::codegen::InheritTypes::{HTMLBodyElementDerived, HTMLElementCast}; use dom::bindings::js::Root; use dom::bindings::utils::Reflectable; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::element::ElementTypeId; -use dom::eventtarget::{EventTarget, EventTargetTypeId, EventTargetHelpers}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::{Node, NodeTypeId, window_from_node, document_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::Msg as ConstellationMsg; @@ -87,18 +86,14 @@ impl<'a> HTMLBodyElementMethods for &'a HTMLBodyElement { } } -pub trait HTMLBodyElementHelpers { - fn get_background_color(self) -> Option; - fn get_background(self) -> Option; -} -impl<'a> HTMLBodyElementHelpers for &'a HTMLBodyElement { - fn get_background_color(self) -> Option { +impl HTMLBodyElement { + pub fn get_background_color(&self) -> Option { self.background_color.get() } #[allow(unsafe_code)] - fn get_background(self) -> Option { + pub fn get_background(&self) -> Option { unsafe { self.background.borrow_for_layout().clone() } diff --git a/servo/components/script/dom/htmlbuttonelement.rs b/servo/components/script/dom/htmlbuttonelement.rs index 798e17ff918d..9ff0a597657e 100644 --- a/servo/components/script/dom/htmlbuttonelement.rs +++ b/servo/components/script/dom/htmlbuttonelement.rs @@ -4,21 +4,19 @@ use dom::activation::Activatable; use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding; use dom::bindings::codegen::Bindings::HTMLButtonElementBinding::HTMLButtonElementMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLButtonElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{HTMLButtonElementDerived, HTMLFieldSetElementDerived}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::ActivationElementHelpers; -use dom::element::{AttributeHandlers, Element, ElementTypeId}; +use dom::element::{Element, ElementTypeId}; use dom::event::Event; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::htmlformelement::{FormSubmitter, FormControl, HTMLFormElementHelpers}; +use dom::htmlformelement::{FormSubmitter, FormControl}; use dom::htmlformelement::{SubmittedFrom}; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::node::{Node, NodeTypeId, document_from_node, window_from_node}; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; diff --git a/servo/components/script/dom/htmlcanvaselement.rs b/servo/components/script/dom/htmlcanvaselement.rs index 35f030f8def2..e0e8e3d2e084 100644 --- a/servo/components/script/dom/htmlcanvaselement.rs +++ b/servo/components/script/dom/htmlcanvaselement.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding; use dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::HTMLCanvasElementMethods; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLContextAttributes; @@ -15,7 +14,6 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableHeap, HeapGCValue, Root}; use dom::bindings::utils::{Reflectable}; use dom::canvasrenderingcontext2d::{CanvasRenderingContext2D, LayoutCanvasRenderingContext2DHelpers}; use dom::document::Document; -use dom::element::AttributeHandlers; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; @@ -153,17 +151,9 @@ impl LayoutHTMLCanvasElementHelpers for LayoutJS { } } -pub trait HTMLCanvasElementHelpers { - fn get_or_init_2d_context(self) -> Option>; - fn get_or_init_webgl_context(self, - cx: *mut JSContext, - attrs: Option) -> Option>; - fn is_valid(self) -> bool; -} - -impl<'a> HTMLCanvasElementHelpers for &'a HTMLCanvasElement { - fn get_or_init_2d_context(self) -> Option> { +impl HTMLCanvasElement { + pub fn get_or_init_2d_context(&self) -> Option> { if self.context.get().is_none() { let window = window_from_node(self); let size = self.get_size(); @@ -177,7 +167,7 @@ impl<'a> HTMLCanvasElementHelpers for &'a HTMLCanvasElement { } } - fn get_or_init_webgl_context(self, + pub fn get_or_init_webgl_context(&self, cx: *mut JSContext, attrs: Option) -> Option> { if self.context.get().is_none() { @@ -210,7 +200,7 @@ impl<'a> HTMLCanvasElementHelpers for &'a HTMLCanvasElement { } } - fn is_valid(self) -> bool { + pub fn is_valid(&self) -> bool { self.height.get() != 0 && self.width.get() != 0 } } diff --git a/servo/components/script/dom/htmlcollection.rs b/servo/components/script/dom/htmlcollection.rs index 142bc6d73efe..19274579eeab 100644 --- a/servo/components/script/dom/htmlcollection.rs +++ b/servo/components/script/dom/htmlcollection.rs @@ -9,8 +9,8 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{namespace_from_domstring, Reflector, reflect_dom_object}; -use dom::element::{Element, AttributeHandlers, ElementHelpers}; -use dom::node::{Node, NodeHelpers, TreeIterator}; +use dom::element::Element; +use dom::node::{Node, TreeIterator}; use dom::window::Window; use util::str::{DOMString, split_html_space_chars}; diff --git a/servo/components/script/dom/htmlelement.rs b/servo/components/script/dom/htmlelement.rs index 01b222fd5397..e525e8d81e55 100644 --- a/servo/components/script/dom/htmlelement.rs +++ b/servo/components/script/dom/htmlelement.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::attr::AttrValue; use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::HTMLElementBinding; @@ -18,16 +17,15 @@ use dom::bindings::error::ErrorResult; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::Reflectable; use dom::cssstyledeclaration::{CSSStyleDeclaration, CSSModificationAccess}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::domstringmap::DOMStringMap; -use dom::element::{Element, ElementTypeId, ActivationElementHelpers, AttributeHandlers}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::element::{Element, ElementTypeId}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlinputelement::HTMLInputElement; use dom::htmlmediaelement::HTMLMediaElementTypeId; use dom::htmltablecellelement::HTMLTableCellElementTypeId; -use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node, SEQUENTIALLY_FOCUSABLE}; +use dom::node::{Node, NodeTypeId, document_from_node, window_from_node, SEQUENTIALLY_FOCUSABLE}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use msg::constellation_msg::FocusType; use util::str::DOMString; @@ -81,18 +79,14 @@ impl HTMLElement { } } -trait PrivateHTMLElementHelpers { - fn is_body_or_frameset(self) -> bool; - fn update_sequentially_focusable_status(self); -} -impl<'a> PrivateHTMLElementHelpers for &'a HTMLElement { - fn is_body_or_frameset(self) -> bool { +impl HTMLElement { + fn is_body_or_frameset(&self) -> bool { let eventtarget = EventTargetCast::from_ref(self); eventtarget.is_htmlbodyelement() || eventtarget.is_htmlframesetelement() } - fn update_sequentially_focusable_status(self) { + fn update_sequentially_focusable_status(&self) { let element = ElementCast::from_ref(self); let node = NodeCast::from_ref(self); if element.has_attribute(&atom!("tabindex")) { @@ -276,11 +270,6 @@ impl<'a> HTMLElementMethods for &'a HTMLElement { } // https://html.spec.whatwg.org/#attr-data-* -pub trait HTMLElementCustomAttributeHelpers { - fn set_custom_attr(self, name: DOMString, value: DOMString) -> ErrorResult; - fn get_custom_attr(self, name: DOMString) -> Option; - fn delete_custom_attr(self, name: DOMString); -} fn to_snake_case(name: DOMString) -> DOMString { let mut attr_name = "data-".to_owned(); @@ -295,8 +284,8 @@ fn to_snake_case(name: DOMString) -> DOMString { attr_name } -impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement { - fn set_custom_attr(self, name: DOMString, value: DOMString) -> ErrorResult { +impl HTMLElement { + pub fn set_custom_attr(&self, name: DOMString, value: DOMString) -> ErrorResult { if name.chars() .skip_while(|&ch| ch != '\u{2d}') .nth(1).map_or(false, |ch| ch >= 'a' && ch <= 'z') { @@ -306,7 +295,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement { element.set_custom_attribute(to_snake_case(name), value) } - fn get_custom_attr(self, local_name: DOMString) -> Option { + pub fn get_custom_attr(&self, local_name: DOMString) -> Option { let element = ElementCast::from_ref(self); let local_name = Atom::from_slice(&to_snake_case(local_name)); element.get_attribute(&ns!(""), &local_name).map(|attr| { @@ -314,7 +303,7 @@ impl<'a> HTMLElementCustomAttributeHelpers for &'a HTMLElement { }) } - fn delete_custom_attr(self, local_name: DOMString) { + pub fn delete_custom_attr(&self, local_name: DOMString) { let element = ElementCast::from_ref(self); let local_name = Atom::from_slice(&to_snake_case(local_name)); element.remove_attribute(&ns!(""), &local_name); diff --git a/servo/components/script/dom/htmlfieldsetelement.rs b/servo/components/script/dom/htmlfieldsetelement.rs index 8c1957c31c1a..a223f87650ef 100644 --- a/servo/components/script/dom/htmlfieldsetelement.rs +++ b/servo/components/script/dom/htmlfieldsetelement.rs @@ -3,19 +3,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding; use dom::bindings::codegen::Bindings::HTMLFieldSetElementBinding::HTMLFieldSetElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLLegendElementDerived}; use dom::bindings::codegen::InheritTypes::{HTMLFieldSetElementDerived, NodeCast}; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; -use dom::element::ElementTypeId; -use dom::element::{AttributeHandlers, Element, ElementHelpers}; +use dom::element::{Element, ElementTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlcollection::{HTMLCollection, CollectionFilter}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; diff --git a/servo/components/script/dom/htmlfontelement.rs b/servo/components/script/dom/htmlfontelement.rs index 907acc97dcb6..f84582bc5dd0 100644 --- a/servo/components/script/dom/htmlfontelement.rs +++ b/servo/components/script/dom/htmlfontelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLFontElementBinding; use dom::bindings::codegen::Bindings::HTMLFontElementBinding::HTMLFontElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLFontElementDerived}; @@ -85,12 +85,9 @@ impl VirtualMethods for HTMLFontElement { } } -pub trait HTMLFontElementHelpers { - fn get_color(&self) -> Option; -} -impl HTMLFontElementHelpers for HTMLFontElement { - fn get_color(&self) -> Option { +impl HTMLFontElement { + pub fn get_color(&self) -> Option { self.color.get() } } diff --git a/servo/components/script/dom/htmlformelement.rs b/servo/components/script/dom/htmlformelement.rs index b5ca5308c4d9..07a2d0e5f502 100644 --- a/servo/components/script/dom/htmlformelement.rs +++ b/servo/components/script/dom/htmlformelement.rs @@ -18,16 +18,14 @@ use dom::bindings::codegen::InheritTypes::HTMLInputElementCast; use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementCast, NodeCast}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{Root}; -use dom::document::{Document, DocumentHelpers}; -use dom::element::ElementTypeId; -use dom::element::{Element, AttributeHandlers}; -use dom::event::{Event, EventHelpers, EventBubbles, EventCancelable}; +use dom::document::Document; +use dom::element::{Element, ElementTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlbuttonelement::{HTMLButtonElement}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::htmlinputelement::{HTMLInputElement, HTMLInputElementHelpers}; -use dom::htmltextareaelement::HTMLTextAreaElementHelpers; -use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::htmlinputelement::HTMLInputElement; +use dom::node::{Node, NodeTypeId, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; use hyper::header::ContentType; use hyper::method::Method; @@ -161,17 +159,9 @@ pub enum ResetFrom { NotFromFormResetMethod } -pub trait HTMLFormElementHelpers { - // https://html.spec.whatwg.org/multipage/#concept-form-submit - fn submit(self, submit_method_flag: SubmittedFrom, submitter: FormSubmitter); - // https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set - fn get_form_dataset(self, submitter: Option) -> Vec; - // https://html.spec.whatwg.org/multipage/#dom-form-reset - fn reset(self, submit_method_flag: ResetFrom); -} -impl<'a> HTMLFormElementHelpers for &'a HTMLFormElement { - fn submit(self, _submit_method_flag: SubmittedFrom, submitter: FormSubmitter) { +impl HTMLFormElement { + pub fn submit(&self, _submit_method_flag: SubmittedFrom, submitter: FormSubmitter) { // Step 1 let doc = document_from_node(self); let win = window_from_node(self); @@ -235,7 +225,7 @@ impl<'a> HTMLFormElementHelpers for &'a HTMLFormElement { win.r().pipeline(), load_data)).unwrap(); } - fn get_form_dataset<'b>(self, submitter: Option>) -> Vec { + pub fn get_form_dataset<'b>(&self, submitter: Option>) -> Vec { fn clean_crlf(s: &str) -> DOMString { // https://html.spec.whatwg.org/multipage/#constructing-the-form-data-set // Step 4 @@ -362,7 +352,7 @@ impl<'a> HTMLFormElementHelpers for &'a HTMLFormElement { ret } - fn reset(self, _reset_method_flag: ResetFrom) { + pub fn reset(&self, _reset_method_flag: ResetFrom) { // https://html.spec.whatwg.org/multipage/#locked-for-reset if self.marked_for_reset.get() { return; diff --git a/servo/components/script/dom/htmliframeelement.rs b/servo/components/script/dom/htmliframeelement.rs index 401f8a368e4a..912efc41cba5 100644 --- a/servo/components/script/dom/htmliframeelement.rs +++ b/servo/components/script/dom/htmliframeelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers, AttrHelpersForLayout, AttrValue}; +use dom::attr::{Attr, AttrHelpersForLayout, AttrValue}; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding; use dom::bindings::codegen::Bindings::HTMLIFrameElementBinding::HTMLIFrameElementMethods; use dom::bindings::codegen::Bindings::WindowBinding::WindowMethods; @@ -17,15 +17,13 @@ use dom::bindings::js::{Root}; use dom::bindings::utils::Reflectable; use dom::customevent::CustomEvent; use dom::document::Document; -use dom::element::ElementTypeId; -use dom::element::{self, AttributeHandlers}; -use dom::event::EventHelpers; +use dom::element::{ElementTypeId, self}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::urlhelper::UrlHelper; use dom::virtualmethods::VirtualMethods; -use dom::window::{Window, WindowHelpers}; +use dom::window::Window; use page::IterablePage; use msg::constellation_msg::IFrameSandboxState::{IFrameSandboxed, IFrameUnsandboxed}; @@ -70,28 +68,14 @@ impl HTMLIFrameElementDerived for EventTarget { } } -pub trait HTMLIFrameElementHelpers { - fn is_sandboxed(self) -> bool; - fn get_url(self) -> Option; - /// https://www.whatwg.org/html/#process-the-iframe-attributes - fn process_the_iframe_attributes(self); - fn generate_new_subpage_id(self) -> (SubpageId, Option); - fn navigate_child_browsing_context(self, url: Url); - fn dispatch_mozbrowser_event(self, event: MozBrowserEvent); - fn update_subpage_id(self, new_subpage_id: SubpageId); -} -pub trait RawHTMLIFrameElementHelpers { - fn get_width(&self) -> LengthOrPercentageOrAuto; - fn get_height(&self) -> LengthOrPercentageOrAuto; -} -impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { - fn is_sandboxed(self) -> bool { +impl HTMLIFrameElement { + pub fn is_sandboxed(&self) -> bool { self.sandbox.get().is_some() } - fn get_url(self) -> Option { + pub fn get_url(&self) -> Option { let element = ElementCast::from_ref(self); element.get_attribute(&ns!(""), &atom!("src")).and_then(|src| { let url = src.r().value(); @@ -105,7 +89,7 @@ impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { }) } - fn generate_new_subpage_id(self) -> (SubpageId, Option) { + pub fn generate_new_subpage_id(&self) -> (SubpageId, Option) { let old_subpage_id = self.subpage_id.get(); let win = window_from_node(self); let subpage_id = win.r().get_next_subpage_id(); @@ -113,7 +97,7 @@ impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { (subpage_id, old_subpage_id) } - fn navigate_child_browsing_context(self, url: Url) { + pub fn navigate_child_browsing_context(&self, url: Url) { let sandboxed = if self.is_sandboxed() { IFrameSandboxed } else { @@ -139,7 +123,7 @@ impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { } } - fn process_the_iframe_attributes(self) { + pub fn process_the_iframe_attributes(&self) { let url = match self.get_url() { Some(url) => url.clone(), None => Url::parse("about:blank").unwrap(), @@ -148,7 +132,7 @@ impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { self.navigate_child_browsing_context(url); } - fn dispatch_mozbrowser_event(self, event: MozBrowserEvent) { + pub fn dispatch_mozbrowser_event(&self, event: MozBrowserEvent) { // TODO(gw): Support mozbrowser event types that have detail which is not a string. // See https://developer.mozilla.org/en-US/docs/Web/API/Using_the_Browser_API // for a list of mozbrowser events. @@ -172,14 +156,14 @@ impl<'a> HTMLIFrameElementHelpers for &'a HTMLIFrameElement { } } - fn update_subpage_id(self, new_subpage_id: SubpageId) { + pub fn update_subpage_id(&self, new_subpage_id: SubpageId) { self.subpage_id.set(Some(new_subpage_id)); } } -impl RawHTMLIFrameElementHelpers for HTMLIFrameElement { +impl HTMLIFrameElement { #[allow(unsafe_code)] - fn get_width(&self) -> LengthOrPercentageOrAuto { + pub fn get_width(&self) -> LengthOrPercentageOrAuto { unsafe { element::get_attr_for_layout(ElementCast::from_ref(&*self), &ns!(""), @@ -190,7 +174,7 @@ impl RawHTMLIFrameElementHelpers for HTMLIFrameElement { } #[allow(unsafe_code)] - fn get_height(&self) -> LengthOrPercentageOrAuto { + pub fn get_height(&self) -> LengthOrPercentageOrAuto { unsafe { element::get_attr_for_layout(ElementCast::from_ref(&*self), &ns!(""), diff --git a/servo/components/script/dom/htmlimageelement.rs b/servo/components/script/dom/htmlimageelement.rs index f60817e8592b..bfd13057f255 100644 --- a/servo/components/script/dom/htmlimageelement.rs +++ b/servo/components/script/dom/htmlimageelement.rs @@ -3,7 +3,7 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::{AttrHelpers, AttrValue}; +use dom::attr::AttrValue; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::HTMLImageElementBinding; use dom::bindings::codegen::Bindings::HTMLImageElementBinding::HTMLImageElementMethods; @@ -14,15 +14,13 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{LayoutJS, Root}; use dom::bindings::refcounted::Trusted; -use dom::document::{Document, DocumentHelpers}; -use dom::element::AttributeHandlers; +use dom::document::Document; use dom::element::ElementTypeId; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{document_from_node, Node, NodeTypeId, NodeHelpers, NodeDamage, window_from_node}; +use dom::node::{document_from_node, Node, NodeTypeId, NodeDamage, window_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use script_task::{Runnable, ScriptChan, CommonScriptMsg}; use string_cache::Atom; use util::str::DOMString; @@ -51,19 +49,13 @@ impl HTMLImageElementDerived for EventTarget { } } -pub trait HTMLImageElementHelpers { - fn get_url(&self) -> Option; -} -impl<'a> HTMLImageElementHelpers for &'a HTMLImageElement { - fn get_url(&self) -> Option{ +impl HTMLImageElement { + pub fn get_url(&self) -> Option{ self.url.borrow().clone() } } -trait PrivateHTMLImageElementHelpers { - fn update_image(self, value: Option<(DOMString, &Url)>); -} struct ImageResponseHandlerRunnable { element: Trusted, @@ -112,10 +104,10 @@ impl Runnable for ImageResponseHandlerRunnable { } } -impl<'a> PrivateHTMLImageElementHelpers for &'a HTMLImageElement { +impl HTMLImageElement { /// Makes the local `image` member match the status of the `src` attribute and starts /// prefetching the image. This method must be called after `src` is changed. - fn update_image(self, value: Option<(DOMString, &Url)>) { + fn update_image(&self, value: Option<(DOMString, &Url)>) { let node = NodeCast::from_ref(self); let document = node.owner_doc(); let window = document.r().window(); diff --git a/servo/components/script/dom/htmlinputelement.rs b/servo/components/script/dom/htmlinputelement.rs index 5dd3c60e8857..b282b1f2f459 100644 --- a/servo/components/script/dom/htmlinputelement.rs +++ b/servo/components/script/dom/htmlinputelement.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::activation::Activatable; -use dom::attr::AttrHelpers; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; @@ -16,20 +15,17 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLInp use dom::bindings::codegen::InheritTypes::{HTMLInputElementDerived, HTMLFieldSetElementDerived, EventTargetCast}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, LayoutJS, Root, RootedReference}; -use dom::document::{Document, DocumentHelpers}; -use dom::element::ElementTypeId; -use dom::element::{AttributeHandlers, Element}; -use dom::element::{RawLayoutElementHelpers, ActivationElementHelpers}; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; +use dom::document::Document; +use dom::element::{Element, ElementTypeId, RawLayoutElementHelpers}; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::htmlformelement::{FormSubmitter, FormControl, HTMLFormElement, HTMLFormElementHelpers}; +use dom::htmlformelement::{FormSubmitter, FormControl, HTMLFormElement}; use dom::htmlformelement::{SubmittedFrom, ResetFrom}; use dom::keyboardevent::KeyboardEvent; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeDamage, NodeTypeId}; +use dom::node::{Node, NodeDamage, NodeTypeId}; use dom::node::{document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use msg::constellation_msg::ConstellationChan; use textinput::KeyReaction::{TriggerDefaultAction, DispatchInput, Nothing}; use textinput::Lines::Single; @@ -331,16 +327,6 @@ impl<'a> HTMLInputElementMethods for &'a HTMLInputElement { } } -pub trait HTMLInputElementHelpers { - fn force_relayout(self); - fn radio_group_updated(self, group: Option<&str>); - fn get_radio_group_name(self) -> Option; - fn update_checked_state(self, checked: bool, dirty: bool); - fn get_size(self) -> u32; - fn get_indeterminate_state(self) -> bool; - fn mutable(self) -> bool; - fn reset(self); -} #[allow(unsafe_code)] fn broadcast_radio_checked(broadcaster: &HTMLInputElement, group: Option<&str>) { @@ -384,27 +370,27 @@ fn in_same_group<'a,'b>(other: &'a HTMLInputElement, } } -impl<'a> HTMLInputElementHelpers for &'a HTMLInputElement { - fn force_relayout(self) { +impl HTMLInputElement { + pub fn force_relayout(&self) { let doc = document_from_node(self); let node = NodeCast::from_ref(self); doc.r().content_changed(node, NodeDamage::OtherNodeDamage) } - fn radio_group_updated(self, group: Option<&str>) { + pub fn radio_group_updated(&self, group: Option<&str>) { if self.Checked() { broadcast_radio_checked(self, group); } } - fn get_radio_group_name(self) -> Option { + pub fn get_radio_group_name(&self) -> Option { //TODO: determine form owner let elem = ElementCast::from_ref(self); elem.get_attribute(&ns!(""), &atom!("name")) .map(|name| name.r().Value()) } - fn update_checked_state(self, checked: bool, dirty: bool) { + pub fn update_checked_state(&self, checked: bool, dirty: bool) { self.checked.set(checked); if dirty { @@ -422,16 +408,16 @@ impl<'a> HTMLInputElementHelpers for &'a HTMLInputElement { //TODO: dispatch change event } - fn get_size(self) -> u32 { + pub fn get_size(&self) -> u32 { self.size.get() } - fn get_indeterminate_state(self) -> bool { + pub fn get_indeterminate_state(&self) -> bool { self.indeterminate.get() } // https://html.spec.whatwg.org/multipage/#concept-fe-mutable - fn mutable(self) -> bool { + pub fn mutable(&self) -> bool { // https://html.spec.whatwg.org/multipage/#the-input-element:concept-fe-mutable // https://html.spec.whatwg.org/multipage/#the-readonly-attribute:concept-fe-mutable let node = NodeCast::from_ref(self); @@ -439,7 +425,7 @@ impl<'a> HTMLInputElementHelpers for &'a HTMLInputElement { } // https://html.spec.whatwg.org/multipage/#the-input-element:concept-form-reset-control - fn reset(self) { + pub fn reset(&self) { match self.input_type.get() { InputType::InputRadio | InputType::InputCheckbox => { self.update_checked_state(self.DefaultChecked(), false); diff --git a/servo/components/script/dom/htmllinkelement.rs b/servo/components/script/dom/htmllinkelement.rs index 8dea8ecf5cb0..f109cd7be583 100644 --- a/servo/components/script/dom/htmllinkelement.rs +++ b/servo/components/script/dom/htmllinkelement.rs @@ -4,7 +4,6 @@ use cssparser::Parser as CssParser; use document_loader::LoadType; -use dom::attr::AttrHelpers; use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding; use dom::bindings::codegen::Bindings::HTMLLinkElementBinding::HTMLLinkElementMethods; @@ -15,16 +14,14 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::js::{RootedReference}; use dom::bindings::refcounted::Trusted; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::domtokenlist::DOMTokenList; -use dom::element::ElementTypeId; -use dom::element::{AttributeHandlers, Element}; -use dom::event::{EventBubbles, EventCancelable, Event, EventHelpers}; +use dom::element::{Element, ElementTypeId}; +use dom::event::{EventBubbles, EventCancelable, Event}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use layout_interface::{LayoutChan, Msg}; use msg::constellation_msg::ConstellationChan; use msg::constellation_msg::Msg as ConstellationMsg; @@ -167,13 +164,9 @@ impl VirtualMethods for HTMLLinkElement { } } -trait PrivateHTMLLinkElementHelpers { - fn handle_stylesheet_url(self, href: &str); - fn handle_favicon_url(self, href: &str); -} -impl<'a> PrivateHTMLLinkElementHelpers for &'a HTMLLinkElement { - fn handle_stylesheet_url(self, href: &str) { +impl HTMLLinkElement { + fn handle_stylesheet_url(&self, href: &str) { let window = window_from_node(self); let window = window.r(); match UrlParser::new().base_url(&window.get_url()).parse(href) { @@ -201,7 +194,7 @@ impl<'a> PrivateHTMLLinkElementHelpers for &'a HTMLLinkElement { } } - fn handle_favicon_url(self, href: &str) { + fn handle_favicon_url(&self, href: &str) { let window = window_from_node(self); let window = window.r(); match UrlParser::new().base_url(&window.get_url()).parse(href) { diff --git a/servo/components/script/dom/htmlobjectelement.rs b/servo/components/script/dom/htmlobjectelement.rs index 4af221e7100e..afd3d32b5229 100644 --- a/servo/components/script/dom/htmlobjectelement.rs +++ b/servo/components/script/dom/htmlobjectelement.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::HTMLObjectElementBinding; @@ -12,11 +11,10 @@ use dom::bindings::codegen::InheritTypes::HTMLObjectElementDerived; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::AttributeHandlers; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{Node, NodeTypeId, NodeHelpers, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; diff --git a/servo/components/script/dom/htmloptgroupelement.rs b/servo/components/script/dom/htmloptgroupelement.rs index 814914d325df..d7173dc8bc86 100644 --- a/servo/components/script/dom/htmloptgroupelement.rs +++ b/servo/components/script/dom/htmloptgroupelement.rs @@ -3,18 +3,16 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding; use dom::bindings::codegen::Bindings::HTMLOptGroupElementBinding::HTMLOptGroupElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast}; use dom::bindings::codegen::InheritTypes::{HTMLOptGroupElementDerived, HTMLOptionElementDerived}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::AttributeHandlers; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::DOMString; diff --git a/servo/components/script/dom/htmloptionelement.rs b/servo/components/script/dom/htmloptionelement.rs index 5bb462a032ce..daf192177382 100644 --- a/servo/components/script/dom/htmloptionelement.rs +++ b/servo/components/script/dom/htmloptionelement.rs @@ -3,7 +3,6 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding; use dom::bindings::codegen::Bindings::HTMLOptionElementBinding::HTMLOptionElementMethods; @@ -14,10 +13,9 @@ use dom::bindings::codegen::InheritTypes::{HTMLScriptElementDerived}; use dom::bindings::js::Root; use dom::document::Document; use dom::element::ElementTypeId; -use dom::element::{AttributeHandlers, ElementHelpers}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; use util::str::{DOMString, split_html_space_chars}; diff --git a/servo/components/script/dom/htmlscriptelement.rs b/servo/components/script/dom/htmlscriptelement.rs index 64ab605ba40d..42d398899d15 100644 --- a/servo/components/script/dom/htmlscriptelement.rs +++ b/servo/components/script/dom/htmlscriptelement.rs @@ -6,7 +6,6 @@ use std::ascii::AsciiExt; use document_loader::LoadType; use dom::attr::Attr; -use dom::attr::AttrHelpers; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; @@ -21,17 +20,15 @@ use dom::bindings::js::RootedReference; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::JSTraceable; -use dom::document::{Document, DocumentHelpers}; -use dom::element::ElementTypeId; -use dom::element::{AttributeHandlers, ElementCreator}; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; +use dom::document::Document; +use dom::element::{ElementCreator, ElementTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeHelpers}; +use dom::node::{ChildrenMutation, CloneChildrenFlag, Node}; use dom::node::{NodeTypeId, document_from_node, window_from_node}; -use dom::servohtmlparser::ServoHTMLParserHelpers; use dom::virtualmethods::VirtualMethods; -use dom::window::{WindowHelpers, ScriptHelpers}; +use dom::window::ScriptHelpers; use js::jsapi::RootedValue; use js::jsval::UndefinedValue; use network_listener::{NetworkListener, PreInvoke}; @@ -110,35 +107,6 @@ impl HTMLScriptElement { } } -pub trait HTMLScriptElementHelpers { - /// Prepare a script () - fn prepare(self) -> NextParserState; - - /// [Execute a script block] - /// (https://html.spec.whatwg.org/multipage/#execute-the-script-block) - fn execute(self, load: ScriptOrigin); - - /// Prepare a script, steps 6 and 7. - fn is_javascript(self) -> bool; - - /// Set the "already started" flag () - fn mark_already_started(self); - - // Queues error event - fn queue_error_event(self); - - /// Dispatch beforescriptexecute event. - fn dispatch_before_script_execute_event(self) -> bool; - - /// Dispatch afterscriptexecute event. - fn dispatch_after_script_execute_event(self); - - /// Dispatch load event. - fn dispatch_load_event(self); - - /// Dispatch error event. - fn dispatch_error_event(self); -} /// Supported script types as defined by /// . @@ -212,8 +180,8 @@ impl AsyncResponseListener for ScriptContext { impl PreInvoke for ScriptContext {} -impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { - fn prepare(self) -> NextParserState { +impl HTMLScriptElement { + pub fn prepare(&self) -> NextParserState { // https://html.spec.whatwg.org/multipage/#prepare-a-script // Step 1. if self.already_started.get() { @@ -365,7 +333,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { NextParserState::Continue } - fn execute(self, load: ScriptOrigin) { + pub fn execute(&self, load: ScriptOrigin) { // Step 1. // TODO: If the element is flagged as "parser-inserted", but the // element's node document is not the Document of the parser that @@ -462,7 +430,7 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { } } - fn queue_error_event(self) { + pub fn queue_error_event(&self) { let window = window_from_node(self); let window = window.r(); let chan = window.script_chan(); @@ -474,31 +442,31 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { chan.send(CommonScriptMsg::RunnableMsg(dispatcher)).unwrap(); } - fn dispatch_before_script_execute_event(self) -> bool { + pub fn dispatch_before_script_execute_event(&self) -> bool { self.dispatch_event("beforescriptexecute".to_owned(), EventBubbles::Bubbles, EventCancelable::Cancelable) } - fn dispatch_after_script_execute_event(self) { + pub fn dispatch_after_script_execute_event(&self) { self.dispatch_event("afterscriptexecute".to_owned(), EventBubbles::Bubbles, EventCancelable::NotCancelable); } - fn dispatch_load_event(self) { + pub fn dispatch_load_event(&self) { self.dispatch_event("load".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable); } - fn dispatch_error_event(self) { + pub fn dispatch_error_event(&self) { self.dispatch_event("error".to_owned(), EventBubbles::DoesNotBubble, EventCancelable::NotCancelable); } - fn is_javascript(self) -> bool { + pub fn is_javascript(&self) -> bool { let element = ElementCast::from_ref(self); match element.get_attribute(&ns!(""), &atom!("type")).map(|s| s.r().Value()) { Some(ref s) if s.is_empty() => { @@ -531,20 +499,14 @@ impl<'a> HTMLScriptElementHelpers for &'a HTMLScriptElement { } } - fn mark_already_started(self) { + pub fn mark_already_started(&self) { self.already_started.set(true); } } -trait PrivateHTMLScriptElementHelpers { - fn dispatch_event(self, - type_: DOMString, - bubbles: EventBubbles, - cancelable: EventCancelable) -> bool; -} -impl<'a> PrivateHTMLScriptElementHelpers for &'a HTMLScriptElement { - fn dispatch_event(self, +impl HTMLScriptElement { + fn dispatch_event(&self, type_: DOMString, bubbles: EventBubbles, cancelable: EventCancelable) -> bool { diff --git a/servo/components/script/dom/htmlselectelement.rs b/servo/components/script/dom/htmlselectelement.rs index cb30c4ad81e6..1339db1e6e91 100644 --- a/servo/components/script/dom/htmlselectelement.rs +++ b/servo/components/script/dom/htmlselectelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers, AttrValue}; +use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLSelectElementBinding; use dom::bindings::codegen::Bindings::HTMLSelectElementBinding::HTMLSelectElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, NodeCast}; @@ -11,11 +11,10 @@ use dom::bindings::codegen::UnionTypes::HTMLElementOrLong; use dom::bindings::codegen::UnionTypes::HTMLOptionElementOrHTMLOptGroupElement; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::AttributeHandlers; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{DisabledStateHelpers, Node, NodeHelpers, NodeTypeId, window_from_node}; +use dom::node::{Node, NodeTypeId, window_from_node}; use dom::validitystate::ValidityState; use dom::virtualmethods::VirtualMethods; diff --git a/servo/components/script/dom/htmlstyleelement.rs b/servo/components/script/dom/htmlstyleelement.rs index 24b903dc693e..eabe8314cd7c 100644 --- a/servo/components/script/dom/htmlstyleelement.rs +++ b/servo/components/script/dom/htmlstyleelement.rs @@ -3,19 +3,17 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ use cssparser::Parser as CssParser; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::HTMLStyleElementBinding; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLStyleElementDerived, NodeCast}; use dom::bindings::js::Root; use dom::document::Document; -use dom::element::{ElementTypeId, AttributeHandlers}; +use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::node::window_from_node; -use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId}; +use dom::node::{ChildrenMutation, Node, NodeTypeId}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use layout_interface::{LayoutChan, Msg}; use style::media_queries::parse_media_query_list; use style::stylesheets::{Origin, Stylesheet}; @@ -52,12 +50,9 @@ impl HTMLStyleElement { } } -pub trait StyleElementHelpers { - fn parse_own_css(self); -} -impl<'a> StyleElementHelpers for &'a HTMLStyleElement { - fn parse_own_css(self) { +impl HTMLStyleElement { + pub fn parse_own_css(&self) { let node = NodeCast::from_ref(self); let element = ElementCast::from_ref(self); assert!(node.is_in_doc()); diff --git a/servo/components/script/dom/htmltablecellelement.rs b/servo/components/script/dom/htmltablecellelement.rs index e992b6c83ed7..acdecf181e4d 100644 --- a/servo/components/script/dom/htmltablecellelement.rs +++ b/servo/components/script/dom/htmltablecellelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers, AttrValue}; +use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableCellElementBinding::HTMLTableCellElementMethods; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableCellElementDerived}; use dom::document::Document; @@ -80,22 +80,17 @@ impl<'a> HTMLTableCellElementMethods for &'a HTMLTableCellElement { make_uint_setter!(SetColSpan, "colspan"); } -pub trait HTMLTableCellElementHelpers { - fn get_background_color(self) -> Option; - fn get_colspan(self) -> Option; - fn get_width(self) -> LengthOrPercentageOrAuto; -} -impl<'a> HTMLTableCellElementHelpers for &'a HTMLTableCellElement { - fn get_background_color(self) -> Option { +impl HTMLTableCellElement { + pub fn get_background_color(&self) -> Option { self.background_color.get() } - fn get_colspan(self) -> Option { + pub fn get_colspan(&self) -> Option { self.colspan.get() } - fn get_width(self) -> LengthOrPercentageOrAuto { + pub fn get_width(&self) -> LengthOrPercentageOrAuto { self.width.get() } } diff --git a/servo/components/script/dom/htmltableelement.rs b/servo/components/script/dom/htmltableelement.rs index 1eb4f2b9818b..00edb684e492 100644 --- a/servo/components/script/dom/htmltableelement.rs +++ b/servo/components/script/dom/htmltableelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers, AttrValue}; +use dom::attr::{Attr, AttrValue}; use dom::bindings::codegen::Bindings::HTMLTableElementBinding; use dom::bindings::codegen::Bindings::HTMLTableElementBinding::HTMLTableElementMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; @@ -11,12 +11,12 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLElementCast, HTMLTab use dom::bindings::codegen::InheritTypes::{HTMLTableElementDerived, NodeCast}; use dom::bindings::js::{Root, RootedReference}; use dom::document::Document; -use dom::element::{ElementHelpers, ElementTypeId}; +use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmltablecaptionelement::HTMLTableCaptionElement; use dom::htmltablesectionelement::HTMLTableSectionElement; -use dom::node::{Node, NodeHelpers, NodeTypeId, document_from_node}; +use dom::node::{Node, NodeTypeId, document_from_node}; use dom::virtualmethods::VirtualMethods; use util::str::{self, DOMString, LengthOrPercentageOrAuto}; @@ -132,27 +132,21 @@ impl<'a> HTMLTableElementMethods for &'a HTMLTableElement { } } -pub trait HTMLTableElementHelpers { - fn get_background_color(self) -> Option; - fn get_border(self) -> Option; - fn get_cellspacing(self) -> Option; - fn get_width(self) -> LengthOrPercentageOrAuto; -} -impl<'a> HTMLTableElementHelpers for &'a HTMLTableElement { - fn get_background_color(self) -> Option { +impl HTMLTableElement { + pub fn get_background_color(&self) -> Option { self.background_color.get() } - fn get_border(self) -> Option { + pub fn get_border(&self) -> Option { self.border.get() } - fn get_cellspacing(self) -> Option { + pub fn get_cellspacing(&self) -> Option { self.cellspacing.get() } - fn get_width(self) -> LengthOrPercentageOrAuto { + pub fn get_width(&self) -> LengthOrPercentageOrAuto { self.width.get() } } diff --git a/servo/components/script/dom/htmltablerowelement.rs b/servo/components/script/dom/htmltablerowelement.rs index 3526c4ab1220..50bf4fac967c 100644 --- a/servo/components/script/dom/htmltablerowelement.rs +++ b/servo/components/script/dom/htmltablerowelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableRowElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableRowElementDerived}; use dom::bindings::js::Root; @@ -53,12 +53,9 @@ impl HTMLTableRowElement { } -pub trait HTMLTableRowElementHelpers { - fn get_background_color(self) -> Option; -} -impl<'a> HTMLTableRowElementHelpers for &'a HTMLTableRowElement { - fn get_background_color(self) -> Option { +impl HTMLTableRowElement { + pub fn get_background_color(&self) -> Option { self.background_color.get() } } diff --git a/servo/components/script/dom/htmltablesectionelement.rs b/servo/components/script/dom/htmltablesectionelement.rs index c9bcb7366f9d..4b9c28036426 100644 --- a/servo/components/script/dom/htmltablesectionelement.rs +++ b/servo/components/script/dom/htmltablesectionelement.rs @@ -2,7 +2,7 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::codegen::Bindings::HTMLTableSectionElementBinding; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTableSectionElementDerived}; use dom::bindings::js::Root; @@ -51,12 +51,9 @@ impl HTMLTableSectionElement { } } -pub trait HTMLTableSectionElementHelpers { - fn get_background_color(self) -> Option; -} -impl<'a> HTMLTableSectionElementHelpers for &'a HTMLTableSectionElement { - fn get_background_color(self) -> Option { +impl HTMLTableSectionElement { + pub fn get_background_color(&self) -> Option { self.background_color.get() } } diff --git a/servo/components/script/dom/htmltextareaelement.rs b/servo/components/script/dom/htmltextareaelement.rs index cdc6efa963ba..49c61c7b5b20 100644 --- a/servo/components/script/dom/htmltextareaelement.rs +++ b/servo/components/script/dom/htmltextareaelement.rs @@ -2,7 +2,6 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -use dom::attr::AttrHelpers; use dom::attr::{Attr, AttrValue}; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::EventBinding::EventMethods; @@ -15,18 +14,16 @@ use dom::bindings::codegen::InheritTypes::{HTMLTextAreaElementDerived, HTMLField use dom::bindings::global::GlobalRef; use dom::bindings::js::{LayoutJS, Root}; use dom::bindings::refcounted::Trusted; -use dom::document::{Document, DocumentHelpers}; -use dom::element::ElementTypeId; -use dom::element::{Element, AttributeHandlers}; +use dom::document::Document; +use dom::element::{Element, ElementTypeId}; use dom::event::{Event, EventBubbles, EventCancelable}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; use dom::htmlformelement::FormControl; use dom::keyboardevent::KeyboardEvent; -use dom::node::{ChildrenMutation, DisabledStateHelpers, Node, NodeDamage}; -use dom::node::{NodeHelpers, NodeTypeId, document_from_node, window_from_node}; +use dom::node::{ChildrenMutation, Node, NodeDamage}; +use dom::node::{NodeTypeId, document_from_node, window_from_node}; use dom::virtualmethods::VirtualMethods; -use dom::window::WindowHelpers; use msg::constellation_msg::ConstellationChan; use script_task::{Runnable, CommonScriptMsg}; use textinput::{TextInput, Lines, KeyReaction}; @@ -203,37 +200,29 @@ impl<'a> HTMLTextAreaElementMethods for &'a HTMLTextAreaElement { } } -pub trait HTMLTextAreaElementHelpers { - fn mutable(self) -> bool; - fn reset(self); -} -impl<'a> HTMLTextAreaElementHelpers for &'a HTMLTextAreaElement { +impl HTMLTextAreaElement { // https://html.spec.whatwg.org/multipage/#concept-fe-mutable - fn mutable(self) -> bool { + pub fn mutable(&self) -> bool { // https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-fe-mutable !(self.Disabled() || self.ReadOnly()) } - fn reset(self) { + pub fn reset(&self) { // https://html.spec.whatwg.org/multipage/#the-textarea-element:concept-form-reset-control self.SetValue(self.DefaultValue()); self.value_changed.set(false); } } -trait PrivateHTMLTextAreaElementHelpers { - fn force_relayout(self); - fn dispatch_change_event(self); -} -impl<'a> PrivateHTMLTextAreaElementHelpers for &'a HTMLTextAreaElement { - fn force_relayout(self) { +impl HTMLTextAreaElement { + fn force_relayout(&self) { let doc = document_from_node(self); let node = NodeCast::from_ref(self); doc.r().content_changed(node, NodeDamage::OtherNodeDamage) } - fn dispatch_change_event(self) { + fn dispatch_change_event(&self) { let window = window_from_node(self); let window = window.r(); let event = Event::new(GlobalRef::Window(window), diff --git a/servo/components/script/dom/htmltitleelement.rs b/servo/components/script/dom/htmltitleelement.rs index 691ab057984f..bf365ff7b95d 100644 --- a/servo/components/script/dom/htmltitleelement.rs +++ b/servo/components/script/dom/htmltitleelement.rs @@ -8,12 +8,11 @@ use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::{CharacterDataCast, TextCast}; use dom::bindings::codegen::InheritTypes::{HTMLElementCast, HTMLTitleElementDerived, NodeCast}; use dom::bindings::js::Root; -use dom::characterdata::CharacterDataHelpers; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::element::ElementTypeId; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::{HTMLElement, HTMLElementTypeId}; -use dom::node::{ChildrenMutation, Node, NodeHelpers, NodeTypeId}; +use dom::node::{ChildrenMutation, Node, NodeTypeId}; use dom::text::Text; use dom::virtualmethods::VirtualMethods; use util::str::DOMString; diff --git a/servo/components/script/dom/imagedata.rs b/servo/components/script/dom/imagedata.rs index 0c2838628ff9..5acbb4f5e59c 100644 --- a/servo/components/script/dom/imagedata.rs +++ b/servo/components/script/dom/imagedata.rs @@ -51,14 +51,10 @@ impl ImageData { } } -pub trait ImageDataHelpers { - fn get_data_array(self, global: &GlobalRef) -> Vec; - fn get_size(self) -> Size2D; -} -impl<'a> ImageDataHelpers for &'a ImageData { +impl ImageData { #[allow(unsafe_code)] - fn get_data_array(self, global: &GlobalRef) -> Vec { + pub fn get_data_array(&self, global: &GlobalRef) -> Vec { unsafe { let cx = global.get_cx(); let data: *const uint8_t = JS_GetUint8ClampedArrayData(self.Data(cx), ptr::null()) as *const uint8_t; @@ -67,7 +63,7 @@ impl<'a> ImageDataHelpers for &'a ImageData { } } - fn get_size(self) -> Size2D { + pub fn get_size(&self) -> Size2D { Size2D::new(self.Width() as i32, self.Height() as i32) } } diff --git a/servo/components/script/dom/keyboardevent.rs b/servo/components/script/dom/keyboardevent.rs index 963ae679c62d..1120ac4f7344 100644 --- a/servo/components/script/dom/keyboardevent.rs +++ b/servo/components/script/dom/keyboardevent.rs @@ -135,17 +135,13 @@ impl KeyboardEvent { } } -pub trait KeyboardEventHelpers { - fn get_key(self) -> Option; - fn get_key_modifiers(self) -> KeyModifiers; -} -impl<'a> KeyboardEventHelpers for &'a KeyboardEvent { - fn get_key(self) -> Option { +impl KeyboardEvent { + pub fn get_key(&self) -> Option { self.key.get().clone() } - fn get_key_modifiers(self) -> KeyModifiers { + pub fn get_key_modifiers(&self) -> KeyModifiers { let mut result = KeyModifiers::empty(); if self.shift.get() { result = result | constellation_msg::SHIFT; diff --git a/servo/components/script/dom/location.rs b/servo/components/script/dom/location.rs index 25c3255f850e..c937d0e4ef2c 100644 --- a/servo/components/script/dom/location.rs +++ b/servo/components/script/dom/location.rs @@ -10,7 +10,6 @@ use dom::bindings::str::USVString; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::urlhelper::UrlHelper; use dom::window::Window; -use dom::window::WindowHelpers; use url::{Url, UrlParser}; use util::str::DOMString; @@ -104,12 +103,9 @@ impl<'a> LocationMethods for &'a Location { } } -trait PrivateLocationHelpers { - fn get_url(self) -> Url; -} -impl<'a> PrivateLocationHelpers for &'a Location { - fn get_url(self) -> Url { +impl Location { + fn get_url(&self) -> Url { let window = self.window.root(); window.r().get_url() } diff --git a/servo/components/script/dom/macros.rs b/servo/components/script/dom/macros.rs index c2becf46c48f..1aab4027b648 100644 --- a/servo/components/script/dom/macros.rs +++ b/servo/components/script/dom/macros.rs @@ -7,7 +7,6 @@ macro_rules! make_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> DOMString { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); element.get_string_attribute(&Atom::from_slice($htmlname)) @@ -23,7 +22,6 @@ macro_rules! make_bool_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> bool { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. @@ -40,7 +38,6 @@ macro_rules! make_uint_getter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(self) -> u32 { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. @@ -60,7 +57,6 @@ macro_rules! make_url_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> DOMString { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not runtime. @@ -78,8 +74,6 @@ macro_rules! make_url_or_base_getter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self) -> DOMString { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; - use dom::window::WindowHelpers; use string_cache::Atom; let element = ElementCast::from_ref(self); let url = element.get_url_attribute(&Atom::from_slice($htmlname)); @@ -101,7 +95,6 @@ macro_rules! make_enumerated_getter( ( $attr:ident, $htmlname:expr, $default:expr, $(($choices: pat))|+) => ( fn $attr(self) -> DOMString { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use std::ascii::AsciiExt; use std::borrow::ToOwned; use string_cache::Atom; @@ -127,7 +120,6 @@ macro_rules! make_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self, value: DOMString) { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. @@ -141,7 +133,6 @@ macro_rules! make_bool_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self, value: bool) { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. @@ -155,7 +146,6 @@ macro_rules! make_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(self, value: u32) { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let value = if value > 2147483647 { $default @@ -177,7 +167,6 @@ macro_rules! make_limited_uint_setter( ($attr:ident, $htmlname:expr, $default:expr) => ( fn $attr(self, value: u32) -> $crate::dom::bindings::error::ErrorResult { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let value = if value == 0 { return Err($crate::dom::bindings::error::Error::IndexSize); @@ -205,7 +194,6 @@ macro_rules! make_atomic_setter( ( $attr:ident, $htmlname:expr ) => ( fn $attr(self, value: DOMString) { use dom::bindings::codegen::InheritTypes::ElementCast; - use dom::element::AttributeHandlers; use string_cache::Atom; let element = ElementCast::from_ref(self); // FIXME(pcwalton): Do this at compile time, not at runtime. diff --git a/servo/components/script/dom/messageevent.rs b/servo/components/script/dom/messageevent.rs index 2fdac8238d6e..c3f3f263a57b 100644 --- a/servo/components/script/dom/messageevent.rs +++ b/servo/components/script/dom/messageevent.rs @@ -10,7 +10,7 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::utils::reflect_dom_object; -use dom::event::{Event, EventHelpers, EventTypeId}; +use dom::event::{Event, EventTypeId}; use dom::eventtarget::EventTarget; use util::str::DOMString; diff --git a/servo/components/script/dom/mod.rs b/servo/components/script/dom/mod.rs index 663d14784a62..e9bc0716217b 100644 --- a/servo/components/script/dom/mod.rs +++ b/servo/components/script/dom/mod.rs @@ -109,16 +109,10 @@ //! Implementing methods for a DOM object //! ===================================== //! -//! XXX JSRef no longer exists - should we remove the *Helpers traits? -//! In order to ensure that DOM objects are rooted when they are called, we -//! require that all methods are implemented for `JSRef<'a, Foo>`. This means -//! that all methods are defined on traits. Conventionally, those traits are -//! called -//! //! * `dom::bindings::codegen::Bindings::FooBindings::FooMethods` for methods //! defined through IDL; -//! * `FooHelpers` for public methods; -//! * `PrivateFooHelpers` for private methods. +//! * `&self` public methods for public helpers; +//! * `&self` methods for private helpers. //! //! Accessing fields of a DOM object //! ================================ diff --git a/servo/components/script/dom/namednodemap.rs b/servo/components/script/dom/namednodemap.rs index ba436d4845b8..bc08b8d7ce1a 100644 --- a/servo/components/script/dom/namednodemap.rs +++ b/servo/components/script/dom/namednodemap.rs @@ -9,7 +9,7 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::utils::{namespace_from_domstring, Reflector, reflect_dom_object}; -use dom::element::{AttributeHandlers, Element, ElementHelpers}; +use dom::element::Element; use dom::window::Window; use util::str::DOMString; diff --git a/servo/components/script/dom/node.rs b/servo/components/script/dom/node.rs index 2297c52fa83e..0db0c2c6ee59 100644 --- a/servo/components/script/dom/node.rs +++ b/servo/components/script/dom/node.rs @@ -6,7 +6,7 @@ use devtools_traits::NodeInfo; use document_loader::DocumentLoader; -use dom::attr::{Attr, AttrHelpers}; +use dom::attr::Attr; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use dom::bindings::codegen::Bindings::CharacterDataBinding::CharacterDataMethods; @@ -32,20 +32,19 @@ use dom::bindings::js::{JS, LayoutJS, MutNullableHeap}; use dom::bindings::trace::JSTraceable; use dom::bindings::trace::RootedVec; use dom::bindings::utils::{namespace_from_domstring, Reflectable, reflect_dom_object}; -use dom::characterdata::{CharacterData, CharacterDataHelpers, CharacterDataTypeId}; +use dom::characterdata::{CharacterData, CharacterDataTypeId}; use dom::comment::Comment; -use dom::document::{Document, DocumentHelpers, IsHTMLDocument, DocumentSource}; +use dom::document::{Document, IsHTMLDocument, DocumentSource}; use dom::documentfragment::DocumentFragment; use dom::documenttype::DocumentType; -use dom::element::ElementHelpers; -use dom::element::{AttributeHandlers, Element, ElementCreator, ElementTypeId}; +use dom::element::{Element, ElementCreator, ElementTypeId}; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::htmlelement::HTMLElementTypeId; -use dom::nodelist::{NodeList, NodeListHelpers}; -use dom::processinginstruction::{ProcessingInstruction, ProcessingInstructionHelpers}; +use dom::nodelist::NodeList; +use dom::processinginstruction::ProcessingInstruction; use dom::text::Text; use dom::virtualmethods::{VirtualMethods, vtable_for}; -use dom::window::{Window, WindowHelpers}; +use dom::window::Window; use euclid::rect::Rect; use layout_interface::{LayoutChan, Msg}; use parse::html::parse_html_fragment; @@ -295,16 +294,12 @@ pub enum NodeTypeId { Element(ElementTypeId), } -trait PrivateNodeHelpers { - fn add_child(self, new_child: &Node, before: Option<&Node>); - fn remove_child(self, child: &Node); -} -impl<'a> PrivateNodeHelpers for &'a Node { +impl Node { /// Adds a new child to the end of this node's list of children. /// /// Fails unless `new_child` is disconnected from the tree. - fn add_child(self, new_child: &Node, before: Option<&Node>) { + fn add_child(&self, new_child: &Node, before: Option<&Node>) { assert!(new_child.parent_node.get().is_none()); assert!(new_child.prev_sibling.get().is_none()); assert!(new_child.next_sibling.get().is_none()); @@ -354,7 +349,7 @@ impl<'a> PrivateNodeHelpers for &'a Node { /// Removes the given child from this node's list of children. /// /// Fails unless `child` is a child of this node. - fn remove_child(self, child: &Node) { + fn remove_child(&self, child: &Node) { assert!(child.parent_node.get().map(Root::from_rooted).r() == Some(self)); let prev_sibling = child.GetPreviousSibling(); match prev_sibling { @@ -425,117 +420,9 @@ impl<'a> Iterator for QuerySelectorIterator { } } -pub trait NodeHelpers { - fn ancestors(self) -> AncestorIterator; - fn inclusive_ancestors(self) -> AncestorIterator; - fn children(self) -> NodeSiblingIterator; - fn rev_children(self) -> ReverseSiblingIterator; - fn child_elements(self) -> ChildElementIterator; - fn following_siblings(self) -> NodeSiblingIterator; - fn preceding_siblings(self) -> ReverseSiblingIterator; - fn following_nodes(self, root: &Node) -> FollowingNodeIterator; - fn preceding_nodes(self, root: &Node) -> PrecedingNodeIterator; - fn descending_last_children(self) -> LastChildIterator; - fn is_in_doc(self) -> bool; - fn is_inclusive_ancestor_of(self, parent: &Node) -> bool; - fn is_parent_of(self, child: &Node) -> bool; - fn type_id(self) -> NodeTypeId; - fn len(self) -> u32; - fn index(self) -> u32; - fn children_count(self) -> u32; - - fn owner_doc(self) -> Root; - fn set_owner_doc(self, document: &Document); - fn is_in_html_doc(self) -> bool; - - fn is_doctype(self) -> bool; - fn is_anchor_element(self) -> bool; - - fn get_flag(self, flag: NodeFlags) -> bool; - fn set_flag(self, flag: NodeFlags, value: bool); - - fn get_hover_state(self) -> bool; - fn set_hover_state(self, state: bool); - - fn get_focus_state(self) -> bool; - fn set_focus_state(self, state: bool); - - fn get_active_state(self) -> bool; - fn set_active_state(self, state: bool); - - fn get_disabled_state(self) -> bool; - fn set_disabled_state(self, state: bool); - - fn get_enabled_state(self) -> bool; - fn set_enabled_state(self, state: bool); - - fn get_has_changed(self) -> bool; - fn set_has_changed(self, state: bool); - - fn get_is_dirty(self) -> bool; - fn set_is_dirty(self, state: bool); - - fn get_has_dirty_siblings(self) -> bool; - fn set_has_dirty_siblings(self, state: bool); - - fn get_has_dirty_descendants(self) -> bool; - fn set_has_dirty_descendants(self, state: bool); - - /// Marks the given node as `IS_DIRTY`, its siblings as `HAS_DIRTY_SIBLINGS` (to deal with - /// sibling selectors), its ancestors as `HAS_DIRTY_DESCENDANTS`, and its descendants as - /// `IS_DIRTY`. If anything more than the node's style was damaged, this method also sets the - /// `HAS_CHANGED` flag. - fn dirty(self, damage: NodeDamage); - - /// Similar to `dirty`, but will always walk the ancestors to mark them dirty, - /// too. This is useful when a node is reparented. The node will frequently - /// already be marked as `changed` to skip double-dirties, but the ancestors - /// still need to be marked as `HAS_DIRTY_DESCENDANTS`. - /// - /// See #4170 - fn force_dirty_ancestors(self, damage: NodeDamage); - - fn dirty_impl(self, damage: NodeDamage, force_ancestors: bool); - - fn dump(self); - fn dump_indent(self, indent: u32); - fn debug_str(self) -> String; - - fn traverse_preorder(self) -> TreeIterator; - fn inclusively_following_siblings(self) -> NodeSiblingIterator; - fn inclusively_preceding_siblings(self) -> ReverseSiblingIterator; - - fn to_trusted_node_address(self) -> TrustedNodeAddress; - - fn get_bounding_content_box(self) -> Rect; - fn get_content_boxes(self) -> Vec>; - fn get_client_rect(self) -> Rect; - - fn before(self, nodes: Vec) -> ErrorResult; - fn after(self, nodes: Vec) -> ErrorResult; - fn replace_with(self, nodes: Vec) -> ErrorResult; - fn prepend(self, nodes: Vec) -> ErrorResult; - fn append(self, nodes: Vec) -> ErrorResult; - - fn query_selector(self, selectors: DOMString) -> Fallible>>; - #[allow(unsafe_code)] - unsafe fn query_selector_iter(self, selectors: DOMString) -> Fallible; - fn query_selector_all(self, selectors: DOMString) -> Fallible>; - - fn remove_self(self); - - fn get_unique_id(self) -> String; - fn summarize(self) -> NodeInfo; - - fn teardown(self); - - fn parse_fragment(self, markup: DOMString) -> Fallible>; - -} - -impl<'a> NodeHelpers for &'a Node { - fn teardown(self) { +impl Node { + pub fn teardown(&self) { self.layout_data.dispose(self); for kid in self.children() { kid.r().teardown(); @@ -543,12 +430,12 @@ impl<'a> NodeHelpers for &'a Node { } /// Dumps the subtree rooted at this node, for debugging. - fn dump(self) { + pub fn dump(&self) { self.dump_indent(0); } /// Dumps the node tree, for debugging, with indentation. - fn dump_indent(self, indent: u32) { + pub fn dump_indent(&self, indent: u32) { let mut s = String::new(); for _ in 0..indent { s.push_str(" "); @@ -564,21 +451,21 @@ impl<'a> NodeHelpers for &'a Node { } /// Returns a string that describes this node. - fn debug_str(self) -> String { + pub fn debug_str(&self) -> String { format!("{:?}", self.type_id) } - fn is_in_doc(self) -> bool { + pub fn is_in_doc(&self) -> bool { self.flags.get().contains(IS_IN_DOC) } /// Returns the type ID of this node. Fails if this node is borrowed mutably. - fn type_id(self) -> NodeTypeId { + pub fn type_id(&self) -> NodeTypeId { self.type_id } // https://dom.spec.whatwg.org/#concept-node-length - fn len(self) -> u32 { + pub fn len(&self) -> u32 { match self.type_id { NodeTypeId::DocumentType => 0, NodeTypeId::CharacterData(_) => { @@ -589,29 +476,29 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#concept-tree-index - fn index(self) -> u32 { + pub fn index(&self) -> u32 { self.preceding_siblings().count() as u32 } - fn children_count(self) -> u32 { + pub fn children_count(&self) -> u32 { self.children_count.get() } #[inline] - fn is_anchor_element(self) -> bool { + pub fn is_anchor_element(&self) -> bool { self.type_id == NodeTypeId::Element(ElementTypeId::HTMLElement(HTMLElementTypeId::HTMLAnchorElement)) } #[inline] - fn is_doctype(self) -> bool { + pub fn is_doctype(&self) -> bool { self.type_id == NodeTypeId::DocumentType } - fn get_flag(self, flag: NodeFlags) -> bool { + pub fn get_flag(&self, flag: NodeFlags) -> bool { self.flags.get().contains(flag) } - fn set_flag(self, flag: NodeFlags, value: bool) { + pub fn set_flag(&self, flag: NodeFlags, value: bool) { let mut flags = self.flags.get(); if value { @@ -623,90 +510,90 @@ impl<'a> NodeHelpers for &'a Node { self.flags.set(flags); } - fn get_hover_state(self) -> bool { + pub fn get_hover_state(&self) -> bool { self.get_flag(IN_HOVER_STATE) } - fn set_hover_state(self, state: bool) { + pub fn set_hover_state(&self, state: bool) { self.set_flag(IN_HOVER_STATE, state); self.dirty(NodeDamage::NodeStyleDamaged); } - fn get_focus_state(self) -> bool { + pub fn get_focus_state(&self) -> bool { self.get_flag(IN_FOCUS_STATE) } - fn set_focus_state(self, state: bool) { + pub fn set_focus_state(&self, state: bool) { self.set_flag(IN_FOCUS_STATE, state); self.dirty(NodeDamage::NodeStyleDamaged); } - fn get_active_state(self) -> bool { + pub fn get_active_state(&self) -> bool { self.get_flag(IN_ACTIVE_STATE) } - fn set_active_state(self, state: bool) { + pub fn set_active_state(&self, state: bool) { self.set_flag(IN_ACTIVE_STATE, state); self.dirty(NodeDamage::NodeStyleDamaged); } - fn get_disabled_state(self) -> bool { + pub fn get_disabled_state(&self) -> bool { self.get_flag(IN_DISABLED_STATE) } - fn set_disabled_state(self, state: bool) { + pub fn set_disabled_state(&self, state: bool) { self.set_flag(IN_DISABLED_STATE, state) } - fn get_enabled_state(self) -> bool { + pub fn get_enabled_state(&self) -> bool { self.get_flag(IN_ENABLED_STATE) } - fn set_enabled_state(self, state: bool) { + pub fn set_enabled_state(&self, state: bool) { self.set_flag(IN_ENABLED_STATE, state) } - fn get_has_changed(self) -> bool { + pub fn get_has_changed(&self) -> bool { self.get_flag(HAS_CHANGED) } - fn set_has_changed(self, state: bool) { + pub fn set_has_changed(&self, state: bool) { self.set_flag(HAS_CHANGED, state) } - fn get_is_dirty(self) -> bool { + pub fn get_is_dirty(&self) -> bool { self.get_flag(IS_DIRTY) } - fn set_is_dirty(self, state: bool) { + pub fn set_is_dirty(&self, state: bool) { self.set_flag(IS_DIRTY, state) } - fn get_has_dirty_siblings(self) -> bool { + pub fn get_has_dirty_siblings(&self) -> bool { self.get_flag(HAS_DIRTY_SIBLINGS) } - fn set_has_dirty_siblings(self, state: bool) { + pub fn set_has_dirty_siblings(&self, state: bool) { self.set_flag(HAS_DIRTY_SIBLINGS, state) } - fn get_has_dirty_descendants(self) -> bool { + pub fn get_has_dirty_descendants(&self) -> bool { self.get_flag(HAS_DIRTY_DESCENDANTS) } - fn set_has_dirty_descendants(self, state: bool) { + pub fn set_has_dirty_descendants(&self, state: bool) { self.set_flag(HAS_DIRTY_DESCENDANTS, state) } - fn force_dirty_ancestors(self, damage: NodeDamage) { + pub fn force_dirty_ancestors(&self, damage: NodeDamage) { self.dirty_impl(damage, true) } - fn dirty(self, damage: NodeDamage) { + pub fn dirty(&self, damage: NodeDamage) { self.dirty_impl(damage, false) } - fn dirty_impl(self, damage: NodeDamage, force_ancestors: bool) { + pub fn dirty_impl(&self, damage: NodeDamage, force_ancestors: bool) { // 1. Dirty self. match damage { NodeDamage::NodeStyleDamaged => {} @@ -755,83 +642,83 @@ impl<'a> NodeHelpers for &'a Node { } /// Iterates over this node and all its descendants, in preorder. - fn traverse_preorder(self) -> TreeIterator { + pub fn traverse_preorder(&self) -> TreeIterator { TreeIterator::new(self) } - fn inclusively_following_siblings(self) -> NodeSiblingIterator { + pub fn inclusively_following_siblings(&self) -> NodeSiblingIterator { NodeSiblingIterator { current: Some(Root::from_ref(self)), } } - fn inclusively_preceding_siblings(self) -> ReverseSiblingIterator { + pub fn inclusively_preceding_siblings(&self) -> ReverseSiblingIterator { ReverseSiblingIterator { current: Some(Root::from_ref(self)), } } - fn is_inclusive_ancestor_of(self, parent: &Node) -> bool { + pub fn is_inclusive_ancestor_of(&self, parent: &Node) -> bool { self == parent || parent.ancestors().any(|ancestor| ancestor.r() == self) } - fn following_siblings(self) -> NodeSiblingIterator { + pub fn following_siblings(&self) -> NodeSiblingIterator { NodeSiblingIterator { current: self.GetNextSibling(), } } - fn preceding_siblings(self) -> ReverseSiblingIterator { + pub fn preceding_siblings(&self) -> ReverseSiblingIterator { ReverseSiblingIterator { current: self.GetPreviousSibling(), } } - fn following_nodes(self, root: &Node) -> FollowingNodeIterator { + pub fn following_nodes(&self, root: &Node) -> FollowingNodeIterator { FollowingNodeIterator { current: Some(Root::from_ref(self)), root: Root::from_ref(root), } } - fn preceding_nodes(self, root: &Node) -> PrecedingNodeIterator { + pub fn preceding_nodes(&self, root: &Node) -> PrecedingNodeIterator { PrecedingNodeIterator { current: Some(Root::from_ref(self)), root: Root::from_ref(root), } } - fn descending_last_children(self) -> LastChildIterator { + pub fn descending_last_children(&self) -> LastChildIterator { LastChildIterator { current: self.GetLastChild(), } } - fn is_parent_of(self, child: &Node) -> bool { + pub fn is_parent_of(&self, child: &Node) -> bool { match child.parent_node.get() { Some(ref parent) => parent.root().r() == self, None => false, } } - fn to_trusted_node_address(self) -> TrustedNodeAddress { + pub fn to_trusted_node_address(&self) -> TrustedNodeAddress { TrustedNodeAddress(&*self as *const Node as *const libc::c_void) } - fn get_bounding_content_box(self) -> Rect { + pub fn get_bounding_content_box(&self) -> Rect { window_from_node(self).r().content_box_query(self.to_trusted_node_address()) } - fn get_content_boxes(self) -> Vec> { + pub fn get_content_boxes(&self) -> Vec> { window_from_node(self).r().content_boxes_query(self.to_trusted_node_address()) } - fn get_client_rect(self) -> Rect { + pub fn get_client_rect(&self) -> Rect { window_from_node(self).r().client_rect_query(self.to_trusted_node_address()) } // https://dom.spec.whatwg.org/#dom-childnode-before - fn before(self, nodes: Vec) -> ErrorResult { + pub fn before(&self, nodes: Vec) -> ErrorResult { // Step 1. let parent = &self.parent_node; @@ -860,7 +747,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#dom-childnode-after - fn after(self, nodes: Vec) -> ErrorResult { + pub fn after(&self, nodes: Vec) -> ErrorResult { // Step 1. let parent = &self.parent_node; @@ -883,7 +770,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#dom-childnode-replacewith - fn replace_with(self, nodes: Vec) -> ErrorResult { + pub fn replace_with(&self, nodes: Vec) -> ErrorResult { match self.parent_node.get() { None => { // Step 1. @@ -900,7 +787,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#dom-parentnode-prepend - fn prepend(self, nodes: Vec) -> ErrorResult { + pub fn prepend(&self, nodes: Vec) -> ErrorResult { // Step 1. let doc = self.owner_doc(); let node = try!(doc.r().node_from_nodes_and_strings(nodes)); @@ -910,7 +797,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#dom-parentnode-append - fn append(self, nodes: Vec) -> ErrorResult { + pub fn append(&self, nodes: Vec) -> ErrorResult { // Step 1. let doc = self.owner_doc(); let node = try!(doc.r().node_from_nodes_and_strings(nodes)); @@ -919,7 +806,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dom.spec.whatwg.org/#dom-parentnode-queryselector - fn query_selector(self, selectors: DOMString) -> Fallible>> { + pub fn query_selector(&self, selectors: DOMString) -> Fallible>> { // Step 1. match parse_author_origin_selector_list_from_str(&selectors) { // Step 2. @@ -939,7 +826,7 @@ impl<'a> NodeHelpers for &'a Node { /// Be careful not to do anything which may manipulate the DOM tree whilst iterating, otherwise /// the iterator may be invalidated #[allow(unsafe_code)] - unsafe fn query_selector_iter(self, selectors: DOMString) + pub unsafe fn query_selector_iter(&self, selectors: DOMString) -> Fallible { // Step 1. match parse_author_origin_selector_list_from_str(&selectors) { @@ -956,49 +843,49 @@ impl<'a> NodeHelpers for &'a Node { // https://dom.spec.whatwg.org/#dom-parentnode-queryselectorall #[allow(unsafe_code)] - fn query_selector_all(self, selectors: DOMString) -> Fallible> { + pub fn query_selector_all(&self, selectors: DOMString) -> Fallible> { let window = window_from_node(self); let iter = try!(unsafe { self.query_selector_iter(selectors) }); Ok(NodeList::new_simple_list(window.r(), iter)) } - fn ancestors(self) -> AncestorIterator { + pub fn ancestors(&self) -> AncestorIterator { AncestorIterator { current: self.GetParentNode() } } - fn inclusive_ancestors(self) -> AncestorIterator { + pub fn inclusive_ancestors(&self) -> AncestorIterator { AncestorIterator { current: Some(Root::from_ref(self)) } } - fn owner_doc(self) -> Root { + pub fn owner_doc(&self) -> Root { self.owner_doc.get().unwrap().root() } - fn set_owner_doc(self, document: &Document) { + pub fn set_owner_doc(&self, document: &Document) { self.owner_doc.set(Some(JS::from_ref(document))); } - fn is_in_html_doc(self) -> bool { + pub fn is_in_html_doc(&self) -> bool { self.owner_doc().r().is_html_document() } - fn children(self) -> NodeSiblingIterator { + pub fn children(&self) -> NodeSiblingIterator { NodeSiblingIterator { current: self.GetFirstChild(), } } - fn rev_children(self) -> ReverseSiblingIterator { + pub fn rev_children(&self) -> ReverseSiblingIterator { ReverseSiblingIterator { current: self.GetLastChild(), } } - fn child_elements(self) -> ChildElementIterator { + pub fn child_elements(&self) -> ChildElementIterator { fn to_temporary(node: Root) -> Option> { ElementCast::to_root(node) } @@ -1007,13 +894,13 @@ impl<'a> NodeHelpers for &'a Node { .peekable() } - fn remove_self(self) { + pub fn remove_self(&self) { if let Some(ref parent) = self.GetParentNode() { Node::remove(self, parent.r(), SuppressObserver::Unsuppressed); } } - fn get_unique_id(self) -> String { + pub fn get_unique_id(&self) -> String { if self.unique_id.borrow().is_empty() { let mut unique_id = self.unique_id.borrow_mut(); *unique_id = uuid::Uuid::new_v4().to_simple_string(); @@ -1021,7 +908,7 @@ impl<'a> NodeHelpers for &'a Node { self.unique_id.borrow().clone() } - fn summarize(self) -> NodeInfo { + pub fn summarize(&self) -> NodeInfo { NodeInfo { uniqueId: self.get_unique_id(), baseURI: self.BaseURI(), @@ -1057,7 +944,7 @@ impl<'a> NodeHelpers for &'a Node { } // https://dvcs.w3.org/hg/innerhtml/raw-file/tip/index.html#dfn-concept-parse-fragment - fn parse_fragment(self, markup: DOMString) -> Fallible> { + pub fn parse_fragment(&self, markup: DOMString) -> Fallible> { let context_node: &Node = NodeCast::from_ref(self); let context_document = document_from_node(self); let fragment = DocumentFragment::new(context_document.r()); @@ -2607,14 +2494,9 @@ impl VirtualMethods for Node { } } -pub trait DisabledStateHelpers { - fn check_ancestors_disabled_state_for_form_control(self); - fn check_parent_disabled_state_for_option(self); - fn check_disabled_attribute(self); -} -impl<'a> DisabledStateHelpers for &'a Node { - fn check_ancestors_disabled_state_for_form_control(self) { +impl Node { + pub fn check_ancestors_disabled_state_for_form_control(&self) { if self.get_disabled_state() { return; } for ancestor in self.ancestors() { let ancestor = ancestor; @@ -2641,7 +2523,7 @@ impl<'a> DisabledStateHelpers for &'a Node { } } - fn check_parent_disabled_state_for_option(self) { + pub fn check_parent_disabled_state_for_option(&self) { if self.get_disabled_state() { return; } if let Some(ref parent) = self.GetParentNode() { if parent.r().is_htmloptgroupelement() && parent.r().get_disabled_state() { @@ -2651,7 +2533,7 @@ impl<'a> DisabledStateHelpers for &'a Node { } } - fn check_disabled_attribute(self) { + pub fn check_disabled_attribute(&self) { let elem = ElementCast::to_ref(self).unwrap(); let has_disabled_attrib = elem.has_attribute(&atom!("disabled")); self.set_disabled_state(has_disabled_attrib); diff --git a/servo/components/script/dom/nodeiterator.rs b/servo/components/script/dom/nodeiterator.rs index ec12b951b236..31b90309c330 100644 --- a/servo/components/script/dom/nodeiterator.rs +++ b/servo/components/script/dom/nodeiterator.rs @@ -12,8 +12,8 @@ use dom::bindings::error::Fallible; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutHeap, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::document::{Document, DocumentHelpers}; -use dom::node::{Node, NodeHelpers}; +use dom::document::Document; +use dom::node::Node; use std::cell::Cell; use std::rc::Rc; @@ -191,14 +191,10 @@ impl<'a> NodeIteratorMethods for &'a NodeIterator { } } -trait PrivateNodeIteratorHelpers { - fn accept_node(self, node: &Node) -> Fallible; - fn is_root_node(self, node: &Node) -> bool; -} -impl<'a> PrivateNodeIteratorHelpers for &'a NodeIterator { +impl NodeIterator { // https://dom.spec.whatwg.org/#concept-node-filter - fn accept_node(self, node: &Node) -> Fallible { + fn accept_node(&self, node: &Node) -> Fallible { // Step 1. let n = node.NodeType() - 1; // Step 2. @@ -212,10 +208,6 @@ impl<'a> PrivateNodeIteratorHelpers for &'a NodeIterator { Filter::Callback(ref callback) => callback.AcceptNode_(self, node, Rethrow) } } - - fn is_root_node(self, node: &Node) -> bool { - JS::from_ref(node) == self.root_node - } } diff --git a/servo/components/script/dom/nodelist.rs b/servo/components/script/dom/nodelist.rs index eb3353a4d6ea..a39abe056a14 100644 --- a/servo/components/script/dom/nodelist.rs +++ b/servo/components/script/dom/nodelist.rs @@ -8,7 +8,7 @@ use dom::bindings::codegen::Bindings::NodeListBinding::NodeListMethods; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::node::{ChildrenMutation, Node, NodeHelpers}; +use dom::node::{ChildrenMutation, Node}; use dom::window::Window; use std::cell::Cell; @@ -79,12 +79,9 @@ impl<'a> NodeListMethods for &'a NodeList { } } -pub trait NodeListHelpers<'a> { - fn as_children_list(self) -> &'a ChildrenList; -} -impl<'a> NodeListHelpers<'a> for &'a NodeList { - fn as_children_list(self) -> &'a ChildrenList { +impl NodeList { + pub fn as_children_list(&self) -> &ChildrenList { if let NodeListType::Children(ref list) = self.list_type { list } else { diff --git a/servo/components/script/dom/performance.rs b/servo/components/script/dom/performance.rs index 703090fb3261..f2e59cf6aeea 100644 --- a/servo/components/script/dom/performance.rs +++ b/servo/components/script/dom/performance.rs @@ -8,7 +8,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::num::Finite; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::performancetiming::{PerformanceTiming, PerformanceTimingHelpers}; +use dom::performancetiming::PerformanceTiming; use dom::window::Window; use time; diff --git a/servo/components/script/dom/performancetiming.rs b/servo/components/script/dom/performancetiming.rs index 1bb6eb4aa65d..4d453dcb4bb7 100644 --- a/servo/components/script/dom/performancetiming.rs +++ b/servo/components/script/dom/performancetiming.rs @@ -46,12 +46,9 @@ impl<'a> PerformanceTimingMethods for &'a PerformanceTiming { } } -pub trait PerformanceTimingHelpers { - fn NavigationStartPrecise(self) -> f64; -} -impl<'a> PerformanceTimingHelpers for &'a PerformanceTiming { - fn NavigationStartPrecise(self) -> f64 { +impl PerformanceTiming { + pub fn NavigationStartPrecise(&self) -> f64 { self.navigationStartPrecise } } diff --git a/servo/components/script/dom/processinginstruction.rs b/servo/components/script/dom/processinginstruction.rs index 9bd7a9d5d5f5..aabe0b95f804 100644 --- a/servo/components/script/dom/processinginstruction.rs +++ b/servo/components/script/dom/processinginstruction.rs @@ -40,12 +40,9 @@ impl ProcessingInstruction { } } -pub trait ProcessingInstructionHelpers<'a> { - fn target(self) -> &'a DOMString; -} -impl<'a> ProcessingInstructionHelpers<'a> for &'a ProcessingInstruction { - fn target(self) -> &'a DOMString { +impl ProcessingInstruction { + pub fn target(&self) -> &DOMString { &self.target } } diff --git a/servo/components/script/dom/range.rs b/servo/components/script/dom/range.rs index fa0843bf00a3..58a1a51aeded 100644 --- a/servo/components/script/dom/range.rs +++ b/servo/components/script/dom/range.rs @@ -17,9 +17,9 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root, RootedReference}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::characterdata::CharacterDataTypeId; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::documentfragment::DocumentFragment; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use std::cell::RefCell; use std::cmp::{Ord, Ordering, PartialEq, PartialOrd}; @@ -125,12 +125,9 @@ impl Range { } } -pub trait RangeHelpers<'a> { - fn inner(self) -> &'a Rc>; -} -impl<'a> RangeHelpers<'a> for &'a Range { - fn inner(self) -> &'a Rc> { +impl Range { + pub fn inner(&self) -> &Rc> { &self.inner } } diff --git a/servo/components/script/dom/servohtmlparser.rs b/servo/components/script/dom/servohtmlparser.rs index 2450b4c8aa32..75d060ddf293 100644 --- a/servo/components/script/dom/servohtmlparser.rs +++ b/servo/components/script/dom/servohtmlparser.rs @@ -8,13 +8,15 @@ use document_loader::LoadType; use dom::bindings::cell::DOMRefCell; use dom::bindings::codegen::Bindings::ServoHTMLParserBinding; +use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::global::GlobalRef; use dom::bindings::js::{JS, Root}; use dom::bindings::refcounted::Trusted; use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::node::{window_from_node, Node}; +use dom::text::Text; use dom::window::Window; use network_listener::PreInvoke; use parse::Parser; @@ -27,7 +29,7 @@ use encoding::all::UTF_8; use encoding::types::{Encoding, DecoderTrap}; use html5ever::tokenizer; use html5ever::tree_builder; -use html5ever::tree_builder::{TreeBuilder, TreeBuilderOpts}; +use html5ever::tree_builder::{NodeOrText, TreeBuilder, TreeBuilderOpts}; use hyper::header::ContentType; use hyper::mime::{Mime, TopLevel, SubLevel}; use js::jsapi::JSTracer; @@ -42,6 +44,19 @@ pub struct Sink { pub document: JS, } +impl Sink { + pub fn get_or_create(&self, child: NodeOrText>) -> Root { + match child { + NodeOrText::AppendNode(n) => n.root(), + NodeOrText::AppendText(t) => { + let doc = self.document.root(); + let text = Text::new(t.into(), &doc); + NodeCast::from_root(text) + } + } + } +} + /// FragmentContext is used only to pass this group of related values /// into functions. #[derive(Copy, Clone)] @@ -272,16 +287,9 @@ impl ServoHTMLParser { } } -trait PrivateServoHTMLParserHelpers { - /// Synchronously run the tokenizer parse loop until explicitly suspended or - /// the tokenizer runs out of input. - fn parse_sync(self); - /// Retrieve the window object associated with this parser. - fn window(self) -> Root; -} -impl<'a> PrivateServoHTMLParserHelpers for &'a ServoHTMLParser { - fn parse_sync(self) { +impl ServoHTMLParser { + fn parse_sync(&self) { let mut first = true; // This parser will continue to parse while there is either pending input or @@ -314,28 +322,20 @@ impl<'a> PrivateServoHTMLParserHelpers for &'a ServoHTMLParser { } } - fn window(self) -> Root { + fn window(&self) -> Root { let doc = self.document.root(); window_from_node(doc.r()) } } -pub trait ServoHTMLParserHelpers { - /// Cause the parser to interrupt next time the tokenizer reaches a quiescent state. - /// No further parsing will occur after that point until the `resume` method is called. - /// Panics if the parser is already suspended. - fn suspend(self); - /// Immediately resume a suspended parser. Panics if the parser is not suspended. - fn resume(self); -} -impl<'a> ServoHTMLParserHelpers for &'a ServoHTMLParser { - fn suspend(self) { +impl ServoHTMLParser { + pub fn suspend(&self) { assert!(!self.suspended.get()); self.suspended.set(true); } - fn resume(self) { + pub fn resume(&self) { assert!(self.suspended.get()); self.suspended.set(false); self.parse_sync(); diff --git a/servo/components/script/dom/storage.rs b/servo/components/script/dom/storage.rs index 8d5d78d56a61..29872ab068a4 100644 --- a/servo/components/script/dom/storage.rs +++ b/servo/components/script/dom/storage.rs @@ -9,10 +9,9 @@ use dom::bindings::global::{GlobalRef, GlobalField}; use dom::bindings::js::{Root, RootedReference}; use dom::bindings::refcounted::Trusted; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::event::{EventHelpers, EventBubbles, EventCancelable}; +use dom::event::{EventBubbles, EventCancelable}; use dom::storageevent::StorageEvent; use dom::urlhelper::UrlHelper; -use dom::window::WindowHelpers; use ipc_channel::ipc; use net_traits::storage_task::{StorageTask, StorageTaskMsg, StorageType}; use page::IterablePage; @@ -140,14 +139,10 @@ impl<'a> StorageMethods for &'a Storage { } } -trait PrivateStorageHelpers { - fn broadcast_change_notification(self, key: Option, old_value: Option, - new_value: Option); -} -impl<'a> PrivateStorageHelpers for &'a Storage { +impl Storage { /// https://html.spec.whatwg.org/multipage/#send-a-storage-notification - fn broadcast_change_notification(self, key: Option, old_value: Option, + fn broadcast_change_notification(&self, key: Option, old_value: Option, new_value: Option) { let global_root = self.global.root(); let global_ref = global_root.r(); diff --git a/servo/components/script/dom/text.rs b/servo/components/script/dom/text.rs index 90913d85982e..cf4b85a9480f 100644 --- a/servo/components/script/dom/text.rs +++ b/servo/components/script/dom/text.rs @@ -13,10 +13,10 @@ use dom::bindings::error::{Error, Fallible}; use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::js::{RootedReference}; -use dom::characterdata::{CharacterData, CharacterDataHelpers, CharacterDataTypeId}; +use dom::characterdata::{CharacterData, CharacterDataTypeId}; use dom::document::Document; use dom::eventtarget::{EventTarget, EventTargetTypeId}; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use util::str::DOMString; /// An HTML text node. diff --git a/servo/components/script/dom/treewalker.rs b/servo/components/script/dom/treewalker.rs index 4c2fa150c5bd..73f2c44e7175 100644 --- a/servo/components/script/dom/treewalker.rs +++ b/servo/components/script/dom/treewalker.rs @@ -13,7 +13,7 @@ use dom::bindings::global::GlobalRef; use dom::bindings::js::Root; use dom::bindings::js::{JS, MutHeap}; use dom::bindings::utils::{Reflector, reflect_dom_object}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::node::Node; use std::rc::Rc; @@ -255,29 +255,10 @@ impl<'a> TreeWalkerMethods for &'a TreeWalker { type NodeAdvancer<'a> = Fn(&Node) -> Option> + 'a; -trait PrivateTreeWalkerHelpers { - fn traverse_children(self, - next_child: F, - next_sibling: G) - -> Fallible>> - where F: Fn(&Node) -> Option>, - G: Fn(&Node) -> Option>; - fn traverse_siblings(self, - next_child: F, - next_sibling: G) - -> Fallible>> - where F: Fn(&Node) -> Option>, - G: Fn(&Node) -> Option>; - fn is_root_node(self, node: &Node) -> bool; - fn is_current_node(self, node: &Node) -> bool; - fn first_following_node_not_following_root(self, node: &Node) - -> Option>; - fn accept_node(self, node: &Node) -> Fallible; -} -impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { +impl TreeWalker { // https://dom.spec.whatwg.org/#concept-traverse-children - fn traverse_children(self, + fn traverse_children(&self, next_child: F, next_sibling: G) -> Fallible>> @@ -352,7 +333,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { } // https://dom.spec.whatwg.org/#concept-traverse-siblings - fn traverse_siblings(self, + fn traverse_siblings(&self, next_child: F, next_sibling: G) -> Fallible>> @@ -414,7 +395,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { } // https://dom.spec.whatwg.org/#concept-tree-following - fn first_following_node_not_following_root(self, node: &Node) + fn first_following_node_not_following_root(&self, node: &Node) -> Option> { // "An object A is following an object B if A and B are in the same tree // and A comes after B in tree order." @@ -441,7 +422,7 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { } // https://dom.spec.whatwg.org/#concept-node-filter - fn accept_node(self, node: &Node) -> Fallible { + fn accept_node(&self, node: &Node) -> Fallible { // "To filter node run these steps:" // "1. Let n be node's nodeType attribute value minus 1." let n = node.NodeType() - 1; @@ -461,11 +442,11 @@ impl<'a> PrivateTreeWalkerHelpers for &'a TreeWalker { } } - fn is_root_node(self, node: &Node) -> bool { + fn is_root_node(&self, node: &Node) -> bool { JS::from_ref(node) == self.root_node } - fn is_current_node(self, node: &Node) -> bool { + fn is_current_node(&self, node: &Node) -> bool { JS::from_ref(node) == self.current_node.get() } } diff --git a/servo/components/script/dom/urlsearchparams.rs b/servo/components/script/dom/urlsearchparams.rs index f51440f51df9..29684ec7a38a 100644 --- a/servo/components/script/dom/urlsearchparams.rs +++ b/servo/components/script/dom/urlsearchparams.rs @@ -123,25 +123,19 @@ impl<'a> URLSearchParamsMethods for &'a URLSearchParams { } } -pub trait URLSearchParamsHelpers { - fn serialize(self, encoding: Option) -> DOMString; -} -impl<'a> URLSearchParamsHelpers for &'a URLSearchParams { +impl URLSearchParams { // https://url.spec.whatwg.org/#concept-urlencoded-serializer - fn serialize(self, encoding: Option) -> DOMString { + pub fn serialize(&self, encoding: Option) -> DOMString { let list = self.list.borrow(); serialize_with_encoding(list.iter(), encoding) } } -trait PrivateURLSearchParamsHelpers { - fn update_steps(self); -} -impl<'a> PrivateURLSearchParamsHelpers for &'a URLSearchParams { +impl URLSearchParams { // https://url.spec.whatwg.org/#concept-uq-update - fn update_steps(self) { + fn update_steps(&self) { // XXXManishearth Implement this when the URL interface is implemented } } diff --git a/servo/components/script/dom/userscripts.rs b/servo/components/script/dom/userscripts.rs index c82f640e1edf..3520cbe57456 100644 --- a/servo/components/script/dom/userscripts.rs +++ b/servo/components/script/dom/userscripts.rs @@ -6,9 +6,7 @@ use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::NodeCast; use dom::bindings::js::{RootedReference}; -use dom::element::AttributeHandlers; use dom::htmlheadelement::HTMLHeadElement; -use dom::node::NodeHelpers; use std::borrow::ToOwned; use std::fs::read_dir; use std::path::PathBuf; diff --git a/servo/components/script/dom/virtualmethods.rs b/servo/components/script/dom/virtualmethods.rs index 86dd2312084c..589a2b2461c7 100644 --- a/servo/components/script/dom/virtualmethods.rs +++ b/servo/components/script/dom/virtualmethods.rs @@ -37,7 +37,7 @@ use dom::element::ElementTypeId; use dom::event::Event; use dom::htmlelement::HTMLElementTypeId; use dom::node::NodeTypeId; -use dom::node::{ChildrenMutation, CloneChildrenFlag, Node, NodeHelpers}; +use dom::node::{ChildrenMutation, CloneChildrenFlag, Node}; use util::str::DOMString; diff --git a/servo/components/script/dom/webglbuffer.rs b/servo/components/script/dom/webglbuffer.rs index f3d8874de8fa..e5fc0295a905 100644 --- a/servo/components/script/dom/webglbuffer.rs +++ b/servo/components/script/dom/webglbuffer.rs @@ -49,19 +49,14 @@ impl WebGLBuffer { } } -pub trait WebGLBufferHelpers { - fn id(self) -> u32; - fn bind(self, target: u32) -> WebGLResult<()>; - fn delete(self); -} -impl<'a> WebGLBufferHelpers for &'a WebGLBuffer { - fn id(self) -> u32 { +impl WebGLBuffer { + pub fn id(&self) -> u32 { self.id } // NB: Only valid buffer targets come here - fn bind(self, target: u32) -> WebGLResult<()> { + pub fn bind(&self, target: u32) -> WebGLResult<()> { if let Some(previous_target) = self.target.get() { if target != previous_target { return Err(WebGLError::InvalidOperation); @@ -74,7 +69,7 @@ impl<'a> WebGLBufferHelpers for &'a WebGLBuffer { Ok(()) } - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteBuffer(self.id))).unwrap(); diff --git a/servo/components/script/dom/webglframebuffer.rs b/servo/components/script/dom/webglframebuffer.rs index c16435f0298a..c387fc2d711a 100644 --- a/servo/components/script/dom/webglframebuffer.rs +++ b/servo/components/script/dom/webglframebuffer.rs @@ -47,23 +47,18 @@ impl WebGLFramebuffer { } } -pub trait WebGLFramebufferHelpers { - fn id(self) -> u32; - fn bind(self, target: u32); - fn delete(self); -} -impl<'a> WebGLFramebufferHelpers for &'a WebGLFramebuffer { - fn id(self) -> u32 { +impl WebGLFramebuffer { + pub fn id(&self) -> u32 { self.id } - fn bind(self, target: u32) { + pub fn bind(&self, target: u32) { let cmd = CanvasWebGLMsg::BindFramebuffer(target, WebGLFramebufferBindingRequest::Explicit(self.id)); self.renderer.send(CanvasMsg::WebGL(cmd)).unwrap(); } - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteFramebuffer(self.id))).unwrap(); diff --git a/servo/components/script/dom/webglprogram.rs b/servo/components/script/dom/webglprogram.rs index 7aee6ad496a5..2a1a0cfc6a5f 100644 --- a/servo/components/script/dom/webglprogram.rs +++ b/servo/components/script/dom/webglprogram.rs @@ -9,7 +9,7 @@ use dom::bindings::js::{JS, MutNullableHeap, Root}; use dom::bindings::utils::reflect_dom_object; use dom::webglobject::WebGLObject; use dom::webglrenderingcontext::MAX_UNIFORM_AND_ATTRIBUTE_LEN; -use dom::webglshader::{WebGLShader, WebGLShaderHelpers}; +use dom::webglshader::WebGLShader; use dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; @@ -54,18 +54,10 @@ impl WebGLProgram { } } -pub trait WebGLProgramHelpers { - fn delete(self); - fn link(self); - fn use_program(self); - fn attach_shader(self, shader: &WebGLShader) -> WebGLResult<()>; - fn get_attrib_location(self, name: String) -> WebGLResult>; - fn get_uniform_location(self, name: String) -> WebGLResult>; -} -impl<'a> WebGLProgramHelpers for &'a WebGLProgram { +impl WebGLProgram { /// glDeleteProgram - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteProgram(self.id))).unwrap(); @@ -73,17 +65,17 @@ impl<'a> WebGLProgramHelpers for &'a WebGLProgram { } /// glLinkProgram - fn link(self) { + pub fn link(&self) { self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::LinkProgram(self.id))).unwrap(); } /// glUseProgram - fn use_program(self) { + pub fn use_program(&self) { self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::UseProgram(self.id))).unwrap(); } /// glAttachShader - fn attach_shader(self, shader: &WebGLShader) -> WebGLResult<()> { + pub fn attach_shader(&self, shader: &WebGLShader) -> WebGLResult<()> { let shader_slot = match shader.gl_type() { constants::FRAGMENT_SHADER => &self.fragment_shader, constants::VERTEX_SHADER => &self.vertex_shader, @@ -104,7 +96,7 @@ impl<'a> WebGLProgramHelpers for &'a WebGLProgram { } /// glGetAttribLocation - fn get_attrib_location(self, name: String) -> WebGLResult> { + pub fn get_attrib_location(&self, name: String) -> WebGLResult> { if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN { return Err(WebGLError::InvalidValue); } @@ -120,7 +112,7 @@ impl<'a> WebGLProgramHelpers for &'a WebGLProgram { } /// glGetUniformLocation - fn get_uniform_location(self, name: String) -> WebGLResult> { + pub fn get_uniform_location(&self, name: String) -> WebGLResult> { if name.len() > MAX_UNIFORM_AND_ATTRIBUTE_LEN { return Err(WebGLError::InvalidValue); } diff --git a/servo/components/script/dom/webglrenderbuffer.rs b/servo/components/script/dom/webglrenderbuffer.rs index fb286c88bb48..a8d963894b64 100644 --- a/servo/components/script/dom/webglrenderbuffer.rs +++ b/servo/components/script/dom/webglrenderbuffer.rs @@ -47,22 +47,17 @@ impl WebGLRenderbuffer { } } -pub trait WebGLRenderbufferHelpers { - fn id(self) -> u32; - fn bind(self, target: u32); - fn delete(self); -} -impl<'a> WebGLRenderbufferHelpers for &'a WebGLRenderbuffer { - fn id(self) -> u32 { +impl WebGLRenderbuffer { + pub fn id(&self) -> u32 { self.id } - fn bind(self, target: u32) { + pub fn bind(&self, target: u32) { self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::BindRenderbuffer(target, self.id))).unwrap(); } - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteRenderbuffer(self.id))).unwrap(); diff --git a/servo/components/script/dom/webglrenderingcontext.rs b/servo/components/script/dom/webglrenderingcontext.rs index 4b9f4d5795e5..0ad3d35f45bc 100644 --- a/servo/components/script/dom/webglrenderingcontext.rs +++ b/servo/components/script/dom/webglrenderingcontext.rs @@ -17,16 +17,14 @@ use dom::bindings::js::{JS, LayoutJS, Root}; use dom::bindings::utils::{Reflector, reflect_dom_object}; use dom::htmlcanvaselement::HTMLCanvasElement; use dom::htmlcanvaselement::utils as canvas_utils; -use dom::htmlimageelement::HTMLImageElementHelpers; -use dom::imagedata::ImageDataHelpers; -use dom::node::{window_from_node, NodeHelpers, NodeDamage}; -use dom::webglbuffer::{WebGLBuffer, WebGLBufferHelpers}; -use dom::webglframebuffer::{WebGLFramebuffer, WebGLFramebufferHelpers}; -use dom::webglprogram::{WebGLProgram, WebGLProgramHelpers}; -use dom::webglrenderbuffer::{WebGLRenderbuffer, WebGLRenderbufferHelpers}; -use dom::webglshader::{WebGLShader, WebGLShaderHelpers}; -use dom::webgltexture::{TexParameterValue, WebGLTexture, WebGLTextureHelpers}; -use dom::webgluniformlocation::{WebGLUniformLocation, WebGLUniformLocationHelpers}; +use dom::node::{window_from_node, NodeDamage}; +use dom::webglbuffer::WebGLBuffer; +use dom::webglframebuffer::WebGLFramebuffer; +use dom::webglprogram::WebGLProgram; +use dom::webglrenderbuffer::WebGLRenderbuffer; +use dom::webglshader::WebGLShader; +use dom::webgltexture::{TexParameterValue, WebGLTexture}; +use dom::webgluniformlocation::WebGLUniformLocation; use euclid::size::Size2D; use ipc_channel::ipc::{self, IpcSender}; use js::jsapi::{JSContext, JSObject, RootedValue}; @@ -906,13 +904,9 @@ impl<'a> WebGLRenderingContextMethods for &'a WebGLRenderingContext { } } -pub trait WebGLRenderingContextHelpers { - fn webgl_error(&self, err: WebGLError); - fn bound_texture_for(&self, target: u32) -> Option>; -} -impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext { - fn webgl_error(&self, err: WebGLError) { +impl WebGLRenderingContext { + pub fn webgl_error(&self, err: WebGLError) { // If an error has been detected no further errors must be // recorded until `getError` has been called if self.last_error.get().is_none() { @@ -920,7 +914,7 @@ impl<'a> WebGLRenderingContextHelpers for &'a WebGLRenderingContext { } } - fn bound_texture_for(&self, target: u32) -> Option> { + pub fn bound_texture_for(&self, target: u32) -> Option> { match target { constants::TEXTURE_2D => self.bound_texture_2d.get(), constants::TEXTURE_CUBE_MAP => self.bound_texture_cube_map.get(), diff --git a/servo/components/script/dom/webglshader.rs b/servo/components/script/dom/webglshader.rs index d18836419ebe..3920bcb7b7c5 100644 --- a/servo/components/script/dom/webglshader.rs +++ b/servo/components/script/dom/webglshader.rs @@ -59,35 +59,25 @@ impl WebGLShader { } } -pub trait WebGLShaderHelpers { - fn id(self) -> u32; - fn gl_type(self) -> u32; - fn compile(self); - fn delete(self); - fn info_log(self) -> Option; - fn parameter(self, param_id: u32) -> WebGLResult; - fn source(self) -> Option; - fn set_source(self, src: String); -} -impl<'a> WebGLShaderHelpers for &'a WebGLShader { - fn id(self) -> u32 { +impl WebGLShader { + pub fn id(&self) -> u32 { self.id } - fn gl_type(self) -> u32 { + pub fn gl_type(&self) -> u32 { self.gl_type } // TODO(ecoal95): Validate shaders to be conforming to the WebGL spec /// glCompileShader - fn compile(self) { + pub fn compile(&self) { self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::CompileShader(self.id))).unwrap() } /// Mark this shader as deleted (if it wasn't previously) /// and delete it as if calling glDeleteShader. - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteShader(self.id))).unwrap() @@ -95,14 +85,14 @@ impl<'a> WebGLShaderHelpers for &'a WebGLShader { } /// glGetShaderInfoLog - fn info_log(self) -> Option { + pub fn info_log(&self) -> Option { let (sender, receiver) = ipc::channel().unwrap(); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::GetShaderInfoLog(self.id, sender))).unwrap(); receiver.recv().unwrap() } /// glGetShaderParameter - fn parameter(self, param_id: u32) -> WebGLResult { + pub fn parameter(&self, param_id: u32) -> WebGLResult { match param_id { constants::SHADER_TYPE | constants::DELETE_STATUS | constants::COMPILE_STATUS => {}, _ => return Err(WebGLError::InvalidEnum), @@ -114,12 +104,12 @@ impl<'a> WebGLShaderHelpers for &'a WebGLShader { } /// Get the shader source - fn source(self) -> Option { + pub fn source(&self) -> Option { self.source.borrow().clone() } /// glShaderSource - fn set_source(self, source: String) { + pub fn set_source(&self, source: String) { *self.source.borrow_mut() = Some(source.clone()); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::ShaderSource(self.id, source))).unwrap() } diff --git a/servo/components/script/dom/webgltexture.rs b/servo/components/script/dom/webgltexture.rs index b14e8e85fe1d..c549a6b7513e 100644 --- a/servo/components/script/dom/webgltexture.rs +++ b/servo/components/script/dom/webgltexture.rs @@ -55,23 +55,14 @@ impl WebGLTexture { } } -pub trait WebGLTextureHelpers { - fn id(self) -> u32; - fn bind(self, target: u32) -> WebGLResult<()>; - fn delete(self); - fn tex_parameter(self, - target: u32, - name: u32, - value: TexParameterValue) -> WebGLResult<()>; -} -impl<'a> WebGLTextureHelpers for &'a WebGLTexture { - fn id(self) -> u32 { +impl WebGLTexture { + pub fn id(&self) -> u32 { self.id } // NB: Only valid texture targets come here - fn bind(self, target: u32) -> WebGLResult<()> { + pub fn bind(&self, target: u32) -> WebGLResult<()> { if let Some(previous_target) = self.target.get() { if target != previous_target { return Err(WebGLError::InvalidOperation); @@ -85,7 +76,7 @@ impl<'a> WebGLTextureHelpers for &'a WebGLTexture { Ok(()) } - fn delete(self) { + pub fn delete(&self) { if !self.is_deleted.get() { self.is_deleted.set(true); self.renderer.send(CanvasMsg::WebGL(CanvasWebGLMsg::DeleteTexture(self.id))).unwrap(); @@ -95,7 +86,7 @@ impl<'a> WebGLTextureHelpers for &'a WebGLTexture { /// We have to follow the conversion rules for GLES 2.0. See: /// https://www.khronos.org/webgl/public-mailing-list/archives/1008/msg00014.html /// - fn tex_parameter(self, + pub fn tex_parameter(&self, target: u32, name: u32, value: TexParameterValue) -> WebGLResult<()> { diff --git a/servo/components/script/dom/webgluniformlocation.rs b/servo/components/script/dom/webgluniformlocation.rs index 2eb9895ce706..ea30afc8b514 100644 --- a/servo/components/script/dom/webgluniformlocation.rs +++ b/servo/components/script/dom/webgluniformlocation.rs @@ -27,12 +27,9 @@ impl WebGLUniformLocation { } } -pub trait WebGLUniformLocationHelpers { - fn id(self) -> i32; -} -impl<'a> WebGLUniformLocationHelpers for &'a WebGLUniformLocation { - fn id(self) -> i32 { +impl WebGLUniformLocation { + pub fn id(&self) -> i32 { self.id } } diff --git a/servo/components/script/dom/websocket.rs b/servo/components/script/dom/websocket.rs index a3fed7616e26..59d11e239d27 100644 --- a/servo/components/script/dom/websocket.rs +++ b/servo/components/script/dom/websocket.rs @@ -19,8 +19,8 @@ use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{reflect_dom_object, Reflectable}; use dom::blob::Blob; use dom::closeevent::CloseEvent; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::messageevent::MessageEvent; use script_task::{Runnable, CommonScriptMsg}; diff --git a/servo/components/script/dom/window.rs b/servo/components/script/dom/window.rs index 6ca00fefbb63..3795b3e58eb9 100644 --- a/servo/components/script/dom/window.rs +++ b/servo/components/script/dom/window.rs @@ -21,12 +21,12 @@ use dom::browsercontext::BrowsingContext; use dom::console::Console; use dom::crypto::Crypto; use dom::cssstyledeclaration::{CSSModificationAccess, CSSStyleDeclaration}; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::element::Element; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::location::Location; use dom::navigator::Navigator; -use dom::node::{window_from_node, TrustedNodeAddress, NodeHelpers, from_untrusted_node_address}; +use dom::node::{window_from_node, TrustedNodeAddress, from_untrusted_node_address}; use dom::performance::Performance; use dom::screen::Screen; use dom::storage::Storage; @@ -591,54 +591,6 @@ impl<'a> WindowMethods for &'a Window { } } -pub trait WindowHelpers { - fn clear_js_runtime(self); - fn init_browsing_context(self, doc: &Document, frame_element: Option<&Element>); - fn load_url(self, url: Url); - fn handle_fire_timer(self, timer_id: TimerId); - fn force_reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason); - fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason); - fn join_layout(self); - fn layout(&self) -> &LayoutRPC; - fn content_box_query(self, content_box_request: TrustedNodeAddress) -> Rect; - fn content_boxes_query(self, content_boxes_request: TrustedNodeAddress) -> Vec>; - fn client_rect_query(self, node_geometry_request: TrustedNodeAddress) -> Rect; - fn resolved_style_query(self, element: TrustedNodeAddress, - pseudo: Option, property: &Atom) -> Option; - fn offset_parent_query(self, node: TrustedNodeAddress) -> (Option>, Rect); - fn handle_reflow_complete_msg(self, reflow_id: u32); - fn set_fragment_name(self, fragment: Option); - fn steal_fragment_name(self) -> Option; - fn set_window_size(self, size: WindowSizeData); - fn window_size(self) -> Option; - fn get_url(self) -> Url; - fn resource_task(self) -> ResourceTask; - fn mem_profiler_chan(self) -> mem::ProfilerChan; - fn devtools_chan(self) -> Option>; - fn layout_chan(self) -> LayoutChan; - fn constellation_chan(self) -> ConstellationChan; - fn windowproxy_handler(self) -> WindowProxyHandler; - fn get_next_subpage_id(self) -> SubpageId; - fn layout_is_idle(self) -> bool; - fn get_pending_reflow_count(self) -> u32; - fn add_pending_reflow(self); - fn set_resize_event(self, event: WindowSizeData); - fn steal_resize_event(self) -> Option; - fn set_page_clip_rect_with_new_viewport(self, viewport: Rect) -> bool; - fn set_devtools_wants_updates(self, value: bool); - fn IndexedGetter(self, _index: u32, _found: &mut bool) -> Option>; - fn thaw(self); - fn freeze(self); - fn need_emit_timeline_marker(self, timeline_type: TimelineMarkerType) -> bool; - fn emit_timeline_marker(self, marker: TimelineMarker); - fn set_devtools_timeline_marker(self, - marker: TimelineMarkerType, - reply: IpcSender); - fn drop_devtools_timeline_markers(self); - fn set_webdriver_script_chan(self, chan: Option>); - fn is_alive(self) -> bool; - fn parent(self) -> Option>; -} pub trait ScriptHelpers { fn evaluate_js_on_global_with_result(self, code: &str, @@ -677,8 +629,8 @@ impl<'a, T: Reflectable> ScriptHelpers for &'a T { } } -impl<'a> WindowHelpers for &'a Window { - fn clear_js_runtime(self) { +impl Window { + pub fn clear_js_runtime(&self) { let document = self.Document(); NodeCast::from_ref(document.r()).teardown(); @@ -703,7 +655,7 @@ impl<'a> WindowHelpers for &'a Window { /// and no reflow is performed. /// /// TODO(pcwalton): Only wait for style recalc, since we have off-main-thread layout. - fn force_reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason) { + pub fn force_reflow(&self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason) { let document = self.Document(); let root = document.r().GetDocumentElement(); let root = match root.r() { @@ -774,7 +726,7 @@ impl<'a> WindowHelpers for &'a Window { /// yet, the page is presumed invisible and no reflow is performed. /// /// TODO(pcwalton): Only wait for style recalc, since we have off-main-thread layout. - fn reflow(self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason) { + pub fn reflow(&self, goal: ReflowGoal, query_type: ReflowQueryType, reason: ReflowReason) { let document = self.Document(); let root = document.r().GetDocumentElement(); let root = match root.r() { @@ -797,7 +749,7 @@ impl<'a> WindowHelpers for &'a Window { /// Sends a ping to layout and waits for the response. The response will arrive when the /// layout task has finished any pending request messages. - fn join_layout(self) { + pub fn join_layout(&self) { let mut layout_join_port = self.layout_join_port.borrow_mut(); if let Some(join_port) = std_mem::replace(&mut *layout_join_port, None) { match join_port.try_recv() { @@ -815,11 +767,11 @@ impl<'a> WindowHelpers for &'a Window { } } - fn layout(&self) -> &LayoutRPC { + pub fn layout(&self) -> &LayoutRPC { &*self.layout_rpc } - fn content_box_query(self, content_box_request: TrustedNodeAddress) -> Rect { + pub fn content_box_query(&self, content_box_request: TrustedNodeAddress) -> Rect { self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxQuery(content_box_request), ReflowReason::Query); @@ -828,7 +780,7 @@ impl<'a> WindowHelpers for &'a Window { rect } - fn content_boxes_query(self, content_boxes_request: TrustedNodeAddress) -> Vec> { + pub fn content_boxes_query(&self, content_boxes_request: TrustedNodeAddress) -> Vec> { self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::ContentBoxesQuery(content_boxes_request), ReflowReason::Query); @@ -837,14 +789,14 @@ impl<'a> WindowHelpers for &'a Window { rects } - fn client_rect_query(self, node_geometry_request: TrustedNodeAddress) -> Rect { + pub fn client_rect_query(&self, node_geometry_request: TrustedNodeAddress) -> Rect { self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::NodeGeometryQuery(node_geometry_request), ReflowReason::Query); self.layout_rpc.node_geometry().client_rect } - fn resolved_style_query(self, + pub fn resolved_style_query(&self, element: TrustedNodeAddress, pseudo: Option, property: &Atom) -> Option { @@ -855,7 +807,7 @@ impl<'a> WindowHelpers for &'a Window { resolved } - fn offset_parent_query(self, node: TrustedNodeAddress) -> (Option>, Rect) { + pub fn offset_parent_query(&self, node: TrustedNodeAddress) -> (Option>, Rect) { self.reflow(ReflowGoal::ForScriptQuery, ReflowQueryType::OffsetParentQuery(node), ReflowReason::Query); @@ -876,105 +828,105 @@ impl<'a> WindowHelpers for &'a Window { (element, response.rect) } - fn handle_reflow_complete_msg(self, reflow_id: u32) { + pub fn handle_reflow_complete_msg(&self, reflow_id: u32) { let last_reflow_id = self.last_reflow_id.get(); if last_reflow_id == reflow_id { *self.layout_join_port.borrow_mut() = None; } } - fn init_browsing_context(self, doc: &Document, frame_element: Option<&Element>) { + pub fn init_browsing_context(&self, doc: &Document, frame_element: Option<&Element>) { let mut browsing_context = self.browsing_context.borrow_mut(); *browsing_context = Some(BrowsingContext::new(doc, frame_element)); (*browsing_context).as_mut().unwrap().create_window_proxy(); } /// Commence a new URL load which will either replace this window or scroll to a fragment. - fn load_url(self, url: Url) { + pub fn load_url(&self, url: Url) { self.main_thread_script_chan().send( MainThreadScriptMsg::Navigate(self.id, LoadData::new(url))).unwrap(); } - fn handle_fire_timer(self, timer_id: TimerId) { + pub fn handle_fire_timer(&self, timer_id: TimerId) { self.timers.fire_timer(timer_id, self); self.reflow(ReflowGoal::ForDisplay, ReflowQueryType::NoQuery, ReflowReason::Timer); } - fn set_fragment_name(self, fragment: Option) { + pub fn set_fragment_name(&self, fragment: Option) { *self.fragment_name.borrow_mut() = fragment; } - fn steal_fragment_name(self) -> Option { + pub fn steal_fragment_name(&self) -> Option { self.fragment_name.borrow_mut().take() } - fn set_window_size(self, size: WindowSizeData) { + pub fn set_window_size(&self, size: WindowSizeData) { self.window_size.set(Some(size)); } - fn window_size(self) -> Option { + pub fn window_size(&self) -> Option { self.window_size.get() } - fn get_url(self) -> Url { + pub fn get_url(&self) -> Url { let doc = self.Document(); doc.r().url() } - fn resource_task(self) -> ResourceTask { + pub fn resource_task(&self) -> ResourceTask { (*self.resource_task).clone() } - fn mem_profiler_chan(self) -> mem::ProfilerChan { + pub fn mem_profiler_chan(&self) -> mem::ProfilerChan { self.mem_profiler_chan.clone() } - fn devtools_chan(self) -> Option> { + pub fn devtools_chan(&self) -> Option> { self.devtools_chan.clone() } - fn layout_chan(self) -> LayoutChan { + pub fn layout_chan(&self) -> LayoutChan { self.layout_chan.clone() } - fn constellation_chan(self) -> ConstellationChan { + pub fn constellation_chan(&self) -> ConstellationChan { self.constellation_chan.clone() } - fn windowproxy_handler(self) -> WindowProxyHandler { + pub fn windowproxy_handler(&self) -> WindowProxyHandler { WindowProxyHandler(self.dom_static.windowproxy_handler.0) } - fn get_next_subpage_id(self) -> SubpageId { + pub fn get_next_subpage_id(&self) -> SubpageId { let subpage_id = self.next_subpage_id.get(); let SubpageId(id_num) = subpage_id; self.next_subpage_id.set(SubpageId(id_num + 1)); subpage_id } - fn layout_is_idle(self) -> bool { + pub fn layout_is_idle(&self) -> bool { self.layout_join_port.borrow().is_none() } - fn get_pending_reflow_count(self) -> u32 { + pub fn get_pending_reflow_count(&self) -> u32 { self.pending_reflow_count.get() } - fn add_pending_reflow(self) { + pub fn add_pending_reflow(&self) { self.pending_reflow_count.set(self.pending_reflow_count.get() + 1); } - fn set_resize_event(self, event: WindowSizeData) { + pub fn set_resize_event(&self, event: WindowSizeData) { self.resize_event.set(Some(event)); } - fn steal_resize_event(self) -> Option { + pub fn steal_resize_event(&self) -> Option { let event = self.resize_event.get(); self.resize_event.set(None); event } - fn set_page_clip_rect_with_new_viewport(self, viewport: Rect) -> bool { + pub fn set_page_clip_rect_with_new_viewport(&self, viewport: Rect) -> bool { // We use a clipping rectangle that is five times the size of the of the viewport, // so that we don't collect display list items for areas too far outside the viewport, // but also don't trigger reflows every time the viewport changes. @@ -999,16 +951,16 @@ impl<'a> WindowHelpers for &'a Window { had_clip_rect } - fn set_devtools_wants_updates(self, value: bool) { + pub fn set_devtools_wants_updates(&self, value: bool) { self.devtools_wants_updates.set(value); } // https://html.spec.whatwg.org/multipage/#accessing-other-browsing-contexts - fn IndexedGetter(self, _index: u32, _found: &mut bool) -> Option> { + pub fn IndexedGetter(&self, _index: u32, _found: &mut bool) -> Option> { None } - fn thaw(self) { + pub fn thaw(&self) { self.timers.resume(); // Push the document title to the compositor since we are @@ -1017,42 +969,42 @@ impl<'a> WindowHelpers for &'a Window { document.r().title_changed(); } - fn freeze(self) { + pub fn freeze(&self) { self.timers.suspend(); } - fn need_emit_timeline_marker(self, timeline_type: TimelineMarkerType) -> bool { + pub fn need_emit_timeline_marker(&self, timeline_type: TimelineMarkerType) -> bool { let markers = self.devtools_markers.borrow(); markers.contains(&timeline_type) } - fn emit_timeline_marker(self, marker: TimelineMarker) { + pub fn emit_timeline_marker(&self, marker: TimelineMarker) { let sender = self.devtools_marker_sender.borrow(); let sender = sender.as_ref().expect("There is no marker sender"); sender.send(marker).unwrap(); } - fn set_devtools_timeline_marker(self, + pub fn set_devtools_timeline_marker(&self, marker: TimelineMarkerType, reply: IpcSender) { *self.devtools_marker_sender.borrow_mut() = Some(reply); self.devtools_markers.borrow_mut().insert(marker); } - fn drop_devtools_timeline_markers(self) { + pub fn drop_devtools_timeline_markers(&self) { self.devtools_markers.borrow_mut().clear(); *self.devtools_marker_sender.borrow_mut() = None; } - fn set_webdriver_script_chan(self, chan: Option>) { + pub fn set_webdriver_script_chan(&self, chan: Option>) { *self.webdriver_script_chan.borrow_mut() = chan; } - fn is_alive(self) -> bool { + pub fn is_alive(&self) -> bool { self.current_state.get() == WindowState::Alive } - fn parent(self) -> Option> { + pub fn parent(&self) -> Option> { let browsing_context = self.browsing_context(); let browsing_context = browsing_context.as_ref().unwrap(); diff --git a/servo/components/script/dom/worker.rs b/servo/components/script/dom/worker.rs index c6226021afe3..5231a4a04748 100644 --- a/servo/components/script/dom/worker.rs +++ b/servo/components/script/dom/worker.rs @@ -16,10 +16,9 @@ use dom::bindings::trace::JSTraceable; use dom::bindings::utils::{Reflectable, reflect_dom_object}; use dom::dedicatedworkerglobalscope::{DedicatedWorkerGlobalScope, WorkerScriptMsg}; use dom::errorevent::ErrorEvent; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::messageevent::MessageEvent; -use dom::window::WindowHelpers; use dom::workerglobalscope::WorkerGlobalScopeInit; use devtools_traits::{DevtoolsPageInfo, ScriptToDevtoolsControlMsg}; diff --git a/servo/components/script/dom/workerglobalscope.rs b/servo/components/script/dom/workerglobalscope.rs index 346396fc3009..685137918df5 100644 --- a/servo/components/script/dom/workerglobalscope.rs +++ b/servo/components/script/dom/workerglobalscope.rs @@ -12,7 +12,6 @@ use dom::bindings::js::{JS, Root, MutNullableHeap}; use dom::bindings::utils::Reflectable; use dom::console::Console; use dom::crypto::Crypto; -use dom::dedicatedworkerglobalscope::DedicatedWorkerGlobalScopeHelpers; use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::window::{base64_atob, base64_btoa}; use dom::workerlocation::WorkerLocation; @@ -284,19 +283,9 @@ impl<'a> WorkerGlobalScopeMethods for &'a WorkerGlobalScope { } } -pub trait WorkerGlobalScopeHelpers { - fn execute_script(self, source: DOMString); - fn handle_fire_timer(self, timer_id: TimerId); - fn script_chan(self) -> Box; - fn pipeline(self) -> PipelineId; - fn new_script_pair(self) -> (Box, Box); - fn process_event(self, msg: CommonScriptMsg); - fn get_cx(self) -> *mut JSContext; - fn set_devtools_wants_updates(self, value: bool); -} -impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { - fn execute_script(self, source: DOMString) { +impl WorkerGlobalScope { + pub fn execute_script(&self, source: DOMString) { match self.runtime.evaluate_script( self.reflector().get_jsobject(), source, self.worker_url.serialize(), 1) { Ok(_) => (), @@ -310,7 +299,7 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { } } - fn script_chan(self) -> Box { + pub fn script_chan(&self) -> Box { let dedicated = DedicatedWorkerGlobalScopeCast::to_ref(self); match dedicated { @@ -319,7 +308,7 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { } } - fn pipeline(self) -> PipelineId { + pub fn pipeline(&self) -> PipelineId { let dedicated = DedicatedWorkerGlobalScopeCast::to_ref(self); match dedicated { @@ -328,7 +317,7 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { } } - fn new_script_pair(self) -> (Box, Box) { + pub fn new_script_pair(&self) -> (Box, Box) { let dedicated = DedicatedWorkerGlobalScopeCast::to_ref(self); match dedicated { @@ -337,7 +326,7 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { } } - fn process_event(self, msg: CommonScriptMsg) { + pub fn process_event(&self, msg: CommonScriptMsg) { let dedicated = DedicatedWorkerGlobalScopeCast::to_ref(self); match dedicated { @@ -346,15 +335,11 @@ impl<'a> WorkerGlobalScopeHelpers for &'a WorkerGlobalScope { } } - fn handle_fire_timer(self, timer_id: TimerId) { + pub fn handle_fire_timer(&self, timer_id: TimerId) { self.timers.fire_timer(timer_id, self); } - fn get_cx(self) -> *mut JSContext { - self.runtime.cx() - } - - fn set_devtools_wants_updates(self, value: bool) { + pub fn set_devtools_wants_updates(&self, value: bool) { self.devtools_wants_updates.set(value); } } diff --git a/servo/components/script/dom/xmlhttprequest.rs b/servo/components/script/dom/xmlhttprequest.rs index 54d62301ddbd..964a3066bfc6 100644 --- a/servo/components/script/dom/xmlhttprequest.rs +++ b/servo/components/script/dom/xmlhttprequest.rs @@ -20,10 +20,9 @@ use dom::bindings::refcounted::Trusted; use dom::bindings::str::ByteString; use dom::bindings::utils::{Reflectable, reflect_dom_object}; use dom::document::Document; -use dom::event::{Event, EventBubbles, EventCancelable, EventHelpers}; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::event::{Event, EventBubbles, EventCancelable}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; use dom::progressevent::ProgressEvent; -use dom::urlsearchparams::URLSearchParamsHelpers; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTarget; use dom::xmlhttprequesteventtarget::XMLHttpRequestEventTargetTypeId; use dom::xmlhttprequestupload::XMLHttpRequestUpload; @@ -747,29 +746,9 @@ impl XMLHttpRequestDerived for EventTarget { pub type TrustedXHRAddress = Trusted; -trait PrivateXMLHttpRequestHelpers { - fn change_ready_state(self, XMLHttpRequestState); - fn process_headers_available(self, cors_request: Option, - gen_id: GenerationId, metadata: Metadata) -> Result<(), Error>; - fn process_data_available(self, gen_id: GenerationId, payload: Vec); - fn process_response_complete(self, gen_id: GenerationId, status: Result<(), String>) -> ErrorResult; - fn process_partial_response(self, progress: XHRProgress); - fn terminate_ongoing_fetch(self); - fn insert_trusted_header(self, name: String, value: String); - fn dispatch_progress_event(self, upload: bool, type_: DOMString, loaded: u64, total: Option); - fn dispatch_upload_progress_event(self, type_: DOMString, partial_load: Option); - fn dispatch_response_progress_event(self, type_: DOMString); - fn text_response(self) -> DOMString; - fn set_timeout(self, timeout: u32); - fn cancel_timeout(self); - fn filter_response_headers(self) -> Headers; - fn discard_subsequent_responses(self); - fn fetch(self, load_data: LoadData, cors_request: Result,()>, - global: GlobalRef) -> ErrorResult; -} -impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { - fn change_ready_state(self, rs: XMLHttpRequestState) { +impl XMLHttpRequest { + fn change_ready_state(&self, rs: XMLHttpRequestState) { assert!(self.ready_state.get() != rs); self.ready_state.set(rs); let global = self.global.root(); @@ -781,7 +760,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { event.r().fire(target); } - fn process_headers_available(self, cors_request: Option, + fn process_headers_available(&self, cors_request: Option, gen_id: GenerationId, metadata: Metadata) -> Result<(), Error> { if let Some(ref req) = cors_request { @@ -801,11 +780,11 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { Ok(()) } - fn process_data_available(self, gen_id: GenerationId, payload: Vec) { + fn process_data_available(&self, gen_id: GenerationId, payload: Vec) { self.process_partial_response(XHRProgress::Loading(gen_id, ByteString::new(payload))); } - fn process_response_complete(self, gen_id: GenerationId, status: Result<(), String>) + fn process_response_complete(&self, gen_id: GenerationId, status: Result<(), String>) -> ErrorResult { match status { Ok(()) => { @@ -819,7 +798,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { } } - fn process_partial_response(self, progress: XHRProgress) { + fn process_partial_response(&self, progress: XHRProgress) { let msg_id = progress.generation_id(); // Aborts processing if abort() or open() was called @@ -941,20 +920,20 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { } } - fn terminate_ongoing_fetch(self) { + fn terminate_ongoing_fetch(&self) { let GenerationId(prev_id) = self.generation_id.get(); self.generation_id.set(GenerationId(prev_id + 1)); *self.timeout_target.borrow_mut() = None; self.response_status.set(Ok(())); } - fn insert_trusted_header(self, name: String, value: String) { + fn insert_trusted_header(&self, name: String, value: String) { // Insert a header without checking spec-compliance // Use for hardcoded headers self.request_headers.borrow_mut().set_raw(name, vec![value.into_bytes()]); } - fn dispatch_progress_event(self, upload: bool, type_: DOMString, loaded: u64, total: Option) { + fn dispatch_progress_event(&self, upload: bool, type_: DOMString, loaded: u64, total: Option) { let global = self.global.root(); let upload_target = self.upload.root(); let progressevent = ProgressEvent::new(global.r(), @@ -970,19 +949,19 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { event.fire(target); } - fn dispatch_upload_progress_event(self, type_: DOMString, partial_load: Option) { + fn dispatch_upload_progress_event(&self, type_: DOMString, partial_load: Option) { // If partial_load is None, loading has completed and we can just use the value from the request body let total = self.request_body_len.get() as u64; self.dispatch_progress_event(true, type_, partial_load.unwrap_or(total), Some(total)); } - fn dispatch_response_progress_event(self, type_: DOMString) { + fn dispatch_response_progress_event(&self, type_: DOMString) { let len = self.response.borrow().len() as u64; let total = self.response_headers.borrow().get::().map(|x| {**x as u64}); self.dispatch_progress_event(false, type_, len, total); } - fn set_timeout(self, duration_ms: u32) { + fn set_timeout(&self, duration_ms: u32) { struct XHRTimeout { xhr: TrustedXHRAddress, gen_id: GenerationId, @@ -1025,13 +1004,13 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { ); } - fn cancel_timeout(self) { + fn cancel_timeout(&self) { if let Some(cancel_tx) = self.timeout_cancel.borrow_mut().take() { let _ = cancel_tx.send(()); } } - fn text_response(self) -> DOMString { + fn text_response(&self) -> DOMString { let mut encoding = UTF_8 as EncodingRef; match self.response_headers.borrow().get() { Some(&ContentType(mime::Mime(_, _, ref params))) => { @@ -1049,7 +1028,7 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { // the result should be fine. XXXManishearth have a closer look at this later encoding.decode(&self.response.borrow(), DecoderTrap::Replace).unwrap().to_owned() } - fn filter_response_headers(self) -> Headers { + fn filter_response_headers(&self) -> Headers { // https://fetch.spec.whatwg.org/#concept-response-header-list use hyper::error::Result; use hyper::header::SetCookie; @@ -1081,11 +1060,11 @@ impl<'a> PrivateXMLHttpRequestHelpers for &'a XMLHttpRequest { headers } - fn discard_subsequent_responses(self) { + fn discard_subsequent_responses(&self) { self.response_status.set(Err(())); } - fn fetch(self, + fn fetch(&self, load_data: LoadData, cors_request: Result,()>, global: GlobalRef) -> ErrorResult { diff --git a/servo/components/script/dom/xmlhttprequesteventtarget.rs b/servo/components/script/dom/xmlhttprequesteventtarget.rs index 548104e9435e..e771d7d76c0f 100644 --- a/servo/components/script/dom/xmlhttprequesteventtarget.rs +++ b/servo/components/script/dom/xmlhttprequesteventtarget.rs @@ -6,7 +6,7 @@ use dom::bindings::codegen::Bindings::EventHandlerBinding::EventHandlerNonNull; use dom::bindings::codegen::Bindings::XMLHttpRequestEventTargetBinding::XMLHttpRequestEventTargetMethods; use dom::bindings::codegen::InheritTypes::EventTargetCast; use dom::bindings::codegen::InheritTypes::XMLHttpRequestEventTargetDerived; -use dom::eventtarget::{EventTarget, EventTargetHelpers, EventTargetTypeId}; +use dom::eventtarget::{EventTarget, EventTargetTypeId}; #[derive(JSTraceable, Copy, Clone, PartialEq, HeapSizeOf)] pub enum XMLHttpRequestEventTargetTypeId { diff --git a/servo/components/script/page.rs b/servo/components/script/page.rs index cea63c08a38b..25dd39cad6e9 100644 --- a/servo/components/script/page.rs +++ b/servo/components/script/page.rs @@ -4,8 +4,7 @@ use dom::bindings::cell::DOMRefCell; use dom::bindings::js::{JS, Root}; -use dom::document::{Document, DocumentHelpers}; -use dom::node::NodeHelpers; +use dom::document::Document; use dom::window::Window; use msg::constellation_msg::PipelineId; diff --git a/servo/components/script/parse/html.rs b/servo/components/script/parse/html.rs index 872fd334ab44..a2dd0109ed13 100644 --- a/servo/components/script/parse/html.rs +++ b/servo/components/script/parse/html.rs @@ -5,7 +5,6 @@ #![allow(unsafe_code, unrooted_must_root)] use document_loader::DocumentLoader; -use dom::attr::AttrHelpers; use dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use dom::bindings::codegen::Bindings::NodeBinding::NodeMethods; use dom::bindings::codegen::InheritTypes::ProcessingInstructionCast; @@ -14,20 +13,17 @@ use dom::bindings::codegen::InheritTypes::{ElementCast, HTMLScriptElementCast}; use dom::bindings::codegen::InheritTypes::{HTMLFormElementDerived, NodeCast}; use dom::bindings::js::{JS, Root}; use dom::bindings::js::{RootedReference}; -use dom::characterdata::{CharacterDataHelpers, CharacterDataTypeId}; +use dom::characterdata::CharacterDataTypeId; use dom::comment::Comment; -use dom::document::{Document, DocumentHelpers}; +use dom::document::Document; use dom::document::{DocumentSource, IsHTMLDocument}; use dom::documenttype::DocumentType; -use dom::element::{Element, AttributeHandlers, ElementHelpers, ElementCreator}; +use dom::element::{Element, ElementCreator}; use dom::htmlscriptelement::HTMLScriptElement; -use dom::htmlscriptelement::HTMLScriptElementHelpers; -use dom::node::{Node, NodeHelpers, NodeTypeId}; +use dom::node::{Node, NodeTypeId}; use dom::node::{document_from_node, window_from_node}; -use dom::processinginstruction::ProcessingInstructionHelpers; use dom::servohtmlparser; use dom::servohtmlparser::{ServoHTMLParser, FragmentContext}; -use dom::text::Text; use parse::Parser; use encoding::types::Encoding; @@ -36,7 +32,7 @@ use html5ever::Attribute; use html5ever::serialize::TraversalScope; use html5ever::serialize::TraversalScope::{IncludeNode, ChildrenOnly}; use html5ever::serialize::{Serializable, Serializer, AttrRef}; -use html5ever::tree_builder::{TreeSink, QuirksMode, NodeOrText, AppendNode, AppendText, NextParserState}; +use html5ever::tree_builder::{NextParserState, NodeOrText, QuirksMode, TreeSink}; use msg::constellation_msg::PipelineId; use std::borrow::Cow; use std::io::{self, Write}; @@ -45,23 +41,6 @@ use tendril::StrTendril; use url::Url; use util::str::DOMString; -trait SinkHelpers { - fn get_or_create(&self, child: NodeOrText>) -> Root; -} - -impl SinkHelpers for servohtmlparser::Sink { - fn get_or_create(&self, child: NodeOrText>) -> Root { - match child { - AppendNode(n) => n.root(), - AppendText(t) => { - let doc = self.document.root(); - let text = Text::new(t.into(), doc.r()); - NodeCast::from_root(text) - } - } - } -} - impl<'a> TreeSink for servohtmlparser::Sink { type Handle = JS; fn get_document(&mut self) -> JS { diff --git a/servo/components/script/script_task.rs b/servo/components/script/script_task.rs index 17e0a58314ff..f9d156ecaaa2 100644 --- a/servo/components/script/script_task.rs +++ b/servo/components/script/script_task.rs @@ -33,15 +33,14 @@ use dom::bindings::js::{RootCollectionPtr, Root, RootedReference}; use dom::bindings::refcounted::{LiveDOMReferences, Trusted, TrustedReference, trace_refcounted_objects}; use dom::bindings::trace::{JSTraceable, trace_traceables, RootedVec}; use dom::bindings::utils::{WRAP_CALLBACKS, DOM_CALLBACKS}; -use dom::document::{Document, IsHTMLDocument, DocumentHelpers, DocumentProgressHandler}; +use dom::document::{Document, IsHTMLDocument, DocumentProgressHandler}; use dom::document::{DocumentProgressTask, DocumentSource, MouseEventType}; -use dom::element::{Element, AttributeHandlers}; -use dom::event::{EventHelpers, EventBubbles, EventCancelable}; -use dom::htmliframeelement::HTMLIFrameElementHelpers; -use dom::node::{Node, NodeHelpers, NodeDamage, window_from_node}; +use dom::element::Element; +use dom::event::{EventBubbles, EventCancelable}; +use dom::node::{Node, NodeDamage, window_from_node}; use dom::servohtmlparser::{ServoHTMLParser, ParserContext}; use dom::uievent::UIEvent; -use dom::window::{Window, WindowHelpers, ScriptHelpers, ReflowReason}; +use dom::window::{Window, ScriptHelpers, ReflowReason}; use dom::worker::TrustedWorkerAddress; use layout_interface::{ReflowQueryType}; use layout_interface::{self, NewLayoutTaskInfo, ScriptLayoutChan, LayoutChan, ReflowGoal}; diff --git a/servo/components/script/textinput.rs b/servo/components/script/textinput.rs index b2c2afdec0f3..ebfdadf954b1 100644 --- a/servo/components/script/textinput.rs +++ b/servo/components/script/textinput.rs @@ -5,7 +5,7 @@ //! Common handling of keyboard input and state management for text input controls use clipboard_provider::ClipboardProvider; -use dom::keyboardevent::{KeyboardEvent, KeyboardEventHelpers, key_value}; +use dom::keyboardevent::{KeyboardEvent, key_value}; use msg::constellation_msg::{Key, KeyModifiers}; use msg::constellation_msg::{SHIFT, CONTROL, ALT, SUPER}; use util::mem::HeapSizeOf; diff --git a/servo/components/script/webdriver_handlers.rs b/servo/components/script/webdriver_handlers.rs index e25e1fb247cc..5c97eca42cb3 100644 --- a/servo/components/script/webdriver_handlers.rs +++ b/servo/components/script/webdriver_handlers.rs @@ -11,9 +11,8 @@ use dom::bindings::codegen::InheritTypes::{NodeCast, ElementCast, HTMLIFrameElem use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::StringificationBehavior; use dom::bindings::js::Root; -use dom::document::DocumentHelpers; -use dom::node::{Node, NodeHelpers}; -use dom::window::{ScriptHelpers, WindowHelpers}; +use dom::node::Node; +use dom::window::ScriptHelpers; use js::jsapi::JSContext; use js::jsapi::{RootedValue, HandleValue}; use js::jsval::UndefinedValue;