OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 #include "content/browser/pointer_lock_browsertest.h" | 5 #include "content/browser/pointer_lock_browsertest.h" |
6 | 6 |
7 #include "content/browser/renderer_host/render_widget_host_impl.h" | 7 #include "content/browser/renderer_host/render_widget_host_impl.h" |
8 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 8 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
9 #include "content/browser/web_contents/web_contents_view_mac.h" | 9 #include "content/browser/web_contents/web_contents_view_mac.h" |
10 | 10 |
11 namespace content { | 11 namespace content { |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 class MockRenderWidgetHostView : public RenderWidgetHostViewMac { | 15 class MockRenderWidgetHostView : public RenderWidgetHostViewMac { |
16 public: | 16 public: |
17 MockRenderWidgetHostView(RenderWidgetHost* host, bool is_guest_view_hack) | 17 MockRenderWidgetHostView(RenderWidgetHost* host, bool is_guest_view_hack) |
18 : RenderWidgetHostViewMac(host, is_guest_view_hack), | 18 : RenderWidgetHostViewMac(host, is_guest_view_hack) {} |
19 host_(RenderWidgetHostImpl::From(host)) {} | |
20 ~MockRenderWidgetHostView() override { | 19 ~MockRenderWidgetHostView() override { |
21 if (mouse_locked_) | 20 if (mouse_locked_) |
22 UnlockMouse(); | 21 UnlockMouse(); |
23 } | 22 } |
24 | 23 |
25 bool LockMouse() override { | 24 bool LockMouse() override { |
26 mouse_locked_ = true; | 25 mouse_locked_ = true; |
27 | 26 |
28 return true; | 27 return true; |
29 } | 28 } |
30 | 29 |
31 void UnlockMouse() override { | 30 void UnlockMouse() override { |
32 host_->LostMouseLock(); | 31 if (RenderWidgetHostImpl* host = |
| 32 RenderWidgetHostImpl::From(GetRenderWidgetHost())) { |
| 33 host->LostMouseLock(); |
| 34 } |
33 mouse_locked_ = false; | 35 mouse_locked_ = false; |
34 } | 36 } |
35 | 37 |
36 bool IsMouseLocked() override { return mouse_locked_; } | 38 bool IsMouseLocked() override { return mouse_locked_; } |
37 | 39 |
38 bool HasFocus() const override { return true; } | 40 bool HasFocus() const override { return true; } |
39 | |
40 RenderWidgetHostImpl* host_; | |
41 }; | 41 }; |
42 | 42 |
43 } // namespace | 43 } // namespace |
44 | 44 |
45 void InstallCreateHooksForPointerLockBrowserTests() { | 45 void InstallCreateHooksForPointerLockBrowserTests() { |
46 WebContentsViewMac::InstallCreateHookForTests( | 46 WebContentsViewMac::InstallCreateHookForTests( |
47 [](RenderWidgetHost* host, | 47 [](RenderWidgetHost* host, |
48 bool is_guest_view_hack) -> RenderWidgetHostViewMac* { | 48 bool is_guest_view_hack) -> RenderWidgetHostViewMac* { |
49 return new MockRenderWidgetHostView(host, is_guest_view_hack); | 49 return new MockRenderWidgetHostView(host, is_guest_view_hack); |
50 }); | 50 }); |
51 } | 51 } |
52 | 52 |
53 } // namespace content | 53 } // namespace content |
OLD | NEW |