| 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); | |
| 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 | |
| 63 // static | 28 // static |
| 64 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { | 29 std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() { |
| 65 if (!ash::IsPaletteFeatureEnabled()) | 30 if (!ash::IsPaletteFeatureEnabled()) |
| 66 return nullptr; | 31 return nullptr; |
| 67 return base::WrapUnique(new PaletteDelegateChromeOS()); | 32 return base::WrapUnique(new PaletteDelegateChromeOS()); |
| 68 } | 33 } |
| 69 | 34 |
| 70 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { | 35 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
| 71 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 36 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
| 72 content::NotificationService::AllSources()); | 37 content::NotificationService::AllSources()); |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 prefs::kEnableStylusTools, | 119 prefs::kEnableStylusTools, |
| 155 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged, | 120 base::Bind(&PaletteDelegateChromeOS::OnPaletteEnabledPrefChanged, |
| 156 base::Unretained(this))); | 121 base::Unretained(this))); |
| 157 | 122 |
| 158 // Run listener with new pref value, if any. | 123 // Run listener with new pref value, if any. |
| 159 OnPaletteEnabledPrefChanged(); | 124 OnPaletteEnabledPrefChanged(); |
| 160 } | 125 } |
| 161 | 126 |
| 162 void PaletteDelegateChromeOS::OnPartialScreenshotDone( | 127 void PaletteDelegateChromeOS::OnPartialScreenshotDone( |
| 163 const base::Closure& then) { | 128 const base::Closure& then) { |
| 164 proxy_screenshot_delegate_.reset(); | |
| 165 if (then) | 129 if (then) |
| 166 then.Run(); | 130 then.Run(); |
| 167 } | 131 } |
| 168 | 132 |
| 169 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { | 133 void PaletteDelegateChromeOS::SetPartialMagnifierState(bool enabled) { |
| 170 ash::PartialMagnificationController* controller = | 134 ash::PartialMagnificationController* controller = |
| 171 ash::Shell::GetInstance()->partial_magnification_controller(); | 135 ash::Shell::GetInstance()->partial_magnification_controller(); |
| 172 controller->SetEnabled(enabled); | 136 controller->SetEnabled(enabled); |
| 173 } | 137 } |
| 174 | 138 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 198 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); | 162 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); |
| 199 } | 163 } |
| 200 | 164 |
| 201 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { | 165 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { |
| 202 auto* screenshot_controller = | 166 auto* screenshot_controller = |
| 203 ash::Shell::GetInstance()->screenshot_controller(); | 167 ash::Shell::GetInstance()->screenshot_controller(); |
| 204 auto* screenshot_delegate = ash::Shell::GetInstance() | 168 auto* screenshot_delegate = ash::Shell::GetInstance() |
| 205 ->accelerator_controller_delegate() | 169 ->accelerator_controller_delegate() |
| 206 ->screenshot_delegate(); | 170 ->screenshot_delegate(); |
| 207 | 171 |
| 208 proxy_screenshot_delegate_ = base::MakeUnique<ProxyScreenshotDelegate>( | 172 screenshot_controller->set_pen_events_only(true); |
| 209 screenshot_delegate, | 173 screenshot_controller->StartPartialScreenshotSession( |
| 174 screenshot_delegate, false /* draw_overlay_immediately */); |
| 175 screenshot_controller->set_on_screenshot_session_done( |
| 210 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | 176 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, |
| 211 weak_factory_.GetWeakPtr(), done)); | 177 weak_factory_.GetWeakPtr(), done)); |
| 212 | |
| 213 screenshot_controller->set_pen_events_only(true); | |
| 214 screenshot_controller->StartPartialScreenshotSession( | |
| 215 proxy_screenshot_delegate_.get(), false /* draw_overlay_immediately */); | |
| 216 } | 178 } |
| 217 | 179 |
| 218 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | 180 void PaletteDelegateChromeOS::CancelPartialScreenshot() { |
| 219 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); | 181 ash::Shell::GetInstance()->screenshot_controller()->CancelScreenshotSession(); |
| 220 } | 182 } |
| 221 | 183 |
| 222 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { | 184 void PaletteDelegateChromeOS::OnStylusStateChanged(ui::StylusState state) { |
| 223 on_stylus_state_changed_.Run(state); | 185 on_stylus_state_changed_.Run(state); |
| 224 } | 186 } |
| 225 } // namespace chromeos | 187 } // namespace chromeos |
| OLD | NEW |