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 1998 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2367 | 2367 |
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 bool allPropertiesEmpty = true; |
2377 for (const auto& pair : cssPropertyWhitelist) { | 2378 for (const auto& pair : cssPropertyWhitelist) { |
2378 style.append(computedStyleInfo->getPropertyValue(pair.second)); | 2379 String value = computedStyleInfo->getPropertyValue(pair.second); |
| 2380 if (!value.isEmpty()) |
| 2381 allPropertiesEmpty = false; |
| 2382 style.append(value); |
2379 } | 2383 } |
2380 | 2384 |
| 2385 // -1 means an empty style. |
| 2386 if (allPropertiesEmpty) |
| 2387 return -1; |
| 2388 |
2381 ComputedStylesMap::iterator it = styleToIndexMap.find(style); | 2389 ComputedStylesMap::iterator it = styleToIndexMap.find(style); |
2382 if (it != styleToIndexMap.end()) | 2390 if (it != styleToIndexMap.end()) |
2383 return it->value; | 2391 return it->value; |
2384 | 2392 |
2385 // It's a distinct style, so append to |computedStyles|. | 2393 // It's a distinct style, so append to |computedStyles|. |
2386 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>> | 2394 std::unique_ptr<protocol::Array<protocol::CSS::CSSComputedStyleProperty>> |
2387 styleProperties = | 2395 styleProperties = |
2388 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); | 2396 protocol::Array<protocol::CSS::CSSComputedStyleProperty>::create(); |
| 2397 |
2389 for (size_t i = 0; i < style.size(); i++) { | 2398 for (size_t i = 0; i < style.size(); i++) { |
| 2399 if (style[i].isEmpty()) |
| 2400 continue; |
2390 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create() | 2401 styleProperties->addItem(protocol::CSS::CSSComputedStyleProperty::create() |
2391 .setName(cssPropertyWhitelist[i].first) | 2402 .setName(cssPropertyWhitelist[i].first) |
2392 .setValue(style[i]) | 2403 .setValue(style[i]) |
2393 .build()); | 2404 .build()); |
2394 } | 2405 } |
2395 computedStyles.addItem(protocol::CSS::ComputedStyle::create() | 2406 computedStyles.addItem(protocol::CSS::ComputedStyle::create() |
2396 .setProperties(std::move(styleProperties)) | 2407 .setProperties(std::move(styleProperties)) |
2397 .build()); | 2408 .build()); |
2398 | 2409 |
2399 size_t index = styleToIndexMap.size(); | 2410 size_t index = styleToIndexMap.size(); |
(...skipping 26 matching lines...) Expand all Loading... |
2426 contentDocument->updateStyleAndLayoutTree(); | 2437 contentDocument->updateStyleAndLayoutTree(); |
2427 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes, | 2438 visitLayoutTreeNodes(contentDocument->documentElement(), layoutTreeNodes, |
2428 cssPropertyWhitelist, styleToIndexMap, | 2439 cssPropertyWhitelist, styleToIndexMap, |
2429 computedStyles); | 2440 computedStyles); |
2430 } | 2441 } |
2431 | 2442 |
2432 LayoutObject* layoutObject = node->layoutObject(); | 2443 LayoutObject* layoutObject = node->layoutObject(); |
2433 if (!layoutObject) | 2444 if (!layoutObject) |
2434 continue; | 2445 continue; |
2435 | 2446 |
2436 int backendNodeId = DOMNodeIds::idForNode(node); | 2447 int nodeId = m_domAgent->boundNodeId(node); |
| 2448 if (!nodeId) |
| 2449 continue; |
| 2450 |
2437 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode = | 2451 std::unique_ptr<protocol::CSS::LayoutTreeNode> layoutTreeNode = |
2438 protocol::CSS::LayoutTreeNode::create() | 2452 protocol::CSS::LayoutTreeNode::create() |
2439 .setBackendNodeId(backendNodeId) | 2453 .setNodeId(nodeId) |
2440 .setStyleIndex(getStyleIndexForNode( | |
2441 node, cssPropertyWhitelist, styleToIndexMap, computedStyles)) | |
2442 .setBoundingBox(buildRectForFloatRect( | 2454 .setBoundingBox(buildRectForFloatRect( |
2443 node->isElementNode() | 2455 node->isElementNode() |
2444 ? FloatRect(toElement(node)->boundsInViewport()) | 2456 ? FloatRect(toElement(node)->boundsInViewport()) |
2445 : layoutObject->absoluteBoundingBoxRect())) | 2457 : layoutObject->absoluteBoundingBoxRect())) |
2446 .build(); | 2458 .build(); |
| 2459 int styleIndex = getStyleIndexForNode(node, cssPropertyWhitelist, |
| 2460 styleToIndexMap, computedStyles); |
| 2461 if (styleIndex != -1) |
| 2462 layoutTreeNode->setStyleIndex(styleIndex); |
2447 | 2463 |
2448 if (layoutObject->isText()) { | 2464 if (layoutObject->isText()) { |
2449 LayoutText* layoutText = toLayoutText(layoutObject); | 2465 LayoutText* layoutText = toLayoutText(layoutObject); |
2450 layoutTreeNode->setLayoutText(layoutText->text()); | 2466 layoutTreeNode->setLayoutText(layoutText->text()); |
2451 if (layoutText->hasTextBoxes()) { | 2467 if (layoutText->hasTextBoxes()) { |
2452 std::unique_ptr<protocol::Array<protocol::CSS::InlineTextBox>> | 2468 std::unique_ptr<protocol::Array<protocol::CSS::InlineTextBox>> |
2453 inlineTextNodes = | 2469 inlineTextNodes = |
2454 protocol::Array<protocol::CSS::InlineTextBox>::create(); | 2470 protocol::Array<protocol::CSS::InlineTextBox>::create(); |
2455 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox; | 2471 for (const InlineTextBox* textBox = layoutText->firstTextBox(); textBox; |
2456 textBox = textBox->nextTextBox()) { | 2472 textBox = textBox->nextTextBox()) { |
(...skipping 26 matching lines...) Expand all Loading... |
2483 visitor->trace(m_idToInspectorStyleSheetForInlineStyle); | 2499 visitor->trace(m_idToInspectorStyleSheetForInlineStyle); |
2484 visitor->trace(m_cssStyleSheetToInspectorStyleSheet); | 2500 visitor->trace(m_cssStyleSheetToInspectorStyleSheet); |
2485 visitor->trace(m_documentToCSSStyleSheets); | 2501 visitor->trace(m_documentToCSSStyleSheets); |
2486 visitor->trace(m_invalidatedDocuments); | 2502 visitor->trace(m_invalidatedDocuments); |
2487 visitor->trace(m_nodeToInspectorStyleSheet); | 2503 visitor->trace(m_nodeToInspectorStyleSheet); |
2488 visitor->trace(m_inspectorUserAgentStyleSheet); | 2504 visitor->trace(m_inspectorUserAgentStyleSheet); |
2489 InspectorBaseAgent::trace(visitor); | 2505 InspectorBaseAgent::trace(visitor); |
2490 } | 2506 } |
2491 | 2507 |
2492 } // namespace blink | 2508 } // namespace blink |
OLD | NEW |