Commit b15a757d authored by Ella Ge's avatar Ella Ge Committed by Commit Bot

RWHV should use IsMouseLocked istead of mouse_locked_

RenderWidgetHostViewAura should use IsMouseLocked instead of
mouse_locked_ because the locked state is stored in RWHV_event_handler.

Remove mouse_locked_ from the base class to prevent misuse.

Bug: 812964
Change-Id: I5201c7b6d77d1e52f9da2344899b6ab293e44f86
Reviewed-on: https://chromium-review.googlesource.com/1102911Reviewed-by: default avatarAntoine Labour <piman@chromium.org>
Reviewed-by: default avatarNavid Zolghadr <nzolghadr@chromium.org>
Reviewed-by: default avatarSadrul Chowdhury <sadrul@chromium.org>
Commit-Queue: Ella Ge <eirage@chromium.org>
Cr-Commit-Position: refs/heads/master@{#570072}
parent bb9ca87d
......@@ -26,32 +26,45 @@
namespace content {
namespace {
class MockPointerLockWebContentsDelegate : public WebContentsDelegate {
public:
MockPointerLockWebContentsDelegate() {}
~MockPointerLockWebContentsDelegate() override {}
void RequestToLockMouse(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) override {
web_contents->GotResponseToLockMouseRequest(true);
}
void LostMouseLock() override {}
};
#ifdef USE_AURA
class MockRenderWidgetHostView : public RenderWidgetHostViewAura {
class MockPointerLockRenderWidgetHostView : public RenderWidgetHostViewAura {
public:
MockRenderWidgetHostView(RenderWidgetHost* host, bool is_guest_view_hack)
MockPointerLockRenderWidgetHostView(RenderWidgetHost* host,
bool is_guest_view_hack)
: RenderWidgetHostViewAura(host,
is_guest_view_hack,
false /* is_mus_browser_plugin_guest */),
host_(RenderWidgetHostImpl::From(host)) {}
~MockRenderWidgetHostView() override {
if (mouse_locked_)
~MockPointerLockRenderWidgetHostView() override {
if (IsMouseLocked())
UnlockMouse();
}
bool LockMouse() override {
mouse_locked_ = true;
event_handler()->mouse_locked_ = true;
return true;
}
void UnlockMouse() override {
host_->LostMouseLock();
mouse_locked_ = false;
event_handler()->mouse_locked_ = false;
}
bool IsMouseLocked() override { return mouse_locked_; }
bool IsMouseLocked() override { return event_handler()->mouse_locked(); }
bool HasFocus() const override { return true; }
......@@ -62,30 +75,13 @@ class MockRenderWidgetHostView : public RenderWidgetHostViewAura {
RenderWidgetHostImpl* host_;
};
#endif // USE_AURA
} // namespace
class MockPointerLockWebContentsDelegate : public WebContentsDelegate {
public:
MockPointerLockWebContentsDelegate() {}
~MockPointerLockWebContentsDelegate() override {}
void RequestToLockMouse(WebContents* web_contents,
bool user_gesture,
bool last_unlocked_by_target) override {
web_contents->GotResponseToLockMouseRequest(true);
}
void LostMouseLock() override {}
};
#ifdef USE_AURA
void InstallCreateHooksForPointerLockBrowserTests() {
WebContentsViewAura::InstallCreateHookForTests(
[](RenderWidgetHost* host,
bool is_guest_view_hack) -> RenderWidgetHostViewAura* {
return new MockRenderWidgetHostView(host, is_guest_view_hack);
return new MockPointerLockRenderWidgetHostView(host,
is_guest_view_hack);
});
}
#endif // USE_AURA
......
......@@ -10,13 +10,12 @@
namespace content {
namespace {
class MockRenderWidgetHostView : public RenderWidgetHostViewMac {
class MockPointerLockRenderWidgetHostView : public RenderWidgetHostViewMac {
public:
MockRenderWidgetHostView(RenderWidgetHost* host, bool is_guest_view_hack)
MockPointerLockRenderWidgetHostView(RenderWidgetHost* host,
bool is_guest_view_hack)
: RenderWidgetHostViewMac(host, is_guest_view_hack) {}
~MockRenderWidgetHostView() override {
~MockPointerLockRenderWidgetHostView() override {
if (mouse_locked_)
UnlockMouse();
}
......@@ -40,13 +39,12 @@ class MockRenderWidgetHostView : public RenderWidgetHostViewMac {
bool HasFocus() const override { return true; }
};
} // namespace
void InstallCreateHooksForPointerLockBrowserTests() {
WebContentsViewMac::InstallCreateHookForTests(
[](RenderWidgetHost* host,
bool is_guest_view_hack) -> RenderWidgetHostViewMac* {
return new MockRenderWidgetHostView(host, is_guest_view_hack);
return new MockPointerLockRenderWidgetHostView(host,
is_guest_view_hack);
});
}
......
......@@ -1506,7 +1506,7 @@ void RenderWidgetHostViewAura::OnBoundsChanged(const gfx::Rect& old_bounds,
}
gfx::NativeCursor RenderWidgetHostViewAura::GetCursor(const gfx::Point& point) {
if (mouse_locked_)
if (IsMouseLocked())
return ui::CursorType::kNone;
return current_cursor_.GetNativeCursor();
}
......@@ -2166,7 +2166,7 @@ void RenderWidgetHostViewAura::InternalSetBounds(const gfx::Rect& rect) {
#if defined(OS_WIN)
UpdateLegacyWin();
if (mouse_locked_)
if (IsMouseLocked())
UpdateMouseLockRegion();
#endif
}
......
......@@ -64,7 +64,7 @@ RenderWidgetHostViewBase::RenderWidgetHostViewBase(RenderWidgetHost* host)
RenderWidgetHostViewBase::~RenderWidgetHostViewBase() {
DCHECK(!keyboard_locked_);
DCHECK(!mouse_locked_);
DCHECK(!IsMouseLocked());
// We call this here to guarantee that observers are notified before we go
// away. However, some subclasses may wish to call this earlier in their
// shutdown process, e.g. to force removal from
......@@ -246,7 +246,7 @@ base::Optional<SkColor> RenderWidgetHostViewBase::GetBackgroundColor() const {
}
bool RenderWidgetHostViewBase::IsMouseLocked() {
return mouse_locked_;
return false;
}
bool RenderWidgetHostViewBase::LockKeyboard(
......
......@@ -621,13 +621,6 @@ class CONTENT_EXPORT RenderWidgetHostViewBase
// Indicates whether keyboard lock is active for this view.
bool keyboard_locked_ = false;
// While the mouse is locked, the cursor is hidden from the user. Mouse events
// are still generated. However, the position they report is the last known
// mouse position just as mouse lock was entered; the movement they report
// indicates what the change in position of the mouse would be had it not been
// locked.
bool mouse_locked_ = false;
// Indicates whether the scroll offset of the root layer is at top, i.e.,
// whether scroll_offset.y() == 0.
bool is_scroll_offset_at_top_ = true;
......
......@@ -179,6 +179,8 @@ class CONTENT_EXPORT RenderWidgetHostViewEventHandler
FRIEND_TEST_ALL_PREFIXES(
RenderWidgetHostViewAuraTest,
KeyEventRoutingKeyboardLockAndChildPopupWithoutInputGrab);
friend class MockPointerLockRenderWidgetHostView;
// Returns true if the |event| passed in can be forwarded to the renderer.
bool CanRendererHandleEvent(const ui::MouseEvent* event,
bool mouse_locked,
......
......@@ -106,6 +106,7 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
void WasUnOccluded() override;
void WasOccluded() override;
gfx::Rect GetViewBounds() const override;
bool IsMouseLocked() override;
void SetActive(bool active) override;
void ShowDefinitionForSelection() override;
void SpeakSelection() override;
......@@ -427,6 +428,7 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
private:
friend class RenderWidgetHostViewMacTest;
friend class MockPointerLockRenderWidgetHostView;
FRIEND_TEST_ALL_PREFIXES(RenderWidgetHostViewMacTest, GetPageTextForSpeech);
// Allocate a new FrameSinkId if this object is the platform view of a
......@@ -563,6 +565,13 @@ class CONTENT_EXPORT RenderWidgetHostViewMac
// Tracks whether keyboard lock is active.
bool is_keyboard_locked_ = false;
// While the mouse is locked, the cursor is hidden from the user. Mouse events
// are still generated. However, the position they report is the last known
// mouse position just as mouse lock was entered; the movement they report
// indicates what the change in position of the mouse would be had it not been
// locked.
bool mouse_locked_ = false;
// Latest capture sequence number which is incremented when the caller
// requests surfaces be synchronized via
// EnsureSurfaceSynchronizedForLayoutTest().
......
......@@ -431,6 +431,10 @@ gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const {
window_frame_in_screen_dip_.OffsetFromOrigin();
}
bool RenderWidgetHostViewMac::IsMouseLocked() {
return mouse_locked_;
}
void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) {
GetCursorManager()->UpdateCursor(this, cursor);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment