| Index: webkit/glue/devtools/dom_agent_impl.cc
|
| ===================================================================
|
| --- webkit/glue/devtools/dom_agent_impl.cc (revision 13008)
|
| +++ webkit/glue/devtools/dom_agent_impl.cc (working copy)
|
| @@ -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 @@
|
| 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 @@
|
| 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(
|
|
|