Commit 54680200 authored by mukai@chromium.org's avatar mukai@chromium.org

Ignores screenshot taking invocations if it's too close to the previous one.


R=sky@chromium.org
BUG=135535
TEST=manually checked the behavior by keep pressing Ctrl-F5 on lumpy


Review URL: https://chromiumcodereview.appspot.com/10802046

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148062 0039d316-1c4b-4281-b951-d872f2087c98
parent e03dc78d
......@@ -443,7 +443,8 @@ bool AcceleratorController::PerformAction(int action,
return HandleRestoreTab();
case TAKE_SCREENSHOT:
case TAKE_SCREENSHOT_BY_PRTSCN_KEY:
if (screenshot_delegate_.get()) {
if (screenshot_delegate_.get() &&
screenshot_delegate_->CanTakeScreenshot()) {
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
for (size_t i = 0; i < root_windows.size(); ++i)
screenshot_delegate_->HandleTakeScreenshot(root_windows[i]);
......
......@@ -81,6 +81,10 @@ class DummyScreenshotDelegate : public ScreenshotDelegate {
++handle_take_partial_screenshot_count_;
}
virtual bool CanTakeScreenshot() OVERRIDE {
return true;
}
int handle_take_screenshot_count() const {
return handle_take_screenshot_count_;
}
......
......@@ -40,6 +40,10 @@ class DummyScreenshotDelegate : public ScreenshotDelegate {
// Do nothing because it's not tested yet.
}
virtual bool CanTakeScreenshot() OVERRIDE {
return true;
}
int handle_take_screenshot_count() const {
return handle_take_screenshot_count_;
}
......
......@@ -29,6 +29,9 @@ class ScreenshotDelegate {
// window.
virtual void HandleTakePartialScreenshot(
aura::Window* window, const gfx::Rect& rect) = 0;
// Returns true if the system is ready to take screenshot.
virtual bool CanTakeScreenshot() = 0;
};
} // namespace ash
......
......@@ -33,6 +33,8 @@
#endif
namespace {
const int kScreenshotMinimumIntervalInMS = 500;
bool ShouldUse24HourClock() {
#if defined(OS_CHROMEOS)
Profile* profile = ProfileManager::GetDefaultProfileOrOffTheRecord();
......@@ -138,6 +140,10 @@ ScreenshotTaker::ScreenshotTaker() {
ScreenshotTaker::~ScreenshotTaker() {
}
void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
HandleTakePartialScreenshot(window, window->bounds());
}
void ScreenshotTaker::HandleTakePartialScreenshot(
aura::Window* window, const gfx::Rect& rect) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
......@@ -164,6 +170,7 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
bool use_24hour_clock = ShouldUse24HourClock();
if (GrabWindowSnapshot(window, rect, &png_data->data())) {
last_screenshot_timestamp_ = base::Time::Now();
DisplayVisualFeedback(rect);
content::BrowserThread::PostTask(
content::BrowserThread::FILE, FROM_HERE,
......@@ -174,8 +181,11 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
}
}
void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
HandleTakePartialScreenshot(window, window->bounds());
bool ScreenshotTaker::CanTakeScreenshot() {
return last_screenshot_timestamp_.is_null() ||
base::Time::Now() - last_screenshot_timestamp_ >
base::TimeDelta::FromMilliseconds(
kScreenshotMinimumIntervalInMS);
}
void ScreenshotTaker::CloseVisualFeedbackLayer() {
......
......@@ -8,6 +8,7 @@
#include "ash/screenshot_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/time.h"
#include "ui/compositor/layer.h"
namespace aura {
......@@ -21,8 +22,9 @@ class ScreenshotTaker : public ash::ScreenshotDelegate {
// Overridden from ash::ScreenshotDelegate:
virtual void HandleTakeScreenshot(aura::Window* window) OVERRIDE;
virtual void HandleTakePartialScreenshot(
aura::Window* window, const gfx::Rect& rect) OVERRIDE;
virtual void HandleTakePartialScreenshot(aura::Window* window,
const gfx::Rect& rect) OVERRIDE;
virtual bool CanTakeScreenshot() OVERRIDE;
private:
// Flashes the screen to provide visual feedback that a screenshot has
......@@ -32,6 +34,11 @@ class ScreenshotTaker : public ash::ScreenshotDelegate {
// Closes the visual feedback layer.
void CloseVisualFeedbackLayer();
// The timestamp when the screenshot task was issued last time.
base::Time last_screenshot_timestamp_;
// The flashing effect of the screen for the visual feedback when taking a
// screenshot.
scoped_ptr<ui::Layer> visual_feedback_layer_;
DISALLOW_COPY_AND_ASSIGN(ScreenshotTaker);
......
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