Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 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 UI_UI_CONTROLS_UI_CONTROLS_H_ | 5 #ifndef UI_UI_CONTROLS_UI_CONTROLS_H_ |
| 6 #define UI_UI_CONTROLS_UI_CONTROLS_H_ | 6 #define UI_UI_CONTROLS_UI_CONTROLS_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 11 #include <wtypes.h> | 11 #include <wtypes.h> |
| 12 #endif | 12 #endif |
| 13 | 13 |
| 14 #include "base/callback_forward.h" | 14 #include "base/callback_forward.h" |
| 15 #include "ui/base/keycodes/keyboard_codes.h" | 15 #include "ui/base/keycodes/keyboard_codes.h" |
| 16 #include "ui/base/ui_export.h" | |
| 16 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 17 #include "ui/base/ui_export.h" | 18 #include "ui/ui_controls/ui_controls_type_delegate.h" |
| 18 | 19 |
| 19 namespace ui_controls { | 20 namespace ui_controls { |
| 20 | 21 |
| 21 // 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. |
| 22 // 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 |
| 23 // 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 |
| 24 // 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 |
| 25 // 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 |
| 26 // run. Hence a usage such as | 27 // run. Hence a usage such as |
| 27 // | 28 // |
| 28 // SendKeyPress(...); | 29 // SendKeyPress(...); |
| 29 // SendKeyPressNotifyWhenDone(..., task); | 30 // SendKeyPressNotifyWhenDone(..., task); |
| 30 // | 31 // |
| 31 // might trigger |task| early. | 32 // might trigger |task| early. |
| 32 // | 33 // |
| 33 // 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 |
| 34 // these functions, so passing NULL is ok. | 35 // these functions, so passing NULL is ok. |
| 35 | 36 |
| 36 // Send a key press with/without modifier keys. | 37 // Send a key press with/without modifier keys. |
| 37 // | 38 // |
| 38 // 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. |
| 39 // See it for details. | 40 // See it for details. |
| 41 | |
| 42 enum MouseButton { | |
| 43 LEFT = 0, | |
| 44 MIDDLE, | |
| 45 RIGHT, | |
| 46 }; | |
| 47 | |
| 48 // Used to indicate the state of the button when generating events. | |
| 49 enum MouseButtonState { | |
| 50 UP = 1, | |
| 51 DOWN = 2 | |
| 52 }; | |
| 53 | |
| 54 | |
| 55 | |
|
oshima
2012/11/15 23:37:41
remove extra (2) new lines
scottmg
2012/11/16 17:58:54
Done.
| |
| 56 // TRANSITION CODE: These global methods all forward to the native | |
| 57 // implementation and are deprecated in favor of retrieving in the correct one | |
| 58 // according to UIControlsType. http://crbug.com/128578 | |
| 40 UI_EXPORT bool SendKeyPress(gfx::NativeWindow window, | 59 UI_EXPORT bool SendKeyPress(gfx::NativeWindow window, |
| 41 ui::KeyboardCode key, | 60 ui::KeyboardCode key, |
| 42 bool control, | 61 bool control, |
| 43 bool shift, | 62 bool shift, |
| 44 bool alt, | 63 bool alt, |
| 45 bool command); | 64 bool command); |
| 46 UI_EXPORT bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | 65 UI_EXPORT bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, |
| 47 ui::KeyboardCode key, | 66 ui::KeyboardCode key, |
| 48 bool control, | 67 bool control, |
| 49 bool shift, | 68 bool shift, |
| 50 bool alt, | 69 bool alt, |
| 51 bool command, | 70 bool command, |
| 52 const base::Closure& task); | 71 const base::Closure& task); |
| 53 | 72 |
| 54 // Simulate a mouse move. (x,y) are absolute screen coordinates. | 73 // Simulate a mouse move. (x,y) are absolute screen coordinates. |
| 55 UI_EXPORT bool SendMouseMove(long x, long y); | 74 UI_EXPORT bool SendMouseMove(long x, long y); |
| 56 UI_EXPORT bool SendMouseMoveNotifyWhenDone(long x, | 75 UI_EXPORT bool SendMouseMoveNotifyWhenDone(long x, |
| 57 long y, | 76 long y, |
| 58 const base::Closure& task); | 77 const base::Closure& task); |
| 59 | |
| 60 enum MouseButton { | |
| 61 LEFT = 0, | |
| 62 MIDDLE, | |
| 63 RIGHT, | |
| 64 }; | |
| 65 | |
| 66 // Used to indicate the state of the button when generating events. | |
| 67 enum MouseButtonState { | |
| 68 UP = 1, | |
| 69 DOWN = 2 | |
| 70 }; | |
| 71 | |
| 72 // Sends a mouse down and/or up message. The click will be sent to wherever | |
| 73 // the cursor currently is, so be sure to move the cursor before calling this | |
| 74 // (and be sure the cursor has arrived!). | |
| 75 UI_EXPORT bool SendMouseEvents(MouseButton type, int state); | 78 UI_EXPORT bool SendMouseEvents(MouseButton type, int state); |
| 76 UI_EXPORT bool SendMouseEventsNotifyWhenDone( | 79 UI_EXPORT bool SendMouseEventsNotifyWhenDone( |
| 77 MouseButton type, int state, | 80 MouseButton type, int state, |
| 78 const base::Closure& task); | 81 const base::Closure& task); |
| 79 // Same as SendMouseEvents with UP | DOWN. | |
| 80 UI_EXPORT bool SendMouseClick(MouseButton type); | 82 UI_EXPORT bool SendMouseClick(MouseButton type); |
| 81 | 83 |
| 82 #if defined(TOOLKIT_VIEWS) | 84 #if defined(TOOLKIT_VIEWS) |
| 83 // Runs |closure| after processing all pending ui events. | 85 // Runs |closure| after processing all pending ui events. |
| 84 UI_EXPORT void RunClosureAfterAllPendingUIEvents( | 86 UI_EXPORT void RunClosureAfterAllPendingUIEvents( |
| 85 const base::Closure& closure); | 87 const base::Closure& closure); |
| 86 #endif | 88 #endif |
| 87 | 89 |
| 88 #if defined(USE_AURA) | 90 // End of deprecated transition methods. |
| 89 class UIControlsAura; | 91 |
| 90 UI_EXPORT void InstallUIControlsAura(UIControlsAura* instance); | 92 |
| 93 class UI_EXPORT UIControls { | |
| 94 public: | |
| 95 UIControls(); | |
| 96 virtual ~UIControls(); | |
| 97 | |
| 98 // Retrieves the UIControls instance that the specified NativeView is | |
| 99 // attached to. A Value of NULL is treated as |UI_CONTROLS_TYPE_NATIVE|. | |
| 100 static UIControls* GetUIControlsFor(gfx::NativeView view); | |
| 101 | |
| 102 // Returns the UI_CONTROLS_TYPE_NATIVE UIControls. This should be used with | |
| 103 // caution, as it is likely to be incorrect for code that runs on Windows. | |
| 104 static UIControls* GetNativeUIControls(); | |
| 105 | |
| 106 // Sets the global UIControls instance for a particular type. Only | |
| 107 // the _NATIVE UIControlsType must be provided. | |
| 108 static void SetUIControlsInstance(UIControlsType type, UIControls* instance); | |
| 109 | |
| 110 // Returns the global UIControls instance for particular type. Types other | |
| 111 // than _NATIVE may be NULL. | |
| 112 static UIControls* GetUIControlsByType(UIControlsType type); | |
| 113 | |
| 114 // Sets the global UIControlsTypeDelegate. May be left unset if the platform | |
| 115 // only uses the _NATIVE UIControlsType. | |
| 116 static void SetUIControlsTypeDelegate(UIControlsTypeDelegate* delegate); | |
| 117 | |
| 118 // Many of the functions in this class include a variant that takes a | |
| 119 // Closure. The version that takes a Closure waits until the generated event | |
| 120 // is processed. Once the generated event is processed the Closure is Run | |
| 121 // (and deleted). Note that this is a somewhat fragile process in that any | |
| 122 // event of the correct type (key down, mouse click, etc.) will trigger the | |
| 123 // Closure to be run. Hence a usage such as | |
| 124 // | |
| 125 // SendKeyPress(...); | |
| 126 // SendKeyPressNotifyWhenDone(..., task); | |
| 127 // | |
| 128 // might trigger |task| early. | |
| 129 // | |
| 130 // Note: Windows does not currently do anything with the |window| argument | |
| 131 // for these functions, so passing NULL is ok. | |
| 132 | |
| 133 // Send a key press with/without modifier keys. | |
| 134 // | |
| 135 // If you're writing a test chances are you want the variant in ui_test_utils. | |
| 136 // See it for details. | |
| 137 virtual bool SendKeyPress(gfx::NativeWindow window, | |
| 138 ui::KeyboardCode key, | |
| 139 bool control, | |
| 140 bool shift, | |
| 141 bool alt, | |
| 142 bool command) = 0; | |
| 143 virtual bool SendKeyPressNotifyWhenDone(gfx::NativeWindow window, | |
| 144 ui::KeyboardCode key, | |
| 145 bool control, | |
| 146 bool shift, | |
| 147 bool alt, | |
| 148 bool command, | |
| 149 const base::Closure& task) = 0; | |
| 150 | |
| 151 // Simulate a mouse move. (x,y) are absolute screen coordinates. | |
| 152 virtual bool SendMouseMove(long x, long y) = 0; | |
| 153 virtual bool SendMouseMoveNotifyWhenDone(long x, | |
| 154 long y, | |
| 155 const base::Closure& task) = 0; | |
| 156 | |
| 157 // Sends a mouse down and/or up message. The click will be sent to wherever | |
| 158 // the cursor currently is, so be sure to move the cursor before calling this | |
| 159 // (and be sure the cursor has arrived!). | |
| 160 virtual bool SendMouseEvents(MouseButton type, int state) = 0; | |
| 161 virtual bool SendMouseEventsNotifyWhenDone( | |
| 162 MouseButton type, int state, | |
| 163 const base::Closure& task) = 0; | |
| 164 // Same as SendMouseEvents with UP | DOWN. | |
| 165 virtual bool SendMouseClick(MouseButton type) = 0; | |
| 166 | |
| 167 #if defined(TOOLKIT_VIEWS) | |
| 168 // Runs |closure| after processing all pending ui events. | |
| 169 virtual void RunClosureAfterAllPendingUIEvents( | |
| 170 const base::Closure& closure) = 0; | |
| 91 #endif | 171 #endif |
| 172 }; | |
| 173 | |
| 174 UIControls* CreateNativeUIControls(); | |
| 92 | 175 |
| 93 } // namespace ui_controls | 176 } // namespace ui_controls |
| 94 | 177 |
| 95 #endif // UI_UI_CONTROLS_UI_CONTROLS_H_ | 178 #endif // UI_UI_CONTROLS_UI_CONTROLS_H_ |
| OLD | NEW |