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

Introduce enum class SetSelectionBy as replacement of enum EUserTriggered

This patch introduces enum class |SetSelectionBy| as replacement of
|EUserTriggered| to allow forward declaration for preparation of the patch[1].

It is done by almost mechanical changes:
 - s/kUserTriggered/SetSelectionBy::kUser/
 - s/kNotUserTriggered/SetSelectionBy::kSystem/

This patch also introduces
 - ConvertSelectionOptionsToSetSelectionBy()
 - ConvertSetSelectionByToSetSelectionOptions()
as |constexpr| instead of |static inline| to utilize C++11 feature and
to avoid |static_cast<>| for improving readability.

[1] http://crrev.com/c/569662: Introduce SetSelectionData for

FrameSelection: :SetSelection()
Change-Id: Ib2f5a1dd942f820cd74ea90c37f9243b93336904
Reviewed-on: https://chromium-review.googlesource.com/579027Reviewed-by: default avatarKent Tamura <tkent@chromium.org>
Commit-Queue: Yoshifumi Inoue <yosin@chromium.org>
Cr-Commit-Position: refs/heads/master@{#488575}
parent c296f5fb
......@@ -270,9 +270,10 @@ void FrameSelection::DidSetSelectionDeprecated(SetSelectionOptions options,
}
}
EUserTriggered user_triggered = SelectionOptionsToUserTriggered(options);
NotifyTextControlOfSelectionChange(user_triggered);
if (user_triggered == kUserTriggered) {
SetSelectionBy set_selection_by =
ConvertSelectionOptionsToSetSelectionBy(options);
NotifyTextControlOfSelectionChange(set_selection_by);
if (set_selection_by == SetSelectionBy::kUser) {
ScrollAlignment alignment;
if (frame_->GetEditor()
......@@ -343,13 +344,13 @@ static DispatchEventResult DispatchSelectStart(
bool FrameSelection::Modify(SelectionModifyAlteration alter,
SelectionDirection direction,
TextGranularity granularity,
EUserTriggered user_triggered) {
SetSelectionBy set_selection_by) {
SelectionModifier selection_modifier(*GetFrame(),
ComputeVisibleSelectionInDOMTree(),
x_pos_for_vertical_arrow_navigation_);
const bool modified =
selection_modifier.Modify(alter, direction, granularity);
if (user_triggered == kUserTriggered &&
if (set_selection_by == SetSelectionBy::kUser &&
selection_modifier.Selection().IsRange() &&
ComputeVisibleSelectionInDOMTree().IsCaret() &&
DispatchSelectStart(ComputeVisibleSelectionInDOMTree()) !=
......@@ -357,7 +358,7 @@ bool FrameSelection::Modify(SelectionModifyAlteration alter,
return false;
}
if (!modified) {
if (user_triggered == kNotUserTriggered)
if (set_selection_by == SetSelectionBy::kSystem)
return false;
// If spatial navigation enabled, focus navigator will move focus to
// another element. See snav-input.html and snav-textarea.html
......@@ -369,7 +370,8 @@ bool FrameSelection::Modify(SelectionModifyAlteration alter,
}
const SetSelectionOptions options =
kCloseTyping | kClearTypingStyle | user_triggered;
kCloseTyping | kClearTypingStyle |
ConvertSetSelectionByToSetSelectionOptions(set_selection_by);
SetSelection(selection_modifier.Selection().AsSelection(), options);
if (granularity == TextGranularity::kLine ||
......@@ -377,7 +379,7 @@ bool FrameSelection::Modify(SelectionModifyAlteration alter,
x_pos_for_vertical_arrow_navigation_ =
selection_modifier.XPosForVerticalArrowNavigation();
if (user_triggered == kUserTriggered)
if (set_selection_by == SetSelectionBy::kUser)
granularity_ = TextGranularity::kCharacter;
ScheduleVisualUpdateForPaintInvalidationIfNeeded();
......@@ -631,7 +633,7 @@ static Node* NonBoundaryShadowTreeRootNode(const Position& position) {
: nullptr;
}
void FrameSelection::SelectAll(EUserTriggered user_triggered) {
void FrameSelection::SelectAll(SetSelectionBy set_selection_by) {
if (isHTMLSelectElement(GetDocument().FocusedElement())) {
HTMLSelectElement* select_element =
toHTMLSelectElement(GetDocument().FocusedElement());
......@@ -643,7 +645,7 @@ void FrameSelection::SelectAll(EUserTriggered user_triggered) {
Node* root = nullptr;
Node* select_start_target = nullptr;
if (user_triggered == kUserTriggered && IsHidden()) {
if (set_selection_by == SetSelectionBy::kUser && IsHidden()) {
// Hidden selection appears as no selection to user, in which case user-
// triggered SelectAll should act as if there is no selection.
root = GetDocument().documentElement();
......@@ -683,14 +685,14 @@ void FrameSelection::SelectAll(EUserTriggered user_triggered) {
return;
}
// TODO(editing-dev): Should we pass in user_triggered?
// TODO(editing-dev): Should we pass in set_selection_by?
SetSelection(SelectionInDOMTree::Builder()
.SelectAllChildren(*root)
.SetIsHandleVisible(IsHandleVisible())
.Build());
SelectFrameElementInParentIfFullySelected();
// TODO(editing-dev): Should we pass in user_triggered?
NotifyTextControlOfSelectionChange(kUserTriggered);
// TODO(editing-dev): Should we pass in set_selection_by?
NotifyTextControlOfSelectionChange(SetSelectionBy::kUser);
if (IsHandleVisible()) {
ContextMenuAllowedScope scope;
frame_->GetEventHandler().ShowNonLocatedContextMenu(nullptr,
......@@ -811,12 +813,12 @@ void FrameSelection::UpdateAppearance() {
}
void FrameSelection::NotifyTextControlOfSelectionChange(
EUserTriggered user_triggered) {
SetSelectionBy set_selection_by) {
TextControlElement* text_control =
EnclosingTextControl(GetSelectionInDOMTree().Base());
if (!text_control)
return;
text_control->SelectionChanged(user_triggered == kUserTriggered);
text_control->SelectionChanged(set_selection_by == SetSelectionBy::kUser);
}
// Helper function that tells whether a particular node is an element that has
......
......@@ -56,7 +56,7 @@ struct PaintInvalidatorContext;
enum class CursorAlignOnScroll { kIfNeeded, kAlways };
enum EUserTriggered { kNotUserTriggered = 0, kUserTriggered = 1 };
enum class SetSelectionBy { kSystem = 0, kUser = 1 };
enum RevealExtentOption { kRevealExtent, kDoNotRevealExtent };
......@@ -77,17 +77,25 @@ class CORE_EXPORT FrameSelection final
~FrameSelection();
enum SetSelectionOption {
// 1 << 0 is reserved for EUserTriggered
kUserTriggered = 1,
kCloseTyping = 1 << 1,
kClearTypingStyle = 1 << 2,
kDoNotSetFocus = 1 << 3,
kDoNotClearStrategy = 1 << 4,
};
// Union of values in SetSelectionOption and EUserTriggered
static_assert(kUserTriggered == static_cast<int>(SetSelectionBy::kUser),
"|kUserTriggered| should equal to |SetSelectionBy::kUser|");
// Union of values in SetSelectionOption and SetSelectionBy
typedef unsigned SetSelectionOptions;
static inline EUserTriggered SelectionOptionsToUserTriggered(
static constexpr SetSelectionBy ConvertSelectionOptionsToSetSelectionBy(
SetSelectionOptions options) {
return static_cast<EUserTriggered>(options & kUserTriggered);
return static_cast<SetSelectionBy>(options &
static_cast<int>(SetSelectionBy::kUser));
}
static constexpr SetSelectionOptions
ConvertSetSelectionByToSetSelectionOptions(SetSelectionBy set_selection_by) {
return static_cast<SetSelectionOptions>(set_selection_by);
}
bool IsAvailable() const { return LifecycleContext(); }
......@@ -112,7 +120,7 @@ class CORE_EXPORT FrameSelection final
SetSelectionOptions = kCloseTyping | kClearTypingStyle,
CursorAlignOnScroll = CursorAlignOnScroll::kIfNeeded,
TextGranularity = TextGranularity::kCharacter);
void SelectAll(EUserTriggered = kNotUserTriggered);
void SelectAll(SetSelectionBy = SetSelectionBy::kSystem);
void Clear();
bool IsHidden() const;
......@@ -138,7 +146,7 @@ class CORE_EXPORT FrameSelection final
bool Modify(SelectionModifyAlteration,
SelectionDirection,
TextGranularity,
EUserTriggered = kNotUserTriggered);
SetSelectionBy = SetSelectionBy::kSystem);
// Moves the selection extent based on the selection granularity strategy.
// This function does not allow the selection to collapse. If the new
......@@ -205,7 +213,7 @@ class CORE_EXPORT FrameSelection final
#endif
void SetFocusedNodeIfNeeded();
void NotifyTextControlOfSelectionChange(EUserTriggered);
void NotifyTextControlOfSelectionChange(SetSelectionBy);
String SelectedHTMLForClipboard() const;
String SelectedText(const TextIteratorBehavior&) const;
......
......@@ -190,7 +190,7 @@ TEST_F(FrameSelectionTest, ModifyWithUserTriggered) {
EXPECT_FALSE(
Selection().Modify(SelectionModifyAlteration::kMove, kDirectionForward,
TextGranularity::kCharacter, kNotUserTriggered))
TextGranularity::kCharacter, SetSelectionBy::kSystem))
<< "Selection.modify() returns false for non-user-triggered call when "
"selection isn't modified.";
EXPECT_EQ(end_of_text,
......@@ -199,7 +199,7 @@ TEST_F(FrameSelectionTest, ModifyWithUserTriggered) {
EXPECT_TRUE(Selection().Modify(SelectionModifyAlteration::kMove,
kDirectionForward, TextGranularity::kCharacter,
kUserTriggered))
SetSelectionBy::kUser))
<< "Selection.modify() returns true for user-triggered call";
EXPECT_EQ(end_of_text,
Selection().ComputeVisibleSelectionInDOMTreeDeprecated().Start())
......
......@@ -1023,7 +1023,7 @@ bool SelectionController::HandleMouseReleaseEvent(
handled = true;
}
Selection().NotifyTextControlOfSelectionChange(kUserTriggered);
Selection().NotifyTextControlOfSelectionChange(SetSelectionBy::kUser);
Selection().SelectFrameElementInParentIfFullySelected();
......
......@@ -1209,13 +1209,15 @@ void WebLocalFrameImpl::SelectRange(
handle_visibility_behavior == kShowSelectionHandle ||
(handle_visibility_behavior == kPreserveHandleVisibility &&
selection.IsHandleVisible());
selection.SetSelection(SelectionInDOMTree::Builder()
.SetBaseAndExtent(range)
.SetAffinity(VP_DEFAULT_AFFINITY)
.SetIsHandleVisible(show_handles)
.SetIsDirectional(false)
.Build(),
kNotUserTriggered);
selection.SetSelection(
SelectionInDOMTree::Builder()
.SetBaseAndExtent(range)
.SetAffinity(VP_DEFAULT_AFFINITY)
.SetIsHandleVisible(show_handles)
.SetIsDirectional(false)
.Build(),
FrameSelection::ConvertSetSelectionByToSetSelectionOptions(
SetSelectionBy::kSystem));
}
WebString WebLocalFrameImpl::RangeAsText(const WebRange& web_range) {
......
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