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

Unified Diff: chrome/browser/automation/ui_controls_linux.cc

Issue 174201: More interactive test porting for Linux. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: fixes Created 11 years, 4 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/automation/ui_controls_linux.cc
===================================================================
--- chrome/browser/automation/ui_controls_linux.cc (revision 23880)
+++ chrome/browser/automation/ui_controls_linux.cc (working copy)
@@ -7,8 +7,10 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
+#include "base/gfx/rect.h"
#include "base/logging.h"
#include "base/message_loop.h"
+#include "chrome/common/gtk_util.h"
#include "chrome/test/automation/automation_constants.h"
namespace {
@@ -46,6 +48,24 @@
GdkEventType type_;
};
+class ClickTask : public Task {
+ public:
+ ClickTask(ui_controls::MouseButton button, int state, Task* followup)
+ : button_(button), state_(state), followup_(followup) {
+ }
+
+ virtual ~ClickTask() {}
+
+ virtual void Run() {
+ ui_controls::SendMouseEventsNotifyWhenDone(button_, state_, followup_);
+ }
+
+ private:
+ ui_controls::MouseButton button_;
+ int state_;
+ Task* followup_;
+};
+
} // namespace
namespace ui_controls {
@@ -109,20 +129,21 @@
return rv;
}
-bool SendMouseClick(const gfx::Point& point, MouseButton type) {
+bool SendMouseEvents(MouseButton type, int state) {
GdkEvent* event = gdk_event_new(GDK_BUTTON_PRESS);
- event->button.window = gdk_window_at_pointer(NULL, NULL);
- g_object_ref(event->button.window);
event->button.send_event = false;
event->button.time = EventTimeNow();
- event->motion.x_root = point.x();
- event->motion.y_root = point.x();
+ gint x, y;
+ event->button.window = gdk_window_at_pointer(&x, &y);
+ g_object_ref(event->button.window);
+ event->motion.x = x;
+ event->motion.y = y;
gint origin_x, origin_y;
gdk_window_get_origin(event->button.window, &origin_x, &origin_y);
- event->button.x = point.x() - origin_x;
- event->button.y = point.y() - origin_y;
+ event->button.x_root = x + origin_x;
+ event->button.y_root = y + origin_y;
event->button.axes = NULL;
// TODO(estade): as above, we may want to pack this with the actual state.
@@ -131,13 +152,15 @@
event->button.device = gdk_device_get_core_pointer();
event->button.type = GDK_BUTTON_PRESS;
- gdk_event_put(event);
+ if (state & DOWN)
+ gdk_event_put(event);
// Also send a release event.
GdkEvent* release_event = gdk_event_copy(event);
release_event->button.type = GDK_BUTTON_RELEASE;
release_event->button.time++;
- gdk_event_put(release_event);
+ if (state & UP)
+ gdk_event_put(release_event);
gdk_event_free(event);
gdk_event_free(release_event);
@@ -145,12 +168,24 @@
return false;
}
-// TODO(estade): need to figure out a better type for this than View.
-void MoveMouseToCenterAndPress(views::View* view,
+bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task) {
+ bool rv = SendMouseEvents(type, state);
+ MessageLoop::current()->PostTask(FROM_HERE, task);
+ return rv;
+}
+
+bool SendMouseClick(MouseButton type) {
+ return SendMouseEvents(type, UP | DOWN);
+}
+
+void MoveMouseToCenterAndPress(GtkWidget* widget,
MouseButton button,
int state,
Task* task) {
- NOTIMPLEMENTED();
+ gfx::Rect bounds = gtk_util::GetWidgetScreenBounds(widget);
+ SendMouseMoveNotifyWhenDone(bounds.x() + bounds.width() / 2,
+ bounds.y() + bounds.height() / 2,
+ new ClickTask(button, state, task));
}
} // namespace ui_controls

Powered by Google App Engine
This is Rietveld 408576698