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

Side by Side Diff: chrome/browser/automation/automation_provider_gtk.cc

Issue 218017: GTK: First cut at tab dragging automation.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: comments Created 11 years, 2 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 | « no previous file | chrome/browser/automation/ui_controls_linux.cc » ('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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/automation_provider.h" 5 #include "chrome/browser/automation/automation_provider.h"
6 6
7 #include <gtk/gtk.h>
8
7 #include "base/gfx/point.h" 9 #include "base/gfx/point.h"
8 #include "base/gfx/rect.h" 10 #include "base/gfx/rect.h"
11 #include "chrome/browser/automation/ui_controls.h"
9 #include "chrome/browser/gtk/browser_window_gtk.h" 12 #include "chrome/browser/gtk/browser_window_gtk.h"
10 #include "chrome/browser/gtk/view_id_util.h" 13 #include "chrome/browser/gtk/view_id_util.h"
11 #include "chrome/common/gtk_util.h" 14 #include "chrome/common/gtk_util.h"
12 #include "chrome/test/automation/automation_messages.h" 15 #include "chrome/test/automation/automation_messages.h"
13 16
14 void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds, 17 void AutomationProvider::SetWindowBounds(int handle, const gfx::Rect& bounds,
15 bool* success) { 18 bool* success) {
16 *success = false; 19 *success = false;
17 GtkWindow* window = window_tracker_->GetResource(handle); 20 GtkWindow* window = window_tracker_->GetResource(handle);
18 if (window) { 21 if (window) {
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 NOTIMPLEMENTED(); 90 NOTIMPLEMENTED();
88 } 91 }
89 92
90 void AutomationProvider::GetBookmarkBarVisibility(int handle, bool* visible, 93 void AutomationProvider::GetBookmarkBarVisibility(int handle, bool* visible,
91 bool* animating) { 94 bool* animating) {
92 *visible = false; 95 *visible = false;
93 *animating = false; 96 *animating = false;
94 NOTIMPLEMENTED(); 97 NOTIMPLEMENTED();
95 } 98 }
96 99
100 // This task sends a WindowDragResponse message with the appropriate
101 // routing ID to the automation proxy. This is implemented as a task so that
102 // we know that the mouse events (and any tasks that they spawn on the message
103 // loop) have been processed by the time this is sent.
104 class WindowDragResponseTask : public Task {
105 public:
106 WindowDragResponseTask(AutomationProvider* provider,
107 IPC::Message* reply_message)
108 : provider_(provider),
109 reply_message_(reply_message) {
110 DCHECK(reply_message_);
111 DCHECK(provider);
Paweł Hajdan Jr. 2009/09/24 18:04:58 very-small-nit: Please be consistent and check thi
112 }
113
114 virtual ~WindowDragResponseTask() {
115 }
116
117 virtual void Run() {
118 AutomationMsg_WindowDrag::WriteReplyParams(reply_message_, true);
119 provider_->Send(reply_message_);
120 }
121
122 private:
123 AutomationProvider* provider_;
124 IPC::Message* reply_message_;
125
126 DISALLOW_COPY_AND_ASSIGN(WindowDragResponseTask);
127 };
128
129 // A task that just runs a SendMouseEvent and performs another task when done.
130 class MouseEventTask : public Task {
131 public:
132 MouseEventTask(Task* next_task, ui_controls::MouseButtonState state)
133 : next_task_(next_task),
134 state_(state) {}
135
136 virtual ~MouseEventTask() {
137 }
138
139 virtual void Run() {
140 ui_controls::SendMouseEventsNotifyWhenDone(ui_controls::LEFT, state_,
141 next_task_);
142 }
143
144 private:
145 // The task to execute when we are done.
146 Task* next_task_;
147
148 // Mouse press or mouse release.
149 ui_controls::MouseButtonState state_;
150
151 DISALLOW_COPY_AND_ASSIGN(MouseEventTask);
152 };
153
154 // A task that just runs a SendMouseMove and performs another task when done.
155 class MouseMoveTask : public Task {
156 public:
157 MouseMoveTask(Task* next_task, int absolute_x, int absolute_y)
158 : next_task_(next_task),
159 x_(absolute_x),
160 y_(absolute_y) {
161 }
162
163 virtual ~MouseMoveTask() {
164 }
165
166 virtual void Run() {
167 ui_controls::SendMouseMoveNotifyWhenDone(x_, y_, next_task_);
168 }
169
170 private:
171 // The task to execute when we are done.
172 Task* next_task_;
173
174 // Coordinates of the press.
175 int x_;
176 int y_;
177
178 DISALLOW_COPY_AND_ASSIGN(MouseMoveTask);
179 };
180
97 void AutomationProvider::WindowSimulateDrag(int handle, 181 void AutomationProvider::WindowSimulateDrag(int handle,
98 std::vector<gfx::Point> drag_path, 182 std::vector<gfx::Point> drag_path,
99 int flags, 183 int flags,
100 bool press_escape_en_route, 184 bool press_escape_en_route,
101 IPC::Message* reply_message) { 185 IPC::Message* reply_message) {
102 NOTIMPLEMENTED(); 186 // TODO(estade): don't ignore |flags| or |escape_en_route|.
103 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false); 187 gfx::NativeWindow window =
104 Send(reply_message); 188 browser_tracker_->GetResource(handle)->window()->GetNativeHandle();
189 if (window && (drag_path.size() > 1)) {
190 int x, y;
191 gdk_window_get_position(GTK_WIDGET(window)->window, &x, &y);
192
193 // Create a nested stack of tasks to run.
194 Task* next_task = new WindowDragResponseTask(this, reply_message);
195 next_task = new MouseEventTask(next_task, ui_controls::UP);
196 next_task = new MouseEventTask(next_task, ui_controls::UP);
197 for (size_t i = drag_path.size() - 1; i > 0; --i) {
198 // Smooth out the mouse movements by adding intermediate points. This
199 // better simulates a real user drag.
200 int dest_x = drag_path[i].x() + x;
201 int dest_y = drag_path[i].y() + y;
202 int half_step_x = (dest_x + drag_path[i - 1].x() + x) / 2;
203 int half_step_y = (dest_y + drag_path[i - 1].y() + y) / 2;
204
205 next_task = new MouseMoveTask(next_task, dest_x, dest_y);
206 next_task = new MouseMoveTask(next_task, half_step_x, half_step_y);
207 }
208 next_task = new MouseEventTask(next_task, ui_controls::DOWN);
209
210 ui_controls::SendMouseMoveNotifyWhenDone(x + drag_path[0].x(),
211 y + drag_path[0].y(),
212 next_task);
213 } else {
214 AutomationMsg_WindowDrag::WriteReplyParams(reply_message, false);
215 Send(reply_message);
216 }
105 } 217 }
106 218
107 void AutomationProvider::TerminateSession(int handle, bool* success) { 219 void AutomationProvider::TerminateSession(int handle, bool* success) {
108 *success = false; 220 *success = false;
109 NOTIMPLEMENTED(); 221 NOTIMPLEMENTED();
110 } 222 }
111 223
112 void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds, 224 void AutomationProvider::GetWindowBounds(int handle, gfx::Rect* bounds,
113 bool* result) { 225 bool* result) {
114 *result = false; 226 *result = false;
115 NOTIMPLEMENTED(); 227 NOTIMPLEMENTED();
116 } 228 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/automation/ui_controls_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698