summaryrefslogtreecommitdiffstats
path: root/webkit/glue/devtools/dom_agent_impl.cc
diff options
context:
space:
mode:
authorserya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 06:37:48 +0000
committerserya@google.com <serya@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-10 06:37:48 +0000
commit327587e7c2b02a106e6282649f078f29062a610a (patch)
treea27ac84c20aa02255639b21e8ea2b22dd34074d0 /webkit/glue/devtools/dom_agent_impl.cc
parent8dc91f79b9f577552f28c01560113df90f53581f (diff)
downloadchromium_src-327587e7c2b02a106e6282649f078f29062a610a.zip
chromium_src-327587e7c2b02a106e6282649f078f29062a610a.tar.gz
chromium_src-327587e7c2b02a106e6282649f078f29062a610a.tar.bz2
Serializing styles in JSON. Previous implementation (serializing as cssText) lost information about prperty shorthands.
Now StyleSidebarPane correctly groups properties. Review URL: http://codereview.chromium.org/65004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'webkit/glue/devtools/dom_agent_impl.cc')
-rw-r--r--webkit/glue/devtools/dom_agent_impl.cc52
1 files changed, 38 insertions, 14 deletions
diff --git a/webkit/glue/devtools/dom_agent_impl.cc b/webkit/glue/devtools/dom_agent_impl.cc
index 04b11da..c63764e 100644
--- a/webkit/glue/devtools/dom_agent_impl.cc
+++ b/webkit/glue/devtools/dom_agent_impl.cc
@@ -6,6 +6,8 @@
#include "AtomicString.h"
#include "CSSComputedStyleDeclaration.h"
+#include "CSSParser.h"
+#include "CSSPropertyNames.h"
#include "CSSRule.h"
#include "CSSRuleList.h"
#include "CSSStyleRule.h"
@@ -447,9 +449,6 @@ void DomAgentImpl::PerformSearch(int call_id, const String& query) {
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.
-
DictionaryValue result;
Node* node = GetNodeForId(element_id);
@@ -460,14 +459,12 @@ void DomAgentImpl::GetNodeStyles(int call_id,
}
Element* element = static_cast<Element*>(node);
- String inline_style = element->style()->cssText();
- result.SetString(L"inlineStyle",
- webkit_glue::StringToStdString(inline_style));
+ result.Set(L"inlineStyle",
+ BuildValueForStyle(*element->style()));
DOMWindow* window = element->document()->defaultView();
- String computed_style = window->getComputedStyle(element, "")->cssText();
- result.SetString(L"computedStyle",
- webkit_glue::StringToStdString(computed_style));
+ result.Set(L"computedStyle",
+ BuildValueForStyle(*window->getComputedStyle(element, "")));
RefPtr<CSSRuleList> rule_list = window->getMatchedCSSRules(element, "",
author_only);
@@ -580,8 +577,9 @@ ListValue* DomAgentImpl::BuildValueForCSSRules(CSSRuleList& matched) {
webkit_glue::StringToStdString(rule->selectorText()));
CSSMutableStyleDeclaration* style = rule->style();
- description->SetString(L"cssText",
- webkit_glue::StringToStdString(style ? style->cssText() : ""));
+ if (style) {
+ description->Set(L"style", BuildValueForStyle(*style));
+ }
CSSStyleSheet* parent_style_sheet = rule->parentStyleSheet();
if (parent_style_sheet) {
@@ -608,15 +606,41 @@ DictionaryValue* DomAgentImpl::BuildValueForAttributeStyles(
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);
+ description->Set(name, BuildValueForStyle(*style));
}
}
return description.release();
}
+ListValue* DomAgentImpl::BuildValueForStyle(const CSSStyleDeclaration& style) {
+ OwnPtr<ListValue> prop_list(new ListValue);
+ for (int i = 0; i != style.length(); ++i) {
+ String name = style.item(i);
+ int id = cssPropertyID(name);
+
+ bool important = style.getPropertyPriority(id);
+ bool implicit = style.isPropertyImplicit(id);
+ int shorthand_id = style.getPropertyShorthand(id);
+ String shorthand =
+ getPropertyName(static_cast<CSSPropertyID>(shorthand_id));
+
+ OwnPtr<ListValue> prop(new ListValue);
+ prop->Append(Value::CreateStringValue(
+ webkit_glue::StringToStdWString(name)));
+ prop->Append(Value::CreateBooleanValue(important));
+ prop->Append(Value::CreateBooleanValue(implicit));
+ prop->Append(Value::CreateStringValue(
+ webkit_glue::StringToStdWString(shorthand)));
+ prop->Append(Value::CreateStringValue(
+ webkit_glue::StringToStdWString(style.getPropertyValue(id))));
+
+ prop_list->Append(prop.release());
+ }
+
+ return prop_list.release();
+}
+
Node* DomAgentImpl::InnerFirstChild(Node* node) {
if (node->isFrameOwnerElement()) {
HTMLFrameOwnerElement* frame_owner =