Commit 587926ad authored by flackr@chromium.org's avatar flackr@chromium.org

Take a screenshot in maximize mode when volume down and power are pressed.

BUG=363732
TEST=MaximizeModeControllerTest.Screenshot
TEST=When device is in maximize mode, hold volume down and press power to take a screenshot.

Review URL: https://codereview.chromium.org/263813002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@269684 0039d316-1c4b-4281-b951-d872f2087c98
parent 78937bb4
...@@ -814,6 +814,8 @@ ...@@ -814,6 +814,8 @@
'test/status_area_widget_test_helper.h', 'test/status_area_widget_test_helper.h',
'test/test_activation_delegate.cc', 'test/test_activation_delegate.cc',
'test/test_activation_delegate.h', 'test/test_activation_delegate.h',
'test/test_lock_state_controller_delegate.cc',
'test/test_lock_state_controller_delegate.h',
'test/test_screenshot_delegate.cc', 'test/test_screenshot_delegate.cc',
'test/test_screenshot_delegate.cc', 'test/test_screenshot_delegate.cc',
'test/test_session_state_delegate.cc', 'test/test_session_state_delegate.cc',
......
// Copyright 2014 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.
#include "ash/test/test_lock_state_controller_delegate.h"
namespace ash {
namespace test {
TestLockStateControllerDelegate::TestLockStateControllerDelegate()
: num_lock_requests_(0),
num_shutdown_requests_(0) {
}
TestLockStateControllerDelegate::~TestLockStateControllerDelegate() {
}
void TestLockStateControllerDelegate::RequestLockScreen() {
++num_lock_requests_;
}
void TestLockStateControllerDelegate::RequestShutdown() {
++num_shutdown_requests_;
}
} // namespace test
} // namespace ash
// Copyright 2014 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.
#ifndef ASH_TEST_TEST_LOCK_STATE_CONTROLLER_DELEGATE_H_
#define ASH_TEST_TEST_LOCK_STATE_CONTROLLER_DELEGATE_H_
#include "ash/wm/lock_state_controller.h"
namespace ash {
namespace test {
// Fake implementation of PowerButtonControllerDelegate that just logs requests
// to lock the screen and shut down the device.
class TestLockStateControllerDelegate : public LockStateControllerDelegate {
public:
TestLockStateControllerDelegate();
virtual ~TestLockStateControllerDelegate();
int num_lock_requests() const { return num_lock_requests_; }
int num_shutdown_requests() const { return num_shutdown_requests_; }
// LockStateControllerDelegate implementation.
virtual void RequestLockScreen() OVERRIDE;
virtual void RequestShutdown() OVERRIDE;
private:
int num_lock_requests_;
int num_shutdown_requests_;
DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate);
};
} // namespace test
} // namespace ash
#endif // ASH_TEST_TEST_LOCK_STATE_CONTROLLER_DELEGATE_H_
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/shell_window_ids.h" #include "ash/shell_window_ids.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/test/test_lock_state_controller_delegate.h"
#include "ash/test/test_shell_delegate.h" #include "ash/test/test_shell_delegate.h"
#include "ash/wm/power_button_controller.h" #include "ash/wm/power_button_controller.h"
#include "ash/wm/session_state_animator.h" #include "ash/wm/session_state_animator.h"
...@@ -68,32 +69,6 @@ void HideBackground() { ...@@ -68,32 +69,6 @@ void HideBackground() {
} // namespace } // namespace
// Fake implementation of PowerButtonControllerDelegate that just logs requests
// to lock the screen and shut down the device.
class TestLockStateControllerDelegate : public LockStateControllerDelegate {
public:
TestLockStateControllerDelegate()
: num_lock_requests_(0),
num_shutdown_requests_(0) {}
int num_lock_requests() const { return num_lock_requests_; }
int num_shutdown_requests() const { return num_shutdown_requests_; }
// LockStateControllerDelegate implementation.
virtual void RequestLockScreen() OVERRIDE {
num_lock_requests_++;
}
virtual void RequestShutdown() OVERRIDE {
num_shutdown_requests_++;
}
private:
int num_lock_requests_;
int num_shutdown_requests_;
DISALLOW_COPY_AND_ASSIGN(TestLockStateControllerDelegate);
};
class LockStateControllerTest : public AshTestBase { class LockStateControllerTest : public AshTestBase {
public: public:
LockStateControllerTest() : controller_(NULL), delegate_(NULL) {} LockStateControllerTest() : controller_(NULL), delegate_(NULL) {}
......
...@@ -4,12 +4,18 @@ ...@@ -4,12 +4,18 @@
#include "ash/wm/maximize_mode/maximize_mode_controller.h" #include "ash/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/accelerators/accelerator_controller.h"
#include "ash/accelerators/accelerator_table.h"
#include "ash/accelerometer/accelerometer_controller.h" #include "ash/accelerometer/accelerometer_controller.h"
#include "ash/ash_switches.h" #include "ash/ash_switches.h"
#include "ash/display/display_manager.h" #include "ash/display/display_manager.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/wm/maximize_mode/maximize_mode_event_blocker.h" #include "ash/wm/maximize_mode/maximize_mode_event_blocker.h"
#include "base/command_line.h" #include "base/command_line.h"
#include "ui/base/accelerators/accelerator.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/vector3d_f.h" #include "ui/gfx/vector3d_f.h"
namespace ash { namespace ash {
...@@ -81,6 +87,47 @@ float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base, ...@@ -81,6 +87,47 @@ float ClockwiseAngleBetweenVectorsInDegrees(const gfx::Vector3dF& base,
return angle; return angle;
} }
#if defined(OS_CHROMEOS)
// An event handler which listens for a volume down + power keypress and
// triggers a screenshot when this is seen.
class ScreenshotActionHandler : public ui::EventHandler {
public:
ScreenshotActionHandler();
virtual ~ScreenshotActionHandler();
// ui::EventHandler:
virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
private:
bool volume_down_pressed_;
DISALLOW_COPY_AND_ASSIGN(ScreenshotActionHandler);
};
ScreenshotActionHandler::ScreenshotActionHandler()
: volume_down_pressed_(false) {
Shell::GetInstance()->PrependPreTargetHandler(this);
}
ScreenshotActionHandler::~ScreenshotActionHandler() {
Shell::GetInstance()->RemovePreTargetHandler(this);
}
void ScreenshotActionHandler::OnKeyEvent(ui::KeyEvent* event) {
if (event->key_code() == ui::VKEY_VOLUME_DOWN) {
volume_down_pressed_ = event->type() == ui::ET_KEY_PRESSED ||
event->type() == ui::ET_TRANSLATED_KEY_PRESS;
} else if (volume_down_pressed_ &&
event->key_code() == ui::VKEY_POWER &&
event->type() == ui::ET_KEY_PRESSED) {
Shell::GetInstance()->accelerator_controller()->PerformAction(
ash::TAKE_SCREENSHOT, ui::Accelerator());
}
}
#endif // OS_CHROMEOS
} // namespace } // namespace
MaximizeModeController::MaximizeModeController() MaximizeModeController::MaximizeModeController()
...@@ -158,10 +205,14 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base, ...@@ -158,10 +205,14 @@ void MaximizeModeController::HandleHingeRotation(const gfx::Vector3dF& base,
angle < kExitMaximizeModeAngle) { angle < kExitMaximizeModeAngle) {
Shell::GetInstance()->EnableMaximizeModeWindowManager(false); Shell::GetInstance()->EnableMaximizeModeWindowManager(false);
event_blocker_.reset(); event_blocker_.reset();
event_handler_.reset();
} else if (!maximize_mode_engaged && } else if (!maximize_mode_engaged &&
angle > kEnterMaximizeModeAngle) { angle > kEnterMaximizeModeAngle) {
Shell::GetInstance()->EnableMaximizeModeWindowManager(true); Shell::GetInstance()->EnableMaximizeModeWindowManager(true);
event_blocker_.reset(new MaximizeModeEventBlocker); event_blocker_.reset(new MaximizeModeEventBlocker);
#if defined(OS_CHROMEOS)
event_handler_.reset(new ScreenshotActionHandler);
#endif
} }
} }
......
...@@ -10,6 +10,10 @@ ...@@ -10,6 +10,10 @@
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/scoped_ptr.h" #include "base/memory/scoped_ptr.h"
namespace ui {
class EventHandler;
}
namespace ash { namespace ash {
class MaximizeModeEventBlocker; class MaximizeModeEventBlocker;
...@@ -53,10 +57,13 @@ class ASH_EXPORT MaximizeModeController : public AccelerometerObserver { ...@@ -53,10 +57,13 @@ class ASH_EXPORT MaximizeModeController : public AccelerometerObserver {
// screen. // screen.
void HandleScreenRotation(const gfx::Vector3dF& lid); void HandleScreenRotation(const gfx::Vector3dF& lid);
// An event handler which traps mouse and keyboard events while maximize // An event targeter controller which traps mouse and keyboard events while
// mode is engaged. // maximize mode is engaged.
scoped_ptr<MaximizeModeEventBlocker> event_blocker_; scoped_ptr<MaximizeModeEventBlocker> event_blocker_;
// An event handler used to detect screenshot actions while in maximize mode.
scoped_ptr<ui::EventHandler> event_handler_;
// When true calls to OnAccelerometerUpdated will not rotate the display. // When true calls to OnAccelerometerUpdated will not rotate the display.
bool rotation_locked_; bool rotation_locked_;
......
...@@ -10,6 +10,8 @@ ...@@ -10,6 +10,8 @@
#include "ash/system/tray/system_tray_delegate.h" #include "ash/system/tray/system_tray_delegate.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "ash/test/display_manager_test_api.h" #include "ash/test/display_manager_test_api.h"
#include "ash/test/test_lock_state_controller_delegate.h"
#include "ash/test/test_screenshot_delegate.h"
#include "ash/test/test_volume_control_delegate.h" #include "ash/test/test_volume_control_delegate.h"
#include "ui/aura/test/event_generator.h" #include "ui/aura/test/event_generator.h"
#include "ui/events/event_handler.h" #include "ui/events/event_handler.h"
...@@ -329,6 +331,36 @@ TEST_F(MaximizeModeControllerTest, BlocksKeyboard) { ...@@ -329,6 +331,36 @@ TEST_F(MaximizeModeControllerTest, BlocksKeyboard) {
counter.reset(); counter.reset();
} }
#if defined(OS_CHROMEOS)
// Tests that a screenshot can be taken in maximize mode by holding volume down
// and pressing power.
TEST_F(MaximizeModeControllerTest, Screenshot) {
Shell::GetInstance()->lock_state_controller()->SetDelegate(
new test::TestLockStateControllerDelegate);
aura::Window* root = Shell::GetPrimaryRootWindow();
aura::test::EventGenerator event_generator(root, root);
test::TestScreenshotDelegate* delegate = GetScreenshotDelegate();
delegate->set_can_take_screenshot(true);
// Open up 270 degrees.
TriggerAccelerometerUpdate(gfx::Vector3dF(0.0f, 0.0f, 1.0f),
gfx::Vector3dF(1.0f, 0.0f, 0.0f));
ASSERT_TRUE(IsMaximizeModeStarted());
// Pressing power alone does not take a screenshot.
event_generator.PressKey(ui::VKEY_POWER, 0);
event_generator.ReleaseKey(ui::VKEY_POWER, 0);
EXPECT_EQ(0, delegate->handle_take_screenshot_count());
// Holding volume down and pressing power takes a screenshot.
event_generator.PressKey(ui::VKEY_VOLUME_DOWN, 0);
event_generator.PressKey(ui::VKEY_POWER, 0);
event_generator.ReleaseKey(ui::VKEY_POWER, 0);
EXPECT_EQ(1, delegate->handle_take_screenshot_count());
event_generator.ReleaseKey(ui::VKEY_VOLUME_DOWN, 0);
}
#endif // OS_CHROMEOS
// Tests that maximize mode does not block Volume Up & Down events. // Tests that maximize mode does not block Volume Up & Down events.
TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) { TEST_F(MaximizeModeControllerTest, AllowsVolumeControl) {
aura::Window* root = Shell::GetPrimaryRootWindow(); aura::Window* root = Shell::GetPrimaryRootWindow();
......
...@@ -63,7 +63,11 @@ ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent( ...@@ -63,7 +63,11 @@ ui::EventTarget* BlockKeyboardAndTouchpadTargeter::FindTargetForEvent(
// (i.e. F9 and F10) from the device's keyboard. https://crbug.com/368669 // (i.e. F9 and F10) from the device's keyboard. https://crbug.com/368669
ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(event); ui::KeyEvent* key_event = static_cast<ui::KeyEvent*>(event);
if (key_event->key_code() != ui::VKEY_VOLUME_DOWN && if (key_event->key_code() != ui::VKEY_VOLUME_DOWN &&
key_event->key_code() != ui::VKEY_VOLUME_UP) { key_event->key_code() != ui::VKEY_VOLUME_UP
#if defined(OS_CHROMEOS)
&& key_event->key_code() != ui::VKEY_POWER
#endif
) {
return NULL; return NULL;
} }
} }
......
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