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

Unified Diff: ui/snapshot/snapshot_mac.mm

Issue 11399002: Implemented GetWindowSnapshot on RenderViewImpl (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Resolved dependency issues Created 8 years 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: ui/snapshot/snapshot_mac.mm
diff --git a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm b/ui/snapshot/snapshot_mac.mm
similarity index 62%
rename from chrome/browser/ui/window_snapshot/window_snapshot_mac.mm
rename to ui/snapshot/snapshot_mac.mm
index be3497241ea0983899fa1e6ec7e529a32479e91d..16ac9fc8b5f8cb5b548e0069e1e2b699ab957d44 100644
--- a/chrome/browser/ui/window_snapshot/window_snapshot_mac.mm
+++ b/ui/snapshot/snapshot_mac.mm
@@ -2,45 +2,50 @@
// 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"
+#include "ui/snapshot/snapshot.h"
#import <Cocoa/Cocoa.h>
+#include <iostream>
Ken Russell (switch to Gerrit) 2012/12/12 23:43:14 Unnecessary; please remove.
+
#include "base/logging.h"
#include "base/mac/scoped_cftyperef.h"
#include "base/memory/scoped_nsobject.h"
#include "ui/gfx/rect.h"
-namespace chrome {
-namespace internal {
+namespace ui {
-bool GrabWindowSnapshot(gfx::NativeWindow window,
- std::vector<unsigned char>* png_representation,
- const gfx::Rect& snapshot_bounds) {
+bool GrabViewSnapshot(gfx::NativeView view,
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect& snapshot_bounds) {
+ NSWindow* window = [view window];
NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame]));
- gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame]));
+
+
+ // Get the view bounds relative to the screen
+ NSRect frame = [view convertRect:[view bounds] toView:nil];
+ frame.origin = [window convertBaseToScreen:frame.origin];
+
+ gfx::Rect view_bounds = gfx::Rect(NSRectToCGRect(frame));
// Flip window coordinates based on the primary screen.
- window_bounds.set_y(
- screen_bounds.height() - window_bounds.y() - window_bounds.height());
+ view_bounds.set_y(
+ screen_bounds.height() - view_bounds.y() - view_bounds.height());
// Convert snapshot bounds relative to window into bounds relative to
// screen.
gfx::Rect screen_snapshot_bounds = snapshot_bounds;
- screen_snapshot_bounds.Offset(window_bounds.OffsetFromOrigin());
+ screen_snapshot_bounds.Offset(view_bounds.OffsetFromOrigin());
- DCHECK_LE(screen_snapshot_bounds.right(), window_bounds.right());
- DCHECK_LE(screen_snapshot_bounds.bottom(), window_bounds.bottom());
+ DCHECK_LE(screen_snapshot_bounds.right(), view_bounds.right());
+ DCHECK_LE(screen_snapshot_bounds.bottom(), view_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(
screen_snapshot_bounds.ToCGRect(), kCGWindowListOptionIncludingWindow,
- [[view window] windowNumber], kCGWindowImageBoundsIgnoreFraming));
+ [window windowNumber], kCGWindowImageBoundsIgnoreFraming));
if (CGImageGetWidth(windowSnapshot) <= 0)
return false;
@@ -58,5 +63,13 @@ bool GrabWindowSnapshot(gfx::NativeWindow window,
return true;
}
-} // namespace internal
-} // namespace chrome
+bool GrabWindowSnapshot(gfx::NativeWindow window,
+ std::vector<unsigned char>* png_representation,
+ const gfx::Rect& snapshot_bounds) {
+ // Make sure to grab the "window frame" view so we get current tab +
+ // tabstrip.
+ return GrabViewSnapshot([[window contentView] superview], png_representation,
+ snapshot_bounds);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698