Commit ac02a401 authored by yosin's avatar yosin Committed by Commit bot

Make GranularityStrategy::updateExtent() to return SelectionInDOM instead of VisibleSelection

This patch makes |GranularityStrategy::updateExtent()| to return
|SelectionInDOM| instead of |VisibleSelection| to reduce usage of
|VisibleSelection| for improving code health.

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

Review-Url: https://codereview.chromium.org/2735143002
Cr-Commit-Position: refs/heads/master@{#455707}
parent b0ef4258
......@@ -1091,14 +1091,14 @@ void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) {
if (computeVisibleSelectionInDOMTreeDeprecated().isNone())
return;
VisibleSelection newSelection =
granularityStrategy()->updateExtent(contentsPoint, m_frame);
setSelection(SelectionInDOMTree::Builder(newSelection.asSelection())
const SetSelectionOptions options =
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
FrameSelection::DoNotClearStrategy | UserTriggered;
setSelection(SelectionInDOMTree::Builder(
granularityStrategy()->updateExtent(contentsPoint, m_frame))
.setIsHandleVisible(true)
.build(),
FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
FrameSelection::DoNotClearStrategy | UserTriggered,
CursorAlignOnScroll::IfNeeded, CharacterGranularity);
options);
}
// TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take
......
......@@ -62,7 +62,7 @@ SelectionStrategy CharacterGranularityStrategy::GetType() const {
void CharacterGranularityStrategy::Clear() {}
VisibleSelection CharacterGranularityStrategy::updateExtent(
SelectionInDOMTree CharacterGranularityStrategy::updateExtent(
const IntPoint& extentPoint,
LocalFrame* frame) {
const VisiblePosition& extentPosition =
......@@ -71,12 +71,12 @@ VisibleSelection CharacterGranularityStrategy::updateExtent(
frame->selection().computeVisibleSelectionInDOMTreeDeprecated();
if (selection.visibleBase().deepEquivalent() ==
extentPosition.deepEquivalent())
return selection;
return createVisibleSelection(SelectionInDOMTree::Builder()
.collapse(selection.base())
.extend(extentPosition.deepEquivalent())
.setAffinity(selection.affinity())
.build());
return selection.asSelection();
return SelectionInDOMTree::Builder()
.collapse(selection.base())
.extend(extentPosition.deepEquivalent())
.setAffinity(selection.affinity())
.build();
}
DirectionGranularityStrategy::DirectionGranularityStrategy()
......@@ -97,7 +97,7 @@ void DirectionGranularityStrategy::Clear() {
m_diffExtentPointFromExtentPosition = IntSize();
}
VisibleSelection DirectionGranularityStrategy::updateExtent(
SelectionInDOMTree DirectionGranularityStrategy::updateExtent(
const IntPoint& extentPoint,
LocalFrame* frame) {
const VisibleSelection& selection =
......@@ -144,7 +144,7 @@ VisibleSelection DirectionGranularityStrategy::updateExtent(
// Do not allow empty selection.
if (newOffsetExtentPosition.deepEquivalent() == base.deepEquivalent())
return selection;
return selection.asSelection();
// The direction granularity strategy, particularly the "offset" feature
// doesn't work with non-horizontal text (e.g. when the text is rotated).
......@@ -153,12 +153,11 @@ VisibleSelection DirectionGranularityStrategy::updateExtent(
// without a line change.
if (verticalChange &&
inSameLine(newOffsetExtentPosition, oldOffsetExtentPosition)) {
return createVisibleSelection(
SelectionInDOMTree::Builder()
.collapse(selection.base())
.extend(newOffsetExtentPosition.deepEquivalent())
.setAffinity(selection.affinity())
.build());
return SelectionInDOMTree::Builder()
.collapse(selection.base())
.extend(newOffsetExtentPosition.deepEquivalent())
.setAffinity(selection.affinity())
.build();
}
int oldExtentBaseOrder = selection.isBaseFirst() ? 1 : -1;
......@@ -168,7 +167,7 @@ VisibleSelection DirectionGranularityStrategy::updateExtent(
if (newOffsetExtentPosition.deepEquivalent() ==
oldOffsetExtentPosition.deepEquivalent()) {
if (m_granularity == CharacterGranularity)
return selection;
return selection.asSelection();
// If we are in Word granularity, we cannot exit here, since we may pass
// the middle of the word without changing the position (in which case
......@@ -270,11 +269,10 @@ VisibleSelection DirectionGranularityStrategy::updateExtent(
m_diffExtentPointFromExtentPosition =
extentPoint + IntSize(m_offset, 0) - positionLocation(newSelectionExtent);
return createVisibleSelection(
SelectionInDOMTree::Builder(selection.asSelection())
.collapse(selection.base())
.extend(newSelectionExtent.deepEquivalent())
.build());
return SelectionInDOMTree::Builder(selection.asSelection())
.collapse(selection.base())
.extend(newSelectionExtent.deepEquivalent())
.build();
}
} // namespace blink
......@@ -6,7 +6,7 @@
#define GranularityStrategy_h
#include "core/editing/SelectionStrategy.h"
#include "core/editing/VisibleSelection.h"
#include "core/editing/SelectionTemplate.h"
#include "wtf/Allocator.h"
namespace blink {
......@@ -21,7 +21,7 @@ class GranularityStrategy {
// Calculates and returns the new selection based on the updated extent
// location in absolute coordinates.
virtual VisibleSelection updateExtent(const IntPoint&, LocalFrame*) = 0;
virtual SelectionInDOMTree updateExtent(const IntPoint&, LocalFrame*) = 0;
protected:
GranularityStrategy();
......@@ -36,7 +36,7 @@ class CharacterGranularityStrategy final : public GranularityStrategy {
// GranularityStrategy:
SelectionStrategy GetType() const final;
void Clear() final;
VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final;
SelectionInDOMTree updateExtent(const IntPoint&, LocalFrame*) final;
};
// "Expand by word, shrink by character" selection strategy.
......@@ -84,7 +84,7 @@ class DirectionGranularityStrategy final : public GranularityStrategy {
// GranularityStrategy:
SelectionStrategy GetType() const final;
void Clear() final;
VisibleSelection updateExtent(const IntPoint&, LocalFrame*) final;
SelectionInDOMTree updateExtent(const IntPoint&, LocalFrame*) final;
private:
enum class StrategyState {
......
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