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