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 | 15 |
16 bool GrabWindowSnapshot(gfx::NativeWindow window, | 16 bool GrabWindowSnapshotImpl(gfx::NativeWindow window, |
17 std::vector<unsigned char>* png_representation, | 17 std::vector<unsigned char>* png_representation, |
18 const gfx::Rect& snapshot_bounds) { | 18 const gfx::Rect& snapshot_bounds) { |
19 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 19 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
20 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); | 20 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); |
21 gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame])); | 21 gfx::Rect window_bounds = gfx::Rect(NSRectToCGRect([window frame])); |
22 | 22 |
23 // Flip window coordinates based on the primary screen. | 23 // Flip window coordinates based on the primary screen. |
24 window_bounds.set_y( | 24 window_bounds.set_y( |
25 screen_bounds.height() - window_bounds.y() - window_bounds.height()); | 25 screen_bounds.height() - window_bounds.y() - window_bounds.height()); |
26 | 26 |
27 // Convert snapshot bounds relative to window into bounds relative to | 27 // Convert snapshot bounds relative to window into bounds relative to |
28 // screen. | 28 // screen. |
(...skipping 23 matching lines...) Expand all Loading... |
52 if (buf == NULL || length == 0) | 52 if (buf == NULL || length == 0) |
53 return false; | 53 return false; |
54 | 54 |
55 png_representation->assign(buf, buf + length); | 55 png_representation->assign(buf, buf + length); |
56 DCHECK(!png_representation->empty()); | 56 DCHECK(!png_representation->empty()); |
57 | 57 |
58 return true; | 58 return true; |
59 } | 59 } |
60 | 60 |
61 } // namespace chrome | 61 } // namespace chrome |
OLD | NEW |