Commit 7c9cfe0a authored by mukai@chromium.org's avatar mukai@chromium.org

Make the visual feedback for taking screenshot, with fix.

This is almost identical with http://codereview.chromium.org/9430041
but contains the fix for the compilation failure on linux-clang
http://build.chromium.org/p/chromium.chromiumos/builders/Linux%20ChromiumOS%20%28Clang%20dbg%29/builds/8613/steps/compile/logs/stdio

BUG=113467
TEST=manually


Review URL: http://codereview.chromium.org/9545014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124929 0039d316-1c4b-4281-b951-d872f2087c98
parent d2e03f81
......@@ -6,6 +6,8 @@
#include <string>
#include "ash/shell.h"
#include "ash/shell_window_ids.h"
#include "base/bind.h"
#include "base/file_path.h"
#include "base/file_util.h"
......@@ -64,11 +66,21 @@ void SaveScreenshot(bool is_logged_in,
}
}
// How opaque should the layer that we flash onscreen to provide visual
// feedback after the screenshot is taken be?
const float kVisualFeedbackLayerOpacity = 0.25f;
// How long should the visual feedback layer be displayed?
const int64 kVisualFeedbackLayerDisplayTimeMs = 100;
} // namespace
ScreenshotTaker::ScreenshotTaker() {
}
ScreenshotTaker::~ScreenshotTaker() {
}
void ScreenshotTaker::HandleTakePartialScreenshot(
aura::Window* window, const gfx::Rect& rect) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
......@@ -81,6 +93,7 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
#endif
if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) {
DisplayVisualFeedback(rect);
content::BrowserThread::PostTask(
content::BrowserThread::FILE, FROM_HERE,
base::Bind(&SaveScreenshot, is_logged_in, png_data));
......@@ -92,3 +105,25 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
HandleTakePartialScreenshot(window, window->bounds());
}
void ScreenshotTaker::CloseVisualFeedbackLayer() {
visual_feedback_layer_.reset();
}
void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) {
visual_feedback_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR));
visual_feedback_layer_->SetColor(SK_ColorWHITE);
visual_feedback_layer_->SetOpacity(kVisualFeedbackLayerOpacity);
visual_feedback_layer_->SetBounds(rect);
ui::Layer* parent = ash::Shell::GetInstance()->GetContainer(
ash::internal::kShellWindowId_OverlayContainer)->layer();
parent->Add(visual_feedback_layer_.get());
visual_feedback_layer_->SetVisible(true);
MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer,
base::Unretained(this)),
base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs));
}
......@@ -9,6 +9,7 @@
#include "ash/screenshot_delegate.h"
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "ui/gfx/compositor/layer.h"
namespace aura {
class Window;
......@@ -17,6 +18,7 @@ class Window;
class ScreenshotTaker : public ash::ScreenshotDelegate {
public:
ScreenshotTaker();
virtual ~ScreenshotTaker();
// Overridden from ash::ScreenshotDelegate:
virtual void HandleTakeScreenshot(aura::Window* window) OVERRIDE;
......@@ -24,6 +26,15 @@ class ScreenshotTaker : public ash::ScreenshotDelegate {
aura::Window* window, const gfx::Rect& rect) OVERRIDE;
private:
// Flashes the screen to provide visual feedback that a screenshot has
// been taken.
void DisplayVisualFeedback(const gfx::Rect& rect);
// Closes the visual feedback layer.
void CloseVisualFeedbackLayer();
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