Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(302)

Side by Side Diff: chrome/test/base/ui_test_utils_gtk.cc

Issue 9390038: Move automation/ui_controls to ui/ui_controls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: win_aura fix, sync Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/ui_test_utils_aura.cc ('k') | chrome/test/base/ui_test_utils_mac.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/bind.h"
9 #include "base/logging.h" 10 #include "base/logging.h"
10 #include "base/message_loop.h" 11 #include "base/message_loop.h"
11 #include "chrome/browser/automation/ui_controls.h"
12 #include "chrome/browser/ui/browser.h" 12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h" 13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/gtk/view_id_util.h" 14 #include "chrome/browser/ui/gtk/view_id_util.h"
15 #include "ui/base/gtk/gtk_screen_util.h"
16 #include "ui/ui_controls/ui_controls.h"
17
15 #if defined(TOOLKIT_VIEWS) 18 #if defined(TOOLKIT_VIEWS)
16 #include "chrome/browser/ui/views/frame/browser_view.h" 19 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "ui/views/focus/focus_manager.h" 20 #include "ui/views/focus/focus_manager.h"
18 #endif 21 #endif
19 22
20 namespace ui_test_utils { 23 namespace ui_test_utils {
21 24
22 #if !defined(TOOLKIT_VIEWS) 25 #if !defined(TOOLKIT_VIEWS)
23 namespace { 26 namespace {
24
25 // Check if the focused widget for |root| is |target| or a child of |target|. 27 // Check if the focused widget for |root| is |target| or a child of |target|.
26 static bool IsWidgetInFocusChain(GtkWidget* root, GtkWidget* target) { 28 static bool IsWidgetInFocusChain(GtkWidget* root, GtkWidget* target) {
27 GtkWidget* iter = root; 29 GtkWidget* iter = root;
28 30
29 while (iter) { 31 while (iter) {
30 if (iter == target) 32 if (iter == target)
31 return true; 33 return true;
32 34
33 if (!GTK_IS_CONTAINER(iter)) 35 if (!GTK_IS_CONTAINER(iter))
34 return false; 36 return false;
35 37
36 iter = GTK_CONTAINER(iter)->focus_child; 38 iter = GTK_CONTAINER(iter)->focus_child;
37 } 39 }
38 40
39 return false; 41 return false;
40 } 42 }
41
42 } // namespace 43 } // namespace
43 #endif 44 #endif
44 45
45 bool IsViewFocused(const Browser* browser, ViewID vid) { 46 bool IsViewFocused(const Browser* browser, ViewID vid) {
46 BrowserWindow* browser_window = browser->window(); 47 BrowserWindow* browser_window = browser->window();
47 DCHECK(browser_window); 48 DCHECK(browser_window);
48 #if defined(TOOLKIT_VIEWS) 49 #if defined(TOOLKIT_VIEWS)
49 gfx::NativeWindow window = browser_window->GetNativeHandle(); 50 gfx::NativeWindow window = browser_window->GetNativeHandle();
50 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window); 51 const views::Widget* widget = views::Widget::GetWidgetForNativeWindow(window);
51 DCHECK(widget); 52 DCHECK(widget);
(...skipping 16 matching lines...) Expand all
68 #if defined(TOOLKIT_VIEWS) 69 #if defined(TOOLKIT_VIEWS)
69 views::View* view = 70 views::View* view =
70 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid); 71 reinterpret_cast<BrowserView*>(browser_window)->GetViewByID(vid);
71 #else 72 #else
72 gfx::NativeWindow window = browser_window->GetNativeHandle(); 73 gfx::NativeWindow window = browser_window->GetNativeHandle();
73 DCHECK(window); 74 DCHECK(window);
74 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid); 75 GtkWidget* view = ViewIDUtil::GetWidget(GTK_WIDGET(window), vid);
75 #endif 76 #endif
76 77
77 DCHECK(view); 78 DCHECK(view);
78 ui_controls::MoveMouseToCenterAndPress( 79 MoveMouseToCenterAndPress(
79 view, 80 view,
80 ui_controls::LEFT, 81 ui_controls::LEFT,
81 ui_controls::DOWN | ui_controls::UP, 82 ui_controls::DOWN | ui_controls::UP,
82 MessageLoop::QuitClosure()); 83 MessageLoop::QuitClosure());
83 RunMessageLoop(); 84 RunMessageLoop();
84 } 85 }
85 86
86 void HideNativeWindow(gfx::NativeWindow window) { 87 void HideNativeWindow(gfx::NativeWindow window) {
87 gtk_widget_hide(GTK_WIDGET(window)); 88 gtk_widget_hide(GTK_WIDGET(window));
88 } 89 }
89 90
90 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) { 91 bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
91 if (!gtk_window_has_toplevel_focus(GTK_WINDOW(window))) 92 if (!gtk_window_has_toplevel_focus(GTK_WINDOW(window)))
92 gtk_window_present(GTK_WINDOW(window)); 93 gtk_window_present(GTK_WINDOW(window));
93 return true; 94 return true;
94 } 95 }
95 96
97 #if defined(TOOLKIT_VIEWS)
98
99 void OnConfigure(GtkWidget* gtk_widget, GdkEvent* event, gpointer data) {
100 views::Widget* widget = static_cast<views::Widget*>(data);
101 gfx::Rect actual = widget->GetWindowScreenBounds();
102 gfx::Rect desired = widget->GetRootView()->bounds();
103 if (actual.size() == desired.size())
104 MessageLoop::current()->Quit();
105 }
106
107 void SynchronizeWidgetSize(views::Widget* widget) {
108 // If the actual window size and desired window size
109 // are different, wait until the window is resized
110 // to desired size.
111 gfx::Rect actual = widget->GetWindowScreenBounds();
112 gfx::Rect desired = widget->GetRootView()->bounds();
113 if (actual.size() != desired.size()) {
114 // Listen to configure-event that is emitted when an window gets
115 // resized.
116 GtkWidget* gtk_widget = widget->GetNativeView();
117 g_signal_connect(gtk_widget, "configure-event",
118 G_CALLBACK(&OnConfigure), widget);
119 MessageLoop::current()->Run();
120 }
121 }
122
123 void MoveMouseToCenterAndPress(views::View* view,
124 ui_controls::MouseButton button,
125 int state,
126 const base::Closure& task) {
127 // X is asynchronous and we need to wait until the window gets
128 // resized to desired size.
129 SynchronizeWidgetSize(view->GetWidget());
130
131 gfx::Point view_center(view->width() / 2, view->height() / 2);
132 views::View::ConvertPointToScreen(view, &view_center);
133 ui_controls::SendMouseMoveNotifyWhenDone(
134 view_center.x(), view_center.y(),
135 base::Bind(&internal::ClickTask, button, state, task));
136 }
137
138 #else // !defined(TOOLKIT_VIEWS)
139
140 void MoveMouseToCenterAndPress(GtkWidget* widget,
141 ui_controls::MouseButton button,
142 int state,
143 const base::Closure& task) {
144 gfx::Rect bounds = ui::GetWidgetScreenBounds(widget);
145 ui_controls::SendMouseMoveNotifyWhenDone(
146 bounds.x() + bounds.width() / 2,
147 bounds.y() + bounds.height() / 2,
148 base::Bind(&internal::ClickTask, button, state, task));
149 }
150
151 #endif // defined(TOOLKIT_VIEWS
152
96 } // namespace ui_test_utils 153 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils_aura.cc ('k') | chrome/test/base/ui_test_utils_mac.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698