Commit a40f5522 authored by sail@chromium.org's avatar sail@chromium.org

Fix constrained window position for inactive tab

If a constrained window was added to an inactive tab it would be incorrectly positioned.

The problem was that an inactive tab view is removed from the browser window. This meant that the constrained window position coudln't be calculated.

When the tab became activated again we weren't updating the sheet position.

This CL changes the code to correclty update the sheet position when the tab is activated.

BUG=163841
TEST=Verified that the bug can no longer be reproduced. Verified that ConstrainedWindowSheetControllerTest.AddToInactiveTab failed without my change and passes with it.


Review URL: https://chromiumcodereview.appspot.com/11416309

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@170782 0039d316-1c4b-4281-b951-d872f2087c98
parent a1560fd8
...@@ -182,6 +182,7 @@ NSValue* GetKeyForParentWindow(NSWindow* parent_window) { ...@@ -182,6 +182,7 @@ NSValue* GetKeyForParentWindow(NSWindow* parent_window) {
- (void)parentViewDidBecomeActive:(NSView*)parentView { - (void)parentViewDidBecomeActive:(NSView*)parentView {
[[self findSheetInfoForParentView:activeView_] hideSheet]; [[self findSheetInfoForParentView:activeView_] hideSheet];
activeView_.reset([parentView retain]); activeView_.reset([parentView retain]);
[self updateSheetPosition:parentView];
[[self findSheetInfoForParentView:activeView_] showSheet]; [[self findSheetInfoForParentView:activeView_] showSheet];
} }
...@@ -236,15 +237,18 @@ NSValue* GetKeyForParentWindow(NSWindow* parent_window) { ...@@ -236,15 +237,18 @@ NSValue* GetKeyForParentWindow(NSWindow* parent_window) {
} }
- (void)onParentViewFrameDidChange:(NSNotification*)note { - (void)onParentViewFrameDidChange:(NSNotification*)note {
[self updateSheetPosition:[note object]]; NSView* parentView = [note object];
if (![activeView_ isEqual:parentView])
return;
[self updateSheetPosition:parentView];
} }
- (void)updateSheetPosition:(NSView*)parentView { - (void)updateSheetPosition:(NSView*)parentView {
if (![activeView_ isEqual:parentView])
return;
ConstrainedWindowSheetInfo* info = ConstrainedWindowSheetInfo* info =
[self findSheetInfoForParentView:parentView]; [self findSheetInfoForParentView:parentView];
DCHECK(info); if (!info)
return;
NSRect rect = [self overlayWindowFrameForParentView:parentView]; NSRect rect = [self overlayWindowFrameForParentView:parentView];
[[info overlayWindow] setFrame:rect display:YES]; [[info overlayWindow] setFrame:rect display:YES];
NSPoint origin = [self originForSheetSize:[[info sheet] frame].size NSPoint origin = [self originForSheetSize:[[info sheet] frame].size
......
...@@ -66,6 +66,13 @@ class ConstrainedWindowSheetControllerTest : public CocoaTest { ...@@ -66,6 +66,13 @@ class ConstrainedWindowSheetControllerTest : public CocoaTest {
return rect; return rect;
} }
void VerifySheetXPosition(NSRect sheet_frame, NSView* parent_view) {
NSRect parent_frame = GetViewFrameInScreenCoordinates(parent_view);
CGFloat expected_x = NSMinX(parent_frame) +
(NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
EXPECT_EQ(expected_x, NSMinX(sheet_frame));
}
scoped_nsobject<NSWindow> sheet_; scoped_nsobject<NSWindow> sheet_;
scoped_nsobject<ConstrainedWindowSheetController> controller_; scoped_nsobject<ConstrainedWindowSheetController> controller_;
scoped_nsobject<NSMutableArray> tab_views_; scoped_nsobject<NSMutableArray> tab_views_;
...@@ -108,6 +115,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, AddToInactiveTab) { ...@@ -108,6 +115,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, AddToInactiveTab) {
ActivateTabView(tab1_); ActivateTabView(tab1_);
EXPECT_EQ(1.0, [sheet_ alphaValue]); EXPECT_EQ(1.0, [sheet_ alphaValue]);
VerifySheetXPosition([sheet_ frame], tab1_);
} }
// Test that two parent windows with two sheet controllers don't conflict. // Test that two parent windows with two sheet controllers don't conflict.
...@@ -141,12 +149,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, TopLevelView) { ...@@ -141,12 +149,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, TopLevelView) {
[controller_ showSheet:sheet_ forParentView:parentView]; [controller_ showSheet:sheet_ forParentView:parentView];
EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]); EXPECT_TRUE([ConstrainedWindowSheetController controllerForSheet:sheet_]);
EXPECT_TRUE([sheet_ isVisible]); EXPECT_TRUE([sheet_ isVisible]);
VerifySheetXPosition([sheet_ frame], parentView);
NSRect parent_frame = GetViewFrameInScreenCoordinates(parentView);
NSRect sheet_frame = [sheet_ frame];
CGFloat expected_x = NSMinX(parent_frame) +
(NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
EXPECT_EQ(expected_x, NSMinX(sheet_frame));
} }
// Test that resizing sheet works. // Test that resizing sheet works.
...@@ -165,10 +168,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, Resize) { ...@@ -165,10 +168,7 @@ TEST_F(ConstrainedWindowSheetControllerTest, Resize) {
EXPECT_EQ(NSMaxY(sheet_frame), NSMaxY(old_frame)); EXPECT_EQ(NSMaxY(sheet_frame), NSMaxY(old_frame));
// X pos should be centered on parent view. // X pos should be centered on parent view.
NSRect parent_frame = GetViewFrameInScreenCoordinates(active_tab_view_); VerifySheetXPosition(sheet_frame, active_tab_view_);
CGFloat expected_x = NSMinX(parent_frame) +
(NSWidth(parent_frame) - NSWidth(sheet_frame)) / 2.0;
EXPECT_EQ(expected_x, NSMinX(sheet_frame));
} }
// Test that resizing a hidden sheet works. // Test that resizing a hidden sheet works.
...@@ -186,5 +186,6 @@ TEST_F(ConstrainedWindowSheetControllerTest, ResizeHiddenSheet) { ...@@ -186,5 +186,6 @@ TEST_F(ConstrainedWindowSheetControllerTest, ResizeHiddenSheet) {
EXPECT_EQ(1.0, [sheet_ alphaValue]); EXPECT_EQ(1.0, [sheet_ alphaValue]);
NSRect new_active_frame = [sheet_ frame]; NSRect new_active_frame = [sheet_ frame];
EXPECT_TRUE(NSEqualRects(new_inactive_frame, new_active_frame)); EXPECT_EQ(NSWidth(new_inactive_frame), NSWidth(new_active_frame));
EXPECT_EQ(NSHeight(new_inactive_frame), NSHeight(new_active_frame));
} }
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