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/aura/shell_port_classic.h" | 8 #include "ash/aura/shell_port_classic.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/system/palette/palette_utils.h" | 11 #include "ash/system/palette/palette_utils.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/arc/arc_util.h" | |
16 #include "chrome/browser/chromeos/arc/voice_interaction/arc_voice_interaction_fr amework_service.h" | |
15 #include "chrome/browser/chromeos/note_taking_helper.h" | 17 #include "chrome/browser/chromeos/note_taking_helper.h" |
16 #include "chrome/browser/chromeos/profiles/profile_helper.h" | 18 #include "chrome/browser/chromeos/profiles/profile_helper.h" |
17 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
18 #include "chrome/browser/profiles/profile_manager.h" | 20 #include "chrome/browser/profiles/profile_manager.h" |
19 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
22 #include "components/arc/arc_bridge_service.h" | |
23 #include "components/arc/arc_service_manager.h" | |
24 #include "components/arc/common/voice_interaction_framework.mojom.h" | |
20 #include "components/prefs/pref_change_registrar.h" | 25 #include "components/prefs/pref_change_registrar.h" |
21 #include "components/prefs/pref_service.h" | 26 #include "components/prefs/pref_service.h" |
22 #include "components/user_manager/user_manager.h" | 27 #include "components/user_manager/user_manager.h" |
23 #include "content/public/browser/notification_service.h" | 28 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 29 #include "content/public/browser/notification_source.h" |
25 | 30 |
26 namespace chromeos { | 31 namespace chromeos { |
27 | 32 |
33 class VoiceInteractionScreenshotDelegate : public ash::ScreenshotDelegate { | |
34 private: | |
oshima
2017/04/12 01:09:22
nit: please define public ctor/dtor and then add
Vladislav Kaznacheev
2017/04/12 16:08:47
Done.
| |
35 void HandleTakeScreenshotForAllRootWindows() override { NOTIMPLEMENTED(); } | |
36 | |
37 void HandleTakePartialScreenshot(aura::Window* window, | |
38 const gfx::Rect& rect) override { | |
39 arc::mojom::VoiceInteractionFrameworkInstance* framework = | |
40 ARC_GET_INSTANCE_FOR_METHOD(arc::ArcServiceManager::Get() | |
41 ->arc_bridge_service() | |
42 ->voice_interaction_framework(), | |
43 StartVoiceInteractionSessionForRegion); | |
44 if (!framework) | |
45 return; | |
46 double device_scale_factor = window->layer()->device_scale_factor(); | |
47 framework->StartVoiceInteractionSessionForRegion( | |
48 gfx::ScaleToEnclosingRect(rect, device_scale_factor)); | |
49 } | |
50 | |
51 void HandleTakeWindowScreenshot(aura::Window* window) override { | |
52 NOTIMPLEMENTED(); | |
53 } | |
54 | |
55 bool CanTakeScreenshot() override { return true; } | |
56 }; | |
57 | |
28 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { | 58 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
29 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 59 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
30 content::NotificationService::AllSources()); | 60 content::NotificationService::AllSources()); |
31 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 61 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
32 content::NotificationService::AllSources()); | 62 content::NotificationService::AllSources()); |
33 } | 63 } |
34 | 64 |
35 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} | 65 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} |
36 | 66 |
37 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> | 67 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 164 |
135 void PaletteDelegateChromeOS::TakeScreenshot() { | 165 void PaletteDelegateChromeOS::TakeScreenshot() { |
136 auto* screenshot_delegate = ash::ShellPortClassic::Get() | 166 auto* screenshot_delegate = ash::ShellPortClassic::Get() |
137 ->accelerator_controller_delegate() | 167 ->accelerator_controller_delegate() |
138 ->screenshot_delegate(); | 168 ->screenshot_delegate(); |
139 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); | 169 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); |
140 } | 170 } |
141 | 171 |
142 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { | 172 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { |
143 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller(); | 173 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller(); |
144 auto* screenshot_delegate = ash::ShellPortClassic::Get() | 174 |
145 ->accelerator_controller_delegate() | 175 ash::ScreenshotDelegate* screenshot_delegate; |
146 ->screenshot_delegate(); | 176 if (arc::ArcVoiceInteractionFrameworkService::IsVoiceInteractionEnabled() && |
177 arc::IsArcAllowedForProfile(profile_)) { | |
178 // This is an experimental mode. It will be either taken out or grow | |
179 // into a separate tool next to "Capture region". | |
180 if (!voice_interaction_screenshot_delegate_) { | |
181 voice_interaction_screenshot_delegate_ = | |
182 base::MakeUnique<VoiceInteractionScreenshotDelegate>(); | |
183 } | |
184 screenshot_delegate = voice_interaction_screenshot_delegate_.get(); | |
185 } else { | |
186 screenshot_delegate = ash::ShellPortClassic::Get() | |
187 ->accelerator_controller_delegate() | |
188 ->screenshot_delegate(); | |
189 } | |
147 | 190 |
148 screenshot_controller->set_pen_events_only(true); | 191 screenshot_controller->set_pen_events_only(true); |
149 screenshot_controller->StartPartialScreenshotSession( | 192 screenshot_controller->StartPartialScreenshotSession( |
150 screenshot_delegate, false /* draw_overlay_immediately */); | 193 screenshot_delegate, false /* draw_overlay_immediately */); |
151 screenshot_controller->set_on_screenshot_session_done( | 194 screenshot_controller->set_on_screenshot_session_done( |
152 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | 195 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, |
153 weak_factory_.GetWeakPtr(), done)); | 196 weak_factory_.GetWeakPtr(), done)); |
154 } | 197 } |
155 | 198 |
156 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | 199 void PaletteDelegateChromeOS::CancelPartialScreenshot() { |
157 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession(); | 200 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession(); |
158 } | 201 } |
159 | 202 |
160 } // namespace chromeos | 203 } // namespace chromeos |
OLD | NEW |