<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>76736</bug_id>
          
          <creation_ts>2012-01-20 13:49:59 -0800</creation_ts>
          <short_desc>window.getMatchedCSSRules() not supporting pseudo classes</short_desc>
          <delta_ts>2012-04-05 11:50:46 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>CSS</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>All</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>0</everconfirmed>
          <reporter name="Eric Guzman">epiceric24</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dstorey</cc>
    
    <cc>jackalmage</cc>
    
    <cc>shanestephens</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>539767</commentid>
    <comment_count>0</comment_count>
      <attachid>123371</attachid>
    <who name="Eric Guzman">epiceric24</who>
    <bug_when>2012-01-20 13:49:59 -0800</bug_when>
    <thetext>Created attachment 123371
Demo of getMatchedCSSRules bug

What steps will reproduce the problem?
1. Create CSS rules that apply to an element (including pseudo-class selectors)
2. Call window.getMatchedCSSRules(domElement, pseudoClassString), with pseudoClassString corresponding to those used in step 1.

What is the expected result?
The method should return a rule list containing the rules with pseudo class selectors.

What happens instead?
It only returns a rule list with the non-pseudo class selectors.

I don&apos;t know why this method only seems to support pseudo element selectors, when the use case for pseudo class selectors seems more common (or at least easy enough to support).

It would also be convenient for the method to return all CSS rules matching an element including all pseudo classes/elements. Currently, if you want to get all of the CSS rules targeting the element (in one state or another), this method would need to be called repeatedly.

Another problem with the method is that if a pseudo argument is supplied, but no css rules match the pseudo, it will return the non-psuedo CSS rules. I think returning null is the appropriate behavior.

About Attachment
I&apos;ve provided an html page which has a demo of the bug. The html page includes an element which is styled with pseudo classes/elements. A button on the page calls &quot;getMatchedCSSRules(element, pseudo)&quot; passing in the pseudo specified in the drop down. There is also a log that shows the cssText of the returned rules.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>552783</commentid>
    <comment_count>1</comment_count>
    <who name="Shane Stephens">shanestephens</who>
    <bug_when>2012-02-08 19:59:24 -0800</bug_when>
    <thetext>getMatchedCSSRules currently has no public specification, but as far as I can tell the second argument is not intended to accept pseudoClasses (i.e. it only accepts pseudoElements by design).

If you feel that (1) getMatchedCSSRules is an important feature for the web platform and (2) it should return pseudoClasses, then I would encourage you to propose the feature on www-style.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>596249</commentid>
    <comment_count>2</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2012-04-04 19:55:37 -0700</bug_when>
    <thetext>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&apos;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&apos;s conclusion is wrong - gMCR *does* return rules that only match due to pseudo-classes.  For example, in the following document you&apos;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(&apos;p&apos;)))%3B%0A%3C%2Fscript%3E

It&apos;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(&apos;button&apos;).onclick%20%3D%20function()%7B%20%0A%20%20console.log(getMatchedCSSRules(document.querySelector(&apos;p&apos;)))%3B%0A%7D%3B%0A%3C%2Fscript%3E

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

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

This sounds like a fine idea (it&apos;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&apos;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.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>596250</commentid>
    <comment_count>3</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2012-04-04 19:59:17 -0700</bug_when>
    <thetext>(In reply to comment #0)
&gt; Another problem with the method is that if a pseudo argument is supplied, but no css rules match the pseudo, it will return the non-psuedo CSS rules. I think returning null is the appropriate behavior.

Please file one bug per bug.  ^_^

This is half-valid.  If you specify a valid pseudo-element, and no rules match the pseudo, it returns null, as it should.  However, it you pass it a string that doesn&apos;t correspond to any pseudo (like getMatchedCSSRules(el, &apos;foo&apos;) ), then it just ignores the second argument and returns the rules that match the element normally.

I agree this isn&apos;t ideal behavior, as it&apos;s future-hostile (if we later add a ::foo pseudo-element, someone accidentally depending on that call returning the rules that match the passed element will break).  Please file a separate bug for this, with a title like &quot;getMatchedCSSRules() should return null when the second argument is an unrecognized pseudo-element name&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>596710</commentid>
    <comment_count>4</comment_count>
    <who name="David Storey">dstorey</who>
    <bug_when>2012-04-05 10:56:30 -0700</bug_when>
    <thetext>(In reply to comment #2)

&gt; What it won&apos;t do, though, is return a rule with a &quot;:hover&quot; selector when the element isn&apos;t being hovered, because that rule isn&apos;t currently matching the element.
&gt; 
&gt; If you&apos;d like to be get the selectors that would apply when an element is hovered, we&apos;d need an additional argument letting us specify some state that we should pretend the element matches.  
&gt; 
&gt; This sounds like a fine idea (it&apos;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.

Yes, this is exactly the kind of thing we want to be able to do.
&gt; 
&gt; Given that this gMCR isn&apos;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.

Yes, it would be great if we could get that argument. Should I file a bug in the CSS bugzilla or post on www-style first?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>596713</commentid>
    <comment_count>5</comment_count>
    <who name="Tab Atkins Jr.">jackalmage</who>
    <bug_when>2012-04-05 11:02:00 -0700</bug_when>
    <thetext>I recommend first posting to www-style proposing to specify gMCR, then when you write the spec discuss adding the additional argument.  Our current implementation counts as a simple experiment, so it&apos;s okay to extend the API as we spec it.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>596758</commentid>
    <comment_count>6</comment_count>
    <who name="Eric Guzman">epiceric24</who>
    <bug_when>2012-04-05 11:50:46 -0700</bug_when>
    <thetext>Thanks for the additional info, Tab, and thanks for the follow-up, David.

I created a bug for the method not returning null, as suggested: https://bugs.webkit.org/show_bug.cgi?id=83298.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>123371</attachid>
            <date>2012-01-20 13:49:59 -0800</date>
            <delta_ts>2012-01-20 13:49:59 -0800</delta_ts>
            <desc>Demo of getMatchedCSSRules bug</desc>
            <filename>index.html</filename>
            <type>text/html</type>
            <size>2227</size>
            <attacher name="Eric Guzman">epiceric24</attacher>
            
              <data encoding="base64">PCFET0NUWVBFIGh0bWw+CjxodG1sPgo8aGVhZD4KCTxtZXRhIGh0dHAtZXF1aXY9IkNvbnRlbnQt
dHlwZSIgY29udGVudD0idGV4dC9odG1sOyBjaGFyc2V0PXV0Zi04Ij4KCTx0aXRsZT5CdWcgd2l0
aCB3aW5kb3cuZ2V0TWF0Y2hlZENTU1J1bGVzKCk8L3RpdGxlPgoKCTxzdHlsZSB0eXBlPSJ0ZXh0
L2NzcyIgbWVkaWE9InNjcmVlbiI+CgkJYm9keSB7CgkJCWZvbnQtZmFtaWx5OiBIZWx2ZXRpY2Es
IEFyaWFsLCBzYW5zLXNlcmlmOwoJCX0KCQkuY29udGFpbmVyIHsKCQkJd2lkdGg6IDUwMHB4OwoJ
CQltYXJnaW46IDAgYXV0bzsKCQkJdGV4dC1hbGlnbjogY2VudGVyOwoJCX0KCQkjZGl2MSB7CgkJ
CWJhY2tncm91bmQtY29sb3I6ICNDQ0M7CgkJCWJvcmRlcjogMTBweCBzb2xpZCAjMzMzOwoJCQl3
aWR0aDogMjAwcHg7CgkJCWhlaWdodDogMjAwcHg7CgkJCW1hcmdpbjogMjBweCBhdXRvOwoJCX0K
CQkjZGl2MSB7CgkJICAgIGNvbG9yOiByZWQ7CgkJfQoJCSNkaXYxOmJlZm9yZSB7CgkJCWNvbnRl
bnQ6ICIjZGl2MSI7CgkJCWJvcmRlcjogMXB4IGRhc2hlZCAjRkZGOwoJCX0KCQkjZGl2MTpob3Zl
ciB7CgkJCWJhY2tncm91bmQtY29sb3I6ICM2NjY7CgkJfQoJCSNkaXYxOmFjdGl2ZSB7CgkJCWJh
Y2tncm91bm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