From 45dc115c810ad32b051c10d3de69e4d9ece835da Mon Sep 17 00:00:00 2001 From: "shinyak@chromium.org" Date: Thu, 17 May 2012 09:30:51 +0000 Subject: [PATCH] [Refactoring] Remove TreeScopeAdjuster https://bugs.webkit.org/show_bug.cgi?id=86599 Reviewed by Hajime Morita. It seems the right place of the method of TreeScopeAdjuster are in VisibleSelection and TreeScope. So we can remove TreeScopeAdjuster. No new tests, no change in behavior. * CMakeLists.txt: * GNUmakefile.list.am: * Target.pri: * WebCore.gypi: * WebCore.vcproj/WebCore.vcproj: * WebCore.xcodeproj/project.pbxproj: * dom/DOMAllInOne.cpp: * dom/TreeScope.cpp: (WebCore::TreeScope::ancestorInThisScope): (WebCore): * dom/TreeScope.h: (TreeScope): * dom/TreeScopeAdjuster.cpp: Removed. * dom/TreeScopeAdjuster.h: Removed. * editing/VisibleSelection.cpp: (WebCore::VisibleSelection::adjustPositionBefore): (WebCore): (WebCore::VisibleSelection::adjustPositionAfter): (WebCore::VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries): * editing/VisibleSelection.h: (VisibleSelection): * page/DOMSelection.cpp: (WebCore::DOMSelection::shadowAdjustedNode): (WebCore::DOMSelection::shadowAdjustedOffset): git-svn-id: http://svn.webkit.org/repository/webkit/trunk@117420 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/WebCore/CMakeLists.txt | 1 - Source/WebCore/ChangeLog | 37 ++++++++++++ Source/WebCore/GNUmakefile.list.am | 2 - Source/WebCore/Target.pri | 2 - Source/WebCore/WebCore.gypi | 2 - Source/WebCore/WebCore.vcproj/WebCore.vcproj | 56 ------------------ Source/WebCore/WebCore.xcodeproj/project.pbxproj | 8 --- Source/WebCore/dom/DOMAllInOne.cpp | 1 - Source/WebCore/dom/TreeScope.cpp | 13 ++++ Source/WebCore/dom/TreeScope.h | 2 + Source/WebCore/dom/TreeScopeAdjuster.cpp | 75 ------------------------ Source/WebCore/dom/TreeScopeAdjuster.h | 53 ----------------- Source/WebCore/editing/VisibleSelection.cpp | 27 ++++++++- Source/WebCore/editing/VisibleSelection.h | 3 + Source/WebCore/page/DOMSelection.cpp | 5 +- 15 files changed, 81 insertions(+), 206 deletions(-) delete mode 100644 Source/WebCore/dom/TreeScopeAdjuster.cpp delete mode 100644 Source/WebCore/dom/TreeScopeAdjuster.h diff --git a/Source/WebCore/CMakeLists.txt b/Source/WebCore/CMakeLists.txt index b200757..7264bb6 100644 --- a/Source/WebCore/CMakeLists.txt +++ b/Source/WebCore/CMakeLists.txt @@ -645,7 +645,6 @@ SET(WebCore_SOURCES dom/TransformSourceLibxslt.cpp dom/Traversal.cpp dom/TreeScope.cpp - dom/TreeScopeAdjuster.cpp dom/TreeScopeAdopter.cpp dom/TreeWalker.cpp dom/UIEvent.cpp diff --git a/Source/WebCore/ChangeLog b/Source/WebCore/ChangeLog index def731f..512e253 100644 --- a/Source/WebCore/ChangeLog +++ b/Source/WebCore/ChangeLog @@ -1,3 +1,40 @@ +2012-05-17 Shinya Kawanaka + + [Refactoring] Remove TreeScopeAdjuster + https://bugs.webkit.org/show_bug.cgi?id=86599 + + Reviewed by Hajime Morita. + + It seems the right place of the method of TreeScopeAdjuster are in VisibleSelection + and TreeScope. So we can remove TreeScopeAdjuster. + + No new tests, no change in behavior. + + * CMakeLists.txt: + * GNUmakefile.list.am: + * Target.pri: + * WebCore.gypi: + * WebCore.vcproj/WebCore.vcproj: + * WebCore.xcodeproj/project.pbxproj: + * dom/DOMAllInOne.cpp: + * dom/TreeScope.cpp: + (WebCore::TreeScope::ancestorInThisScope): + (WebCore): + * dom/TreeScope.h: + (TreeScope): + * dom/TreeScopeAdjuster.cpp: Removed. + * dom/TreeScopeAdjuster.h: Removed. + * editing/VisibleSelection.cpp: + (WebCore::VisibleSelection::adjustPositionBefore): + (WebCore): + (WebCore::VisibleSelection::adjustPositionAfter): + (WebCore::VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries): + * editing/VisibleSelection.h: + (VisibleSelection): + * page/DOMSelection.cpp: + (WebCore::DOMSelection::shadowAdjustedNode): + (WebCore::DOMSelection::shadowAdjustedOffset): + 2012-05-17 Zoltan Herczeg NEON intrinsic should be used with arithmetic mode of composite filter diff --git a/Source/WebCore/GNUmakefile.list.am b/Source/WebCore/GNUmakefile.list.am index 60b4c8e..68a99a3 100644 --- a/Source/WebCore/GNUmakefile.list.am +++ b/Source/WebCore/GNUmakefile.list.am @@ -1989,8 +1989,6 @@ webcore_sources += \ Source/WebCore/dom/TreeDepthLimit.h \ Source/WebCore/dom/TreeScope.cpp \ Source/WebCore/dom/TreeScope.h \ - Source/WebCore/dom/TreeScopeAdjuster.cpp \ - Source/WebCore/dom/TreeScopeAdjuster.h \ Source/WebCore/dom/TreeScopeAdopter.cpp \ Source/WebCore/dom/TreeScopeAdopter.h \ Source/WebCore/dom/TreeWalker.cpp \ diff --git a/Source/WebCore/Target.pri b/Source/WebCore/Target.pri index cf32210..c278b6b 100644 --- a/Source/WebCore/Target.pri +++ b/Source/WebCore/Target.pri @@ -620,7 +620,6 @@ SOURCES += \ dom/TouchList.cpp \ dom/Traversal.cpp \ dom/TreeScope.cpp \ - dom/TreeScopeAdjuster.cpp \ dom/TreeScopeAdopter.cpp \ dom/TreeWalker.cpp \ dom/UIEvent.cpp \ @@ -1775,7 +1774,6 @@ HEADERS += \ dom/Traversal.h \ dom/TreeDepthLimit.h \ dom/TreeScope.h \ - dom/TreeScopeAdjuster.h \ dom/TreeScopeAdopter.h \ dom/TreeWalker.h \ dom/UIEvent.h \ diff --git a/Source/WebCore/WebCore.gypi b/Source/WebCore/WebCore.gypi index 9974efc..1b70d0b 100644 --- a/Source/WebCore/WebCore.gypi +++ b/Source/WebCore/WebCore.gypi @@ -5397,8 +5397,6 @@ 'dom/TreeDepthLimit.h', 'dom/TreeScope.cpp', 'dom/TreeScope.h', - 'dom/TreeScopeAdjuster.cpp', - 'dom/TreeScopeAdjuster.h', 'dom/TreeScopeAdopter.cpp', 'dom/TreeScopeAdopter.h', 'dom/TreeWalker.cpp', diff --git a/Source/WebCore/WebCore.vcproj/WebCore.vcproj b/Source/WebCore/WebCore.vcproj/WebCore.vcproj index 0fe7b98..213d93b 100755 --- a/Source/WebCore/WebCore.vcproj/WebCore.vcproj +++ b/Source/WebCore/WebCore.vcproj/WebCore.vcproj @@ -53486,62 +53486,6 @@ > - - - - - - - - - - - - - - - - - - - - - - treeScope() == this) + return node; + if (!node->isInShadowTree()) + return 0; + node = node->shadowAncestorNode(); + } + + return 0; +} + void TreeScope::addImageMap(HTMLMapElement* imageMap) { AtomicStringImpl* name = imageMap->getName().impl(); diff --git a/Source/WebCore/dom/TreeScope.h b/Source/WebCore/dom/TreeScope.h index 9920932..e4c4ef3 100644 --- a/Source/WebCore/dom/TreeScope.h +++ b/Source/WebCore/dom/TreeScope.h @@ -55,6 +55,8 @@ public: void addElementById(const AtomicString& elementId, Element*); void removeElementById(const AtomicString& elementId, Element*); + Node* ancestorInThisScope(Node*) const; + void addImageMap(HTMLMapElement*); void removeImageMap(HTMLMapElement*); HTMLMapElement* getImageMap(const String& url) const; diff --git a/Source/WebCore/dom/TreeScopeAdjuster.cpp b/Source/WebCore/dom/TreeScopeAdjuster.cpp deleted file mode 100644 index 1711fdd..0000000 --- a/Source/WebCore/dom/TreeScopeAdjuster.cpp +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2012 Google Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include "config.h" -#include "TreeScopeAdjuster.h" - -#include "Node.h" -#include "TreeScope.h" - -namespace WebCore { - -TreeScopeAdjuster::TreeScopeAdjuster(const TreeScope* treeScope) - : m_treeScope(treeScope) -{ -} - -Node* TreeScopeAdjuster::ancestorInThisScope(Node* node) -{ - while (node) { - if (node->treeScope() == treeScope()) - return node; - if (!node->isInShadowTree()) - return 0; - node = node->shadowAncestorNode(); - } - - return 0; -} - -Position TreeScopeAdjuster::adjustPositionBefore(const Position& currentPosition) -{ - if (Node* ancestor = ancestorInThisScope(currentPosition.anchorNode())) - return positionBeforeNode(ancestor); - - if (Node* lastChild = treeScope()->rootNode()->lastChild()) - return positionAfterNode(lastChild); - - return Position(); -} - -Position TreeScopeAdjuster::adjustPositionAfter(const Position& currentPosition) -{ - if (Node* ancestor = ancestorInThisScope(currentPosition.anchorNode())) - return positionAfterNode(ancestor); - - if (Node* firstChild = treeScope()->rootNode()->firstChild()) - return positionBeforeNode(firstChild); - - return Position(); -} - -} // namespace WebCore - diff --git a/Source/WebCore/dom/TreeScopeAdjuster.h b/Source/WebCore/dom/TreeScopeAdjuster.h deleted file mode 100644 index c7689514..0000000 --- a/Source/WebCore/dom/TreeScopeAdjuster.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2012 Google Inc. All Rights Reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY - * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef TreeScopeAdjuster_h -#define TreeScopeAdjuster_h - -#include "Position.h" - -namespace WebCore { - -class Node; -class TreeScope; - -class TreeScopeAdjuster { -public: - explicit TreeScopeAdjuster(const TreeScope*); - - inline const TreeScope* treeScope() const { return m_treeScope; } - - Node* ancestorInThisScope(Node*); - - Position adjustPositionBefore(const Position&); - Position adjustPositionAfter(const Position&); - -private: - const TreeScope* m_treeScope; -}; - -} // namespace WebCore - -#endif // TreeScopeAdjuster_h diff --git a/Source/WebCore/editing/VisibleSelection.cpp b/Source/WebCore/editing/VisibleSelection.cpp index 09bef90..6e68c35 100644 --- a/Source/WebCore/editing/VisibleSelection.cpp +++ b/Source/WebCore/editing/VisibleSelection.cpp @@ -30,7 +30,6 @@ #include "Element.h" #include "htmlediting.h" #include "TextIterator.h" -#include "TreeScopeAdjuster.h" #include "VisiblePosition.h" #include "visible_units.h" #include "Range.h" @@ -411,6 +410,28 @@ void VisibleSelection::updateSelectionType() m_affinity = DOWNSTREAM; } +Position VisibleSelection::adjustPositionBefore(TreeScope* treeScope, const Position& currentPosition) +{ + if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.anchorNode())) + return positionBeforeNode(ancestor); + + if (Node* lastChild = treeScope->rootNode()->lastChild()) + return positionAfterNode(lastChild); + + return Position(); +} + +Position VisibleSelection::adjustPositionAfter(TreeScope* treeScope, const Position& currentPosition) +{ + if (Node* ancestor = treeScope->ancestorInThisScope(currentPosition.anchorNode())) + return positionAfterNode(ancestor); + + if (Node* firstChild = treeScope->rootNode()->firstChild()) + return positionBeforeNode(firstChild); + + return Position(); +} + void VisibleSelection::validate(TextGranularity granularity) { setBaseAndExtentToDeepEquivalents(); @@ -466,10 +487,10 @@ void VisibleSelection::adjustSelectionToAvoidCrossingShadowBoundaries() return; if (m_baseIsFirst) { - m_extent = TreeScopeAdjuster(m_start.anchorNode()->treeScope()).adjustPositionBefore(m_end); + m_extent = adjustPositionBefore(m_start.anchorNode()->treeScope(), m_end); m_end = m_extent; } else { - m_extent = TreeScopeAdjuster(m_end.anchorNode()->treeScope()).adjustPositionAfter(m_start); + m_extent = adjustPositionAfter(m_end.anchorNode()->treeScope(), m_start); m_start = m_extent; } diff --git a/Source/WebCore/editing/VisibleSelection.h b/Source/WebCore/editing/VisibleSelection.h index 8c810da..21999bb 100644 --- a/Source/WebCore/editing/VisibleSelection.h +++ b/Source/WebCore/editing/VisibleSelection.h @@ -122,6 +122,9 @@ private: void adjustSelectionToAvoidCrossingEditingBoundaries(); void updateSelectionType(); + Position adjustPositionBefore(TreeScope*, const Position&); + Position adjustPositionAfter(TreeScope*, const Position&); + // We need to store these as Positions because VisibleSelection is // used to store values in editing commands for use when // undoing the command. We need to be able to create a selection that, while currently diff --git a/Source/WebCore/page/DOMSelection.cpp b/Source/WebCore/page/DOMSelection.cpp index 8358dce..59f266f 100644 --- a/Source/WebCore/page/DOMSelection.cpp +++ b/Source/WebCore/page/DOMSelection.cpp @@ -40,7 +40,6 @@ #include "Range.h" #include "TextIterator.h" #include "TreeScope.h" -#include "TreeScopeAdjuster.h" #include "htmlediting.h" namespace WebCore { @@ -506,7 +505,7 @@ Node* DOMSelection::shadowAdjustedNode(const Position& position) const return 0; Node* containerNode = position.containerNode(); - Node* adjustedNode = TreeScopeAdjuster(m_treeScope).ancestorInThisScope(containerNode); + Node* adjustedNode = m_treeScope->ancestorInThisScope(containerNode); if (!adjustedNode) return 0; @@ -523,7 +522,7 @@ int DOMSelection::shadowAdjustedOffset(const Position& position) const return 0; Node* containerNode = position.containerNode(); - Node* adjustedNode = TreeScopeAdjuster(m_treeScope).ancestorInThisScope(containerNode); + Node* adjustedNode = m_treeScope->ancestorInThisScope(containerNode); if (!adjustedNode) return 0; -- 2.7.4