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/test/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
6 | 6 |
7 #include <Carbon/Carbon.h> | 7 #include <Carbon/Carbon.h> |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/message_loop.h" | 12 #include "base/message_loop.h" |
13 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
14 #include "chrome/browser/ui/browser_window.h" | 14 #include "chrome/browser/ui/browser_window.h" |
15 #include "ui/ui_controls/ui_controls.h" | 15 #include "ui/ui_controls/ui_controls.h" |
16 #import "chrome/browser/ui/cocoa/view_id_util.h" | 16 #import "chrome/browser/ui/cocoa/view_id_util.h" |
17 | 17 |
18 namespace ui_test_utils { | 18 namespace ui_test_utils { |
19 | 19 |
20 void SetWindowBounds(gfx::NativeWindow window, const gfx::Rect& bounds) { | |
21 NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect()); | |
22 if ([[NSScreen screens] count] > 0) { | |
23 new_bounds.origin.y = | |
24 [[[NSScreen screens] objectAtIndex:0] frame].size.height - | |
25 new_bounds.origin.y - new_bounds.size.height; | |
26 } | |
27 | |
28 [window setFrame:new_bounds display:NO]; | |
29 } | |
30 | |
31 bool IsViewFocused(const Browser* browser, ViewID vid) { | 20 bool IsViewFocused(const Browser* browser, ViewID vid) { |
32 NSWindow* window = browser->window()->GetNativeWindow(); | 21 NSWindow* window = browser->window()->GetNativeWindow(); |
33 DCHECK(window); | 22 DCHECK(window); |
34 NSView* view = view_id_util::GetView(window, vid); | 23 NSView* view = view_id_util::GetView(window, vid); |
35 if (!view) | 24 if (!view) |
36 return false; | 25 return false; |
37 | 26 |
38 NSResponder* firstResponder = [window firstResponder]; | 27 NSResponder* firstResponder = [window firstResponder]; |
39 if (firstResponder == static_cast<NSResponder*>(view)) | 28 if (firstResponder == static_cast<NSResponder*>(view)) |
40 return true; | 29 return true; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 center = [view convertPoint:center toView:nil]; | 84 center = [view convertPoint:center toView:nil]; |
96 center = [window convertBaseToScreen:center]; | 85 center = [window convertBaseToScreen:center]; |
97 center = NSMakePoint(center.x, [screen frame].size.height - center.y); | 86 center = NSMakePoint(center.x, [screen frame].size.height - center.y); |
98 | 87 |
99 ui_controls::SendMouseMoveNotifyWhenDone( | 88 ui_controls::SendMouseMoveNotifyWhenDone( |
100 center.x, center.y, | 89 center.x, center.y, |
101 base::Bind(&internal::ClickTask, button, state, task)); | 90 base::Bind(&internal::ClickTask, button, state, task)); |
102 } | 91 } |
103 | 92 |
104 } // namespace ui_test_utils | 93 } // namespace ui_test_utils |
OLD | NEW |