File: event_rewriter_delegate_impl.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (136 lines) | stat: -rw-r--r-- 5,797 bytes parent folder | download | duplicates (6)
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
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_ASH_EVENTS_EVENT_REWRITER_DELEGATE_IMPL_H_
#define CHROME_BROWSER_ASH_EVENTS_EVENT_REWRITER_DELEGATE_IMPL_H_

#include <optional>
#include <utility>

#include "ash/public/cpp/input_device_settings_controller.h"
#include "base/containers/flat_set.h"
#include "base/memory/raw_ptr.h"
#include "ui/events/ash/event_rewriter_ash.h"
#include "ui/events/ash/mojom/extended_fkeys_modifier.mojom-shared.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/wm/public/activation_client.h"

class PrefService;

namespace ash {

class DeprecationNotificationController;
class InputDeviceSettingsNotificationController;

class EventRewriterDelegateImpl : public ui::EventRewriterAsh::Delegate {
 public:
  explicit EventRewriterDelegateImpl(wm::ActivationClient* activation_client);
  EventRewriterDelegateImpl(
      wm::ActivationClient* activation_client,
      std::unique_ptr<DeprecationNotificationController> deprecation_controller,
      std::unique_ptr<InputDeviceSettingsNotificationController>
          input_device_settings_notification_controller,
      InputDeviceSettingsController* input_device_settings_controller);

  EventRewriterDelegateImpl(const EventRewriterDelegateImpl&) = delete;
  EventRewriterDelegateImpl& operator=(const EventRewriterDelegateImpl&) =
      delete;

  ~EventRewriterDelegateImpl() override;

  void set_pref_service_for_testing(PrefService* pref_service) {
    pref_service_for_testing_ = pref_service;
  }

  // ui::EventRewriterAsh::Delegate:
  bool RewriteModifierKeys() override;
  bool RewriteMetaTopRowKeyComboEvents(int device_id) const override;
  std::optional<ui::mojom::ModifierKey> GetKeyboardRemappedModifierValue(
      int device_id,
      ui::mojom::ModifierKey modifier_key,
      const std::string& pref_name) const override;
  bool TopRowKeysAreFunctionKeys(int device_id) const override;
  bool IsExtensionCommandRegistered(ui::KeyboardCode key_code,
                                    int flags) const override;
  bool IsSearchKeyAcceleratorReserved() const override;
  bool NotifyDeprecatedRightClickRewrite() override;
  bool NotifyDeprecatedSixPackKeyRewrite(ui::KeyboardCode key_code) override;
  void SuppressModifierKeyRewrites(bool should_suppress) override;
  void SuppressMetaTopRowKeyComboRewrites(bool should_suppress) override;
  void RecordEventRemappedToRightClick(bool alt_based_right_click) override;
  void RecordSixPackEventRewrite(ui::KeyboardCode key_code,
                                 bool alt_based) override;
  std::optional<ui::mojom::SimulateRightClickModifier>
  GetRemapRightClickModifier(int device_id) override;
  std::optional<ui::mojom::SixPackShortcutModifier>
  GetShortcutModifierForSixPackKey(int device_id,
                                   ui::KeyboardCode key_code) override;
  void NotifyRightClickRewriteBlockedBySetting(
      ui::mojom::SimulateRightClickModifier blocked_modifier,
      ui::mojom::SimulateRightClickModifier active_modifier) override;

  void NotifySixPackRewriteBlockedBySetting(
      ui::KeyboardCode key_code,
      ui::mojom::SixPackShortcutModifier blocked_modifier,
      ui::mojom::SixPackShortcutModifier active_modifier,
      int device_id) override;

  std::optional<ui::mojom::ExtendedFkeysModifier> GetExtendedFkeySetting(
      int device_id,
      ui::KeyboardCode key_code) override;

  // Push a notification when the device has an Fn key and six pack shortcut
  // with search key is pressed.
  void NotifySixPackRewriteBlockedByFnKey(
      ui::KeyboardCode key_code,
      ui::mojom::SixPackShortcutModifier modifier) override;

  // Push a notification when the device has an Fn key and search plus top
  // row key is pressed.
  void NotifyTopRowRewriteBlockedByFnKey() override;

  // Workaround for test behavior injection.
  // Currently, there's no easier way to inject
  // ExtensionCommandsGlobalRegistry's behavior, so difficult to test
  // EventRewriterAsh with changing IsExtensionCommandRegistered's behavior.
  // Introducing a fake class of Delegate implementation can solve the issue,
  // but without further larger refactoring some testing coverage will be lost.
  // This API is for the mitigation for short term.
  // TODO(crbug.com/40265877): Consider clear separation of EventRewriterAsh's
  // test and Delegate's test, then to remove this API.
  void SetExtensionCommandsOverrideForTesting(
      std::optional<base::flat_set<std::pair<ui::KeyboardCode, int>>>
          commands) {
    extension_commands_override_for_testing_ = std::move(commands);
  }

 private:
  PrefService* GetPrefService() const;

  raw_ptr<PrefService> pref_service_for_testing_;

  std::optional<base::flat_set<std::pair<ui::KeyboardCode, int>>>
      extension_commands_override_for_testing_;

  raw_ptr<wm::ActivationClient, DanglingUntriaged> activation_client_;

  // Handles showing notifications when deprecated event rewrites occur.
  std::unique_ptr<DeprecationNotificationController> deprecation_controller_;
  std::unique_ptr<InputDeviceSettingsNotificationController>
      input_device_settings_notification_controller_;

  // Tracks whether modifier rewrites should be suppressed or not.
  bool suppress_modifier_key_rewrites_ = false;

  // Tracks whether meta + top row key rewrites should be suppressed or not.
  bool suppress_meta_top_row_key_rewrites_ = false;

  raw_ptr<InputDeviceSettingsController, DanglingUntriaged>
      input_device_settings_controller_;
};

}  // namespace ash

#endif  // CHROME_BROWSER_ASH_EVENTS_EVENT_REWRITER_DELEGATE_IMPL_H_