[Bug 17090] [Shadow]: Listening to specific nodes, distributed to insertion points is hard

https://www.w3.org/Bugs/Public/show_bug.cgi?id=17090

--- Comment #5 from Hayato Ito <hayato@chromium.org> 2012-06-14 07:46:24 UTC ---
I propose the following algorithms for 6.1 and 6.2 of Shadow DOM spec. That can
achieve desired results.
I've just implemented a new algorithm which should produces an equivalent
result, using WebKit. That seemed to work well.


6.1. Event Retargeting

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

1. Let STACK be a stack of DOM nodes
2. Let ANCESTOR be NODE
3. Repeat while ANCESTOR exists:
  1. If STACK is empty, push ANCESTOR into STACK
  2. Otherwise, if ANCESTOR is an insertion point
     1. Let TARGET be the DOM node at the top of STACK
     2. push TARGET into STACK
  3. Let TARGET be the DOM node at the top of STACK     
  4. Add (TARGET, ANCESTOR) tuple to TARGETS
  5. If ANCESTOR is a shadow root
    1. Pop STACK
  6. Set ANCESTOR to be the result of parent calculation algorithm, given
ANCESTOR as input


6.2. Retargeting relatedTarget

Input
  NODE, the DOM node on which event listeners would be invoked
  RELATED, the related target for the event
Output
  ADJUSTED, the adjusted related target for NODE


1. Let TARGET be NODE
2. Let ADJUSTED be undefined
3. Repeat while TARGET exists
  1. Let ANCESTOR be RELATED
  2. Let STACK be a stack of DOM nodes
  3. Repeat while ANCESTOR exists:
    1. If STACK is empty, push ANCESTOR into STACK
    2. Otherwise, if ANCESTOR is an insertion point
       1. Let HEAD be the DOM node at the top of STACK
       2. push HEAD into STACK
    3. If a ANCESTOR and TARGET are in the same subtree:
       1. let ADJUSTED be the DOM node at the top of STACK
       2. stops
    4. If ANCESTOR is a shadow root
       1. Pop STACK
    5. Set ANCESTOR to be the result of parent calculation algorithm, given
ANCESTOR as input
  4. If TARGET is a shadow root, let TARGET be the shadow host of TARGET
  5. Otherwise, let TARGET be TARGET's parent node

-- 
Configure bugmail: https://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

Received on Thursday, 14 June 2012 07:46:32 UTC