Merge ~santoshbit2007/oxide:santosh@html5pointerLock_branch into oxide:master
- Git
- lp:~santoshbit2007/oxide
- santosh@html5pointerLock_branch
- Merge into master
Proposed by
Chris Coulson
Status: | Work in progress |
---|---|
Proposed branch: | ~santoshbit2007/oxide:santosh@html5pointerLock_branch |
Merge into: | oxide:master |
Diff against target: |
685 lines (+331/-2) 30 files modified
qt/core/browser/oxide_qt_contents_view.cc (+4/-0) qt/core/browser/oxide_qt_contents_view.h (+2/-0) qt/core/browser/oxide_qt_screen_client.cc (+11/-0) qt/core/browser/oxide_qt_screen_client.h (+5/-0) qt/core/browser/oxide_qt_web_view.cc (+10/-0) qt/core/browser/oxide_qt_web_view.h (+2/-0) qt/core/glue/oxide_qt_contents_view_proxy_client.h (+1/-0) qt/core/glue/oxide_qt_web_view_proxy_client.h (+2/-0) qt/qmlplugin/oxide_qml_plugin.cc (+1/-0) qt/quick/api/oxideqquickwebview.cc (+26/-0) qt/quick/api/oxideqquickwebview.h (+1/-0) qt/quick/api/oxideqquickwebview_p.h (+2/-0) qt/quick/oxide_qquick_before_unload_dialog.cc (+1/-0) qt/quick/oxide_qquick_contents_view.cc (+4/-0) qt/quick/oxide_qquick_contents_view.h (+1/-0) qt/tests/qmltests/api/tst_MouseLockPermissionRequest.html (+43/-0) qt/tests/qmltests/api/tst_MouseLockPermissionRequest.qml (+103/-0) shared/browser/oxide_render_widget_host_view.cc (+25/-2) shared/browser/oxide_render_widget_host_view.h (+3/-0) shared/browser/oxide_render_widget_host_view_container.h (+2/-0) shared/browser/oxide_screen_client.h (+3/-0) shared/browser/oxide_web_contents_view.cc (+4/-0) shared/browser/oxide_web_contents_view.h (+2/-0) shared/browser/oxide_web_contents_view_client.cc (+3/-0) shared/browser/oxide_web_contents_view_client.h (+1/-0) shared/browser/oxide_web_view.cc (+21/-0) shared/browser/oxide_web_view.h (+12/-0) shared/browser/permissions/oxide_permission_request_dispatcher.cc (+26/-0) shared/browser/permissions/oxide_permission_request_dispatcher.h (+7/-0) shared/browser/permissions/oxide_permission_request_dispatcher_client.h (+3/-0) |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Chris Coulson | Needs Fixing | ||
Review via email: mp+294906@code.launchpad.net |
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
Chris Coulson (chrisccoulson) wrote : | # |
Thanks for working on this - I've left a few comments inline. As Olivier pointed out, please do use curly braces even around single-line conditional blocks (in general, we try to stick to the Chromium style but this is one of the exceptions).
As discussed online, we're missing the actual pointer lock implementation here. There is an API for doing this - http://
I've not had a look at the test yet.
review:
Needs Fixing
- f17ce0d... by Santosh Mahto <email address hidden>
-
HTML5 pointerLock implementation
Revision history for this message
Santosh (santoshbit2007) : | # |
Revision history for this message
Olivier Tilloy (osomon) wrote : | # |
I’ve replied to one of your questions inline.
Unmerged commits
- f17ce0d... by Santosh Mahto <email address hidden>
-
HTML5 pointerLock implementation
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | diff --git a/qt/core/browser/oxide_qt_contents_view.cc b/qt/core/browser/oxide_qt_contents_view.cc |
2 | index 4c93147..cfed182 100644 |
3 | --- a/qt/core/browser/oxide_qt_contents_view.cc |
4 | +++ b/qt/core/browser/oxide_qt_contents_view.cc |
5 | @@ -626,5 +626,9 @@ QScreen* ContentsView::GetScreen() const { |
6 | return screen; |
7 | } |
8 | |
9 | +void ContentsView::GrabMouse(bool grab) const { |
10 | + client_->GrabMouse(grab); |
11 | +} |
12 | + |
13 | } // namespace qt |
14 | } // namespace oxide |
15 | diff --git a/qt/core/browser/oxide_qt_contents_view.h b/qt/core/browser/oxide_qt_contents_view.h |
16 | index 13f44e2..db60fc7 100644 |
17 | --- a/qt/core/browser/oxide_qt_contents_view.h |
18 | +++ b/qt/core/browser/oxide_qt_contents_view.h |
19 | @@ -67,6 +67,8 @@ class ContentsView : public ContentsViewProxy, |
20 | |
21 | float GetLocationBarContentOffset() const; |
22 | |
23 | + void GrabMouse(bool grab) const; |
24 | + |
25 | private: |
26 | // ContentsViewProxy implementation |
27 | QSharedPointer<CompositorFrameHandle> compositorFrameHandle() override; |
28 | diff --git a/qt/core/browser/oxide_qt_screen_client.cc b/qt/core/browser/oxide_qt_screen_client.cc |
29 | index 3d3e5e3..09abaad 100644 |
30 | --- a/qt/core/browser/oxide_qt_screen_client.cc |
31 | +++ b/qt/core/browser/oxide_qt_screen_client.cc |
32 | @@ -86,6 +86,17 @@ gfx::Point ScreenClient::GetCursorScreenPoint() { |
33 | return gfx::Point(point.x(), point.y()); |
34 | } |
35 | |
36 | +void ScreenClient::HideMousePointer() { |
37 | + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
38 | + QCursor cursor(Qt::BlankCursor); |
39 | + QGuiApplication::setOverrideCursor(cursor); |
40 | +} |
41 | + |
42 | +void ScreenClient::ShowMousePointer() { |
43 | + DCHECK_CURRENTLY_ON(content::BrowserThread::UI); |
44 | + QGuiApplication::restoreOverrideCursor(); |
45 | +} |
46 | + |
47 | ScreenClient::ScreenClient() { |
48 | QScreen* primary_screen = QGuiApplication::primaryScreen(); |
49 | primary_screen->setOrientationUpdateMask(Qt::LandscapeOrientation | |
50 | diff --git a/qt/core/browser/oxide_qt_screen_client.h b/qt/core/browser/oxide_qt_screen_client.h |
51 | index f7a492d..df82427 100644 |
52 | --- a/qt/core/browser/oxide_qt_screen_client.h |
53 | +++ b/qt/core/browser/oxide_qt_screen_client.h |
54 | @@ -38,6 +38,11 @@ class ScreenClient : public QObject, |
55 | public: |
56 | ScreenClient(); |
57 | ~ScreenClient() override; |
58 | + // TODO(santosh.mahto) Right now this hide the mouse pointer |
59 | + // from the current application not from screen which should |
60 | + // be actual behaviour |
61 | + void HideMousePointer() override; |
62 | + void ShowMousePointer() override; |
63 | |
64 | private Q_SLOTS: |
65 | void OnScreenGeometryChanged(const QRect& geometry); |
66 | diff --git a/qt/core/browser/oxide_qt_web_view.cc b/qt/core/browser/oxide_qt_web_view.cc |
67 | index 6670657..b4dc88d 100644 |
68 | --- a/qt/core/browser/oxide_qt_web_view.cc |
69 | +++ b/qt/core/browser/oxide_qt_web_view.cc |
70 | @@ -666,6 +666,16 @@ void WebView::RequestMediaAccessPermission( |
71 | client_->RequestMediaAccessPermission(req.release()); |
72 | } |
73 | |
74 | + |
75 | +void WebView::RequestMouseLockPermission( |
76 | + std::unique_ptr<oxide::PermissionRequest> request) { |
77 | + std::unique_ptr<OxideQPermissionRequest> req( |
78 | + OxideQPermissionRequestPrivate::Create(std::move(request))); |
79 | + |
80 | + // The embedder takes ownership of this |
81 | + client_->RequestMouseLockPermission(std::move(req)); |
82 | +} |
83 | + |
84 | void WebView::FrameCreated(oxide::WebFrame* frame) { |
85 | DCHECK(!frame_tree_torn_down_); |
86 | DCHECK(!WebFrame::FromSharedWebFrame(frame)); |
87 | diff --git a/qt/core/browser/oxide_qt_web_view.h b/qt/core/browser/oxide_qt_web_view.h |
88 | index 053bafa..4914274 100644 |
89 | --- a/qt/core/browser/oxide_qt_web_view.h |
90 | +++ b/qt/core/browser/oxide_qt_web_view.h |
91 | @@ -171,6 +171,8 @@ class WebView : public oxide::WebViewClient, |
92 | void RequestMediaAccessPermission( |
93 | std::unique_ptr<oxide::MediaAccessPermissionRequest> request) override; |
94 | |
95 | + void RequestMouseLockPermission( |
96 | + std::unique_ptr<oxide::PermissionRequest> request) override; |
97 | // oxide::WebFrameTreeObserver implementation |
98 | void FrameCreated(oxide::WebFrame* frame) override; |
99 | void FrameDeleted(oxide::WebFrame* frame) override; |
100 | diff --git a/qt/core/glue/oxide_qt_contents_view_proxy_client.h b/qt/core/glue/oxide_qt_contents_view_proxy_client.h |
101 | index c5cf713..72f3666 100644 |
102 | --- a/qt/core/glue/oxide_qt_contents_view_proxy_client.h |
103 | +++ b/qt/core/glue/oxide_qt_contents_view_proxy_client.h |
104 | @@ -62,6 +62,7 @@ class ContentsViewProxyClient { |
105 | virtual void EvictCurrentFrame() = 0; |
106 | |
107 | virtual void UpdateCursor(const QCursor& cursor) = 0; |
108 | + virtual void GrabMouse(bool grab) const = 0; |
109 | |
110 | virtual void SetInputMethodEnabled(bool enabled) = 0; |
111 | |
112 | diff --git a/qt/core/glue/oxide_qt_web_view_proxy_client.h b/qt/core/glue/oxide_qt_web_view_proxy_client.h |
113 | index 436e550..23cb3cd 100644 |
114 | --- a/qt/core/glue/oxide_qt_web_view_proxy_client.h |
115 | +++ b/qt/core/glue/oxide_qt_web_view_proxy_client.h |
116 | @@ -105,6 +105,8 @@ class WebViewProxyClient { |
117 | OxideQGeolocationPermissionRequest* request) = 0; |
118 | virtual void RequestMediaAccessPermission( |
119 | OxideQMediaAccessPermissionRequest* request) = 0; |
120 | + virtual void RequestMouseLockPermission( |
121 | + std::unique_ptr<OxideQPermissionRequest> request) = 0; |
122 | virtual void RequestNotificationPermission( |
123 | OxideQPermissionRequest* request) = 0; |
124 | |
125 | diff --git a/qt/qmlplugin/oxide_qml_plugin.cc b/qt/qmlplugin/oxide_qml_plugin.cc |
126 | index 6895600..a3e59ee 100644 |
127 | --- a/qt/qmlplugin/oxide_qml_plugin.cc |
128 | +++ b/qt/qmlplugin/oxide_qml_plugin.cc |
129 | @@ -206,6 +206,7 @@ class OxideQmlPlugin : public QQmlExtensionPlugin { |
130 | "TouchSelectionController is accessed via " |
131 | "WebView.touchSelectionController"); |
132 | qmlRegisterType<OxideQQuickWebView, 8>(uri, 1, 15, "WebView"); |
133 | + qmlRegisterType<OxideQQuickWebView, 9>(uri, 1, 16, "WebView"); |
134 | } |
135 | }; |
136 | |
137 | diff --git a/qt/quick/api/oxideqquickwebview.cc b/qt/quick/api/oxideqquickwebview.cc |
138 | index a804d4e..b559094 100644 |
139 | --- a/qt/quick/api/oxideqquickwebview.cc |
140 | +++ b/qt/quick/api/oxideqquickwebview.cc |
141 | @@ -374,6 +374,32 @@ void OxideQQuickWebViewPrivate::RequestMediaAccessPermission( |
142 | |
143 | } |
144 | |
145 | +void OxideQQuickWebViewPrivate::RequestMouseLockPermission( |
146 | + std::unique_ptr<OxideQPermissionRequest> request) { |
147 | + Q_Q(OxideQQuickWebView); |
148 | + |
149 | + // See the comment in RequestGeolocationPermission |
150 | + |
151 | + QQmlEngine* engine = qmlEngine(q); |
152 | + if (!engine) { |
153 | + return; |
154 | + } |
155 | + |
156 | + { |
157 | + OxideQPermissionRequest* req = request.release(); |
158 | + QJSValue val = engine->newQObject(req); |
159 | + if (!val.isQObject()) { |
160 | + delete req; |
161 | + return; |
162 | + } |
163 | + |
164 | + emit q->mouseLockPermissionRequested(val); |
165 | + } |
166 | + |
167 | + engine->collectGarbage(); |
168 | + |
169 | +} |
170 | + |
171 | void OxideQQuickWebViewPrivate::RequestNotificationPermission( |
172 | OxideQPermissionRequest* request) { |
173 | Q_Q(OxideQQuickWebView); |
174 | diff --git a/qt/quick/api/oxideqquickwebview.h b/qt/quick/api/oxideqquickwebview.h |
175 | index 9279bf6..b0a4e4f 100644 |
176 | --- a/qt/quick/api/oxideqquickwebview.h |
177 | +++ b/qt/quick/api/oxideqquickwebview.h |
178 | @@ -361,6 +361,7 @@ class OXIDE_QTQUICK_EXPORT OxideQQuickWebView : public QQuickItem { |
179 | void newViewRequested(OxideQNewViewRequest* request); |
180 | void geolocationPermissionRequested(const QJSValue& request); |
181 | Q_REVISION(4) void mediaAccessPermissionRequested(const QJSValue& request); |
182 | + Q_REVISION(9) void mouseLockPermissionRequested(const QJSValue& request); |
183 | Q_REVISION(6) void notificationPermissionRequested(const QJSValue& request); |
184 | void javaScriptConsoleMessage(LogMessageSeverityLevel level, |
185 | const QString& message, |
186 | diff --git a/qt/quick/api/oxideqquickwebview_p.h b/qt/quick/api/oxideqquickwebview_p.h |
187 | index cddc57d..5c39dba 100644 |
188 | --- a/qt/quick/api/oxideqquickwebview_p.h |
189 | +++ b/qt/quick/api/oxideqquickwebview_p.h |
190 | @@ -119,6 +119,8 @@ class OxideQQuickWebViewPrivate : public oxide::qt::WebViewProxyClient { |
191 | OxideQGeolocationPermissionRequest* request) override; |
192 | void RequestMediaAccessPermission( |
193 | OxideQMediaAccessPermissionRequest* request) override; |
194 | + void RequestMouseLockPermission( |
195 | + std::unique_ptr<OxideQPermissionRequest> request) override; |
196 | void RequestNotificationPermission( |
197 | OxideQPermissionRequest* request) override; |
198 | void FrameMetadataUpdated( |
199 | diff --git a/qt/quick/oxide_qquick_before_unload_dialog.cc b/qt/quick/oxide_qquick_before_unload_dialog.cc |
200 | index 05cc6c3..91d2af6 100644 |
201 | --- a/qt/quick/oxide_qquick_before_unload_dialog.cc |
202 | +++ b/qt/quick/oxide_qquick_before_unload_dialog.cc |
203 | @@ -54,6 +54,7 @@ QString BeforeUnloadDialogContext::message() const { |
204 | "BeforeUnloadDialogContext::message is deprecated and the message text " |
205 | "provided by the web page is ignored. This API returns a message for " |
206 | "compatibility purposes, but applications should stop using it"; |
207 | + |
208 | return QString( |
209 | dgettext(OXIDE_GETTEXT_DOMAIN, "Changes you made may not be saved.")); |
210 | } |
211 | diff --git a/qt/quick/oxide_qquick_contents_view.cc b/qt/quick/oxide_qquick_contents_view.cc |
212 | index 0df4f95..d6c0027 100644 |
213 | --- a/qt/quick/oxide_qquick_contents_view.cc |
214 | +++ b/qt/quick/oxide_qquick_contents_view.cc |
215 | @@ -519,5 +519,9 @@ void ContentsView::hideTouchSelectionController() const { |
216 | proxy()->hideTouchSelectionController(); |
217 | } |
218 | |
219 | +void ContentsView::GrabMouse(bool grab) const { |
220 | + grab ? item_->grabMouse() : item_->ungrabMouse(); |
221 | +} |
222 | + |
223 | } // namespace qquick |
224 | } // namespace oxide |
225 | diff --git a/qt/quick/oxide_qquick_contents_view.h b/qt/quick/oxide_qquick_contents_view.h |
226 | index 1797eb2..5e040be 100644 |
227 | --- a/qt/quick/oxide_qquick_contents_view.h |
228 | +++ b/qt/quick/oxide_qquick_contents_view.h |
229 | @@ -101,6 +101,7 @@ class ContentsView : public QObject, |
230 | } |
231 | |
232 | void hideTouchSelectionController() const; |
233 | + void GrabMouse(bool grab) const; |
234 | |
235 | private Q_SLOTS: |
236 | void windowChanged(QQuickWindow* window); |
237 | diff --git a/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.html b/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.html |
238 | new file mode 100644 |
239 | index 0000000..a83c233 |
240 | --- /dev/null |
241 | +++ b/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.html |
242 | @@ -0,0 +1,43 @@ |
243 | +<html> |
244 | +<body> |
245 | +<button id="button" onclick="requestMouseLock()">Click Here</button> |
246 | +<canvas height=100 width=100> </canvas> |
247 | +</body> |
248 | +<script> |
249 | +var canvas = document.querySelector('canvas'); |
250 | +var ctx = canvas.getContext('2d'); |
251 | +ctx.fillStyle = "#FF0000"; |
252 | +ctx.fillRect(0,0,100,100); |
253 | + |
254 | +canvas.requestPointerLock = canvas.requestPointerLock || |
255 | + canvas.mozRequestPointerLock; |
256 | + |
257 | +document.addEventListener('pointerlockchange', lockChanged, false); |
258 | +document.addEventListener('pointerlockerror', lockChangeError, false); |
259 | +document.addEventListener('keydown', exitLock, false); |
260 | + |
261 | +document.exitPointerLock = document.exitPointerLock || document.mozExitPointerLock; |
262 | + |
263 | +function exitLock(event) { |
264 | + if (event.keyCode = 27 /* ESC */) |
265 | + document.exitPointerLock(); |
266 | +} |
267 | + |
268 | +function requestMouseLock() { |
269 | + canvas.requestPointerLock(); |
270 | +} |
271 | + |
272 | +function lockChanged(event) { |
273 | + console.log("lockchanged"); |
274 | + var e = new CustomEvent("oxidemouselockresult", { bubbles: true, detail: { status: 1 } }); |
275 | + document.documentElement.dispatchEvent(e); |
276 | +} |
277 | + |
278 | +function lockChangeError() { |
279 | + console.log("lockerror"); |
280 | + var e = new CustomEvent("oxidemouselockresult", { bubbles: true, detail: { status: 0 } }); |
281 | + document.documentElement.dispatchEvent(e); |
282 | +} |
283 | + |
284 | +</script> |
285 | +</html> |
286 | diff --git a/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.qml b/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.qml |
287 | new file mode 100644 |
288 | index 0000000..23303de |
289 | --- /dev/null |
290 | +++ b/qt/tests/qmltests/api/tst_MouseLockPermissionRequest.qml |
291 | @@ -0,0 +1,103 @@ |
292 | +import QtQuick 2.0 |
293 | +import QtTest 1.0 |
294 | +import com.canonical.Oxide 1.15 |
295 | +import Oxide.testsupport 1.0 |
296 | + |
297 | +TestWebView { |
298 | + id: webView |
299 | + width: 400 |
300 | + height: 400 |
301 | + |
302 | + property var lastMouseLockRequest: null |
303 | + |
304 | + SignalSpy { |
305 | + id: spy |
306 | + target: webView |
307 | + signalName: "mouseLockPermissionRequested" |
308 | + } |
309 | + |
310 | + SignalSpy { |
311 | + id: cancelSpy |
312 | + signalName: "cancelled" |
313 | + } |
314 | + |
315 | + onMouseLockPermissionRequested: { |
316 | + lastMouseLockRequest = request; |
317 | + } |
318 | + |
319 | + property var lastMouseLockStatus: -1 |
320 | + |
321 | + messageHandlers: [ |
322 | + ScriptMessageHandler { |
323 | + msgId: "MOUSELOCK-RESPONSE" |
324 | + contexts: [ "oxide://testutils/" ] |
325 | + callback: function(msg) { |
326 | + webView.lastMouseLockStatus = msg.payload; |
327 | + } |
328 | + } |
329 | + ] |
330 | + |
331 | + TestCase { |
332 | + id: test |
333 | + name: "MouseLockPermissionRequest" |
334 | + when: windowShown |
335 | + |
336 | + function init() { |
337 | + spy.clear(); |
338 | + cancelSpy.clear(); |
339 | + webView.lastMouseLockRequest = null; |
340 | + webView.lastMouseLockStatus = -1; |
341 | + } |
342 | + |
343 | + function _test_allow() { |
344 | + webView.lastMouseLockRequest.allow(); |
345 | + } |
346 | + |
347 | + function _test_accept() { |
348 | + webView.lastMouseLockRequest.accept(); |
349 | + } |
350 | + |
351 | + function _test_deny() { |
352 | + webView.lastMouseLockRequest.deny(); |
353 | + } |
354 | + |
355 | + function _test_destroy() { |
356 | + webView.lastMouseLockRequest.destroy(); |
357 | + } |
358 | + |
359 | + function test_MouseLockPermissionRequest1_main_frame_data() { |
360 | + return [ |
361 | + { function: _test_allow, expected: 1 }, |
362 | + { function: _test_deny, expected: 0 }, |
363 | + ]; |
364 | + } |
365 | + |
366 | + function test_MouseLockPermissionRequest1_main_frame(data) { |
367 | + webView.url = "https://testsuite/tst_MouseLockPermissionRequest.html"; |
368 | + verify(webView.waitForLoadSucceeded(), |
369 | + "Timed out waiting for successful load"); |
370 | + |
371 | + webView.getTestApi().evaluateCode( |
372 | +"document.addEventListener(\"oxidemouselockresult\", function(event) { |
373 | + oxide.sendMessage(\"MOUSELOCK-RESPONSE\", event.detail.status); |
374 | +});", true); |
375 | + |
376 | + var r = webView.getTestApi().getBoundingClientRectForSelector("#button"); |
377 | + mouseClick(webView, r.x + r.width / 2, r.y + r.height / 2, Qt.LeftButton, Qt.NoModifier); |
378 | + |
379 | + if (!webView.lastMouseLockRequest) { |
380 | + spy.wait(); |
381 | + } |
382 | + |
383 | + compare(webView.lastMouseLockRequest.origin, "https://testsuite/"); |
384 | + compare(webView.lastMouseLockRequest.embedder, "https://testsuite/"); |
385 | + compare(webView.lastMouseLockRequest.isCancelled, false); |
386 | + |
387 | + data.function(); |
388 | + |
389 | + verify(TestUtils.waitFor(function() { return webView.lastMouseLockStatus != -1; }), |
390 | + "Timed out waiting for mouseLock response"); |
391 | + compare(webView.lastMouseLockStatus, data.expected); |
392 | + } |
393 | +} |
394 | +} |
395 | diff --git a/shared/browser/oxide_render_widget_host_view.cc b/shared/browser/oxide_render_widget_host_view.cc |
396 | index efef1ca..8c9b5d0 100644 |
397 | --- a/shared/browser/oxide_render_widget_host_view.cc |
398 | +++ b/shared/browser/oxide_render_widget_host_view.cc |
399 | @@ -57,6 +57,7 @@ |
400 | #include "oxide_browser_platform_integration.h" |
401 | #include "oxide_browser_process_main.h" |
402 | #include "oxide_event_utils.h" |
403 | +#include "oxide_screen_client.h" |
404 | #include "oxide_render_widget_host_view_container.h" |
405 | |
406 | namespace oxide { |
407 | @@ -500,11 +501,32 @@ gfx::Rect RenderWidgetHostView::GetViewBounds() const { |
408 | return bounds; |
409 | } |
410 | |
411 | + |
412 | +bool RenderWidgetHostView::IsMouseLocked() { |
413 | + return mouse_locked_; |
414 | +} |
415 | + |
416 | bool RenderWidgetHostView::LockMouse() { |
417 | - return false; |
418 | + ScreenClient* screen_client = BrowserPlatformIntegration::GetInstance()-> |
419 | + GetScreenClient(); |
420 | + if(screen_client) { |
421 | + screen_client->HideMousePointer(); |
422 | + } |
423 | + container_->GrabMouse(true); |
424 | + mouse_locked_ = true; |
425 | + return true; |
426 | } |
427 | |
428 | -void RenderWidgetHostView::UnlockMouse() {} |
429 | +void RenderWidgetHostView::UnlockMouse() { |
430 | + ScreenClient* screen_client = BrowserPlatformIntegration::GetInstance()-> |
431 | + GetScreenClient(); |
432 | + if(screen_client) { |
433 | + screen_client->ShowMousePointer(); |
434 | + } |
435 | + container_->GrabMouse(false); |
436 | + host_->LostMouseLock(); |
437 | + mouse_locked_= false; |
438 | +} |
439 | |
440 | void RenderWidgetHostView::CompositorDidCommit() { |
441 | committed_frame_metadata_ = last_submitted_frame_metadata_; |
442 | @@ -806,6 +828,7 @@ RenderWidgetHostView::RenderWidgetHostView( |
443 | top_controls_shrink_blink_size_(false), |
444 | gesture_provider_(GestureProvider::Create(this)), |
445 | handle_drag_in_progress_(false), |
446 | + mouse_locked_(false), |
447 | weak_ptr_factory_(this) { |
448 | CHECK(host_) << "Implementation didn't supply a RenderWidgetHost"; |
449 | |
450 | diff --git a/shared/browser/oxide_render_widget_host_view.h b/shared/browser/oxide_render_widget_host_view.h |
451 | index 7607dde..2f9a0ee 100644 |
452 | --- a/shared/browser/oxide_render_widget_host_view.h |
453 | +++ b/shared/browser/oxide_render_widget_host_view.h |
454 | @@ -174,6 +174,7 @@ class RenderWidgetHostView |
455 | bool IsSurfaceAvailableForCopy() const override; |
456 | bool IsShowing() override; |
457 | gfx::Rect GetViewBounds() const override; |
458 | + bool IsMouseLocked() override; |
459 | bool LockMouse() override; |
460 | void UnlockMouse() override; |
461 | |
462 | @@ -250,6 +251,8 @@ class RenderWidgetHostView |
463 | std::unique_ptr<ui::TouchSelectionController> selection_controller_; |
464 | bool handle_drag_in_progress_; |
465 | |
466 | + bool mouse_locked_; |
467 | + |
468 | base::WeakPtrFactory<RenderWidgetHostView> weak_ptr_factory_; |
469 | |
470 | DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostView); |
471 | diff --git a/shared/browser/oxide_render_widget_host_view_container.h b/shared/browser/oxide_render_widget_host_view_container.h |
472 | index 9c15472..6ef83eb 100644 |
473 | --- a/shared/browser/oxide_render_widget_host_view_container.h |
474 | +++ b/shared/browser/oxide_render_widget_host_view_container.h |
475 | @@ -75,6 +75,8 @@ class RenderWidgetHostViewContainer { |
476 | bool insertion_handle_tapped) const = 0; |
477 | |
478 | virtual void EditingCapabilitiesChanged(RenderWidgetHostView* view) = 0; |
479 | + |
480 | + virtual void GrabMouse(bool grab) const = 0; |
481 | }; |
482 | |
483 | } // namespace oxide |
484 | diff --git a/shared/browser/oxide_screen_client.h b/shared/browser/oxide_screen_client.h |
485 | index 91133ed..e270c9b 100644 |
486 | --- a/shared/browser/oxide_screen_client.h |
487 | +++ b/shared/browser/oxide_screen_client.h |
488 | @@ -30,6 +30,9 @@ class ScreenClient { |
489 | virtual display::Display GetPrimaryDisplay() = 0; |
490 | |
491 | virtual gfx::Point GetCursorScreenPoint() = 0; |
492 | + |
493 | + virtual void HideMousePointer() = 0; |
494 | + virtual void ShowMousePointer() = 0; |
495 | }; |
496 | |
497 | } // namespace oxide |
498 | diff --git a/shared/browser/oxide_web_contents_view.cc b/shared/browser/oxide_web_contents_view.cc |
499 | index 2544bf3..c7a7c5c 100644 |
500 | --- a/shared/browser/oxide_web_contents_view.cc |
501 | +++ b/shared/browser/oxide_web_contents_view.cc |
502 | @@ -1052,4 +1052,8 @@ void WebContentsView::HideTouchSelectionController() { |
503 | } |
504 | } |
505 | |
506 | +void WebContentsView::GrabMouse(bool grab) const { |
507 | + client_->GrabMouse(grab); |
508 | +} |
509 | + |
510 | } // namespace oxide |
511 | diff --git a/shared/browser/oxide_web_contents_view.h b/shared/browser/oxide_web_contents_view.h |
512 | index 8de5702..6554118 100644 |
513 | --- a/shared/browser/oxide_web_contents_view.h |
514 | +++ b/shared/browser/oxide_web_contents_view.h |
515 | @@ -245,6 +245,8 @@ class OXIDE_SHARED_EXPORT WebContentsView |
516 | bool insertion_handle_tapped) const override; |
517 | void EditingCapabilitiesChanged(RenderWidgetHostView* view) override; |
518 | |
519 | + void GrabMouse(bool grab) const override; |
520 | + |
521 | WebContentsViewClient* client_; |
522 | base::Closure editing_capabilities_changed_callback_; |
523 | |
524 | diff --git a/shared/browser/oxide_web_contents_view_client.cc b/shared/browser/oxide_web_contents_view_client.cc |
525 | index 8334d18..a1b16ff 100644 |
526 | --- a/shared/browser/oxide_web_contents_view_client.cc |
527 | +++ b/shared/browser/oxide_web_contents_view_client.cc |
528 | @@ -70,4 +70,7 @@ InputMethodContext* WebContentsViewClient::GetInputMethodContext() const { |
529 | void WebContentsViewClient::UnhandledKeyboardEvent( |
530 | const content::NativeWebKeyboardEvent& event) {} |
531 | |
532 | +void WebContentsViewClient::GrabMouse(bool grab) const { |
533 | +} |
534 | + |
535 | } // namespace oxide |
536 | diff --git a/shared/browser/oxide_web_contents_view_client.h b/shared/browser/oxide_web_contents_view_client.h |
537 | index c2ccaa7..34e6a1d 100644 |
538 | --- a/shared/browser/oxide_web_contents_view_client.h |
539 | +++ b/shared/browser/oxide_web_contents_view_client.h |
540 | @@ -91,6 +91,7 @@ class OXIDE_SHARED_EXPORT WebContentsViewClient { |
541 | |
542 | virtual void UnhandledKeyboardEvent( |
543 | const content::NativeWebKeyboardEvent& event); |
544 | + virtual void GrabMouse(bool grab) const; |
545 | |
546 | protected: |
547 | WebContentsViewClient(); |
548 | diff --git a/shared/browser/oxide_web_view.cc b/shared/browser/oxide_web_view.cc |
549 | index 625c1e0..1999c7d 100644 |
550 | --- a/shared/browser/oxide_web_view.cc |
551 | +++ b/shared/browser/oxide_web_view.cc |
552 | @@ -801,6 +801,27 @@ bool WebView::CheckMediaAccessPermission(content::WebContents* source, |
553 | return status == TEMPORARY_SAVED_PERMISSION_STATUS_ALLOWED; |
554 | } |
555 | |
556 | +void WebView::RespondToLockMouse(content::WebContents* web_contents, |
557 | + PermissionRequestResponse response) { |
558 | + DCHECK(web_contents_.get() == web_contents); |
559 | + if (response == PERMISSION_REQUEST_RESPONSE_ALLOW) { |
560 | + web_contents_->GotResponseToLockMouseRequest(true); |
561 | + } else { |
562 | + web_contents_->GotResponseToLockMouseRequest(false); |
563 | + } |
564 | +} |
565 | + |
566 | +void WebView::RequestToLockMouse(content::WebContents* web_contents, |
567 | + bool user_gesture, bool last_unlocked_by_target) { |
568 | + content::RenderFrameHost* rfh = web_contents->GetMainFrame(); |
569 | + PermissionRequestDispatcher::FromWebContents(web_contents)-> |
570 | + RequestMouseLockPermission(rfh, rfh->GetLastCommittedURL().GetOrigin(), |
571 | + user_gesture, last_unlocked_by_target, |
572 | + base::Bind(&WebView::RespondToLockMouse, |
573 | + weak_factory_.GetWeakPtr(), |
574 | + web_contents)); |
575 | +} |
576 | + |
577 | void WebView::RenderFrameForInterstitialPageCreated( |
578 | content::RenderFrameHost* render_frame_host) { |
579 | if (render_frame_host->GetParent()) { |
580 | diff --git a/shared/browser/oxide_web_view.h b/shared/browser/oxide_web_view.h |
581 | index 951670b..f0a99ca 100644 |
582 | --- a/shared/browser/oxide_web_view.h |
583 | +++ b/shared/browser/oxide_web_view.h |
584 | @@ -46,6 +46,7 @@ |
585 | #include "shared/browser/oxide_render_object_id.h" |
586 | #include "shared/browser/oxide_script_message_target.h" |
587 | #include "shared/browser/oxide_web_preferences_observer.h" |
588 | +#include "shared/browser/permissions/oxide_permission_request_response.h" |
589 | #include "shared/common/oxide_message_enums.h" |
590 | #include "shared/common/oxide_shared_export.h" |
591 | |
592 | @@ -283,6 +284,10 @@ class OXIDE_SHARED_EXPORT WebView : public ScriptMessageTarget, |
593 | |
594 | void EditingCapabilitiesChanged(); |
595 | |
596 | + // callback for pointer lock permission request |
597 | + void RespondToLockMouse(content::WebContents* web_contents, |
598 | + PermissionRequestResponse response); |
599 | + |
600 | // ScriptMessageTarget implementation |
601 | virtual size_t GetScriptMessageHandlerCount() const override; |
602 | virtual const ScriptMessageHandler* GetScriptMessageHandlerAt( |
603 | @@ -369,6 +374,13 @@ class OXIDE_SHARED_EXPORT WebView : public ScriptMessageTarget, |
604 | const GURL& security_origin, |
605 | content::MediaStreamType type) override; |
606 | |
607 | + void RequestToLockMouse(content::WebContents* web_contents, |
608 | + bool user_gesture, |
609 | + bool last_unlocked_by_target) final; |
610 | + |
611 | + // Notification that the page has lost the mouse lock. |
612 | + //void LostMouseLock() final; |
613 | + |
614 | // content::WebContentsObserver implementation |
615 | void RenderFrameForInterstitialPageCreated( |
616 | content::RenderFrameHost* render_frame_host) override; |
617 | diff --git a/shared/browser/permissions/oxide_permission_request_dispatcher.cc b/shared/browser/permissions/oxide_permission_request_dispatcher.cc |
618 | index 0e605ad..353e698 100644 |
619 | --- a/shared/browser/permissions/oxide_permission_request_dispatcher.cc |
620 | +++ b/shared/browser/permissions/oxide_permission_request_dispatcher.cc |
621 | @@ -230,6 +230,32 @@ void PermissionRequestDispatcher::CancelPermissionRequest(int request_id) { |
622 | } |
623 | } |
624 | |
625 | +int PermissionRequestDispatcher::RequestMouseLockPermission( |
626 | + content::RenderFrameHost* render_frame_host, |
627 | + const GURL& requesting_origin, |
628 | + bool, bool, |
629 | + const PermissionRequestCallback& callback) { |
630 | + |
631 | + if (!CanDispatchRequest()) { |
632 | + callback.Run(PERMISSION_REQUEST_RESPONSE_CANCEL); |
633 | + return -1; |
634 | + } |
635 | + |
636 | + int request_id = next_request_id_++; |
637 | + |
638 | + std::unique_ptr<PermissionRequest> request( |
639 | + new PermissionRequest( |
640 | + request_id, |
641 | + RenderFrameHostID(), |
642 | + requesting_origin, |
643 | + web_contents()->GetLastCommittedURL().GetOrigin(), |
644 | + callback)); |
645 | + AddPendingRequest(request.get()); |
646 | + |
647 | + client_->RequestMouseLockPermission(std::move(request)); |
648 | + return request_id; |
649 | +} |
650 | + |
651 | int PermissionRequestDispatcher::RequestMediaAccessPermission( |
652 | content::RenderFrameHost* render_frame_host, |
653 | const GURL& requesting_origin, |
654 | diff --git a/shared/browser/permissions/oxide_permission_request_dispatcher.h b/shared/browser/permissions/oxide_permission_request_dispatcher.h |
655 | index d3be2ce..804aed5 100644 |
656 | --- a/shared/browser/permissions/oxide_permission_request_dispatcher.h |
657 | +++ b/shared/browser/permissions/oxide_permission_request_dispatcher.h |
658 | @@ -80,6 +80,13 @@ class OXIDE_SHARED_EXPORT PermissionRequestDispatcher |
659 | bool video, |
660 | const PermissionRequestCallback& callback); |
661 | |
662 | + // Request permission to lock mouse pointer |
663 | + int RequestMouseLockPermission(content::RenderFrameHost* render_frame_host, |
664 | + const GURL& requesting_origin, |
665 | + bool user_gesture, |
666 | + bool last_unlocked_by_target, |
667 | + const PermissionRequestCallback& callback); |
668 | + |
669 | private: |
670 | friend class content::WebContentsUserData<PermissionRequestDispatcher>; |
671 | friend class PermissionRequest; |
672 | diff --git a/shared/browser/permissions/oxide_permission_request_dispatcher_client.h b/shared/browser/permissions/oxide_permission_request_dispatcher_client.h |
673 | index c2d58f7..498f134 100644 |
674 | --- a/shared/browser/permissions/oxide_permission_request_dispatcher_client.h |
675 | +++ b/shared/browser/permissions/oxide_permission_request_dispatcher_client.h |
676 | @@ -39,6 +39,9 @@ class PermissionRequestDispatcherClient { |
677 | virtual void RequestMediaAccessPermission( |
678 | std::unique_ptr<MediaAccessPermissionRequest> request) {} |
679 | |
680 | + virtual void RequestMouseLockPermission( |
681 | + std::unique_ptr<PermissionRequest> request) {} |
682 | + |
683 | virtual void RequestNotificationPermission( |
684 | std::unique_ptr<PermissionRequest> request) {} |
685 | }; |
Not a complete review by any means, but I had a very quick look at the diff and added a few inline comments.