Skip to content

Commit 0956b4e

Browse files
committed
added graphics web view implementation
1 parent a73be7b commit 0956b4e

File tree

6 files changed

+987
-0
lines changed

6 files changed

+987
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#ifndef WEBDRIVER_GRAPHICS_WEB_VIEW_ENUMERATOR_H_
2+
#define WEBDRIVER_GRAPHICS_WEB_VIEW_ENUMERATOR_H_
3+
4+
#include <string>
5+
#include <vector>
6+
#include <set>
7+
8+
#include "webdriver_view_enumerator.h"
9+
10+
namespace webdriver {
11+
12+
/// class for QDeclarativeWebView enumerator
13+
class GraphicsQmlWebViewEnumeratorImpl : public AbstractViewEnumeratorImpl {
14+
public:
15+
virtual void EnumerateViews(Session* session, std::set<ViewId>* views) const;
16+
};
17+
18+
} // namespace webdriver
19+
20+
#endif // WEBDRIVER_GRAPHICS_WEB_VIEW_ENUMERATOR_H_
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#ifndef WEBDRIVER_GRAPHICS_WEB_VIEW_EXECUTOR_H
2+
#define WEBDRIVER_GRAPHICS_WEB_VIEW_EXECUTOR_H
3+
4+
#include <string>
5+
#include <vector>
6+
#include <map>
7+
8+
#include "base/memory/scoped_ptr.h"
9+
#include "webdriver_view_executor.h"
10+
#include "webdriver_error.h"
11+
12+
#include <QtCore/QDebug>
13+
14+
class QGraphicsWebView;
15+
16+
namespace webdriver {
17+
18+
class QWebkitProxy;
19+
20+
class GraphicsWebViewCmdExecutorCreator : public ViewCmdExecutorCreator {
21+
public:
22+
static const ViewType GRAPHICS_WEB_VIEW_TYPE;
23+
24+
GraphicsWebViewCmdExecutorCreator();
25+
virtual ~GraphicsWebViewCmdExecutorCreator();
26+
27+
virtual ViewCmdExecutor* CreateExecutor(Session* session, ViewId viewId) const;
28+
virtual bool CanHandleView(Session* session, ViewId viewId, ViewType* viewType = NULL) const;
29+
private:
30+
31+
DISALLOW_COPY_AND_ASSIGN(GraphicsWebViewCmdExecutorCreator);
32+
};
33+
34+
#define NOT_SUPPORTED_IMPL {*error = new Error(kCommandNotSupported, "Current view doesnt support this command.");}
35+
36+
class GraphicsWebViewCmdExecutor : public ViewCmdExecutor {
37+
public:
38+
explicit GraphicsWebViewCmdExecutor(Session* session, ViewId viewId);
39+
virtual ~GraphicsWebViewCmdExecutor();
40+
41+
virtual void CanHandleUrl(const std::string& url, bool* can, Error **error);
42+
virtual void GetTitle(std::string* title, Error **error);
43+
virtual void GetWindowName(std::string* name, Error ** error);
44+
virtual void GetBounds(Rect *bounds, Error **error);
45+
virtual void SetBounds(const Rect& bounds, Error** error) NOT_SUPPORTED_IMPL;
46+
virtual void Maximize(Error** error) NOT_SUPPORTED_IMPL;
47+
virtual void GetScreenShot(std::string* png, Error** error);
48+
virtual void GoForward(Error** error);
49+
virtual void GoBack(Error** error);
50+
virtual void Reload(Error** error);
51+
virtual void GetSource(std::string* source, Error** error);
52+
virtual void SendKeys(const string16& keys, Error** error);
53+
virtual void SendKeys(const ElementId& element, const string16& keys, Error** error);
54+
virtual void Close(Error** error) NOT_SUPPORTED_IMPL;
55+
virtual void MouseDoubleClick(Error** error);
56+
virtual void MouseButtonUp(Error** error);
57+
virtual void MouseButtonDown(Error** error);
58+
virtual void MouseClick(MouseButton button, Error** error);
59+
virtual void MouseMove(const int x_offset, const int y_offset, Error** error);
60+
virtual void MouseMove(const ElementId& element, int x_offset, const int y_offset, Error** error);
61+
virtual void MouseMove(const ElementId& element, Error** error);
62+
virtual void ClickElement(const ElementId& element, Error** error);
63+
virtual void GetAttribute(const ElementId& element, const std::string& key, base::Value** value, Error** error);
64+
virtual void ClearElement(const ElementId& element, Error** error);
65+
virtual void IsElementDisplayed(const ElementId& element, bool ignore_opacity, bool* is_displayed, Error** error);
66+
virtual void IsElementEnabled(const ElementId& element, bool* is_enabled, Error** error);
67+
virtual void ElementEquals(const ElementId& element1, const ElementId& element2, bool* is_equal, Error** error);
68+
virtual void GetElementLocation(const ElementId& element, Point* location, Error** error);
69+
virtual void GetElementLocationInView(const ElementId& element, Point* location, Error** error);
70+
virtual void GetElementTagName(const ElementId& element, std::string* tag_name, Error** error);
71+
virtual void IsOptionElementSelected(const ElementId& element, bool* is_selected, Error** error);
72+
virtual void SetOptionElementSelected(const ElementId& element, bool selected, Error** error);
73+
virtual void GetElementSize(const ElementId& element, Size* size, Error** error);
74+
virtual void ElementSubmit(const ElementId& element, Error** error);
75+
virtual void GetElementText(const ElementId& element, std::string* element_text, Error** error);
76+
virtual void GetElementCssProperty(const ElementId& element, const std::string& property, base::Value** value, Error** error);
77+
virtual void FindElement(const ElementId& root_element, const std::string& locator, const std::string& query, ElementId* element, Error** error);
78+
virtual void FindElements(const ElementId& root_element, const std::string& locator, const std::string& query, std::vector<ElementId>* elements, Error** error);
79+
virtual void ActiveElement(ElementId* element, Error** error);
80+
virtual void SwitchTo(Error** error);
81+
virtual void SwitchToFrameWithNameOrId(const std::string& name_or_id, Error** error);
82+
virtual void SwitchToFrameWithIndex(int index, Error** error);
83+
virtual void SwitchToFrameWithElement(const ElementId& element, Error** error);
84+
virtual void SwitchToTopFrame(Error** error);
85+
virtual void SwitchToTopFrameIfCurrentFrameInvalid(Error** error);
86+
virtual void NavigateToURL(const std::string& url, bool sync, Error** error);
87+
virtual void GetURL(std::string* url, Error** error);
88+
virtual void ExecuteScript(const std::string& script, const base::ListValue* const args, base::Value** value, Error** error);
89+
virtual void ExecuteAsyncScript(const std::string& script, const base::ListValue* const args, base::Value** value, Error** error);
90+
virtual void GetAppCacheStatus(int* status, Error** error);
91+
virtual void GetCookies(const std::string& url, base::ListValue** cookies, Error** error);
92+
virtual void SetCookie(const std::string& url, base::DictionaryValue* cookie_dict, Error** error);
93+
virtual void DeleteCookie(const std::string& url, const std::string& cookie_name, Error** error);
94+
virtual void GetStorageKeys(StorageType type, base::ListValue** keys, Error** error);
95+
virtual void SetStorageItem(StorageType type, const std::string& key, const std::string& value, Error** error);
96+
virtual void ClearStorage(StorageType type, Error** error);
97+
virtual void GetStorageItem(StorageType type, const std::string& key, std::string* value, Error** error);
98+
virtual void RemoveStorageItem(StorageType type, const std::string& key, std::string* value, Error** error);
99+
virtual void GetStorageSize(StorageType type, int* size, Error** error);
100+
virtual void GetGeoLocation(base::DictionaryValue** geolocation, Error** error) NOT_SUPPORTED_IMPL;
101+
virtual void SetGeoLocation(const base::DictionaryValue* geolocation, Error** error) NOT_SUPPORTED_IMPL;
102+
virtual void TouchClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
103+
virtual void TouchDoubleClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
104+
virtual void TouchDown(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
105+
virtual void TouchUp(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
106+
virtual void TouchMove(const int &x, const int &y, Error **error) NOT_SUPPORTED_IMPL;
107+
virtual void TouchLongClick(const ElementId& element, Error **error) NOT_SUPPORTED_IMPL;
108+
virtual void TouchScroll(const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
109+
virtual void TouchScroll(const ElementId &element, const int &xoffset, const int &yoffset, Error **error) NOT_SUPPORTED_IMPL;
110+
virtual void TouchFlick(const int &xSpeed, const int &ySpeed, Error **error) NOT_SUPPORTED_IMPL;
111+
virtual void TouchFlick(const ElementId &element, const int &xoffset, const int &yoffset, const int &speed, Error **error) NOT_SUPPORTED_IMPL;
112+
virtual void GetBrowserLog(base::ListValue** browserLog, Error **error);
113+
virtual void GetPlayerState(const ElementId& element, PlayerState*, Error**);
114+
virtual void SetPlayerState(const ElementId& element, PlayerState, Error**);
115+
virtual void GetPlayerVolume(const ElementId& element, double*, Error**);
116+
virtual void SetPlayerVolume(const ElementId& element, double, Error**);
117+
virtual void GetPlayingPosition(const ElementId& element, double*, Error**);
118+
virtual void SetPlayingPosition(const ElementId& element, double, Error**);
119+
virtual void SetMute(const ElementId& element, bool, Error**);
120+
virtual void GetMute(const ElementId& element, bool*, Error**);
121+
virtual void SetPlaybackSpeed(const ElementId& element, double, Error**);
122+
virtual void GetPlaybackSpeed(const ElementId& element, double*, Error**);
123+
virtual void VisualizerSource(std::string* source, Error** error);
124+
virtual void VisualizerShowPoint(Error** error);
125+
virtual void GetAlertMessage(std::string* text, Error** error) NOT_SUPPORTED_IMPL;
126+
virtual void SetAlertPromptText(const std::string& alert_prompt_text, Error** error) NOT_SUPPORTED_IMPL;
127+
virtual void AcceptOrDismissAlert(bool accept, Error** error) NOT_SUPPORTED_IMPL;
128+
virtual void SetOrientation(const std::string &orientation, Error **error) NOT_SUPPORTED_IMPL;
129+
virtual void GetOrientation(std::string *orientation, Error **error);
130+
131+
protected:
132+
QGraphicsWebView* getView(const ViewId& viewId, Error** error);
133+
134+
private:
135+
scoped_ptr<QWebkitProxy> webkitProxy_;
136+
QGraphicsWebView* view_;
137+
138+
DISALLOW_COPY_AND_ASSIGN(GraphicsWebViewCmdExecutor);
139+
};
140+
141+
} // namespace webdriver
142+
143+
#endif // WEBDRIVER_GRAPHICS_WEB_VIEW_EXECUTOR_H
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#ifndef WEBDRIVER_QT_GRAPHICS_WEB_VIEW_H_
2+
#define WEBDRIVER_QT_GRAPHICS_WEB_VIEW_H_
3+
4+
#include <string>
5+
6+
#include "webdriver_view_id.h"
7+
8+
#include <QtCore/QPointer>
9+
10+
#include <QtCore/QtGlobal>
11+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
12+
#include <QtWebKitWidgets/QGraphicsWebView>
13+
#else
14+
#include <QtWebKit/QGraphicsWebView>
15+
#endif
16+
17+
namespace webdriver {
18+
19+
class GraphicsWebViewHandle : public ViewHandle {
20+
public:
21+
GraphicsWebViewHandle();
22+
GraphicsWebViewHandle(QGraphicsWebView* view);
23+
24+
virtual bool is_valid() const { return !view_.isNull(); };
25+
virtual bool equals(const ViewHandle* other) const;
26+
QGraphicsWebView* get() { return view_.data(); };
27+
28+
protected:
29+
QPointer<QGraphicsWebView> view_;
30+
//private:
31+
virtual ~GraphicsWebViewHandle() {};
32+
};
33+
34+
} // namespace webdriver
35+
36+
#endif // WEBDRIVER_QT_GRAPHICS_WEB_VIEW_H_
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#include "extension_qt/graphics_web_view_enumerator.h"
2+
3+
#include "webdriver_session.h"
4+
#include "webdriver_logging.h"
5+
6+
#include "extension_qt/graphics_web_view_handle.h"
7+
8+
#include <QtCore/QGlobalStatic>
9+
#include <QtCore/QDebug>
10+
#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
11+
#include <QtWidgets/QGraphicsView>
12+
#include <QtWidgets/QApplication>
13+
#else
14+
#include <QtGui/QGraphicsView>
15+
#include <QtGui/QApplication>
16+
#endif
17+
18+
19+
namespace webdriver {
20+
21+
void GraphicsQmlWebViewEnumeratorImpl::EnumerateViews(Session* session, std::set<ViewId>* views) const {
22+
session->logger().Log(kInfoLogLevel, ">>>>> QGraphicsWebView enumerate");
23+
24+
foreach(QWidget* pWidget, qApp->allWidgets()) {
25+
if (pWidget->isHidden()) continue;
26+
27+
QGraphicsView* pView = qobject_cast<QGraphicsView*>(pWidget);
28+
if (NULL != pView) {
29+
QList<QGraphicsItem*> childs = pView->items();
30+
foreach(QGraphicsItem *child, childs) {
31+
QGraphicsWebView* webView = qobject_cast<QGraphicsWebView*>(child->toGraphicsObject());
32+
if (webView) {
33+
// found
34+
ViewHandlePtr handle(new GraphicsWebViewHandle(webView));
35+
ViewId viewId = session->GetViewForHandle(handle);
36+
if (!viewId.is_valid()) {
37+
if (session->AddNewView(handle, &viewId)) {
38+
session->logger().Log(kInfoLogLevel,
39+
"GraphicsQmlWebViewEnumerator found new view("+viewId.id()+")");
40+
}
41+
}
42+
if (viewId.is_valid()) {
43+
views->insert(viewId);
44+
}
45+
}
46+
}
47+
}
48+
}
49+
}
50+
51+
} // namespace webdriver

0 commit comments

Comments
 (0)