Commit 90099734 authored by shrike's avatar shrike Committed by Commit bot

Fix docked browser window sometimes appears onscreen after restart

(Continuing from original cl https://codereview.chromium.org/1055893003 .)

Change IsMaximized() to return false if the window is in the dock, and
a unit test to make sure this is always the case. It turns out
-isZoomed can sometimes return YES for a docked window, which
sometimes results in the window becoming undocked on the next restart.
Please read the long entry in the bug report for a complete explanation
of how the change fixes the problem.

BUG=452976

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

Cr-Commit-Position: refs/heads/master@{#324079}
parent fe8398d4
...@@ -363,7 +363,10 @@ gfx::Rect BrowserWindowCocoa::GetBounds() const { ...@@ -363,7 +363,10 @@ gfx::Rect BrowserWindowCocoa::GetBounds() const {
} }
bool BrowserWindowCocoa::IsMaximized() const { bool BrowserWindowCocoa::IsMaximized() const {
return [window() isZoomed]; // -isZoomed returns YES if the window's frame equals the rect returned by
// -windowWillUseStandardFrame:defaultFrame:, even if the window is in the
// dock, so have to explicitly check for miniaturization state first.
return ![window() isMiniaturized] && [window() isZoomed];
} }
bool BrowserWindowCocoa::IsMinimized() const { bool BrowserWindowCocoa::IsMinimized() const {
......
...@@ -48,6 +48,22 @@ TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) { ...@@ -48,6 +48,22 @@ TEST_F(BrowserWindowCocoaTest, TestBookmarkBarVisible) {
EXPECT_EQ(before, bwc->IsBookmarkBarVisible()); EXPECT_EQ(before, bwc->IsBookmarkBarVisible());
} }
// Test that IsMaximized() returns false when the browser window goes from
// maximized to minimized state - http://crbug/452976.
TEST_F(BrowserWindowCocoaTest, TestMinimizeState) {
scoped_ptr<BrowserWindowCocoa> bwc(
new BrowserWindowCocoa(browser(), controller_));
EXPECT_FALSE(bwc->IsMinimized());
bwc->Maximize();
EXPECT_TRUE(bwc->IsMaximized());
EXPECT_FALSE(bwc->IsMinimized());
bwc->Minimize();
EXPECT_FALSE(bwc->IsMaximized());
EXPECT_TRUE(bwc->IsMinimized());
bwc->Restore();
}
// Tests that BrowserWindowCocoa::Close mimics the behavior of // Tests that BrowserWindowCocoa::Close mimics the behavior of
// -[NSWindow performClose:]. // -[NSWindow performClose:].
class BrowserWindowCocoaCloseTest : public CocoaProfileTest { class BrowserWindowCocoaCloseTest : public CocoaProfileTest {
......
...@@ -727,6 +727,8 @@ using content::WebContents; ...@@ -727,6 +727,8 @@ using content::WebContents;
// browsers' behaviour, and is desirable in multi-tab situations. Note, however, // browsers' behaviour, and is desirable in multi-tab situations. Note, however,
// that the "toggle" behaviour means that the window can still be "unzoomed" to // that the "toggle" behaviour means that the window can still be "unzoomed" to
// the user size. // the user size.
// Note: this method is also called from -isZoomed. If the returned zoomed rect
// equals the current window's frame, -isZoomed returns YES.
- (NSRect)windowWillUseStandardFrame:(NSWindow*)window - (NSRect)windowWillUseStandardFrame:(NSWindow*)window
defaultFrame:(NSRect)frame { defaultFrame:(NSRect)frame {
// Forget that we grew the window up (if we in fact did). // Forget that we grew the window up (if we in fact did).
......
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