Commit ccd93bb9 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Get rid of redundant member variable VisibleSelectionTemplate::selection_type_

This patch gets rid of redundant member variable |selection_type_| from
|VisibleSelectionTemplate| to simplify |VisibleSelectionTemplate| for improving
code health.

Bug: 657237
Change-Id: I9a45a73d719bc9aa6300fd59b982ec820dd1c0ea
Reviewed-on: https://chromium-review.googlesource.com/579896Reviewed-by: default avatarXiaocheng Hu <xiaochengh@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491265}
parent 3993a5c4
......@@ -43,7 +43,6 @@ namespace blink {
template <typename Strategy>
VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate()
: affinity_(TextAffinity::kDownstream),
selection_type_(kNoSelection),
base_is_first_(true),
is_directional_(false) {}
......@@ -52,7 +51,6 @@ VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(
const SelectionTemplate<Strategy>& selection,
TextGranularity granularity)
: affinity_(selection.Affinity()),
selection_type_(kNoSelection),
is_directional_(selection.IsDirectional()) {
Validate(selection, granularity);
}
......@@ -115,7 +113,6 @@ VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(
: base_(other.base_),
extent_(other.extent_),
affinity_(other.affinity_),
selection_type_(other.selection_type_),
base_is_first_(other.base_is_first_),
is_directional_(other.is_directional_) {}
......@@ -125,7 +122,6 @@ operator=(const VisibleSelectionTemplate<Strategy>& other) {
base_ = other.base_;
extent_ = other.extent_;
affinity_ = other.affinity_;
selection_type_ = other.selection_type_;
base_is_first_ = other.base_is_first_;
is_directional_ = other.is_directional_;
return *this;
......@@ -146,6 +142,21 @@ SelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::AsSelection()
.Build();
}
template <typename Strategy>
bool VisibleSelectionTemplate<Strategy>::IsCaret() const {
return base_.IsNotNull() && base_ == extent_;
}
template <typename Strategy>
bool VisibleSelectionTemplate<Strategy>::IsNone() const {
return base_.IsNull();
}
template <typename Strategy>
bool VisibleSelectionTemplate<Strategy>::IsRange() const {
return base_ != extent_;
}
template <typename Strategy>
PositionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::Start() const {
return base_is_first_ ? base_ : extent_;
......@@ -474,7 +485,6 @@ void VisibleSelectionTemplate<Strategy>::Validate(
if (canonicalized_selection.IsNone()) {
base_ = extent_ = PositionTemplate<Strategy>();
base_is_first_ = true;
selection_type_ = kNoSelection;
affinity_ = TextAffinity::kDownstream;
return;
}
......@@ -517,8 +527,9 @@ void VisibleSelectionTemplate<Strategy>::Validate(
const EphemeralRangeTemplate<Strategy> editing_adjusted_range =
AdjustSelectionToAvoidCrossingEditingBoundaries(shadow_adjusted_range,
base_);
selection_type_ = ComputeSelectionType(editing_adjusted_range.StartPosition(),
editing_adjusted_range.EndPosition());
const SelectionType selection_type =
ComputeSelectionType(editing_adjusted_range.StartPosition(),
editing_adjusted_range.EndPosition());
// "Constrain" the selection to be the smallest equivalent range of
// nodes. This is a somewhat arbitrary choice, but experience shows that
......@@ -530,13 +541,13 @@ void VisibleSelectionTemplate<Strategy>::Validate(
// (when we set these two positions to |VisiblePosition|
// |DeepEquivalent()|s above)?
const EphemeralRangeTemplate<Strategy> range =
selection_type_ == kRangeSelection
selection_type == kRangeSelection
? EphemeralRangeTemplate<Strategy>(
MostForwardCaretPosition(
editing_adjusted_range.StartPosition()),
MostBackwardCaretPosition(editing_adjusted_range.EndPosition()))
: editing_adjusted_range;
if (selection_type_ == kCaretSelection) {
if (selection_type == kCaretSelection) {
base_ = extent_ = range.StartPosition();
base_is_first_ = true;
return;
......@@ -578,14 +589,12 @@ VisibleSelectionTemplate<Strategy>::CreateWithoutValidationDeprecated(
visible_selection.extent_ = extent;
visible_selection.base_is_first_ = base.CompareTo(extent) <= 0;
if (base == extent) {
visible_selection.selection_type_ = kCaretSelection;
visible_selection.affinity_ = affinity;
return visible_selection;
}
// Since |affinity_| for non-|CaretSelection| is always |kDownstream|,
// we should keep this invariant. Note: This function can be called with
// |affinity_| is |kUpstream|.
visible_selection.selection_type_ = kRangeSelection;
visible_selection.affinity_ = TextAffinity::kDownstream;
return visible_selection;
}
......
......@@ -61,8 +61,6 @@ class CORE_TEMPLATE_CLASS_EXPORT VisibleSelectionTemplate {
const SelectionTemplate<Strategy>&,
TextGranularity);
SelectionType GetSelectionType() const { return selection_type_; }
TextAffinity Affinity() const { return affinity_; }
SelectionTemplate<Strategy> AsSelection() const;
......@@ -97,9 +95,9 @@ class CORE_TEMPLATE_CLASS_EXPORT VisibleSelectionTemplate {
return !operator==(other);
}
bool IsNone() const { return GetSelectionType() == kNoSelection; }
bool IsCaret() const { return GetSelectionType() == kCaretSelection; }
bool IsRange() const { return GetSelectionType() == kRangeSelection; }
bool IsNone() const;
bool IsCaret() const;
bool IsRange() const;
bool IsNonOrphanedCaretOrRange() const {
return !IsNone() && !Start().IsOrphan() && !End().IsOrphan();
}
......@@ -157,7 +155,6 @@ class CORE_TEMPLATE_CLASS_EXPORT VisibleSelectionTemplate {
TextAffinity affinity_; // the upstream/downstream affinity of the caret
// these are cached, can be recalculated by validate()
SelectionType selection_type_; // None, Caret, Range
bool base_is_first_ : 1; // True if base is before the extent
// Non-directional ignores m_baseIsFirst and selection always extends on shift
// + arrow key.
......
......@@ -259,7 +259,7 @@ TEST_F(VisibleSelectionTest, Initialisation) {
const VisibleSelection no_selection =
CreateVisibleSelection(SelectionInDOMTree::Builder().Build());
EXPECT_EQ(kNoSelection, no_selection.GetSelectionType());
EXPECT_TRUE(no_selection.IsNone());
}
// For http://crbug.com/695317
......
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