summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/dom_agent_impl.cc
diff options
context:
space:
mode:
authorpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-02 13:59:13 +0000
committerpfeldman@chromium.org <pfeldman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-02 13:59:13 +0000
commitcad26edcdccf0cc36afab1e8584ff165460373e0 (patch)
tree16bdfeccca051afc0212cbbb70f35aa49b9fc9c8 /webkit/glue/devtools/dom_agent_impl.cc
parent51996efd0e452dc7cea81616783958cb3fbf81e2 (diff)
downloadchromium_src-cad26edcdccf0cc36afab1e8584ff165460373e0.zip
chromium_src-cad26edcdccf0cc36afab1e8584ff165460373e0.tar.gz
chromium_src-cad26edcdccf0cc36afab1e8584ff165460373e0.tar.bz2
DevTools: Add support for r/o CSS inspection. Original review CL by serya : http://codereview.chromium.org/57007
Review URL: http://codereview.chromium.org/60047 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13009 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools/dom_agent_impl.cc')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.cc97
1 files changed, 96 insertions, 1 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc
index 81016462..0e83054 100644
--- a/webkit/glue/devtools/dom_agent_impl.cc
+++ b/webkit/glue/devtools/dom_agent_impl.cc
@@ -5,6 +5,12 @@
#include "config.h"
#include "AtomicString.h"
+#include "CSSComputedStyleDeclaration.h"
+#include "CSSRule.h"
+#include "CSSRuleList.h"
+#include "CSSStyleRule.h"
+#include "CSSStyleSheet.h"
+#include "DOMWindow.h"
#include "Document.h"
#include "Event.h"
#include "EventListener.h"
@@ -435,6 +441,95 @@ void DomAgentImpl::PerformSearch(int call_id, const String& query) {
delegate_->DidPerformSearch(call_id, list);
}
+void DomAgentImpl::GetNodeStyles(int call_id,
+ int element_id,
+ bool author_only) {
+ // TODO (serya): Currently styles are serialized as cssText.
+ // It could be not enough.
+ String computed_style;
+ String inline_style;
+ OwnPtr<DictionaryValue> style_attributes(new DictionaryValue());
+ OwnPtr<ListValue> matched_css_rules(new ListValue());
+
+ Node* node = GetNodeForId(element_id);
+ DCHECK(!node || node->nodeType() == Node::ELEMENT_NODE);
+ if (node && node->nodeType() == Node::ELEMENT_NODE) {
+ Element* element = static_cast<Element*>(node);
+ inline_style = element->style()->cssText();
+ DOMWindow* window = element->document()->defaultView();
+ computed_style = window->getComputedStyle(element, "")->cssText();
+ BuildValueForCSSRules(*window->getMatchedCSSRules(element, "",
+ author_only), *matched_css_rules);
+ BuildValueForAttributeStyles(*element->attributes(),
+ *style_attributes);
+ }
+
+ DictionaryValue styles;
+
+ styles.SetString(L"computedStyle",
+ webkit_glue::StringToStdString(computed_style));
+ styles.SetString(L"inlineStyle",
+ webkit_glue::StringToStdString(inline_style));
+ styles.Set(L"styleAttributes", style_attributes.release());
+ styles.Set(L"matchedCSSRules", matched_css_rules.release());
+
+ delegate_->DidGetNodeStyles(call_id, styles);
+}
+
+void DomAgentImpl::BuildValueForCSSRules(CSSRuleList& matched,
+ ListValue& descriptionList) {
+ for (unsigned i = 0; i < matched.length(); ++i) {
+ if (!matched.item(i)->isStyleRule()) {
+ continue;
+ }
+
+ CSSStyleRule* rule = static_cast<CSSStyleRule*>(matched.item(i));
+ String selector_text = rule->selectorText();
+ String css_text;
+
+ CSSMutableStyleDeclaration* style = rule->style();
+ if (style) {
+ css_text = style->cssText();
+ }
+
+ OwnPtr<DictionaryValue> description(new DictionaryValue());
+ description->SetString(L"selector",
+ webkit_glue::StringToStdString(selector_text));
+ description->SetString(L"cssText",
+ webkit_glue::StringToStdString(css_text));
+
+ CSSStyleSheet* parent_style_sheet = rule->parentStyleSheet();
+ if (parent_style_sheet) {
+ description->SetString(L"parentStyleSheetHref",
+ webkit_glue::StringToStdString(parent_style_sheet->href()));
+
+ Node* owner_node = parent_style_sheet->ownerNode();
+ if (owner_node) {
+ description->SetString(L"parentStyleSheetOwnerNodeName",
+ webkit_glue::StringToStdString(owner_node->nodeName()));
+ }
+ }
+
+ descriptionList.Append(description.release());
+ }
+}
+
+void DomAgentImpl::BuildValueForAttributeStyles(const NamedNodeMap& attributes,
+ DictionaryValue& description) {
+ for (size_t i = 0; i < attributes.length(); ++i) {
+ Attribute* attr = attributes.attributeItem(i);
+
+ if (CSSStyleDeclaration* style = attr->style()) {
+ std::wstring name =
+ webkit_glue::StringToStdWString(attr->name().toString());
+ std::string css_text =
+ webkit_glue::StringToStdString(style->cssText());
+
+ description.SetString(name, css_text);
+ }
+ }
+}
+
ListValue* DomAgentImpl::BuildValueForNode(Node* node, int depth) {
OwnPtr<ListValue> value(new ListValue());
int id = Bind(node);
@@ -485,7 +580,7 @@ ListValue* DomAgentImpl::BuildValueForElementAttributes(Element* element) {
return attributes_value.release();
}
unsigned num_attrs = attr_map->length();
- for (unsigned i = 0; i < num_attrs; i++) {
+ for (unsigned i = 0; i < num_attrs; ++i) {
// Add attribute pair
const Attribute *attribute = attr_map->attributeItem(i);
OwnPtr<Value> name(Value::CreateStringValue(