diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 15:55:52 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-27 15:55:52 +0000 |
commit | 8b386cede11a8a5c907b5a75271c7edee12f1774 (patch) | |
tree | c89a26a9b685d15af0250e2baf8b463a3d70352a /base/mac_util.mm | |
parent | b3f97bc7bb26c47a37a2403f0edf9dc51443359c (diff) | |
download | chromium_src-8b386cede11a8a5c907b5a75271c7edee12f1774.zip chromium_src-8b386cede11a8a5c907b5a75271c7edee12f1774.tar.gz chromium_src-8b386cede11a8a5c907b5a75271c7edee12f1774.tar.bz2 |
Add GrabWindowSnapshot method to mac_util class, and a unit test.
BUG= none
TEST= none
Review URL: http://codereview.chromium.org/333018
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30199 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/mac_util.mm')
-rw-r--r-- | base/mac_util.mm | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/base/mac_util.mm b/base/mac_util.mm index 772fe16b..3ffab82 100644 --- a/base/mac_util.mm +++ b/base/mac_util.mm @@ -1,4 +1,4 @@ -// Copyright (c) 2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2008-2009 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -161,4 +161,21 @@ void ReleaseFullScreen() { SetSystemUIMode(kUIModeNormal, 0); } +void GrabWindowSnapshot(NSWindow* window, + std::vector<unsigned char>* png_representation) { + // 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]; + 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){ + png_representation->assign(buf, buf + length); + DCHECK(png_representation->size() > 0); + } +} + } // namespace mac_util |