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