diff options
Diffstat (limited to 'chrome')
22 files changed, 683 insertions, 550 deletions
diff --git a/chrome/browser/ui/panels/auto_hiding_desktop_bar.h b/chrome/browser/ui/panels/auto_hiding_desktop_bar.h new file mode 100644 index 0000000..d910a15 --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar.h @@ -0,0 +1,72 @@ +// 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 new file mode 100644 index 0000000..671b7ca --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_aura.cc @@ -0,0 +1,56 @@ +// 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 new file mode 100644 index 0000000..60a8daa --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_chromeos.cc @@ -0,0 +1,56 @@ +// 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 new file mode 100644 index 0000000..7db2c72 --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_cocoa.mm @@ -0,0 +1,61 @@ +// 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 new file mode 100644 index 0000000..e9c5d6ef --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_gtk.cc @@ -0,0 +1,61 @@ +// 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/display_settings_provider_win.cc b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.cc index 156dfca..06ae85a 100644 --- a/chrome/browser/ui/panels/display_settings_provider_win.cc +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.cc @@ -1,8 +1,8 @@ -// Copyright (c) 2012 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. -#include "chrome/browser/ui/panels/display_settings_provider_win.h" +#include "chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h" #include <shellapi.h> @@ -18,16 +18,21 @@ const int kHiddenAutoHideTaskbarThickness = 2; const int kCheckTaskbarPollingIntervalMs = 500; } // namespace -DisplaySettingsProviderWin::DisplaySettingsProviderWin(Observer* observer) - : DisplaySettingsProvider(observer), +AutoHidingDesktopBarWin::AutoHidingDesktopBarWin(Observer* observer) + : observer_(observer), monitor_(NULL) { + DCHECK(observer); memset(taskbars_, 0, sizeof(taskbars_)); } -DisplaySettingsProviderWin::~DisplaySettingsProviderWin() { +AutoHidingDesktopBarWin::~AutoHidingDesktopBarWin() { } -void DisplaySettingsProviderWin::OnWorkAreaChanged() { +void AutoHidingDesktopBarWin::UpdateWorkArea(const gfx::Rect& work_area) { + if (work_area_ == work_area) + return; + work_area_ = work_area; + RECT rect = work_area_.ToRECT(); monitor_ = ::MonitorFromRect(&rect, MONITOR_DEFAULTTOPRIMARY); DCHECK(monitor_); @@ -42,7 +47,7 @@ void DisplaySettingsProviderWin::OnWorkAreaChanged() { polling_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(kCheckTaskbarPollingIntervalMs), this, - &DisplaySettingsProviderWin::OnPollingTimer); + &AutoHidingDesktopBarWin::OnPollingTimer); } } else { if (polling_timer_.IsRunning()) @@ -50,25 +55,24 @@ void DisplaySettingsProviderWin::OnWorkAreaChanged() { } } -bool DisplaySettingsProviderWin::IsAutoHidingDesktopBarEnabled( - DesktopBarAlignment alignment) { +bool AutoHidingDesktopBarWin::IsEnabled( + AutoHidingDesktopBar::Alignment alignment) { CheckTaskbars(false); return taskbars_[static_cast<int>(alignment)].window != NULL; } -int DisplaySettingsProviderWin::GetDesktopBarThickness( - DesktopBarAlignment alignment) const { - return GetDesktopBarThicknessFromBounds(alignment, GetBounds(alignment)); +int AutoHidingDesktopBarWin::GetThickness( + AutoHidingDesktopBar::Alignment alignment) const { + return GetThicknessFromBounds(alignment, GetBounds(alignment)); } -DisplaySettingsProvider::DesktopBarVisibility -DisplaySettingsProviderWin::GetDesktopBarVisibility( - DesktopBarAlignment alignment) const { - return GetDesktopBarVisibilityFromBounds(alignment, GetBounds(alignment)); +AutoHidingDesktopBar::Visibility AutoHidingDesktopBarWin::GetVisibility( + AutoHidingDesktopBar::Alignment alignment) const { + return GetVisibilityFromBounds(alignment, GetBounds(alignment)); } -gfx::Rect DisplaySettingsProviderWin::GetBounds( - DesktopBarAlignment alignment) const { +gfx::Rect AutoHidingDesktopBarWin::GetBounds( + AutoHidingDesktopBar::Alignment alignment) const { HWND taskbar_window = taskbars_[static_cast<int>(alignment)].window; if (!taskbar_window) return gfx::Rect(); @@ -79,14 +83,14 @@ gfx::Rect DisplaySettingsProviderWin::GetBounds( return gfx::Rect(rect); } -int DisplaySettingsProviderWin::GetDesktopBarThicknessFromBounds( - DesktopBarAlignment alignment, +int AutoHidingDesktopBarWin::GetThicknessFromBounds( + AutoHidingDesktopBar::Alignment alignment, const gfx::Rect& taskbar_bounds) const { switch (alignment) { - case DESKTOP_BAR_ALIGNED_BOTTOM: + case AutoHidingDesktopBar::ALIGN_BOTTOM: return taskbar_bounds.height(); - case DESKTOP_BAR_ALIGNED_LEFT: - case DESKTOP_BAR_ALIGNED_RIGHT: + case AutoHidingDesktopBar::ALIGN_LEFT: + case AutoHidingDesktopBar::ALIGN_RIGHT: return taskbar_bounds.width(); default: NOTREACHED(); @@ -94,49 +98,49 @@ int DisplaySettingsProviderWin::GetDesktopBarThicknessFromBounds( } } -DisplaySettingsProvider::DesktopBarVisibility -DisplaySettingsProviderWin::GetDesktopBarVisibilityFromBounds( - DesktopBarAlignment alignment, +AutoHidingDesktopBar::Visibility +AutoHidingDesktopBarWin::GetVisibilityFromBounds( + AutoHidingDesktopBar::Alignment alignment, const gfx::Rect& taskbar_bounds) const { switch (alignment) { - case DESKTOP_BAR_ALIGNED_BOTTOM: + case AutoHidingDesktopBar::ALIGN_BOTTOM: if (taskbar_bounds.bottom() <= work_area_.bottom()) - return DESKTOP_BAR_VISIBLE; + return VISIBLE; else if (taskbar_bounds.y() >= work_area_.bottom() - kHiddenAutoHideTaskbarThickness) - return DESKTOP_BAR_HIDDEN; + return HIDDEN; else - return DESKTOP_BAR_ANIMATING; + return ANIMATING; - case DESKTOP_BAR_ALIGNED_LEFT: + case AutoHidingDesktopBar::ALIGN_LEFT: if (taskbar_bounds.x() >= work_area_.x()) - return DESKTOP_BAR_VISIBLE; + return VISIBLE; else if (taskbar_bounds.right() <= work_area_.x() + kHiddenAutoHideTaskbarThickness) - return DESKTOP_BAR_HIDDEN; + return HIDDEN; else - return DESKTOP_BAR_ANIMATING; + return ANIMATING; - case DESKTOP_BAR_ALIGNED_RIGHT: + case AutoHidingDesktopBar::ALIGN_RIGHT: if (taskbar_bounds.right() <= work_area_.right()) - return DESKTOP_BAR_VISIBLE; + return VISIBLE; else if (taskbar_bounds.x() >= work_area_.right() - kHiddenAutoHideTaskbarThickness) - return DESKTOP_BAR_HIDDEN; + return HIDDEN; else - return DESKTOP_BAR_ANIMATING; + return ANIMATING; default: NOTREACHED(); - return DESKTOP_BAR_VISIBLE; + return VISIBLE; } } -void DisplaySettingsProviderWin::OnPollingTimer() { +void AutoHidingDesktopBarWin::OnPollingTimer() { CheckTaskbars(true); } -bool DisplaySettingsProviderWin::CheckTaskbars(bool notify_observer) { +bool AutoHidingDesktopBarWin::CheckTaskbars(bool notify_observer) { bool taskbar_exists = false; UINT edges[] = { ABE_BOTTOM, ABE_LEFT, ABE_RIGHT }; for (size_t i = 0; i < kMaxTaskbars; ++i) { @@ -148,27 +152,27 @@ bool DisplaySettingsProviderWin::CheckTaskbars(bool notify_observer) { if (!taskbar_exists) { for (size_t i = 0; i < kMaxTaskbars; ++i) { taskbars_[i].thickness = 0; - taskbars_[i].visibility = DESKTOP_BAR_HIDDEN; + taskbars_[i].visibility = AutoHidingDesktopBar::HIDDEN; } return false; } bool thickness_changed = false; for (size_t i = 0; i < kMaxTaskbars; ++i) { - DesktopBarAlignment alignment = static_cast<DesktopBarAlignment>(i); + AutoHidingDesktopBar::Alignment alignment = static_cast<Alignment>(i); gfx::Rect bounds = GetBounds(alignment); // Check the thickness change. - int thickness = GetDesktopBarThicknessFromBounds(alignment, bounds); + int thickness = GetThicknessFromBounds(alignment, bounds); if (thickness != taskbars_[i].thickness) { taskbars_[i].thickness = thickness; thickness_changed = true; } // Check and notify the visibility change. - DesktopBarVisibility visibility = GetDesktopBarVisibilityFromBounds( - alignment, bounds); + AutoHidingDesktopBar::Visibility visibility = + GetVisibilityFromBounds(alignment, bounds); if (visibility != taskbars_[i].visibility) { taskbars_[i].visibility = visibility; if (notify_observer) { @@ -186,6 +190,6 @@ bool DisplaySettingsProviderWin::CheckTaskbars(bool notify_observer) { } // static -DisplaySettingsProvider* DisplaySettingsProvider::Create(Observer* observer) { - return new DisplaySettingsProviderWin(observer); +AutoHidingDesktopBar* AutoHidingDesktopBar::Create(Observer* observer) { + return new AutoHidingDesktopBarWin(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 new file mode 100644 index 0000000..5bc1206 --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win.h @@ -0,0 +1,66 @@ +// 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 new file mode 100644 index 0000000..0a3ca3f --- /dev/null +++ b/chrome/browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc @@ -0,0 +1,67 @@ +// 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 1bce3a3..f5cc68c 100644 --- a/chrome/browser/ui/panels/base_panel_browser_test.cc +++ b/chrome/browser/ui/panels/base_panel_browser_test.cc @@ -37,92 +37,85 @@ namespace { const int kTestingWorkAreaWidth = 800; const int kTestingWorkAreaHeight = 600; +const int kDefaultAutoHidingDesktopBarThickness = 40; struct MockDesktopBar { bool auto_hiding_enabled; - DisplaySettingsProvider::DesktopBarVisibility visibility; + AutoHidingDesktopBar::Visibility visibility; int thickness; }; -class MockDisplaySettingsProviderImpl : - public BasePanelBrowserTest::MockDisplaySettingsProvider { +class MockAutoHidingDesktopBarImpl : + public BasePanelBrowserTest::MockAutoHidingDesktopBar { public: - 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; + 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; } private: - void NotifyDesktopBarVisibilityChange(DesktopBarAlignment alignment, - DesktopBarVisibility visibility); - void NotifyDesktopBarThicknessChange(); + void NotifyVisibilityChange(Alignment alignment, Visibility visibility); + void NotifyThicknessChange(); + Observer* observer_; MockDesktopBar mock_desktop_bars[3]; + base::WeakPtrFactory<MockAutoHidingDesktopBarImpl> method_factory_; - DISALLOW_COPY_AND_ASSIGN(MockDisplaySettingsProviderImpl); + DISALLOW_COPY_AND_ASSIGN(MockAutoHidingDesktopBarImpl); }; -MockDisplaySettingsProviderImpl::MockDisplaySettingsProviderImpl( - DisplaySettingsProvider::Observer* observer) - : MockDisplaySettingsProvider(observer) { +MockAutoHidingDesktopBarImpl::MockAutoHidingDesktopBarImpl( + AutoHidingDesktopBar::Observer* observer) + : observer_(observer), method_factory_(this) { memset(mock_desktop_bars, 0, sizeof(mock_desktop_bars)); } -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_; +void MockAutoHidingDesktopBarImpl::UpdateWorkArea( + const gfx::Rect& work_area) { } -bool MockDisplaySettingsProviderImpl::IsAutoHidingDesktopBarEnabled( - DesktopBarAlignment alignment) { +bool MockAutoHidingDesktopBarImpl::IsEnabled( + AutoHidingDesktopBar::Alignment alignment) { return mock_desktop_bars[static_cast<int>(alignment)].auto_hiding_enabled; } -int MockDisplaySettingsProviderImpl::GetDesktopBarThickness( - DesktopBarAlignment alignment) const { +int MockAutoHidingDesktopBarImpl::GetThickness( + AutoHidingDesktopBar::Alignment alignment) const { return mock_desktop_bars[static_cast<int>(alignment)].thickness; } -DisplaySettingsProvider::DesktopBarVisibility -MockDisplaySettingsProviderImpl::GetDesktopBarVisibility( - DesktopBarAlignment alignment) const { +AutoHidingDesktopBar::Visibility +MockAutoHidingDesktopBarImpl::GetVisibility( + AutoHidingDesktopBar::Alignment alignment) const { return mock_desktop_bars[static_cast<int>(alignment)].visibility; } -void MockDisplaySettingsProviderImpl::EnableAutoHidingDesktopBar( - DesktopBarAlignment alignment, bool enabled, int thickness) { +void MockAutoHidingDesktopBarImpl::EnableAutoHiding( + AutoHidingDesktopBar::Alignment 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 MockDisplaySettingsProviderImpl::SetWorkArea(const gfx::Rect& work_area) { - work_area_ = work_area; -} - -void MockDisplaySettingsProviderImpl::SetDesktopBarVisibility( - DesktopBarAlignment alignment, DesktopBarVisibility visibility) { +void MockAutoHidingDesktopBarImpl::SetVisibility( + AutoHidingDesktopBar::Alignment alignment, + AutoHidingDesktopBar::Visibility visibility) { MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); if (!bar->auto_hiding_enabled) return; @@ -131,15 +124,14 @@ void MockDisplaySettingsProviderImpl::SetDesktopBarVisibility( bar->visibility = visibility; MessageLoop::current()->PostTask( FROM_HERE, - base::Bind( - &MockDisplaySettingsProviderImpl::NotifyDesktopBarVisibilityChange, - base::Unretained(this), - alignment, - visibility)); + base::Bind(&MockAutoHidingDesktopBarImpl::NotifyVisibilityChange, + method_factory_.GetWeakPtr(), + alignment, + visibility)); } -void MockDisplaySettingsProviderImpl::SetDesktopBarThickness( - DesktopBarAlignment alignment, int thickness) { +void MockAutoHidingDesktopBarImpl::SetThickness( + AutoHidingDesktopBar::Alignment alignment, int thickness) { MockDesktopBar* bar = &(mock_desktop_bars[static_cast<int>(alignment)]); if (!bar->auto_hiding_enabled) return; @@ -148,18 +140,17 @@ void MockDisplaySettingsProviderImpl::SetDesktopBarThickness( bar->thickness = thickness; MessageLoop::current()->PostTask( FROM_HERE, - base::Bind( - &MockDisplaySettingsProviderImpl::NotifyDesktopBarThicknessChange, - base::Unretained(this))); + base::Bind(&MockAutoHidingDesktopBarImpl::NotifyThicknessChange, + method_factory_.GetWeakPtr())); } -void MockDisplaySettingsProviderImpl::NotifyDesktopBarVisibilityChange( - DesktopBarAlignment alignment, - DesktopBarVisibility visibility) { +void MockAutoHidingDesktopBarImpl::NotifyVisibilityChange( + AutoHidingDesktopBar::Alignment alignment, + AutoHidingDesktopBar::Visibility visibility) { observer_->OnAutoHidingDesktopBarVisibilityChanged(alignment, visibility); } -void MockDisplaySettingsProviderImpl::NotifyDesktopBarThicknessChange() { +void MockAutoHidingDesktopBarImpl::NotifyThicknessChange() { observer_->OnAutoHidingDesktopBarThicknessChanged(); } @@ -174,7 +165,9 @@ const FilePath::CharType* BasePanelBrowserTest::kTestDir = FILE_PATH_LITERAL("panels"); BasePanelBrowserTest::BasePanelBrowserTest() - : InProcessBrowserTest() { + : InProcessBrowserTest(), + testing_work_area_(0, 0, kTestingWorkAreaWidth, + kTestingWorkAreaHeight) { #if defined(OS_MACOSX) FindBarBridge::disable_animations_during_testing_ = true; #endif @@ -210,12 +203,13 @@ 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_display_settings_provider_ = new MockDisplaySettingsProviderImpl( + mock_auto_hiding_desktop_bar_ = new MockAutoHidingDesktopBarImpl( panel_manager); - panel_manager->set_display_settings_provider(mock_display_settings_provider_); - SetTestingWorkArea(gfx::Rect( - 0, 0, kTestingWorkAreaWidth, kTestingWorkAreaHeight)); - + 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->enable_auto_sizing(false); PanelManager::shorten_time_intervals_for_testing(); @@ -428,15 +422,6 @@ 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 e96f504..ad86073 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/display_settings_provider.h" +#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.h" #include "chrome/browser/ui/panels/panel.h" #include "chrome/browser/ui/panels/panel_strip.h" #include "chrome/common/extensions/extension.h" @@ -17,21 +17,15 @@ class BasePanelBrowserTest : public InProcessBrowserTest { public: - class MockDisplaySettingsProvider : public DisplaySettingsProvider { + class MockAutoHidingDesktopBar : public AutoHidingDesktopBar { public: - 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; + 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; }; BasePanelBrowserTest(); @@ -99,17 +93,19 @@ class BasePanelBrowserTest : public InProcessBrowserTest { static void CloseWindowAndWait(Browser* browser); static std::string MakePanelName(int index); - gfx::Rect GetTestingWorkArea() const; - void SetTestingWorkArea(const gfx::Rect& work_area); + 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; + } - MockDisplaySettingsProvider* mock_display_settings_provider() const { - return mock_display_settings_provider_; + MockAutoHidingDesktopBar* mock_auto_hiding_desktop_bar() const { + return mock_auto_hiding_desktop_bar_.get(); } static const FilePath::CharType* kTestDir; private: - // Passed to and owned by PanelManager. - MockDisplaySettingsProvider* mock_display_settings_provider_; + gfx::Rect testing_work_area_; + scoped_refptr<MockAutoHidingDesktopBar> mock_auto_hiding_desktop_bar_; }; #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 deleted file mode 100644 index 05c0dc5..0000000 --- a/chrome/browser/ui/panels/display_settings_provider.cc +++ /dev/null @@ -1,59 +0,0 @@ -// 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 deleted file mode 100644 index 4dab327..0000000 --- a/chrome/browser/ui/panels/display_settings_provider.h +++ /dev/null @@ -1,85 +0,0 @@ -// 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/display_settings_provider_win.h b/chrome/browser/ui/panels/display_settings_provider_win.h deleted file mode 100644 index 3c134f2..0000000 --- a/chrome/browser/ui/panels/display_settings_provider_win.h +++ /dev/null @@ -1,62 +0,0 @@ -// 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 deleted file mode 100644 index dd3565f..0000000 --- a/chrome/browser/ui/panels/display_settings_provider_win_unittest.cc +++ /dev/null @@ -1,77 +0,0 @@ -// 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 63d8597..57a4bee 100644 --- a/chrome/browser/ui/panels/docked_panel_strip.cc +++ b/chrome/browser/ui/panels/docked_panel_strip.cc @@ -503,13 +503,10 @@ 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. - 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 && + AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); + if (desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM) && + desktop_bar->GetVisibility(AutoHidingDesktopBar::ALIGN_BOTTOM) == + AutoHidingDesktopBar::VISIBLE && mouse_y >= display_area_.bottom()) return true; @@ -550,16 +547,12 @@ 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. - 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)) { + 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)) { // 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 @@ -640,13 +633,10 @@ 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. - DisplaySettingsProvider* provider = - panel_manager_->display_settings_provider(); + AutoHidingDesktopBar* desktop_bar = panel_manager_->auto_hiding_desktop_bar(); if (expansion_state == Panel::TITLE_ONLY && - provider->IsAutoHidingDesktopBarEnabled( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM)) { - bottom -= provider->GetDesktopBarThickness( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM); + desktop_bar->IsEnabled(AutoHidingDesktopBar::ALIGN_BOTTOM)) { + bottom -= desktop_bar->GetThickness(AutoHidingDesktopBar::ALIGN_BOTTOM); } return bottom; @@ -659,15 +649,14 @@ void DockedPanelStrip::OnMouseMove(const gfx::Point& mouse_position) { } void DockedPanelStrip::OnAutoHidingDesktopBarVisibilityChanged( - DisplaySettingsProvider::DesktopBarAlignment alignment, - DisplaySettingsProvider::DesktopBarVisibility visibility) { + AutoHidingDesktopBar::Alignment alignment, + AutoHidingDesktopBar::Visibility visibility) { if (delayed_titlebar_action_ == NO_ACTION) return; - DisplaySettingsProvider::DesktopBarVisibility expected_visibility = - delayed_titlebar_action_ == BRING_UP - ? DisplaySettingsProvider::DESKTOP_BAR_VISIBLE - : DisplaySettingsProvider::DESKTOP_BAR_HIDDEN; + AutoHidingDesktopBar::Visibility expected_visibility = + delayed_titlebar_action_ == BRING_UP ? AutoHidingDesktopBar::VISIBLE + : AutoHidingDesktopBar::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 d26fbed..89cf565 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/display_settings_provider.h" +#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.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( - DisplaySettingsProvider::DesktopBarAlignment alignment, - DisplaySettingsProvider::DesktopBarVisibility visibility); + AutoHidingDesktopBar::Alignment alignment, + AutoHidingDesktopBar::Visibility 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 da33eb0..3c83c0e 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 = panel_manager->work_area().height(); + int expected_bottom_on_expanded = testing_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_display_settings_provider()->EnableAutoHidingDesktopBar( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, + mock_auto_hiding_desktop_bar()->EnableAutoHiding( + AutoHidingDesktopBar::ALIGN_BOTTOM, enable_auto_hiding, bottom_thickness); if (enable_auto_hiding) @@ -246,18 +246,16 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { panel3->SetExpansionState(Panel::MINIMIZED); EXPECT_EQ(Panel::MINIMIZED, panel3->expansion_state()); - mock_display_settings_provider()->SetDesktopBarVisibility( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, - DisplaySettingsProvider::DESKTOP_BAR_VISIBLE); + mock_auto_hiding_desktop_bar()->SetVisibility( + AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::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_display_settings_provider()->SetDesktopBarVisibility( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_BOTTOM, - DisplaySettingsProvider::DESKTOP_BAR_HIDDEN); + mock_auto_hiding_desktop_bar()->SetVisibility( + AutoHidingDesktopBar::ALIGN_BOTTOM, AutoHidingDesktopBar::HIDDEN); panel_manager->BringUpOrDownTitlebars(false); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ(Panel::MINIMIZED, panel1->expansion_state()); @@ -360,14 +358,10 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { int bottom_bar_thickness = 20; int right_bar_thickness = 30; - 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); + 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); EXPECT_EQ( initial_starting_right_position - manager->StartingRightPosition(), right_bar_thickness); @@ -376,9 +370,9 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { panel->SetExpansionState(Panel::TITLE_ONLY); WaitTillBoundsAnimationFinished(panel); - EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, + EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(manager->work_area().right() - right_bar_thickness, + EXPECT_GT(testing_work_area().right() - right_bar_thickness, panel->GetBounds().right()); initial_starting_right_position = manager->StartingRightPosition(); @@ -386,19 +380,17 @@ 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_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); + mock_auto_hiding_desktop_bar()->SetThickness( + AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); + mock_auto_hiding_desktop_bar()->SetThickness( + AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ( initial_starting_right_position - manager->StartingRightPosition(), right_bar_thickness_delta); - EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, + EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(manager->work_area().right() - right_bar_thickness, + EXPECT_GT(testing_work_area().right() - right_bar_thickness, panel->GetBounds().right()); initial_starting_right_position = manager->StartingRightPosition(); @@ -406,19 +398,17 @@ class PanelBrowserViewTest : public BasePanelBrowserTest { bottom_bar_thickness -= bottom_bar_thickness_delta; right_bar_thickness_delta = 10; right_bar_thickness -= right_bar_thickness_delta; - 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); + mock_auto_hiding_desktop_bar()->SetThickness( + AutoHidingDesktopBar::ALIGN_BOTTOM, bottom_bar_thickness); + mock_auto_hiding_desktop_bar()->SetThickness( + AutoHidingDesktopBar::ALIGN_RIGHT, right_bar_thickness); MessageLoopForUI::current()->RunAllPending(); EXPECT_EQ( manager->StartingRightPosition() - initial_starting_right_position, right_bar_thickness_delta); - EXPECT_EQ(manager->work_area().height() - bottom_bar_thickness, + EXPECT_EQ(testing_work_area().height() - bottom_bar_thickness, panel->GetBounds().bottom()); - EXPECT_GT(manager->work_area().right() - right_bar_thickness, + EXPECT_GT(testing_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 c0cd60f..c860e85 100644 --- a/chrome/browser/ui/panels/panel_browsertest.cc +++ b/chrome/browser/ui/panels/panel_browsertest.cc @@ -428,13 +428,12 @@ IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreatePanel) { } IN_PROC_BROWSER_TEST_F(PanelBrowserTest, CreateBigPanel) { - gfx::Rect work_area = GetTestingWorkArea(); - Panel* panel = CreatePanelWithBounds("BigPanel", work_area); + Panel* panel = CreatePanelWithBounds("BigPanel", testing_work_area()); gfx::Rect bounds = panel->GetBounds(); EXPECT_EQ(panel->max_size().width(), bounds.width()); - EXPECT_LT(bounds.width(), work_area.width()); + EXPECT_LT(bounds.width(), testing_work_area().width()); EXPECT_EQ(panel->max_size().height(), bounds.height()); - EXPECT_LT(bounds.height(), work_area.height()); + EXPECT_LT(bounds.height(), testing_work_area().height()); panel->Close(); } @@ -964,7 +963,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. - SetTestingWorkArea(gfx::Rect(0, 0, 1200, 900)); + panel_manager->SetWorkAreaForTesting(gfx::Rect(0, 0, 1200, 900)); // Create a test panel with tab contents loaded. CreatePanelParams params("PanelTest1", gfx::Rect(), SHOW_AS_ACTIVE); @@ -2025,18 +2024,15 @@ 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(); @@ -2044,6 +2040,8 @@ 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 8b06ce7..22195b6 100644 --- a/chrome/browser/ui/panels/panel_manager.cc +++ b/chrome/browser/ui/panels/panel_manager.cc @@ -21,6 +21,7 @@ #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; @@ -70,8 +71,7 @@ PanelManager::PanelManager() docked_strip_.reset(new DockedPanelStrip(this)); overflow_strip_.reset(new OverflowPanelStrip(this)); drag_controller_.reset(new PanelDragController()); - display_settings_provider_.reset(DisplaySettingsProvider::Create(this)); - + auto_hiding_desktop_bar_ = AutoHidingDesktopBar::Create(this); OnDisplayChanged(); } @@ -79,12 +79,23 @@ PanelManager::~PanelManager() { } void PanelManager::OnDisplayChanged() { - gfx::Rect work_area = display_settings_provider_->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 + SetWorkArea(work_area); +} + +void PanelManager::SetWorkArea(const gfx::Rect& work_area) { if (work_area == work_area_) return; work_area_ = work_area; - AdjustWorkAreaForDisplaySettingsProviders(); + auto_hiding_desktop_bar_->UpdateWorkArea(work_area_); + AdjustWorkAreaForAutoHidingDesktopBars(); Layout(); } @@ -105,11 +116,6 @@ 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)); @@ -243,21 +249,19 @@ void PanelManager::BringUpOrDownTitlebars(bool bring_up) { docked_strip_->BringUpOrDownTitlebars(bring_up); } -void PanelManager::AdjustWorkAreaForDisplaySettingsProviders() { +void PanelManager::AdjustWorkAreaForAutoHidingDesktopBars() { // 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 (display_settings_provider_->IsAutoHidingDesktopBarEnabled( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT)) { - int space = display_settings_provider_->GetDesktopBarThickness( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_LEFT); + if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_LEFT)) { + int space = auto_hiding_desktop_bar_->GetThickness( + AutoHidingDesktopBar::ALIGN_LEFT); adjusted_work_area_.set_x(adjusted_work_area_.x() + space); adjusted_work_area_.set_width(adjusted_work_area_.width() - space); } - if (display_settings_provider_->IsAutoHidingDesktopBarEnabled( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT)) { - int space = display_settings_provider_->GetDesktopBarThickness( - DisplaySettingsProvider::DESKTOP_BAR_ALIGNED_RIGHT); + if (auto_hiding_desktop_bar_->IsEnabled(AutoHidingDesktopBar::ALIGN_RIGHT)) { + int space = auto_hiding_desktop_bar_->GetThickness( + AutoHidingDesktopBar::ALIGN_RIGHT); adjusted_work_area_.set_width(adjusted_work_area_.width() - space); } } @@ -277,13 +281,13 @@ BrowserWindow* PanelManager::GetNextBrowserWindowToActivate( } void PanelManager::OnAutoHidingDesktopBarThicknessChanged() { - AdjustWorkAreaForDisplaySettingsProviders(); + AdjustWorkAreaForAutoHidingDesktopBars(); Layout(); } void PanelManager::OnAutoHidingDesktopBarVisibilityChanged( - DisplaySettingsProvider::DesktopBarAlignment alignment, - DisplaySettingsProvider::DesktopBarVisibility visibility) { + AutoHidingDesktopBar::Alignment alignment, + AutoHidingDesktopBar::Visibility 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 7f72726..3194cf8 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/display_settings_provider.h" +#include "chrome/browser/ui/panels/auto_hiding_desktop_bar.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 DisplaySettingsProvider::Observer { +class PanelManager : public AutoHidingDesktopBar::Observer { public: // Returns a single instance. static PanelManager* GetInstance(); @@ -91,8 +91,8 @@ class PanelManager : public DisplaySettingsProvider::Observer { return drag_controller_.get(); } - DisplaySettingsProvider* display_settings_provider() const { - return display_settings_provider_.get(); + AutoHidingDesktopBar* auto_hiding_desktop_bar() const { + return auto_hiding_desktop_bar_; } PanelMouseWatcher* mouse_watcher() const { @@ -134,9 +134,9 @@ class PanelManager : public DisplaySettingsProvider::Observer { shorten_time_intervals_ = true; } - void set_display_settings_provider( - DisplaySettingsProvider* display_settings_provider) { - display_settings_provider_.reset(display_settings_provider); + void set_auto_hiding_desktop_bar( + AutoHidingDesktopBar* auto_hiding_desktop_bar) { + auto_hiding_desktop_bar_ = auto_hiding_desktop_bar; } void enable_auto_sizing(bool enabled) { @@ -147,6 +147,10 @@ class PanelManager : public DisplaySettingsProvider::Observer { return work_area_; } + void SetWorkAreaForTesting(const gfx::Rect& work_area) { + SetWorkArea(work_area); + } + void SetMouseWatcherForTesting(PanelMouseWatcher* watcher) { SetMouseWatcher(watcher); } @@ -158,14 +162,18 @@ class PanelManager : public DisplaySettingsProvider::Observer { PanelManager(); virtual ~PanelManager(); - // Overridden from DisplaySettingsProvider::Observer: + // Overridden from AutoHidingDesktopBar::Observer: virtual void OnAutoHidingDesktopBarThicknessChanged() OVERRIDE; virtual void OnAutoHidingDesktopBarVisibilityChanged( - DisplaySettingsProvider::DesktopBarAlignment alignment, - DisplaySettingsProvider::DesktopBarVisibility visibility) OVERRIDE; + 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); // Adjusts the work area to exclude the influence of auto-hiding desktop bars. - void AdjustWorkAreaForDisplaySettingsProviders(); + void AdjustWorkAreaForAutoHidingDesktopBars(); // Positions the various groupings of panels. void Layout(); @@ -200,7 +208,7 @@ class PanelManager : public DisplaySettingsProvider::Observer { // right of the screen edges) when they become fully visible. gfx::Rect adjusted_work_area_; - scoped_ptr<DisplaySettingsProvider> display_settings_provider_; + scoped_refptr<AutoHidingDesktopBar> auto_hiding_desktop_bar_; // 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 3330795..90a61dc 100644 --- a/chrome/chrome_browser.gypi +++ b/chrome/chrome_browser.gypi @@ -3402,12 +3402,15 @@ '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', @@ -4586,7 +4589,7 @@ ['exclude', '^browser/google/google_update.h'], ['exclude', '^browser/hang_monitor/'], ['exclude', '^browser/renderer_host/render_widget_host_view_views*'], - ['exclude', '^browser/ui/panels/display_settings_provider_win.cc'], + ['exclude', '^browser/ui/panels/auto_hiding_desktop_bar_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 2120ed8..a7067fc 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/display_settings_provider_win_unittest.cc', + 'browser/ui/panels/auto_hiding_desktop_bar_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/display_settings_provider_win_unittest.cc'], + ['exclude', '^browser/ui/panels/auto_hiding_desktop_bar_win_unittest.cc'], ['exclude', '^browser/bookmarks/bookmark_node_data_unittest.cc'], ], }], |
