Home | History | Annotate | Download | only in automation
      1 // Copyright (c) 2010 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.
      4 
      5 #ifndef CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
      6 #define CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
      7 #pragma once
      8 
      9 #include "build/build_config.h"
     10 
     11 #if defined(OS_WIN)
     12 #include <wtypes.h>
     13 #endif
     14 
     15 #include "ui/base/keycodes/keyboard_codes.h"
     16 #include "ui/gfx/native_widget_types.h"
     17 #include "ui/gfx/point.h"
     18 
     19 #if defined(TOOLKIT_VIEWS)
     20 namespace views {
     21 class View;
     22 }
     23 #endif
     24 
     25 class Task;
     26 
     27 namespace ui_controls {
     28 
     29 // Many of the functions in this class include a variant that takes a Task.
     30 // The version that takes a Task waits until the generated event is processed.
     31 // Once the generated event is processed the Task is Run (and deleted). Note
     32 // that this is a somewhat fragile process in that any event of the correct
     33 // type (key down, mouse click, etc.) will trigger the Task to be run. Hence
     34 // a usage such as
     35 //
     36 //   SendKeyPress(...);
     37 //   SendKeyPressNotifyWhenDone(..., task);
     38 //
     39 // might trigger |task| early.
     40 //
     41 // Note: Windows does not currently do anything with the |window| argument for
     42 // these functions, so passing NULL is ok.
     43 
     44 // Send a key press with/without modifier keys.
     45 //
     46 // If you're writing a test chances are you want the variant in ui_test_utils.
     47 // See it for details.
     48 bool SendKeyPress(gfx::NativeWindow window,
     49                   ui::KeyboardCode key,
     50                   bool control,
     51                   bool shift,
     52                   bool alt,
     53                   bool command);
     54 bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window,
     55                                 ui::KeyboardCode key,
     56                                 bool control,
     57                                 bool shift,
     58                                 bool alt,
     59                                 bool command,
     60                                 Task* task);
     61 
     62 // Simulate a mouse move. (x,y) are absolute screen coordinates.
     63 bool SendMouseMove(long x, long y);
     64 bool SendMouseMoveNotifyWhenDone(long x, long y, Task* task);
     65 
     66 enum MouseButton {
     67   LEFT = 0,
     68   MIDDLE,
     69   RIGHT,
     70 };
     71 
     72 // Used to indicate the state of the button when generating events.
     73 enum MouseButtonState {
     74   UP = 1,
     75   DOWN = 2
     76 };
     77 
     78 // Sends a mouse down and/or up message. The click will be sent to wherever
     79 // the cursor currently is, so be sure to move the cursor before calling this
     80 // (and be sure the cursor has arrived!).
     81 bool SendMouseEvents(MouseButton type, int state);
     82 bool SendMouseEventsNotifyWhenDone(MouseButton type, int state, Task* task);
     83 // Same as SendMouseEvents with UP | DOWN.
     84 bool SendMouseClick(MouseButton type);
     85 
     86 // A combination of SendMouseMove to the middle of the view followed by
     87 // SendMouseEvents.
     88 void MoveMouseToCenterAndPress(
     89 #if defined(TOOLKIT_VIEWS)
     90     views::View* view,
     91 #elif defined(TOOLKIT_GTK)
     92     GtkWidget* widget,
     93 #elif defined(OS_MACOSX)
     94     NSView* view,
     95 #endif
     96     MouseButton button,
     97     int state,
     98     Task* task);
     99 
    100 }  // ui_controls
    101 
    102 #endif  // CHROME_BROWSER_AUTOMATION_UI_CONTROLS_H_
    103