Changeset 252682 in webkit


Ignore:
Timestamp:
Nov 19, 2019 8:31:20 PM (4 years ago)
Author:
Devin Rousso
Message:

Web Inspector: DOM.highlightSelector should work for "div, div::before"
https://bugs.webkit.org/show_bug.cgi?id=204306

Reviewed by Brian Burg.

.:

  • ManualTests/inspector/overlay-selectors.html: Added.

Source/WebCore:

In r252436, the implementation of DOM.highlightSelector was changed from just calling
document.querySelectorAll to actually attempting to mimic what the CSS selector matching
engine does. Basically, this meant adding logic to walk the entire DOM tree and for each
node test each CSSSelector of the given selector string to see if it matched.

At the time, I had incorrectly assumed that once a selector was found that matched the
current node, it wouldn't need to be checked against ever again. This would be a fine
assumption if we didn't care about :before/:after, but since DOM.highlightSelector
also wants to match those, it is necessary to test every CSSSelector in case a later one
in the given selector string matches a pseudo-element (e.g. div, div:before).

The fix is simply to change break to continue and to ensure that every item in the
generated NodeList is unique (otherwise the overlay for a node may be drawn twice).

  • inspector/agents/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::highlightSelector):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r252366 r252682  
     12019-11-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: DOM.highlightSelector should work for "div, div::before"
     4        https://bugs.webkit.org/show_bug.cgi?id=204306
     5
     6        Reviewed by Brian Burg.
     7
     8        * ManualTests/inspector/overlay-selectors.html: Added.
     9
    1102019-11-12  Carlos Alberto Lopez Perez  <clopez@igalia.com>
    211
  • trunk/Source/WebCore/ChangeLog

    r252681 r252682  
     12019-11-19  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: DOM.highlightSelector should work for "div, div::before"
     4        https://bugs.webkit.org/show_bug.cgi?id=204306
     5
     6        Reviewed by Brian Burg.
     7
     8        In r252436, the implementation of `DOM.highlightSelector` was changed from just calling
     9        `document.querySelectorAll` to actually attempting to mimic what the CSS selector matching
     10        engine does. Basically, this meant adding logic to walk the entire DOM tree and for each
     11        node test each `CSSSelector` of the given `selector` string to see if it matched.
     12
     13        At the time, I had incorrectly assumed that once a selector was found that matched the
     14        current node, it wouldn't need to be checked against ever again. This would be a fine
     15        assumption if we didn't care about `:before`/`:after`, but since `DOM.highlightSelector`
     16        also wants to match those, it is necessary to test every `CSSSelector` in case a later one
     17        in the given `selector` string matches a pseudo-element (e.g. `div, div:before`).
     18
     19        The fix is simply to change `break` to `continue` and to ensure that every item in the
     20        generated `NodeList` is unique (otherwise the overlay for a node may be drawn twice).
     21
     22        * inspector/agents/InspectorDOMAgent.cpp:
     23        (WebCore::InspectorDOMAgent::highlightSelector):
     24
    1252019-11-19  Youenn Fablet  <youenn@apple.com>
    226
  • trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp

    r252436 r252682  
    12611261    SelectorChecker selectorChecker(*document);
    12621262
    1263     Vector<Ref<Node>> nodes;
     1263    Vector<Ref<Node>> nodeList;
     1264    HashSet<Node*> seenNodes;
    12641265
    12651266    for (auto& descendant : composedTreeDescendants(*document)) {
     
    12821283            unsigned ignoredSpecificity;
    12831284            if (selectorChecker.match(*selector, descendantElement, context, ignoredSpecificity)) {
    1284                 nodes.append(descendantElement);
    1285                 break;
     1285                if (seenNodes.add(&descendantElement))
     1286                    nodeList.append(descendantElement);
    12861287            }
    12871288
     
    12911292                if (pseudoIDs.has(PseudoId::Before)) {
    12921293                    pseudoIDs.remove(PseudoId::Before);
    1293                     if (auto* beforePseudoElement = descendantElement.beforePseudoElement())
    1294                         nodes.append(*beforePseudoElement);
     1294                    if (auto* beforePseudoElement = descendantElement.beforePseudoElement()) {
     1295                        if (seenNodes.add(beforePseudoElement))
     1296                            nodeList.append(*beforePseudoElement);
     1297                    }
    12951298                }
    12961299
    12971300                if (pseudoIDs.has(PseudoId::After)) {
    12981301                    pseudoIDs.remove(PseudoId::After);
    1299                     if (auto* afterPseudoElement = descendantElement.afterPseudoElement())
    1300                         nodes.append(*afterPseudoElement);
     1302                    if (auto* afterPseudoElement = descendantElement.afterPseudoElement()) {
     1303                        if (seenNodes.add(afterPseudoElement))
     1304                            nodeList.append(*afterPseudoElement);
     1305                    }
    13011306                }
    13021307
    13031308                if (pseudoIDs) {
    1304                     nodes.append(descendantElement);
    1305                     break;
     1309                    if (seenNodes.add(&descendantElement))
     1310                        nodeList.append(descendantElement);
    13061311                }
    13071312            }
     
    13091314    }
    13101315
    1311     m_overlay->highlightNodeList(StaticNodeList::create(WTFMove(nodes)), *highlightConfig);
     1316    m_overlay->highlightNodeList(StaticNodeList::create(WTFMove(nodeList)), *highlightConfig);
    13121317}
    13131318
Note: See TracChangeset for help on using the changeset viewer.