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/magnifier/partial_magnification_controller.h" | 9 #include "ash/magnifier/partial_magnification_controller.h" |
10 #include "ash/screenshot_delegate.h" | 10 #include "ash/screenshot_delegate.h" |
11 #include "ash/shell.h" | 11 #include "ash/shell.h" |
12 #include "ash/utility/screenshot_controller.h" | 12 #include "ash/utility/screenshot_controller.h" |
13 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
15 #include "chrome/browser/chromeos/note_taking_helper.h" | 15 #include "chrome/browser/chromeos/note_taking_helper.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 16 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 18 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
20 #include "components/prefs/pref_change_registrar.h" | 20 #include "components/prefs/pref_change_registrar.h" |
21 #include "components/prefs/pref_service.h" | 21 #include "components/prefs/pref_service.h" |
22 #include "components/user_manager/user_manager.h" | 22 #include "components/user_manager/user_manager.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
25 #include "ui/events/devices/input_device_manager.h" | |
26 | 25 |
27 namespace chromeos { | 26 namespace chromeos { |
28 | 27 |
29 // static | |
30 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { | |
31 if (!ash::IsPaletteFeatureEnabled()) | |
32 return nullptr; | |
33 return base::WrapUnique(new PaletteDelegateChromeOS()); | |
34 } | |
35 | |
36 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { | 28 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
37 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 29 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
38 content::NotificationService::AllSources()); | 30 content::NotificationService::AllSources()); |
39 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 31 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
40 content::NotificationService::AllSources()); | 32 content::NotificationService::AllSources()); |
41 | |
42 ui::InputDeviceManager::GetInstance()->AddObserver(this); | |
43 } | 33 } |
44 | 34 |
45 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() { | 35 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} |
46 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | |
47 } | |
48 | 36 |
49 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> | 37 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> |
50 PaletteDelegateChromeOS::AddPaletteEnableListener( | 38 PaletteDelegateChromeOS::AddPaletteEnableListener( |
51 const EnableListener& on_state_changed) { | 39 const EnableListener& on_state_changed) { |
52 auto subscription = palette_enabled_callback_list_.Add(on_state_changed); | 40 auto subscription = palette_enabled_callback_list_.Add(on_state_changed); |
53 OnPaletteEnabledPrefChanged(); | 41 OnPaletteEnabledPrefChanged(); |
54 return subscription; | 42 return subscription; |
55 } | 43 } |
56 | 44 |
57 void PaletteDelegateChromeOS::CreateNote() { | 45 void PaletteDelegateChromeOS::CreateNote() { |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 if (then) | 119 if (then) |
132 then.Run(); | 120 then.Run(); |
133 } | 121 } |
134 | 122 |
135 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { | 123 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { |
136 ash::PartialMagnificationController* controller = | 124 ash::PartialMagnificationController* controller = |
137 ash::Shell::GetInstance()->partial_magnification_controller(); | 125 ash::Shell::GetInstance()->partial_magnification_controller(); |
138 controller->SetEnabled(enabled); | 126 controller->SetEnabled(enabled); |
139 } | 127 } |
140 | 128 |
141 void PaletteDelegateChromeOS::SetStylusStateChangedCallback( | |
142 const OnStylusStateChangedCallback& on_stylus_state_changed) { | |
143 on_stylus_state_changed_ = on_stylus_state_changed; | |
144 } | |
145 | |
146 bool PaletteDelegateChromeOS::ShouldAutoOpenPalette() { | 129 bool PaletteDelegateChromeOS::ShouldAutoOpenPalette() { |
147 if (!profile_) | 130 if (!profile_) |
148 return false; | 131 return false; |
149 | 132 |
150 return profile_->GetPrefs()->GetBoolean(prefs::kLaunchPaletteOnEjectEvent); | 133 return profile_->GetPrefs()->GetBoolean(prefs::kLaunchPaletteOnEjectEvent); |
151 } | 134 } |
152 | 135 |
153 bool PaletteDelegateChromeOS::ShouldShowPalette() { | 136 bool PaletteDelegateChromeOS::ShouldShowPalette() { |
154 if (!profile_) | 137 if (!profile_) |
155 return false; | 138 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
176 screenshot_delegate, false /* draw_overlay_immediately */); | 159 screenshot_delegate, false /* draw_overlay_immediately */); |
177 screenshot_controller->set_on_screenshot_session_done( | 160 screenshot_controller->set_on_screenshot_session_done( |
178 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | 161 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, |
179 weak_factory_.GetWeakPtr(), done)); | 162 weak_factory_.GetWeakPtr(), done)); |
180 } | 163 } |
181 | 164 |
182 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | 165 void PaletteDelegateChromeOS::CancelPartialScreenshot() { |
183 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); | 166 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); |
184 } | 167 } |
185 | 168 |
186 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { | |
187 on_stylus_state_changed_.Run(state); | |
188 } | |
189 } // namespace chromeos | 169 } // namespace chromeos |
OLD | NEW |