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

Unified 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: Merge with NSApp changes in r73581 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 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
new file mode 100755
index 0000000000000000000000000000000000000000..deb72202698d4e841892b01e5f411a7c29c456e7
--- /dev/null
+++ b/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm
@@ -0,0 +1,44 @@
+// Copyright (c) 2011 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.
+
+#include "chrome/browser/ui/window_snapshot/window_snapshot.h"
+
+#import <Cocoa/Cocoa.h>
+
+#include "base/logging.h"
+#include "base/mac/scoped_cftyperef.h"
+#include "base/scoped_nsobject.h"
+#include "gfx/rect.h"
+
+namespace browser {
+
+gfx::Rect GrabWindowSnapshot(gfx::NativeWindow window,
+ std::vector<unsigned char>* png_representation) {
+ 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,
+ [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming));
+ if (CGImageGetWidth(windowSnapshot) <= 0)
+ return gfx::Rect();
+
+ 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)
+ return gfx::Rect();
+
+ png_representation->assign(buf, buf + length);
+ DCHECK(png_representation->size() > 0);
+
+ return gfx::Rect(static_cast<int>([rep pixelsWide]),
+ static_cast<int>([rep pixelsHigh]));
+}
+
+} // namespace browser
« no previous file with comments | « chrome/browser/ui/window_snapshot/window_snapshot.h ('k') | chrome/browser/ui/window_snapshot/window_snapshot_mac_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698