Chromium Code Reviews| 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 "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); | |
|
oshima
2016/09/02 13:55:19
just q: are you going to do the same for this mode
jdufault
2016/09/02 19:46:31
Not planned right now, because that is an instanta
| |
| 52 } | |
| 53 bool CanTakeScreenshot() override { return delegate_->CanTakeScreenshot(); } | |
| 54 | |
| 55 ash::ScreenshotDelegate* delegate_; | |
|
oshima
2016/09/02 13:55:19
nit: document ownership
jdufault
2016/09/02 19:46:31
Done.
| |
| 56 base::Closure on_partial_screenshot_taken_; | |
| 57 | |
| 58 DISALLOW_COPY_AND_ASSIGN(ProxyScreenshotDelegate); | |
| 59 }; | |
| 60 | |
| 28 // static | 61 // static |
| 29 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { | 62 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { |
| 30 if (!ash::IsPaletteFeatureEnabled()) | 63 if (!ash::IsPaletteFeatureEnabled()) |
| 31 return nullptr; | 64 return nullptr; |
| 32 return base::WrapUnique(new PaletteDelegateChromeOS()); | 65 return base::WrapUnique(new PaletteDelegateChromeOS()); |
| 33 } | 66 } |
| 34 | 67 |
| 35 PaletteDelegateChromeOS::PaletteDelegateChromeOS() { | 68 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
| 36 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 69 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
| 37 content::NotificationService::AllSources()); | 70 content::NotificationService::AllSources()); |
| 38 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 71 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
| 39 content::NotificationService::AllSources()); | 72 content::NotificationService::AllSources()); |
| 40 | 73 |
| 41 ui::InputDeviceManager::GetInstance()->AddObserver(this); | 74 ui::InputDeviceManager::GetInstance()->AddObserver(this); |
| 42 } | 75 } |
| 43 | 76 |
| 44 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() { | 77 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() { |
| 45 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); | 78 ui::InputDeviceManager::GetInstance()->RemoveObserver(this); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 117 pref_change_registrar_->Init(prefs); | 150 pref_change_registrar_->Init(prefs); |
| 118 pref_change_registrar_->Add( | 151 pref_change_registrar_->Add( |
| 119 prefs::kEnableStylusTools, | 152 prefs::kEnableStylusTools, |
| 120 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged, | 153 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged, |
| 121 base::Unretained(this))); | 154 base::Unretained(this))); |
| 122 | 155 |
| 123 // Run listener with new pref value, if any. | 156 // Run listener with new pref value, if any. |
| 124 OnPaletteEnabledPrefChanged(); | 157 OnPaletteEnabledPrefChanged(); |
| 125 } | 158 } |
| 126 | 159 |
| 160 void PaletteDelegateChromeOS::OnPartialScreenshotDone( | |
| 161 const base::Closure& then) { | |
| 162 proxy_screenshot_delegate_.reset(); | |
| 163 if (then) | |
| 164 then.Run(); | |
| 165 } | |
| 166 | |
| 127 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { | 167 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { |
| 128 ash::PartialMagnificationController* controller = | 168 ash::PartialMagnificationController* controller = |
| 129 ash::Shell::GetInstance()->partial_magnification_controller(); | 169 ash::Shell::GetInstance()->partial_magnification_controller(); |
| 130 controller->SetEnabled(enabled); | 170 controller->SetEnabled(enabled); |
| 131 } | 171 } |
| 132 | 172 |
| 133 void PaletteDelegateChromeOS::SetStylusStateChangedCallback( | 173 void PaletteDelegateChromeOS::SetStylusStateChangedCallback( |
| 134 const OnStylusStateChangedCallback& on_stylus_state_changed) { | 174 const OnStylusStateChangedCallback& on_stylus_state_changed) { |
| 135 on_stylus_state_changed_ = on_stylus_state_changed; | 175 on_stylus_state_changed_ = on_stylus_state_changed; |
| 136 } | 176 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 149 return profile_->GetPrefs()->GetBoolean(prefs::kEnableStylusTools); | 189 return profile_->GetPrefs()->GetBoolean(prefs::kEnableStylusTools); |
| 150 } | 190 } |
| 151 | 191 |
| 152 void PaletteDelegateChromeOS::TakeScreenshot() { | 192 void PaletteDelegateChromeOS::TakeScreenshot() { |
| 153 auto* screenshot_delegate = ash::Shell::GetInstance() | 193 auto* screenshot_delegate = ash::Shell::GetInstance() |
| 154 ->accelerator_controller_delegate() | 194 ->accelerator_controller_delegate() |
| 155 ->screenshot_delegate(); | 195 ->screenshot_delegate(); |
| 156 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); | 196 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); |
| 157 } | 197 } |
| 158 | 198 |
| 159 void PaletteDelegateChromeOS::TakePartialScreenshot() { | 199 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { |
| 160 auto* screenshot_controller = | 200 auto* screenshot_controller = |
| 161 ash::Shell::GetInstance()->screenshot_controller(); | 201 ash::Shell::GetInstance()->screenshot_controller(); |
| 162 auto* screenshot_delegate = ash::Shell::GetInstance() | 202 auto* screenshot_delegate = ash::Shell::GetInstance() |
| 163 ->accelerator_controller_delegate() | 203 ->accelerator_controller_delegate() |
| 164 ->screenshot_delegate(); | 204 ->screenshot_delegate(); |
| 165 | 205 |
| 206 proxy_screenshot_delegate_ = base::MakeUnique<ProxyScreenshotDelegate>( | |
| 207 screenshot_delegate, | |
| 208 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | |
| 209 weak_factory_.GetWeakPtr(), done)); | |
| 210 | |
| 166 screenshot_controller->set_pen_events_only(true); | 211 screenshot_controller->set_pen_events_only(true); |
| 167 screenshot_controller->StartPartialScreenshotSession( | 212 screenshot_controller->StartPartialScreenshotSession( |
| 168 screenshot_delegate, false /* draw_overlay_immediately */); | 213 proxy_screenshot_delegate_.get(), false /* draw_overlay_immediately */); |
| 214 } | |
| 215 | |
| 216 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | |
| 217 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); | |
| 169 } | 218 } |
| 170 | 219 |
| 171 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { | 220 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { |
| 172 on_stylus_state_changed_.Run(state); | 221 on_stylus_state_changed_.Run(state); |
| 173 } | 222 } |
| 174 | 223 |
| 175 } // namespace chromeos | 224 } // namespace chromeos |
| OLD | NEW |