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

Unified 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, 10 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/ui/webui/settings/chromeos/keyboard_handler.cc
diff --git a/chrome/browser/ui/webui/settings/chromeos/keyboard_handler.cc b/chrome/browser/ui/webui/settings/chromeos/keyboard_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ec65b99358b30f87ceeee046b9a8e03e419bf966
--- /dev/null
+++ b/chrome/browser/ui/webui/settings/chromeos/keyboard_handler.cc
@@ -0,0 +1,69 @@
+// Copyright 2016 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/ui/webui/settings/chromeos/keyboard_handler.h"
+
+#include "base/bind.h"
+#include "base/command_line.h"
+#include "base/values.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chromeos/chromeos_switches.h"
+#include "content/public/browser/web_ui.h"
+#include "ui/events/devices/device_data_manager.h"
+#include "ui/events/devices/keyboard_device.h"
+
+
+namespace chromeos {
+namespace settings {
+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
+
+bool HasExternalKeyboard() {
+ for (const ui::KeyboardDevice& keyboard :
+ ui::DeviceDataManager::GetInstance()->keyboard_devices()) {
+ if (keyboard.type == ui::InputDeviceType::INPUT_DEVICE_EXTERNAL)
+ return true;
+ }
+
+ return false;
+}
+
+} // namespace
+
+KeyboardHandler::KeyboardHandler(content::WebUI* webui)
+ : profile_(Profile::FromWebUI(webui)) {
+ ui::DeviceDataManager::GetInstance()->AddObserver(this);
+}
+
+KeyboardHandler::~KeyboardHandler() {
+ ui::DeviceDataManager::GetInstance()->RemoveObserver(this);
+}
+
+void KeyboardHandler::RegisterMessages() {
+ web_ui()->RegisterMessageCallback(
+ "initializeKeyboardSettings",
+ base::Bind(&KeyboardHandler::HandleInitialize,
+ base::Unretained(this)));
+}
+
+void KeyboardHandler::OnKeyboardDeviceConfigurationChanged() {
+ UpdateShowKeys();
+}
+
+void KeyboardHandler::HandleInitialize(const base::ListValue* args) {
+ UpdateShowKeys();
+}
+
+void KeyboardHandler::UpdateShowKeys() const {
+ const base::FundamentalValue has_caps_lock(HasExternalKeyboard());
+ const base::FundamentalValue has_diamond_key(
+ base::CommandLine::ForCurrentProcess()->HasSwitch(
+ chromeos::switches::kHasChromeOSDiamondKey));
+ web_ui()->CallJavascriptFunction("cr.webUIListenerCallback",
+ base::StringValue("show-keys-changed"),
+ has_caps_lock,
+ has_diamond_key);
+}
+
+} // namespace settings
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698