1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
8 #include "base/observer_list.h"
9 #include "base/timer/timer.h"
10 #include "ui/gfx/rect.h"
12 // Encapsulates the logic to provide display settings support, including the
15 // 2) Auto-hiding desktop bars, like Windows taskbar and MacOSX dock.
16 class DisplaySettingsProvider
{
18 // Indicates which screen edge the desktop bar is aligned to.
19 // We do not care about the desktop aligned to the top screen edge.
20 enum DesktopBarAlignment
{
21 DESKTOP_BAR_ALIGNED_BOTTOM
= 0,
22 DESKTOP_BAR_ALIGNED_LEFT
= 1,
23 DESKTOP_BAR_ALIGNED_RIGHT
= 2
26 // Indicates current visibility state of the desktop bar.
27 enum DesktopBarVisibility
{
29 DESKTOP_BAR_ANIMATING
,
33 class DisplayObserver
{
35 virtual void OnDisplayChanged() = 0;
38 class DesktopBarObserver
{
40 virtual void OnAutoHidingDesktopBarVisibilityChanged(
41 DesktopBarAlignment alignment
, DesktopBarVisibility visibility
) = 0;
42 virtual void OnAutoHidingDesktopBarThicknessChanged(
43 DesktopBarAlignment alignment
, int thickness
) = 0;
46 class FullScreenObserver
{
48 virtual void OnFullScreenModeChanged(bool is_full_screen
) = 0;
51 static DisplaySettingsProvider
* Create();
53 virtual ~DisplaySettingsProvider();
55 // Subscribes/unsubscribes from the display settings change notification.
56 void AddDisplayObserver(DisplayObserver
* observer
);
57 void RemoveDisplayObserver(DisplayObserver
* observer
);
59 void AddDesktopBarObserver(DesktopBarObserver
* observer
);
60 void RemoveDesktopBarObserver(DesktopBarObserver
* observer
);
62 void AddFullScreenObserver(FullScreenObserver
* observer
);
63 void RemoveFullScreenObserver(FullScreenObserver
* observer
);
67 // This is the area of a display (monitor). There could be multiple display
70 // This is the standard work area returned by the system. It is usually
71 // computed by the system as the part of display area that excludes
72 // top-most system menu or bars aligned to the screen edges.
75 // Returns the bounds of primary display.
76 virtual gfx::Rect
GetPrimaryDisplayArea() const;
78 // Returns the bounds of the work area of primary display.
79 virtual gfx::Rect
GetPrimaryWorkArea() const;
81 // Returns the bounds of the display area that most closely intersects the
83 virtual gfx::Rect
GetDisplayAreaMatching(const gfx::Rect
& bounds
) const;
85 // Returns the bounds of the work area that most closely intersects the
87 virtual gfx::Rect
GetWorkAreaMatching(const gfx::Rect
& bounds
) const;
89 // Invoked when the display settings has changed, due to any of the following:
90 // 1) screen resolution changes
91 // 2) the thickness of desktop bar changes
92 // 3) desktop bar switches between auto-hiding and non-auto-hiding
93 virtual void OnDisplaySettingsChanged();
95 // Returns true if there is a desktop bar that is aligned to the specified
96 // screen edge and set to auto-hide.
97 virtual bool IsAutoHidingDesktopBarEnabled(DesktopBarAlignment alignment
);
99 // Returns the thickness of the desktop bar that is aligned to the specified
100 // screen edge, when it is visible. When the desktop bar is aligned to bottom
101 // edge, this is the height of the bar. If the desktop bar is aligned to
102 // left or right edge, this is the width of the bar.
103 virtual int GetDesktopBarThickness(DesktopBarAlignment alignment
) const;
105 // Returns the visibility state of the desktop bar that is aligned to the
106 // specified screen edge.
107 virtual DesktopBarVisibility
GetDesktopBarVisibility(
108 DesktopBarAlignment alignment
) const;
110 ObserverList
<DisplayObserver
>& display_observers() {
111 return display_observers_
;
114 ObserverList
<DesktopBarObserver
>& desktop_bar_observers() {
115 return desktop_bar_observers_
;
118 ObserverList
<FullScreenObserver
>& full_screen_observers() {
119 return full_screen_observers_
;
122 bool is_full_screen() const { return is_full_screen_
; }
125 enum FullScreenCheckMode
{
126 ASSUME_FULLSCREEN_ON
,
127 ASSUME_FULLSCREEN_OFF
,
128 PERFORM_FULLSCREEN_CHECK
131 DisplaySettingsProvider();
133 // Returns true if we need to perform fullscreen check periodically.
134 virtual bool NeedsPeriodicFullScreenCheck() const;
136 // Returns true if full screen or presentation mode in main screen is entered.
137 virtual bool IsFullScreen();
139 // Callback to perform periodic check for full screen mode changes.
140 void CheckFullScreenMode(FullScreenCheckMode check_mode
);
143 // Observers that listen to various display settings changes.
144 ObserverList
<DisplayObserver
> display_observers_
;
145 ObserverList
<DesktopBarObserver
> desktop_bar_observers_
;
146 ObserverList
<FullScreenObserver
> full_screen_observers_
;
148 // True if full screen mode or presentation mode is entered.
149 bool is_full_screen_
;
151 // Timer used to detect full-screen mode change.
152 base::RepeatingTimer
<DisplaySettingsProvider
> full_screen_mode_timer_
;
154 DISALLOW_COPY_AND_ASSIGN(DisplaySettingsProvider
);
157 #endif // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_