blob: c307303617306c43aa7282dfb415521cd626dcc5 [file] [log] [blame]
jdufaulte4546d222016-09-02 20:27:171// Copyright 2016 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
James Cooka35a1e22017-04-08 02:33:085#include "ash/system/palette/tools/capture_region_mode.h"
jdufaulte4546d222016-09-02 20:27:176
James Cook643b7182017-03-05 22:02:587#include "ash/common/accelerators/accelerator_controller.h"
James Cook6316a552017-03-05 21:46:218#include "ash/common/palette_delegate.h"
James Cook6def4d9d2017-03-05 22:13:479#include "ash/common/system/toast/toast_data.h"
10#include "ash/common/system/toast/toast_manager.h"
estade81c69852016-09-08 21:25:5911#include "ash/resources/vector_icons/vector_icons.h"
sky07a24d42017-03-09 23:57:3012#include "ash/shell.h"
jamescooke45f8112017-03-02 16:45:4213#include "ash/strings/grit/ash_strings.h"
James Cooka35a1e22017-04-08 02:33:0814#include "ash/system/palette/palette_ids.h"
jdufaulte4546d222016-09-02 20:27:1715#include "ui/base/l10n/l10n_util.h"
16
17namespace ash {
18
19namespace {
20
21const char kToastId[] = "palette_capture_region";
22const int kToastDurationMs = 2500;
23
24} // namespace
25
26CaptureRegionMode::CaptureRegionMode(Delegate* delegate)
27 : CommonPaletteTool(delegate), weak_factory_(this) {}
28
29CaptureRegionMode::~CaptureRegionMode() {}
30
31PaletteGroup CaptureRegionMode::GetGroup() const {
32 return PaletteGroup::MODE;
33}
34
35PaletteToolId CaptureRegionMode::GetToolId() const {
36 return PaletteToolId::CAPTURE_REGION;
37}
38
estade81c69852016-09-08 21:25:5939const gfx::VectorIcon& CaptureRegionMode::GetActiveTrayIcon() const {
jdufault53bbe592016-09-19 19:44:3540 return kPaletteTrayIconCaptureRegionIcon;
jdufaulte4546d222016-09-02 20:27:1741}
42
43void CaptureRegionMode::OnEnable() {
44 CommonPaletteTool::OnEnable();
45
46 ToastData toast(kToastId, l10n_util::GetStringUTF16(
47 IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_TOAST),
jdufaulta30f7c12016-11-17 21:47:5648 kToastDurationMs, base::Optional<base::string16>());
skycb4be5b2017-04-06 17:52:4549 Shell::Get()->toast_manager()->Show(toast);
jdufaulte4546d222016-09-02 20:27:1750
skycb4be5b2017-04-06 17:52:4551 Shell::Get()->palette_delegate()->TakePartialScreenshot(base::Bind(
jdufaulte4546d222016-09-02 20:27:1752 &CaptureRegionMode::OnScreenshotDone, weak_factory_.GetWeakPtr()));
53 delegate()->HidePalette();
54}
55
56void 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.
skycb4be5b2017-04-06 17:52:4561 Shell::Get()->palette_delegate()->CancelPartialScreenshot();
jdufaulte4546d222016-09-02 20:27:1762}
63
64views::View* CaptureRegionMode::CreateView() {
65 return CreateDefaultView(
66 l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION));
67}
68
estade81c69852016-09-08 21:25:5969const gfx::VectorIcon& CaptureRegionMode::GetPaletteIcon() const {
70 return kPaletteActionCaptureRegionIcon;
jdufaulte4546d222016-09-02 20:27:1771}
72
73void CaptureRegionMode::OnScreenshotDone() {
74 // The screenshot finished, so disable the tool.
75 delegate()->DisableTool(GetToolId());
76}
77
78} // namespace ash