Changeset 252436 in webkit


Ignore:
Timestamp:
Nov 13, 2019 3:56:36 PM (4 years ago)
Author:
Devin Rousso
Message:

Web Inspector: DOM.highlightSelector should work for "a:visited"
https://bugs.webkit.org/show_bug.cgi?id=146161
<rdar://problem/21467303>

Reviewed by Antti Koivisto.

  • inspector/agents/InspectorDOMAgent.cpp:

(WebCore::InspectorDOMAgent::highlightSelector):
Rather than use document.querySelectorAll, which doesn't match pseudo-selectors, attempt
to mimic how CSS actually matches nodes.

  • rendering/style/RenderStyleConstants.h:

(WebCore::PseudoIdSet::remove): Added.

Location:
trunk/Source/WebCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252435 r252436  
     12019-11-13  Devin Rousso  <drousso@apple.com>
     2
     3        Web Inspector: DOM.highlightSelector should work for "a:visited"
     4        https://bugs.webkit.org/show_bug.cgi?id=146161
     5        <rdar://problem/21467303>
     6
     7        Reviewed by Antti Koivisto.
     8
     9        * inspector/agents/InspectorDOMAgent.cpp:
     10        (WebCore::InspectorDOMAgent::highlightSelector):
     11        Rather than use `document.querySelectorAll`, which doesn't match pseudo-selectors, attempt
     12        to mimic how CSS actually matches nodes.
     13
     14        * rendering/style/RenderStyleConstants.h:
     15        (WebCore::PseudoIdSet::remove): Added.
     16
    1172019-11-13  Myles C. Maxfield  <mmaxfield@apple.com>
    218
  • trunk/Source/WebCore/inspector/agents/InspectorDOMAgent.cpp

    r251871 r252436  
    3636#include "Attr.h"
    3737#include "CSSComputedStyleDeclaration.h"
     38#include "CSSParser.h"
    3839#include "CSSPropertyNames.h"
    3940#include "CSSPropertySourceData.h"
    4041#include "CSSRule.h"
    4142#include "CSSRuleList.h"
     43#include "CSSSelector.h"
     44#include "CSSSelectorList.h"
    4245#include "CSSStyleRule.h"
    4346#include "CSSStyleSheet.h"
    4447#include "CharacterData.h"
    4548#include "CommandLineAPIHost.h"
     49#include "ComposedTreeIterator.h"
    4650#include "ContainerNode.h"
    4751#include "Cookie.h"
     
    9397#include "RenderStyleConstants.h"
    9498#include "ScriptState.h"
     99#include "SelectorChecker.h"
    95100#include "ShadowRoot.h"
    96101#include "StaticNodeList.h"
     
    110115#include <JavaScriptCore/JSCInlines.h>
    111116#include <pal/crypto/CryptoDigest.h>
     117#include <wtf/Function.h>
    112118#include <wtf/text/Base64.h>
    113119#include <wtf/text/CString.h>
     
    12231229void InspectorDOMAgent::highlightSelector(ErrorString& errorString, const JSON::Object& highlightInspectorObject, const String& selectorString, const String* frameId)
    12241230{
     1231    auto highlightConfig = highlightConfigFromInspectorObject(errorString, &highlightInspectorObject);
     1232    if (!highlightConfig)
     1233        return;
     1234
    12251235    RefPtr<Document> document;
    12261236
     
    12451255    }
    12461256
    1247     auto queryResult = document->querySelectorAll(selectorString);
    1248     // FIXME: <https://webkit.org/b/146161> Web Inspector: DOM.highlightSelector should work for "a:visited"
    1249     if (queryResult.hasException()) {
    1250         errorString = "DOM Error while querying with given selectorString"_s;
    1251         return;
    1252     }
    1253 
    1254     auto highlightConfig = highlightConfigFromInspectorObject(errorString, &highlightInspectorObject);
    1255     if (!highlightConfig)
    1256         return;
    1257 
    1258     m_overlay->highlightNodeList(queryResult.releaseReturnValue(), *highlightConfig);
     1257    CSSParser parser(*document);
     1258    CSSSelectorList selectorList;
     1259    parser.parseSelector(selectorString, selectorList);
     1260
     1261    SelectorChecker selectorChecker(*document);
     1262
     1263    Vector<Ref<Node>> nodes;
     1264
     1265    for (auto& descendant : composedTreeDescendants(*document)) {
     1266        if (!is<Element>(descendant))
     1267            continue;
     1268
     1269        auto& descendantElement = downcast<Element>(descendant);
     1270
     1271        auto isInUserAgentShadowTree = descendantElement.isInUserAgentShadowTree();
     1272        auto pseudoId = descendantElement.pseudoId();
     1273        auto& pseudo = descendantElement.pseudo();
     1274
     1275        for (const auto* selector = selectorList.first(); selector; selector = CSSSelectorList::next(selector)) {
     1276            if (isInUserAgentShadowTree && (selector->match() != CSSSelector::PseudoElement || selector->value() != pseudo))
     1277                continue;
     1278
     1279            SelectorChecker::CheckingContext context(SelectorChecker::Mode::ResolvingStyle);
     1280            context.pseudoId = pseudoId;
     1281
     1282            unsigned ignoredSpecificity;
     1283            if (selectorChecker.match(*selector, descendantElement, context, ignoredSpecificity)) {
     1284                nodes.append(descendantElement);
     1285                break;
     1286            }
     1287
     1288            if (context.pseudoIDSet) {
     1289                auto pseudoIDs = PseudoIdSet::fromMask(context.pseudoIDSet.data());
     1290
     1291                if (pseudoIDs.has(PseudoId::Before)) {
     1292                    pseudoIDs.remove(PseudoId::Before);
     1293                    if (auto* beforePseudoElement = descendantElement.beforePseudoElement())
     1294                        nodes.append(*beforePseudoElement);
     1295                }
     1296
     1297                if (pseudoIDs.has(PseudoId::After)) {
     1298                    pseudoIDs.remove(PseudoId::After);
     1299                    if (auto* afterPseudoElement = descendantElement.afterPseudoElement())
     1300                        nodes.append(*afterPseudoElement);
     1301                }
     1302
     1303                if (pseudoIDs) {
     1304                    nodes.append(descendantElement);
     1305                    break;
     1306                }
     1307            }
     1308        }
     1309    }
     1310
     1311    m_overlay->highlightNodeList(StaticNodeList::create(WTFMove(nodes)), *highlightConfig);
    12591312}
    12601313
  • trunk/Source/WebCore/rendering/style/RenderStyleConstants.h

    r252336 r252436  
    140140        ASSERT((sizeof(m_data) * 8) > static_cast<unsigned>(pseudoId));
    141141        m_data |= (1U << static_cast<unsigned>(pseudoId));
     142    }
     143
     144    void remove(PseudoId pseudoId)
     145    {
     146        ASSERT((sizeof(m_data) * 8) > static_cast<unsigned>(pseudoId));
     147        m_data &= ~(1U << static_cast<unsigned>(pseudoId));
    142148    }
    143149
Note: See TracChangeset for help on using the changeset viewer.