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

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

Issue 9874030: Revert http://codereview.chromium.org/9838043/ (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/ash/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/ash/screenshot_taker.h" 5 #include "chrome/browser/ui/views/ash/screenshot_taker.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "ash/shell.h" 9 #include "ash/shell.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 screenshot_filename); 59 screenshot_filename);
60 if (!file_util::ReplaceFile(screenshot_path, real_path)) { 60 if (!file_util::ReplaceFile(screenshot_path, real_path)) {
61 LOG(ERROR) << "Failed to rename the file to " << real_path.value(); 61 LOG(ERROR) << "Failed to rename the file to " << real_path.value();
62 } 62 }
63 } 63 }
64 } else { 64 } else {
65 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); 65 LOG(ERROR) << "Failed to save to " << screenshot_path.value();
66 } 66 }
67 } 67 }
68 68
69 // Actually takes the screenshot. 69 // How opaque should the layer that we flash onscreen to provide visual
70 void TakeScreenshot(aura::Window* window, const gfx::Rect& rect) { 70 // feedback after the screenshot is taken be?
71 const float kVisualFeedbackLayerOpacity = 0.25f;
72
73 // How long should the visual feedback layer be displayed?
74 const int64 kVisualFeedbackLayerDisplayTimeMs = 100;
75
76 } // namespace
77
78 ScreenshotTaker::ScreenshotTaker() {
79 }
80
81 ScreenshotTaker::~ScreenshotTaker() {
82 }
83
84 void ScreenshotTaker::HandleTakePartialScreenshot(
85 aura::Window* window, const gfx::Rect& rect) {
71 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); 86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
72 87
73 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); 88 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes);
74 89
75 bool is_logged_in = true; 90 bool is_logged_in = true;
76 #if defined(OS_CHROMEOS) 91 #if defined(OS_CHROMEOS)
77 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn(); 92 is_logged_in = chromeos::UserManager::Get()->IsUserLoggedIn();
78 #endif 93 #endif
79 94
80 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { 95 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) {
96 DisplayVisualFeedback(rect);
81 content::BrowserThread::PostTask( 97 content::BrowserThread::PostTask(
82 content::BrowserThread::FILE, FROM_HERE, 98 content::BrowserThread::FILE, FROM_HERE,
83 base::Bind(&SaveScreenshot, is_logged_in, png_data)); 99 base::Bind(&SaveScreenshot, is_logged_in, png_data));
84 } else { 100 } else {
85 LOG(ERROR) << "Failed to grab the window screenshot"; 101 LOG(ERROR) << "Failed to grab the window screenshot";
86 } 102 }
87 } 103 }
88 104
89 // How opaque should the layer that we flash onscreen to provide visual
90 // feedback after the screenshot is taken be?
91 const float kVisualFeedbackLayerOpacity = 0.25f;
92
93 // How long should the visual feedback layer be displayed?
94 const int64 kVisualFeedbackLayerDisplayTimeMs = 100;
95
96 } // namespace
97
98 ScreenshotTaker::ScreenshotTaker() {
99 }
100
101 ScreenshotTaker::~ScreenshotTaker() {
102 }
103
104 void ScreenshotTaker::HandleTakePartialScreenshot(aura::Window* window,
105 const gfx::Rect& rect) {
106 // browser::GrabWindowSnapshot takes ~100msec and making visual feedback after
107 // that leads noticeable delay. To prevent this delay, we just make the
108 // visual effect first, and then run the actual task of taking screenshot.
109 DisplayVisualFeedback(
110 rect,
111 base::Bind(&TakeScreenshot, base::Unretained(window), rect));
112 }
113
114 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { 105 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) {
115 HandleTakePartialScreenshot(window, window->bounds()); 106 HandleTakePartialScreenshot(window, window->bounds());
116 } 107 }
117 108
118 void ScreenshotTaker::CloseVisualFeedbackLayer(const base::Closure& task) { 109 void ScreenshotTaker::CloseVisualFeedbackLayer() {
119 visual_feedback_layer_.reset(); 110 visual_feedback_layer_.reset();
120 task.Run();
121 } 111 }
122 112
123 void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect, 113 void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) {
124 const base::Closure& task) {
125 visual_feedback_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); 114 visual_feedback_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR));
126 visual_feedback_layer_->SetColor(SK_ColorWHITE); 115 visual_feedback_layer_->SetColor(SK_ColorWHITE);
127 visual_feedback_layer_->SetOpacity(kVisualFeedbackLayerOpacity); 116 visual_feedback_layer_->SetOpacity(kVisualFeedbackLayerOpacity);
128 visual_feedback_layer_->SetBounds(rect); 117 visual_feedback_layer_->SetBounds(rect);
129 118
130 ui::Layer* parent = ash::Shell::GetInstance()->GetContainer( 119 ui::Layer* parent = ash::Shell::GetInstance()->GetContainer(
131 ash::internal::kShellWindowId_OverlayContainer)->layer(); 120 ash::internal::kShellWindowId_OverlayContainer)->layer();
132 parent->Add(visual_feedback_layer_.get()); 121 parent->Add(visual_feedback_layer_.get());
133 visual_feedback_layer_->SetVisible(true); 122 visual_feedback_layer_->SetVisible(true);
134 123
135 MessageLoopForUI::current()->PostDelayedTask( 124 MessageLoopForUI::current()->PostDelayedTask(
136 FROM_HERE, 125 FROM_HERE,
137 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, 126 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer,
138 base::Unretained(this), 127 base::Unretained(this)),
139 task),
140 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); 128 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs));
141 } 129 }
OLDNEW
« 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