Fix pointerlock screen center position on secondary display
When lock cursor, we want to move the cursor to window center, to ensure that the cursor is inside window, but the center coordinates was wrong (need flip y). Adding the coordinate conversion to fix it. Bug: 956980 Change-Id: Ifc668fe8a4bfcd24630143d77c50986857b6a884 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1595658 Reviewed-by: Elly Fong-Jones <ellyjones@chromium.org> Commit-Queue: Ella Ge <eirage@chromium.org> Cr-Commit-Position: refs/heads/master@{#657357}
This commit is contained in:
content
app_shim_remote_cocoa
browser
renderer_host
@ -658,11 +658,10 @@ void ExtractUnderlines(NSAttributedString* string,
|
||||
mouse_locked_ = locked;
|
||||
if (mouse_locked_) {
|
||||
CGAssociateMouseAndMouseCursorPosition(NO);
|
||||
NSRect bound = [self bounds];
|
||||
bound = [[self window] convertRectToScreen:bound];
|
||||
NSRect bound = [[self window] convertRectToScreen:[self bounds]];
|
||||
gfx::Point screen_center = gfx::ScreenRectFromNSRect(bound).CenterPoint();
|
||||
mouse_locked_screen_position_ = last_mouse_screen_position_;
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(),
|
||||
NSMakePoint(NSMidX(bound), NSMidY(bound)));
|
||||
CGDisplayMoveCursorToPoint(CGMainDisplayID(), screen_center.ToCGPoint());
|
||||
[NSCursor hide];
|
||||
} else {
|
||||
// Unlock position of mouse cursor and unhide it.
|
||||
|
@ -63,6 +63,7 @@
|
||||
#include "ui/events/blink/blink_features.h"
|
||||
#include "ui/events/blink/web_input_event_traits.h"
|
||||
#include "ui/events/test/cocoa_test_event_utils.h"
|
||||
#include "ui/gfx/mac/coordinate_conversion.h"
|
||||
#include "ui/latency/latency_info.h"
|
||||
|
||||
using testing::_;
|
||||
@ -2283,4 +2284,21 @@ TEST_F(RenderWidgetHostViewMacTest, AccessibilityParentTest) {
|
||||
EXPECT_NSEQ([view accessibilityParent], parent_view);
|
||||
}
|
||||
|
||||
// Tests that when entering mouse lock, the cursor will lock to window center.
|
||||
TEST_F(RenderWidgetHostViewMacTest, PointerLockCenterPosition) {
|
||||
NSView* view = rwhv_mac_->cocoa_view();
|
||||
|
||||
NSRect bound = NSMakeRect(123, 234, 456, 678);
|
||||
[view setFrame:bound];
|
||||
|
||||
EXPECT_EQ(gfx::Rect([view bounds]), gfx::Rect(0, 0, 456, 678));
|
||||
|
||||
rwhv_mac_->LockMouse();
|
||||
EXPECT_TRUE(rwhv_mac_->IsMouseLocked());
|
||||
|
||||
gfx::Point mouse_pos =
|
||||
gfx::Point([window_ mouseLocationOutsideOfEventStream]);
|
||||
EXPECT_EQ(mouse_pos, gfx::Point(228, 339));
|
||||
}
|
||||
|
||||
} // namespace content
|
||||
|
Reference in New Issue
Block a user