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

Unified Diff: chrome/browser/ui/window_snapshot/window_snapshot_mac.mm

Issue 8523022: Change snasphotting API to take in a bounds Rect (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Nicer diff 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_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..a56f3a87d54bf7651d8e41eb733115cda4310c07 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm
@@ -13,18 +13,36 @@
namespace browser {
-gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window,
- std::vector<unsigned char>* png_representation) {
+bool 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());
Nico 2011/11/15 17:10:09 DCHECK_LE. Also below.
+ DCHECK(screen_snapshot_bounds.bottom() <= window_bounds.bottom());
+
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,
+ screen_snapshot_bounds.ToCGRect(), kCGWindowListOptionIncludingWindow,
[[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming));
if (CGImageGetWidth(windowSnapshot) <= 0)
- return gfx::Rect();
+ return false;
scoped_nsobject<NSBitmapImageRep> rep(
[[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]);
@@ -32,13 +50,12 @@ gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window,
const unsigned char* buf = static_cast<const unsigned char*>([data bytes]);
NSUInteger length = [data length];
if (buf == NULL || length == 0)
- return gfx::Rect();
+ return false;
png_representation->assign(buf, buf + length);
DCHECK(!png_representation->empty());
- return gfx::Rect(static_cast<int>([rep pixelsWide]),
- static_cast<int>([rep pixelsHigh]));
+ return true;
}
} // namespace browser

Powered by Google App Engine
This is Rietveld 408576698