diff options
author | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-12 21:06:12 +0000 |
---|---|---|
committer | rkc@chromium.org <rkc@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-12 21:06:12 +0000 |
commit | b25edd5d882736340e3b4c5de68536535eaa1468 (patch) | |
tree | e3a498395e838b97bfd26e944491c6d3a0e3a52d /base/mac | |
parent | 2b2276608f079e2d59d2aeaf4321e1a2c0fa749c (diff) | |
download | chromium_src-b25edd5d882736340e3b4c5de68536535eaa1468.zip chromium_src-b25edd5d882736340e3b4c5de68536535eaa1468.tar.gz chromium_src-b25edd5d882736340e3b4c5de68536535eaa1468.tar.bz2 |
Fix GrabWindowSnapshot for Mac Chrome.
Changed the mechanism to take a screenshot over to CG; we now just take a direct bit dump of the window into an image and convert that to a png.
BUG=69160
TEST=Tested with sending feedback from a Mac; screenshot appeared on screen and on the report correctly.
Review URL: http://codereview.chromium.org/6121005
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71233 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac')
-rw-r--r-- | base/mac/mac_util.mm | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/base/mac/mac_util.mm b/base/mac/mac_util.mm index 21213ba..f5eb03d 100644 --- a/base/mac/mac_util.mm +++ b/base/mac/mac_util.mm @@ -359,21 +359,31 @@ bool ShouldWindowsMiniaturizeOnDoubleClick() { void GrabWindowSnapshot(NSWindow* window, std::vector<unsigned char>* png_representation, int* width, int* height) { + png_representation->clear(); + *width = 0; + *height = 0; + // Make sure to grab the "window frame" view so we get current tab + // tabstrip. NSView* view = [[window contentView] superview]; - NSBitmapImageRep* rep = - [view bitmapImageRepForCachingDisplayInRect:[view bounds]]; - [view cacheDisplayInRect:[view bounds] toBitmapImageRep:rep]; + ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( + CGRectNull, kCGWindowListOptionIncludingWindow, + [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming)); + if (CGImageGetWidth(windowSnapshot) <= 0) + return; + + scoped_nsobject<NSBitmapImageRep> rep( + [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]); NSData* data = [rep representationUsingType:NSPNGFileType properties:nil]; const unsigned char* buf = static_cast<const unsigned char*>([data bytes]); NSUInteger length = [data length]; - if (buf != NULL && length > 0){ - *width = static_cast<int>([rep pixelsWide]); - *height = static_cast<int>([rep pixelsHigh]); - png_representation->assign(buf, buf + length); - DCHECK(png_representation->size() > 0); - } + if (buf == NULL || length == 0) + return; + + *width = static_cast<int>([rep pixelsWide]); + *height = static_cast<int>([rep pixelsHigh]); + png_representation->assign(buf, buf + length); + DCHECK(png_representation->size() > 0); } void ActivateProcess(pid_t pid) { |