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