OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/automation/testing_automation_provider.h" | 5 #include "chrome/browser/automation/testing_automation_provider.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "ui/base/l10n/l10n_util.h" | 9 #include "ui/base/l10n/l10n_util.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 #include "base/sys_string_conversions.h" | 11 #include "base/sys_string_conversions.h" |
12 #include "chrome/browser/automation/automation_browser_tracker.h" | 12 #include "chrome/browser/automation/automation_browser_tracker.h" |
13 #include "chrome/browser/automation/automation_window_tracker.h" | 13 #include "chrome/browser/automation/automation_window_tracker.h" |
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 14 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
15 #include "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" | 15 #include "chrome/browser/ui/cocoa/tabs/tab_window_controller.h" |
16 #include "chrome/browser/ui/view_ids.h" | 16 #include "chrome/browser/ui/view_ids.h" |
17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
18 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
19 | 19 |
20 void TestingAutomationProvider::ActivateWindow(int handle) { | |
21 NOTIMPLEMENTED(); | |
22 } | |
23 | |
24 void TestingAutomationProvider::IsWindowMaximized(int handle, | |
25 bool* is_maximized, | |
26 bool* success) { | |
27 *success = false; | |
28 NSWindow* window = window_tracker_->GetResource(handle); | |
29 if (!window) | |
30 return; | |
31 *is_maximized = [window isZoomed]; | |
32 *success = true; | |
33 } | |
34 | |
35 void TestingAutomationProvider::TerminateSession(int handle, bool* success) { | 20 void TestingAutomationProvider::TerminateSession(int handle, bool* success) { |
36 *success = false; | 21 *success = false; |
37 NOTIMPLEMENTED(); | 22 NOTIMPLEMENTED(); |
38 } | 23 } |
39 | 24 |
40 void TestingAutomationProvider::WindowGetViewBounds(int handle, | 25 void TestingAutomationProvider::WindowGetViewBounds(int handle, |
41 int view_id, | 26 int view_id, |
42 bool screen_coordinates, | 27 bool screen_coordinates, |
43 bool* success, | 28 bool* success, |
44 gfx::Rect* bounds) { | 29 gfx::Rect* bounds) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
76 [[[NSScreen screens] objectAtIndex:0] frame].size.height; | 61 [[[NSScreen screens] objectAtIndex:0] frame].size.height; |
77 } else { | 62 } else { |
78 coord_sys_height = [window frame].size.height; | 63 coord_sys_height = [window frame].size.height; |
79 } | 64 } |
80 // Flip coordinate system. | 65 // Flip coordinate system. |
81 rect.origin.y = coord_sys_height - rect.origin.y; | 66 rect.origin.y = coord_sys_height - rect.origin.y; |
82 *bounds = gfx::Rect(NSRectToCGRect(rect)); | 67 *bounds = gfx::Rect(NSRectToCGRect(rect)); |
83 *success = true; | 68 *success = true; |
84 } | 69 } |
85 | 70 |
86 void TestingAutomationProvider::GetWindowBounds(int handle, | |
87 gfx::Rect* bounds, | |
88 bool* success) { | |
89 *success = false; | |
90 NSWindow* window = window_tracker_->GetResource(handle); | |
91 if (window) { | |
92 // Move rect to reflect flipped coordinate system. | |
93 if ([[NSScreen screens] count] > 0) { | |
94 NSRect rect = [window frame]; | |
95 rect.origin.y = | |
96 [[[NSScreen screens] objectAtIndex:0] frame].size.height - | |
97 rect.origin.y - rect.size.height; | |
98 *bounds = gfx::Rect(NSRectToCGRect(rect)); | |
99 *success = true; | |
100 } | |
101 } | |
102 } | |
103 | |
104 void TestingAutomationProvider::SetWindowBounds(int handle, | 71 void TestingAutomationProvider::SetWindowBounds(int handle, |
105 const gfx::Rect& bounds, | 72 const gfx::Rect& bounds, |
106 bool* success) { | 73 bool* success) { |
107 *success = false; | 74 *success = false; |
108 NSWindow* window = window_tracker_->GetResource(handle); | 75 NSWindow* window = window_tracker_->GetResource(handle); |
109 if (window) { | 76 if (window) { |
110 NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect()); | 77 NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect()); |
111 | 78 |
112 if ([[NSScreen screens] count] > 0) { | 79 if ([[NSScreen screens] count] > 0) { |
113 new_bounds.origin.y = | 80 new_bounds.origin.y = |
114 [[[NSScreen screens] objectAtIndex:0] frame].size.height - | 81 [[[NSScreen screens] objectAtIndex:0] frame].size.height - |
115 new_bounds.origin.y - new_bounds.size.height; | 82 new_bounds.origin.y - new_bounds.size.height; |
116 } | 83 } |
117 | 84 |
118 [window setFrame:new_bounds display:NO]; | 85 [window setFrame:new_bounds display:NO]; |
119 *success = true; | 86 *success = true; |
120 } | 87 } |
121 } | 88 } |
122 | |
123 void TestingAutomationProvider::SetWindowVisible(int handle, | |
124 bool visible, | |
125 bool* result) { | |
126 *result = false; | |
127 NSWindow* window = window_tracker_->GetResource(handle); | |
128 if (window) { | |
129 if (visible) { | |
130 [window orderFront:nil]; | |
131 } else { | |
132 [window orderOut:nil]; | |
133 } | |
134 *result = true; | |
135 } | |
136 } | |
137 | |
138 void TestingAutomationProvider::GetWindowTitle(int handle, string16* text) { | |
139 gfx::NativeWindow window = window_tracker_->GetResource(handle); | |
140 NSString* title = nil; | |
141 if ([[window delegate] isKindOfClass:[TabWindowController class]]) { | |
142 TabWindowController* delegate = | |
143 reinterpret_cast<TabWindowController*>([window delegate]); | |
144 title = [delegate activeTabTitle]; | |
145 } else { | |
146 title = [window title]; | |
147 } | |
148 // If we don't yet have a title, use "Untitled". | |
149 if (![title length]) { | |
150 text->assign(l10n_util::GetStringUTF16( | |
151 IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED)); | |
152 return; | |
153 } | |
154 | |
155 text->assign(base::SysNSStringToUTF16(title)); | |
156 } | |
OLD | NEW |