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

Side by Side Diff: chrome/browser/ui/ash/palette_delegate_chromeos.cc

Issue 2291913002: Allow the user to cancel the capture region action, and show its active status in the tray. (Closed)
Patch Set: Address comments Created 4 years, 3 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
« no previous file with comments | « chrome/browser/ui/ash/palette_delegate_chromeos.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/chromeos/note_taking_app_utils.h" 14 #include "chrome/browser/chromeos/note_taking_app_utils.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" 24 #include "ui/events/devices/input_device_manager.h"
25 25
26 namespace chromeos { 26 namespace chromeos {
27 27
28 class PaletteDelegateChromeOS::ProxyScreenshotDelegate
29 : public ash::ScreenshotDelegate {
30 public:
31 ProxyScreenshotDelegate(ash::ScreenshotDelegate* delegate,
32 const base::Closure& on_partial_screenshot_taken)
33 : delegate_(delegate),
34 on_partial_screenshot_taken_(on_partial_screenshot_taken) {}
35 ~ProxyScreenshotDelegate() override {}
36
37 private:
38 // ash::ScreenshotDelegate:
39 void HandleTakeScreenshotForAllRootWindows() override {
40 return delegate_->HandleTakeScreenshotForAllRootWindows();
41 }
42 void HandleTakePartialScreenshot(aura::Window* window,
43 const gfx::Rect& rect) override {
44 delegate_->HandleTakePartialScreenshot(window, rect);
45
46 // Run the delegate last, as it may delete this object.
47 if (on_partial_screenshot_taken_)
48 on_partial_screenshot_taken_.Run();
49 }
50 void HandleTakeWindowScreenshot(aura::Window* window) override {
51 return delegate_->HandleTakeWindowScreenshot(window);
52 }
53 bool CanTakeScreenshot() override { return delegate_->CanTakeScreenshot(); }
54
55 // Not owned; delegate_ is expected to live beyond the lifetime of this
56 // object.
57 ash::ScreenshotDelegate* delegate_;
58 base::Closure on_partial_screenshot_taken_;
59
60 DISALLOW_COPY_AND_ASSIGN(ProxyScreenshotDelegate);
61 };
62
28 // static 63 // static
29 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { 64 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() {
30 if (!ash::IsPaletteFeatureEnabled()) 65 if (!ash::IsPaletteFeatureEnabled())
31 return nullptr; 66 return nullptr;
32 return base::WrapUnique(new PaletteDelegateChromeOS()); 67 return base::WrapUnique(new PaletteDelegateChromeOS());
33 } 68 }
34 69
35 PaletteDelegateChromeOS::PaletteDelegateChromeOS() { 70 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) {
36 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, 71 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
37 content::NotificationService::AllSources()); 72 content::NotificationService::AllSources());
38 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 73 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
39 content::NotificationService::AllSources()); 74 content::NotificationService::AllSources());
40 75
41 ui::InputDeviceManager::GetInstance()->AddObserver(this); 76 ui::InputDeviceManager::GetInstance()->AddObserver(this);
42 } 77 }
43 78
44 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() { 79 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {
45 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); 80 ui::InputDeviceManager::GetInstance()->RemoveObserver(this);
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 pref_change_registrar_->Init(prefs); 152 pref_change_registrar_->Init(prefs);
118 pref_change_registrar_->Add( 153 pref_change_registrar_->Add(
119 prefs::kEnableStylusTools, 154 prefs::kEnableStylusTools,
120 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged, 155 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged,
121 base::Unretained(this))); 156 base::Unretained(this)));
122 157
123 // Run listener with new pref value, if any. 158 // Run listener with new pref value, if any.
124 OnPaletteEnabledPrefChanged(); 159 OnPaletteEnabledPrefChanged();
125 } 160 }
126 161
162 void PaletteDelegateChromeOS::OnPartialScreenshotDone(
163 const base::Closure& then) {
164 proxy_screenshot_delegate_.reset();
165 if (then)
166 then.Run();
167 }
168
127 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { 169 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) {
128 ash::PartialMagnificationController* controller = 170 ash::PartialMagnificationController* controller =
129 ash::Shell::GetInstance()->partial_magnification_controller(); 171 ash::Shell::GetInstance()->partial_magnification_controller();
130 controller->SetEnabled(enabled); 172 controller->SetEnabled(enabled);
131 } 173 }
132 174
133 void PaletteDelegateChromeOS::SetStylusStateChangedCallback( 175 void PaletteDelegateChromeOS::SetStylusStateChangedCallback(
134 const OnStylusStateChangedCallback& on_stylus_state_changed) { 176 const OnStylusStateChangedCallback& on_stylus_state_changed) {
135 on_stylus_state_changed_ = on_stylus_state_changed; 177 on_stylus_state_changed_ = on_stylus_state_changed;
136 } 178 }
(...skipping 12 matching lines...) Expand all
149 return profile_->GetPrefs()->GetBoolean(prefs::kEnableStylusTools); 191 return profile_->GetPrefs()->GetBoolean(prefs::kEnableStylusTools);
150 } 192 }
151 193
152 void PaletteDelegateChromeOS::TakeScreenshot() { 194 void PaletteDelegateChromeOS::TakeScreenshot() {
153 auto* screenshot_delegate = ash::Shell::GetInstance() 195 auto* screenshot_delegate = ash::Shell::GetInstance()
154 ->accelerator_controller_delegate() 196 ->accelerator_controller_delegate()
155 ->screenshot_delegate(); 197 ->screenshot_delegate();
156 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); 198 screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
157 } 199 }
158 200
159 void PaletteDelegateChromeOS::TakePartialScreenshot() { 201 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) {
160 auto* screenshot_controller = 202 auto* screenshot_controller =
161 ash::Shell::GetInstance()->screenshot_controller(); 203 ash::Shell::GetInstance()->screenshot_controller();
162 auto* screenshot_delegate = ash::Shell::GetInstance() 204 auto* screenshot_delegate = ash::Shell::GetInstance()
163 ->accelerator_controller_delegate() 205 ->accelerator_controller_delegate()
164 ->screenshot_delegate(); 206 ->screenshot_delegate();
165 207
208 proxy_screenshot_delegate_ = base::MakeUnique<ProxyScreenshotDelegate>(
209 screenshot_delegate,
210 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone,
211 weak_factory_.GetWeakPtr(), done));
212
166 screenshot_controller->set_pen_events_only(true); 213 screenshot_controller->set_pen_events_only(true);
167 screenshot_controller->StartPartialScreenshotSession( 214 screenshot_controller->StartPartialScreenshotSession(
168 screenshot_delegate, false /* draw_overlay_immediately */); 215 proxy_screenshot_delegate_.get(), false /* draw_overlay_immediately */);
216 }
217
218 void PaletteDelegateChromeOS::CancelPartialScreenshot() {
219 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession();
169 } 220 }
170 221
171 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { 222 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) {
172 on_stylus_state_changed_.Run(state); 223 on_stylus_state_changed_.Run(state);
173 } 224 }
174 225
175 void PaletteDelegateChromeOS::OnLaserPointerEnabled() { 226 void PaletteDelegateChromeOS::OnLaserPointerEnabled() {
176 // We lock the cursor after we hide it because compound_event_filter.cc will 227 // We lock the cursor after we hide it because compound_event_filter.cc will
177 // attempt to call ShowCursor every time it recieves a mouse event. 228 // attempt to call ShowCursor every time it recieves a mouse event.
178 ash::Shell::GetInstance()->cursor_manager()->HideCursor(); 229 ash::Shell::GetInstance()->cursor_manager()->HideCursor();
179 ash::Shell::GetInstance()->cursor_manager()->LockCursor(); 230 ash::Shell::GetInstance()->cursor_manager()->LockCursor();
180 } 231 }
181 232
182 void PaletteDelegateChromeOS::OnLaserPointerDisabled() { 233 void PaletteDelegateChromeOS::OnLaserPointerDisabled() {
183 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor(); 234 ash::Shell::GetInstance()->cursor_manager()->UnlockCursor();
184 ash::Shell::GetInstance()->cursor_manager()->ShowCursor(); 235 ash::Shell::GetInstance()->cursor_manager()->ShowCursor();
185 } 236 }
186 } // namespace chromeos 237 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/ui/ash/palette_delegate_chromeos.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698