Bug 29703 - Add a function to element to check whether it matches a CSS selector
: Add a function to element to check whether it matches a CSS selector
Status: RESOLVED FIXED
: WebKit
HTML DOM
: 528+ (Nightly build)
: All Mac OS X 10.6
: P2 Normal
Assigned To:
:
:
:
:
  Show dependency treegraph
 
Reported: 2009-09-24 00:09 PST by
Modified: 2010-07-29 13:40 PST (History)


Attachments
patch (32.00 KB, patch)
2009-09-24 00:14 PST, Sam Weinig
mitz: review+
Review Patch | Details | Formatted Diff | Diff
modified version of jressig's test (61.03 KB, text/html)
2009-09-24 15:41 PST, Sam Weinig
no flags Details


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2009-09-24 00:09:00 PST
As is being discussed for v2 of the Selectors API, we should add a function to Element to check if it matches a selector (Element.webkitMatchesSelector).  Mozilla is also working on this (https://bugzilla.mozilla.org/show_bug.cgi?id=518003).
------- Comment #1 From 2009-09-24 00:14:50 PST -------
Created an attachment (id=40048) [details]
patch

Implement Element.webkitMatchesSelector.
------- Comment #2 From 2009-09-24 10:48:15 PST -------
Landed in r48723.
------- Comment #3 From 2009-09-24 15:41:21 PST -------
Created an attachment (id=40087) [details]
modified version of jressig's test
------- Comment #4 From 2009-10-05 08:34:07 PST -------
I believe there is a performance problem with the webkitMatchesSelector() method as you are currently implementing. Proof is that my javascript implementation is about 10/20% faster than native C++ implementation.

The method I use is to parse and compile the passed CSS selector strings in ad-hoc javascript functions that can be reused for the rest of the page lifetime, it is a pure bottom-up matcher, very fast.

The speed improvements will be really high for this method, I would like to underline the fact that this new methods could be called thousands of time during page interactions controlled by event delegation, so it seems important
to have the fastest outcome in speed from these methods.

Here is the test showing the described slowness:

  http://dl.getdropbox.com/u/598365/matchspeed/matchspeed-custom.html

Can be tested only with r48723 and above or a nightly Firefox.

I used r49078 in my tests.