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

Side by Side Diff: chrome/browser/chromeos/events/event_rewriter_delegate_impl.cc

Issue 2724913002: Move chromeos::EventRewriter to //ui/chromeos/events (Closed)
Patch Set: Fix build issue 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 unified diff | Download patch
OLDNEW
(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
68 const PrefService::Preference* preference =
69 pref_service->FindPreference(prefs::kLanguageSendFunctionKeys);
70 if (!preference)
71 return false;
72 DCHECK_EQ(preference->GetType(), base::Value::Type::BOOLEAN);
73 return preference->GetValue()->GetBool();
sadrul 2017/03/14 01:15:41 Just use preference->GetBoolean(...), instead of D
Peng 2017/03/14 16:06:52 I checked the code and found the preference object
sadrul 2017/03/16 05:02:43 Sorry, yeah, I was referring to using PrefService:
Peng 2017/03/16 15:44:58 Done.
74 }
75
76 bool EventRewriterDelegateImpl::IsExtensionCommandRegistered(
77 ui::KeyboardCode key_code,
78 int flags) const {
79 // Some keyboard events for ChromeOS get rewritten, such as:
80 // Search+Shift+Left gets converted to Shift+Home (BeginDocument).
81 // This doesn't make sense if the user has assigned that shortcut
82 // to an extension. Because:
83 // 1) The extension would, upon seeing a request for Ctrl+Shift+Home have
84 // to register for Shift+Home, instead.
85 // 2) The conversion is unnecessary, because Shift+Home (BeginDocument) isn't
86 // going to be executed.
87 // Therefore, we skip converting the accelerator if an extension has
88 // registered for this shortcut.
89 Profile* profile = ProfileManager::GetActiveUserProfile();
90 if (!profile || !extensions::ExtensionCommandsGlobalRegistry::Get(profile))
91 return false;
92
93 const int modifiers = flags & (ui::EF_SHIFT_DOWN | ui::EF_CONTROL_DOWN |
94 ui::EF_ALT_DOWN | ui::EF_COMMAND_DOWN);
95 ui::Accelerator accelerator(key_code, modifiers);
96 return extensions::ExtensionCommandsGlobalRegistry::Get(profile)
97 ->IsRegistered(accelerator);
98 }
99
100 const PrefService* EventRewriterDelegateImpl::GetPrefService() const {
101 if (pref_service_for_testing_)
102 return pref_service_for_testing_;
103 Profile* profile = ProfileManager::GetActiveUserProfile();
104 return profile ? profile->GetPrefs() : nullptr;
105 }
106
107 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698