Skip to content
  • shinyak@chromium.org's avatar
    ShadowRoot.selection should return the seleciton whose range is in a shadow tree. · 589b39fc
    shinyak@chromium.org authored
    https://bugs.webkit.org/show_bug.cgi?id=82698
    
    Reviewed by Ryosuke Niwa.
    
    Source/WebCore:
    
    The selection object returned from shadowRoot.selection should be able to see
    the inner object of the shadowRoot.
    
    In the previous code, the node out of the shadow subtree was returned for
    anchorNode, focusNode, baseNode, and extentNode. This patch enables us to get
    the corresponding shadow ancestor in the specified TreeScope (m_treeScope).
    
    Tests: editing/shadow/selection-of-orphan-shadowroot.html
           editing/shadow/selection-of-shadowroot.html
    
    * dom/ShadowRoot.cpp:
    (WebCore::ShadowRoot::selection):
    * dom/ShadowRoot.h:
    (ShadowRoot):
    * dom/TreeScope.cpp:
    (WebCore::TreeScope::getSelection): When shadow DOM feature is not enabled, we want to use the same
    instance of DOMSelection among Document and ShadowRoot.
    * dom/TreeScopeAdjuster.cpp:
    (WebCore::TreeScopeAdjuster::TreeScopeAdjuster):
    (WebCore::TreeScopeAdjuster::ancestorInThisScope): Since node could be null, I've added a node check code.
    * dom/TreeScopeAdjuster.h:
    (TreeScopeAdjuster):
    (WebCore::TreeScopeAdjuster::treeScope):
    * page/DOMSelection.cpp:
    (WebCore::DOMSelection::anchorNode):
    (WebCore::DOMSelection::anchorOffset):
    (WebCore::DOMSelection::focusNode):
    (WebCore::DOMSelection::focusOffset):
    (WebCore::DOMSelection::baseNode):
    (WebCore::DOMSelection::baseOffset):
    (WebCore::DOMSelection::extentNode):
    (WebCore::DOMSelection::extentOffset):
    (WebCore::DOMSelection::shadowAdjustedNode): Gets the corresponding node in the m_treeScope from the Position.
    (WebCore):
    (WebCore::DOMSelection::shadowAdjustedOffset): Gets the corresponding node offset in the m_treeScope from the Position.
    * page/DOMSelection.h:
    (WebCore):
    (DOMSelection):
    
    LayoutTests:
    
    This patch contains 2 tests:
    - Generates a complex HTML tree having a ShadowRoot, an older ShadowRoot, a nested ShadowRoot,
    nested ShadowRoot in an older ShadowRoot, etc., and try to drag from a nested shadow root of
    older shadow root to a nested shadow root of younger shadow root. Then checks nodes of Shadowroot.selection
    are in the same tree scope or null.
    - Generates a ShadowDOM which is not inserted into a document, and confirms nodes taken from
    the selection are all null.
    
    Also, this patch deprecates old shadowRoot.selection tests, because they test to check
    window.getSelection() and shadowRoot.selection is the same. This behavior is changed by this patch.
    
    * editing/shadow/selection-of-orphan-shadowroot-expected.txt: Added.
    * editing/shadow/selection-of-orphan-shadowroot.html: Added.
    * editing/shadow/selection-of-shadowroot-expected.txt: Added.
    * editing/shadow/selection-of-shadowroot.html: Added.
    * fast/dom/resources/event-sender-util.js:
    (mouseMoveToElem):
    (dragFromTo):
    * fast/dom/shadow/resources/shadow-dom-util.js: Added.
    (getElementByIdConsideringShadowDOM.iter):
    (getElementByIdConsideringShadowDOM):
    * fast/dom/shadow/selection-in-shadow.html: Removed.
    * platform/chromium-mac-snowleopard/fast/dom/shadow/selection-in-shadow-expected.txt: Removed.
    * platform/chromium/fast/dom/shadow/selection-in-shadow-expected.txt: Removed.
    * platform/qt/Skipped:
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117249 268f45cc-cd09-0410-ab3c-d52691b4dbfc
    589b39fc