Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
|
robertshield
2012/04/11 17:03:36
2012
| |
| 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/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.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(gfx::NativeWindow window_handle) { |
| 18 RECT content_rect = {0, 0, 0, 0}; | 18 RECT content_rect = {0, 0, 0, 0}; |
| 19 ::GetWindowRect(window_handle, &content_rect); | 19 if (window_handle) { |
|
robertshield
2012/04/11 17:03:36
perhaps if (IsWindow(window_handle))?
grt (UTC plus 2)
2012/04/11 17:33:08
I don't think so. NULL specifically means the des
| |
| 20 ::GetWindowRect(window_handle, &content_rect); | |
| 21 } else { | |
| 22 MONITORINFO monitor_info = {}; | |
| 23 monitor_info.cbSize = sizeof(monitor_info); | |
| 24 if (GetMonitorInfo(MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY), | |
| 25 &monitor_info)) { | |
| 26 content_rect = monitor_info.rcMonitor; | |
| 27 } | |
| 28 } | |
| 20 content_rect.right++; // Match what PrintWindow wants. | 29 content_rect.right++; // Match what PrintWindow wants. |
| 21 | 30 |
| 22 return gfx::Rect(content_rect.right - content_rect.left, | 31 return gfx::Rect(content_rect.right - content_rect.left, |
| 23 content_rect.bottom - content_rect.top); | 32 content_rect.bottom - content_rect.top); |
| 24 } | 33 } |
| 25 | 34 |
| 26 } // namespace | 35 } // namespace |
| 27 | 36 |
| 28 namespace browser { | 37 namespace browser { |
| 29 | 38 |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 60 // First, see if PrintWindow is defined (it's not in Windows 2000). | 69 // First, see if PrintWindow is defined (it's not in Windows 2000). |
| 61 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); | 70 typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT); |
| 62 PrintWindowPointer print_window = | 71 PrintWindowPointer print_window = |
| 63 reinterpret_cast<PrintWindowPointer>( | 72 reinterpret_cast<PrintWindowPointer>( |
| 64 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); | 73 GetProcAddress(GetModuleHandle(L"User32.dll"), "PrintWindow")); |
| 65 | 74 |
| 66 // If PrintWindow is defined, use it. It will work on partially | 75 // If PrintWindow is defined, use it. It will work on partially |
| 67 // obscured windows, and works better for out of process sub-windows. | 76 // obscured windows, and works better for out of process sub-windows. |
| 68 // Otherwise grab the bits we can get with BitBlt; it's better | 77 // Otherwise grab the bits we can get with BitBlt; it's better |
| 69 // than nothing and will work fine in the average case (window is | 78 // than nothing and will work fine in the average case (window is |
| 70 // completely on screen). | 79 // completely on screen). Always BitBlt when grabbing the whole screen. |
| 71 if (snapshot_bounds.origin() == gfx::Point() && print_window) | 80 if (snapshot_bounds.origin() == gfx::Point() && print_window && window_handle) |
| 72 (*print_window)(window_handle, mem_hdc, 0); | 81 (*print_window)(window_handle, mem_hdc, 0); |
| 73 else | 82 else |
| 74 BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), | 83 BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(), |
| 75 window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY); | 84 window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY); |
| 76 | 85 |
| 77 // We now have a copy of the window contents in a DIB, so | 86 // We now have a copy of the window contents in a DIB, so |
| 78 // encode it into a useful format for posting to the bug report | 87 // encode it into a useful format for posting to the bug report |
| 79 // server. | 88 // server. |
| 80 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, | 89 gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA, |
| 81 snapshot_bounds.size(), | 90 snapshot_bounds.size(), |
| 82 snapshot_bounds.width() * 4, true, | 91 snapshot_bounds.width() * 4, true, |
| 83 std::vector<gfx::PNGCodec::Comment>(), | 92 std::vector<gfx::PNGCodec::Comment>(), |
| 84 png_representation); | 93 png_representation); |
| 85 | 94 |
| 86 ReleaseDC(window_handle, window_hdc); | 95 ReleaseDC(window_handle, window_hdc); |
| 87 | 96 |
| 88 return true; | 97 return true; |
| 89 } | 98 } |
| 90 | 99 |
| 91 } // namespace browser | 100 } // namespace browser |
| OLD | NEW |