Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(7267)

Unified Diff: chrome/browser/ui/window_snapshot/window_snapshot_win.cc

Issue 8523022: Change snasphotting API to take in a bounds Rect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes as requested Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/window_snapshot/window_snapshot_win.cc
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc
index 2d30dad10448a85de52ee78e09d2db276d06fd43..26bdb65cf62ae6aca545cf5642ef9742825ef58c 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc
@@ -14,20 +14,38 @@
namespace browser {
+namespace {
jonathan.backer 2011/11/14 13:45:02 No need to nest anon namespace. Customary to follo
+gfx::Rect GetWindowBounds(gfx::NativeWindow window_handle) {
+ RECT content_rect = {0, 0, 0, 0};
+ ::GetWindowRect(window_handle, &content_rect);
+ content_rect.right++; // Match what PrintWindow wants.
+
+ return gfx::Rect(content_rect.right - content_rect.left,
jonathan.backer 2011/11/14 13:45:02 Feel free to ignore, but aren't you really returni
+ content_rect.bottom - content_rect.top);
+}
+
+} // namespace
+
gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
std::vector<unsigned char>* png_representation) {
+ return GrabWindowSnapshot(window_handle, png_representation,
+ GetWindowBounds(window_handle));
+}
+
+gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect snapshot_bounds) {
+ DCHECK(snapshot_bounds.right() <= GetWindowBounds(window_handle).right());
+ DCHECK(snapshot_bounds.bottom() <= GetWindowBounds(window_handle).bottom());
+
// Create a memory DC that's compatible with the window.
HDC window_hdc = GetWindowDC(window_handle);
base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
- // Create a DIB that's the same size as the window.
- RECT content_rect = {0, 0, 0, 0};
- ::GetWindowRect(window_handle, &content_rect);
- content_rect.right++; // Match what PrintWindow wants.
- int width = content_rect.right - content_rect.left;
- int height = content_rect.bottom - content_rect.top;
BITMAPINFOHEADER hdr;
- gfx::CreateBitmapHeader(width, height, &hdr);
+ gfx::CreateBitmapHeader(snapshot_bounds.width(),
+ snapshot_bounds.height(),
+ &hdr);
unsigned char *bit_ptr = NULL;
base::win::ScopedBitmap bitmap(
CreateDIBSection(mem_hdc,
@@ -41,7 +59,8 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
// show up on a white background, and strangely-shaped windows
// look reasonable). Not capturing an alpha mask saves a
// bit of space.
- PatBlt(mem_hdc, 0, 0, width, height, WHITENESS);
+ PatBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(),
+ WHITENESS);
// Grab a copy of the window
// First, see if PrintWindow is defined (it's not in Windows 2000).
typedef BOOL (WINAPI *PrintWindowPointer)(HWND, HDC, UINT);
@@ -54,22 +73,24 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
// Otherwise grab the bits we can get with BitBlt; it's better
// than nothing and will work fine in the average case (window is
// completely on screen).
- if (print_window)
+ if (snapshot_bounds.origin() == gfx::Point() && print_window)
(*print_window)(window_handle, mem_hdc, 0);
else
- BitBlt(mem_hdc, 0, 0, width, height, window_hdc, 0, 0, SRCCOPY);
+ BitBlt(mem_hdc, 0, 0, snapshot_bounds.width(), snapshot_bounds.height(),
+ window_hdc, snapshot_bounds.x(), snapshot_bounds.y(), SRCCOPY);
// We now have a copy of the window contents in a DIB, so
// encode it into a useful format for posting to the bug report
// server.
gfx::PNGCodec::Encode(bit_ptr, gfx::PNGCodec::FORMAT_BGRA,
- gfx::Size(width, height), width * 4, true,
+ snapshot_bounds.size(),
+ snapshot_bounds.width() * 4, true,
std::vector<gfx::PNGCodec::Comment>(),
png_representation);
ReleaseDC(window_handle, window_hdc);
- return gfx::Rect(width, height);
+ return gfx::Rect(snapshot_bounds.size());
}
} // namespace browser

Powered by Google App Engine
This is Rietveld 408576698