Commit 41a94267 authored by tapted's avatar tapted Committed by Commit bot

Mac: Give bubble windows an initial position before showing them.

Otherwise initialization that occurs offscreen can load incorrect screen
metric information. E.g. a RenderView will assume it is on the primary
display when loaded in a bubble, which results in it being created with
an incorrect scale factor in some screen setups.

This CL adds a call to -[BaseBubbleController setAnchorPosition] in the
non-NIB initializer to give the window a good estimate of the position
it will eventually be shown at.

BUG=324748

Review URL: https://codereview.chromium.org/573143002

Cr-Commit-Position: refs/heads/master@{#295625}
parent 66668ed3
...@@ -72,7 +72,6 @@ ...@@ -72,7 +72,6 @@
DCHECK(theWindow); DCHECK(theWindow);
if ((self = [super initWithWindow:theWindow])) { if ((self = [super initWithWindow:theWindow])) {
parentWindow_ = parentWindow; parentWindow_ = parentWindow;
anchor_ = anchoredAt;
shouldOpenAsKeyWindow_ = YES; shouldOpenAsKeyWindow_ = YES;
shouldCloseOnResignKey_ = YES; shouldCloseOnResignKey_ = YES;
...@@ -86,6 +85,7 @@ ...@@ -86,6 +85,7 @@
[self registerForNotifications]; [self registerForNotifications];
[self awakeFromNib]; [self awakeFromNib];
[self setAnchorPoint:anchoredAt];
} }
return self; return self;
} }
......
...@@ -232,6 +232,20 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignCenterArrow) { ...@@ -232,6 +232,20 @@ TEST_F(BaseBubbleControllerTest, AnchorAlignCenterArrow) {
EXPECT_GE(NSMaxY(frame), kAnchorPointY); EXPECT_GE(NSMaxY(frame), kAnchorPointY);
} }
// Test that the window is given an initial position before being shown. This
// ensures offscreen initialization is done using correct screen metrics.
TEST_F(BaseBubbleControllerTest, PositionedBeforeShow) {
// Verify default alignment settings, used when initialized in SetUp().
EXPECT_EQ(info_bubble::kTopRight, [[controller_ bubble] arrowLocation]);
EXPECT_EQ(info_bubble::kAlignArrowToAnchor, [[controller_ bubble] alignment]);
// Verify the default frame (positioned relative to the test_window() origin).
NSRect frame = [[controller_ window] frame];
EXPECT_EQ(NSMaxX(frame) - info_bubble::kBubbleArrowXOffset -
floorf(info_bubble::kBubbleArrowWidth / 2.0), kAnchorPointX);
EXPECT_EQ(NSMaxY(frame), kAnchorPointY);
}
// Tests that when a new window gets key state (and the bubble resigns) that // Tests that when a new window gets key state (and the bubble resigns) that
// the key window changes. // the key window changes.
TEST_F(BaseBubbleControllerTest, ResignKeyCloses) { TEST_F(BaseBubbleControllerTest, ResignKeyCloses) {
......
...@@ -403,6 +403,11 @@ class DevtoolsNotificationBridge : public content::NotificationObserver { ...@@ -403,6 +403,11 @@ class DevtoolsNotificationBridge : public content::NotificationObserver {
} }
- (void)onWindowChanged { - (void)onWindowChanged {
// The window is positioned before creating the host, to ensure the host is
// created with the correct screen information.
if (!host_)
return;
ExtensionViewMac* extensionView = ExtensionViewMac* extensionView =
static_cast<ExtensionViewMac*>(host_->view()); static_cast<ExtensionViewMac*>(host_->view());
// Let the extension view know, so that it can tell plugins. // Let the extension view know, so that it can tell plugins.
......
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