[Webkit-unassigned] [Bug 76736] window.getMatchedCSSRules() not supporting pseudo classes

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Wed Apr 4 19:55:37 PDT 2012


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


Tab Atkins Jr. <jackalmage at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jackalmage at gmail.com




--- Comment #2 from Tab Atkins Jr. <jackalmage at gmail.com>  2012-04-04 19:55:37 PST ---
Pseudo-classes and pseudo-elements are completely different things.  They have almost no relation, except for an unfortunate early design flaw that made their syntax identical, and which carried over due to IE.

The second argument to gMCR is solely for selecting pseudo-elements, because you can't actually get a reference to a pseudo-element normally to pass as the first argument.

So, the premise of the bug is incorrect - gMCR *never* took a pseudo-class string argument.  Further, it's conclusion is wrong - gMCR *does* return rules that only match due to pseudo-classes.  For example, in the following document you'll get both rules showing up in your console results: 

data:text/html;charset=utf-8,%3C!DOCTYPE%20html%3E%0A%3Cp%3Efoo%0A%3Cstyle%3E%0Ap%20%7B%20color%3A%20red%3B%20%7D%0A%3Afirst-child%20%7B%20background%3A%20blue%3B%20%7D%0A%3C%2Fstyle%3E%0A%3Cscript%3E%0Aconsole.log(getMatchedCSSRules(document.querySelector('p')))%3B%0A%3C%2Fscript%3E

It'll even work for :hover rules *if you make the gMCR call while the element is being hovered*.  Example (press the button to call gMCR and log it to console): 

data:text/html;charset=utf-8,%3C!DOCTYPE%20html%3E%0A%3Cp%3Efoo%3Cbutton%3Ebar%3C%2Fbutton%3E%0A%3Cstyle%3E%0Ap%20%7B%20color%3A%20red%3B%20%7D%0Ap%3Afirst-child%20%7B%20background%3A%20blue%3B%20%7D%0Ap%3Ahover%20%7B%20background%3A%20green%3B%20%7D%0A%3C%2Fstyle%3E%0A%3Cscript%3E%0Adocument.querySelector('button').onclick%20%3D%20function()%7B%20%0A%20%20console.log(getMatchedCSSRules(document.querySelector('p')))%3B%0A%7D%3B%0A%3C%2Fscript%3E

What it won't do, though, is return a rule with a ":hover" selector when the element isn't being hovered, because that rule isn't currently matching the element.

If you'd like to be get the selectors that would apply when an element is hovered, we'd need an additional argument letting us specify some state that we should pretend the element matches.  

This sounds like a fine idea (it's needed if you want a relatively easy way to achieve functionality like what Inspector does when it shows you the rules that apply during :hover), but it needs specification.

Given that this gMCR isn't specified *at all* right now, the right thing to do is fix that problem first and write a CSSOM subspec, then add this argument to the spec so we can implement it.

-- 
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