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

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

Issue 2644713002: cros: Use runtime stylus detection for ash palette. (Closed)
Patch Set: Fix test Created 3 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 unified diff | Download patch
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.h" 5 #include "chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.h"
6 6
7 #include "ash/common/system/chromeos/palette/palette_utils.h"
8 #include "base/bind.h"
7 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "ui/events/devices/input_device_manager.h"
8 11
9 namespace chromeos { 12 namespace chromeos {
10 namespace settings { 13 namespace settings {
11 14
12 namespace { 15 namespace {
13 16
14 // Keys in objects passed to onNoteTakingAppsUpdated. 17 // Keys in objects passed to onNoteTakingAppsUpdated.
15 constexpr char kAppNameKey[] = "name"; 18 constexpr char kAppNameKey[] = "name";
16 constexpr char kAppIdKey[] = "value"; 19 constexpr char kAppIdKey[] = "value";
17 constexpr char kAppPreferredKey[] = "preferred"; 20 constexpr char kAppPreferredKey[] = "preferred";
18 21
19 } // namespace 22 } // namespace
20 23
21 StylusHandler::StylusHandler() { 24 StylusHandler::StylusHandler() {
22 NoteTakingHelper::Get()->AddObserver(this); 25 NoteTakingHelper::Get()->AddObserver(this);
26 ui::InputDeviceManager::GetInstance()->AddObserver(this);
23 } 27 }
24 28
25 StylusHandler::~StylusHandler() { 29 StylusHandler::~StylusHandler() {
30 ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
26 NoteTakingHelper::Get()->RemoveObserver(this); 31 NoteTakingHelper::Get()->RemoveObserver(this);
27 } 32 }
28 33
29 void StylusHandler::RegisterMessages() { 34 void StylusHandler::RegisterMessages() {
30 DCHECK(web_ui()); 35 DCHECK(web_ui());
31 36
32 web_ui()->RegisterMessageCallback( 37 web_ui()->RegisterMessageCallback(
38 "initializeStylusSettings",
39 base::Bind(&StylusHandler::HandleInitialize, base::Unretained(this)));
40 web_ui()->RegisterMessageCallback(
33 "requestNoteTakingApps", 41 "requestNoteTakingApps",
34 base::Bind(&StylusHandler::RequestApps, base::Unretained(this))); 42 base::Bind(&StylusHandler::RequestApps, base::Unretained(this)));
35 web_ui()->RegisterMessageCallback( 43 web_ui()->RegisterMessageCallback(
36 "setPreferredNoteTakingApp", 44 "setPreferredNoteTakingApp",
37 base::Bind(&StylusHandler::SetPreferredNoteTakingApp, 45 base::Bind(&StylusHandler::SetPreferredNoteTakingApp,
38 base::Unretained(this))); 46 base::Unretained(this)));
39 } 47 }
40 48
41 void StylusHandler::OnAvailableNoteTakingAppsUpdated() { 49 void StylusHandler::OnAvailableNoteTakingAppsUpdated() {
42 UpdateNoteTakingApps(); 50 UpdateNoteTakingApps();
43 } 51 }
44 52
53 void StylusHandler::OnDeviceListsComplete() {
54 SendHasStylus();
55 }
56
45 void StylusHandler::UpdateNoteTakingApps() { 57 void StylusHandler::UpdateNoteTakingApps() {
46 bool waiting_for_android = false; 58 bool waiting_for_android = false;
47 note_taking_app_ids_.clear(); 59 note_taking_app_ids_.clear();
48 base::ListValue apps_list; 60 base::ListValue apps_list;
49 61
50 NoteTakingHelper* helper = NoteTakingHelper::Get(); 62 NoteTakingHelper* helper = NoteTakingHelper::Get();
51 if (helper->android_enabled() && !helper->android_apps_received()) { 63 if (helper->android_enabled() && !helper->android_apps_received()) {
52 // If Android is enabled but not ready yet, let the JS know so it can 64 // If Android is enabled but not ready yet, let the JS know so it can
53 // disable the menu and display an explanatory message. 65 // disable the menu and display an explanatory message.
54 waiting_for_android = true; 66 waiting_for_android = true;
(...skipping 29 matching lines...) Expand all
84 // currently-available set. 96 // currently-available set.
85 if (!note_taking_app_ids_.count(app_id)) { 97 if (!note_taking_app_ids_.count(app_id)) {
86 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; 98 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\"";
87 return; 99 return;
88 } 100 }
89 101
90 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), 102 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()),
91 app_id); 103 app_id);
92 } 104 }
93 105
106 void StylusHandler::HandleInitialize(const base::ListValue* args) {
107 AllowJavascript();
108 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete())
109 SendHasStylus();
110 }
111
112 void StylusHandler::SendHasStylus() {
113 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete());
114 CallJavascriptFunction(
115 "cr.webUIListenerCallback", base::StringValue("has-stylus-changed"),
116 base::FundamentalValue(ash::palette_utils::HasStylusInput()));
117 }
118
94 } // namespace settings 119 } // namespace settings
95 } // namespace chromeos 120 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/webui/settings/chromeos/device_stylus_handler.h ('k') | chrome/browser/ui/webui/settings/md_settings_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698