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
3 // found in the LICENSE file.
5 #include "chrome/browser/automation/testing_automation_provider.h"
7 #import <Cocoa/Cocoa.h>
9 #include "ui/base/l10n/l10n_util.h"
10 #include "base/logging.h"
11 #include "base/strings/sys_string_conversions.h"
12 #include "chrome/browser/automation/automation_browser_tracker.h"
13 #include "chrome/browser/automation/automation_window_tracker.h"
14 #import "chrome/browser/ui/cocoa/browser_window_controller.h"
15 #include "chrome/browser/ui/cocoa/tabs/tab_window_controller.h"
16 #include "chrome/browser/ui/view_ids.h"
17 #include "grit/generated_resources.h"
18 #include "ui/base/l10n/l10n_util_mac.h"
20 void TestingAutomationProvider::TerminateSession(int handle, bool* success) {
25 void TestingAutomationProvider::WindowGetViewBounds(int handle,
27 bool screen_coordinates,
32 // At the moment we hard code the view ID used by WebDriver and do
33 // not support arbitrary view IDs. suzhe is working on general view
34 // ID support for the Mac.
35 if (view_id != VIEW_ID_TAB_CONTAINER) {
40 NSWindow* window = window_tracker_->GetResource(handle);
44 BrowserWindowController* controller = [window windowController];
45 DCHECK([controller isKindOfClass:[BrowserWindowController class]]);
46 if (![controller isKindOfClass:[BrowserWindowController class]])
49 [[[controller tabStripController] activeTabContentsController] view];
53 NSRect rect = [tab convertRect:[tab bounds] toView:nil];
54 // The origin of the bounding box should be the top left of the tab contents,
55 // not bottom left, to match other platforms.
56 rect.origin.y += rect.size.height;
57 CGFloat coord_sys_height;
58 if (screen_coordinates && [[NSScreen screens] count] > 0) {
59 rect.origin = [window convertBaseToScreen:rect.origin];
61 [[[NSScreen screens] objectAtIndex:0] frame].size.height;
63 coord_sys_height = [window frame].size.height;
65 // Flip coordinate system.
66 rect.origin.y = coord_sys_height - rect.origin.y;
67 *bounds = gfx::Rect(NSRectToCGRect(rect));
71 void TestingAutomationProvider::SetWindowBounds(int handle,
72 const gfx::Rect& bounds,
75 NSWindow* window = window_tracker_->GetResource(handle);
77 NSRect new_bounds = NSRectFromCGRect(bounds.ToCGRect());
79 if ([[NSScreen screens] count] > 0) {
81 [[[NSScreen screens] objectAtIndex:0] frame].size.height -
82 new_bounds.origin.y - new_bounds.size.height;
85 [window setFrame:new_bounds display:NO];