[Webkit-unassigned] [Bug 110524] New: Add a way to watch pages for elements matching a CSS selector

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Thu Feb 21 15:55:49 PST 2013


https://bugs.webkit.org/show_bug.cgi?id=110524

           Summary: Add a way to watch pages for elements matching a CSS
                    selector
           Product: WebKit
           Version: 528+ (Nightly build)
          Platform: All
        OS/Version: All
            Status: UNCONFIRMED
          Severity: Enhancement
          Priority: P2
         Component: CSS
        AssignedTo: webkit-unassigned at lists.webkit.org
        ReportedBy: jyasskin at chromium.org
                CC: tony at chromium.org


Created an attachment (id=189626)
 --> (https://bugs.webkit.org/attachment.cgi?id=189626&action=review)
Preliminary patch adding a -webkit-callback CSS property

In order to implement http://developer.chrome.com/trunk/extensions/declarativeContent.html efficiently, I'd like to add a way to cause certain CSS selectors to fire a callback in the WebKit embedder when they match an element on the page.


The attached patch is a possible direction for this: I've added a -webkit-callback CSS property with values of 'none' and '-webkit-presence'. If a rule with -webkit-callback: -webkit-presence matches any element in a frame, WebCore::FrameLoaderClient::selectorMatchChanged(selector, true), where 'selector' is the result of SelectorList::selectorsText() on the matching rule. Unlike most (all?) other CSS properties, if multiple rules match with this property, all of their selectors get passed back to the client.  The WebKit/chromium embedding then batches these within a microtask to present a summary of the changes out to Chromium itself.

If the DOM changes so that a particular rule doesn't match any element on the page anymore, selectorMatchChanged(selector, false) is called.

Setting '-webkit-callback: none' in a rule unregisters interest in the particular selector used for that rule, but not other selectors. 'initial' and 'inherit' have no effect.

I chose "-webkit-presence" because this callback is watching for the presence of a type of element on the page. There's an obvious extension to watch for each element's creation or destruction, but handling that would be more complex and would require me to make this sort of RenderStyle unshareable. Since I don't need to watch particular elements for my use case, I didn't do this.  I also don't see any need to expose these callbacks to Javascript.

A preliminary use of this API is at https://codereview.chromium.org/12326052/.


This patch still lacks tests, and probably does many things in totally the wrong way. I'd appreciate any suggestions for how to do it better, even if that means completely redoing the approach.  One other interface that might work would be to extend mutation observers to filter by css selector. I didn't pick this route because it would seem to require a web platform change, and I don't immediately see a way to do it without notifying on every element change, which, as I said above, is heavier-weight than I actually need.

Let me know what you think. Thanks.

-- 
Configure bugmail: https://bugs.webkit.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.



More information about the webkit-unassigned mailing list