jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame^] | 5 | #include "ash/system/palette/tools/capture_region_mode.h" |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 6 | |
James Cook | 643b718 | 2017-03-05 22:02:58 | [diff] [blame] | 7 | #include "ash/common/accelerators/accelerator_controller.h" |
James Cook | 6316a55 | 2017-03-05 21:46:21 | [diff] [blame] | 8 | #include "ash/common/palette_delegate.h" |
James Cook | 6def4d9d | 2017-03-05 22:13:47 | [diff] [blame] | 9 | #include "ash/common/system/toast/toast_data.h" |
| 10 | #include "ash/common/system/toast/toast_manager.h" |
estade | 81c6985 | 2016-09-08 21:25:59 | [diff] [blame] | 11 | #include "ash/resources/vector_icons/vector_icons.h" |
sky | 07a24d4 | 2017-03-09 23:57:30 | [diff] [blame] | 12 | #include "ash/shell.h" |
jamescook | e45f811 | 2017-03-02 16:45:42 | [diff] [blame] | 13 | #include "ash/strings/grit/ash_strings.h" |
James Cook | a35a1e2 | 2017-04-08 02:33:08 | [diff] [blame^] | 14 | #include "ash/system/palette/palette_ids.h" |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 15 | #include "ui/base/l10n/l10n_util.h" |
| 16 | |
| 17 | namespace ash { |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | const char kToastId[] = "palette_capture_region"; |
| 22 | const int kToastDurationMs = 2500; |
| 23 | |
| 24 | } // namespace |
| 25 | |
| 26 | CaptureRegionMode::CaptureRegionMode(Delegate* delegate) |
| 27 | : CommonPaletteTool(delegate), weak_factory_(this) {} |
| 28 | |
| 29 | CaptureRegionMode::~CaptureRegionMode() {} |
| 30 | |
| 31 | PaletteGroup CaptureRegionMode::GetGroup() const { |
| 32 | return PaletteGroup::MODE; |
| 33 | } |
| 34 | |
| 35 | PaletteToolId CaptureRegionMode::GetToolId() const { |
| 36 | return PaletteToolId::CAPTURE_REGION; |
| 37 | } |
| 38 | |
estade | 81c6985 | 2016-09-08 21:25:59 | [diff] [blame] | 39 | const gfx::VectorIcon& CaptureRegionMode::GetActiveTrayIcon() const { |
jdufault | 53bbe59 | 2016-09-19 19:44:35 | [diff] [blame] | 40 | return kPaletteTrayIconCaptureRegionIcon; |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void CaptureRegionMode::OnEnable() { |
| 44 | CommonPaletteTool::OnEnable(); |
| 45 | |
| 46 | ToastData toast(kToastId, l10n_util::GetStringUTF16( |
| 47 | IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_TOAST), |
jdufault | a30f7c1 | 2016-11-17 21:47:56 | [diff] [blame] | 48 | kToastDurationMs, base::Optional<base::string16>()); |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 49 | Shell::Get()->toast_manager()->Show(toast); |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 50 | |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 51 | Shell::Get()->palette_delegate()->TakePartialScreenshot(base::Bind( |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 52 | &CaptureRegionMode::OnScreenshotDone, weak_factory_.GetWeakPtr())); |
| 53 | delegate()->HidePalette(); |
| 54 | } |
| 55 | |
| 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. |
sky | cb4be5b | 2017-04-06 17:52:45 | [diff] [blame] | 61 | Shell::Get()->palette_delegate()->CancelPartialScreenshot(); |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 62 | } |
| 63 | |
| 64 | views::View* CaptureRegionMode::CreateView() { |
| 65 | return CreateDefaultView( |
| 66 | l10n_util::GetStringUTF16(IDS_ASH_STYLUS_TOOLS_CAPTURE_REGION_ACTION)); |
| 67 | } |
| 68 | |
estade | 81c6985 | 2016-09-08 21:25:59 | [diff] [blame] | 69 | const gfx::VectorIcon& CaptureRegionMode::GetPaletteIcon() const { |
| 70 | return kPaletteActionCaptureRegionIcon; |
jdufault | e4546d22 | 2016-09-02 20:27:17 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | void CaptureRegionMode::OnScreenshotDone() { |
| 74 | // The screenshot finished, so disable the tool. |
| 75 | delegate()->DisableTool(GetToolId()); |
| 76 | } |
| 77 | |
| 78 | } // namespace ash |