Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / aura / test / event_generator.cc
index dea96a5..8ee8085 100644 (file)
@@ -8,14 +8,19 @@
 #include "base/memory/scoped_ptr.h"
 #include "base/message_loop/message_loop_proxy.h"
 #include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/root_window.h"
+#include "ui/aura/window_event_dispatcher.h"
+#include "ui/aura/window_tree_host.h"
 #include "ui/events/event.h"
+#include "ui/events/event_source.h"
 #include "ui/events/event_utils.h"
+#include "ui/events/test/events_test_utils.h"
 #include "ui/gfx/vector2d_conversions.h"
 
 #if defined(USE_X11)
 #include <X11/Xlib.h>
 #include "ui/base/x/x11_util.h"
+#include "ui/events/event_utils.h"
+#include "ui/events/test/events_test_utils_x11.h"
 #endif
 
 #if defined(OS_WIN)
@@ -36,8 +41,8 @@ class DefaultEventGeneratorDelegate : public EventGeneratorDelegate {
   virtual ~DefaultEventGeneratorDelegate() {}
 
   // EventGeneratorDelegate overrides:
-  virtual RootWindow* GetRootWindowAt(const gfx::Point& point) const OVERRIDE {
-    return root_window_->GetDispatcher();
+  virtual WindowTreeHost* GetHostAt(const gfx::Point& point) const OVERRIDE {
+    return root_window_->GetHost();
   }
 
   virtual client::ScreenPositionClient* GetScreenPositionClient(
@@ -79,7 +84,7 @@ const int kAllButtonMask = ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON;
 
 EventGenerator::EventGenerator(Window* root_window)
     : delegate_(new DefaultEventGeneratorDelegate(root_window)),
-      current_root_window_(delegate_->GetRootWindowAt(current_location_)),
+      current_host_(delegate_->GetHostAt(current_location_)),
       flags_(0),
       grab_(false),
       async_(false) {
@@ -88,7 +93,7 @@ EventGenerator::EventGenerator(Window* root_window)
 EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point)
     : delegate_(new DefaultEventGeneratorDelegate(root_window)),
       current_location_(point),
-      current_root_window_(delegate_->GetRootWindowAt(current_location_)),
+      current_host_(delegate_->GetHostAt(current_location_)),
       flags_(0),
       grab_(false),
       async_(false) {
@@ -97,7 +102,7 @@ EventGenerator::EventGenerator(Window* root_window, const gfx::Point& point)
 EventGenerator::EventGenerator(Window* root_window, Window* window)
     : delegate_(new DefaultEventGeneratorDelegate(root_window)),
       current_location_(CenterOfWindow(window)),
-      current_root_window_(delegate_->GetRootWindowAt(current_location_)),
+      current_host_(delegate_->GetHostAt(current_location_)),
       flags_(0),
       grab_(false),
       async_(false) {
@@ -105,7 +110,7 @@ EventGenerator::EventGenerator(Window* root_window, Window* window)
 
 EventGenerator::EventGenerator(EventGeneratorDelegate* delegate)
     : delegate_(delegate),
-      current_root_window_(delegate_->GetRootWindowAt(current_location_)),
+      current_host_(delegate_->GetHostAt(current_location_)),
       flags_(0),
       grab_(false),
       async_(false) {
@@ -148,20 +153,20 @@ void EventGenerator::ReleaseRightButton() {
 
 void EventGenerator::SendMouseExit() {
   gfx::Point exit_location(current_location_);
-  ConvertPointToTarget(current_root_window_, &exit_location);
+  ConvertPointToTarget(current_host_->window(), &exit_location);
   ui::MouseEvent mouseev(ui::ET_MOUSE_EXITED, exit_location, exit_location,
-                         flags_);
+                         flags_, 0);
   Dispatch(&mouseev);
 }
 
 void EventGenerator::MoveMouseToInHost(const gfx::Point& point_in_host) {
   const ui::EventType event_type = (flags_ & ui::EF_LEFT_MOUSE_BUTTON) ?
       ui::ET_MOUSE_DRAGGED : ui::ET_MOUSE_MOVED;
-  ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_);
+  ui::MouseEvent mouseev(event_type, point_in_host, point_in_host, flags_, 0);
   Dispatch(&mouseev);
 
   current_location_ = point_in_host;
-  current_root_window_->ConvertPointFromHost(&current_location_);
+  current_host_->ConvertPointFromHost(&current_location_);
 }
 
 void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
@@ -176,9 +181,9 @@ void EventGenerator::MoveMouseTo(const gfx::Point& point_in_screen,
     step.Scale(i / count);
     gfx::Point move_point = current_location_ + gfx::ToRoundedVector2d(step);
     if (!grab_)
-      UpdateCurrentRootWindow(move_point);
-    ConvertPointToTarget(current_root_window_, &move_point);
-    ui::MouseEvent mouseev(event_type, move_point, move_point, flags_);
+      UpdateCurrentDispatcher(move_point);
+    ConvertPointToTarget(current_host_->window(), &move_point);
+    ui::MouseEvent mouseev(event_type, move_point, move_point, flags_, 0);
     Dispatch(&mouseev);
   }
   current_location_ = point_in_screen;
@@ -222,7 +227,7 @@ void EventGenerator::MoveTouchId(const gfx::Point& point, int touch_id) {
   Dispatch(&touchev);
 
   if (!grab_)
-    UpdateCurrentRootWindow(point);
+    UpdateCurrentDispatcher(point);
 }
 
 void EventGenerator::ReleaseTouch() {
@@ -245,6 +250,18 @@ void EventGenerator::PressMoveAndReleaseTouchToCenterOf(Window* window) {
   PressMoveAndReleaseTouchTo(CenterOfWindow(window));
 }
 
+void EventGenerator::GestureEdgeSwipe() {
+  ui::GestureEvent gesture(
+      ui::ET_GESTURE_WIN8_EDGE_SWIPE,
+      0,
+      0,
+      0,
+      ui::EventTimeForNow(),
+      ui::GestureEventDetails(ui::ET_GESTURE_WIN8_EDGE_SWIPE, 0, 0),
+      0);
+  Dispatch(&gesture);
+}
+
 void EventGenerator::GestureTapAt(const gfx::Point& location) {
   const int kTouchId = 2;
   ui::TouchEvent press(ui::ET_TOUCH_PRESSED,
@@ -495,6 +512,12 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
   MSG native_event =
       { NULL, (is_press ? key_press : WM_KEYUP), key_code, 0 };
   TestKeyEvent keyev(native_event, flags, key_press == WM_CHAR);
+#elif defined(USE_X11)
+  ui::ScopedXI2Event xevent;
+  xevent.InitKeyEvent(is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED,
+                      key_code,
+                      flags);
+  ui::KeyEvent keyev(xevent, false);
 #else
   ui::EventType type = is_press ? ui::ET_KEY_PRESSED : ui::ET_KEY_RELEASED;
   ui::KeyEvent keyev(type, key_code, flags, false);
@@ -502,8 +525,8 @@ void EventGenerator::DispatchKeyEvent(bool is_press,
   Dispatch(&keyev);
 }
 
-void EventGenerator::UpdateCurrentRootWindow(const gfx::Point& point) {
-  current_root_window_ = delegate_->GetRootWindowAt(point);
+void EventGenerator::UpdateCurrentDispatcher(const gfx::Point& point) {
+  current_host_ = delegate_->GetHostAt(point);
 }
 
 void EventGenerator::PressButton(int flag) {
@@ -511,7 +534,8 @@ void EventGenerator::PressButton(int flag) {
     flags_ |= flag;
     grab_ = flags_ & kAllButtonMask;
     gfx::Point location = GetLocationInCurrentRoot();
-    ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_);
+    ui::MouseEvent mouseev(ui::ET_MOUSE_PRESSED, location, location, flags_,
+                           flag);
     Dispatch(&mouseev);
   }
 }
@@ -520,7 +544,7 @@ void EventGenerator::ReleaseButton(int flag) {
   if (flags_ & flag) {
     gfx::Point location = GetLocationInCurrentRoot();
     ui::MouseEvent mouseev(ui::ET_MOUSE_RELEASED, location,
-                           location, flags_);
+                           location, flags_, flag);
     Dispatch(&mouseev);
     flags_ ^= flag;
   }
@@ -551,7 +575,7 @@ void EventGenerator::ConvertPointToTarget(const aura::Window* target,
 
 gfx::Point EventGenerator::GetLocationInCurrentRoot() const {
   gfx::Point p(current_location_);
-  ConvertPointToTarget(current_root_window_, &p);
+  ConvertPointToTarget(current_host_->window(), &p);
   return p;
 }
 
@@ -585,23 +609,11 @@ void EventGenerator::DoDispatchEvent(ui::Event* event, bool async) {
     }
     pending_events_.push_back(pending_event);
   } else {
-    RootWindowHostDelegate* root_window_host_delegate =
-        current_root_window_->AsRootWindowHostDelegate();
-    if (event->IsKeyEvent()) {
-      root_window_host_delegate->OnHostKeyEvent(
-          static_cast<ui::KeyEvent*>(event));
-    } else if (event->IsMouseEvent()) {
-      root_window_host_delegate->OnHostMouseEvent(
-          static_cast<ui::MouseEvent*>(event));
-    } else if (event->IsTouchEvent()) {
-      root_window_host_delegate->OnHostTouchEvent(
-          static_cast<ui::TouchEvent*>(event));
-    } else if (event->IsScrollEvent()) {
-      root_window_host_delegate->OnHostScrollEvent(
-          static_cast<ui::ScrollEvent*>(event));
-    } else {
-      NOTREACHED() << "Invalid event type";
-    }
+    ui::EventSource* event_source = current_host_->GetEventSource();
+    ui::EventSourceTestApi event_source_test(event_source);
+    ui::EventDispatchDetails details =
+        event_source_test.SendEventToProcessor(event);
+    CHECK(!details.dispatcher_destroyed);
   }
 }