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