Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(518)

Unified Diff: third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp

Issue 2455613002: Fix index used to join results of DOM.getDocument and CSS.getLayoutTreeAndStyles (Closed)
Patch Set: Fix skew between property names and values when emepty ones are skipped. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
diff --git a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
index 1d366dd242374e8f133a1cd2c1aaf046061144fb..32a79edb4fb79cafe687e354afbf527c0322bfa0 100644
--- a/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
+++ b/third_party/WebKit/Source/core/inspector/InspectorCSSAgent.cpp
@@ -354,8 +354,8 @@ class InspectorCSSAgent::StyleSheetAction : public InspectorHistory::Action {
struct InspectorCSSAgent::VectorStringHashTraits
: public WTF::GenericHashTraits<Vector<String>> {
static unsigned hash(const Vector<String>& vec) {
- unsigned h = DefaultHash<String>::Hash::hash(vec[0]);
- for (size_t i = 1; i < vec.size(); i++) {
+ unsigned h = DefaultHash<size_t>::Hash::hash(vec.size());
+ for (size_t i = 0; i < vec.size(); i++) {
h = WTF::hashInts(h, DefaultHash<String>::Hash::hash(vec[i]));
}
return h;
@@ -2374,10 +2374,18 @@ int InspectorCSSAgent::getStyleIndexForNode(
CSSComputedStyleDeclaration::create(node, true);
Vector<String> style;
+ bool allPropertiesEmpty = true;
for (const auto& pair : cssPropertyWhitelist) {
- style.append(computedStyleInfo->getPropertyValue(pair.second));
+ String value = computedStyleInfo->getPropertyValue(pair.second);
+ if (!value.isEmpty())
+ allPropertiesEmpty = false;
+ style.append(value);
}
+ // -1 means an empty style.
+ if (allPropertiesEmpty)
+ return -1;
+
ComputedStylesMap::iterator it = styleToIndexMap.find(style);
if (it != styleToIndexMap.end())
return it->value;
@@ -2386,7 +2394,10 @@ int InspectorCSSAgent::getStyleIndexForNode(
std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>
styleProperties =
protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create();
+
for (size_t i = 0; i < style.size(); i++) {
+ if (style[i].isEmpty())
+ continue;
styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create()
.setName(cssPropertyWhitelist[i].first)
.setValue(style[i])
@@ -2433,17 +2444,22 @@ void InspectorCSSAgent::visitLayoutTreeNodes(
if (!layoutObject)
continue;
- int backendNodeId = DOMNodeIds::idForNode(node);
+ int nodeId = m_domAgent->boundNodeId(node);
+ if (!nodeId)
+ continue;
+
std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode =
protocol::CSS::LayoutTreeNode::create()
- .setBackendNodeId(backendNodeId)
- .setStyleIndex(getStyleIndexForNode(
- node, cssPropertyWhitelist, styleToIndexMap, computedStyles))
+ .setNodeId(nodeId)
.setBoundingBox(buildRectForFloatRect(
node->isElementNode()
? FloatRect(toElement(node)->boundsInViewport())
: layoutObject->absoluteBoundingBoxRect()))
.build();
+ int styleIndex = getStyleIndexForNode(node, cssPropertyWhitelist,
+ styleToIndexMap, computedStyles);
+ if (styleIndex != -1)
+ layoutTreeNode->setStyleIndex(styleIndex);
if (layoutObject->isText()) {
LayoutText* layoutText = toLayoutText(layoutObject);

Powered by Google App Engine
This is Rietveld 408576698