| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/snapshot/snapshot.h" | 5 #include "ui/snapshot/snapshot_hwnd_win.h" |
| 6 | 6 |
| 7 #include "base/win/scoped_gdi_object.h" | 7 #include "base/win/scoped_gdi_object.h" |
| 8 #include "base/win/scoped_hdc.h" | 8 #include "base/win/scoped_hdc.h" |
| 9 #include "base/win/scoped_select_object.h" | 9 #include "base/win/scoped_select_object.h" |
| 10 #include "ui/gfx/codec/png_codec.h" | 10 #include "ui/gfx/codec/png_codec.h" |
| 11 #include "ui/gfx/gdi_util.h" | 11 #include "ui/gfx/gdi_util.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/size.h" | 13 #include "ui/gfx/size.h" |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 gfx::Rect GetWindowBounds(gfx::NativeWindow window_handle) { | 17 gfx::Rect GetWindowBounds(HWND window_handle) { |
| 18 RECT content_rect = {0, 0, 0, 0}; | 18 RECT content_rect = {0, 0, 0, 0}; |
| 19 if (window_handle) { | 19 if (window_handle) { |
| 20 ::GetWindowRect(window_handle, &content_rect); | 20 ::GetWindowRect(window_handle, &content_rect); |
| 21 } else { | 21 } else { |
| 22 MONITORINFO monitor_info = {}; | 22 MONITORINFO monitor_info = {}; |
| 23 monitor_info.cbSize = sizeof(monitor_info); | 23 monitor_info.cbSize = sizeof(monitor_info); |
| 24 if (GetMonitorInfo(MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY), | 24 if (GetMonitorInfo(MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY), |
| 25 &monitor_info)) { | 25 &monitor_info)) { |
| 26 content_rect = monitor_info.rcMonitor; | 26 content_rect = monitor_info.rcMonitor; |
| 27 } | 27 } |
| 28 } | 28 } |
| 29 content_rect.right++; // Match what PrintWindow wants. | 29 content_rect.right++; // Match what PrintWindow wants. |
| 30 | 30 |
| 31 return gfx::Rect(content_rect.right - content_rect.left, | 31 return gfx::Rect(content_rect.right - content_rect.left, |
| 32 content_rect.bottom - content_rect.top); | 32 content_rect.bottom - content_rect.top); |
| 33 } | 33 } |
| 34 | 34 |
| 35 } // namespace | 35 } // namespace |
| 36 | 36 |
| 37 namespace ui { | 37 namespace ui { |
| 38 namespace internal { |
| 38 | 39 |
| 39 bool GrabViewSnapshot(gfx::NativeView view_handle, | 40 bool GrabHwndSnapshot(HWND window_handle, |
| 40 std::vector<unsigned char>* png_representation, | 41 std::vector<unsigned char>* png_representation, |
| 41 const gfx::Rect& snapshot_bounds) { | 42 const gfx::Rect& snapshot_bounds) { |
| 42 return GrabWindowSnapshot(view_handle, png_representation, snapshot_bounds); | |
| 43 } | |
| 44 | |
| 45 bool GrabWindowSnapshot(gfx::NativeWindow window_handle, | |
| 46 std::vector<unsigned char>* png_representation, | |
| 47 const gfx::Rect& snapshot_bounds) { | |
| 48 DCHECK(snapshot_bounds.right() <= GetWindowBounds(window_handle).right()); | 43 DCHECK(snapshot_bounds.right() <= GetWindowBounds(window_handle).right()); |
| 49 DCHECK(snapshot_bounds.bottom() <= GetWindowBounds(window_handle).bottom()); | 44 DCHECK(snapshot_bounds.bottom() <= GetWindowBounds(window_handle).bottom()); |
| 50 | 45 |
| 51 // Create a memory DC that's compatible with the window. | 46 // Create a memory DC that's compatible with the window. |
| 52 HDC window_hdc = GetWindowDC(window_handle); | 47 HDC window_hdc = GetWindowDC(window_handle); |
| 53 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc)); | 48 base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc)); |
| 54 | 49 |
| 55 BITMAPINFOHEADER hdr; | 50 BITMAPINFOHEADER hdr; |
| 56 gfx::CreateBitmapHeader(snapshot_bounds.width(), | 51 gfx::CreateBitmapHeader(snapshot_bounds.width(), |
| 57 snapshot_bounds.height(), | 52 snapshot_bounds.height(), |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 snapshot_bounds.size(), | 91 snapshot_bounds.size(), |
| 97 snapshot_bounds.width() * 4, true, | 92 snapshot_bounds.width() * 4, true, |
| 98 std::vector<gfx::PNGCodec::Comment>(), | 93 std::vector<gfx::PNGCodec::Comment>(), |
| 99 png_representation); | 94 png_representation); |
| 100 | 95 |
| 101 ReleaseDC(window_handle, window_hdc); | 96 ReleaseDC(window_handle, window_hdc); |
| 102 | 97 |
| 103 return true; | 98 return true; |
| 104 } | 99 } |
| 105 | 100 |
| 101 } // namespace internal |
| 106 } // namespace ui | 102 } // namespace ui |
| OLD | NEW |