From c831c2c0a528b6a04b355cc51169023f8c29b761 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Thu, 27 Aug 2015 01:22:42 +0200 Subject: Remove helper traits Now that JSRef is gone, there is no need to have helper traits. On components/script/*.rs: # Remove imports. /^ *use dom::[a-z]+::\{.*Helpers/ { s/\{(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers, /\{/ s/, (Raw[^L]|[^L][^a])[a-zA-Z]+Helpers([,}])/\2/g s/\{([a-zA-Z]+)\}/\1/ /\{\}/d s/::self;$/;/ } /^ *use dom::[a-z]+::\{?(Raw[^L]|[^L][^a])[a-zA-Z]+Helpers\}?;$/d On components/script/dom/*.rs: # Ignore layout things. /^(pub )?(impl|trait).*Layout.* \{/,/^}$/ { P; D; } # Delete helpers traits. /^(pub )?trait ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? \{$/,/^\}$/D # Patch private helpers. /^impl.*Private.*Helpers/,/^\}$/ { s/^impl<'a> Private([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for &'a ([^ ]+) \{$/impl \3 {/ /^ *(unsafe )?fn .*\(self.*[<&]'a/ { s/&'a /\&/g s/<'a, /)? ([^L][^ ]|L[^a])[^ ]+Helpers(<'a>)? for (&'a )?([^ ]+) \{$/impl \5 {/ /^ *(unsafe )?fn .*\(self.*[<&]'a/ { s/&'a /\&/g s/<'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(); -- cgit v1.2.3