Class: WebkitRemote::Client::DomNode
- Inherits:
-
Object
- Object
- WebkitRemote::Client::DomNode
- Defined in:
- lib/webkit_remote/client/dom.rb
Overview
Cached information about a DOM node.
Constant Summary collapse
- NODE_TYPES =
Maps numeric DOM types to their symbolic representation.
{ 1 => :element, 2 => :attribute, 3 => :text, 4 => :cdata_section, 5 => :entity_reference, 6 => :entity, 7 => :processing_instruction, 8 => :comment, 9 => :document, 10 => :document_type, 11 => :document_fragment, 12 => :notation }.freeze
Instance Attribute Summary collapse
-
#attr_name ⇒ String
readonly
Name, for attribute nodes.
-
#attr_value ⇒ String
readonly
Value, for attribute nodes.
-
#children ⇒ Array<WebkitRemote::Client::DomNode>
readonly
Children nodes.
- #document_url ⇒ WebkitRemote::Client::DomNode, String readonly
-
#internal_subset ⇒ String
readonly
Internal subset, for doctype nodes.
-
#local_name ⇒ String
readonly
The node’s local name.
-
#name ⇒ String
readonly
The node’s name.
-
#node_type ⇒ Symbol
readonly
The DOM node type (such as :element, :text, :attribute).
-
#public_id ⇒ String
readonly
Public ID, for doctype nodes.
-
#system_id ⇒ String
readonly
System ID, for doctype nodes.
-
#value ⇒ String
readonly
The node’s value.
-
#xml_version ⇒ String
readonly
The XML version, for document nodes.
Class Method Summary collapse
-
.initializer(name) ⇒ Object
Registers a module initializer.
Instance Method Summary collapse
-
#attributes ⇒ Hash<String, Object>
The node’s attributes.
-
#attributes! ⇒ Hash<String, Object>
Retrieves this node’s attributes, bypassing its cache.
-
#highlight!(options) ⇒ Object
Highlights this DOM node.
-
#initialize(remote_id, client) ⇒ DomNode
constructor
A new instance of DomNode.
-
#js_object ⇒ WebkitRemote::Client::JsObject
This node’s JavaScript object.
-
#js_object!(group = nil) ⇒ WebkitRemote::Client::JsObject
Retrieves this node’s JavaScript object, bypassing the node’s cache.
-
#outer_html ⇒ String
HTML markup for the node and all its contents.
-
#outer_html! ⇒ String
HTML markup for the node and all its contents.
-
#query_selector(css_selector) ⇒ WebkitRemote::Client::DomNode
Retrieves the first descendant of this node that matches a CSS selector.
-
#query_selector_all(css_selector) ⇒ Array<WebkitRemote::Client::DomNode>
Retrieves all this node’s descendants that match a CSS selector.
-
#remove ⇒ WebkitRemote::Client::DomNode
Removes this node from the document.
-
#remove_attribute(attr_name) ⇒ WebkitRemote::Client::DomNode
Deletes one of the node (element)‘s attributes.
-
#update_all(raw_node) ⇒ WebkitRemote::Client::DomNode
Updates node state to reflect new data from the Webkit debugging server.
Constructor Details
#initialize(remote_id, client) ⇒ DomNode
Returns a new instance of DomNode.
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/webkit_remote/client/dom.rb', line 208 def initialize(remote_id, client) @remote_id = remote_id @client = client @attributes = nil @attr_name = nil @attr_value = nil @children = nil @content_document = nil @document_url = nil @internal_subset = nil @js_object = nil @local_name = nil @name = nil @node_type = nil @outer_html = nil @public_id = nil @system_id = nil @value = nil @xml_version = nil initialize_modules end |
Instance Attribute Details
#attr_name ⇒ String (readonly)
Returns name, for attribute nodes.
78 79 80 |
# File 'lib/webkit_remote/client/dom.rb', line 78 def attr_name @attr_name end |
#attr_value ⇒ String (readonly)
Returns value, for attribute nodes.
80 81 82 |
# File 'lib/webkit_remote/client/dom.rb', line 80 def attr_value @attr_value end |
#children ⇒ Array<WebkitRemote::Client::DomNode> (readonly)
Returns children nodes.
66 67 68 |
# File 'lib/webkit_remote/client/dom.rb', line 66 def children @children end |
#document_url ⇒ WebkitRemote::Client::DomNode, String (readonly)
92 93 94 |
# File 'lib/webkit_remote/client/dom.rb', line 92 def document_url @document_url end |
#internal_subset ⇒ String (readonly)
Returns internal subset, for doctype nodes.
83 84 85 |
# File 'lib/webkit_remote/client/dom.rb', line 83 def internal_subset @internal_subset end |
#local_name ⇒ String (readonly)
Returns the node’s local name.
69 70 71 |
# File 'lib/webkit_remote/client/dom.rb', line 69 def local_name @local_name end |
#name ⇒ String (readonly)
Returns the node’s name.
71 72 73 |
# File 'lib/webkit_remote/client/dom.rb', line 71 def name @name end |
#node_type ⇒ Symbol (readonly)
Returns the DOM node type (such as :element, :text, :attribute).
75 76 77 |
# File 'lib/webkit_remote/client/dom.rb', line 75 def node_type @node_type end |
#public_id ⇒ String (readonly)
Returns public ID, for doctype nodes.
85 86 87 |
# File 'lib/webkit_remote/client/dom.rb', line 85 def public_id @public_id end |
#system_id ⇒ String (readonly)
Returns system ID, for doctype nodes.
87 88 89 |
# File 'lib/webkit_remote/client/dom.rb', line 87 def system_id @system_id end |
#value ⇒ String (readonly)
Returns the node’s value.
73 74 75 |
# File 'lib/webkit_remote/client/dom.rb', line 73 def value @value end |
#xml_version ⇒ String (readonly)
Returns the XML version, for document nodes.
94 95 96 |
# File 'lib/webkit_remote/client/dom.rb', line 94 def xml_version @xml_version end |
Class Method Details
.initializer(name) ⇒ Object
Registers a module initializer.
237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/webkit_remote/client/dom.rb', line 237 def self.initializer(name) before_name = :"initialize_modules_before_#{name}" alias_method before_name, :initialize_modules private before_name remove_method :initialize_modules eval <<END_METHOD def initialize_modules #{name} #{before_name.to_s} end END_METHOD private :initialize_modules end |
Instance Method Details
#attributes ⇒ Hash<String, Object>
Returns the node’s attributes.
97 98 99 |
# File 'lib/webkit_remote/client/dom.rb', line 97 def attributes @attributes ||= attributes! end |
#attributes! ⇒ Hash<String, Object>
Retrieves this node’s attributes, bypassing its cache.
104 105 106 107 |
# File 'lib/webkit_remote/client/dom.rb', line 104 def attributes! result = @client.rpc.call 'DOM.getAttributes', nodeId: @remote_id @attributes = Hash[result['attributes'].each_slice(2).to_a] end |
#highlight!(options) ⇒ Object
Highlights this DOM node.
196 197 198 199 200 201 202 203 204 205 |
# File 'lib/webkit_remote/client/dom.rb', line 196 def highlight!() config = {} config[:marginColor] = [:margin] if [:margin] config[:borderColor] = [:border] if [:border] config[:paddingColor] = [:padding] if [:padding] config[:contentColor] = [:content] if [:content] config[:showInfo] = true if [:tooltip] @client.rpc.call 'DOM.highlightNode', nodeId: @remote_id, highlightConfig: config end |
#js_object ⇒ WebkitRemote::Client::JsObject
Returns this node’s JavaScript object.
110 111 112 |
# File 'lib/webkit_remote/client/dom.rb', line 110 def js_object @js_object ||= js_object! end |
#js_object!(group = nil) ⇒ WebkitRemote::Client::JsObject
Retrieves this node’s JavaScript object, bypassing the node’s cache.
120 121 122 123 124 125 |
# File 'lib/webkit_remote/client/dom.rb', line 120 def js_object!(group = nil) group ||= @client.object_group_auto_name result = @client.rpc.call 'DOM.resolveNode', nodeId: @remote_id, groupName: group WebkitRemote::Client::JsObject.for result['object'], @client, group end |
#outer_html ⇒ String
Returns HTML markup for the node and all its contents.
128 129 130 |
# File 'lib/webkit_remote/client/dom.rb', line 128 def outer_html @outer_html ||= outer_html! end |
#outer_html! ⇒ String
Returns HTML markup for the node and all its contents.
133 134 135 136 |
# File 'lib/webkit_remote/client/dom.rb', line 133 def outer_html! result = @client.rpc.call 'DOM.getOuterHTML', nodeId: @remote_id @outer_html = result['outerHTML'] end |
#query_selector(css_selector) ⇒ WebkitRemote::Client::DomNode
Retrieves the first descendant of this node that matches a CSS selector.
145 146 147 148 149 150 151 |
# File 'lib/webkit_remote/client/dom.rb', line 145 def query_selector(css_selector) result = @client.rpc.call 'DOM.querySelector', nodeId: @remote_id, selector: css_selector node_id = result['nodeId'] return nil if node_id == 0 @client.dom_node result['nodeId'] end |
#query_selector_all(css_selector) ⇒ Array<WebkitRemote::Client::DomNode>
Retrieves all this node’s descendants that match a CSS selector.
159 160 161 162 163 |
# File 'lib/webkit_remote/client/dom.rb', line 159 def query_selector_all(css_selector) result = @client.rpc.call 'DOM.querySelectorAll', nodeId: @remote_id, selector: css_selector result['nodeIds'].map { |remote_id| @client.dom_node remote_id } end |
#remove ⇒ WebkitRemote::Client::DomNode
Removes this node from the document.
178 179 180 181 |
# File 'lib/webkit_remote/client/dom.rb', line 178 def remove @client.rpc.call 'DOM.removeNode', nodeId: @remote_id self end |
#remove_attribute(attr_name) ⇒ WebkitRemote::Client::DomNode
Deletes one of the node (element)‘s attributes.
169 170 171 172 173 |
# File 'lib/webkit_remote/client/dom.rb', line 169 def remove_attribute(attr_name) @attributes.delete attr_name if @attributes @client.rpc.call 'DOM.removeAttribute', nodeId: @remote_id, name: attr_name self end |
#update_all(raw_node) ⇒ WebkitRemote::Client::DomNode
Updates node state to reflect new data from the Webkit debugging server.
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 |
# File 'lib/webkit_remote/client/dom.rb', line 259 def update_all(raw_node) if raw_node['attributes'] @attributes = Hash[raw_node['attributes'].each_slice(2).to_a] end if raw_node['children'] @children = raw_node['children'].map do |child_node| @client.dom_update_node child_node end end if raw_node['contentDocument'] @content_document = @client.dom_update_node raw_node['contentDocument'] end @document_url = raw_node['documentURL'] if raw_node['documentURL'] @internal_subset = raw_node['internalSubset'] if raw_node['internalSubset'] @node_local_name = raw_node['localName'] if raw_node['localName'] @attr_name = raw_node['name'] if raw_node['name'] @name = raw_node['nodeName'] if raw_node['nodeName'] if raw_node['nodeType'] @node_type = NODE_TYPES[raw_node['nodeType'].to_i] || raw_node['nodeType'] end @value = raw_node['nodeValue'] if raw_node['nodeValue'] @public_id = raw_node['publicId'] if raw_node['publicId'] @system_id = raw_node['systemId'] if raw_node['systemId'] @attr_value = raw_node['value'] if raw_node['value'] @xml_version = raw_node['xmlVersion'] if raw_node['xmlVersion'] self end |