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

Side by Side Diff: chrome/browser/ui/window_snapshot/window_snapshot_mac.mm

Issue 6386009: Remove app/win/win_util.h,cc etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Code cleanup Created 9 years, 11 months 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h"
6
7 #import <Cocoa/Cocoa.h>
8
9 #include "base/logging.h"
10 #include "base/mac/scoped_cftyperef.h"
11 #include "base/scoped_nsobject.h"
12
13 namespace browser {
14
15 void GrabWindowSnapshot(gfx::NativeWindow window,
16 std::vector<unsigned char>* png_representation,
17 int* width, int* height) {
18 png_representation->clear();
19 *width = 0;
20 *height = 0;
21
22 // Make sure to grab the "window frame" view so we get current tab +
23 // tabstrip.
24 NSView* view = [[window contentView] superview];
25 base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage(
26 CGRectNull, kCGWindowListOptionIncludingWindow,
27 [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming));
28 if (CGImageGetWidth(windowSnapshot) <= 0)
29 return;
30
31 scoped_nsobject<NSBitmapImageRep> rep(
32 [[NSBitmapImageRep alloc] initWithCGImage:windowSnapshot]);
33 NSData* data = [rep representationUsingType:NSPNGFileType properties:nil];
34 const unsigned char* buf = static_cast<const unsigned char*>([data bytes]);
35 NSUInteger length = [data length];
36 if (buf == NULL || length == 0)
37 return;
38
39 *width = static_cast<int>([rep pixelsWide]);
40 *height = static_cast<int>([rep pixelsHigh]);
41 png_representation->assign(buf, buf + length);
42 DCHECK(png_representation->size() > 0);
43 }
44
45 } // namespace browser
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698