<?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>61532</bug_id>
          
          <creation_ts>2011-05-26 07:54:34 -0700</creation_ts>
          <short_desc>A focusedNode should be kept in each TreeScope, not in each Document.</short_desc>
          <delta_ts>2011-06-08 22:51:23 -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>DOM</component>
          <version>528+ (Nightly build)</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          <blocked>59832</blocked>
    
    <blocked>61409</blocked>
          <everconfirmed>1</everconfirmed>
          <reporter name="Hayato Ito">hayato</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>dglazkov</cc>
    
    <cc>dominicc</cc>
    
    <cc>morrita</cc>
    
    <cc>rolandsteiner</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>410438</commentid>
    <comment_count>0</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2011-05-26 07:54:34 -0700</bug_when>
    <thetext>Currently, a focusedNode is tracked in each Document using Document::focusedNode().
To make elements in shadow DOM focusable and make it simple, it is nice to keep focusedNode in each TreeScope, not in each Document.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>412120</commentid>
    <comment_count>1</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2011-05-29 22:21:20 -0700</bug_when>
    <thetext>Let me share my idea briefly here.

The main motivation is to make a &apos;shadow-host&apos; act similar to a &apos;iframe&apos;, which is a boundary of focus scope. For example, if a iframe element is not focusable, all descendant elements in the iframe are skipped when we press &apos;Tab&apos; key. I&apos;d like to apply the same behavior to shadow host.

I am trying to implement &apos;tab traversal into shadow&apos; in bug 61410. But it turned out that we should make things changed: I&apos;d like to have focusedNode in each TreeScope, not in each Document. Let me explain by using examples:

See the following tree:

  Document (outer)
    - &lt;p&gt;
    - &lt;iframe&gt;  &lt;--- A
       - Document (inner)
         - &lt;input&gt;  &lt;---- B
         - &lt;input&gt;


 When a node B is focused, the following things will happen:
  - focusController::focusedFrame -&gt; A
  - outerDocument::focusedNode() -&gt; 0 (Hmm.. I&apos;d like to change this behavior. If that were A, some things would get simpler..?)
  - innerDocument::focusedNode() -&gt; B
  - outerDocument.activeElement -&gt; A
  - innerDocument.activeElement -&gt; B


See the next tree, which contains a shadow-host element

  Document
    - &lt;p&gt;
    - &lt;shadow-host&gt;   &lt;--- A
        .. shadow-root
             - &lt;input&gt;  &lt;---- B
             - &lt;input&gt;


 When a node B is focused, what is expected? In working patch in https://bugs.webkit.org/attachment.cgi?id=95126, the following will happen:
  - focusController::focusedFrame -&gt; a document (There is only one document, which is shared between an outer tree and a shadow root.)
  - document::focusedNode() -&gt; B
  - document.activeElement -&gt;  should be A (Not implemented yet, there is a working patch in bug 61413 ).

I&apos;d like to vanish this difference and treat these uniformly:

- Have focusedNode in each TreeScope, not in each Document.
- To make FocusControler have focusedTreeSocpe() in addition to focusedFrame().

By these changes, we cat get current deepest focusedNode by focusController-&gt;focusedTreeScope()-&gt;focusedNode().
And ideally, document.activeElement is always same to the return value of &apos;document::focusedNode&apos;.

So the latter case should be:

  focusController::focusedTreeScope() -&gt; shadow-root 
  shadow-root::focusedNode() -&gt; B
  shadow-root::activeElement -&gt; ??? (Should TreeScope has activeElement?)
  document::focusedNode() -&gt; A (shadow host)
  document.activeElement -&gt;  A (shadow host)

This is my rough idea.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>412124</commentid>
    <comment_count>2</comment_count>
    <who name="Dominic Cooney">dominicc</who>
    <bug_when>2011-05-29 22:42:15 -0700</bug_when>
    <thetext>That sounds good to me. Putting activeElement on TreeScope and having it point to the shadow host when an element in the shadow has focus sounds good.

I don’t understand why focusedNode belongs on TreeScope. Is focusedNode() the same for all TreeScopes in a document? Why does having focusedNode on TreeScope make things easier?

focusedNode is completely internal to WebKit, right? Who uses it? Why would making it non-0 when a frame is focused make things easier? Seems like it might be good to know when you’re crossing an iframe boundary.

Another question: What happens when you have this?

Document
  - &lt;shadow-host&gt; &lt;--- A
    … shadow-root
      - &lt;content&gt;
    - &lt;input&gt; &lt;--- B

Say node B has focus. Is the activeElement of the document A or B?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>412135</commentid>
    <comment_count>3</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2011-05-29 23:44:10 -0700</bug_when>
    <thetext>Thank you for the comment. I appreciate it.

(In reply to comment #2)
&gt; That sounds good to me. Putting activeElement on TreeScope and having it point to the shadow host when an element in the shadow has focus sounds good.
&gt; 
&gt; I don’t understand why focusedNode belongs on TreeScope. Is focusedNode() the same for all TreeScopes in a document? Why does having focusedNode on TreeScope make things easier?
&gt; 
&gt; focusedNode is completely internal to WebKit, right? Who uses it? Why would making it non-0 when a frame is focused make things easier? Seems like it might be good to know when you’re crossing an iframe boundary.

That&apos;s good point. Actually we don&apos;t need maintain each focusedNode in each scope. We can calculate an upper scope&apos;s direct focused child on the fly once we know a deepest focused Node.
e.g. If we know E is focused, we can easily calculate that A&apos;s direct focused child is B.

  - shadow-host - A
     - shadow-host - B
        - iframe - C
           - shadow-host - D
                &lt;input&gt; E ---&gt; focused

Maybe the similar discussion can apply to the Document::m_focusedNode. A focusedNode is the same for all Documents (and iframes) within one &apos;page&apos;, isn&apos;t it? We can calculate each iframe&apos;s activeElement on the fly only if we know a deepest focused Node. Document::activeElement() is actually doing that. It looks that Document::m_focusedNode is only used internally to make implementations simpler.
I&apos;d would like to treat iframe and shadow-root uniformly.
  - Both maintain a focusedNode.
  - Or neither maintain focusedNode. Only focusedController maintains focusedNode within one page.

I&apos;ve not started to try implementation of this idea, so having focusedNode in each TreeScope might not be a good idea.  Anyway, it should be just a implementation detail, so I might change my mind if things won&apos;t go well as I expected.


&gt; 
&gt; Another question: What happens when you have this?
&gt; 
&gt; Document
&gt;   - &lt;shadow-host&gt; &lt;--- A
&gt;     … shadow-root
&gt;       - &lt;content&gt;
&gt;     - &lt;input&gt; &lt;--- B
&gt; 
&gt; Say node B has focus. Is the activeElement of the document A or B?

Interesting. In this case, document.activeElement should be &apos;A&apos; for me at the first glance.
But we should discuss which is better and natural.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>417103</commentid>
    <comment_count>4</comment_count>
    <who name="Roland Steiner">rolandsteiner</who>
    <bug_when>2011-06-07 23:15:26 -0700</bug_when>
    <thetext>(In reply to comment #1)
&gt; When a node B is focused, the following things will happen:
&gt;  - focusController::focusedFrame -&gt; A
&gt;  - outerDocument::focusedNode() -&gt; 0 (Hmm.. I&apos;d like to change this behavior. If that were A, some things would get simpler..?)
&gt;  - innerDocument::focusedNode() -&gt; B
&gt;  - outerDocument.activeElement -&gt; A
&gt;  - innerDocument.activeElement -&gt; B

This seems to be correct to me. The focused node is not in outerDocument, so outerDocument::focusedNode() can only be 0 (the &lt;iframe&gt; isn&apos;t what is focused, after all).

(In reply to comment #3)
&gt;   - shadow-host - A
&gt;      - shadow-host - B
&gt;         - iframe - C
&gt;            - shadow-host - D
&gt;                 &lt;input&gt; E ---&gt; focused

All in all, from the discussion it seems to me, that the question rather is how should &apos;activeElement&apos; behave, rather than focusedNode (?).

One possibility could be to have a separate TreeScope.activeElement: a TreeScope&apos;s activeElement could point to the deepest ancestor node of the focused node that is still in the same TreeScope, while a Document&apos;s activeElement is the deepest ancestor node of the focused node that is still in the same document. (where ancestors cross document boundaries). However, this would require a distinction between &apos;Document-as-TreeScope&apos; and &apos;Document-as-Document&apos;.

&gt; &gt; Another question: What happens when you have this?
&gt; &gt; 
&gt; &gt; Document
&gt; &gt;   - &lt;shadow-host&gt; &lt;--- A
&gt; &gt;     … shadow-root
&gt; &gt;       - &lt;content&gt;
&gt; &gt;     - &lt;input&gt; &lt;--- B
&gt; &gt; 
&gt; &gt; Say node B has focus. Is the activeElement of the document A or B?
&gt; 
&gt; Interesting. In this case, document.activeElement should be &apos;A&apos; for me at the first glance.
&gt; But we should discuss which is better and natural.

(Assuming B is a child of the shadow host) IMHO this can only be &apos;B&apos; as otherwise activeElement would require rendering knowledge.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>417837</commentid>
    <comment_count>5</comment_count>
    <who name="Hayato Ito">hayato</who>
    <bug_when>2011-06-08 22:51:23 -0700</bug_when>
    <thetext>Thank you for the comments. Let me update the status.

I tried to implement this idea, keeping a focusedNode in each TreeScope.
But I have not used this approach in implementing &lt;Tab&gt; traversal in shadow, bug 61410.
I just used the current approach, keeping a focusedNode in each Document.

Although I am not sure which is better or not, let me close this bug as WONTFIX until we have clear thought that this is worth doing or not. I might open this issue again in the future.


(In reply to comment #4)
&gt; (In reply to comment #1)
&gt; &gt; When a node B is focused, the following things will happen:
&gt; &gt;  - focusController::focusedFrame -&gt; A
&gt; &gt;  - outerDocument::focusedNode() -&gt; 0 (Hmm.. I&apos;d like to change this behavior. If that were A, some things would get simpler..?)
&gt; &gt;  - innerDocument::focusedNode() -&gt; B
&gt; &gt;  - outerDocument.activeElement -&gt; A
&gt; &gt;  - innerDocument.activeElement -&gt; B
&gt; 
&gt; This seems to be correct to me. The focused node is not in outerDocument, so outerDocument::focusedNode() can only be 0 (the &lt;iframe&gt; isn&apos;t what is focused, after all).
&gt; 
&gt; (In reply to comment #3)
&gt; &gt;   - shadow-host - A
&gt; &gt;      - shadow-host - B
&gt; &gt;         - iframe - C
&gt; &gt;            - shadow-host - D
&gt; &gt;                 &lt;input&gt; E ---&gt; focused
&gt; 
&gt; All in all, from the discussion it seems to me, that the question rather is how should &apos;activeElement&apos; behave, rather than focusedNode (?).
&gt; 
&gt; One possibility could be to have a separate TreeScope.activeElement: a TreeScope&apos;s activeElement could point to the deepest ancestor node of the focused node that is still in the same TreeScope, while a Document&apos;s activeElement is the deepest ancestor node of the focused node that is still in the same document. (where ancestors cross document boundaries). However, this would require a distinction between &apos;Document-as-TreeScope&apos; and &apos;Document-as-Document&apos;.
&gt; 
&gt; &gt; &gt; Another question: What happens when you have this?
&gt; &gt; &gt; 
&gt; &gt; &gt; Document
&gt; &gt; &gt;   - &lt;shadow-host&gt; &lt;--- A
&gt; &gt; &gt;     … shadow-root
&gt; &gt; &gt;       - &lt;content&gt;
&gt; &gt; &gt;     - &lt;input&gt; &lt;--- B
&gt; &gt; &gt; 
&gt; &gt; &gt; Say node B has focus. Is the activeElement of the document A or B?
&gt; &gt; 
&gt; &gt; Interesting. In this case, document.activeElement should be &apos;A&apos; for me at the first glance.
&gt; &gt; But we should discuss which is better and natural.
&gt; 
&gt; (Assuming B is a child of the shadow host) IMHO this can only be &apos;B&apos; as otherwise activeElement would require rendering knowledge.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>