Commit 5cb48123 authored by Yoshifumi Inoue's avatar Yoshifumi Inoue Committed by Commit Bot

Get rid of SelectionTemplate::granularity_

This patch gets rid of |SelectionTemplate::granularity_| since it is always
|TextGranularity::kCharacter| since the patch[1] for improving code health.

This patch also renames |SelectionTypeWithLegacyGranularity()| to |Type()| since
|SelectionTemplate| doesn't have granularity any more.

[1] http://crrev.com/2970043002: Simplify
SelectionController::UpdateSelectionForMouseDrag()

Bug: 692923
Change-Id: Ic58dfcf8eef7f7fe2121df27b5639d98da16986d
Reviewed-on: https://chromium-review.googlesource.com/567781Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#485881}
parent 1be89cc4
......@@ -1508,10 +1508,7 @@ void Editor::ChangeSelectionAfterCommand(
// sequence, but we want to do these things (matches AppKit).
if (selection_did_not_change_dom_position) {
Client().RespondToChangedSelection(
frame_, GetFrame()
.Selection()
.GetSelectionInDOMTree()
.SelectionTypeWithLegacyGranularity());
frame_, GetFrame().Selection().GetSelectionInDOMTree().Type());
}
}
......@@ -1760,11 +1757,8 @@ void Editor::RespondToChangedSelection(
const Position& old_selection_start,
FrameSelection::SetSelectionOptions options) {
GetSpellChecker().RespondToChangedSelection(old_selection_start, options);
Client().RespondToChangedSelection(&GetFrame(),
GetFrame()
.Selection()
.GetSelectionInDOMTree()
.SelectionTypeWithLegacyGranularity());
Client().RespondToChangedSelection(
&GetFrame(), GetFrame().Selection().GetSelectionInDOMTree().Type());
SetStartNewKillRingSequence(true);
}
......
......@@ -303,7 +303,6 @@ void FrameSelection::SetSelection(const SelectionInFlatTree& new_selection,
builder.SetAffinity(new_selection.Affinity())
.SetBaseAndExtent(ToPositionInDOMTree(new_selection.Base()),
ToPositionInDOMTree(new_selection.Extent()))
.SetGranularity(new_selection.Granularity())
.SetIsDirectional(new_selection.IsDirectional())
.SetIsHandleVisible(new_selection.IsHandleVisible());
return SetSelection(builder.Build(), options, align, granularity);
......@@ -593,8 +592,7 @@ void FrameSelection::SelectFrameElementInParentIfFullySelected() {
// Check if the selection contains the entire frame contents; if not, then
// there is nothing to do.
if (GetSelectionInDOMTree().SelectionTypeWithLegacyGranularity() !=
kRangeSelection) {
if (GetSelectionInDOMTree().Type() != kRangeSelection) {
return;
}
......
......@@ -11,6 +11,8 @@
namespace blink {
enum class TextGranularity;
class GranularityStrategy {
USING_FAST_MALLOC(GranularityStrategy);
......
......@@ -1195,7 +1195,7 @@ void SelectionController::NotifySelectionChanged() {
const SelectionInDOMTree& selection =
this->Selection().GetSelectionInDOMTree();
switch (selection.SelectionTypeWithLegacyGranularity()) {
switch (selection.Type()) {
case kNoSelection:
selection_state_ = SelectionState::kHaveNotStartedSelection;
return;
......
......@@ -415,7 +415,6 @@ void SelectionEditor::UpdateCachedVisibleSelectionInFlatTreeIfNeeded() const {
else if (extent.IsNotNull())
builder.Collapse(extent);
builder.SetAffinity(selection_.Affinity())
.SetGranularity(selection_.Granularity())
.SetIsDirectional(selection_.IsDirectional());
cached_visible_selection_in_flat_tree_ =
CreateVisibleSelection(builder.Build());
......
......@@ -14,7 +14,6 @@ SelectionTemplate<Strategy>::SelectionTemplate(const SelectionTemplate& other)
: base_(other.base_),
extent_(other.extent_),
affinity_(other.affinity_),
granularity_(other.granularity_),
is_directional_(other.is_directional_),
is_handle_visible_(other.is_handle_visible_)
#if DCHECK_IS_ON()
......@@ -39,7 +38,7 @@ bool SelectionTemplate<Strategy>::operator==(
return false;
DCHECK_EQ(base_.GetDocument(), other.GetDocument()) << *this << ' ' << other;
return base_ == other.base_ && extent_ == other.extent_ &&
affinity_ == other.affinity_ && granularity_ == other.granularity_ &&
affinity_ == other.affinity_ &&
is_directional_ == other.is_directional_ &&
is_handle_visible_ == other.is_handle_visible_;
}
......@@ -78,14 +77,12 @@ const PositionTemplate<Strategy>& SelectionTemplate<Strategy>::Extent() const {
template <typename Strategy>
bool SelectionTemplate<Strategy>::IsCaret() const {
return base_.IsNotNull() && base_ == extent_ &&
granularity_ == TextGranularity::kCharacter;
return base_.IsNotNull() && base_ == extent_;
}
template <typename Strategy>
bool SelectionTemplate<Strategy>::IsRange() const {
return base_ != extent_ ||
(base_.IsNotNull() && granularity_ != TextGranularity::kCharacter);
return base_ != extent_;
}
template <typename Strategy>
......@@ -155,11 +152,10 @@ SelectionTemplate<Strategy>::ComputeStartPosition() const {
}
template <typename Strategy>
SelectionType SelectionTemplate<Strategy>::SelectionTypeWithLegacyGranularity()
const {
SelectionType SelectionTemplate<Strategy>::Type() const {
if (base_.IsNull())
return kNoSelection;
if (base_ == extent_ && granularity_ == TextGranularity::kCharacter)
if (base_ == extent_)
return kCaretSelection;
return kRangeSelection;
}
......@@ -302,14 +298,6 @@ SelectionTemplate<Strategy>::Builder::SetBaseAndExtentDeprecated(
return SetBaseAndExtent(EphemeralRangeTemplate<Strategy>());
}
template <typename Strategy>
typename SelectionTemplate<Strategy>::Builder&
SelectionTemplate<Strategy>::Builder::SetGranularity(
TextGranularity granularity) {
selection_.granularity_ = granularity;
return *this;
}
template <typename Strategy>
typename SelectionTemplate<Strategy>::Builder&
SelectionTemplate<Strategy>::Builder::SetIsDirectional(bool is_directional) {
......
......@@ -13,7 +13,6 @@
#include "core/editing/PositionWithAffinity.h"
#include "core/editing/SelectionType.h"
#include "core/editing/TextAffinity.h"
#include "core/editing/TextGranularity.h"
#include "platform/wtf/Allocator.h"
namespace blink {
......@@ -64,7 +63,6 @@ class CORE_EXPORT SelectionTemplate final {
const PositionTemplate<Strategy>& extent);
Builder& SetAffinity(TextAffinity);
Builder& SetGranularity(TextGranularity);
Builder& SetIsDirectional(bool);
Builder& SetIsHandleVisible(bool);
......@@ -85,7 +83,6 @@ class CORE_EXPORT SelectionTemplate final {
const PositionTemplate<Strategy>& Base() const;
const PositionTemplate<Strategy>& Extent() const;
TextAffinity Affinity() const { return affinity_; }
TextGranularity Granularity() const { return granularity_; }
bool IsCaret() const;
bool IsDirectional() const { return is_directional_; }
bool IsHandleVisible() const { return is_handle_visible_; }
......@@ -100,12 +97,8 @@ class CORE_EXPORT SelectionTemplate final {
const PositionTemplate<Strategy>& ComputeEndPosition() const;
const PositionTemplate<Strategy>& ComputeStartPosition() const;
// Returns |SelectionType| for |this| based on |m_base| and |m_extent|
// If |m_granularity| is |CharacterGranularity|, otherwise this function
// returns |RangeSelection| event if |m_base| == |m_extent|.
// Note: |m_granularity| will be removed, using this function is not
// encouraged.
SelectionType SelectionTypeWithLegacyGranularity() const;
// Returns |SelectionType| for |this| based on |base_| and |extent_|.
SelectionType Type() const;
DECLARE_TRACE();
......@@ -122,7 +115,6 @@ class CORE_EXPORT SelectionTemplate final {
PositionTemplate<Strategy> base_;
PositionTemplate<Strategy> extent_;
TextAffinity affinity_ = TextAffinity::kDownstream;
TextGranularity granularity_ = TextGranularity::kCharacter;
bool is_directional_ = false;
bool is_handle_visible_ = false;
#if DCHECK_IS_ON()
......
......@@ -15,7 +15,6 @@ TEST_F(SelectionTest, defaultConstructor) {
SelectionInDOMTree selection;
EXPECT_EQ(TextAffinity::kDownstream, selection.Affinity());
EXPECT_EQ(TextGranularity::kCharacter, selection.Granularity());
EXPECT_FALSE(selection.IsDirectional());
EXPECT_FALSE(selection.IsHandleVisible());
EXPECT_TRUE(selection.IsNone());
......@@ -33,7 +32,6 @@ TEST_F(SelectionTest, caret) {
const SelectionInDOMTree& selection = builder.Build();
EXPECT_EQ(TextAffinity::kDownstream, selection.Affinity());
EXPECT_EQ(TextGranularity::kCharacter, selection.Granularity());
EXPECT_FALSE(selection.IsDirectional());
EXPECT_FALSE(selection.IsHandleVisible());
EXPECT_FALSE(selection.IsNone());
......@@ -53,7 +51,6 @@ TEST_F(SelectionTest, range) {
const SelectionInDOMTree& selection = builder.Build();
EXPECT_EQ(TextAffinity::kDownstream, selection.Affinity());
EXPECT_EQ(TextGranularity::kCharacter, selection.Granularity());
EXPECT_FALSE(selection.IsDirectional());
EXPECT_FALSE(selection.IsHandleVisible());
EXPECT_FALSE(selection.IsNone());
......
......@@ -62,7 +62,7 @@ VisibleSelectionTemplate<Strategy>::VisibleSelectionTemplate(
template <typename Strategy>
VisibleSelectionTemplate<Strategy> VisibleSelectionTemplate<Strategy>::Create(
const SelectionTemplate<Strategy>& selection) {
return VisibleSelectionTemplate(selection, selection.Granularity());
return VisibleSelectionTemplate(selection, TextGranularity::kCharacter);
}
VisibleSelection CreateVisibleSelection(const SelectionInDOMTree& selection) {
......
......@@ -744,7 +744,7 @@ void TextControlElement::SelectionChanged(bool user_triggered) {
return;
const SelectionInDOMTree& selection =
frame->Selection().GetSelectionInDOMTree();
if (selection.SelectionTypeWithLegacyGranularity() != kRangeSelection)
if (selection.Type() != kRangeSelection)
return;
DispatchEvent(Event::CreateBubble(EventTypeNames::select));
}
......
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