Index: chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
index ab790872e0db1c88dd5602bf31d0f384e2623306..47b2a535baf93c09ea0c63b101b708dbc7c2f72c 100644 |
--- a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm |
@@ -13,15 +13,17 @@ |
namespace browser { |
jonathan.backer
2011/11/14 13:45:02
Maybe move this below? No sense nesting an anonymo
|
+namespace { |
gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, |
- std::vector<unsigned char>* png_representation) { |
+ std::vector<unsigned char>* png_representation, |
+ CGRect windowRect) { |
sky
2011/11/14 16:23:09
const CGRect&
|
png_representation->clear(); |
// Make sure to grab the "window frame" view so we get current tab + |
// tabstrip. |
NSView* view = [[window contentView] superview]; |
base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( |
- CGRectNull, kCGWindowListOptionIncludingWindow, |
+ windowRect, kCGWindowListOptionIncludingWindow, |
[[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming)); |
if (CGImageGetWidth(windowSnapshot) <= 0) |
return gfx::Rect(); |
@@ -41,4 +43,36 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, |
static_cast<int>([rep pixelsHigh])); |
} |
+} // namespace |
+ |
+gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, |
+ std::vector<unsigned char>* png_representation) { |
+ return GrabWindowSnapshot(window, png_representation, CGRectNull); |
jonathan.backer
2011/11/14 13:45:02
Maybe document that CGRectNull means to grab the w
|
+} |
+ NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
jonathan.backer
2011/11/14 13:45:02
Bad merge?
|
+ |
+gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window, |
+ std::vector<unsigned char>* png_representation, |
+ const gfx::Rect snapshot_bounds) { |
+ NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
+ gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); |
+ gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame])); |
+ |
+ // Flip window coordinates based on the primary screen. |
+ window_bounds.set_y( |
+ screen_bounds.height() - window_bounds.y() - window_bounds.height()); |
+ |
+ // Convert snapshot bounds relative to window into bounds relative to |
+ // screen. |
+ gfx::Rect screen_snapshot_bounds = gfx::Rect( |
+ window_bounds.origin().Add(snapshot_bounds.origin()), |
+ snapshot_bounds.size()); |
+ |
+ DCHECK(screen_snapshot_bounds.right() <= window_bounds.right()); |
+ DCHECK(screen_snapshot_bounds.bottom() <= window_bounds.bottom()); |
+ |
+ CGRect windowRect = screen_snapshot_bounds.ToCGRect(); |
+ return GrabWindowSnapshot(window, png_representation, windowRect); |
+} |
+ |
} // namespace browser |