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 "ui/snapshot/snapshot.h" | 5 #include "ui/snapshot/snapshot.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/callback.h" | 9 #include "base/callback.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/mac/scoped_cftyperef.h" | 11 #include "base/mac/scoped_cftyperef.h" |
12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
13 #include "base/task_runner.h" | 13 #include "base/task_runner.h" |
14 #include "ui/gfx/geometry/rect.h" | 14 #include "ui/gfx/geometry/rect.h" |
15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
16 | 16 |
17 namespace ui { | 17 namespace ui { |
18 | 18 |
19 bool GrabViewSnapshot(gfx::NativeView view, | 19 bool GrabViewSnapshot(gfx::NativeView view, |
20 std::vector<unsigned char>* png_representation, | 20 std::vector<unsigned char>* png_representation, |
21 const gfx::Rect& snapshot_bounds) { | 21 const gfx::Rect& snapshot_bounds) { |
22 NSWindow* window = [view window]; | 22 NSWindow* window = [view window]; |
23 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 23 NSScreen* screen = [[NSScreen screens] firstObject]; |
24 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); | 24 gfx::Rect screen_bounds = gfx::Rect(NSRectToCGRect([screen frame])); |
25 | 25 |
26 | 26 |
27 // Get the view bounds relative to the screen | 27 // Get the view bounds relative to the screen |
28 NSRect frame = [view convertRect:[view bounds] toView:nil]; | 28 NSRect frame = [view convertRect:[view bounds] toView:nil]; |
29 frame.origin = [window convertBaseToScreen:frame.origin]; | 29 frame.origin = [window convertBaseToScreen:frame.origin]; |
30 | 30 |
31 gfx::Rect view_bounds = gfx::Rect(NSRectToCGRect(frame)); | 31 gfx::Rect view_bounds = gfx::Rect(NSRectToCGRect(frame)); |
32 | 32 |
33 // Flip window coordinates based on the primary screen. | 33 // Flip window coordinates based on the primary screen. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 void GrabWindowSnapshotAsync( | 95 void GrabWindowSnapshotAsync( |
96 gfx::NativeWindow window, | 96 gfx::NativeWindow window, |
97 const gfx::Rect& source_rect, | 97 const gfx::Rect& source_rect, |
98 scoped_refptr<base::TaskRunner> background_task_runner, | 98 scoped_refptr<base::TaskRunner> background_task_runner, |
99 const GrabWindowSnapshotAsyncPNGCallback& callback) { | 99 const GrabWindowSnapshotAsyncPNGCallback& callback) { |
100 return GrabViewSnapshotAsync([[window contentView] superview], source_rect, | 100 return GrabViewSnapshotAsync([[window contentView] superview], source_rect, |
101 background_task_runner, callback); | 101 background_task_runner, callback); |
102 } | 102 } |
103 | 103 |
104 } // namespace ui | 104 } // namespace ui |
OLD | NEW |