diff options
22 files changed, 550 insertions, 683 deletions
diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar.h b/chrome/browser/ui/panels/auto_hiding_desktop_bar.h deleted file mode 100644 index d910a15..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar.h +++ /dev/null @@ -1,72 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_H_ -#define CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_H_ -#pragma once - -#include "base/memory/ref_counted.h" - -namespace gfx { -class Rect; -} - -// Encapsulates the logic to deal with always-on-top auto-hiding desktop bars, -// like Windows taskbar or MacOSX dock. -// Note that the ref count is needed by using PostTask in the implementation of -// MockAutoHidingDesktopBar that derives from AutoHidingDesktopBar. -class AutoHidingDesktopBar : public base::RefCounted<AutoHidingDesktopBar> { - public: - // Indicates which screen edge the desktop bar is aligned to. - // We do not care about the desktop aligned to the top screen edge. - enum Alignment { - ALIGN_BOTTOM = 0, - ALIGN_LEFT = 1, - ALIGN_RIGHT = 2 - }; - - enum Visibility { - VISIBLE, - ANIMATING, - HIDDEN - }; - - // Observer can listen to various events regarding the desktop bar changes. - class Observer { - public: - // Called when any of the desktop bars get their thickness changed. - // Note that if an auto-hiding desktop bar is moved from one edge - // to another edge, it will cause thickness changes to both edges. - virtual void OnAutoHidingDesktopBarThicknessChanged() = 0; - - // Called when an auto-hiding desktop bar has its visibility changed. - virtual void OnAutoHidingDesktopBarVisibilityChanged( - Alignment alignment, Visibility visibility) = 0; - }; - - static AutoHidingDesktopBar* Create(Observer* observer); - - virtual ~AutoHidingDesktopBar() { } - - // This should be called each time when the work area is changed. We only - // care about the desktop bars that sit on the screen that hosts the specified - // work area. - virtual void UpdateWorkArea(const gfx::Rect& work_area) = 0; - - // Returns true if there is a desktop bar that is aligned to the specified - // screen edge and set to auto-hide. - virtual bool IsEnabled(Alignment alignment) = 0; - - // Returns the thickness of the desktop bar that is aligned to the specified - // screen edge, when it is visible. When the desktop bar is aligned to bottom - // edge, this is the height of the bar. If the desktop bar is aligned to - // left or right edge, this is the width of the bar. - virtual int GetThickness(Alignment alignment) const = 0; - - // Returns the visibility state of the desktop bar that is aligned to the - // specified screen edge. - virtual Visibility GetVisibility(Alignment alignment) const = 0; -}; - -#endif // CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_H_ diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_aura.cc b/chrome/browser/ui/panels/auto_hiding_desktop_bar_aura.cc deleted file mode 100644 index 671b7ca..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_aura.cc +++ /dev/null @@ -1,56 +0,0 @@ -// 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" - -#include "base/compiler_specific.h" - -namespace { - -class AutoHidingDesktopBarAura : public AutoHidingDesktopBar { - public: - explicit AutoHidingDesktopBarAura(Observer* observer); - virtual ~AutoHidingDesktopBarAura() { } - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - - private: - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(AutoHidingDesktopBarAura); -}; - -AutoHidingDesktopBarAura::AutoHidingDesktopBarAura(Observer* observer) - : observer_(observer) { -} - -void AutoHidingDesktopBarAura::UpdateWorkArea(const gfx::Rect& work_area) { -} - -bool AutoHidingDesktopBarAura::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { - // No taskbar exists on ChromeOS. - return false; -} - -int AutoHidingDesktopBarAura::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { - return 0; -} - -AutoHidingDesktopBar::Visibility AutoHidingDesktopBarAura::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { - return AutoHidingDesktopBar::HIDDEN; -} - -} // namespace - -// static -AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { - return new AutoHidingDesktopBarAura(observer); -} diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_chromeos.cc b/chrome/browser/ui/panels/auto_hiding_desktop_bar_chromeos.cc deleted file mode 100644 index 60a8daa..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_chromeos.cc +++ /dev/null @@ -1,56 +0,0 @@ -// 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" - -#include "base/compiler_specific.h" - -namespace { - -class AutoHidingDesktopBarChromeOS : public AutoHidingDesktopBar { - public: - explicit AutoHidingDesktopBarChromeOS(Observer* observer); - virtual ~AutoHidingDesktopBarChromeOS() { } - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - - private: - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(AutoHidingDesktopBarChromeOS); -}; - -AutoHidingDesktopBarChromeOS::AutoHidingDesktopBarChromeOS(Observer* observer) - : observer_(observer) { -} - -void AutoHidingDesktopBarChromeOS::UpdateWorkArea(const gfx::Rect& work_area) { -} - -bool AutoHidingDesktopBarChromeOS::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { - // No taskbar exists on ChromeOS. - return false; -} - -int AutoHidingDesktopBarChromeOS::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { - return 0; -} - -AutoHidingDesktopBar::Visibility AutoHidingDesktopBarChromeOS::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { - return AutoHidingDesktopBar::HIDDEN; -} - -} // namespace - -// static -AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { - return new AutoHidingDesktopBarChromeOS(observer); -} diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_cocoa.mm b/chrome/browser/ui/panels/auto_hiding_desktop_bar_cocoa.mm deleted file mode 100644 index 7db2c72..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_cocoa.mm +++ /dev/null @@ -1,61 +0,0 @@ -// 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" - -#include "base/compiler_specific.h" -#include "base/logging.h" - -namespace { - -class AutoHidingDesktopBarCocoa : public AutoHidingDesktopBar { - public: - explicit AutoHidingDesktopBarCocoa(Observer* observer); - virtual ~AutoHidingDesktopBarCocoa() { } - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - - private: - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(AutoHidingDesktopBarCocoa); -}; - -AutoHidingDesktopBarCocoa::AutoHidingDesktopBarCocoa(Observer* observer) - : observer_(observer) { - DCHECK(observer); -} - -void AutoHidingDesktopBarCocoa::UpdateWorkArea(const gfx::Rect& work_area) { - // TODO(jianli): Implement. -} - -bool AutoHidingDesktopBarCocoa::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { - // TODO(jianli): Implement. - return false; -} - -int AutoHidingDesktopBarCocoa::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { - NOTIMPLEMENTED(); - return 0; -} - -AutoHidingDesktopBar::Visibility AutoHidingDesktopBarCocoa::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { - NOTIMPLEMENTED(); - return AutoHidingDesktopBar::HIDDEN; -} - -} // namespace - -// static -AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { - return new AutoHidingDesktopBarCocoa(observer); -} diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_gtk.cc b/chrome/browser/ui/panels/auto_hiding_desktop_bar_gtk.cc deleted file mode 100644 index e9c5d6ef..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_gtk.cc +++ /dev/null @@ -1,61 +0,0 @@ -// 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" - -#include "base/compiler_specific.h" -#include "base/logging.h" - -namespace { - -class AutoHidingDesktopBarGtk : public AutoHidingDesktopBar { - public: - explicit AutoHidingDesktopBarGtk(Observer* observer); - virtual ~AutoHidingDesktopBarGtk() { } - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - - private: - Observer* observer_; - - DISALLOW_COPY_AND_ASSIGN(AutoHidingDesktopBarGtk); -}; - -AutoHidingDesktopBarGtk::AutoHidingDesktopBarGtk(Observer* observer) - : observer_(observer) { - DCHECK(observer); -} - -void AutoHidingDesktopBarGtk::UpdateWorkArea(const gfx::Rect& work_area) { - // TODO(prasadt): Not implemented yet. http://crbug.com/102719 -} - -bool AutoHidingDesktopBarGtk::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { - // TODO(prasadt): Not implemented yet. http://crbug.com/102719 - return false; -} - -int AutoHidingDesktopBarGtk::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { - // TODO(prasadt): Not implemented yet. http://crbug.com/102719 - return 0; -} - -AutoHidingDesktopBar::Visibility AutoHidingDesktopBarGtk::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { - // TODO(prasadt): Not implemented yet. http://crbug.com/102719 - return AutoHidingDesktopBar::HIDDEN; -} - -} // namespace - -// static -AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { - return new AutoHidingDesktopBarGtk(observer); -} diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h deleted file mode 100644 index 5bc1206..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h +++ /dev/null @@ -1,66 +0,0 @@ -// 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. - -#ifndef CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_WIN_H_ -#define CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_WIN_H_ -#pragma once - -#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" - -#include <windows.h> -#include "base/compiler_specific.h" -#include "base/timer.h" -#include "ui/gfx/rect.h" - -class AutoHidingDesktopBarWin : public AutoHidingDesktopBar { - public: - explicit AutoHidingDesktopBarWin(Observer* observer); - virtual ~AutoHidingDesktopBarWin(); - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - -#ifdef UNIT_TEST - void set_work_area(const gfx::Rect& work_area) { - work_area_ = work_area; - } -#endif - - private: - friend class AutoHidingDesktopBarWinTest; - - struct Taskbar { - HWND window; - AutoHidingDesktopBar::Visibility visibility; - int thickness; - }; - - // Callback to perform periodic check for taskbar changes. - void OnPollingTimer(); - - // Returns true if there is at least one auto-hiding taskbar found. - bool CheckTaskbars(bool notify_observer); - - gfx::Rect GetBounds(Alignment alignment) const; - int GetThicknessFromBounds( - Alignment alignment, const gfx::Rect& taskbar_bounds) const; - Visibility GetVisibilityFromBounds( - Alignment alignment, const gfx::Rect& taskbar_bounds) const; - - // Maximum number of taskbars we're interested in: bottom, left, and right. - static const int kMaxTaskbars = 3; - - Observer* observer_; - gfx::Rect work_area_; - HMONITOR monitor_; - Taskbar taskbars_[kMaxTaskbars]; - base::RepeatingTimer<AutoHidingDesktopBarWin> polling_timer_; - - DISALLOW_COPY_AND_ASSIGN(AutoHidingDesktopBarWin); -}; - -#endif // CHROME_BROWSER_UI_PANELS_AUTO_HIDING_DESKTOP_BAR_WIN_H_ diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc deleted file mode 100644 index 0a3ca3f..0000000 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc +++ /dev/null @@ -1,67 +0,0 @@ -// 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h" - -#include "base/memory/scoped_ptr.h" -#include "testing/gtest/include/gtest/gtest.h" - - -class AutoHidingDesktopBarWinTest : public testing::Test, - public AutoHidingDesktopBar::Observer { - protected: - // Overridden from AutoHidingDesktopBar::Observer: - virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE { - } - - virtual void OnAutoHidingDesktopBarVisibilityChanged( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) OVERRIDE { - } - - void TestGetVisibilityFromBounds() { - scoped_refptr<AutoHidingDesktopBarWin> bar = - new AutoHidingDesktopBarWin(this); - bar->set_work_area(gfx::Rect(0, 0, 800, 600)); - - AutoHidingDesktopBar::Visibility visibility; - - // Tests for bottom bar. - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_BOTTOM, gfx::Rect(0, 560, 800, 40)); - EXPECT_EQ(AutoHidingDesktopBar::VISIBLE, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_BOTTOM, gfx::Rect(0, 598, 800, 40)); - EXPECT_EQ(AutoHidingDesktopBar::HIDDEN, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_BOTTOM, gfx::Rect(0, 580, 800, 40)); - EXPECT_EQ(AutoHidingDesktopBar::ANIMATING, visibility); - - // Tests for right bar. - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_RIGHT, gfx::Rect(760, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::VISIBLE, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_RIGHT, gfx::Rect(798, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::HIDDEN, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_RIGHT, gfx::Rect(780, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::ANIMATING, visibility); - - // Tests for left bar. - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_LEFT, gfx::Rect(0, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::VISIBLE, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_LEFT, gfx::Rect(-38, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::HIDDEN, visibility); - visibility = bar->GetVisibilityFromBounds( - AutoHidingDesktopBar::ALIGN_LEFT, gfx::Rect(-15, 0, 40, 600)); - EXPECT_EQ(AutoHidingDesktopBar::ANIMATING, visibility); - } -}; - -TEST_F(AutoHidingDesktopBarWinTest, GetVisibilityFromBounds) { - TestGetVisibilityFromBounds(); -} diff --git a/chrome/browser/ui/panels/base_panel_browser_test.cc b/chrome/browser/ui/panels/base_panel_browser_test.cc index f5cc68c..1bce3a3 100644 --- a/chrome/browser/ui/panels/base_panel_browser_test.cc +++ b/chrome/browser/ui/panels/base_panel_browser_test.cc @@ -37,85 +37,92 @@ namespace { const int kTestingWorkAreaWidth = 800; const int kTestingWorkAreaHeight = 600; -const int kDefaultAutoHidingDesktopBarThickness = 40; struct MockDesktopBar { bool auto_hiding_enabled; - AutoHidingDesktopBar::Visibility visibility; + DisplaySettingsProvider::DesktopBarVisibility visibility; int thickness; }; -class MockAutoHidingDesktopBarImpl : - public BasePanelBrowserTest::MockAutoHidingDesktopBar { +class MockDisplaySettingsProviderImpl : + public BasePanelBrowserTest::MockDisplaySettingsProvider { public: - explicit MockAutoHidingDesktopBarImpl(Observer* observer); - virtual ~MockAutoHidingDesktopBarImpl() { } - - // Overridden from AutoHidingDesktopBar: - virtual void UpdateWorkArea(const gfx::Rect& work_area) OVERRIDE; - virtual bool IsEnabled(Alignment alignment) OVERRIDE; - virtual int GetThickness(Alignment alignment) const OVERRIDE; - virtual Visibility GetVisibility(Alignment alignment) const OVERRIDE; - - // Overridden from MockAutoHidingDesktopBar: - virtual void EnableAutoHiding(Alignment alignment, - bool enabled, - int thickness) OVERRIDE; - virtual void SetVisibility(Alignment alignment, - Visibility visibility) OVERRIDE; - virtual void SetThickness(Alignment alignment, int thickness) OVERRIDE; - - void set_observer(Observer* observer) { observer_ = observer; } + explicit MockDisplaySettingsProviderImpl(Observer* observer); + virtual ~MockDisplaySettingsProviderImpl() { } + + // Overridden from DisplaySettingsProvider: + virtual gfx::Rect GetWorkArea() OVERRIDE; + virtual bool IsAutoHidingDesktopBarEnabled( + DesktopBarAlignment alignment) OVERRIDE; + virtual int GetDesktopBarThickness( + DesktopBarAlignment alignment) const OVERRIDE; + virtual DesktopBarVisibility GetDesktopBarVisibility( + DesktopBarAlignment alignment) const OVERRIDE; + + // Overridden from MockDisplaySettingsProvider: + virtual void SetWorkArea(const gfx::Rect& work_area) OVERRIDE; + virtual void EnableAutoHidingDesktopBar(DesktopBarAlignment alignment, + bool enabled, + int thickness) OVERRIDE; + virtual void SetDesktopBarVisibility( + DesktopBarAlignment alignment, DesktopBarVisibility visibility) OVERRIDE; + virtual void SetDesktopBarThickness(DesktopBarAlignment alignment, + int thickness) OVERRIDE; private: - void NotifyVisibilityChange(Alignment alignment, Visibility visibility); - void NotifyThicknessChange(); + void NotifyDesktopBarVisibilityChange(DesktopBarAlignment alignment, + DesktopBarVisibility visibility); + void NotifyDesktopBarThicknessChange(); - Observer* observer_; MockDesktopBar mock_desktop_bars[3]; - base::WeakPtrFactory<MockAutoHidingDesktopBarImpl> method_factory_; - DISALLOW_COPY_AND_ASSIGN(MockAutoHidingDesktopBarImpl); + DISALLOW_COPY_AND_ASSIGN(MockDisplaySettingsProviderImpl); }; -MockAutoHidingDesktopBarImpl::MockAutoHidingDesktopBarImpl( - AutoHidingDesktopBar::Observer* observer) - : observer_(observer), method_factory_(this) { +MockDisplaySettingsProviderImpl::MockDisplaySettingsProviderImpl( + DisplaySettingsProvider::Observer* observer) + : MockDisplaySettingsProvider(observer) { memset(mock_desktop_bars, 0, sizeof(mock_desktop_bars)); } -void MockAutoHidingDesktopBarImpl::UpdateWorkArea( - const gfx::Rect& work_area) { +gfx::Rect MockDisplaySettingsProviderImpl::GetWorkArea() { + // Some test might want to use the actual work area, that is indicated by + // passing empty testing work area. + return work_area_.IsEmpty() ? DisplaySettingsProvider::GetWorkArea() + : work_area_; } -bool MockAutoHidingDesktopBarImpl::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { +bool MockDisplaySettingsProviderImpl::IsAutoHidingDesktopBarEnabled( + DesktopBarAlignment alignment) { return mock_desktop_bars[static_cast<int>(alignment)].auto_hiding_enabled; } -int MockAutoHidingDesktopBarImpl::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { +int MockDisplaySettingsProviderImpl::GetDesktopBarThickness( + DesktopBarAlignment alignment) const { return mock_desktop_bars[static_cast<int>(alignment)].thickness; } -AutoHidingDesktopBar::Visibility -MockAutoHidingDesktopBarImpl::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { +DisplaySettingsProvider::DesktopBarVisibility +MockDisplaySettingsProviderImpl::GetDesktopBarVisibility( + DesktopBarAlignment alignment) const { return mock_desktop_bars[static_cast<int>(alignment)].visibility; } -void MockAutoHidingDesktopBarImpl::EnableAutoHiding( - AutoHidingDesktopBar::Alignment alignment, bool enabled, int thickness) { +void MockDisplaySettingsProviderImpl::EnableAutoHidingDesktopBar( + DesktopBarAlignment alignment, bool enabled, int thickness) { MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); bar->auto_hiding_enabled = enabled; bar->thickness = thickness; observer_->OnAutoHidingDesktopBarThicknessChanged(); } -void MockAutoHidingDesktopBarImpl::SetVisibility( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) { +void MockDisplaySettingsProviderImpl::SetWorkArea(const gfx::Rect& work_area) { + work_area_ = work_area; +} + +void MockDisplaySettingsProviderImpl::SetDesktopBarVisibility( + DesktopBarAlignment alignment, DesktopBarVisibility visibility) { MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); if (!bar->auto_hiding_enabled) return; @@ -124,14 +131,15 @@ void MockAutoHidingDesktopBarImpl::SetVisibility( bar->visibility = visibility; MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&MockAutoHidingDesktopBarImpl::NotifyVisibilityChange, - method_factory_.GetWeakPtr(), - alignment, - visibility)); + base::Bind( + &MockDisplaySettingsProviderImpl::NotifyDesktopBarVisibilityChange, + base::Unretained(this), + alignment, + visibility)); } -void MockAutoHidingDesktopBarImpl::SetThickness( - AutoHidingDesktopBar::Alignment alignment, int thickness) { +void MockDisplaySettingsProviderImpl::SetDesktopBarThickness( + DesktopBarAlignment alignment, int thickness) { MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); if (!bar->auto_hiding_enabled) return; @@ -140,17 +148,18 @@ void MockAutoHidingDesktopBarImpl::SetThickness( bar->thickness = thickness; MessageLoop::current()->PostTask( FROM_HERE, - base::Bind(&MockAutoHidingDesktopBarImpl::NotifyThicknessChange, - method_factory_.GetWeakPtr())); + base::Bind( + &MockDisplaySettingsProviderImpl::NotifyDesktopBarThicknessChange, + base::Unretained(this))); } -void MockAutoHidingDesktopBarImpl::NotifyVisibilityChange( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) { +void MockDisplaySettingsProviderImpl::NotifyDesktopBarVisibilityChange( + DesktopBarAlignment alignment, + DesktopBarVisibility visibility) { observer_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); } -void MockAutoHidingDesktopBarImpl::NotifyThicknessChange() { +void MockDisplaySettingsProviderImpl::NotifyDesktopBarThicknessChange() { observer_->OnAutoHidingDesktopBarThicknessChanged(); } @@ -165,9 +174,7 @@ const FilePath::CharType* BasePanelBrowserTest::kTestDir = FILE_PATH_LITERAL("panels"); BasePanelBrowserTest::BasePanelBrowserTest() - : InProcessBrowserTest(), - testing_work_area_(0, 0, kTestingWorkAreaWidth, - kTestingWorkAreaHeight) { + : InProcessBrowserTest() { #if defined(OS_MACOSX) FindBarBridge::disable_animations_during_testing_ = true; #endif @@ -203,13 +210,12 @@ void BasePanelBrowserTest::SetUpOnMainThread() { // Setup the work area and desktop bar so that we have consistent testing // environment for all panel related tests. PanelManager* panel_manager = PanelManager::GetInstance(); - mock_auto_hiding_desktop_bar_ = new MockAutoHidingDesktopBarImpl( + mock_display_settings_provider_ = new MockDisplaySettingsProviderImpl( panel_manager); - panel_manager->set_auto_hiding_desktop_bar(mock_auto_hiding_desktop_bar_); - // Do not use the testing work area if it is empty since we're going to - // use the actual work area in some testing scenarios. - if (!testing_work_area_.IsEmpty()) - panel_manager->SetWorkAreaForTesting(testing_work_area_); + panel_manager->set_display_settings_provider(mock_display_settings_provider_); + SetTestingWorkArea(gfx::Rect( + 0, 0, kTestingWorkAreaWidth, kTestingWorkAreaHeight)); + panel_manager->enable_auto_sizing(false); PanelManager::shorten_time_intervals_for_testing(); @@ -422,6 +428,15 @@ scoped_refptr<Extension> BasePanelBrowserTest::CreateExtension( return extension; } +gfx::Rect BasePanelBrowserTest::GetTestingWorkArea() const { + return mock_display_settings_provider_->GetWorkArea(); +} + +void BasePanelBrowserTest::SetTestingWorkArea(const gfx::Rect& work_area) { + mock_display_settings_provider_->SetWorkArea(work_area); + PanelManager::GetInstance()->OnDisplayChanged(); +} + void BasePanelBrowserTest::CloseWindowAndWait(Browser* browser) { // Closing a browser window may involve several async tasks. Need to use // message pump and wait for the notification. diff --git a/chrome/browser/ui/panels/base_panel_browser_test.h b/chrome/browser/ui/panels/base_panel_browser_test.h index ad86073..e96f504 100644 --- a/chrome/browser/ui/panels/base_panel_browser_test.h +++ b/chrome/browser/ui/panels/base_panel_browser_test.h @@ -8,7 +8,7 @@ #include "base/values.h" #include "base/memory/scoped_ptr.h" -#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" +#include "chrome/browser/ui/panels/display_settings_provider.h" #include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel_strip.h" #include "chrome/common/extensions/extension.h" @@ -17,15 +17,21 @@ class BasePanelBrowserTest : public InProcessBrowserTest { public: - class MockAutoHidingDesktopBar : public AutoHidingDesktopBar { + class MockDisplaySettingsProvider : public DisplaySettingsProvider { public: - virtual ~MockAutoHidingDesktopBar() { } - - virtual void EnableAutoHiding(Alignment alignment, - bool enabled, - int thickness) = 0; - virtual void SetVisibility(Alignment alignment, Visibility visibility) = 0; - virtual void SetThickness(Alignment alignment, int thickness) = 0; + explicit MockDisplaySettingsProvider(Observer* observer) + : DisplaySettingsProvider(observer) { + } + virtual ~MockDisplaySettingsProvider() { } + + virtual void SetWorkArea(const gfx::Rect& work_area) = 0; + virtual void EnableAutoHidingDesktopBar(DesktopBarAlignment alignment, + bool enabled, + int thickness) = 0; + virtual void SetDesktopBarVisibility(DesktopBarAlignment alignment, + DesktopBarVisibility visibility) = 0; + virtual void SetDesktopBarThickness(DesktopBarAlignment alignment, + int thickness) = 0; }; BasePanelBrowserTest(); @@ -93,19 +99,17 @@ class BasePanelBrowserTest : public InProcessBrowserTest { static void CloseWindowAndWait(Browser* browser); static std::string MakePanelName(int index); - gfx::Rect testing_work_area() const { return testing_work_area_; } - void set_testing_work_area(const gfx::Rect& work_area) { - testing_work_area_ = work_area; - } + gfx::Rect GetTestingWorkArea() const; + void SetTestingWorkArea(const gfx::Rect& work_area); - MockAutoHidingDesktopBar* mock_auto_hiding_desktop_bar() const { - return mock_auto_hiding_desktop_bar_.get(); + MockDisplaySettingsProvider* mock_display_settings_provider() const { + return mock_display_settings_provider_; } static const FilePath::CharType* kTestDir; private: - gfx::Rect testing_work_area_; - scoped_refptr<MockAutoHidingDesktopBar> mock_auto_hiding_desktop_bar_; + // Passed to and owned by PanelManager. + MockDisplaySettingsProvider* mock_display_settings_provider_; }; #endif // CHROME_BROWSER_UI_PANELS_BASE_PANEL_BROWSER_TEST_H_ diff --git a/chrome/browser/ui/panels/display_settings_provider.cc b/chrome/browser/ui/panels/display_settings_provider.cc new file mode 100644 index 0000000..05c0dc5 --- /dev/null +++ b/chrome/browser/ui/panels/display_settings_provider.cc @@ -0,0 +1,59 @@ +// Copyright (c) 2012 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 "chrome/browser/ui/panels/display_settings_provider.h" + +#include "base/logging.h" +#include "ui/gfx/screen.h" + +DisplaySettingsProvider::DisplaySettingsProvider(Observer* observer) + : observer_(observer) { + DCHECK(observer); +} + +DisplaySettingsProvider::~DisplaySettingsProvider() { +} + +gfx::Rect DisplaySettingsProvider::GetWorkArea() { +#if defined(OS_MACOSX) + // On OSX, panels should be dropped all the way to the bottom edge of the + // screen (and overlap Dock). + gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorBounds(); +#else + gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); +#endif + + if (work_area_ != work_area) { + work_area_ = work_area; + OnWorkAreaChanged(); + } + + return work_area; +} + +void DisplaySettingsProvider::OnWorkAreaChanged() { +} + +bool DisplaySettingsProvider::IsAutoHidingDesktopBarEnabled( + DesktopBarAlignment alignment) { + return false; +} + +int DisplaySettingsProvider::GetDesktopBarThickness( + DesktopBarAlignment alignment) const { + return 0; +} + +DisplaySettingsProvider::DesktopBarVisibility +DisplaySettingsProvider::GetDesktopBarVisibility( + DesktopBarAlignment alignment) const { + return DESKTOP_BAR_VISIBLE; +} + +#if !defined(OS_WIN) +// static +DisplaySettingsProvider* DisplaySettingsProvider::Create(Observer* observer) { + return new DisplaySettingsProvider(observer); +} +#endif diff --git a/chrome/browser/ui/panels/display_settings_provider.h b/chrome/browser/ui/panels/display_settings_provider.h new file mode 100644 index 0000000..4dab327 --- /dev/null +++ b/chrome/browser/ui/panels/display_settings_provider.h @@ -0,0 +1,85 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ +#define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ +#pragma once + +#include "ui/gfx/rect.h" + +// Encapsulates the logic to provide display settings support, including the +// information for: +// 1) Work area +// 2) Auto-hiding desktop bars, like Windows taskbar and MacOSX dock. +class DisplaySettingsProvider { + public: + // Indicates which screen edge the desktop bar is aligned to. + // We do not care about the desktop aligned to the top screen edge. + enum DesktopBarAlignment { + DESKTOP_BAR_ALIGNED_BOTTOM = 0, + DESKTOP_BAR_ALIGNED_LEFT = 1, + DESKTOP_BAR_ALIGNED_RIGHT = 2 + }; + + // Indicates current visibility state of the desktop bar. + enum DesktopBarVisibility { + DESKTOP_BAR_VISIBLE, + DESKTOP_BAR_ANIMATING, + DESKTOP_BAR_HIDDEN + }; + + // Observer can listen to various events regarding the desktop bar changes. + class Observer { + public: + // Called when any of the desktop bars get their thickness changed. + // Note that if an auto-hiding desktop bar is moved from one edge + // to another edge, it will cause thickness changes to both edges. + virtual void OnAutoHidingDesktopBarThicknessChanged() = 0; + + // Called when an auto-hiding desktop bar has its visibility changed. + virtual void OnAutoHidingDesktopBarVisibilityChanged( + DesktopBarAlignment alignment, DesktopBarVisibility visibility) = 0; + }; + + static DisplaySettingsProvider* Create(Observer* observer); + + virtual ~DisplaySettingsProvider(); + + // Returns the bounds of the work area. + virtual gfx::Rect GetWorkArea(); + + // Returns true if there is a desktop bar that is aligned to the specified + // screen edge and set to auto-hide. + virtual bool IsAutoHidingDesktopBarEnabled(DesktopBarAlignment alignment); + + // Returns the thickness of the desktop bar that is aligned to the specified + // screen edge, when it is visible. When the desktop bar is aligned to bottom + // edge, this is the height of the bar. If the desktop bar is aligned to + // left or right edge, this is the width of the bar. + virtual int GetDesktopBarThickness(DesktopBarAlignment alignment) const; + + // Returns the visibility state of the desktop bar that is aligned to the + // specified screen edge. + virtual DesktopBarVisibility GetDesktopBarVisibility( + DesktopBarAlignment alignment) const; + +#ifdef UNIT_TEST + void set_work_area(const gfx::Rect& work_area) { + work_area_ = work_area; + } +#endif + + protected: + explicit DisplaySettingsProvider(Observer* observer); + + // Invoked when the work area is changed in order to update the information + // about the desktop bars. We only care about the desktop bars that sit on + // the screen that hosts the specified work area. + virtual void OnWorkAreaChanged(); + + Observer* observer_; + gfx::Rect work_area_; +}; + +#endif // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.cc b/chrome/browser/ui/panels/display_settings_provider_win.cc index 06ae85a..156dfca 100644 --- a/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.cc +++ b/chrome/browser/ui/panels/display_settings_provider_win.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Copyright (c) 2012 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 "chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h" +#include "chrome/browser/ui/panels/display_settings_provider_win.h" #include <shellapi.h> @@ -18,21 +18,16 @@ const int kHiddenAutoHideTaskbarThickness = 2; const int kCheckTaskbarPollingIntervalMs = 500; } // namespace -AutoHidingDesktopBarWin::AutoHidingDesktopBarWin(Observer* observer) - : observer_(observer), +DisplaySettingsProviderWin::DisplaySettingsProviderWin(Observer* observer) + : DisplaySettingsProvider(observer), monitor_(NULL) { - DCHECK(observer); memset(taskbars_, 0, sizeof(taskbars_)); } -AutoHidingDesktopBarWin::~AutoHidingDesktopBarWin() { +DisplaySettingsProviderWin::~DisplaySettingsProviderWin() { } -void AutoHidingDesktopBarWin::UpdateWorkArea(const gfx::Rect& work_area) { - if (work_area_ == work_area) - return; - work_area_ = work_area; - +void DisplaySettingsProviderWin::OnWorkAreaChanged() { RECT rect = work_area_.ToRECT(); monitor_ = ::MonitorFromRect(&rect, MONITOR_DEFAULTTOPRIMARY); DCHECK(monitor_); @@ -47,7 +42,7 @@ void AutoHidingDesktopBarWin::UpdateWorkArea(const gfx::Rect& work_area) { polling_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckTaskbarPollingIntervalMs), this, - &AutoHidingDesktopBarWin::OnPollingTimer); + &DisplaySettingsProviderWin::OnPollingTimer); } } else { if (polling_timer_.IsRunning()) @@ -55,24 +50,25 @@ void AutoHidingDesktopBarWin::UpdateWorkArea(const gfx::Rect& work_area) { } } -bool AutoHidingDesktopBarWin::IsEnabled( - AutoHidingDesktopBar::Alignment alignment) { +bool DisplaySettingsProviderWin::IsAutoHidingDesktopBarEnabled( + DesktopBarAlignment alignment) { CheckTaskbars(false); return taskbars_[static_cast<int>(alignment)].window != NULL; } -int AutoHidingDesktopBarWin::GetThickness( - AutoHidingDesktopBar::Alignment alignment) const { - return GetThicknessFromBounds(alignment, GetBounds(alignment)); +int DisplaySettingsProviderWin::GetDesktopBarThickness( + DesktopBarAlignment alignment) const { + return GetDesktopBarThicknessFromBounds(alignment, GetBounds(alignment)); } -AutoHidingDesktopBar::Visibility AutoHidingDesktopBarWin::GetVisibility( - AutoHidingDesktopBar::Alignment alignment) const { - return GetVisibilityFromBounds(alignment, GetBounds(alignment)); +DisplaySettingsProvider::DesktopBarVisibility +DisplaySettingsProviderWin::GetDesktopBarVisibility( + DesktopBarAlignment alignment) const { + return GetDesktopBarVisibilityFromBounds(alignment, GetBounds(alignment)); } -gfx::Rect AutoHidingDesktopBarWin::GetBounds( - AutoHidingDesktopBar::Alignment alignment) const { +gfx::Rect DisplaySettingsProviderWin::GetBounds( + DesktopBarAlignment alignment) const { HWND taskbar_window = taskbars_[static_cast<int>(alignment)].window; if (!taskbar_window) return gfx::Rect(); @@ -83,14 +79,14 @@ gfx::Rect AutoHidingDesktopBarWin::GetBounds( return gfx::Rect(rect); } -int AutoHidingDesktopBarWin::GetThicknessFromBounds( - AutoHidingDesktopBar::Alignment alignment, +int DisplaySettingsProviderWin::GetDesktopBarThicknessFromBounds( + DesktopBarAlignment alignment, const gfx::Rect& taskbar_bounds) const { switch (alignment) { - case AutoHidingDesktopBar::ALIGN_BOTTOM: + case DESKTOP_BAR_ALIGNED_BOTTOM: return taskbar_bounds.height(); - case AutoHidingDesktopBar::ALIGN_LEFT: - case AutoHidingDesktopBar::ALIGN_RIGHT: + case DESKTOP_BAR_ALIGNED_LEFT: + case DESKTOP_BAR_ALIGNED_RIGHT: return taskbar_bounds.width(); default: NOTREACHED(); @@ -98,49 +94,49 @@ int AutoHidingDesktopBarWin::GetThicknessFromBounds( } } -AutoHidingDesktopBar::Visibility -AutoHidingDesktopBarWin::GetVisibilityFromBounds( - AutoHidingDesktopBar::Alignment alignment, +DisplaySettingsProvider::DesktopBarVisibility +DisplaySettingsProviderWin::GetDesktopBarVisibilityFromBounds( + DesktopBarAlignment alignment, const gfx::Rect& taskbar_bounds) const { switch (alignment) { - case AutoHidingDesktopBar::ALIGN_BOTTOM: + case DESKTOP_BAR_ALIGNED_BOTTOM: if (taskbar_bounds.bottom() <= work_area_.bottom()) - return VISIBLE; + return DESKTOP_BAR_VISIBLE; else if (taskbar_bounds.y() >= work_area_.bottom() - kHiddenAutoHideTaskbarThickness) - return HIDDEN; + return DESKTOP_BAR_HIDDEN; else - return ANIMATING; + return DESKTOP_BAR_ANIMATING; - case AutoHidingDesktopBar::ALIGN_LEFT: + case DESKTOP_BAR_ALIGNED_LEFT: if (taskbar_bounds.x() >= work_area_.x()) - return VISIBLE; + return DESKTOP_BAR_VISIBLE; else if (taskbar_bounds.right() <= work_area_.x() + kHiddenAutoHideTaskbarThickness) - return HIDDEN; + return DESKTOP_BAR_HIDDEN; else - return ANIMATING; + return DESKTOP_BAR_ANIMATING; - case AutoHidingDesktopBar::ALIGN_RIGHT: + case DESKTOP_BAR_ALIGNED_RIGHT: if (taskbar_bounds.right() <= work_area_.right()) - return VISIBLE; + return DESKTOP_BAR_VISIBLE; else if (taskbar_bounds.x() >= work_area_.right() - kHiddenAutoHideTaskbarThickness) - return HIDDEN; + return DESKTOP_BAR_HIDDEN; else - return ANIMATING; + return DESKTOP_BAR_ANIMATING; default: NOTREACHED(); - return VISIBLE; + return DESKTOP_BAR_VISIBLE; } } -void AutoHidingDesktopBarWin::OnPollingTimer() { +void DisplaySettingsProviderWin::OnPollingTimer() { CheckTaskbars(true); } -bool AutoHidingDesktopBarWin::CheckTaskbars(bool notify_observer) { +bool DisplaySettingsProviderWin::CheckTaskbars(bool notify_observer) { bool taskbar_exists = false; UINT edges[] = { ABE_BOTTOM, ABE_LEFT, ABE_RIGHT }; for (size_t i = 0; i < kMaxTaskbars; ++i) { @@ -152,27 +148,27 @@ bool AutoHidingDesktopBarWin::CheckTaskbars(bool notify_observer) { if (!taskbar_exists) { for (size_t i = 0; i < kMaxTaskbars; ++i) { taskbars_[i].thickness = 0; - taskbars_[i].visibility = AutoHidingDesktopBar::HIDDEN; + taskbars_[i].visibility = DESKTOP_BAR_HIDDEN; } return false; } bool thickness_changed = false; for (size_t i = 0; i < kMaxTaskbars; ++i) { - AutoHidingDesktopBar::Alignment alignment = static_cast<Alignment>(i); + DesktopBarAlignment alignment = static_cast<DesktopBarAlignment>(i); gfx::Rect bounds = GetBounds(alignment); // Check the thickness change. - int thickness = GetThicknessFromBounds(alignment, bounds); + int thickness = GetDesktopBarThicknessFromBounds(alignment, bounds); if (thickness != taskbars_[i].thickness) { taskbars_[i].thickness = thickness; thickness_changed = true; } // Check and notify the visibility change. - AutoHidingDesktopBar::Visibility visibility = - GetVisibilityFromBounds(alignment, bounds); + DesktopBarVisibility visibility = GetDesktopBarVisibilityFromBounds( + alignment, bounds); if (visibility != taskbars_[i].visibility) { taskbars_[i].visibility = visibility; if (notify_observer) { @@ -190,6 +186,6 @@ bool AutoHidingDesktopBarWin::CheckTaskbars(bool notify_observer) { } // static -AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { - return new AutoHidingDesktopBarWin(observer); +DisplaySettingsProvider* DisplaySettingsProvider::Create(Observer* observer) { + return new DisplaySettingsProviderWin(observer); } diff --git a/chrome/browser/ui/panels/display_settings_provider_win.h b/chrome/browser/ui/panels/display_settings_provider_win.h new file mode 100644 index 0000000..3c134f2 --- /dev/null +++ b/chrome/browser/ui/panels/display_settings_provider_win.h @@ -0,0 +1,62 @@ +// Copyright (c) 2012 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. + +#ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_WIN_H_ +#define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_WIN_H_ +#pragma once + +#include "chrome/browser/ui/panels/display_settings_provider.h" + +#include <windows.h> +#include "base/compiler_specific.h" +#include "base/timer.h" + +class DisplaySettingsProviderWin : public DisplaySettingsProvider { + public: + explicit DisplaySettingsProviderWin(Observer* observer); + virtual ~DisplaySettingsProviderWin(); + + protected: + // Overridden from DisplaySettingsProvider: + virtual void OnWorkAreaChanged() OVERRIDE; + virtual bool IsAutoHidingDesktopBarEnabled( + DesktopBarAlignment alignment) OVERRIDE; + virtual int GetDesktopBarThickness( + DesktopBarAlignment alignment) const OVERRIDE; + virtual DesktopBarVisibility GetDesktopBarVisibility( + DesktopBarAlignment alignment) const OVERRIDE; + + private: + friend class DisplaySettingsProviderWinTest; + + struct Taskbar { + HWND window; + DesktopBarVisibility visibility; + int thickness; + }; + + // Callback to perform periodic check for taskbar changes. + void OnPollingTimer(); + + // Returns true if there is at least one auto-hiding taskbar found. + bool CheckTaskbars(bool notify_observer); + + gfx::Rect GetBounds(DesktopBarAlignment alignment) const; + int GetDesktopBarThicknessFromBounds( + DesktopBarAlignment alignment, const gfx::Rect& taskbar_bounds) const; + DesktopBarVisibility GetDesktopBarVisibilityFromBounds( + DesktopBarAlignment alignment, const gfx::Rect& taskbar_bounds) const; + + // Maximum number of taskbars we're interested in: bottom, left, and right. + static const int kMaxTaskbars = 3; + + Observer* observer_; + HMONITOR monitor_; + Taskbar taskbars_[kMaxTaskbars]; + base::RepeatingTimer<DisplaySettingsProviderWin> polling_timer_; + + DISALLOW_COPY_AND_ASSIGN(DisplaySettingsProviderWin); +}; + +#endif // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_WIN_H_ diff --git a/chrome/browser/ui/panels/display_settings_provider_win_unittest.cc b/chrome/browser/ui/panels/display_settings_provider_win_unittest.cc new file mode 100644 index 0000000..dd3565f --- /dev/null +++ b/chrome/browser/ui/panels/display_settings_provider_win_unittest.cc @@ -0,0 +1,77 @@ +// Copyright (c) 2012 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 "chrome/browser/ui/panels/display_settings_provider_win.h" + +#include "base/memory/scoped_ptr.h" +#include "testing/gtest/include/gtest/gtest.h" + + +class DisplaySettingsProviderWinTest : + public testing::Test, + public DisplaySettingsProvider::Observer { + protected: + // Overridden from DisplaySettingsProvider::Observer: + virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE { + } + + virtual void OnAutoHidingDesktopBarVisibilityChanged( + DisplaySettingsProvider::DesktopBarAlignment alignment, + DisplaySettingsProvider::DesktopBarVisibility visibility) OVERRIDE { + } + + void TestGetDesktopBarVisibilityFromBounds() { + scoped_ptr<DisplaySettingsProviderWin> provider( + new DisplaySettingsProviderWin(this)); + provider->set_work_area(gfx::Rect(0, 0, 800, 600)); + + DisplaySettingsProvider::DesktopBarVisibility visibility; + + // Tests for bottom bar. + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + gfx::Rect(0, 560, 800, 40)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + gfx::Rect(0, 598, 800, 40)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + gfx::Rect(0, 580, 800, 40)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING, visibility); + + // Tests for right bar. + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + gfx::Rect(760, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + gfx::Rect(798, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + gfx::Rect(780, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING, visibility); + + // Tests for left bar. + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT, + gfx::Rect(0, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_VISIBLE, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT, + gfx::Rect(-38, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_HIDDEN, visibility); + visibility = provider->GetDesktopBarVisibilityFromBounds( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT, + gfx::Rect(-15, 0, 40, 600)); + EXPECT_EQ(DisplaySettingsProvider::DESKTOP_BAR_ANIMATING, visibility); + } +}; + +TEST_F(DisplaySettingsProviderWinTest, GetDesktopBarVisibilityFromBounds) { + TestGetDesktopBarVisibilityFromBounds(); +} diff --git a/chrome/browser/ui/panels/docked_panel_strip.cc b/chrome/browser/ui/panels/docked_panel_strip.cc index 57a4bee..63d8597 100644 --- a/chrome/browser/ui/panels/docked_panel_strip.cc +++ b/chrome/browser/ui/panels/docked_panel_strip.cc @@ -503,10 +503,13 @@ void DockedPanelStrip::ResizePanelWindow( bool DockedPanelStrip::ShouldBringUpTitlebars(int mouse_x, int mouse_y) const { // We should always bring up the titlebar if the mouse is over the // visible auto-hiding bottom bar. - AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); - if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && - desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == - AutoHidingDesktopBar::VISIBLE && + DisplaySettingsProvider* provider = + panel_manager_->display_settings_provider(); + if (provider->IsAutoHidingDesktopBarEnabled( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM) && + provider->GetDesktopBarVisibility( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM) == + DisplaySettingsProvider::DESKTOP_BAR_VISIBLE && mouse_y >= display_area_.bottom()) return true; @@ -547,12 +550,16 @@ void DockedPanelStrip::BringUpOrDownTitlebars(bool bring_up) { // If the auto-hiding bottom bar exists, delay the action until the bottom // bar is fully visible or hidden. We do not want both bottom bar and panel // titlebar to move at the same time but with different speeds. - AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); - if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { - AutoHidingDesktopBar::Visibility visibility = - desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM); - if (visibility != (bring_up ? AutoHidingDesktopBar::VISIBLE - : AutoHidingDesktopBar::HIDDEN)) { + DisplaySettingsProvider* provider = + panel_manager_->display_settings_provider(); + if (provider->IsAutoHidingDesktopBarEnabled( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { + DisplaySettingsProvider::DesktopBarVisibility visibility = + provider->GetDesktopBarVisibility( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM); + if (visibility != + (bring_up ? DisplaySettingsProvider::DESKTOP_BAR_VISIBLE + : DisplaySettingsProvider::DESKTOP_BAR_HIDDEN)) { // Occasionally some system, like Windows, might not bring up or down the // bottom bar when the mouse enters or leaves the bottom screen area. // Thus, we schedule a delayed task to do the work if we do not receive @@ -633,10 +640,13 @@ int DockedPanelStrip::GetBottomPositionForExpansionState( int bottom = display_area_.bottom(); // If there is an auto-hiding desktop bar aligned to the bottom edge, we need // to move the title-only panel above the auto-hiding desktop bar. - AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); + DisplaySettingsProvider* provider = + panel_manager_->display_settings_provider(); if (expansion_state == Panel::TITLE_ONLY && - desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { - bottom -= desktop_bar->GetThickness(AutoHidingDesktopBar::ALIGN_BOTTOM); + provider->IsAutoHidingDesktopBarEnabled( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { + bottom -= provider->GetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM); } return bottom; @@ -649,14 +659,15 @@ void DockedPanelStrip::OnMouseMove(const gfx::Point& mouse_position) { } void DockedPanelStrip::OnAutoHidingDesktopBarVisibilityChanged( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) { + DisplaySettingsProvider::DesktopBarAlignment alignment, + DisplaySettingsProvider::DesktopBarVisibility visibility) { if (delayed_titlebar_action_ == NO_ACTION) return; - AutoHidingDesktopBar::Visibility expected_visibility = - delayed_titlebar_action_ == BRING_UP ? AutoHidingDesktopBar::VISIBLE - : AutoHidingDesktopBar::HIDDEN; + DisplaySettingsProvider::DesktopBarVisibility expected_visibility = + delayed_titlebar_action_ == BRING_UP + ? DisplaySettingsProvider::DESKTOP_BAR_VISIBLE + : DisplaySettingsProvider::DESKTOP_BAR_HIDDEN; if (visibility != expected_visibility) return; diff --git a/chrome/browser/ui/panels/docked_panel_strip.h b/chrome/browser/ui/panels/docked_panel_strip.h index 89cf565..d26fbed 100644 --- a/chrome/browser/ui/panels/docked_panel_strip.h +++ b/chrome/browser/ui/panels/docked_panel_strip.h @@ -10,7 +10,7 @@ #include <set> #include "base/basictypes.h" #include "base/memory/weak_ptr.h" -#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" +#include "chrome/browser/ui/panels/display_settings_provider.h" #include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel_strip.h" #include "chrome/browser/ui/panels/panel_mouse_watcher_observer.h" @@ -88,8 +88,8 @@ class DockedPanelStrip : public PanelStrip, int StartingRightPosition() const; void OnAutoHidingDesktopBarVisibilityChanged( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility); + DisplaySettingsProvider::DesktopBarAlignment alignment, + DisplaySettingsProvider::DesktopBarVisibility visibility); void OnFullScreenModeChanged(bool is_full_screen); diff --git a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc index 3c83c0e..da33eb0 100644 --- a/chrome/browser/ui/panels/panel_browser_view_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browser_view_browsertest.cc @@ -177,14 +177,14 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { // for the purpose of accessing its private members. void TestMinimizeAndRestore(bool enable_auto_hiding) { PanelManager* panel_manager = PanelManager::GetInstance(); - int expected_bottom_on_expanded = testing_work_area().height(); + int expected_bottom_on_expanded = panel_manager->work_area().height(); int expected_bottom_on_title_only = expected_bottom_on_expanded; int expected_bottom_on_minimized = expected_bottom_on_expanded; // Turn on auto-hiding if requested. static const int bottom_thickness = 40; - mock_auto_hiding_desktop_bar()->EnableAutoHiding( - AutoHidingDesktopBar::ALIGN_BOTTOM, + mock_display_settings_provider()->EnableAutoHidingDesktopBar( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, enable_auto_hiding, bottom_thickness); if (enable_auto_hiding) @@ -246,16 +246,18 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { panel3->SetExpansionState(Panel::MINIMIZED); EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); - mock_auto_hiding_desktop_bar()->SetVisibility( - AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::VISIBLE); + mock_display_settings_provider()->SetDesktopBarVisibility( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + DisplaySettingsProvider::DESKTOP_BAR_VISIBLE); panel_manager->BringUpOrDownTitlebars(true); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(Panel::TITLE_ONLY, panel1->expansion_state()); EXPECT_EQ(Panel::EXPANDED, panel2->expansion_state()); EXPECT_EQ(Panel::TITLE_ONLY, panel3->expansion_state()); - mock_auto_hiding_desktop_bar()->SetVisibility( - AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::HIDDEN); + mock_display_settings_provider()->SetDesktopBarVisibility( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + DisplaySettingsProvider::DESKTOP_BAR_HIDDEN); panel_manager->BringUpOrDownTitlebars(false); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); @@ -358,10 +360,14 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { int bottom_bar_thickness = 20; int right_bar_thickness = 30; - mock_auto_hiding_desktop_bar()->EnableAutoHiding( - AutoHidingDesktopBar::ALIGN_BOTTOM, true, bottom_bar_thickness); - mock_auto_hiding_desktop_bar()->EnableAutoHiding( - AutoHidingDesktopBar::ALIGN_RIGHT, true, right_bar_thickness); + mock_display_settings_provider()->EnableAutoHidingDesktopBar( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + true, + bottom_bar_thickness); + mock_display_settings_provider()->EnableAutoHidingDesktopBar( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + true, + right_bar_thickness); EXPECT_EQ( initial_starting_right_position - manager->StartingRightPosition(), right_bar_thickness); @@ -370,9 +376,9 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { panel->SetExpansionState(Panel::TITLE_ONLY); WaitTillBoundsAnimationFinished(panel); - EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, + EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(testing_work_area().right() - right_bar_thickness, + EXPECT_GT(manager->work_area().right() - right_bar_thickness, panel->GetBounds().right()); initial_starting_right_position = manager->StartingRightPosition(); @@ -380,17 +386,19 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { bottom_bar_thickness += bottom_bar_thickness_delta; int right_bar_thickness_delta = 15; right_bar_thickness += right_bar_thickness_delta; - mock_auto_hiding_desktop_bar()->SetThickness( - AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); - mock_auto_hiding_desktop_bar()->SetThickness( - AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); + mock_display_settings_provider()->SetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + bottom_bar_thickness); + mock_display_settings_provider()->SetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + right_bar_thickness); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ( initial_starting_right_position - manager->StartingRightPosition(), right_bar_thickness_delta); - EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, + EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(testing_work_area().right() - right_bar_thickness, + EXPECT_GT(manager->work_area().right() - right_bar_thickness, panel->GetBounds().right()); initial_starting_right_position = manager->StartingRightPosition(); @@ -398,17 +406,19 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { bottom_bar_thickness -= bottom_bar_thickness_delta; right_bar_thickness_delta = 10; right_bar_thickness -= right_bar_thickness_delta; - mock_auto_hiding_desktop_bar()->SetThickness( - AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); - mock_auto_hiding_desktop_bar()->SetThickness( - AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); + mock_display_settings_provider()->SetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + bottom_bar_thickness); + mock_display_settings_provider()->SetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT, + right_bar_thickness); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ( manager->StartingRightPosition() - initial_starting_right_position, right_bar_thickness_delta); - EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, + EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(testing_work_area().right() - right_bar_thickness, + EXPECT_GT(manager->work_area().right() - right_bar_thickness, panel->GetBounds().right()); panel->Close(); diff --git a/chrome/browser/ui/panels/panel_browsertest.cc b/chrome/browser/ui/panels/panel_browsertest.cc index c860e85..c0cd60f 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -428,12 +428,13 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { } IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) { - Panel* panel = CreatePanelWithBounds("BigPanel", testing_work_area()); + gfx::Rect work_area = GetTestingWorkArea(); + Panel* panel = CreatePanelWithBounds("BigPanel", work_area); gfx::Rect bounds = panel->GetBounds(); EXPECT_EQ(panel->max_size().width(), bounds.width()); - EXPECT_LT(bounds.width(), testing_work_area().width()); + EXPECT_LT(bounds.width(), work_area.width()); EXPECT_EQ(panel->max_size().height(), bounds.height()); - EXPECT_LT(bounds.height(), testing_work_area().height()); + EXPECT_LT(bounds.height(), work_area.height()); panel->Close(); } @@ -963,7 +964,7 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, DISABLED_AutoResize) { PanelManager* panel_manager = PanelManager::GetInstance(); panel_manager->enable_auto_sizing(true); // Bigger space is needed by this test. - panel_manager->SetWorkAreaForTesting(gfx::Rect(0, 0, 1200, 900)); + SetTestingWorkArea(gfx::Rect(0, 0, 1200, 900)); // Create a test panel with tab contents loaded. CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); @@ -2024,15 +2025,18 @@ IN_PROC_BROWSER_TEST_F(PanelDownloadTest, MAYBE_DownloadNoTabbedBrowser) { class PanelAndNotificationTest : public PanelBrowserTest { public: PanelAndNotificationTest() : PanelBrowserTest() { - // Do not use our own testing work area since desktop notification code - // does not have the hook up for testing work area. - set_testing_work_area(gfx::Rect()); } virtual ~PanelAndNotificationTest() { } virtual void SetUpOnMainThread() OVERRIDE { + PanelBrowserTest::SetUpOnMainThread(); + + // Do not use our own testing work area since desktop notification code + // does not have the hook up for testing work area. + SetTestingWorkArea(gfx::Rect()); + g_browser_process->local_state()->SetInteger( prefs::kDesktopNotificationPosition, BalloonCollection::LOWER_RIGHT); balloons_ = new BalloonCollectionImpl(); @@ -2040,8 +2044,6 @@ class PanelAndNotificationTest : public PanelBrowserTest { g_browser_process->local_state(), balloons_)); service_.reset(new DesktopNotificationService(browser()->profile(), ui_manager_.get())); - - PanelBrowserTest::SetUpOnMainThread(); } virtual void CleanUpOnMainThread() OVERRIDE { diff --git a/chrome/browser/ui/panels/panel_manager.cc b/chrome/browser/ui/panels/panel_manager.cc index 22195b6..8b06ce7 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -21,7 +21,6 @@ #include "chrome/common/chrome_version_info.h" #include "content/public/browser/notification_service.h" #include "content/public/browser/notification_source.h" -#include "ui/gfx/screen.h" namespace { const int kOverflowStripThickness = 26; @@ -71,7 +70,8 @@ PanelManager::PanelManager() docked_strip_.reset(new DockedPanelStrip(this)); overflow_strip_.reset(new OverflowPanelStrip(this)); drag_controller_.reset(new PanelDragController()); - auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); + display_settings_provider_.reset(DisplaySettingsProvider::Create(this)); + OnDisplayChanged(); } @@ -79,23 +79,12 @@ PanelManager::~PanelManager() { } void PanelManager::OnDisplayChanged() { -#if defined(OS_MACOSX) - // On OSX, panels should be dropped all the way to the bottom edge of the - // screen (and overlap Dock). - gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorBounds(); -#else - gfx::Rect work_area = gfx::Screen::GetPrimaryMonitorWorkArea(); -#endif - SetWorkArea(work_area); -} - -void PanelManager::SetWorkArea(const gfx::Rect& work_area) { + gfx::Rect work_area = display_settings_provider_->GetWorkArea(); if (work_area == work_area_) return; work_area_ = work_area; - auto_hiding_desktop_bar_->UpdateWorkArea(work_area_); - AdjustWorkAreaForAutoHidingDesktopBars(); + AdjustWorkAreaForDisplaySettingsProviders(); Layout(); } @@ -116,6 +105,11 @@ void PanelManager::Layout() { } Panel* PanelManager::CreatePanel(Browser* browser) { + // Need to sync the display area if no panel is present. This is because we + // could only get display area notifications through a panel window. + if (num_panels() == 0) + OnDisplayChanged(); + int width = browser->override_bounds().width(); int height = browser->override_bounds().height(); Panel* panel = new Panel(browser, gfx::Size(width, height)); @@ -249,19 +243,21 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { docked_strip_->BringUpOrDownTitlebars(bring_up); } -void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { +void PanelManager::AdjustWorkAreaForDisplaySettingsProviders() { // Note that we do not care about the desktop bar aligned to the top edge // since panels could not reach so high due to size constraint. adjusted_work_area_ = work_area_; - if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_LEFT)) { - int space = auto_hiding_desktop_bar_->GetThickness( - AutoHidingDesktopBar::ALIGN_LEFT); + if (display_settings_provider_->IsAutoHidingDesktopBarEnabled( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT)) { + int space = display_settings_provider_->GetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT); adjusted_work_area_.set_x(adjusted_work_area_.x() + space); adjusted_work_area_.set_width(adjusted_work_area_.width() - space); } - if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { - int space = auto_hiding_desktop_bar_->GetThickness( - AutoHidingDesktopBar::ALIGN_RIGHT); + if (display_settings_provider_->IsAutoHidingDesktopBarEnabled( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT)) { + int space = display_settings_provider_->GetDesktopBarThickness( + DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT); adjusted_work_area_.set_width(adjusted_work_area_.width() - space); } } @@ -281,13 +277,13 @@ BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( } void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { - AdjustWorkAreaForAutoHidingDesktopBars(); + AdjustWorkAreaForDisplaySettingsProviders(); Layout(); } void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) { + DisplaySettingsProvider::DesktopBarAlignment alignment, + DisplaySettingsProvider::DesktopBarVisibility visibility) { docked_strip_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); } diff --git a/chrome/browser/ui/panels/panel_manager.h b/chrome/browser/ui/panels/panel_manager.h index 3194cf8..7f72726 100644 --- a/chrome/browser/ui/panels/panel_manager.h +++ b/chrome/browser/ui/panels/panel_manager.h @@ -11,7 +11,7 @@ #include "base/lazy_instance.h" #include "base/memory/scoped_ptr.h" #include "base/timer.h" -#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" +#include "chrome/browser/ui/panels/display_settings_provider.h" #include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel_strip.h" #include "ui/gfx/rect.h" @@ -24,7 +24,7 @@ class PanelDragController; class PanelMouseWatcher; // This class manages a set of panels. -class PanelManager : public AutoHidingDesktopBar::Observer { +class PanelManager : public DisplaySettingsProvider::Observer { public: // Returns a single instance. static PanelManager* GetInstance(); @@ -91,8 +91,8 @@ class PanelManager : public AutoHidingDesktopBar::Observer { return drag_controller_.get(); } - AutoHidingDesktopBar* auto_hiding_desktop_bar() const { - return auto_hiding_desktop_bar_; + DisplaySettingsProvider* display_settings_provider() const { + return display_settings_provider_.get(); } PanelMouseWatcher* mouse_watcher() const { @@ -134,9 +134,9 @@ class PanelManager : public AutoHidingDesktopBar::Observer { shorten_time_intervals_ = true; } - void set_auto_hiding_desktop_bar( - AutoHidingDesktopBar* auto_hiding_desktop_bar) { - auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; + void set_display_settings_provider( + DisplaySettingsProvider* display_settings_provider) { + display_settings_provider_.reset(display_settings_provider); } void enable_auto_sizing(bool enabled) { @@ -147,10 +147,6 @@ class PanelManager : public AutoHidingDesktopBar::Observer { return work_area_; } - void SetWorkAreaForTesting(const gfx::Rect& work_area) { - SetWorkArea(work_area); - } - void SetMouseWatcherForTesting(PanelMouseWatcher* watcher) { SetMouseWatcher(watcher); } @@ -162,18 +158,14 @@ class PanelManager : public AutoHidingDesktopBar::Observer { PanelManager(); virtual ~PanelManager(); - // Overridden from AutoHidingDesktopBar::Observer: + // Overridden from DisplaySettingsProvider::Observer: virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; virtual void OnAutoHidingDesktopBarVisibilityChanged( - AutoHidingDesktopBar::Alignment alignment, - AutoHidingDesktopBar::Visibility visibility) OVERRIDE; - - // Applies the new work area. This is called by OnDisplayChanged and the test - // code. - void SetWorkArea(const gfx::Rect& work_area); + DisplaySettingsProvider::DesktopBarAlignment alignment, + DisplaySettingsProvider::DesktopBarVisibility visibility) OVERRIDE; // Adjusts the work area to exclude the influence of auto-hiding desktop bars. - void AdjustWorkAreaForAutoHidingDesktopBars(); + void AdjustWorkAreaForDisplaySettingsProviders(); // Positions the various groupings of panels. void Layout(); @@ -208,7 +200,7 @@ class PanelManager : public AutoHidingDesktopBar::Observer { // right of the screen edges) when they become fully visible. gfx::Rect adjusted_work_area_; - scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_; + scoped_ptr<DisplaySettingsProvider> display_settings_provider_; // Whether or not bounds will be updated when the preferred content size is // changed. The testing code could set this flag to false so that other tests diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi index 90a61dc..3330795 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3402,15 +3402,12 @@ 'browser/ui/options/options_util.cc', 'browser/ui/options/options_util.h', 'browser/ui/page_info_bubble.h', - 'browser/ui/panels/auto_hiding_desktop_bar_aura.cc', - 'browser/ui/panels/auto_hiding_desktop_bar_chromeos.cc', - 'browser/ui/panels/auto_hiding_desktop_bar_cocoa.mm', - 'browser/ui/panels/auto_hiding_desktop_bar_gtk.cc', - 'browser/ui/panels/auto_hiding_desktop_bar_win.cc', - 'browser/ui/panels/auto_hiding_desktop_bar_win.h', - 'browser/ui/panels/auto_hiding_desktop_bar.h', 'browser/ui/panels/detached_panel_strip.cc', 'browser/ui/panels/detached_panel_strip.h', + 'browser/ui/panels/display_settings_provider_win.cc', + 'browser/ui/panels/display_settings_provider_win.h', + 'browser/ui/panels/display_settings_provider.cc', + 'browser/ui/panels/display_settings_provider.h', 'browser/ui/panels/docked_panel_strip.cc', 'browser/ui/panels/docked_panel_strip.h', 'browser/ui/panels/native_panel.h', @@ -4589,7 +4586,7 @@ ['exclude', '^browser/google/google_update.h'], ['exclude', '^browser/hang_monitor/'], ['exclude', '^browser/renderer_host/render_widget_host_view_views*'], - ['exclude', '^browser/ui/panels/auto_hiding_desktop_bar_win.cc'], + ['exclude', '^browser/ui/panels/display_settings_provider_win.cc'], ['exclude', '^browser/ui/tabs/dock_info_win.cc'], ['exclude', '^browser/ui/views/about_ipc_dialog.cc'], ['exclude', '^browser/ui/views/app_menu_button_win.cc'], diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi index a7067fc..2120ed8 100644 --- a/chrome/chrome_tests.gypi +++ b/chrome/chrome_tests.gypi @@ -1987,7 +1987,7 @@ 'browser/ui/intents/web_intents_model_unittest.cc', 'browser/ui/login/login_prompt_unittest.cc', 'browser/ui/omnibox/omnibox_view_unittest.cc', - 'browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc', + 'browser/ui/panels/display_settings_provider_win_unittest.cc', 'browser/ui/panels/panel_browser_window_cocoa_unittest.mm', 'browser/ui/panels/panel_mouse_watcher_unittest.cc', 'browser/ui/prefs/prefs_tab_helper_unittest.cc', @@ -2186,7 +2186,7 @@ ['exclude', '^browser/ui/views/extensions/browser_action_drag_data_unittest.cc'], ['exclude', '^browser/ui/views/select_file_dialog_win_unittest.cc'], ['exclude', '^browser/ui/views/bookmarks/bookmark_editor_view_unittest.cc'], - ['exclude', '^browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc'], + ['exclude', '^browser/ui/panels/display_settings_provider_win_unittest.cc'], ['exclude', '^browser/bookmarks/bookmark_node_data_unittest.cc'], ], }], |