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

Side by Side Diff: chrome/browser/ui/views/aura/screenshot_taker.cc

Issue 9430041: Makes the visual feedback for taking screenshot. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: rebase 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/aura/screenshot_taker.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/aura/screenshot_taker.h" 5 #include "chrome/browser/ui/views/aura/screenshot_taker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h"
9 #include "base/bind.h" 11 #include "base/bind.h"
10 #include "base/file_path.h" 12 #include "base/file_path.h"
11 #include "base/file_util.h" 13 #include "base/file_util.h"
12 #include "base/logging.h" 14 #include "base/logging.h"
13 #include "base/memory/ref_counted_memory.h" 15 #include "base/memory/ref_counted_memory.h"
14 #include "base/stringprintf.h" 16 #include "base/stringprintf.h"
15 #include "base/time.h" 17 #include "base/time.h"
16 #include "chrome/browser/download/download_util.h" 18 #include "chrome/browser/download/download_util.h"
17 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" 19 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
18 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 screenshot_filename); 59 screenshot_filename);
58 if (!file_util::ReplaceFile(screenshot_path, real_path)) { 60 if (!file_util::ReplaceFile(screenshot_path, real_path)) {
59 LOG(ERROR) << "Failed to rename the file to " << real_path.value(); 61 LOG(ERROR) << "Failed to rename the file to " << real_path.value();
60 } 62 }
61 } 63 }
62 } else { 64 } else {
63 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); 65 LOG(ERROR) << "Failed to save to " << screenshot_path.value();
64 } 66 }
65 } 67 }
66 68
69 // How opaque should the layer that we flash onscreen to provide visual
70 // feedback after the screenshot is taken be?
71 const unsigned char kVisualFeedbackLayerOpacity = 64;
72
73 // How long should the visual feedback layer be displayed?
74 const int64 kVisualFeedbackLayerDisplayTimeMs = 100;
75
67 } // namespace 76 } // namespace
68 77
69 ScreenshotTaker::ScreenshotTaker() { 78 ScreenshotTaker::ScreenshotTaker() {
70 } 79 }
71 80
72 void ScreenshotTaker::HandleTakePartialScreenshot( 81 void ScreenshotTaker::HandleTakePartialScreenshot(
73 aura::Window* window, const gfx::Rect& rect) { 82 aura::Window* window, const gfx::Rect& rect) {
74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 83 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
75 84
76 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); 85 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes);
77 86
78 bool is_logged_in = true; 87 bool is_logged_in = true;
79 #if defined(OS_CHROMEOS) 88 #if defined(OS_CHROMEOS)
80 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in(); 89 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in();
81 #endif 90 #endif
82 91
83 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { 92 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) {
93 DisplayVisualFeedback(rect);
84 content::BrowserThread::PostTask( 94 content::BrowserThread::PostTask(
85 content::BrowserThread::FILE, FROM_HERE, 95 content::BrowserThread::FILE, FROM_HERE,
86 base::Bind(&SaveScreenshot, is_logged_in, png_data)); 96 base::Bind(&SaveScreenshot, is_logged_in, png_data));
87 } else { 97 } else {
88 LOG(ERROR) << "Failed to grab the window screenshot"; 98 LOG(ERROR) << "Failed to grab the window screenshot";
89 } 99 }
90 } 100 }
91 101
92 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { 102 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
93 HandleTakePartialScreenshot(window, window->bounds()); 103 HandleTakePartialScreenshot(window, window->bounds());
94 } 104 }
105
106 void ScreenshotTaker::CloseVisualFeedbackLayer() {
107 visual_feedback_layer_.reset();
108 }
109
110 void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) {
111 visual_feedback_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR));
112 visual_feedback_layer_->SetColor(
113 SkColorSetA(SK_ColorWHITE, kVisualFeedbackLayerOpacity));
114 visual_feedback_layer_->SetBounds(rect);
115
116 ui::Layer* parent = ash::Shell::GetInstance()->GetContainer(
117 ash::internal::kShellWindowId_OverlayContainer)->layer();
118 parent->Add(visual_feedback_layer_.get());
119 visual_feedback_layer_->SetVisible(true);
120
121 MessageLoopForUI::current()->PostDelayedTask(
122 FROM_HERE,
123 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer,
124 base::Unretained(this)),
125 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs));
126 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/aura/screenshot_taker.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698