| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" | 5 #include "chrome/browser/ui/window_snapshot/window_snapshot.h" |
| 6 | 6 |
| 7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/scoped_cftyperef.h" | 10 #include "base/mac/scoped_cftyperef.h" |
| 11 #include "base/memory/scoped_nsobject.h" | 11 #include "base/memory/scoped_nsobject.h" |
| 12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
| 13 | 13 |
| 14 namespace chrome { | 14 namespace chrome { |
| 15 namespace internal { | 15 namespace internal { |
| 16 | 16 |
| 17 bool GrabWindowSnapshot(gfx::NativeWindow window, | 17 bool GrabWindowSnapshot(gfx::NativeWindow window, |
| 18 std::vector<unsigned char>* png_representation, | 18 std::vector<unsigned char>* png_representation, |
| 19 const gfx::Rect& snapshot_bounds) { | 19 const gfx::Rect& snapshot_bounds) { |
| 20 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 20 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 21 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); | 21 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); |
| 22 gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame])); | 22 gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame])); |
| 23 | 23 |
| 24 // Flip window coordinates based on the primary screen. | 24 // Flip window coordinates based on the primary screen. |
| 25 window_bounds.set_y( | 25 window_bounds.set_y( |
| 26 screen_bounds.height() - window_bounds.y() - window_bounds.height()); | 26 screen_bounds.height() - window_bounds.y() - window_bounds.height()); |
| 27 | 27 |
| 28 // Convert snapshot bounds relative to window into bounds relative to | 28 // Convert snapshot bounds relative to window into bounds relative to |
| 29 // screen. | 29 // screen. |
| 30 gfx::Rect screen_snapshot_bounds = gfx::Rect( | 30 gfx::Rect screen_snapshot_bounds = snapshot_bounds; |
| 31 window_bounds.origin().Add(snapshot_bounds.origin()), | 31 screen_snapshot_bounds.Offset(window_bounds.OffsetFromOrigin()); |
| 32 snapshot_bounds.size()); | |
| 33 | 32 |
| 34 DCHECK_LE(screen_snapshot_bounds.right(), window_bounds.right()); | 33 DCHECK_LE(screen_snapshot_bounds.right(), window_bounds.right()); |
| 35 DCHECK_LE(screen_snapshot_bounds.bottom(), window_bounds.bottom()); | 34 DCHECK_LE(screen_snapshot_bounds.bottom(), window_bounds.bottom()); |
| 36 | 35 |
| 37 png_representation->clear(); | 36 png_representation->clear(); |
| 38 | 37 |
| 39 // Make sure to grab the "window frame" view so we get current tab + | 38 // Make sure to grab the "window frame" view so we get current tab + |
| 40 // tabstrip. | 39 // tabstrip. |
| 41 NSView* view = [[window contentView] superview]; | 40 NSView* view = [[window contentView] superview]; |
| 42 base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( | 41 base::mac::ScopedCFTypeRef<CGImageRef> windowSnapshot(CGWindowListCreateImage( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 54 return false; | 53 return false; |
| 55 | 54 |
| 56 png_representation->assign(buf, buf + length); | 55 png_representation->assign(buf, buf + length); |
| 57 DCHECK(!png_representation->empty()); | 56 DCHECK(!png_representation->empty()); |
| 58 | 57 |
| 59 return true; | 58 return true; |
| 60 } | 59 } |
| 61 | 60 |
| 62 } // namespace internal | 61 } // namespace internal |
| 63 } // namespace chrome | 62 } // namespace chrome |
| OLD | NEW |