Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(919)

Unified Diff: chrome/browser/ui/views/ash/screenshot_taker.cc

Issue 9838043: Change the order of visual feedback effect and grabbing screenshot. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove unnecessary comment Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/ui/views/ash/screenshot_taker.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/views/ash/screenshot_taker.cc
diff --git a/chrome/browser/ui/views/ash/screenshot_taker.cc b/chrome/browser/ui/views/ash/screenshot_taker.cc
index b5f78289ca467c3f33281d786ba65ebca508d913..1657409ab7d4491df66b307632e0465e2504d18d 100644
--- a/chrome/browser/ui/views/ash/screenshot_taker.cc
+++ b/chrome/browser/ui/views/ash/screenshot_taker.cc
@@ -66,23 +66,8 @@ 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) {
+// Actually takes the screenshot.
+void TakeScreenshot(aura::Window* window, const gfx::Rect& rect) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes);
@@ -93,7 +78,6 @@ 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));
@@ -102,15 +86,42 @@ void ScreenshotTaker::HandleTakePartialScreenshot(
}
}
+// 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) {
+ // browser::GrabWindowSnapshot takes ~100msec and making visual feedback after
+ // that leads noticeable delay. To prevent this delay, we just make the
+ // visual effect first, and then run the actual task of taking screenshot.
+ DisplayVisualFeedback(
+ rect,
+ base::Bind(&TakeScreenshot, base::Unretained(window), rect));
+}
+
void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
HandleTakePartialScreenshot(window, window->bounds());
}
-void ScreenshotTaker::CloseVisualFeedbackLayer() {
+void ScreenshotTaker::CloseVisualFeedbackLayer(const base::Closure& task) {
visual_feedback_layer_.reset();
+ task.Run();
}
-void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) {
+void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect,
+ const base::Closure& task) {
visual_feedback_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR));
visual_feedback_layer_->SetColor(SK_ColorWHITE);
visual_feedback_layer_->SetOpacity(kVisualFeedbackLayerOpacity);
@@ -124,6 +135,7 @@ void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) {
MessageLoopForUI::current()->PostDelayedTask(
FROM_HERE,
base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer,
- base::Unretained(this)),
+ base::Unretained(this),
+ task),
base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs));
}
« no previous file with comments | « chrome/browser/ui/views/ash/screenshot_taker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698