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

Side by Side Diff: chrome/browser/ui/webui/settings/chromeos/keyboard_handler.cc

Issue 1753653002: MD Settings: First half of Device > Keyboard sub-page. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixes Created 4 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 2016 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/ui/webui/settings/chromeos/keyboard_handler.h"
6
7 #include "base/bind.h"
8 #include "base/command_line.h"
9 #include "base/values.h"
10 #include "chrome/browser/profiles/profile.h"
11 #include "chromeos/chromeos_switches.h"
12 #include "content/public/browser/web_ui.h"
13 #include "ui/events/devices/device_data_manager.h"
14 #include "ui/events/devices/keyboard_device.h"
15
16
17 namespace chromeos {
18 namespace settings {
19 namespace {
dschuyler 2016/03/02 01:08:06 I've usually seen anonymous namespaces placed betw
michaelpg 2016/03/02 02:42:06 If I understand you correctly, I don't think it ma
20
21 bool HasExternalKeyboard() {
22 for (const ui::KeyboardDevice& keyboard :
23 ui::DeviceDataManager::GetInstance()->keyboard_devices()) {
24 if (keyboard.type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
25 return true;
26 }
27
28 return false;
29 }
30
31 } // namespace
32
33 KeyboardHandler::KeyboardHandler(content::WebUI* webui)
34 : profile_(Profile::FromWebUI(webui)) {
35 ui::DeviceDataManager::GetInstance()->AddObserver(this);
36 }
37
38 KeyboardHandler::~KeyboardHandler() {
39 ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
40 }
41
42 void KeyboardHandler::RegisterMessages() {
43 web_ui()->RegisterMessageCallback(
44 "initializeKeyboardSettings",
45 base::Bind(&KeyboardHandler::HandleInitialize,
46 base::Unretained(this)));
47 }
48
49 void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() {
50 UpdateShowKeys();
51 }
52
53 void KeyboardHandler::HandleInitialize(const base::ListValue* args) {
54 UpdateShowKeys();
55 }
56
57 void KeyboardHandler::UpdateShowKeys() const {
58 const base::FundamentalValue has_caps_lock(HasExternalKeyboard());
59 const base::FundamentalValue has_diamond_key(
60 base::CommandLine::ForCurrentProcess()->HasSwitch(
61 chromeos::switches::kHasChromeOSDiamondKey));
62 web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
63 base::StringValue("show-keys-changed"),
64 has_caps_lock,
65 has_diamond_key);
66 }
67
68 } // namespace settings
69 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698