Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2024)

Unified Diff: chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc

Issue 2724913002: Move chromeos::EventRewriter to //ui/chromeos/events (Closed)
Patch Set: Fix a typo Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc
diff --git a/chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc b/chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cd4d32658ccbff6cc1f240cf8dcef8f94a0abc56
--- /dev/null
+++ b/chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc
@@ -0,0 +1,101 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/chromeos/events/event_rewriter_delegate_impl.h"
+
+#include "chrome/browser/chromeos/login/ui/login_display_host.h"
+#include "chrome/browser/extensions/extension_commands_global_registry.h"
+#include "chrome/browser/profiles/profile_manager.h"
+#include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h"
+#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
+#include "chrome/common/pref_names.h"
+#include "components/prefs/pref_service.h"
+#include "components/user_manager/user_manager.h"
+
+namespace chromeos {
+
+EventRewriterDelegateImpl::EventRewriterDelegateImpl()
+ : pref_service_for_testing_(nullptr) {}
+
+EventRewriterDelegateImpl::~EventRewriterDelegateImpl() {}
+
+bool EventRewriterDelegateImpl::RewriteModifierKeys() {
+ // Do nothing if we have just logged in as guest but have not restarted chrome
+ // process yet (so we are still on the login screen). In this situations we
+ // have no user profile so can not do anything useful.
+ // Note that currently, unlike other accounts, when user logs in as guest, we
+ // restart chrome process. In future this is to be changed.
+ // TODO(glotov): remove the following condition when we do not restart chrome
+ // when user logs in as guest.
+ // TODO(kpschoedel): check whether this is still necessary.
+ if (user_manager::UserManager::Get()->IsLoggedInAsGuest() &&
+ LoginDisplayHost::default_host())
+ return false;
+ return true;
+}
+
+bool EventRewriterDelegateImpl::GetKeyboardRemappedPrefValue(
+ const std::string& pref_name,
+ int* value) const {
+ DCHECK(value);
+ // If we're at the login screen, try to get the pref from the global prefs
+ // dictionary.
+ if (LoginDisplayHost::default_host() &&
+ LoginDisplayHost::default_host()
+ ->GetOobeUI()
+ ->signin_screen_handler()
+ ->GetKeyboardRemappedPrefValue(pref_name, value))
+ return true;
+ const PrefService* pref_service = GetPrefService();
+ if (!pref_service)
+ return false;
+ const PrefService::Preference* preference =
+ pref_service->FindPreference(pref_name);
+ if (!preference)
+ return false;
+
+ DCHECK_EQ(preference->GetType(), base::Value::Type::INTEGER);
+ *value = preference->GetValue()->GetInt();
+ return true;
+}
+
+bool EventRewriterDelegateImpl::TopRowKeysAreFunctionKeys() const {
+ const PrefService* pref_service = GetPrefService();
+ if (!pref_service)
+ return false;
+ return pref_service->GetBoolean(prefs::kLanguageSendFunctionKeys);
+}
+
+bool EventRewriterDelegateImpl::IsExtensionCommandRegistered(
+ ui::KeyboardCode key_code,
+ int flags) const {
+ // Some keyboard events for ChromeOS get rewritten, such as:
+ // Search+Shift+Left gets converted to Shift+Home (BeginDocument).
+ // This doesn't make sense if the user has assigned that shortcut
+ // to an extension. Because:
+ // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have
+ // to register for Shift+Home, instead.
+ // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't
+ // going to be executed.
+ // Therefore, we skip converting the accelerator if an extension has
+ // registered for this shortcut.
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile))
+ return false;
+
+ constexpr int kModifierMasks = ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
+ ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN;
+ ui::Accelerator accelerator(key_code, flags & kModifierMasks);
+ return extensions::ExtensionCommandsGlobalRegistry::Get(profile)
+ ->IsRegistered(accelerator);
+}
+
+const PrefService* EventRewriterDelegateImpl::GetPrefService() const {
+ if (pref_service_for_testing_)
+ return pref_service_for_testing_;
+ Profile* profile = ProfileManager::GetActiveUserProfile();
+ return profile ? profile->GetPrefs() : nullptr;
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698