Chromium Code Reviews| 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" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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 |
| 81 ScreenshotTaker::~ScreenshotTaker() { | |
| 82 } | |
| 83 | |
| 72 void ScreenshotTaker::HandleTakePartialScreenshot( | 84 void ScreenshotTaker::HandleTakePartialScreenshot( |
| 73 aura::Window* window, const gfx::Rect& rect) { | 85 aura::Window* window, const gfx::Rect& rect) { |
| 74 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); | 86 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI)); |
| 75 | 87 |
| 76 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); | 88 scoped_refptr<RefCountedBytes> png_data(new RefCountedBytes); |
| 77 | 89 |
| 78 bool is_logged_in = true; | 90 bool is_logged_in = true; |
| 79 #if defined(OS_CHROMEOS) | 91 #if defined(OS_CHROMEOS) |
| 80 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in(); | 92 is_logged_in = chromeos::UserManager::Get()->user_is_logged_in(); |
| 81 #endif | 93 #endif |
| 82 | 94 |
| 83 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { | 95 if (browser::GrabWindowSnapshot(window, &png_data->data(), rect)) { |
| 96 DisplayVisualFeedback(rect); | |
| 84 content::BrowserThread::PostTask( | 97 content::BrowserThread::PostTask( |
| 85 content::BrowserThread::FILE, FROM_HERE, | 98 content::BrowserThread::FILE, FROM_HERE, |
| 86 base::Bind(&SaveScreenshot, is_logged_in, png_data)); | 99 base::Bind(&SaveScreenshot, is_logged_in, png_data)); |
| 87 } else { | 100 } else { |
| 88 LOG(ERROR) << "Failed to grab the window screenshot"; | 101 LOG(ERROR) << "Failed to grab the window screenshot"; |
| 89 } | 102 } |
| 90 } | 103 } |
| 91 | 104 |
| 92 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { | 105 void ScreenshotTaker::HandleTakeScreenshot(aura::Window* window) { |
| 93 HandleTakePartialScreenshot(window, window->bounds()); | 106 HandleTakePartialScreenshot(window, window->bounds()); |
| 94 } | 107 } |
| 108 | |
| 109 void ScreenshotTaker::CloseVisualFeedbackLayer() { | |
| 110 visual_feedback_layer_.reset(); | |
| 111 } | |
| 112 | |
| 113 void ScreenshotTaker::DisplayVisualFeedback(const gfx::Rect& rect) { | |
| 114 visual_feedback_layer_.reset(new ui::Layer(ui::Layer::LAYER_SOLID_COLOR)); | |
| 115 visual_feedback_layer_->SetColor( | |
| 116 SkColorSetA(SK_ColorWHITE, kVisualFeedbackLayerOpacity)); | |
|
Daniel Erat
2012/03/01 17:15:40
When I was adding Layer::LAYER_SOLID_COLOR, I thou
Jun Mukai
2012/03/02 03:41:18
Added SetOpacity. Just curious, is this a bug? W
| |
| 117 visual_feedback_layer_->SetBounds(rect); | |
| 118 | |
| 119 ui::Layer* parent = ash::Shell::GetInstance()->GetContainer( | |
| 120 ash::internal::kShellWindowId_OverlayContainer)->layer(); | |
| 121 parent->Add(visual_feedback_layer_.get()); | |
| 122 visual_feedback_layer_->SetVisible(true); | |
| 123 | |
| 124 MessageLoopForUI::current()->PostDelayedTask( | |
| 125 FROM_HERE, | |
| 126 base::Bind(&ScreenshotTaker::CloseVisualFeedbackLayer, | |
| 127 base::Unretained(this)), | |
| 128 base::TimeDelta::FromMilliseconds(kVisualFeedbackLayerDisplayTimeMs)); | |
| 129 } | |
| OLD | NEW |