diff options
author | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:02:29 +0000 |
---|---|---|
committer | levin@chromium.org <levin@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-14 22:02:29 +0000 |
commit | fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707 (patch) | |
tree | 77a6d41d45ec1f249f6493c94e1ad44be619a23f /views | |
parent | 221287ab0652cf72eea6ccb98f33b3505444df72 (diff) | |
download | chromium_src-fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707.zip chromium_src-fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707.tar.gz chromium_src-fd4aafc80ad6b4fc7dcbbe36dfec3b7e1bcbd707.tar.bz2 |
WidgetWin::SetBound on a maximized window leaves the window in the 'maximized' state.
Now when SetBounds is called, we detect the maximized state and take the window
out of this state.
BUG=69618
TEST=WidgetWinTest.SetBoundsForZoomedWindow (added)
Review URL: http://codereview.chromium.org/6268002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71499 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r-- | views/views.gyp | 3 | ||||
-rwxr-xr-x[-rw-r--r--] | views/widget/widget_win.cc | 4 | ||||
-rwxr-xr-x | views/widget/widget_win_unittest.cc | 81 |
3 files changed, 86 insertions, 2 deletions
diff --git a/views/views.gyp b/views/views.gyp index 191fc7d..7cbcfe0 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -1,4 +1,4 @@ -# Copyright (c) 2010 The Chromium Authors. All rights reserved. +# Copyright (c) 2011 The Chromium Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. @@ -440,6 +440,7 @@ 'run_all_unittests.cc', 'test/test_views_delegate.h', 'view_unittest.cc', + 'widget/widget_win_unittest.cc', '<(SHARED_INTERMEDIATE_DIR)/app/app_resources/app_resources.rc', ], diff --git a/views/widget/widget_win.cc b/views/widget/widget_win.cc index 8fab0ae..8bc3c2c 100644..100755 --- a/views/widget/widget_win.cc +++ b/views/widget/widget_win.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -239,6 +239,8 @@ void WidgetWin::GetBounds(gfx::Rect* out, bool including_frame) const { } void WidgetWin::SetBounds(const gfx::Rect& bounds) { + if (IsZoomed()) + ShowWindow(SW_SHOWNOACTIVATE); SetWindowPos(NULL, bounds.x(), bounds.y(), bounds.width(), bounds.height(), SWP_NOACTIVATE | SWP_NOZORDER); } diff --git a/views/widget/widget_win_unittest.cc b/views/widget/widget_win_unittest.cc new file mode 100755 index 0000000..28b4d9f --- /dev/null +++ b/views/widget/widget_win_unittest.cc @@ -0,0 +1,81 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/widget/widget_win.h" + +#include "base/basictypes.h" +#include "base/message_loop.h" +#include "base/scoped_ptr.h" +#include "testing/gtest/include/gtest/gtest.h" + +using namespace views; + +class WidgetWinTest : public testing::Test { + public: + WidgetWinTest() { + OleInitialize(NULL); + } + + ~WidgetWinTest() { + OleUninitialize(); + } + + virtual void TearDown() { + // Flush the message loop because we have pending release tasks + // and these tasks if un-executed would upset Valgrind. + RunPendingMessages(); + } + + // Create a simple widget win. The caller is responsible for taking ownership + // of the returned value. + WidgetWin* CreateWidgetWin(); + + void RunPendingMessages() { + message_loop_.RunAllPending(); + } + + private: + MessageLoopForUI message_loop_; + + DISALLOW_COPY_AND_ASSIGN(WidgetWinTest); +}; + + +WidgetWin* WidgetWinTest::CreateWidgetWin() { + scoped_ptr<WidgetWin> window(new WidgetWin()); + window->set_delete_on_destroy(false); + window->set_window_style(WS_OVERLAPPEDWINDOW); + window->Init(NULL, gfx::Rect(50, 50, 650, 650)); + return window.release(); +} + +TEST_F(WidgetWinTest, ZoomWindow) { + scoped_ptr<WidgetWin> window(CreateWidgetWin()); + window->ShowWindow(SW_HIDE); + EXPECT_FALSE(window->IsActive()); + window->ShowWindow(SW_MAXIMIZE); + EXPECT_TRUE(window->IsZoomed()); + window->CloseNow(); +} + +TEST_F(WidgetWinTest, SetBoundsForZoomedWindow) { + scoped_ptr<WidgetWin> window(CreateWidgetWin()); + window->ShowWindow(SW_MAXIMIZE); + EXPECT_TRUE(window->IsZoomed()); + + // Create another window, so that it will be active. + scoped_ptr<WidgetWin> window2(CreateWidgetWin()); + window2->ShowWindow(SW_MAXIMIZE); + EXPECT_TRUE(window2->IsActive()); + + // Verify that setting the bounds of a zoomed window will unzoom it and not + // cause it to be activated. + window->SetBounds(gfx::Rect(50, 50, 650, 650)); + EXPECT_FALSE(window->IsZoomed()); + EXPECT_FALSE(window->IsActive()); + + // Cleanup. + window->CloseNow(); + window2->CloseNow(); +} |