Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/chromeos/events/event_rewriter_delegate_impl.h" | |
| 6 | |
| 7 #include "chrome/browser/chromeos/login/ui/login_display_host.h" | |
| 8 #include "chrome/browser/extensions/extension_commands_global_registry.h" | |
| 9 #include "chrome/browser/profiles/profile_manager.h" | |
| 10 #include "chrome/browser/ui/webui/chromeos/login/oobe_ui.h" | |
| 11 #include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h" | |
| 12 #include "chrome/common/pref_names.h" | |
| 13 #include "components/prefs/pref_service.h" | |
| 14 #include "components/user_manager/user_manager.h" | |
| 15 | |
| 16 namespace chromeos { | |
| 17 | |
| 18 EventRewriterDelegateImpl::EventRewriterDelegateImpl() | |
| 19 : pref_service_for_testing_(nullptr) {} | |
| 20 | |
| 21 EventRewriterDelegateImpl::~EventRewriterDelegateImpl() {} | |
| 22 | |
| 23 bool EventRewriterDelegateImpl::RewriteModifierKeys() { | |
| 24 // Do nothing if we have just logged in as guest but have not restarted chrome | |
| 25 // process yet (so we are still on the login screen). In this situations we | |
| 26 // have no user profile so can not do anything useful. | |
| 27 // Note that currently, unlike other accounts, when user logs in as guest, we | |
| 28 // restart chrome process. In future this is to be changed. | |
| 29 // TODO(glotov): remove the following condition when we do not restart chrome | |
| 30 // when user logs in as guest. | |
| 31 // TODO(kpschoedel): check whether this is still necessary. | |
| 32 if (user_manager::UserManager::Get()->IsLoggedInAsGuest() && | |
| 33 LoginDisplayHost::default_host()) | |
| 34 return false; | |
| 35 return true; | |
| 36 } | |
| 37 | |
| 38 bool EventRewriterDelegateImpl::GetKeyboardRemappedPrefValue( | |
| 39 const std::string& pref_name, | |
| 40 int* value) const { | |
| 41 DCHECK(value); | |
| 42 // If we're at the login screen, try to get the pref from the global prefs | |
| 43 // dictionary. | |
| 44 if (LoginDisplayHost::default_host() && | |
| 45 LoginDisplayHost::default_host() | |
| 46 ->GetOobeUI() | |
| 47 ->signin_screen_handler() | |
| 48 ->GetKeyboardRemappedPrefValue(pref_name, value)) | |
| 49 return true; | |
| 50 const PrefService* pref_service = GetPrefService(); | |
| 51 if (!pref_service) | |
| 52 return false; | |
| 53 const PrefService::Preference* preference = | |
| 54 pref_service->FindPreference(pref_name); | |
| 55 if (!preference) | |
| 56 return false; | |
| 57 | |
| 58 DCHECK_EQ(preference->GetType(), base::Value::Type::INTEGER); | |
| 59 *value = preference->GetValue()->GetInt(); | |
| 60 return true; | |
| 61 } | |
| 62 | |
| 63 bool EventRewriterDelegateImpl::TopRowKeysAreFunctionKeys() const { | |
| 64 const PrefService* pref_service = GetPrefService(); | |
| 65 if (!pref_service) | |
| 66 return false; | |
| 67 return pref_service->GetBoolean(prefs::kLanguageSendFunctionKeys); | |
| 68 } | |
| 69 | |
| 70 bool EventRewriterDelegateImpl::IsExtensionCommandRegistered( | |
| 71 ui::KeyboardCode key_code, | |
| 72 int flags) const { | |
| 73 // Some keyboard events for ChromeOS get rewritten, such as: | |
| 74 // Search+Shift+Left gets converted to Shift+Home (BeginDocument). | |
| 75 // This doesn't make sense if the user has assigned that shortcut | |
| 76 // to an extension. Because: | |
| 77 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have | |
| 78 // to register for Shift+Home, instead. | |
| 79 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't | |
| 80 // going to be executed. | |
| 81 // Therefore, we skip converting the accelerator if an extension has | |
| 82 // registered for this shortcut. | |
| 83 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 84 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile)) | |
| 85 return false; | |
| 86 | |
| 87 const int modifiers = flags & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN | | |
| 88 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN); | |
|
oshima
2017/03/16 18:51:08
nit: define mask as constexpr. you may inline modi
Peng
2017/03/16 20:33:27
Done.
| |
| 89 ui::Accelerator accelerator(key_code, modifiers); | |
| 90 return extensions::ExtensionCommandsGlobalRegistry::Get(profile) | |
| 91 ->IsRegistered(accelerator); | |
| 92 } | |
| 93 | |
| 94 const PrefService* EventRewriterDelegateImpl::GetPrefService() const { | |
| 95 if (pref_service_for_testing_) | |
| 96 return pref_service_for_testing_; | |
| 97 Profile* profile = ProfileManager::GetActiveUserProfile(); | |
| 98 return profile ? profile->GetPrefs() : nullptr; | |
| 99 } | |
| 100 | |
| 101 } // namespace chromeos | |
| OLD | NEW |