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: | |
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) { | |
Luis Héctor Chávez
2017/04/11 20:02:04
nit: you can elide braces
Vladislav Kaznacheev
2017/04/11 20:49:42
Done.
| |
45 return; | |
46 } | |
47 double device_scale_factor = window->layer()->device_scale_factor(); | |
48 framework->StartVoiceInteractionSessionForRegion( | |
49 gfx::ScaleToEnclosingRect(rect, device_scale_factor)); | |
50 } | |
51 | |
52 void HandleTakeWindowScreenshot(aura::Window* window) override { | |
53 NOTIMPLEMENTED(); | |
54 } | |
55 | |
56 bool CanTakeScreenshot() override { return true; } | |
57 }; | |
58 | |
28 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { | 59 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { |
29 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, | 60 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, |
30 content::NotificationService::AllSources()); | 61 content::NotificationService::AllSources()); |
31 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, | 62 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, |
32 content::NotificationService::AllSources()); | 63 content::NotificationService::AllSources()); |
33 } | 64 } |
34 | 65 |
35 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} | 66 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} |
36 | 67 |
37 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> | 68 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 | 165 |
135 void PaletteDelegateChromeOS::TakeScreenshot() { | 166 void PaletteDelegateChromeOS::TakeScreenshot() { |
136 auto* screenshot_delegate = ash::ShellPortClassic::Get() | 167 auto* screenshot_delegate = ash::ShellPortClassic::Get() |
137 ->accelerator_controller_delegate() | 168 ->accelerator_controller_delegate() |
138 ->screenshot_delegate(); | 169 ->screenshot_delegate(); |
139 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); | 170 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); |
140 } | 171 } |
141 | 172 |
142 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { | 173 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { |
143 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller(); | 174 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller(); |
144 auto* screenshot_delegate = ash::ShellPortClassic::Get() | 175 |
145 ->accelerator_controller_delegate() | 176 ash::ScreenshotDelegate* screenshot_delegate; |
146 ->screenshot_delegate(); | 177 if (arc::ArcVoiceInteractionFrameworkService::IsVoiceInteractionEnabled() && |
178 arc::IsArcAllowedForProfile(profile_)) { | |
179 if (!voice_interaction_screenshot_delegate_) { | |
180 voice_interaction_screenshot_delegate_ = | |
181 base::MakeUnique<VoiceInteractionScreenshotDelegate>(); | |
182 } | |
183 screenshot_delegate = voice_interaction_screenshot_delegate_.get(); | |
184 } else { | |
185 screenshot_delegate = ash::ShellPortClassic::Get() | |
186 ->accelerator_controller_delegate() | |
187 ->screenshot_delegate(); | |
188 } | |
147 | 189 |
148 screenshot_controller->set_pen_events_only(true); | 190 screenshot_controller->set_pen_events_only(true); |
149 screenshot_controller->StartPartialScreenshotSession( | 191 screenshot_controller->StartPartialScreenshotSession( |
150 screenshot_delegate, false /* draw_overlay_immediately */); | 192 screenshot_delegate, false /* draw_overlay_immediately */); |
151 screenshot_controller->set_on_screenshot_session_done( | 193 screenshot_controller->set_on_screenshot_session_done( |
152 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, | 194 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, |
153 weak_factory_.GetWeakPtr(), done)); | 195 weak_factory_.GetWeakPtr(), done)); |
154 } | 196 } |
155 | 197 |
156 void PaletteDelegateChromeOS::CancelPartialScreenshot() { | 198 void PaletteDelegateChromeOS::CancelPartialScreenshot() { |
157 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession(); | 199 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession(); |
158 } | 200 } |
159 | 201 |
160 } // namespace chromeos | 202 } // namespace chromeos |
OLD | NEW |