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