mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +01:00
Implemeneted ModifyAttribute handler to update DOM elements.
This commit is contained in:
parent
ad9aedac77
commit
72a5ae7210
6 changed files with 208 additions and 93 deletions
|
@ -5,7 +5,7 @@
|
|||
/// Liberally derived from the [Firefox JS implementation](http://mxr.mozilla.org/mozilla-central/source/toolkit/devtools/server/actors/inspector.js).
|
||||
|
||||
use devtools_traits::{GetRootNode, GetDocumentElement, GetChildren, DevtoolScriptControlMsg};
|
||||
use devtools_traits::{GetLayout, NodeInfo};
|
||||
use devtools_traits::{GetLayout, NodeInfo, ModifyAttribute};
|
||||
|
||||
use actor::{Actor, ActorRegistry};
|
||||
use protocol::JsonPacketStream;
|
||||
|
@ -41,6 +41,12 @@ struct HighlighterActor {
|
|||
name: String,
|
||||
}
|
||||
|
||||
pub struct NodeActor {
|
||||
pub name: String,
|
||||
script_chan: Sender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId,
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
struct ShowBoxModelReply {
|
||||
from: String,
|
||||
|
@ -52,7 +58,7 @@ struct HideBoxModelReply {
|
|||
}
|
||||
|
||||
impl Actor for HighlighterActor {
|
||||
fn name(&self) -> String {
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
|
@ -83,6 +89,44 @@ impl Actor for HighlighterActor {
|
|||
}
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
struct ModifyAttributeReply{
|
||||
from: String,
|
||||
}
|
||||
|
||||
impl Actor for NodeActor {
|
||||
fn name(&self) -> String {
|
||||
self.name.clone()
|
||||
}
|
||||
|
||||
fn handle_message(&self,
|
||||
registry: &ActorRegistry,
|
||||
msg_type: &String,
|
||||
msg: &json::JsonObject,
|
||||
stream: &mut TcpStream) -> bool {
|
||||
match msg_type.as_slice() {
|
||||
"modifyAttributes" => {
|
||||
let target = msg.get(&"to".to_string()).unwrap().as_string().unwrap();
|
||||
let mods = msg.get(&"modifications".to_string()).unwrap().as_list().unwrap();
|
||||
let modifications = mods.iter().map(|json_mod| {
|
||||
json::decode(json_mod.to_string().as_slice()).unwrap()
|
||||
}).collect();
|
||||
|
||||
self.script_chan.send(ModifyAttribute(self.pipeline,
|
||||
registry.actor_to_script(target.to_string()),
|
||||
modifications));
|
||||
let reply = ModifyAttributeReply{
|
||||
from: self.name(),
|
||||
};
|
||||
stream.write_json_packet(&reply);
|
||||
true
|
||||
}
|
||||
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Encodable)]
|
||||
struct GetWalkerReply {
|
||||
from: String,
|
||||
|
@ -131,14 +175,28 @@ struct NodeActorMsg {
|
|||
}
|
||||
|
||||
trait NodeInfoToProtocol {
|
||||
fn encode(self, actors: &ActorRegistry, display: bool) -> NodeActorMsg;
|
||||
fn encode(self,
|
||||
actors: &ActorRegistry,
|
||||
display: bool,
|
||||
script_chan: Sender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId) -> NodeActorMsg;
|
||||
}
|
||||
|
||||
impl NodeInfoToProtocol for NodeInfo {
|
||||
fn encode(self, actors: &ActorRegistry, display: bool) -> NodeActorMsg {
|
||||
fn encode(self,
|
||||
actors: &ActorRegistry,
|
||||
display: bool,
|
||||
script_chan: Sender<DevtoolScriptControlMsg>,
|
||||
pipeline: PipelineId) -> NodeActorMsg {
|
||||
let actor_name = if !actors.script_actor_registered(self.uniqueId.clone()) {
|
||||
let name = actors.new_name("node");
|
||||
let node_actor = NodeActor {
|
||||
name: name.clone(),
|
||||
script_chan: script_chan,
|
||||
pipeline: pipeline.clone(),
|
||||
};
|
||||
actors.register_script_actor(self.uniqueId, name.clone());
|
||||
actors.register_later(box node_actor);
|
||||
name
|
||||
} else {
|
||||
actors.script_to_actor(self.uniqueId)
|
||||
|
@ -232,8 +290,7 @@ impl Actor for WalkerActor {
|
|||
let (tx, rx) = channel();
|
||||
self.script_chan.send(GetDocumentElement(self.pipeline, tx));
|
||||
let doc_elem_info = rx.recv();
|
||||
|
||||
let node = doc_elem_info.encode(registry, true);
|
||||
let node = doc_elem_info.encode(registry, true, self.script_chan.clone(), self.pipeline);
|
||||
|
||||
let msg = DocumentElementReply {
|
||||
from: self.name(),
|
||||
|
@ -263,7 +320,7 @@ impl Actor for WalkerActor {
|
|||
hasFirst: true,
|
||||
hasLast: true,
|
||||
nodes: children.into_iter().map(|child| {
|
||||
child.encode(registry, true)
|
||||
child.encode(registry, true, self.script_chan.clone(), self.pipeline)
|
||||
}).collect(),
|
||||
from: self.name(),
|
||||
};
|
||||
|
@ -453,7 +510,7 @@ impl Actor for InspectorActor {
|
|||
self.script_chan.send(GetRootNode(self.pipeline, tx));
|
||||
let root_info = rx.recv();
|
||||
|
||||
let node = root_info.encode(registry, false);
|
||||
let node = root_info.encode(registry, false, self.script_chan.clone(), self.pipeline);
|
||||
|
||||
let msg = GetWalkerReply {
|
||||
from: self.name(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue