Clean up subtrees selection code
authormihnea@adobe.com <mihnea@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 16:05:32 +0000 (16:05 +0000)
committermihnea@adobe.com <mihnea@adobe.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 28 Oct 2014 16:05:32 +0000 (16:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=137740

Reviewed by David Hyatt.

Clean up subtrees selection code. Add a new class SelectionSubtreeData
that keeps only the selection data. Have SelectionSubtreeRoot class embed
a SelectionSubtreeData member and keep the business logic methods.
No functionality changed therefore no new layout tests.

* rendering/RenderObject.cpp:
(WebCore::RenderObject::selectionStartEnd):
* rendering/RenderView.cpp:
(WebCore::RenderView::subtreeSelectionBounds):
(WebCore::RenderView::repaintSubtreeSelection):
(WebCore::RenderView::setSelection):
(WebCore::RenderView::splitSelectionBetweenSubtrees):
(WebCore::RenderView::updateSelectionForSubtrees):
(WebCore::RenderView::clearSubtreeSelection):
(WebCore::RenderView::applySubtreeSelection):
* rendering/RenderView.h:
* rendering/SelectionSubtreeRoot.cpp:
(WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot):
(WebCore::SelectionSubtreeRoot::adjustForVisibleSelection):
* rendering/SelectionSubtreeRoot.h:
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::SelectionSubtreeData):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStart):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEnd):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEndPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionClear):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartEndPositions):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStart):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStartPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEnd):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEndPos):
(WebCore::SelectionSubtreeRoot::SelectionSubtreeData::clearSelection):
(WebCore::SelectionSubtreeRoot::selectionData):
(WebCore::SelectionSubtreeRoot::setSelectionData):
(WebCore::SelectionSubtreeRoot::selectionStart): Deleted.
(WebCore::SelectionSubtreeRoot::selectionStartPos): Deleted.
(WebCore::SelectionSubtreeRoot::selectionEnd): Deleted.
(WebCore::SelectionSubtreeRoot::selectionEndPos): Deleted.
(WebCore::SelectionSubtreeRoot::selectionStartEndPositions): Deleted.
(WebCore::SelectionSubtreeRoot::selectionClear): Deleted.
(WebCore::SelectionSubtreeRoot::setSelectionStart): Deleted.
(WebCore::SelectionSubtreeRoot::setSelectionStartPos): Deleted.
(WebCore::SelectionSubtreeRoot::setSelectionEnd): Deleted.
(WebCore::SelectionSubtreeRoot::setSelectionEndPos): Deleted.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@175252 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WebCore/ChangeLog
Source/WebCore/rendering/RenderObject.cpp
Source/WebCore/rendering/RenderView.cpp
Source/WebCore/rendering/RenderView.h
Source/WebCore/rendering/SelectionSubtreeRoot.cpp
Source/WebCore/rendering/SelectionSubtreeRoot.h

index 59cd2da..5ae8b22 100644 (file)
@@ -1,3 +1,55 @@
+2014-10-28  Mihnea Ovidenie  <mihnea@adobe.com>
+
+        Clean up subtrees selection code
+        https://bugs.webkit.org/show_bug.cgi?id=137740
+
+        Reviewed by David Hyatt.
+
+        Clean up subtrees selection code. Add a new class SelectionSubtreeData
+        that keeps only the selection data. Have SelectionSubtreeRoot class embed
+        a SelectionSubtreeData member and keep the business logic methods.
+        No functionality changed therefore no new layout tests.
+
+        * rendering/RenderObject.cpp:
+        (WebCore::RenderObject::selectionStartEnd):
+        * rendering/RenderView.cpp:
+        (WebCore::RenderView::subtreeSelectionBounds):
+        (WebCore::RenderView::repaintSubtreeSelection):
+        (WebCore::RenderView::setSelection):
+        (WebCore::RenderView::splitSelectionBetweenSubtrees):
+        (WebCore::RenderView::updateSelectionForSubtrees):
+        (WebCore::RenderView::clearSubtreeSelection):
+        (WebCore::RenderView::applySubtreeSelection):
+        * rendering/RenderView.h:
+        * rendering/SelectionSubtreeRoot.cpp:
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeRoot):
+        (WebCore::SelectionSubtreeRoot::adjustForVisibleSelection):
+        * rendering/SelectionSubtreeRoot.h:
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::SelectionSubtreeData):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStart):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartPos):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEnd):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionEndPos):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionClear):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::selectionStartEndPositions):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStart):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionStartPos):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEnd):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::setSelectionEndPos):
+        (WebCore::SelectionSubtreeRoot::SelectionSubtreeData::clearSelection):
+        (WebCore::SelectionSubtreeRoot::selectionData):
+        (WebCore::SelectionSubtreeRoot::setSelectionData):
+        (WebCore::SelectionSubtreeRoot::selectionStart): Deleted.
+        (WebCore::SelectionSubtreeRoot::selectionStartPos): Deleted.
+        (WebCore::SelectionSubtreeRoot::selectionEnd): Deleted.
+        (WebCore::SelectionSubtreeRoot::selectionEndPos): Deleted.
+        (WebCore::SelectionSubtreeRoot::selectionStartEndPositions): Deleted.
+        (WebCore::SelectionSubtreeRoot::selectionClear): Deleted.
+        (WebCore::SelectionSubtreeRoot::setSelectionStart): Deleted.
+        (WebCore::SelectionSubtreeRoot::setSelectionStartPos): Deleted.
+        (WebCore::SelectionSubtreeRoot::setSelectionEnd): Deleted.
+        (WebCore::SelectionSubtreeRoot::setSelectionEndPos): Deleted.
+
 2014-10-28  Jer Noble  <jer.noble@apple.com>
 
         [Mac] The first software paint of a <video> element takes up to 2.5s.
index c295531..95c2338 100644 (file)
@@ -1632,7 +1632,7 @@ SelectionSubtreeRoot& RenderObject::selectionRoot() const
 
 void RenderObject::selectionStartEnd(int& spos, int& epos) const
 {
-    selectionRoot().selectionStartEndPositions(spos, epos);
+    selectionRoot().selectionData().selectionStartEndPositions(spos, epos);
 }
 
 FloatPoint RenderObject::localToAbsolute(const FloatPoint& localPoint, MapCoordinatesFlags mode) const
index 5160926..6bbf360 100644 (file)
@@ -759,11 +759,11 @@ LayoutRect RenderView::subtreeSelectionBounds(const SelectionSubtreeRoot& root,
     typedef HashMap<RenderObject*, std::unique_ptr<RenderSelectionInfo>> SelectionMap;
     SelectionMap selectedObjects;
 
-    RenderObject* os = root.selectionStart();
-    RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
+    RenderObject* os = root.selectionData().selectionStart();
+    RenderObject* stop = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     SelectionIterator selectionIterator(os);
     while (os && os != stop) {
-        if ((os->canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd()) && os->selectionState() != SelectionNone) {
+        if ((os->canBeSelectionLeaf() || os == root.selectionData().selectionStart() || os == root.selectionData().selectionEnd()) && os->selectionState() != SelectionNone) {
             // Blocks are responsible for painting line gaps and margin gaps. They must be examined as well.
             selectedObjects.set(os, std::make_unique<RenderSelectionInfo>(*os, clipToVisibleContent));
             RenderBlock* cb = os->containingBlock();
@@ -809,10 +809,10 @@ void RenderView::repaintSubtreeSelection(const SelectionSubtreeRoot& root) const
 {
     HashSet<RenderBlock*> processedBlocks;
 
-    RenderObject* end = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
-    SelectionIterator selectionIterator(root.selectionStart());
+    RenderObject* end = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
+    SelectionIterator selectionIterator(root.selectionData().selectionStart());
     for (RenderObject* o = selectionIterator.current(); o && o != end; o = selectionIterator.next()) {
-        if (!o->canBeSelectionLeaf() && o != root.selectionStart() && o != root.selectionEnd())
+        if (!o->canBeSelectionLeaf() && o != root.selectionData().selectionStart() && o != root.selectionData().selectionEnd())
             continue;
         if (o->selectionState() == SelectionNone)
             continue;
@@ -870,7 +870,7 @@ void RenderView::setSelection(RenderObject* start, int startPos, RenderObject* e
     // If there is no RenderNamedFlowThreads we follow the regular selection.
     if (!hasRenderNamedFlowThreads()) {
         RenderSubtreesMap singleSubtreeMap;
-        singleSubtreeMap.set(this, SelectionSubtreeRoot(start, startPos, end, endPos));
+        singleSubtreeMap.set(this, SelectionSubtreeData(start, startPos, end, endPos));
         updateSelectionForSubtrees(singleSubtreeMap, blockRepaintMode);
         return;
     }
@@ -883,7 +883,7 @@ void RenderView::splitSelectionBetweenSubtrees(const RenderObject* start, int st
     // Compute the visible selection end points for each of the subtrees.
     RenderSubtreesMap renderSubtreesMap;
 
-    SelectionSubtreeRoot initialSelection;
+    SelectionSubtreeData initialSelection;
     renderSubtreesMap.set(this, initialSelection);
     for (auto* namedFlowThread : *flowThreadController().renderNamedFlowThreadList())
         renderSubtreesMap.set(namedFlowThread, initialSelection);
@@ -899,7 +899,7 @@ void RenderView::splitSelectionBetweenSubtrees(const RenderObject* start, int st
                 continue;
 
             SelectionSubtreeRoot& root = renderer->selectionRoot();
-            SelectionSubtreeRoot selectionData = renderSubtreesMap.get(&root);
+            SelectionSubtreeData selectionData = renderSubtreesMap.get(&root);
             if (selectionData.selectionClear()) {
                 selectionData.setSelectionStart(node->renderer());
                 selectionData.setSelectionStartPos(node == startNode ? startPos : 0);
@@ -922,29 +922,24 @@ void RenderView::updateSelectionForSubtrees(RenderSubtreesMap& renderSubtreesMap
 {
     SubtreeOldSelectionDataMap oldSelectionDataMap;
     for (auto& subtreeSelectionInfo : renderSubtreesMap) {
-        SelectionSubtreeRoot& subtreeSelectionData = subtreeSelectionInfo.value;
-        if (hasRenderNamedFlowThreads())
-            subtreeSelectionData.adjustForVisibleSelection(document());
-
-        std::unique_ptr<OldSelectionData> oldSelectionData = std::make_unique<OldSelectionData>();
         SelectionSubtreeRoot& root = *subtreeSelectionInfo.key;
+        std::unique_ptr<OldSelectionData> oldSelectionData = std::make_unique<OldSelectionData>();
+
         clearSubtreeSelection(root, blockRepaintMode, *oldSelectionData);
         oldSelectionDataMap.set(&root, WTF::move(oldSelectionData));
 
-        root.setSelectionStart(subtreeSelectionData.selectionStart());
-        root.setSelectionStartPos(subtreeSelectionData.selectionStartPos());
-        root.setSelectionEnd(subtreeSelectionData.selectionEnd());
-        root.setSelectionEndPos(subtreeSelectionData.selectionEndPos());
+        root.setSelectionData(subtreeSelectionInfo.value);
+        if (hasRenderNamedFlowThreads())
+            root.adjustForVisibleSelection(document());
     }
 
     // Update selection status for the objects inside the selection subtrees.
     // This needs to be done after the previous loop updated the selectionStart/End
     // parameters of all subtrees because we're going to be climbing up the containing
     // block chain and we might end up in a different selection subtree.
-    for (auto& subtreeSelectionInfo : renderSubtreesMap) {
-        SelectionSubtreeRoot& subtreeSelectionData = subtreeSelectionInfo.value;
-        OldSelectionData& oldSelectionData = *oldSelectionDataMap.get(subtreeSelectionInfo.key);
-        applySubtreeSelection(*subtreeSelectionInfo.key, subtreeSelectionData.selectionStart(), subtreeSelectionData.selectionEnd(), subtreeSelectionData.selectionEndPos(), blockRepaintMode, oldSelectionData);
+    for (const auto* subtreeSelectionRoot : renderSubtreesMap.keys()) {
+        OldSelectionData& oldSelectionData = *oldSelectionDataMap.get(subtreeSelectionRoot);
+        applySubtreeSelection(*subtreeSelectionRoot, blockRepaintMode, oldSelectionData);
     }
 }
 
@@ -952,18 +947,18 @@ void RenderView::clearSubtreeSelection(const SelectionSubtreeRoot& root, Selecti
 {
     // Record the old selected objects.  These will be used later
     // when we compare against the new selected objects.
-    oldSelectionData.selectionStartPos = root.selectionStartPos();
-    oldSelectionData.selectionEndPos = root.selectionEndPos();
+    oldSelectionData.selectionStartPos = root.selectionData().selectionStartPos();
+    oldSelectionData.selectionEndPos = root.selectionData().selectionEndPos();
     
     // Blocks contain selected objects and fill gaps between them, either on the left, right, or in between lines and blocks.
     // In order to get the repaint rect right, we have to examine left, middle, and right rects individually, since otherwise
     // the union of those rects might remain the same even when changes have occurred.
 
-    RenderObject* os = root.selectionStart();
-    RenderObject* stop = rendererAfterPosition(root.selectionEnd(), root.selectionEndPos());
+    RenderObject* os = root.selectionData().selectionStart();
+    RenderObject* stop = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     SelectionIterator selectionIterator(os);
     while (os && os != stop) {
-        if ((os->canBeSelectionLeaf() || os == root.selectionStart() || os == root.selectionEnd())
+        if ((os->canBeSelectionLeaf() || os == root.selectionData().selectionStart() || os == root.selectionData().selectionEnd())
             && os->selectionState() != SelectionNone) {
             // Blocks are responsible for painting line gaps and margin gaps.  They must be examined as well.
             oldSelectionData.selectedObjects.set(os, std::make_unique<RenderSelectionInfo>(*os, true));
@@ -982,28 +977,28 @@ void RenderView::clearSubtreeSelection(const SelectionSubtreeRoot& root, Selecti
         os = selectionIterator.next();
     }
 
-    for (const auto& selectedObjectInfo : oldSelectionData.selectedObjects)
-        selectedObjectInfo.key->setSelectionStateIfNeeded(SelectionNone);
+    for (auto* selectedObject : oldSelectionData.selectedObjects.keys())
+        selectedObject->setSelectionStateIfNeeded(SelectionNone);
 }
 
-void RenderView::applySubtreeSelection(const SelectionSubtreeRoot& root, RenderObject* start, RenderObject* end, int endPos, SelectionRepaintMode blockRepaintMode, const OldSelectionData& oldSelectionData)
+void RenderView::applySubtreeSelection(const SelectionSubtreeRoot& root, SelectionRepaintMode blockRepaintMode, const OldSelectionData& oldSelectionData)
 {
     // Update the selection status of all objects between selectionStart and selectionEnd
-    if (start && start == end)
-        start->setSelectionStateIfNeeded(SelectionBoth);
+    if (root.selectionData().selectionStart() && root.selectionData().selectionStart() == root.selectionData().selectionEnd())
+        root.selectionData().selectionStart()->setSelectionStateIfNeeded(SelectionBoth);
     else {
-        if (start)
-            start->setSelectionStateIfNeeded(SelectionStart);
-        if (end)
-            end->setSelectionStateIfNeeded(SelectionEnd);
+        if (root.selectionData().selectionStart())
+            root.selectionData().selectionStart()->setSelectionStateIfNeeded(SelectionStart);
+        if (root.selectionData().selectionEnd())
+            root.selectionData().selectionEnd()->setSelectionStateIfNeeded(SelectionEnd);
     }
 
-    RenderObject* o = start;
-    RenderObject* stop = rendererAfterPosition(end, endPos);
+    RenderObject* o = root.selectionData().selectionStart();
+    RenderObject* stop = rendererAfterPosition(root.selectionData().selectionEnd(), root.selectionData().selectionEndPos());
     SelectionIterator selectionIterator(o);
     
     while (o && o != stop) {
-        if (o != start && o != end && o->canBeSelectionLeaf())
+        if (o != root.selectionData().selectionStart() && o != root.selectionData().selectionEnd() && o->canBeSelectionLeaf())
             o->setSelectionStateIfNeeded(SelectionInside);
         o = selectionIterator.next();
     }
@@ -1015,10 +1010,10 @@ void RenderView::applySubtreeSelection(const SelectionSubtreeRoot& root, RenderO
     // put them in the new objects list.
     SelectedObjectMap newSelectedObjects;
     SelectedBlockMap newSelectedBlocks;
-    o = start;
+    o = root.selectionData().selectionStart();
     selectionIterator = SelectionIterator(o);
     while (o && o != stop) {
-        if ((o->canBeSelectionLeaf() || o == start || o == end) && o->selectionState() != SelectionNone) {
+        if ((o->canBeSelectionLeaf() || o == root.selectionData().selectionStart() || o == root.selectionData().selectionEnd()) && o->selectionState() != SelectionNone) {
             std::unique_ptr<RenderSelectionInfo> selectionInfo = std::make_unique<RenderSelectionInfo>(*o, true);
 
 #if ENABLE(SERVICE_CONTROLS)
@@ -1056,8 +1051,8 @@ void RenderView::applySubtreeSelection(const SelectionSubtreeRoot& root, RenderO
         RenderSelectionInfo* newInfo = newSelectedObjects.get(obj);
         RenderSelectionInfo* oldInfo = selectedObjectInfo.value.get();
         if (!newInfo || oldInfo->rect() != newInfo->rect() || oldInfo->state() != newInfo->state()
-            || (root.selectionStart() == obj && oldSelectionData.selectionStartPos != root.selectionStartPos())
-            || (root.selectionEnd() == obj && oldSelectionData.selectionEndPos != root.selectionEndPos())) {
+            || (root.selectionData().selectionStart() == obj && oldSelectionData.selectionStartPos != root.selectionData().selectionStartPos())
+            || (root.selectionData().selectionEnd() == obj && oldSelectionData.selectionEndPos != root.selectionData().selectionEndPos())) {
             oldInfo->repaint();
             if (newInfo) {
                 newInfo->repaint();
@@ -1072,7 +1067,7 @@ void RenderView::applySubtreeSelection(const SelectionSubtreeRoot& root, RenderO
 
     // Have any of the old blocks changed?
     for (const auto& selectedBlockInfo : oldSelectionData.selectedBlocks) {
-        RenderBlock* block = selectedBlockInfo.key;
+        const RenderBlock* block = selectedBlockInfo.key;
         RenderBlockSelectionInfo* newInfo = newSelectedBlocks.get(block);
         RenderBlockSelectionInfo* oldInfo = selectedBlockInfo.value.get();
         if (!newInfo || oldInfo->rects() != newInfo->rects() || oldInfo->state() != newInfo->state()) {
index 296ff56..bfe9930 100644 (file)
@@ -304,7 +304,7 @@ private:
     void splitSelectionBetweenSubtrees(const RenderObject* startRenderer, int startPos, const RenderObject* endRenderer, int endPos, SelectionRepaintMode blockRepaintMode);
     void clearSubtreeSelection(const SelectionSubtreeRoot&, SelectionRepaintMode, OldSelectionData&) const;
     void updateSelectionForSubtrees(RenderSubtreesMap&, SelectionRepaintMode);
-    void applySubtreeSelection(const SelectionSubtreeRoot&, RenderObject* startRenderer, RenderObject* endRenderer, int endPos, SelectionRepaintMode, const OldSelectionData&);
+    void applySubtreeSelection(const SelectionSubtreeRoot&, SelectionRepaintMode, const OldSelectionData&);
     LayoutRect subtreeSelectionBounds(const SelectionSubtreeRoot&, bool clipToVisibleContent = true) const;
     void repaintSubtreeSelection(const SelectionSubtreeRoot&) const;
 
index fafaee6..8b6b2e6 100644 (file)
 namespace WebCore {
 
 SelectionSubtreeRoot::SelectionSubtreeRoot()
-    : m_selectionStart(nullptr)
-    , m_selectionStartPos(-1)
-    , m_selectionEnd(nullptr)
-    , m_selectionEndPos(-1)
 {
 }
 
 SelectionSubtreeRoot::SelectionSubtreeRoot(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos)
-    : m_selectionStart(selectionStart)
-    , m_selectionStartPos(selectionStartPos)
-    , m_selectionEnd(selectionEnd)
-    , m_selectionEndPos(selectionEndPos)
+    : m_selectionSubtreeData(selectionStart, selectionStartPos, selectionEnd, selectionEndPos)
 {
 }
 
 void SelectionSubtreeRoot::adjustForVisibleSelection(Document& document)
 {
-    if (selectionClear())
+    if (m_selectionSubtreeData.selectionClear())
         return;
 
     // Create a range based on the cached end points
-    Position startPosition = createLegacyEditingPosition(m_selectionStart->node(), m_selectionStartPos);
-    Position endPosition = createLegacyEditingPosition(m_selectionEnd->node(), m_selectionEndPos);
+    Position startPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionStart()->node(), m_selectionSubtreeData.selectionStartPos());
+    Position endPosition = createLegacyEditingPosition(m_selectionSubtreeData.selectionEnd()->node(), m_selectionSubtreeData.selectionEndPos());
 
     RefPtr<Range> range = Range::create(document, startPosition.parentAnchoredEquivalent(), endPosition.parentAnchoredEquivalent());
     VisibleSelection selection(range.get());
@@ -74,19 +67,16 @@ void SelectionSubtreeRoot::adjustForVisibleSelection(Document& document)
     if (candidate.isCandidate())
         endPos = candidate;
 
-    m_selectionStart = nullptr;
-    m_selectionStartPos = -1;
-    m_selectionEnd = nullptr;
-    m_selectionEndPos = -1;
+    m_selectionSubtreeData.clearSelection();
 
     if (startPos.isNotNull()
         && endPos.isNotNull()
         && selection.visibleStart() != selection.visibleEnd()
         && startPos.deprecatedNode()->renderer()->flowThreadContainingBlock() == endPos.deprecatedNode()->renderer()->flowThreadContainingBlock()) {
-        m_selectionStart = startPos.deprecatedNode()->renderer();
-        m_selectionStartPos = startPos.deprecatedEditingOffset();
-        m_selectionEnd = endPos.deprecatedNode()->renderer();
-        m_selectionEndPos = endPos.deprecatedEditingOffset();
+        m_selectionSubtreeData.setSelectionStart(startPos.deprecatedNode()->renderer());
+        m_selectionSubtreeData.setSelectionStartPos(startPos.deprecatedEditingOffset());
+        m_selectionSubtreeData.setSelectionEnd(endPos.deprecatedNode()->renderer());
+        m_selectionSubtreeData.setSelectionEndPos(endPos.deprecatedEditingOffset());
     }
 }
 
index 42c5c93..dd19197 100644 (file)
@@ -1,4 +1,4 @@
-/*
+ /*
  * Copyright (C) 2014 Igalia S.L.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -41,8 +41,7 @@ class SelectionSubtreeRoot {
 public:
     
     typedef HashMap<RenderObject*, std::unique_ptr<RenderSelectionInfo>> SelectedObjectMap;
-    typedef HashMap<RenderBlock*, std::unique_ptr<RenderBlockSelectionInfo>> SelectedBlockMap;
-    typedef HashMap<SelectionSubtreeRoot*, SelectionSubtreeRoot> RenderSubtreesMap;
+    typedef HashMap<const RenderBlock*, std::unique_ptr<RenderBlockSelectionInfo>> SelectedBlockMap;
 
     struct OldSelectionData {
         OldSelectionData()
@@ -56,44 +55,75 @@ public:
         SelectedObjectMap selectedObjects;
         SelectedBlockMap selectedBlocks;
     };
-    
-    typedef HashMap<SelectionSubtreeRoot*, std::unique_ptr<OldSelectionData>> SubtreeOldSelectionDataMap;
+
+    class SelectionSubtreeData {
+    public:
+        SelectionSubtreeData()
+            : m_selectionStart(nullptr)
+            , m_selectionStartPos(-1)
+            , m_selectionEnd(nullptr)
+            , m_selectionEndPos(-1)
+        {
+        }
+
+        SelectionSubtreeData(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos)
+            : m_selectionStart(selectionStart)
+            , m_selectionStartPos(selectionStartPos)
+            , m_selectionEnd(selectionEnd)
+            , m_selectionEndPos(selectionEndPos)
+        {
+        }
+
+        RenderObject* selectionStart() const { return m_selectionStart; }
+        int selectionStartPos() const { return m_selectionStartPos; }
+        RenderObject* selectionEnd() const { return m_selectionEnd; }
+        int selectionEndPos() const { return m_selectionEndPos; }
+        bool selectionClear() const
+        {
+            return !m_selectionStart
+            && (m_selectionStartPos == -1)
+            && !m_selectionEnd
+            && (m_selectionEndPos == -1);
+        }
+
+        void selectionStartEndPositions(int& startPos, int& endPos) const
+        {
+            startPos = m_selectionStartPos;
+            endPos = m_selectionEndPos;
+        }
+        void setSelectionStart(RenderObject* selectionStart) { m_selectionStart = selectionStart; }
+        void setSelectionStartPos(int selectionStartPos) { m_selectionStartPos = selectionStartPos; }
+        void setSelectionEnd(RenderObject* selectionEnd) { m_selectionEnd = selectionEnd; }
+        void setSelectionEndPos(int selectionEndPos) { m_selectionEndPos = selectionEndPos; }
+        void clearSelection()
+        {
+            m_selectionStart = nullptr;
+            m_selectionStartPos = -1;
+            m_selectionEnd = nullptr;
+            m_selectionEndPos = -1;
+        }
+
+    private:
+        RenderObject* m_selectionStart;
+        int m_selectionStartPos;
+        RenderObject* m_selectionEnd;
+        int m_selectionEndPos;
+    };
+
+    typedef HashMap<SelectionSubtreeRoot*, SelectionSubtreeData> RenderSubtreesMap;
+    typedef HashMap<const SelectionSubtreeRoot*, std::unique_ptr<OldSelectionData>> SubtreeOldSelectionDataMap;
 
     SelectionSubtreeRoot();
     SelectionSubtreeRoot(RenderObject* selectionStart, int selectionStartPos, RenderObject* selectionEnd, int selectionEndPos);
 
-    RenderObject* selectionStart() const { return m_selectionStart; }
-    int selectionStartPos() const { return m_selectionStartPos; }
-    RenderObject* selectionEnd() const { return m_selectionEnd; }
-    int selectionEndPos() const { return m_selectionEndPos; }
-    void selectionStartEndPositions(int& startPos, int& endPos) const
-    {
-        startPos = m_selectionStartPos;
-        endPos = m_selectionEndPos;
-    }
-
-    bool selectionClear() const
-    {
-        return !m_selectionStart
-        && (m_selectionStartPos == -1)
-        && !m_selectionEnd
-        && (m_selectionEndPos == -1);
-    }
-
-    void setSelectionStart(RenderObject* selectionStart) { m_selectionStart = selectionStart; }
-    void setSelectionStartPos(int selectionStartPos) { m_selectionStartPos = selectionStartPos; }
-    void setSelectionEnd(RenderObject* selectionEnd) { m_selectionEnd = selectionEnd; }
-    void setSelectionEndPos(int selectionEndPos) { m_selectionEndPos = selectionEndPos; }
+    SelectionSubtreeData& selectionData() { return m_selectionSubtreeData; }
+    const SelectionSubtreeData& selectionData() const { return m_selectionSubtreeData; }
 
+    void setSelectionData(const SelectionSubtreeData& selectionSubtreeData) { m_selectionSubtreeData = selectionSubtreeData; }
     void adjustForVisibleSelection(Document&);
 
 private:
-
-    RenderObject* m_selectionStart;
-    int m_selectionStartPos;
-    RenderObject* m_selectionEnd;
-    int m_selectionEndPos;
-
+    SelectionSubtreeData m_selectionSubtreeData;
 };
 
 } // namespace WebCore