OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 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/ash/palette_delegate_chromeos.h" | 5 #include "chrome/browser/ui/ash/palette_delegate_chromeos.h" |
6 | 6 |
7 #include "ash/accelerators/accelerator_controller_delegate_aura.h" | 7 #include "ash/accelerators/accelerator_controller_delegate_aura.h" |
8 #include "ash/common/system/chromeos/palette/palette_utils.h" | 8 #include "ash/common/system/chromeos/palette/palette_utils.h" |
9 #include "ash/screenshot_delegate.h" | 9 #include "ash/screenshot_delegate.h" |
10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
11 #include "ash/utility/screenshot_controller.h" | 11 #include "ash/utility/screenshot_controller.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
14 #include "chrome/browser/chromeos/note_taking_helper.h" | 14 #include "chrome/browser/chromeos/note_taking_helper.h" |
15 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 15 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
16 #include "chrome/browser/profiles/profile.h" | 16 #include "chrome/browser/profiles/profile.h" |
17 #include "chrome/browser/profiles/profile_manager.h" | 17 #include "chrome/browser/profiles/profile_manager.h" |
18 #include "chrome/common/pref_names.h" | 18 #include "chrome/common/pref_names.h" |
19 #include "components/prefs/pref_change_registrar.h" | 19 #include "components/prefs/pref_change_registrar.h" |
20 #include "components/prefs/pref_service.h" | 20 #include "components/prefs/pref_service.h" |
21 #include "components/user_manager/user_manager.h" | 21 #include "components/user_manager/user_manager.h" |
22 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
23 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
24 #include "ui/events/devices/input_device_manager.h" | |
25 | 24 |
26 namespace chromeos { | 25 namespace chromeos { |
27 | 26 |
28 // static | |
29 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { | |
30 if (!ash::IsPaletteFeatureEnabled()) | |
31 return nullptr; | |
32 return base::WrapUnique(new PaletteDelegateChromeOS()); | |
33 } | |
34 | |
35 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { | 27 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
36 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 28 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
37 content::NotificationService::AllSources()); | 29 content::NotificationService::AllSources()); |
38 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 30 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
39 content::NotificationService::AllSources()); | 31 content::NotificationService::AllSources()); |
40 | |
41 ui::InputDeviceManager::GetInstance()->AddObserver(this); | |
42 } | 32 } |
43 | 33 |
44 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() { | 34 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} |
45 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | |
46 } | |
47 | 35 |
48 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> | 36 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> |
49 PaletteDelegateChromeOS::AddPaletteEnableListener( | 37 PaletteDelegateChromeOS::AddPaletteEnableListener( |
50 const EnableListener& on_state_changed) { | 38 const EnableListener& on_state_changed) { |
51 auto subscription = palette_enabled_callback_list_.Add(on_state_changed); | 39 auto subscription = palette_enabled_callback_list_.Add(on_state_changed); |
52 OnPaletteEnabledPrefChanged(); | 40 OnPaletteEnabledPrefChanged(); |
53 return subscription; | 41 return subscription; |
54 } | 42 } |
55 | 43 |
56 void PaletteDelegateChromeOS::CreateNote() { | 44 void PaletteDelegateChromeOS::CreateNote() { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 // Run listener with new pref value, if any. | 112 // Run listener with new pref value, if any. |
125 OnPaletteEnabledPrefChanged(); | 113 OnPaletteEnabledPrefChanged(); |
126 } | 114 } |
127 | 115 |
128 void PaletteDelegateChromeOS::OnPartialScreenshotDone( | 116 void PaletteDelegateChromeOS::OnPartialScreenshotDone( |
129 const base::Closure& then) { | 117 const base::Closure& then) { |
130 if (then) | 118 if (then) |
131 then.Run(); | 119 then.Run(); |
132 } | 120 } |
133 | 121 |
134 void PaletteDelegateChromeOS::SetStylusStateChangedCallback( | |
135 const OnStylusStateChangedCallback& on_stylus_state_changed) { | |
136 on_stylus_state_changed_ = on_stylus_state_changed; | |
137 } | |
138 | |
139 bool PaletteDelegateChromeOS::ShouldAutoOpenPalette() { | 122 bool PaletteDelegateChromeOS::ShouldAutoOpenPalette() { |
140 if (!profile_) | 123 if (!profile_) |
141 return false; | 124 return false; |
142 | 125 |
143 return profile_->GetPrefs()->GetBoolean(prefs::kLaunchPaletteOnEjectEvent); | 126 return profile_->GetPrefs()->GetBoolean(prefs::kLaunchPaletteOnEjectEvent); |
144 } | 127 } |
145 | 128 |
146 bool PaletteDelegateChromeOS::ShouldShowPalette() { | 129 bool PaletteDelegateChromeOS::ShouldShowPalette() { |
147 if (!profile_) | 130 if (!profile_) |
148 return false; | 131 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
169 screenshot_delegate, false /* draw_overlay_immediately */); | 152 screenshot_delegate, false /* draw_overlay_immediately */); |
170 screenshot_controller->set_on_screenshot_session_done( | 153 screenshot_controller->set_on_screenshot_session_done( |
171 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | 154 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, |
172 weak_factory_.GetWeakPtr(), done)); | 155 weak_factory_.GetWeakPtr(), done)); |
173 } | 156 } |
174 | 157 |
175 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | 158 void PaletteDelegateChromeOS::CancelPartialScreenshot() { |
176 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); | 159 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); |
177 } | 160 } |
178 | 161 |
179 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { | |
180 on_stylus_state_changed_.Run(state); | |
181 } | |
182 } // namespace chromeos | 162 } // namespace chromeos |
OLD | NEW |