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

Side by Side 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: Created 4 years, 1 month 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010, Google Inc. All rights reserved. 2 * Copyright (C) 2010, Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 2357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 2368
2369 int InspectorCSSAgent::getStyleIndexForNode( 2369 int InspectorCSSAgent::getStyleIndexForNode(
2370 Node* node, 2370 Node* node,
2371 const Vector<std::pair<String, CSSPropertyID>>& cssPropertyWhitelist, 2371 const Vector<std::pair<String, CSSPropertyID>>& cssPropertyWhitelist,
2372 ComputedStylesMap& styleToIndexMap, 2372 ComputedStylesMap& styleToIndexMap,
2373 protocol::Array<protocol::CSS::ComputedStyle>& computedStyles) { 2373 protocol::Array<protocol::CSS::ComputedStyle>& computedStyles) {
2374 CSSComputedStyleDeclaration* computedStyleInfo = 2374 CSSComputedStyleDeclaration* computedStyleInfo =
2375 CSSComputedStyleDeclaration::create(node, true); 2375 CSSComputedStyleDeclaration::create(node, true);
2376 2376
2377 Vector<String> style; 2377 Vector<String> style;
2378 // WTF::HashMap refuses to allow you to insert an empty vector :(
2379 style.append("dummy value");
Sami 2016/10/26 17:15:23 Would it be hard to fix this in WTF::HashMap? (I w
dgozman 2016/10/26 17:24:39 There should be a possibility with some magic bool
alex clarke (OOO till 29th) 2016/10/26 21:18:49 Possibly, I'm not sure how though. Honestly WTF::
2378 for (const auto& pair : cssPropertyWhitelist) { 2380 for (const auto& pair : cssPropertyWhitelist) {
2379 style.append(computedStyleInfo->getPropertyValue(pair.second)); 2381 String value = computedStyleInfo->getPropertyValue(pair.second);
2382 if (value.isEmpty())
2383 continue;
dgozman 2016/10/26 17:24:39 If you skip values in resulting array, how does cl
alex clarke (OOO till 29th) 2016/10/26 21:18:49 We send the key as well as the value, see: styleP
2384 style.append(value);
2380 } 2385 }
2381 2386
2382 ComputedStylesMap::iterator it = styleToIndexMap.find(style); 2387 ComputedStylesMap::iterator it = styleToIndexMap.find(style);
2383 if (it != styleToIndexMap.end()) 2388 if (it != styleToIndexMap.end())
2384 return it->value; 2389 return it->value;
2385 2390
2386 // It's a distinct style, so append to |computedStyles|. 2391 // It's a distinct style, so append to |computedStyles|.
2387 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>> 2392 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>>
2388 styleProperties = 2393 styleProperties =
2389 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); 2394 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create();
2390 for (size_t i = 0; i < style.size(); i++) { 2395 // Skip the dummy value...
2396 for (size_t i = 1; i < style.size(); i++) {
2391 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create() 2397 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create()
2392 .setName(cssPropertyWhitelist[i].first) 2398 .setName(cssPropertyWhitelist[i - 1].first)
2393 .setValue(style[i]) 2399 .setValue(style[i])
2394 .build()); 2400 .build());
2395 } 2401 }
2396 computedStyles.addItem(protocol::CSS::ComputedStyle::create() 2402 computedStyles.addItem(protocol::CSS::ComputedStyle::create()
2397 .setProperties(std::move(styleProperties)) 2403 .setProperties(std::move(styleProperties))
2398 .build()); 2404 .build());
2399 2405
2400 size_t index = styleToIndexMap.size(); 2406 size_t index = styleToIndexMap.size();
2401 styleToIndexMap.add(std::move(style), index); 2407 styleToIndexMap.add(std::move(style), index);
2402 return index; 2408 return index;
(...skipping 24 matching lines...) Expand all
2427 contentDocument->updateStyleAndLayoutTree(); 2433 contentDocument->updateStyleAndLayoutTree();
2428 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes, 2434 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes,
2429 cssPropertyWhitelist, styleToIndexMap, 2435 cssPropertyWhitelist, styleToIndexMap,
2430 computedStyles); 2436 computedStyles);
2431 } 2437 }
2432 2438
2433 LayoutObject* layoutObject = node->layoutObject(); 2439 LayoutObject* layoutObject = node->layoutObject();
2434 if (!layoutObject) 2440 if (!layoutObject)
2435 continue; 2441 continue;
2436 2442
2437 int backendNodeId = DOMNodeIds::idForNode(node); 2443 int nodeId = m_domAgent->boundNodeId(node);
dgozman 2016/10/26 17:24:39 This requires the node to be already pushed to the
alex clarke (OOO till 29th) 2016/10/26 21:18:49 What I want to do is join the results of DOM.getDo
2444 if (!nodeId)
2445 continue;
2438 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode = 2446 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode =
2439 protocol::CSS::LayoutTreeNode::create() 2447 protocol::CSS::LayoutTreeNode::create()
2440 .setBackendNodeId(backendNodeId) 2448 .setNodeId(nodeId)
2441 .setStyleIndex(getStyleIndexForNode( 2449 .setStyleIndex(getStyleIndexForNode(
2442 node, cssPropertyWhitelist, styleToIndexMap, computedStyles)) 2450 node, cssPropertyWhitelist, styleToIndexMap, computedStyles))
2443 .setBoundingBox(buildRectForFloatRect( 2451 .setBoundingBox(buildRectForFloatRect(
2444 node->isElementNode() 2452 node->isElementNode()
2445 ? FloatRect(toElement(node)->boundsInViewport()) 2453 ? FloatRect(toElement(node)->boundsInViewport())
2446 : layoutObject->absoluteBoundingBoxRect())) 2454 : layoutObject->absoluteBoundingBoxRect()))
2447 .build(); 2455 .build();
2448 2456
2449 if (layoutObject->isText()) { 2457 if (layoutObject->isText()) {
2450 LayoutText* layoutText = toLayoutText(layoutObject); 2458 LayoutText* layoutText = toLayoutText(layoutObject);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
2484 visitor->trace(m_idToInspectorStyleSheetForInlineStyle); 2492 visitor->trace(m_idToInspectorStyleSheetForInlineStyle);
2485 visitor->trace(m_cssStyleSheetToInspectorStyleSheet); 2493 visitor->trace(m_cssStyleSheetToInspectorStyleSheet);
2486 visitor->trace(m_documentToCSSStyleSheets); 2494 visitor->trace(m_documentToCSSStyleSheets);
2487 visitor->trace(m_invalidatedDocuments); 2495 visitor->trace(m_invalidatedDocuments);
2488 visitor->trace(m_nodeToInspectorStyleSheet); 2496 visitor->trace(m_nodeToInspectorStyleSheet);
2489 visitor->trace(m_inspectorUserAgentStyleSheet); 2497 visitor->trace(m_inspectorUserAgentStyleSheet);
2490 InspectorBaseAgent::trace(visitor); 2498 InspectorBaseAgent::trace(visitor);
2491 } 2499 }
2492 2500
2493 } // namespace blink 2501 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698