Skip to content

Commit 0d9b4f0

Browse files
committed
added mouse wheel command
1 parent b84ac80 commit 0d9b4f0

17 files changed

+171
-1
lines changed

inc/commands/mouse_commands.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class HoverCommand : public ElementCommand {
5555
/// - /session/:sessionId/buttondown
5656
/// - /session/:sessionId/buttonup
5757
/// - /session/:sessionId/doubleclick
58+
/// - /session/:sessionId/wheel
5859
class AdvancedMouseCommand : public ViewCommand {
5960
public:
6061
AdvancedMouseCommand(const std::vector<std::string>& path_segments,
@@ -158,6 +159,25 @@ class DoubleClickCommand : public AdvancedMouseCommand {
158159
DISALLOW_COPY_AND_ASSIGN(DoubleClickCommand);
159160
};
160161

162+
/// Scrolls the wheel of the mouse by the given number of ticks, where a positive
163+
/// number indicates a downward scroll (wheel was rotated forwards away from the user)
164+
/// and a negative is upward scroll (wheel was rotated backwards toward the user).
165+
166+
class WheelCommand : public AdvancedMouseCommand {
167+
public:
168+
WheelCommand(const std::vector<std::string>& path_segments,
169+
const base::DictionaryValue* const parameters);
170+
virtual ~WheelCommand();
171+
172+
virtual bool Init(Response* const response) OVERRIDE;
173+
virtual void ExecutePost(Response* const response) OVERRIDE;
174+
175+
private:
176+
int ticks_;
177+
178+
DISALLOW_COPY_AND_ASSIGN(WheelCommand);
179+
};
180+
161181
} // namespace webdriver
162182

163183
#endif // WEBDRIVER_COMMANDS_MOUSE_COMMANDS_H_

inc/extension_qt/graphics_web_view_executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ class GraphicsWebViewCmdExecutor : public ViewCmdExecutor {
5959
virtual void MouseButtonUp(Error** error);
6060
virtual void MouseButtonDown(Error** error);
6161
virtual void MouseClick(MouseButton button, Error** error);
62+
virtual void MouseWheel(const int delta, Error **error);
6263
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
6364
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
6465
virtual void MouseMove(const ElementId& element, Error** error);

inc/extension_qt/qml_view_executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ class QQmlViewCmdExecutor : public QViewCmdExecutor {
4343
virtual void MouseButtonUp(Error** error);
4444
virtual void MouseButtonDown(Error** error);
4545
virtual void MouseClick(MouseButton button, Error** error);
46+
virtual void MouseWheel(const int delta, Error **error);
4647
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
4748
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
4849
virtual void MouseMove(const ElementId& element, Error** error);

inc/extension_qt/quick2_view_executor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ class Quick2ViewCmdExecutor : public QWindowViewCmdExecutor {
4141
virtual void MouseDoubleClick(Error** error);
4242
virtual void MouseButtonUp(Error** error);
4343
virtual void MouseButtonDown(Error** error);
44-
virtual void MouseClick(MouseButton button, Error** error);
44+
virtual void MouseClick(MouseButton button, Error** error);
45+
virtual void MouseWheel(const int delta, Error **error);
4546
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
4647
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
4748
virtual void MouseMove(const ElementId& element, Error** error);

inc/extension_qt/web_view_executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class QWebViewCmdExecutor : public QViewCmdExecutor {
5656
virtual void MouseButtonUp(Error** error);
5757
virtual void MouseButtonDown(Error** error);
5858
virtual void MouseClick(MouseButton button, Error** error);
59+
virtual void MouseWheel(const int delta, Error **error);
5960
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
6061
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
6162
virtual void MouseMove(const ElementId& element, Error** error);

inc/extension_qt/widget_view_executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class QWidgetViewCmdExecutor : public QViewCmdExecutor {
3838
virtual void MouseButtonUp(Error** error);
3939
virtual void MouseButtonDown(Error** error);
4040
virtual void MouseClick(MouseButton button, Error** error);
41+
virtual void MouseWheel(const int delta, Error **error);
4142
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
4243
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
4344
virtual void MouseMove(const ElementId& element, Error** error);

inc/webdriver_route_patterns.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class CommandRoutes {
4545
static const char kMouseButtonDown[];
4646
static const char kMouseButtonUp[];
4747
static const char kMouseMoveTo[];
48+
static const char kMouseWheel[];
4849
static const char kClearElement[];
4950
static const char kSendKeysToElement[];
5051
static const char kSubmitElement[];

inc/webdriver_route_table.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
/// - kMouseButtonDown[] = "/session/*/buttondown";
6060
/// - kMouseButtonUp[] = "/session/*/buttonup";
6161
/// - kMouseMoveTo[] = "/session/*/moveto";
62+
/// - kMouseWheel[] = "/session/*/wheel";
6263
/// - kFindElement[] = "/session/*/element";
6364
/// - kFindElements[] = "/session/*/elements";
6465
/// - kClearElement[] = "/session/*/element/*/clear";

inc/webdriver_view_executor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ class ViewCmdExecutor{
8383
virtual void MouseButtonUp(Error** error) = 0;
8484
virtual void MouseButtonDown(Error** error) = 0;
8585
virtual void MouseClick(MouseButton button, Error** error) = 0;
86+
virtual void MouseWheel(const int delta, Error** error) = 0;
8687
/// move mouse to position: cur_point + offset
8788
virtual void MouseMove(const int x_offset, const int y_offset, Error** error) = 0;
8889
/// Move the mouse by an offset of the specificed element

src/webdriver/commands/mouse_commands.cc

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,4 +256,43 @@ void DoubleClickCommand::ExecutePost(Response* const response) {
256256
}
257257
}
258258

259+
WheelCommand::WheelCommand(
260+
const std::vector<std::string> &path_segments,
261+
const base::DictionaryValue * const parameters)
262+
: AdvancedMouseCommand(path_segments, parameters) {}
263+
264+
WheelCommand::~WheelCommand() {}
265+
266+
bool WheelCommand::Init(Response* const response) {
267+
if (!AdvancedMouseCommand::Init(response))
268+
return false;
269+
270+
if (!GetIntegerParameter("ticks", &ticks_)) {
271+
response->SetError(new Error(kBadRequest, "Missing ticks argument"));
272+
return false;
273+
}
274+
275+
return true;
276+
}
277+
278+
void WheelCommand::ExecutePost(Response * const response) {
279+
Error* error = NULL;
280+
281+
// Most mouse types work in steps of 15 degrees,
282+
// in which case the delta value is a multiple of 15 * 8 = 120;
283+
const int STEP_WHEEL = 120;
284+
int delta = ticks_ * STEP_WHEEL;
285+
286+
session_->RunSessionTask(base::Bind(
287+
&ViewCmdExecutor::MouseWheel,
288+
base::Unretained(executor_.get()),
289+
delta,
290+
&error));
291+
292+
if (error) {
293+
response->SetError(error);
294+
return;
295+
}
296+
}
297+
259298
} // namespace webdriver

0 commit comments

Comments
 (0)