Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 347 StyleSheetAction(const String& name) : InspectorHistory::Action(name) {} | 347 StyleSheetAction(const String& name) : InspectorHistory::Action(name) {} |
| 348 | 348 |
| 349 virtual std::unique_ptr<protocol::CSS::CSSStyle> takeSerializedStyle() { | 349 virtual std::unique_ptr<protocol::CSS::CSSStyle> takeSerializedStyle() { |
| 350 return nullptr; | 350 return nullptr; |
| 351 } | 351 } |
| 352 }; | 352 }; |
| 353 | 353 |
| 354 struct InspectorCSSAgent::VectorStringHashTraits | 354 struct InspectorCSSAgent::VectorStringHashTraits |
| 355 : public WTF::GenericHashTraits<Vector<String>> { | 355 : public WTF::GenericHashTraits<Vector<String>> { |
| 356 static unsigned hash(const Vector<String>& vec) { | 356 static unsigned hash(const Vector<String>& vec) { |
| 357 unsigned h = DefaultHash<String>::Hash::hash(vec[0]); | 357 unsigned h = DefaultHash<size_t>::Hash::hash(vec.size()); |
| 358 for (size_t i = 1; i < vec.size(); i++) { | 358 for (size_t i = 0; i < vec.size(); i++) { |
| 359 h = WTF::hashInts(h, DefaultHash<String>::Hash::hash(vec[i])); | 359 h = WTF::hashInts(h, DefaultHash<String>::Hash::hash(vec[i])); |
| 360 } | 360 } |
| 361 return h; | 361 return h; |
| 362 } | 362 } |
| 363 | 363 |
| 364 static bool equal(const Vector<String>& a, const Vector<String>& b) { | 364 static bool equal(const Vector<String>& a, const Vector<String>& b) { |
| 365 if (a.size() != b.size()) | 365 if (a.size() != b.size()) |
| 366 return false; | 366 return false; |
| 367 for (size_t i = 0; i < a.size(); i++) { | 367 for (size_t i = 0; i < a.size(); i++) { |
| 368 if (a[i] != b[i]) | 368 if (a[i] != b[i]) |
| (...skipping 1999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2368 int InspectorCSSAgent::getStyleIndexForNode( | 2368 int InspectorCSSAgent::getStyleIndexForNode( |
| 2369 Node* node, | 2369 Node* node, |
| 2370 const Vector<std::pair<String, CSSPropertyID>>& cssPropertyWhitelist, | 2370 const Vector<std::pair<String, CSSPropertyID>>& cssPropertyWhitelist, |
| 2371 ComputedStylesMap& styleToIndexMap, | 2371 ComputedStylesMap& styleToIndexMap, |
| 2372 protocol::Array<protocol::CSS::ComputedStyle>& computedStyles) { | 2372 protocol::Array<protocol::CSS::ComputedStyle>& computedStyles) { |
| 2373 CSSComputedStyleDeclaration* computedStyleInfo = | 2373 CSSComputedStyleDeclaration* computedStyleInfo = |
| 2374 CSSComputedStyleDeclaration::create(node, true); | 2374 CSSComputedStyleDeclaration::create(node, true); |
| 2375 | 2375 |
| 2376 Vector<String> style; | 2376 Vector<String> style; |
| 2377 for (const auto& pair : cssPropertyWhitelist) { | 2377 for (const auto& pair : cssPropertyWhitelist) { |
| 2378 style.append(computedStyleInfo->getPropertyValue(pair.second)); | 2378 String value = computedStyleInfo->getPropertyValue(pair.second); |
| 2379 if (value.isEmpty()) | |
| 2380 continue; | |
| 2381 style.append(value); | |
| 2379 } | 2382 } |
| 2380 | 2383 |
| 2384 // -1 means an empty style. | |
| 2385 if (style.isEmpty()) | |
| 2386 return -1; | |
| 2387 | |
| 2381 ComputedStylesMap::iterator it = styleToIndexMap.find(style); | 2388 ComputedStylesMap::iterator it = styleToIndexMap.find(style); |
| 2382 if (it != styleToIndexMap.end()) | 2389 if (it != styleToIndexMap.end()) |
| 2383 return it->value; | 2390 return it->value; |
| 2384 | 2391 |
| 2385 // It's a distinct style, so append to |computedStyles|. | 2392 // It's a distinct style, so append to |computedStyles|. |
| 2386 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>> | 2393 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>> |
| 2387 styleProperties = | 2394 styleProperties = |
| 2388 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); | 2395 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); |
| 2396 | |
| 2389 for (size_t i = 0; i < style.size(); i++) { | 2397 for (size_t i = 0; i < style.size(); i++) { |
| 2390 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create() | 2398 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create() |
| 2391 .setName(cssPropertyWhitelist[i].first) | 2399 .setName(cssPropertyWhitelist[i].first) |
|
dgozman
2016/10/27 19:16:05
Aren't these two out of sync, since we skip items
alex clarke (OOO till 29th)
2016/10/27 20:51:19
Uh wow yes! Fixed now.
| |
| 2392 .setValue(style[i]) | 2400 .setValue(style[i]) |
| 2393 .build()); | 2401 .build()); |
| 2394 } | 2402 } |
| 2395 computedStyles.addItem(protocol::CSS::ComputedStyle::create() | 2403 computedStyles.addItem(protocol::CSS::ComputedStyle::create() |
| 2396 .setProperties(std::move(styleProperties)) | 2404 .setProperties(std::move(styleProperties)) |
| 2397 .build()); | 2405 .build()); |
| 2398 | 2406 |
| 2399 size_t index = styleToIndexMap.size(); | 2407 size_t index = styleToIndexMap.size(); |
| 2400 styleToIndexMap.add(std::move(style), index); | 2408 styleToIndexMap.add(std::move(style), index); |
| 2401 return index; | 2409 return index; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 2426 contentDocument->updateStyleAndLayoutTree(); | 2434 contentDocument->updateStyleAndLayoutTree(); |
| 2427 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes, | 2435 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes, |
| 2428 cssPropertyWhitelist, styleToIndexMap, | 2436 cssPropertyWhitelist, styleToIndexMap, |
| 2429 computedStyles); | 2437 computedStyles); |
| 2430 } | 2438 } |
| 2431 | 2439 |
| 2432 LayoutObject* layoutObject = node->layoutObject(); | 2440 LayoutObject* layoutObject = node->layoutObject(); |
| 2433 if (!layoutObject) | 2441 if (!layoutObject) |
| 2434 continue; | 2442 continue; |
| 2435 | 2443 |
| 2436 int backendNodeId = DOMNodeIds::idForNode(node); | 2444 int nodeId = m_domAgent->boundNodeId(node); |
| 2445 if (!nodeId) | |
| 2446 continue; | |
| 2447 | |
| 2437 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode = | 2448 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode = |
| 2438 protocol::CSS::LayoutTreeNode::create() | 2449 protocol::CSS::LayoutTreeNode::create() |
| 2439 .setBackendNodeId(backendNodeId) | 2450 .setNodeId(nodeId) |
| 2440 .setStyleIndex(getStyleIndexForNode( | |
| 2441 node, cssPropertyWhitelist, styleToIndexMap, computedStyles)) | |
| 2442 .setBoundingBox(buildRectForFloatRect( | 2451 .setBoundingBox(buildRectForFloatRect( |
| 2443 node->isElementNode() | 2452 node->isElementNode() |
| 2444 ? FloatRect(toElement(node)->boundsInViewport()) | 2453 ? FloatRect(toElement(node)->boundsInViewport()) |
| 2445 : layoutObject->absoluteBoundingBoxRect())) | 2454 : layoutObject->absoluteBoundingBoxRect())) |
| 2446 .build(); | 2455 .build(); |
| 2456 int styleIndex = getStyleIndexForNode(node, cssPropertyWhitelist, | |
| 2457 styleToIndexMap, computedStyles); | |
| 2458 if (styleIndex != -1) | |
| 2459 layoutTreeNode->setStyleIndex(styleIndex); | |
| 2447 | 2460 |
| 2448 if (layoutObject->isText()) { | 2461 if (layoutObject->isText()) { |
| 2449 LayoutText* layoutText = toLayoutText(layoutObject); | 2462 LayoutText* layoutText = toLayoutText(layoutObject); |
| 2450 layoutTreeNode->setLayoutText(layoutText->text()); | 2463 layoutTreeNode->setLayoutText(layoutText->text()); |
| 2451 if (layoutText->hasTextBoxes()) { | 2464 if (layoutText->hasTextBoxes()) { |
| 2452 std::unique_ptr<protocol::Array<protocol::CSS::InlineTextBox>> | 2465 std::unique_ptr<protocol::Array<protocol::CSS::InlineTextBox>> |
| 2453 inlineTextNodes = | 2466 inlineTextNodes = |
| 2454 protocol::Array<protocol::CSS::InlineTextBox>::create(); | 2467 protocol::Array<protocol::CSS::InlineTextBox>::create(); |
| 2455 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox; | 2468 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox; |
| 2456 textBox = textBox->nextTextBox()) { | 2469 textBox = textBox->nextTextBox()) { |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2483 visitor->trace(m_idToInspectorStyleSheetForInlineStyle); | 2496 visitor->trace(m_idToInspectorStyleSheetForInlineStyle); |
| 2484 visitor->trace(m_cssStyleSheetToInspectorStyleSheet); | 2497 visitor->trace(m_cssStyleSheetToInspectorStyleSheet); |
| 2485 visitor->trace(m_documentToCSSStyleSheets); | 2498 visitor->trace(m_documentToCSSStyleSheets); |
| 2486 visitor->trace(m_invalidatedDocuments); | 2499 visitor->trace(m_invalidatedDocuments); |
| 2487 visitor->trace(m_nodeToInspectorStyleSheet); | 2500 visitor->trace(m_nodeToInspectorStyleSheet); |
| 2488 visitor->trace(m_inspectorUserAgentStyleSheet); | 2501 visitor->trace(m_inspectorUserAgentStyleSheet); |
| 2489 InspectorBaseAgent::trace(visitor); | 2502 InspectorBaseAgent::trace(visitor); |
| 2490 } | 2503 } |
| 2491 | 2504 |
| 2492 } // namespace blink | 2505 } // namespace blink |
| OLD | NEW |