Commit 7a5ca21b authored by Tommy C. Li's avatar Tommy C. Li Committed by Commit Bot

Omnibox UI Experiments: Steady State elisions - fix double-click-select.

Fix double-click word select for steady state elisions.

This bug is caused by the fact that we change the text in response to
a double-click on the second mousedown. That confuses the double click
word select logic, which saves the range into a member variable.

There's no way for the selection controller to get the correct selected
word except for us to inject an offset into it...

Bug: 797354
Change-Id: I464d405920de7dfcbc317ed9ecbe8b664b920f8d
Reviewed-on: https://chromium-review.googlesource.com/940603
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarPeter Kasting <pkasting@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#539913}
parent 8bf6c2f6
...@@ -545,6 +545,10 @@ bool OmniboxViewViews::UnapplySteadyStateElisions() { ...@@ -545,6 +545,10 @@ bool OmniboxViewViews::UnapplySteadyStateElisions() {
if (offset != base::string16::npos) { if (offset != base::string16::npos) {
start += offset; start += offset;
end += offset; end += offset;
// Since we are changing the text in the double-click event handler, we
// need to fix the cached indices of the double-clicked word.
OffsetDoubleClickWord(offset);
} }
// Update the text to the full unelided URL. The caret is positioned at 0, as // Update the text to the full unelided URL. The caret is positioned at 0, as
......
...@@ -1884,6 +1884,10 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) { ...@@ -1884,6 +1884,10 @@ void Textfield::ExecuteTextEditCommand(ui::TextEditCommand command) {
OnAfterUserAction(); OnAfterUserAction();
} }
void Textfield::OffsetDoubleClickWord(int offset) {
selection_controller_.OffsetDoubleClickWord(offset);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Textfield, private: // Textfield, private:
......
...@@ -360,6 +360,11 @@ class VIEWS_EXPORT Textfield : public View, ...@@ -360,6 +360,11 @@ class VIEWS_EXPORT Textfield : public View,
// Executes the given |command|. // Executes the given |command|.
virtual void ExecuteTextEditCommand(ui::TextEditCommand command); virtual void ExecuteTextEditCommand(ui::TextEditCommand command);
// Offsets the double-clicked word's range. This is only used in the unusual
// case where the text changes on the second mousedown of a double-click.
// This is harmless if there is not a currently double-clicked word.
void OffsetDoubleClickWord(int offset);
private: private:
friend class TextfieldTestApi; friend class TextfieldTestApi;
......
...@@ -154,6 +154,11 @@ void SelectionController::OnMouseCaptureLost() { ...@@ -154,6 +154,11 @@ void SelectionController::OnMouseCaptureLost() {
delegate_->UpdateSelectionClipboard(); delegate_->UpdateSelectionClipboard();
} }
void SelectionController::OffsetDoubleClickWord(int offset) {
double_click_word_.set_start(double_click_word_.start() + offset);
double_click_word_.set_end(double_click_word_.end() + offset);
}
void SelectionController::TrackMouseClicks(const ui::MouseEvent& event) { void SelectionController::TrackMouseClicks(const ui::MouseEvent& event) {
if (event.IsOnlyLeftMouseButton()) { if (event.IsOnlyLeftMouseButton()) {
base::TimeDelta time_delta = event.time_stamp() - last_click_time_; base::TimeDelta time_delta = event.time_stamp() - last_click_time_;
......
...@@ -58,6 +58,11 @@ class VIEWS_EXPORT SelectionController { ...@@ -58,6 +58,11 @@ class VIEWS_EXPORT SelectionController {
handles_selection_clipboard_ = value; handles_selection_clipboard_ = value;
} }
// Offsets the double-clicked word's range. This is only used in the unusual
// case where the text changes on the second mousedown of a double-click.
// This is harmless if there is not a currently double-clicked word.
void OffsetDoubleClickWord(int offset);
private: private:
// Tracks the mouse clicks for single/double/triple clicks. // Tracks the mouse clicks for single/double/triple clicks.
void TrackMouseClicks(const ui::MouseEvent& event); void TrackMouseClicks(const ui::MouseEvent& event);
......
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