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

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: 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..515700332f5437cbde4415224decc2409ed4d1af 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_win.cc
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_win.cc
@@ -15,7 +15,8 @@
namespace browser {
gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
- std::vector<unsigned char>* png_representation) {
+ std::vector<unsigned char>* png_representation,
+ gfx::Rect snapshot_bounds) {
// Create a memory DC that's compatible with the window.
HDC window_hdc = GetWindowDC(window_handle);
base::win::ScopedCreateDC mem_hdc(CreateCompatibleDC(window_hdc));
@@ -24,10 +25,20 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window_handle,
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;
+
+ if (snapshot_bounds.IsEmpty()) {
+ snapshot_bounds(gfx::Size(content_rect.right - content_rect.left,
+ content_rect.bottom - content_rect.top));
+ } else {
+ snapshot_bounds.Offset(content_rect.left, content_rect.top);
+ DCHECK(snapshot_bounds.right() <= content_rect.right);
+ DCHECK(snapshot_bounds.bottom() <= content_rect.bottom);
+ }
+
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 +52,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 +66,23 @@ 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(), 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