Skip to content

Commit

Permalink
Intents: Make pressing Enter in Intent Picker open the focused app
Browse files Browse the repository at this point in the history
To help with keyboard-only usage of the new grid-style intent picker
bubble, pressing enter on the keyboard with an app focused will directly
open the app. Without this change, you needed to tab through to the
'Open' button and press enter/space on that.

Bug: 1346457
Change-Id: I578ef9df65ae16fbdc0cbd084ae9494ad9bd843e
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3809012
Commit-Queue: Tim Sergeant <tsergeant@chromium.org>
Auto-Submit: Tim Sergeant <tsergeant@chromium.org>
Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1032447}
  • Loading branch information
tgsergeant authored and Chromium LUCI CQ committed Aug 8, 2022
1 parent bf3761e commit 199441d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
6 changes: 5 additions & 1 deletion chrome/browser/ui/views/intent_picker_bubble_view.cc
Expand Up @@ -41,6 +41,7 @@
#include "ui/base/metadata/metadata_impl_macros.h"
#include "ui/base/models/image_model.h"
#include "ui/color/color_id.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/insets.h"
#include "ui/gfx/text_constants.h"
#include "ui/strings/grit/ui_strings.h"
Expand Down Expand Up @@ -206,7 +207,10 @@ class IntentPickerAppGridButton : public views::Button {
}

void OnPressed(const ui::Event& event) {
selected_callback_.Run(IsDoubleClick(event));
bool should_open = IsDoubleClick(event) ||
(event.IsKeyEvent() &&
event.AsKeyEvent()->key_code() == ui::VKEY_RETURN);
selected_callback_.Run(should_open);
}

bool selected_ = false;
Expand Down
22 changes: 22 additions & 0 deletions chrome/browser/ui/views/intent_picker_bubble_view_unittest.cc
Expand Up @@ -29,6 +29,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/models/image_model.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/image/image.h"
Expand Down Expand Up @@ -453,6 +454,7 @@ TEST_P(IntentPickerBubbleViewLayoutTest, CloseDialog) {
apps::IntentPickerCloseReason::DIALOG_DEACTIVATED);
}

// TODO(crbug.com/1330440): Fix flakiness on Windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_KeyboardNavigation DISABLED_KeyboardNavigation
#else
Expand Down Expand Up @@ -525,3 +527,23 @@ TEST_F(IntentPickerBubbleViewGridLayoutTest, DefaultSelectionTwoApps) {

ASSERT_FALSE(bubble_->GetSelectedIndex().has_value());
}

// TODO(crbug.com/1330440): Fix flakiness on Windows.
#if BUILDFLAG(IS_WIN)
#define MAYBE_OpenWithReturnKey DISABLED_OpenWithReturnKey
#else
#define MAYBE_OpenWithReturnKey OpenWithReturnKey
#endif
TEST_F(IntentPickerBubbleViewGridLayoutTest, MAYBE_OpenWithReturnKey) {
AddDefaultApps();
CreateBubbleView(/*use_icons=*/false, /*show_stay_in_chrome=*/false,
BubbleType::kLinkCapturing,
/*initiating_origin=*/absl::nullopt);

GetButtonAtIndex(0)->RequestFocus();
EXPECT_TRUE(GetButtonAtIndex(0)->HasFocus());

event_generator_->PressKey(ui::VKEY_RETURN, ui::EF_NONE);

EXPECT_EQ(last_close_reason_, apps::IntentPickerCloseReason::OPEN_APP);
}

0 comments on commit 199441d

Please sign in to comment.