OLD | NEW |
(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/device_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 namespace { |
| 17 |
| 18 bool HasExternalKeyboard() { |
| 19 for (const ui::KeyboardDevice& keyboard : |
| 20 ui::DeviceDataManager::GetInstance()->keyboard_devices()) { |
| 21 if (keyboard.type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL) |
| 22 return true; |
| 23 } |
| 24 |
| 25 return false; |
| 26 } |
| 27 |
| 28 } // namespace |
| 29 |
| 30 namespace chromeos { |
| 31 namespace settings { |
| 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 |
OLD | NEW |