OLD | NEW |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2016 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/options/chromeos/options_stylus_handler.h" | 5 #include "chrome/browser/ui/webui/options/chromeos/options_stylus_handler.h" |
6 | 6 |
7 #include "ash/common/system/chromeos/palette/palette_utils.h" | 7 #include "ash/common/system/chromeos/palette/palette_utils.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
| 12 #include "ui/events/devices/input_device_manager.h" |
12 | 13 |
13 namespace chromeos { | 14 namespace chromeos { |
14 namespace options { | 15 namespace options { |
15 | 16 |
16 namespace { | 17 namespace { |
17 | 18 |
18 // Keys in objects passed to updateNoteTakingApps_. | 19 // Keys in objects passed to updateNoteTakingApps_. |
19 constexpr char kAppNameKey[] = "name"; | 20 constexpr char kAppNameKey[] = "name"; |
20 constexpr char kAppIdKey[] = "id"; | 21 constexpr char kAppIdKey[] = "id"; |
21 constexpr char kAppPreferredKey[] = "preferred"; | 22 constexpr char kAppPreferredKey[] = "preferred"; |
22 | 23 |
23 } // namespace | 24 } // namespace |
24 | 25 |
25 OptionsStylusHandler::OptionsStylusHandler() : weak_ptr_factory_(this) { | 26 OptionsStylusHandler::OptionsStylusHandler() : weak_ptr_factory_(this) { |
26 NoteTakingHelper::Get()->AddObserver(this); | 27 NoteTakingHelper::Get()->AddObserver(this); |
| 28 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
27 } | 29 } |
28 | 30 |
29 OptionsStylusHandler::~OptionsStylusHandler() { | 31 OptionsStylusHandler::~OptionsStylusHandler() { |
| 32 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
30 NoteTakingHelper::Get()->RemoveObserver(this); | 33 NoteTakingHelper::Get()->RemoveObserver(this); |
31 } | 34 } |
32 | 35 |
33 void OptionsStylusHandler::GetLocalizedValues( | 36 void OptionsStylusHandler::GetLocalizedValues( |
34 base::DictionaryValue* localized_strings) { | 37 base::DictionaryValue* localized_strings) { |
35 DCHECK(localized_strings); | 38 DCHECK(localized_strings); |
36 | 39 |
37 RegisterTitle(localized_strings, "stylusOverlay", IDS_SETTINGS_STYLUS_TITLE); | 40 RegisterTitle(localized_strings, "stylusOverlay", IDS_SETTINGS_STYLUS_TITLE); |
38 | 41 |
39 localized_strings->SetString( | 42 localized_strings->SetString( |
(...skipping 13 matching lines...) Expand all Loading... |
53 "stylusNoteTakingApp", | 56 "stylusNoteTakingApp", |
54 l10n_util::GetStringUTF16(IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_LABEL)); | 57 l10n_util::GetStringUTF16(IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_LABEL)); |
55 localized_strings->SetString( | 58 localized_strings->SetString( |
56 "stylusNoteTakingAppNoneAvailable", | 59 "stylusNoteTakingAppNoneAvailable", |
57 l10n_util::GetStringUTF16( | 60 l10n_util::GetStringUTF16( |
58 IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_NONE_AVAILABLE)); | 61 IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_NONE_AVAILABLE)); |
59 localized_strings->SetString( | 62 localized_strings->SetString( |
60 "stylusNoteTakingAppWaitingForAndroid", | 63 "stylusNoteTakingAppWaitingForAndroid", |
61 l10n_util::GetStringUTF16( | 64 l10n_util::GetStringUTF16( |
62 IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_WAITING_FOR_ANDROID)); | 65 IDS_OPTIONS_STYLUS_NOTE_TAKING_APP_WAITING_FOR_ANDROID)); |
63 | |
64 localized_strings->SetBoolean("showStylusSettings", | |
65 ash::IsPaletteFeatureEnabled()); | |
66 } | 66 } |
67 | 67 |
68 void OptionsStylusHandler::InitializePage() { | 68 void OptionsStylusHandler::InitializePage() { |
69 UpdateNoteTakingApps(); | 69 UpdateNoteTakingApps(); |
70 } | 70 } |
71 | 71 |
72 void OptionsStylusHandler::RegisterMessages() { | 72 void OptionsStylusHandler::RegisterMessages() { |
73 web_ui()->RegisterMessageCallback( | 73 web_ui()->RegisterMessageCallback( |
74 "setPreferredNoteTakingApp", | 74 "setPreferredNoteTakingApp", |
75 base::Bind(&OptionsStylusHandler::SetPreferredNoteTakingApp, | 75 base::Bind(&OptionsStylusHandler::SetPreferredNoteTakingApp, |
76 weak_ptr_factory_.GetWeakPtr())); | 76 weak_ptr_factory_.GetWeakPtr())); |
| 77 web_ui()->RegisterMessageCallback( |
| 78 "requestStylusHardwareState", |
| 79 base::Bind(&OptionsStylusHandler::RequestStylusHardwareState, |
| 80 weak_ptr_factory_.GetWeakPtr())); |
77 } | 81 } |
78 | 82 |
79 void OptionsStylusHandler::OnAvailableNoteTakingAppsUpdated() { | 83 void OptionsStylusHandler::OnAvailableNoteTakingAppsUpdated() { |
80 UpdateNoteTakingApps(); | 84 UpdateNoteTakingApps(); |
81 } | 85 } |
82 | 86 |
| 87 void OptionsStylusHandler::OnDeviceListsComplete() { |
| 88 SendHasStylus(); |
| 89 } |
| 90 |
| 91 void OptionsStylusHandler::RequestStylusHardwareState( |
| 92 const base::ListValue* args) { |
| 93 if (ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()) |
| 94 SendHasStylus(); |
| 95 } |
| 96 |
| 97 void OptionsStylusHandler::SendHasStylus() { |
| 98 DCHECK(ui::InputDeviceManager::GetInstance()->AreDeviceListsComplete()); |
| 99 |
| 100 web_ui()->CallJavascriptFunctionUnsafe( |
| 101 "BrowserOptions.setStylusInputStatus", |
| 102 base::FundamentalValue(ash::palette_utils::HasStylusInput())); |
| 103 } |
| 104 |
83 void OptionsStylusHandler::UpdateNoteTakingApps() { | 105 void OptionsStylusHandler::UpdateNoteTakingApps() { |
84 bool waiting_for_android = false; | 106 bool waiting_for_android = false; |
85 note_taking_app_ids_.clear(); | 107 note_taking_app_ids_.clear(); |
86 base::ListValue apps_list; | 108 base::ListValue apps_list; |
87 | 109 |
88 NoteTakingHelper* helper = NoteTakingHelper::Get(); | 110 NoteTakingHelper* helper = NoteTakingHelper::Get(); |
89 if (helper->android_enabled() && !helper->android_apps_received()) { | 111 if (helper->android_enabled() && !helper->android_apps_received()) { |
90 // If Android is enabled but not ready yet, let the JS know so it can | 112 // If Android is enabled but not ready yet, let the JS know so it can |
91 // disable the menu and display an explanatory message. | 113 // disable the menu and display an explanatory message. |
92 waiting_for_android = true; | 114 waiting_for_android = true; |
(...skipping 28 matching lines...) Expand all Loading... |
121 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; | 143 LOG(ERROR) << "Got unknown note-taking-app ID \"" << app_id << "\""; |
122 return; | 144 return; |
123 } | 145 } |
124 | 146 |
125 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), | 147 NoteTakingHelper::Get()->SetPreferredApp(Profile::FromWebUI(web_ui()), |
126 app_id); | 148 app_id); |
127 } | 149 } |
128 | 150 |
129 } // namespace options | 151 } // namespace options |
130 } // namespace chromeos | 152 } // namespace chromeos |
OLD | NEW |