This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 17089 - [Shadow]: activeElement adjustment adjusts activeElement to the shadow root itself
Summary: [Shadow]: activeElement adjustment adjusts activeElement to the shadow root i...
Status: RESOLVED MOVED
Alias: None
Product: WebAppsWG
Classification: Unclassified
Component: HISTORICAL - Component Model (show other bugs)
Version: unspecified
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Dimitri Glazkov
QA Contact: public-webapps-bugzilla
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-05-17 14:13 UTC by Dominic Cooney
Modified: 2015-07-06 08:07 UTC (History)
0 users

See Also:


Attachments

Description Dominic Cooney 2012-05-17 14:13:58 UTC
Given this situation:

<div id="d">
+ {SR}
  +<input id="i">

and the input has focus, then intuitively the document.activeElement should be #d and the ShadowRoot.activeElement should be #i.

To do this adjustment, Section 8.3 says:

Run the retargeting algorithm with ELEMENT (ie #i) as input

The retargeting algorithm says:

Input
  NODE, a DOM node
Output
  TARGETS, a list of tuples, each containing NODE's ancestor and its relative target

[So NODE=#i]

Let BOUNDARY be a flag, initialized to false
[NODE=#i, BOUNDARY=false]
Let STACK be a stack of DOM nodes
[NODE=#i, BOUNDARY=false, STACK=[]]
Let ANCESTOR be NODE
[NODE=#i, ANCESTOR=#i, BOUNDARY=false,STACK=[]]
Repeat while ANCESTOR exists: {
[it exists]
  If ANCESTOR is a shadow root, set BOUNDARY to true
[ANCESTOR=#i is not a shadow root]
  If ANCESTOR is as an insertion point, push ANCESTOR into STACK
[ANCESTOR=#i is not an insertion point]
  If BOUNDARY is set to true {
[BOUNDARY=false is not set to true, so skip]
    Pop STACK if STACK is not empty
    Set BOUNDARY to false state
  If STACK is empty, push ANCESTOR into STACK
[NODE=#i, ANCESTOR=#i, BOUNDARY=false, STACK=[#i]]
  Let TARGET be the DOM node at the top of STACK
[TARGET=#i, NODE=#i, ANCESTOR=#i, BOUNDARY=false, STACK=[#i]]
  Add (TARGET, ANCESTOR) tuple to TARGETS
[TARGET=#i, NODE=#i, ANCESTOR=#i, BOUNDARY=false, STACK=[#i], TARGETS={(#i, #i)}]
  Set ANCESTOR to be the result of parent calculation algorithm, given ANCESTOR as input
[Since #i is not a shadow root, and not distributed to an insertion point, ANCESTOR=SR per the parent calculation algorithm]

The second iteration of the loop:

[TARGET=#i, NODE=#i, ANCESTOR=SR, BOUNDARY=false, STACK=[#i], TARGETS={(#i, #i)}]
If ANCESTOR is a shadow root, set BOUNDARY to true
[TARGET=#i, NODE=#i, ANCESTOR=SR, BOUNDARY=true, STACK=[#i], TARGETS={(#i, #i)}]
If ANCESTOR is as an insertion point, push ANCESTOR into STACK
[No]
If BOUNDARY is set to true {
[Yes]
  Pop STACK if STACK is not empty
[TARGET=#i, NODE=#i, ANCESTOR=SR, BOUNDARY=true, STACK=[], TARGETS={(#i, #i)}]
  Set BOUNDARY to false state
[TARGET=#i, NODE=#i, ANCESTOR=SR, BOUNDARY=false, STACK=[], TARGETS={(#i, #i)}]
}
If STACK is empty, push ANCESTOR into STACK
[TARGET=#i, NODE=#i, ANCESTOR=SR, BOUNDARY=false, STACK=[SR], TARGETS={(#i, #i)}]
Let TARGET be the DOM node at the top of STACK
[TARGET=SR, NODE=#i, ANCESTOR=SR, BOUNDARY=false, STACK=[SR], TARGETS={(#i, #i)}]
Add (TARGET, ANCESTOR) tuple to TARGETS
[TARGET=SR, NODE=#i, ANCESTOR=SR, BOUNDARY=false, STACK=[SR], TARGETS={(#i, #i), (SR, SR)}]
… (algorithm continues) …

Note that we are off the rails at this point by pushing (SR, SR) to TARGETS, because Section 8.3 continues:

For each TUPLE in the resulting list of tuples:
Let ADJUSTED be the first value of the TUPLE
Let NODE be the second value of the TUPLE
If NODE is a Document or a shadow root, set the value of the activeElement to ADJUSTED.

This means that the ShadowRoot.activeElement is set to the ShadowRoot, and hence information about the active element (ie #i) is lost. This is contrary to the goal of section 8.3, "To prevent loss of information when adjusting this value, each shadow root must also have an activeElement property to store the value of the focused element in the shadow DOM subtree."
Comment 1 Hayato Ito 2015-07-06 08:07:33 UTC
Moved to https://github.com/w3c/webcomponents/issues/251