OLD | NEW |
---|---|
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" |
19 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
22 #include "ui/gfx/compositor/layer.h" | |
20 | 23 |
21 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
22 #include "chrome/browser/chromeos/login/user_manager.h" | 25 #include "chrome/browser/chromeos/login/user_manager.h" |
23 #endif | 26 #endif |
24 | 27 |
25 namespace { | 28 namespace { |
26 std::string GetScreenshotFileName() { | 29 std::string GetScreenshotFileName() { |
27 base::Time::Exploded now; | 30 base::Time::Exploded now; |
28 base::Time::Now().LocalExplode(&now); | 31 base::Time::Now().LocalExplode(&now); |
29 | 32 |
(...skipping 27 matching lines...) Expand all Loading... | |
57 screenshot_filename); | 60 screenshot_filename); |
58 if (!file_util::ReplaceFile(screenshot_path, real_path)) { | 61 if (!file_util::ReplaceFile(screenshot_path, real_path)) { |
59 LOG(ERROR) << "Failed to rename the file to " << real_path.value(); | 62 LOG(ERROR) << "Failed to rename the file to " << real_path.value(); |
60 } | 63 } |
61 } | 64 } |
62 } else { | 65 } else { |
63 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); | 66 LOG(ERROR) << "Failed to save to " << screenshot_path.value(); |
64 } | 67 } |
65 } | 68 } |
66 | 69 |
70 // How opaque should the layer that we flash onscreen to provide visual | |
71 // feedback after the screenshot is taken be? | |
72 const unsigned char kVisualFeedbackWindowOpacity = 64; | |
Daniel Erat
2012/02/24 00:48:46
nit: s/Window/Layer/ in variable name
Jun Mukai
2012/02/24 02:24:55
Done.
| |
73 | |
74 // How long should the visual feedback window be displayed? | |
75 const uint64_t kVisualFeedbackWindowDisplayTimeMs = 100; | |
Daniel Erat
2012/02/24 00:48:46
s/Window/Layer/
Jun Mukai
2012/02/24 02:24:55
Done.
| |
76 | |
77 void CloseFeedbackLayer(ui::Layer* layer) { | |
78 DCHECK(layer); | |
79 layer->SetVisible(false); | |
Daniel Erat
2012/02/24 00:48:46
nit: unneeded; deleting it makes it invisible :-)
Jun Mukai
2012/02/24 02:24:55
Done.
| |
80 delete layer; | |
81 } | |
82 | |
83 // Flashes the screen to provide visual feedback that a screenshot has | |
84 // been taken. | |
85 void DisplayVisualFeedback(const gfx::Rect& rect) { | |
86 scoped_ptr<ui::Layer> layer(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR)); | |
87 layer->SetColor(SkColorSetA(SK_ColorWHITE, kVisualFeedbackWindowOpacity)); | |
88 layer->SetBounds(rect); | |
89 | |
90 ui::Layer* parent = ash::Shell::GetInstance()->GetContainer( | |
91 ash::internal::kShellWindowId_OverlayContainer)->layer(); | |
92 parent->Add(layer.get()); | |
93 layer->SetVisible(true); | |
94 | |
95 MessageLoopForUI::current()->PostDelayedTask( | |
96 FROM_HERE, | |
97 base::Bind(&CloseFeedbackLayer, base::Unretained(layer.release())), | |
Daniel Erat
2012/02/24 00:48:46
i meant that you could make these functions instea
Jun Mukai
2012/02/24 02:24:55
Ah, thank you for the explanation. Done.
| |
98 kVisualFeedbackWindowDisplayTimeMs); | |
99 } | |
100 | |
67 } // namespace | 101 } // namespace |
68 | 102 |
69 ScreenshotTaker::ScreenshotTaker() { | 103 ScreenshotTaker::ScreenshotTaker() { |
70 } | 104 } |
71 | 105 |
72 void ScreenshotTaker::HandleTakePartialScreenshot( | 106 void ScreenshotTaker::HandleTakePartialScreenshot( |
73 aura::Window* window, const gfx::Rect& rect) { | 107 aura::Window* window, const gfx::Rect& rect) { |
74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 108 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
75 | 109 |
76 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); | 110 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); |
77 | 111 |
78 bool is_logged_in = true; | 112 bool is_logged_in = true; |
79 #if defined(OS_CHROMEOS) | 113 #if defined(OS_CHROMEOS) |
80 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in(); | 114 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in(); |
81 #endif | 115 #endif |
82 | 116 |
83 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { | 117 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { |
118 DisplayVisualFeedback(rect); | |
84 content::BrowserThread::PostTask( | 119 content::BrowserThread::PostTask( |
85 content::BrowserThread::FILE, FROM_HERE, | 120 content::BrowserThread::FILE, FROM_HERE, |
86 base::Bind(&SaveScreenshot, is_logged_in, png_data)); | 121 base::Bind(&SaveScreenshot, is_logged_in, png_data)); |
87 } else { | 122 } else { |
88 LOG(ERROR) << "Failed to grab the window screenshot"; | 123 LOG(ERROR) << "Failed to grab the window screenshot"; |
89 } | 124 } |
90 } | 125 } |
91 | 126 |
92 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { | 127 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { |
93 HandleTakePartialScreenshot(window, window->bounds()); | 128 HandleTakePartialScreenshot(window, window->bounds()); |
94 } | 129 } |
OLD | NEW |