1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154

ash / system / input_device_settings / input_device_settings_notification_controller.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_SYSTEM_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_NOTIFICATION_CONTROLLER_H_
#define ASH_SYSTEM_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_NOTIFICATION_CONTROLLER_H_

#include "ash/ash_export.h"
#include "ash/public/mojom/input_device_settings.mojom.h"
#include "base/containers/flat_map.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "ui/events/ash/mojom/simulate_right_click_modifier.mojom-shared.h"
#include "ui/events/ash/mojom/six_pack_shortcut_modifier.mojom-shared.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia.h"

class PrefRegistrySimple;

namespace message_center {
class MessageCenter;
}  // namespace message_center

namespace ash {

// The notification button index.
enum NotificationButtonIndex {
  BUTTON_EDIT_SHORTCUT = 0,
  BUTTON_LEARN_MORE,
};

// Manages showing notifications for Six Pack/right-click event rewrites.
// Notifications are shown when the user's setting is inconsistent with
// the matched modifier key or the setting is disabled.
class ASH_EXPORT InputDeviceSettingsNotificationController {
 public:
  explicit InputDeviceSettingsNotificationController(
      message_center::MessageCenter* message_center);
  InputDeviceSettingsNotificationController(
      const InputDeviceSettingsNotificationController&) = delete;
  InputDeviceSettingsNotificationController& operator=(
      const InputDeviceSettingsNotificationController&) = delete;
  virtual ~InputDeviceSettingsNotificationController();

  static void RegisterProfilePrefs(PrefRegistrySimple* pref_registry);

  // Used to display a notification when an incoming event would have been
  // remapped to a right click but either the user's setting is inconsistent
  // with the matched modifier key or remapping to right click is disabled.
  void NotifyRightClickRewriteBlockedBySetting(
      ui::mojom::SimulateRightClickModifier blocked_modifier,
      ui::mojom::SimulateRightClickModifier active_modifier);

  // Used to display a notification when an incoming event would have been
  // remapped to a Six Pack key action but either the user's setting is
  // inconsistent with the matched modifier key or remapping to right click
  // is disabled. `key_code` is used to lookup the correct Six Pack key and
  // the `device_id` is provided to route the user to the correct remap keys
  // subpage when the notification is clicked on.
  void NotifySixPackRewriteBlockedBySetting(
      ui::KeyboardCode key_code,
      ui::mojom::SixPackShortcutModifier blocked_modifier,
      ui::mojom::SixPackShortcutModifier active_modifier,
      int device_id);

  // Used to display a notification when a customizable mouse is connected to
  // the chromebook for the first time.
  void NotifyMouseIsCustomizable(const mojom::Mouse& mouse,
                                 const gfx::ImageSkia& device_image);

  // Used to display a notification when a customizable graphics tablet is
  // connected to the chromebook for the first time.
  void NotifyGraphicsTabletIsCustomizable(
      const mojom::GraphicsTablet& graphics_tablet,
      const gfx::ImageSkia& device_image);

  // Used to display a notification when a customizable keyboard is connected
  // to the chromebook for the first time.
  void ShowKeyboardSettingsNotification(const mojom::Keyboard& keyboard,
                                        const gfx::ImageSkia& device_image);

  // Used to display a notification when a customizable touchpad is connected
  // to the chromebook for the first time.
  void ShowTouchpadSettingsNotification(const mojom::Touchpad& touchpad,
                                        const gfx::ImageSkia& device_image);

  // Use to display a notification when a mouse is first connected.
  void NotifyMouseFirstTimeConnected(const mojom::Mouse& mouse,
                                     const gfx::ImageSkia& device_image = {});

  // Used to display a notification when a customizable pointing stick is
  // connected to the chromebook for the first time.
  void ShowPointingStickSettingsNotification(
      const mojom::PointingStick& pointing_stick);

  // Use to display a notification when a graphics table is first connected.
  void NotifyGraphicsTabletFirstTimeConnected(
      const mojom::GraphicsTablet& graphics_tablet,
      const gfx::ImageSkia& device_image = {});

  // Use to display a notification when a keyboard is first connected.
  void NotifyKeyboardFirstTimeConnected(const mojom::Keyboard& keyboard,
                                        const gfx::ImageSkia& device_image);

  // Use to display a notification when a touchpad is first connected.
  void NotifyTouchpadFirstTimeConnected(const mojom::Touchpad& touchpad,
                                        const gfx::ImageSkia& device_image);

  // Use to display a notification when a pointing stick is first connected.
  void NotifyPointingStickFirstTimeConnected(
      const mojom::PointingStick& pointing_stick);

  // Use to display a notification to remind users to press Fn key when users
  // press search key with top row keys and there is no matching behavior.
  void ShowTopRowRewritingNudge();

  // Use to display a notification to remind users to press Fn key when users
  // press search key or alt key with arrow keys and there is no matching
  // behavior.
  void ShowSixPackKeyRewritingNudge(
      ui::KeyboardCode key_code,
      ui::mojom::SixPackShortcutModifier blocked_modifier);

  // Use to display a notification to remind users to press Fn key when users
  // press search key or quick insert key with alt key to switch caps lock
  // and there is no matching.
  void ShowCapsLockRewritingNudge();

  std::optional<std::string> GetDeviceKeyForNotificationId(
      const std::string& notification_id);

 private:
  void HandleRightClickNotificationClicked(const std::string& notification_id,
                                           std::optional<int> button_index);

  void HandleSixPackNotificationClicked(int device_id,
                                        const char* pref_name,
                                        const std::string& notification_id,
                                        std::optional<int> button_index);

  base::flat_map<std::string, std::string> notification_id_to_device_key_map_;

  // MessageCenter for adding notifications.
  const raw_ptr<message_center::MessageCenter, DanglingUntriaged>
      message_center_;

  base::WeakPtrFactory<InputDeviceSettingsNotificationController>
      weak_ptr_factory_{this};
};

}  // namespace ash

#endif  // ASH_SYSTEM_INPUT_DEVICE_SETTINGS_INPUT_DEVICE_SETTINGS_NOTIFICATION_CONTROLLER_H_