Commit 82db1ff7 authored by yosin's avatar yosin Committed by Commit bot

Move setNonDirectionalSelectionIfNeeded() to SelectionController from FrameSelection

This patch moves |setNonDirectionalSelectionIfNeeded()| to |SelectionController|
from |FrameSelection| since it is used only in |SelectionController| to simplify
|FrameSelection| for improving code health.

This patch also gets rid of |originalBase()| which had been used in
|setNonDirectionalSelectionIfNeeded()|, but it has never been used.

BUG=n/a
TEST=n/a; no behavior changes

Review-Url: https://codereview.chromium.org/2441573002
Cr-Commit-Position: refs/heads/master@{#427032}
parent 91be04c4
...@@ -120,6 +120,7 @@ ...@@ -120,6 +120,7 @@
#include "core/editing/Editor.h" #include "core/editing/Editor.h"
#include "core/editing/FrameSelection.h" #include "core/editing/FrameSelection.h"
#include "core/editing/InputMethodController.h" #include "core/editing/InputMethodController.h"
#include "core/editing/SelectionController.h"
#include "core/editing/markers/DocumentMarkerController.h" #include "core/editing/markers/DocumentMarkerController.h"
#include "core/editing/serializers/Serialization.h" #include "core/editing/serializers/Serialization.h"
#include "core/editing/spellcheck/SpellChecker.h" #include "core/editing/spellcheck/SpellChecker.h"
...@@ -2354,6 +2355,7 @@ void Document::shutdown() { ...@@ -2354,6 +2355,7 @@ void Document::shutdown() {
frameHost()->eventHandlerRegistry().documentDetached(*this); frameHost()->eventHandlerRegistry().documentDetached(*this);
m_frame->selection().documentDetached(*this); m_frame->selection().documentDetached(*this);
m_frame->eventHandler().selectionController().documentDetached();
m_frame->inputMethodController().documentDetached(); m_frame->inputMethodController().documentDetached();
// If this Document is associated with a live DocumentLoader, the // If this Document is associated with a live DocumentLoader, the
......
...@@ -223,7 +223,9 @@ static void adjustEndpointsAtBidiBoundary( ...@@ -223,7 +223,9 @@ static void adjustEndpointsAtBidiBoundary(
} }
} }
void FrameSelection::setNonDirectionalSelectionIfNeeded( // TODO(yosin): We should move |setNonDirectionalSelectionIfNeeded()| to
// "SelectionController.cpp"
void SelectionController::setNonDirectionalSelectionIfNeeded(
const VisibleSelectionInFlatTree& passedNewSelection, const VisibleSelectionInFlatTree& passedNewSelection,
TextGranularity granularity, TextGranularity granularity,
EndPointsAdjustmentMode endpointsAdjustmentMode) { EndPointsAdjustmentMode endpointsAdjustmentMode) {
...@@ -256,7 +258,7 @@ void FrameSelection::setNonDirectionalSelectionIfNeeded( ...@@ -256,7 +258,7 @@ void FrameSelection::setNonDirectionalSelectionIfNeeded(
newSelection.setBase(newBase); newSelection.setBase(newBase);
newSelection.setExtent(newExtent); newSelection.setExtent(newExtent);
} else if (originalBase.isNotNull()) { } else if (originalBase.isNotNull()) {
if (visibleSelection<EditingInFlatTreeStrategy>().base() == if (selection().visibleSelection<EditingInFlatTreeStrategy>().base() ==
newSelection.base()) newSelection.base())
newSelection.setBase(originalBase); newSelection.setBase(originalBase);
m_originalBaseInFlatTree = VisiblePositionInFlatTree(); m_originalBaseInFlatTree = VisiblePositionInFlatTree();
...@@ -264,11 +266,12 @@ void FrameSelection::setNonDirectionalSelectionIfNeeded( ...@@ -264,11 +266,12 @@ void FrameSelection::setNonDirectionalSelectionIfNeeded(
// Adjusting base and extent will make newSelection always directional // Adjusting base and extent will make newSelection always directional
newSelection.setIsDirectional(isDirectional); newSelection.setIsDirectional(isDirectional);
if (visibleSelection<EditingInFlatTreeStrategy>() == newSelection) if (selection().visibleSelection<EditingInFlatTreeStrategy>() == newSelection)
return; return;
const SetSelectionOptions options = CloseTyping | ClearTypingStyle; const FrameSelection::SetSelectionOptions options =
setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle;
selection().setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded,
granularity); granularity);
} }
...@@ -813,7 +816,6 @@ void FrameSelection::documentAttached(Document* document) { ...@@ -813,7 +816,6 @@ void FrameSelection::documentAttached(Document* document) {
void FrameSelection::documentDetached(const Document& document) { void FrameSelection::documentDetached(const Document& document) {
DCHECK_EQ(m_document, document); DCHECK_EQ(m_document, document);
m_document = nullptr; m_document = nullptr;
m_originalBaseInFlatTree = VisiblePositionInFlatTree();
m_granularity = CharacterGranularity; m_granularity = CharacterGranularity;
LayoutViewItem view = m_frame->contentLayoutItem(); LayoutViewItem view = m_frame->contentLayoutItem();
...@@ -823,6 +825,7 @@ void FrameSelection::documentDetached(const Document& document) { ...@@ -823,6 +825,7 @@ void FrameSelection::documentDetached(const Document& document) {
clearTypingStyle(); clearTypingStyle();
m_selectionEditor->documentDetached(document); m_selectionEditor->documentDetached(document);
m_frameCaret->documentDetached(); m_frameCaret->documentDetached();
m_frame->eventHandler().selectionController().documentDetached();
} }
LayoutBlock* FrameSelection::caretLayoutObject() const { LayoutBlock* FrameSelection::caretLayoutObject() const {
...@@ -1373,7 +1376,6 @@ DEFINE_TRACE(FrameSelection) { ...@@ -1373,7 +1376,6 @@ DEFINE_TRACE(FrameSelection) {
visitor->trace(m_frame); visitor->trace(m_frame);
visitor->trace(m_pendingSelection); visitor->trace(m_pendingSelection);
visitor->trace(m_selectionEditor); visitor->trace(m_selectionEditor);
visitor->trace(m_originalBaseInFlatTree);
visitor->trace(m_typingStyle); visitor->trace(m_typingStyle);
visitor->trace(m_frameCaret); visitor->trace(m_frameCaret);
} }
......
...@@ -249,14 +249,6 @@ class CORE_EXPORT FrameSelection final ...@@ -249,14 +249,6 @@ class CORE_EXPORT FrameSelection final
void showTreeForThis() const; void showTreeForThis() const;
#endif #endif
enum EndPointsAdjustmentMode {
AdjustEndpointsAtBidiBoundary,
DoNotAdjustEndpoints
};
void setNonDirectionalSelectionIfNeeded(
const VisibleSelectionInFlatTree&,
TextGranularity,
EndPointsAdjustmentMode = DoNotAdjustEndpoints);
void setFocusedNodeIfNeeded(); void setFocusedNodeIfNeeded();
void notifyLayoutObjectOfSelectionChange(EUserTriggered); void notifyLayoutObjectOfSelectionChange(EUserTriggered);
...@@ -295,6 +287,7 @@ class CORE_EXPORT FrameSelection final ...@@ -295,6 +287,7 @@ class CORE_EXPORT FrameSelection final
private: private:
friend class FrameSelectionTest; friend class FrameSelectionTest;
friend class PaintControllerPaintTestForSlimmingPaintV1AndV2; friend class PaintControllerPaintTestForSlimmingPaintV1AndV2;
friend class SelectionControllerTest;
FRIEND_TEST_ALL_PREFIXES(PaintControllerPaintTestForSlimmingPaintV1AndV2, FRIEND_TEST_ALL_PREFIXES(PaintControllerPaintTestForSlimmingPaintV1AndV2,
FullDocumentPaintingWithCaret); FullDocumentPaintingWithCaret);
...@@ -304,11 +297,6 @@ class CORE_EXPORT FrameSelection final ...@@ -304,11 +297,6 @@ class CORE_EXPORT FrameSelection final
// use |visibleSelection<EditingInFlatTreeStrategy>()|. // use |visibleSelection<EditingInFlatTreeStrategy>()|.
const VisibleSelectionInFlatTree& selectionInFlatTree() const; const VisibleSelectionInFlatTree& selectionInFlatTree() const;
template <typename Strategy>
VisiblePositionTemplate<Strategy> originalBase() const;
void setOriginalBase(const VisiblePosition&);
void setOriginalBase(const VisiblePositionInFlatTree&);
template <typename Strategy> template <typename Strategy>
void setSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>&, void setSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>&,
SetSelectionOptions, SetSelectionOptions,
...@@ -345,8 +333,6 @@ class CORE_EXPORT FrameSelection final ...@@ -345,8 +333,6 @@ class CORE_EXPORT FrameSelection final
const Member<PendingSelection> m_pendingSelection; const Member<PendingSelection> m_pendingSelection;
const Member<SelectionEditor> m_selectionEditor; const Member<SelectionEditor> m_selectionEditor;
// Used to store base before the adjustment at bidi boundary
VisiblePositionInFlatTree m_originalBaseInFlatTree;
TextGranularity m_granularity; TextGranularity m_granularity;
LayoutUnit m_xPosForVerticalArrowNavigation; LayoutUnit m_xPosForVerticalArrowNavigation;
......
...@@ -10,8 +10,10 @@ ...@@ -10,8 +10,10 @@
#include "core/dom/Text.h" #include "core/dom/Text.h"
#include "core/editing/EditingTestBase.h" #include "core/editing/EditingTestBase.h"
#include "core/editing/FrameCaret.h" #include "core/editing/FrameCaret.h"
#include "core/editing/SelectionController.h"
#include "core/frame/FrameView.h" #include "core/frame/FrameView.h"
#include "core/html/HTMLBodyElement.h" #include "core/html/HTMLBodyElement.h"
#include "core/input/EventHandler.h"
#include "core/layout/LayoutView.h" #include "core/layout/LayoutView.h"
#include "core/paint/PaintInfo.h" #include "core/paint/PaintInfo.h"
#include "core/paint/PaintLayer.h" #include "core/paint/PaintLayer.h"
...@@ -273,7 +275,40 @@ TEST_F(FrameSelectionTest, MoveRangeSelectionTest) { ...@@ -273,7 +275,40 @@ TEST_F(FrameSelectionTest, MoveRangeSelectionTest) {
EXPECT_EQ_SELECTED_TEXT("Foo Bar"); EXPECT_EQ_SELECTED_TEXT("Foo Bar");
} }
TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) { // TODO(yosin): We should move |SelectionControllerTest" to
// "SelectionControllerTest.cpp"
class SelectionControllerTest : public EditingTestBase {
protected:
SelectionControllerTest() = default;
const VisibleSelection& visibleSelectionInDOMTree() const {
return selection().selection();
}
const VisibleSelectionInFlatTree& visibleSelectionInFlatTree() const {
return selection().selectionInFlatTree();
}
void setNonDirectionalSelectionIfNeeded(const VisibleSelectionInFlatTree&,
TextGranularity);
private:
DISALLOW_COPY_AND_ASSIGN(SelectionControllerTest);
};
// TODO(yosin): We should move this function to "SelectionControllerTest.cpp"
void SelectionControllerTest::setNonDirectionalSelectionIfNeeded(
const VisibleSelectionInFlatTree& newSelection,
TextGranularity granularity) {
frame()
.eventHandler()
.selectionController()
.setNonDirectionalSelectionIfNeeded(
newSelection, granularity, SelectionController::DoNotAdjustEndpoints);
}
// TODO(yosin): We should move this test to "SelectionControllerTest.cpp"
TEST_F(SelectionControllerTest, setNonDirectionalSelectionIfNeeded) {
const char* bodyContent = "<span id=top>top</span><span id=host></span>"; const char* bodyContent = "<span id=top>top</span><span id=host></span>";
const char* shadowContent = "<span id=bottom>bottom</span>"; const char* shadowContent = "<span id=bottom>bottom</span>";
setBodyContent(bodyContent); setBodyContent(bodyContent);
...@@ -284,7 +319,7 @@ TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) { ...@@ -284,7 +319,7 @@ TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) {
Node* host = document().getElementById("host"); Node* host = document().getElementById("host");
// top to bottom // top to bottom
selection().setNonDirectionalSelectionIfNeeded( setNonDirectionalSelectionIfNeeded(
createVisibleSelection(SelectionInFlatTree::Builder() createVisibleSelection(SelectionInFlatTree::Builder()
.collapse(PositionInFlatTree(top, 1)) .collapse(PositionInFlatTree(top, 1))
.extend(PositionInFlatTree(bottom, 3)) .extend(PositionInFlatTree(bottom, 3))
...@@ -302,7 +337,7 @@ TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) { ...@@ -302,7 +337,7 @@ TEST_F(FrameSelectionTest, setNonDirectionalSelectionIfNeeded) {
EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end()); EXPECT_EQ(PositionInFlatTree(bottom, 3), visibleSelectionInFlatTree().end());
// bottom to top // bottom to top
selection().setNonDirectionalSelectionIfNeeded( setNonDirectionalSelectionIfNeeded(
createVisibleSelection(SelectionInFlatTree::Builder() createVisibleSelection(SelectionInFlatTree::Builder()
.collapse(PositionInFlatTree(bottom, 3)) .collapse(PositionInFlatTree(bottom, 3))
.extend(PositionInFlatTree(top, 1)) .extend(PositionInFlatTree(top, 1))
......
...@@ -61,6 +61,7 @@ SelectionController::SelectionController(LocalFrame& frame) ...@@ -61,6 +61,7 @@ SelectionController::SelectionController(LocalFrame& frame)
DEFINE_TRACE(SelectionController) { DEFINE_TRACE(SelectionController) {
visitor->trace(m_frame); visitor->trace(m_frame);
visitor->trace(m_originalBaseInFlatTree);
} }
namespace { namespace {
...@@ -123,6 +124,15 @@ VisiblePositionInFlatTree visiblePositionOfHitTestResult( ...@@ -123,6 +124,15 @@ VisiblePositionInFlatTree visiblePositionOfHitTestResult(
} // namespace } // namespace
Document& SelectionController::document() const {
DCHECK(m_frame->document());
return *m_frame->document();
}
void SelectionController::documentDetached() {
m_originalBaseInFlatTree = VisiblePositionInFlatTree();
}
bool SelectionController::handleMousePressEventSingleClick( bool SelectionController::handleMousePressEventSingleClick(
const MouseEventWithHitTestResults& event) { const MouseEventWithHitTestResults& event) {
TRACE_EVENT0("blink", TRACE_EVENT0("blink",
...@@ -332,9 +342,8 @@ void SelectionController::updateSelectionForMouseDrag( ...@@ -332,9 +342,8 @@ void SelectionController::updateSelectionForMouseDrag(
if (selection().granularity() != CharacterGranularity) if (selection().granularity() != CharacterGranularity)
newSelection.expandUsingGranularity(selection().granularity()); newSelection.expandUsingGranularity(selection().granularity());
selection().setNonDirectionalSelectionIfNeeded( setNonDirectionalSelectionIfNeeded(newSelection, selection().granularity(),
newSelection, selection().granularity(), AdjustEndpointsAtBidiBoundary);
FrameSelection::AdjustEndpointsAtBidiBoundary);
} }
bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
...@@ -362,7 +371,8 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart( ...@@ -362,7 +371,8 @@ bool SelectionController::updateSelectionForMouseDownDispatchingSelectStart(
m_selectionState = SelectionState::PlacedCaret; m_selectionState = SelectionState::PlacedCaret;
} }
this->selection().setNonDirectionalSelectionIfNeeded(selection, granularity); setNonDirectionalSelectionIfNeeded(selection, granularity,
DoNotAdjustEndpoints);
return true; return true;
} }
......
...@@ -39,13 +39,15 @@ class FrameSelection; ...@@ -39,13 +39,15 @@ class FrameSelection;
class HitTestResult; class HitTestResult;
class LocalFrame; class LocalFrame;
class SelectionController final : public GarbageCollected<SelectionController> { class CORE_EXPORT SelectionController final
: public GarbageCollectedFinalized<SelectionController> {
WTF_MAKE_NONCOPYABLE(SelectionController); WTF_MAKE_NONCOPYABLE(SelectionController);
public: public:
static SelectionController* create(LocalFrame&); static SelectionController* create(LocalFrame&);
DECLARE_TRACE(); DECLARE_TRACE();
void documentDetached();
void handleMousePressEvent(const MouseEventWithHitTestResults&); void handleMousePressEvent(const MouseEventWithHitTestResults&);
bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&); bool handleMousePressEventSingleClick(const MouseEventWithHitTestResults&);
bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&); bool handleMousePressEventDoubleClick(const MouseEventWithHitTestResults&);
...@@ -80,10 +82,18 @@ class SelectionController final : public GarbageCollected<SelectionController> { ...@@ -80,10 +82,18 @@ class SelectionController final : public GarbageCollected<SelectionController> {
} }
private: private:
friend class SelectionControllerTest;
explicit SelectionController(LocalFrame&); explicit SelectionController(LocalFrame&);
enum class AppendTrailingWhitespace { ShouldAppend, DontAppend }; enum class AppendTrailingWhitespace { ShouldAppend, DontAppend };
enum class SelectInputEventType { Touch, Mouse }; enum class SelectInputEventType { Touch, Mouse };
enum EndPointsAdjustmentMode {
AdjustEndpointsAtBidiBoundary,
DoNotAdjustEndpoints
};
Document& document() const;
void selectClosestWordFromHitTestResult(const HitTestResult&, void selectClosestWordFromHitTestResult(const HitTestResult&,
AppendTrailingWhitespace, AppendTrailingWhitespace,
...@@ -95,6 +105,9 @@ class SelectionController final : public GarbageCollected<SelectionController> { ...@@ -95,6 +105,9 @@ class SelectionController final : public GarbageCollected<SelectionController> {
const MouseEventWithHitTestResults&); const MouseEventWithHitTestResults&);
void selectClosestWordOrLinkFromMouseEvent( void selectClosestWordOrLinkFromMouseEvent(
const MouseEventWithHitTestResults&); const MouseEventWithHitTestResults&);
void setNonDirectionalSelectionIfNeeded(const VisibleSelectionInFlatTree&,
TextGranularity,
EndPointsAdjustmentMode);
bool updateSelectionForMouseDownDispatchingSelectStart( bool updateSelectionForMouseDownDispatchingSelectStart(
Node*, Node*,
const VisibleSelectionInFlatTree&, const VisibleSelectionInFlatTree&,
...@@ -103,6 +116,10 @@ class SelectionController final : public GarbageCollected<SelectionController> { ...@@ -103,6 +116,10 @@ class SelectionController final : public GarbageCollected<SelectionController> {
FrameSelection& selection() const; FrameSelection& selection() const;
Member<LocalFrame> const m_frame; Member<LocalFrame> const m_frame;
// TODO(yosin): We should use |PositionWIthAffinityInFlatTree| since we
// should reduce usage of |VisibleSelectionInFlatTree|.
// Used to store base before the adjustment at bidi boundary
VisiblePositionInFlatTree m_originalBaseInFlatTree;
bool m_mouseDownMayStartSelect; bool m_mouseDownMayStartSelect;
bool m_mouseDownWasSingleClickInSelection; bool m_mouseDownWasSingleClickInSelection;
bool m_mouseDownAllowsMultiClick; bool m_mouseDownAllowsMultiClick;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment