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

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

Issue 2803403002: Support region selection for voice interaction session (Closed)
Patch Set: Removed 'auto' Created 3 years, 8 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
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/aura/wm_shell_aura.h" 8 #include "ash/aura/wm_shell_aura.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/command_line.h"
13 #include "base/memory/ptr_util.h" 14 #include "base/memory/ptr_util.h"
14 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/chromeos/arc/arc_util.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 "chromeos/chromeos_switches.h"
23 #include "components/arc/arc_bridge_service.h"
24 #include "components/arc/arc_service_manager.h"
25 #include "components/arc/common/voice_interaction_framework.mojom.h"
20 #include "components/prefs/pref_change_registrar.h" 26 #include "components/prefs/pref_change_registrar.h"
21 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
22 #include "components/user_manager/user_manager.h" 28 #include "components/user_manager/user_manager.h"
23 #include "content/public/browser/notification_service.h" 29 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_source.h" 30 #include "content/public/browser/notification_source.h"
25 31
26 namespace chromeos { 32 namespace chromeos {
27 33
34 class VoiceInteractionScreenshotDelegate : public ash::ScreenshotDelegate {
35 public:
36 explicit VoiceInteractionScreenshotDelegate(Profile* profile)
37 : profile_(profile) {}
38
39 private:
40 Profile* profile_;
Luis Héctor Chávez 2017/04/11 16:11:16 nit: Profile* const profile_;
Vladislav Kaznacheev 2017/04/11 18:59:33 Removed as unused.
41
42 void HandleTakeScreenshotForAllRootWindows() override { NOTIMPLEMENTED(); }
43
44 void HandleTakePartialScreenshot(aura::Window* window,
45 const gfx::Rect& rect) override {
46 arc::mojom::VoiceInteractionFrameworkInstance* framework =
47 ARC_GET_INSTANCE_FOR_METHOD(arc::ArcServiceManager::Get()
48 ->arc_bridge_service()
49 ->voice_interaction_framework(),
50 StartVoiceInteractionSessionForRegion);
51 if (!framework) {
52 LOG(ERROR) << "Cannot connect to ARC";
dcheng 2017/04/11 07:39:47 Nit: please use DLOG
Luis Héctor Chávez 2017/04/11 16:11:16 You can also remove this logging completely: ARC_G
Vladislav Kaznacheev 2017/04/11 18:59:33 Acknowledged.
Vladislav Kaznacheev 2017/04/11 18:59:33 Done.
53 return;
54 }
55 double device_scale_factor = window->layer()->device_scale_factor();
56 framework->StartVoiceInteractionSessionForRegion(
57 gfx::ScaleToEnclosingRect(rect, device_scale_factor));
58 }
59
60 void HandleTakeWindowScreenshot(aura::Window* window) override {
61 NOTIMPLEMENTED();
62 }
63
64 bool CanTakeScreenshot() override { return true; }
65 };
66
28 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) { 67 PaletteDelegateChromeOS::PaletteDelegateChromeOS() : weak_factory_(this) {
29 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED, 68 registrar_.Add(this, chrome::NOTIFICATION_SESSION_STARTED,
30 content::NotificationService::AllSources()); 69 content::NotificationService::AllSources());
31 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED, 70 registrar_.Add(this, chrome::NOTIFICATION_PROFILE_DESTROYED,
32 content::NotificationService::AllSources()); 71 content::NotificationService::AllSources());
33 } 72 }
34 73
35 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {} 74 PaletteDelegateChromeOS::~PaletteDelegateChromeOS() {}
36 75
37 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription> 76 std::unique_ptr<PaletteDelegateChromeOS::EnableListenerSubscription>
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 173
135 void PaletteDelegateChromeOS::TakeScreenshot() { 174 void PaletteDelegateChromeOS::TakeScreenshot() {
136 auto* screenshot_delegate = ash::WmShellAura::Get() 175 auto* screenshot_delegate = ash::WmShellAura::Get()
137 ->accelerator_controller_delegate() 176 ->accelerator_controller_delegate()
138 ->screenshot_delegate(); 177 ->screenshot_delegate();
139 screenshot_delegate->HandleTakeScreenshotForAllRootWindows(); 178 screenshot_delegate->HandleTakeScreenshotForAllRootWindows();
140 } 179 }
141 180
142 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) { 181 void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) {
143 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller(); 182 auto* screenshot_controller = ash::Shell::Get()->screenshot_controller();
144 auto* screenshot_delegate = ash::WmShellAura::Get() 183
145 ->accelerator_controller_delegate() 184 ash::ScreenshotDelegate* screenshot_delegate;
146 ->screenshot_delegate(); 185 if (base::CommandLine::ForCurrentProcess()->HasSwitch(
186 chromeos::switches::kEnableVoiceInteraction) &&
Luis Héctor Chávez 2017/04/11 16:11:16 nit: ArcVoiceInteractionFrameworkService::IsVoiceI
Vladislav Kaznacheev 2017/04/11 18:59:33 Done.
187 arc::IsArcAllowedForProfile(profile_)) {
188 if (!voice_interaction_screenshot_delegate_) {
189 voice_interaction_screenshot_delegate_ =
190 base::MakeUnique<VoiceInteractionScreenshotDelegate>(profile_);
191 }
192 screenshot_delegate = voice_interaction_screenshot_delegate_.get();
193 } else {
194 screenshot_delegate = ash::WmShellAura::Get()
195 ->accelerator_controller_delegate()
196 ->screenshot_delegate();
197 }
147 198
148 screenshot_controller->set_pen_events_only(true); 199 screenshot_controller->set_pen_events_only(true);
149 screenshot_controller->StartPartialScreenshotSession( 200 screenshot_controller->StartPartialScreenshotSession(
150 screenshot_delegate, false /* draw_overlay_immediately */); 201 screenshot_delegate, false /* draw_overlay_immediately */);
151 screenshot_controller->set_on_screenshot_session_done( 202 screenshot_controller->set_on_screenshot_session_done(
152 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone, 203 base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone,
153 weak_factory_.GetWeakPtr(), done)); 204 weak_factory_.GetWeakPtr(), done));
154 } 205 }
155 206
156 void PaletteDelegateChromeOS::CancelPartialScreenshot() { 207 void PaletteDelegateChromeOS::CancelPartialScreenshot() {
157 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession(); 208 ash::Shell::Get()->screenshot_controller()->CancelScreenshotSession();
158 } 209 }
159 210
160 } // namespace chromeos 211 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698