Commit 2b47980e authored by Stephen Sigwart's avatar Stephen Sigwart Committed by Commit Bot

[omnibox] Fix right click URL to select all

When you right click the URL in the omnibox, it should select the full
URL.

Bug: 1101679
Change-Id: I01e62bb0d6d85b01b79b0ff41e8b3830648d7b61
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2275749
Commit-Queue: Tommy Li <tommycli@chromium.org>
Reviewed-by: default avatarTommy Li <tommycli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#785811}
parent 4eb08e30
...@@ -1292,6 +1292,10 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { ...@@ -1292,6 +1292,10 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
bool handled = views::Textfield::OnMousePressed(event); bool handled = views::Textfield::OnMousePressed(event);
// Reset next double click length
if (event.GetClickCount() == 1)
next_double_click_selection_len_ = 0;
if (!select_all_on_mouse_release_) { if (!select_all_on_mouse_release_) {
if (UnapplySteadyStateElisions(UnelisionGesture::OTHER)) { if (UnapplySteadyStateElisions(UnelisionGesture::OTHER)) {
// This ensures that when the user makes a double-click partial select, we // This ensures that when the user makes a double-click partial select, we
...@@ -1299,7 +1303,7 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { ...@@ -1299,7 +1303,7 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
// selection, which is on mousedown. // selection, which is on mousedown.
TextChanged(); TextChanged();
filter_drag_events_for_unelision_ = true; filter_drag_events_for_unelision_ = true;
} else if (event.GetClickCount() == 1) { } else if (event.GetClickCount() == 1 && event.IsLeftMouseButton()) {
// Select the current word and record it for later. Selection will be // Select the current word and record it for later. Selection will be
// immediately reset to cursor position, so no need to clean up. This is // immediately reset to cursor position, so no need to clean up. This is
// done to handle an edge case where the wrong word is selected on a // done to handle an edge case where the wrong word is selected on a
...@@ -1318,11 +1322,8 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { ...@@ -1318,11 +1322,8 @@ bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) {
next_double_click_selection_offset_ = next_double_click_selection_offset_ =
offset + GetCursorPosition() - next_double_click_selection_len_; offset + GetCursorPosition() - next_double_click_selection_len_;
} }
} else {
// Clear length so we don't try to use it again on later double clicks.
next_double_click_selection_len_ = 0;
} }
} else if (event.GetClickCount() == 2) { } else if (event.GetClickCount() == 2 && event.IsLeftMouseButton()) {
// If the user double clicked and we unelided between the first and second // If the user double clicked and we unelided between the first and second
// click, offset double click. // click, offset double click.
if (next_double_click_selection_len_ != 0) { if (next_double_click_selection_len_ != 0) {
......
...@@ -254,9 +254,11 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase { ...@@ -254,9 +254,11 @@ class OmniboxViewViewsTest : public OmniboxViewViewsTestBase {
return test_api_->GetRenderText()->cursor_enabled(); return test_api_->GetRenderText()->cursor_enabled();
} }
ui::MouseEvent CreateMouseEvent(ui::EventType type, const gfx::Point& point) { ui::MouseEvent CreateMouseEvent(ui::EventType type,
const gfx::Point& point,
int event_flags = ui::EF_LEFT_MOUSE_BUTTON) {
return ui::MouseEvent(type, point, point, ui::EventTimeForNow(), return ui::MouseEvent(type, point, point, ui::EventTimeForNow(),
ui::EF_LEFT_MOUSE_BUTTON, ui::EF_LEFT_MOUSE_BUTTON); event_flags, event_flags);
} }
protected: protected:
...@@ -919,11 +921,15 @@ class OmniboxViewViewsSteadyStateElisionsTest : public OmniboxViewViewsTest { ...@@ -919,11 +921,15 @@ class OmniboxViewViewsSteadyStateElisionsTest : public OmniboxViewViewsTest {
// Sends a mouse down and mouse up event at a point // Sends a mouse down and mouse up event at a point
// beginning of the RenderText. // beginning of the RenderText.
void SendMouseClickAtPoint(gfx::Point point, int click_count) { void SendMouseClickAtPoint(gfx::Point point,
auto mouse_pressed = CreateMouseEvent(ui::ET_MOUSE_PRESSED, point); int click_count,
int event_flags = ui::EF_LEFT_MOUSE_BUTTON) {
auto mouse_pressed =
CreateMouseEvent(ui::ET_MOUSE_PRESSED, point, event_flags);
mouse_pressed.SetClickCount(click_count); mouse_pressed.SetClickCount(click_count);
omnibox_textfield()->OnMousePressed(mouse_pressed); omnibox_textfield()->OnMousePressed(mouse_pressed);
auto mouse_released = CreateMouseEvent(ui::ET_MOUSE_RELEASED, point); auto mouse_released =
CreateMouseEvent(ui::ET_MOUSE_RELEASED, point, event_flags);
mouse_released.SetClickCount(click_count); mouse_released.SetClickCount(click_count);
omnibox_textfield()->OnMouseReleased(mouse_released); omnibox_textfield()->OnMouseReleased(mouse_released);
} }
...@@ -1121,6 +1127,27 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseSingleThenDoubleClick) { ...@@ -1121,6 +1127,27 @@ TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseSingleThenDoubleClick) {
EXPECT_EQ(19U, end); EXPECT_EQ(19U, end);
} }
TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseSingleThenRightClick) {
EXPECT_TRUE(IsElidedUrlDisplayed());
auto point = GetPointInTextAtXOffset(4 * kCharacterWidth);
SendMouseClickAtPoint(point, 1);
EXPECT_TRUE(IsElidedUrlDisplayed());
EXPECT_EQ(base::ASCIIToUTF16("example.com"), omnibox_view()->GetText());
// Verify that the whole full URL is selected.
EXPECT_TRUE(omnibox_view()->IsSelectAll());
// Advance the clock 5 seconds so the next click is not interpreted as a
// double click.
clock()->Advance(base::TimeDelta::FromSeconds(5));
// Right click
SendMouseClickAtPoint(point, 1, ui::EF_RIGHT_MOUSE_BUTTON);
EXPECT_TRUE(IsElidedUrlDisplayed());
EXPECT_TRUE(omnibox_view()->IsSelectAll());
EXPECT_TRUE(omnibox_view()->HasFocus());
}
TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseTripleClick) { TEST_F(OmniboxViewViewsSteadyStateElisionsTest, MouseTripleClick) {
auto point = GetPointInTextAtXOffset(4 * kCharacterWidth); auto point = GetPointInTextAtXOffset(4 * kCharacterWidth);
SendMouseClickAtPoint(point, 1); SendMouseClickAtPoint(point, 1);
......
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