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

Side by Side Diff: ash/common/system/chromeos/palette/tools/capture_region_mode.cc

Issue 2291913002: Allow the user to cancel the capture region action, and show its active status in the tray. (Closed)
Patch Set: Address comments Created 4 years, 3 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 "ash/common/system/chromeos/palette/tools/capture_region_action.h" 5 #include "ash/common/system/chromeos/palette/tools/capture_region_mode.h"
6 6
7 #include "ash/common/accelerators/accelerator_controller.h" 7 #include "ash/common/accelerators/accelerator_controller.h"
8 #include "ash/common/palette_delegate.h" 8 #include "ash/common/palette_delegate.h"
9 #include "ash/common/system/chromeos/palette/palette_ids.h" 9 #include "ash/common/system/chromeos/palette/palette_ids.h"
10 #include "ash/common/system/toast/toast_data.h" 10 #include "ash/common/system/toast/toast_data.h"
11 #include "ash/common/system/toast/toast_manager.h" 11 #include "ash/common/system/toast/toast_manager.h"
12 #include "ash/common/wm_shell.h" 12 #include "ash/common/wm_shell.h"
13 #include "grit/ash_strings.h" 13 #include "grit/ash_strings.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 15
16 namespace ash { 16 namespace ash {
17 17
18 namespace { 18 namespace {
19 19
20 const char kToastId[] = "palette_capture_region"; 20 const char kToastId[] = "palette_capture_region";
21 const int kToastDurationMs = 2500; 21 const int kToastDurationMs = 2500;
22 22
23 } // namespace 23 } // namespace
24 24
25 CaptureRegionAction::CaptureRegionAction(Delegate* delegate) 25 CaptureRegionMode::CaptureRegionMode(Delegate* delegate)
26 : CommonPaletteTool(delegate) {} 26 : CommonPaletteTool(delegate), weak_factory_(this) {}
27 27
28 CaptureRegionAction::~CaptureRegionAction() {} 28 CaptureRegionMode::~CaptureRegionMode() {}
29 29
30 PaletteGroup CaptureRegionAction::GetGroup() const { 30 PaletteGroup CaptureRegionMode::GetGroup() const {
31 return PaletteGroup::ACTION; 31 return PaletteGroup::MODE;
32 } 32 }
33 33
34 PaletteToolId CaptureRegionAction::GetToolId() const { 34 PaletteToolId CaptureRegionMode::GetToolId() const {
35 return PaletteToolId::CAPTURE_REGION; 35 return PaletteToolId::CAPTURE_REGION;
36 } 36 }
37 37
38 void CaptureRegionAction::OnEnable() { 38 gfx::VectorIconId CaptureRegionMode::GetActiveTrayIcon() {
39 // TODO(jdufault): Update to real icon once new tray icons are ready.
40 return gfx::VectorIconId::PALETTE_TRAY_ICON_MAGNIFY;
41 }
42
43 void CaptureRegionMode::OnEnable() {
39 CommonPaletteTool::OnEnable(); 44 CommonPaletteTool::OnEnable();
40 45
41 ToastData toast(kToastId, l10n_util::GetStringUTF16( 46 ToastData toast(kToastId, l10n_util::GetStringUTF16(
42 IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_TOAST), 47 IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_TOAST),
43 kToastDurationMs, base::string16()); 48 kToastDurationMs, base::string16());
44 ash::WmShell::Get()->toast_manager()->Show(toast); 49 ash::WmShell::Get()->toast_manager()->Show(toast);
45 50
46 WmShell::Get()->palette_delegate()->TakePartialScreenshot(); 51 WmShell::Get()->palette_delegate()->TakePartialScreenshot(base::Bind(
47 delegate()->DisableTool(GetToolId()); 52 &CaptureRegionMode::OnScreenshotDone, weak_factory_.GetWeakPtr()));
48 delegate()->HidePalette(); 53 delegate()->HidePalette();
49 } 54 }
50 55
51 views::View* CaptureRegionAction::CreateView() { 56 void CaptureRegionMode::OnDisable() {
57 CommonPaletteTool::OnDisable();
58
59 // If the user manually cancelled the action we need to make sure to cancel
60 // the screenshot session as well.
61 WmShell::Get()->palette_delegate()->CancelPartialScreenshot();
62 }
63
64 views::View* CaptureRegionMode::CreateView() {
52 return CreateDefaultView( 65 return CreateDefaultView(
53 l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION)); 66 l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION));
54 } 67 }
55 68
56 gfx::VectorIconId CaptureRegionAction::GetPaletteIconId() { 69 gfx::VectorIconId CaptureRegionMode::GetPaletteIconId() {
57 return gfx::VectorIconId::PALETTE_ACTION_CAPTURE_REGION; 70 return gfx::VectorIconId::PALETTE_ACTION_CAPTURE_REGION;
58 } 71 }
59 72
73 void CaptureRegionMode::OnScreenshotDone() {
74 // The screenshot finished, so disable the tool.
75 delegate()->DisableTool(GetToolId());
76 }
77
60 } // namespace ash 78 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698