Skip to content

Commit

Permalink
Tweak "Press Overview" messages when external keyboard attached.
Browse files Browse the repository at this point in the history
BUG=b:203622329

Change-Id: I9c44abc73c460f5efbb7bd4645d4e5c4c20611ea
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3488748
Reviewed-by: Mitsuru Oshima <oshima@chromium.org>
Commit-Queue: Chloe Pelling <cpelling@google.com>
Cr-Commit-Position: refs/heads/main@{#976927}
  • Loading branch information
cpelling authored and Chromium LUCI CQ committed Mar 3, 2022
1 parent 537f9d2 commit ffee99d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 14 deletions.
4 changes: 3 additions & 1 deletion ash/bluetooth_devices_observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#ifndef ASH_BLUETOOTH_DEVICES_OBSERVER_H_
#define ASH_BLUETOOTH_DEVICES_OBSERVER_H_

#include "ash/ash_export.h"
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "device/bluetooth/bluetooth_adapter.h"
Expand All @@ -17,7 +18,8 @@ namespace ash {
// ui::InputDeviceEventObserver as InputDeviceEventObserver does not have
// knowledge about bluetooth device status thus does not send notifications of
// bluetooth device changes.
class BluetoothDevicesObserver : public device::BluetoothAdapter::Observer {
class ASH_EXPORT BluetoothDevicesObserver
: public device::BluetoothAdapter::Observer {
public:
// Note |device| can be nullptr here if only the bluetooth adapter status
// changes.
Expand Down
76 changes: 63 additions & 13 deletions components/exo/ui_lock_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include <memory>

#include "ash/bluetooth_devices_observer.h"
#include "ash/constants/app_types.h"
#include "ash/constants/ash_features.h"
#include "ash/public/cpp/keyboard/keyboard_controller.h"
Expand All @@ -30,6 +31,7 @@
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/window.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/devices/device_data_manager.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/gfx/paint_vector_icon.h"
Expand Down Expand Up @@ -82,6 +84,31 @@ bool IsUILockControllerEnabled(aura::Window* window) {
return false;
}

// Return true if an external keyboard is attached to the device.
//
// Note: May mistakenly return true when certain non-keyboard devices are
// attached; see crbug/882410, crbug/884096.
//
// Copied from ash/keyboard/virtual_keyboard_controller.cc.
// TODO(cpelling): Refactor to avoid duplicating this logic.
bool HasExternalKeyboard() {
ui::DeviceDataManager* device_data_manager =
ui::DeviceDataManager::GetInstance();

ash::BluetoothDevicesObserver bluetooth(base::DoNothing());

for (const ui::InputDevice& device :
device_data_manager->GetKeyboardDevices()) {
ui::InputDeviceType type = device.type;
if (type == ui::InputDeviceType::INPUT_DEVICE_USB ||
(type == ui::InputDeviceType::INPUT_DEVICE_BLUETOOTH &&
bluetooth.IsConnectedBluetoothDevice(device))) {
return true;
}
}
return false;
}

// Creates the separator view between bubble views of modifiers and key.
std::unique_ptr<views::View> CreateIconView(const gfx::VectorIcon& icon) {
constexpr int kIconSize = 28;
Expand Down Expand Up @@ -181,13 +208,24 @@ class ExitNotifier : public ui::EventHandler, public ash::WindowStateObserver {
views::Widget::ClosedReason::kUnspecified);
}

if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
pointer_capture_notification_ =
CreateEscNotification(window_, IDS_PRESS_TO_EXIT_MOUSELOCK_TWO_KEYS,
{IDS_APP_SEARCH_KEY, IDS_APP_OVERVIEW_KEY});
if (HasExternalKeyboard()) {
if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
pointer_capture_notification_ =
CreateEscNotification(window_, IDS_PRESS_TO_EXIT_MOUSELOCK_TWO_KEYS,
{IDS_APP_META_KEY, IDS_APP_F5_KEY});
} else {
pointer_capture_notification_ = CreateEscNotification(
window_, IDS_PRESS_TO_EXIT_MOUSELOCK, {IDS_APP_F5_KEY});
}
} else {
pointer_capture_notification_ = CreateEscNotification(
window_, IDS_PRESS_TO_EXIT_MOUSELOCK, {IDS_APP_OVERVIEW_KEY});
if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
pointer_capture_notification_ =
CreateEscNotification(window_, IDS_PRESS_TO_EXIT_MOUSELOCK_TWO_KEYS,
{IDS_APP_SEARCH_KEY, IDS_APP_OVERVIEW_KEY});
} else {
pointer_capture_notification_ = CreateEscNotification(
window_, IDS_PRESS_TO_EXIT_MOUSELOCK, {IDS_APP_OVERVIEW_KEY});
}
}

pointer_capture_notification_->Show();
Expand Down Expand Up @@ -281,14 +319,26 @@ class ExitNotifier : public ui::EventHandler, public ash::WindowStateObserver {
}

if (window_->GetProperty(chromeos::kUseOverviewToExitFullscreen)) {
if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN_TWO_KEYS,
{IDS_APP_SEARCH_KEY, IDS_APP_OVERVIEW_KEY});
if (HasExternalKeyboard()) {
if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN_TWO_KEYS,
{IDS_APP_META_KEY, IDS_APP_F5_KEY});
} else {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN,
{IDS_APP_F5_KEY});
}
} else {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN,
{IDS_APP_OVERVIEW_KEY});
if (ash::KeyboardController::Get()->AreTopRowKeysFunctionKeys()) {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN_TWO_KEYS,
{IDS_APP_SEARCH_KEY, IDS_APP_OVERVIEW_KEY});
} else {
fullscreen_esc_notification_ = CreateEscNotification(
window_, IDS_FULLSCREEN_PRESS_TO_EXIT_FULLSCREEN,
{IDS_APP_OVERVIEW_KEY});
}
}
} else {
fullscreen_esc_notification_ = CreateEscNotification(
Expand Down
6 changes: 6 additions & 0 deletions ui/strings/ui_strings.grd
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,9 @@ need to be translated for each locale.-->
<message name="IDS_APP_F1_KEY" desc="F1 key">
F1
</message>
<message name="IDS_APP_F5_KEY" desc="F5 key">
F5
</message>
<message name="IDS_APP_F6_KEY" is_accessibility_with_no_ui="true" desc="F6 key">
F6
</message>
Expand Down Expand Up @@ -723,6 +726,9 @@ need to be translated for each locale.-->
</message>
</if>
<if expr="chromeos">
<message name="IDS_APP_META_KEY" desc="External Meta key (Search key on ChromeOS keyboards, Windows key on Windows keyboards, and Command key on Mac keyboards)">
Meta
</message>
<message name="IDS_APP_FULLSCREEN_KEY" desc="This refers to the 'Fullscreen' media key on certain keyboards.">
Fullscreen
</message>
Expand Down
1 change: 1 addition & 0 deletions ui/strings/ui_strings_grd/IDS_APP_F5_KEY.png.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
acfa0af623fc7b62fcc699df8f2c7bcc58b38206
1 change: 1 addition & 0 deletions ui/strings/ui_strings_grd/IDS_APP_META_KEY.png.sha1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
acfa0af623fc7b62fcc699df8f2c7bcc58b38206

0 comments on commit ffee99d

Please sign in to comment.