Commit 53bbe593 authored by jdufault's avatar jdufault Committed by Commit bot

cros/ash: Cancel screenshot mode if screenshot is cancelled or not taken.

TEST=ash_unittests
BUG=645277

Review-Url: https://codereview.chromium.org/2324803003
Cr-Commit-Position: refs/heads/master@{#419534}
parent 4607efe4
......@@ -37,8 +37,7 @@ PaletteToolId CaptureRegionMode::GetToolId() const {
}
const gfx::VectorIcon& CaptureRegionMode::GetActiveTrayIcon() const {
// TODO(jdufault): Update to real icon once new tray icons are ready.
return kPaletteTrayIconMagnifyIcon;
return kPaletteTrayIconCaptureRegionIcon;
}
void CaptureRegionMode::OnEnable() {
......
......@@ -18,6 +18,8 @@ action("aggregate_vector_icons") {
"palette_mode_laser_pointer.icon",
"palette_mode_magnify.1x.icon",
"palette_mode_magnify.icon",
"palette_tray_icon_capture_region.1x.icon",
"palette_tray_icon_capture_region.icon",
"palette_tray_icon_default.1x.icon",
"palette_tray_icon_default.icon",
"palette_tray_icon_laser_pointer.1x.icon",
......
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 16,
MOVE_TO, 9.97f, 8.99f,
V_LINE_TO, 8,
R_H_LINE_TO, -0.98f,
R_V_LINE_TO, 0.99f,
H_LINE_TO, 8,
R_V_LINE_TO, 0.97f,
R_H_LINE_TO, 0.99f,
R_V_LINE_TO, 1,
R_H_LINE_TO, 0.99f,
V_LINE_TO, 9.97f,
R_H_LINE_TO, 0.99f,
R_V_LINE_TO, -0.98f,
H_LINE_TO, 9.97f,
CLOSE,
MOVE_TO, 7.02f, 6.48f,
LINE_TO, 2, 11.5f,
V_LINE_TO, 14,
R_H_LINE_TO, 2.49f,
R_LINE_TO, 2.5f, -2.62f,
V_LINE_TO, 8.25f,
R_CUBIC_TO, 0, -0.44f, 0.21f, -0.81f, 0.52f, -1.09f,
R_LINE_TO, -0.48f, -0.68f,
CLOSE,
R_MOVE_TO, 2.39f, -2.4f,
LINE_TO, 7.72f, 5.77f,
R_LINE_TO, 1.27f, 1.23f,
H_LINE_TO, 11.68f,
R_LINE_TO, 2.13f, -2.29f,
R_CUBIC_TO, 0.26f, -0.26f, 0.26f, -0.69f, 0, -0.95f,
R_LINE_TO, -1.56f, -1.55f,
R_CUBIC_TO, -0.26f, -0.26f, -0.69f, -0.26f, -0.94f, 0,
R_LINE_TO, -0.94f, 0.94f,
R_LINE_TO, -0.95f, -0.94f,
R_CUBIC_TO, -0.25f, -0.26f, -0.69f, -0.27f, -0.95f, -0.01f,
LINE_TO, 4.22f, 6.43f,
R_LINE_TO, 0.93f, 0.93f,
R_LINE_TO, 3.77f, -3.77f,
R_LINE_TO, 0.49f, 0.49f,
CLOSE,
MOVE_TO, 14, 10,
R_H_LINE_TO, -1,
V_LINE_TO, 9,
R_CUBIC_TO, 0.55f, 0, 1, 0.48f, 1, 1,
CLOSE,
R_MOVE_TO, -2, 0,
R_H_LINE_TO, 1,
V_LINE_TO, 9,
R_H_LINE_TO, -1,
R_V_LINE_TO, 1,
CLOSE,
R_MOVE_TO, -1, 4,
R_H_LINE_TO, 1,
R_V_LINE_TO, -1,
R_H_LINE_TO, -1,
R_V_LINE_TO, 1,
CLOSE,
R_MOVE_TO, -2, -2,
R_H_LINE_TO, 1,
R_V_LINE_TO, -1,
H_LINE_TO, 9,
R_V_LINE_TO, 1,
CLOSE,
R_MOVE_TO, 1, 2,
R_CUBIC_TO, -0.55f, 0, -1, -0.52f, -1, -1,
R_H_LINE_TO, 1,
R_V_LINE_TO, 1,
CLOSE,
R_MOVE_TO, 3, -2,
R_H_LINE_TO, 1,
R_V_LINE_TO, -1,
R_H_LINE_TO, -1,
R_V_LINE_TO, 1,
CLOSE,
R_MOVE_TO, 0, 2,
R_CUBIC_TO, 0.55f, 0, 1, -0.45f, 1, -1,
R_H_LINE_TO, -1,
R_V_LINE_TO, 1,
CLOSE,
END
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
CANVAS_DIMENSIONS, 32,
MOVE_TO, 24.45f, 25.91f,
LINE_TO, 26.65f, 28,
LINE_TO, 28, 26.48f,
R_LINE_TO, -2.11f, -2.01f,
CUBIC_TO, 26.59f, 23.49f, 27, 22.29f, 27, 21,
CUBIC_TO, 27, 17.69f, 24.31f, 15, 21, 15,
R_CUBIC_TO, -3.31f, 0, -6, 2.69f, -6, 6,
CUBIC_TO, 15, 24.31f, 17.69f, 27, 21, 27,
R_CUBIC_TO, 1.28f, 0, 2.48f, -0.41f, 3.45f, -1.09f,
CLOSE,
R_MOVE_TO, -8.94f, -11.47f,
R_LINE_TO, -1.48f, -1.48f,
LINE_TO, 4, 23,
R_V_LINE_TO, 5,
R_H_LINE_TO, 4.99f,
LINE_TO, 13.09f, 23.9f,
R_CUBIC_TO, -0.42f, -0.97f, -0.65f, -2.04f, -0.65f, -3.16f,
R_CUBIC_TO, 0, -2.56f, 1.21f, -4.83f, 3.08f, -6.3f,
CLOSE,
R_MOVE_TO, 8.1f, -1.04f,
R_LINE_TO, 4, -4,
R_CUBIC_TO, 0.52f, -0.52f, 0.51f, -1.37f, -0.01f, -1.89f,
R_LINE_TO, -3.12f, -3.11f,
R_CUBIC_TO, -0.52f, -0.52f, -1.37f, -0.52f, -1.88f, 0,
R_LINE_TO, -1.89f, 1.88f,
R_LINE_TO, -1.89f, -1.88f,
R_CUBIC_TO, -0.51f, -0.52f, -1.37f, -0.53f, -1.89f, -0.01f,
R_LINE_TO, -8.49f, 8.48f,
R_LINE_TO, 1.87f, 1.87f,
LINE_TO, 17.85f, 7.19f,
R_LINE_TO, 0.97f, 0.97f,
R_LINE_TO, -3.37f, 3.37f,
R_LINE_TO, 1.85f, 1.85f,
R_CUBIC_TO, 0.97f, -0.41f, 2.03f, -0.64f, 3.14f, -0.64f,
R_CUBIC_TO, 1.13f, 0, 2.2f, 0.24f, 3.18f, 0.66f,
CLOSE,
MOVE_TO, 21, 17.01f,
R_CUBIC_TO, -2.2f, 0, -3.99f, 1.79f, -3.99f, 3.99f,
R_CUBIC_TO, 0, 2.2f, 1.79f, 3.99f, 3.99f, 3.99f,
R_CUBIC_TO, 2.2f, 0, 3.99f, -1.79f, 3.99f, -3.99f,
R_CUBIC_TO, 0, -2.2f, -1.79f, -3.99f, -3.99f, -3.99f,
CLOSE,
MOVE_TO, 24, 20,
R_H_LINE_TO, -2,
R_V_LINE_TO, -2,
R_H_LINE_TO, -2,
R_V_LINE_TO, 2,
R_H_LINE_TO, -2,
R_V_LINE_TO, 2,
R_H_LINE_TO, 2,
R_V_LINE_TO, 2,
R_H_LINE_TO, 2,
R_V_LINE_TO, -2,
R_H_LINE_TO, 2,
R_V_LINE_TO, -2,
CLOSE,
END
......@@ -308,6 +308,14 @@ void ScreenshotController::CancelScreenshotSession() {
base::STLDeleteValues(&layers_);
cursor_setter_.reset();
EnableMouseWarp(true);
if (on_screenshot_session_done_) {
// Copy the closure to a temporary value so that if it calls
// CancelScreenshotSession we do not loop forever.
base::Closure on_done = on_screenshot_session_done_;
on_screenshot_session_done_.Reset();
on_done.Run();
}
}
void ScreenshotController::MaybeStart(const ui::LocatedEvent& event) {
......
......@@ -12,6 +12,7 @@
#include "ash/ash_export.h"
#include "ash/common/shell_observer.h"
#include "base/callback.h"
#include "base/macros.h"
#include "ui/aura/window_observer.h"
#include "ui/display/display_observer.h"
......@@ -57,6 +58,13 @@ class ASH_EXPORT ScreenshotController : public ui::EventHandler,
// Cancels any active screenshot session.
void CancelScreenshotSession();
// Set a function that will be called when the current screenshot session has
// been completed or cancelled. This is reset after the screenshot session is
// done.
void set_on_screenshot_session_done(const base::Closure& on_done) {
on_screenshot_session_done_ = on_done;
}
// If set to true, then only events generated by a pen can be used to select
// the area to take a screenshot of. This is reset to false after a screenshot
// operation is completed.
......@@ -108,6 +116,8 @@ class ASH_EXPORT ScreenshotController : public ui::EventHandler,
// screenshot region.
bool pen_events_only_ = false;
base::Closure on_screenshot_session_done_;
// The data to build the screenshot region.
gfx::Point start_position_;
aura::Window* root_window_;
......
......@@ -25,41 +25,6 @@
namespace chromeos {
class PaletteDelegateChromeOS::ProxyScreenshotDelegate
: public ash::ScreenshotDelegate {
public:
ProxyScreenshotDelegate(ash::ScreenshotDelegate* delegate,
const base::Closure& on_partial_screenshot_taken)
: delegate_(delegate),
on_partial_screenshot_taken_(on_partial_screenshot_taken) {}
~ProxyScreenshotDelegate() override {}
private:
// ash::ScreenshotDelegate:
void HandleTakeScreenshotForAllRootWindows() override {
return delegate_->HandleTakeScreenshotForAllRootWindows();
}
void HandleTakePartialScreenshot(aura::Window* window,
const gfx::Rect& rect) override {
delegate_->HandleTakePartialScreenshot(window, rect);
// Run the delegate last, as it may delete this object.
if (on_partial_screenshot_taken_)
on_partial_screenshot_taken_.Run();
}
void HandleTakeWindowScreenshot(aura::Window* window) override {
return delegate_->HandleTakeWindowScreenshot(window);
}
bool CanTakeScreenshot() override { return delegate_->CanTakeScreenshot(); }
// Not owned; delegate_ is expected to live beyond the lifetime of this
// object.
ash::ScreenshotDelegate* delegate_;
base::Closure on_partial_screenshot_taken_;
DISALLOW_COPY_AND_ASSIGN(ProxyScreenshotDelegate);
};
// static
std::unique_ptr<PaletteDelegateChromeOS> PaletteDelegateChromeOS::Create() {
if (!ash::IsPaletteFeatureEnabled())
......@@ -161,7 +126,6 @@ void PaletteDelegateChromeOS::SetProfile(Profile* profile) {
void PaletteDelegateChromeOS::OnPartialScreenshotDone(
const base::Closure& then) {
proxy_screenshot_delegate_.reset();
if (then)
then.Run();
}
......@@ -205,14 +169,12 @@ void PaletteDelegateChromeOS::TakePartialScreenshot(const base::Closure& done) {
->accelerator_controller_delegate()
->screenshot_delegate();
proxy_screenshot_delegate_ = base::MakeUnique<ProxyScreenshotDelegate>(
screenshot_delegate,
base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone,
weak_factory_.GetWeakPtr(), done));
screenshot_controller->set_pen_events_only(true);
screenshot_controller->StartPartialScreenshotSession(
proxy_screenshot_delegate_.get(), false /* draw_overlay_immediately */);
screenshot_delegate, false /* draw_overlay_immediately */);
screenshot_controller->set_on_screenshot_session_done(
base::Bind(&PaletteDelegateChromeOS::OnPartialScreenshotDone,
weak_factory_.GetWeakPtr(), done));
}
void PaletteDelegateChromeOS::CancelPartialScreenshot() {
......
......@@ -41,8 +41,6 @@ class PaletteDelegateChromeOS : public ash::PaletteDelegate,
private:
PaletteDelegateChromeOS();
class ProxyScreenshotDelegate;
// ash::PaletteDelegate:
std::unique_ptr<EnableListenerSubscription> AddPaletteEnableListener(
const EnableListener& on_state_changed) override;
......@@ -77,8 +75,6 @@ class PaletteDelegateChromeOS : public ash::PaletteDelegate,
base::CallbackList<void(bool)> palette_enabled_callback_list_;
OnStylusStateChangedCallback on_stylus_state_changed_;
std::unique_ptr<ProxyScreenshotDelegate> proxy_screenshot_delegate_;
// Unowned pointer to the active profile.
Profile* profile_ = nullptr;
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment