Improve documentation for devtools messages a bit more.

This commit is contained in:
Josh Matthews 2015-08-13 11:55:39 -04:00
parent c81c3a2f70
commit 820c74649b
3 changed files with 19 additions and 9 deletions

View file

@ -5,7 +5,7 @@
//! Liberally derived from the [Firefox JS implementation] //! Liberally derived from the [Firefox JS implementation]
//! (http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/inspector.js). //! (http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/inspector.js).
use devtools_traits::{DevtoolScriptControlMsg, NodeInfo}; use devtools_traits::{DevtoolScriptControlMsg, NodeInfo, ComputedNodeLayout};
use devtools_traits::DevtoolScriptControlMsg::{GetRootNode, GetDocumentElement, GetChildren}; use devtools_traits::DevtoolScriptControlMsg::{GetRootNode, GetDocumentElement, GetChildren};
use devtools_traits::DevtoolScriptControlMsg::{GetLayout, ModifyAttribute}; use devtools_traits::DevtoolScriptControlMsg::{GetLayout, ModifyAttribute};
@ -458,7 +458,7 @@ impl Actor for PageStyleActor {
registry.actor_to_script(target.to_string()), registry.actor_to_script(target.to_string()),
tx)) tx))
.unwrap(); .unwrap();
let (width, height) = rx.recv().unwrap(); let ComputedNodeLayout { width, height } = rx.recv().unwrap();
let auto_margins = msg.get(&"autoMargins".to_string()) let auto_margins = msg.get(&"autoMargins".to_string())
.and_then(&Json::as_boolean).unwrap_or(false); .and_then(&Json::as_boolean).unwrap_or(false);

View file

@ -145,24 +145,31 @@ pub enum TimelineMarkerType {
DOMEvent, DOMEvent,
} }
/// The properties of a DOM node as computed by layout.
#[derive(Deserialize, Serialize)]
pub struct ComputedNodeLayout {
pub width: f32,
pub height: f32,
}
/// Messages to process in a particular script task, as instructed by a devtools client. /// Messages to process in a particular script task, as instructed by a devtools client.
#[derive(Deserialize, Serialize)] #[derive(Deserialize, Serialize)]
pub enum DevtoolScriptControlMsg { pub enum DevtoolScriptControlMsg {
/// Evaluate a JS snippet in the context of the global for the given pipeline. /// Evaluate a JS snippet in the context of the global for the given pipeline.
EvaluateJS(PipelineId, String, IpcSender<EvaluateJSReply>), EvaluateJS(PipelineId, String, IpcSender<EvaluateJSReply>),
/// Retrieve the details of the root node (ie. document) for the given pipeline. /// Retrieve the details of the root node (ie. the document) for the given pipeline.
GetRootNode(PipelineId, IpcSender<NodeInfo>), GetRootNode(PipelineId, IpcSender<NodeInfo>),
/// Retrieve the details of the document element for the given pipeline. /// Retrieve the details of the document element for the given pipeline.
GetDocumentElement(PipelineId, IpcSender<NodeInfo>), GetDocumentElement(PipelineId, IpcSender<NodeInfo>),
/// Retrieve the details of the child nodes of the given node in the given pipeline. /// Retrieve the details of the child nodes of the given node in the given pipeline.
GetChildren(PipelineId, String, IpcSender<Vec<NodeInfo>>), GetChildren(PipelineId, String, IpcSender<Vec<NodeInfo>>),
/// Retrieve the computed layout properties of the given node in the given pipeline. /// Retrieve the computed layout properties of the given node in the given pipeline.
GetLayout(PipelineId, String, IpcSender<(f32, f32)>), GetLayout(PipelineId, String, IpcSender<ComputedNodeLayout>),
/// Retrieve all stored console messages for a given pipeline. /// Retrieve all stored console messages for the given pipeline.
GetCachedMessages(PipelineId, CachedConsoleMessageTypes, IpcSender<Vec<CachedConsoleMessage>>), GetCachedMessages(PipelineId, CachedConsoleMessageTypes, IpcSender<Vec<CachedConsoleMessage>>),
/// Update a given node's attributes with a list of modifications. /// Update a given node's attributes with a list of modifications.
ModifyAttribute(PipelineId, String, Vec<Modification>), ModifyAttribute(PipelineId, String, Vec<Modification>),
/// Request live console messages for a given pipeline. /// Request live console messages for a given pipeline (true if desired, false otherwise).
WantsLiveNotifications(PipelineId, bool), WantsLiveNotifications(PipelineId, bool),
/// Request live notifications for a given set of timeline events for a given pipeline. /// Request live notifications for a given set of timeline events for a given pipeline.
SetTimelineMarkers(PipelineId, Vec<TimelineMarkerType>, IpcSender<TimelineMarker>), SetTimelineMarkers(PipelineId, Vec<TimelineMarkerType>, IpcSender<TimelineMarker>),

View file

@ -4,7 +4,7 @@
use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API}; use devtools_traits::{CachedConsoleMessage, CachedConsoleMessageTypes, PAGE_ERROR, CONSOLE_API};
use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType}; use devtools_traits::{EvaluateJSReply, NodeInfo, Modification, TimelineMarker, TimelineMarkerType};
use devtools_traits::{ConsoleAPI, PageError, ScriptToDevtoolsControlMsg}; use devtools_traits::{ConsoleAPI, PageError, ScriptToDevtoolsControlMsg, ComputedNodeLayout};
use dom::bindings::conversions::jsstring_to_str; use dom::bindings::conversions::jsstring_to_str;
use dom::bindings::conversions::FromJSValConvertible; use dom::bindings::conversions::FromJSValConvertible;
use dom::bindings::js::Root; use dom::bindings::js::Root;
@ -97,13 +97,16 @@ pub fn handle_get_children(page: &Rc<Page>, pipeline: PipelineId, node_id: Strin
reply.send(children).unwrap(); reply.send(children).unwrap();
} }
pub fn handle_get_layout(page: &Rc<Page>, pipeline: PipelineId, node_id: String, reply: IpcSender<(f32, f32)>) { pub fn handle_get_layout(page: &Rc<Page>,
pipeline: PipelineId,
node_id: String,
reply: IpcSender<ComputedNodeLayout>) {
let node = find_node_by_unique_id(&*page, pipeline, node_id); let node = find_node_by_unique_id(&*page, pipeline, node_id);
let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element"); let elem = ElementCast::to_ref(node.r()).expect("should be getting layout of element");
let rect = elem.GetBoundingClientRect(); let rect = elem.GetBoundingClientRect();
let width = *rect.r().Width(); let width = *rect.r().Width();
let height = *rect.r().Height(); let height = *rect.r().Height();
reply.send((width, height)).unwrap(); reply.send(ComputedNodeLayout { width: width, height: height }).unwrap();
} }
pub fn handle_get_cached_messages(_pipeline_id: PipelineId, pub fn handle_get_cached_messages(_pipeline_id: PipelineId,