- add sources.
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / panels / display_settings_provider.h
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.
4
5 #ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
7
8 #include "base/observer_list.h"
9 #include "base/timer/timer.h"
10 #include "ui/gfx/rect.h"
11
12 // Encapsulates the logic to provide display settings support, including the
13 // information for:
14 // 1) Work area
15 // 2) Auto-hiding desktop bars, like Windows taskbar and MacOSX dock.
16 class DisplaySettingsProvider {
17  public:
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
24   };
25
26   // Indicates current visibility state of the desktop bar.
27   enum DesktopBarVisibility {
28     DESKTOP_BAR_VISIBLE,
29     DESKTOP_BAR_ANIMATING,
30     DESKTOP_BAR_HIDDEN
31   };
32
33   class DisplayObserver {
34    public:
35     virtual void OnDisplayChanged() = 0;
36   };
37
38   class DesktopBarObserver {
39    public:
40     virtual void OnAutoHidingDesktopBarVisibilityChanged(
41         DesktopBarAlignment alignment, DesktopBarVisibility visibility) = 0;
42     virtual void OnAutoHidingDesktopBarThicknessChanged(
43         DesktopBarAlignment alignment, int thickness) = 0;
44   };
45
46   class FullScreenObserver {
47    public:
48     virtual void OnFullScreenModeChanged(bool is_full_screen) = 0;
49   };
50
51   static DisplaySettingsProvider* Create();
52
53   virtual ~DisplaySettingsProvider();
54
55   // Subscribes/unsubscribes from the display settings change notification.
56   void AddDisplayObserver(DisplayObserver* observer);
57   void RemoveDisplayObserver(DisplayObserver* observer);
58
59   void AddDesktopBarObserver(DesktopBarObserver* observer);
60   void RemoveDesktopBarObserver(DesktopBarObserver* observer);
61
62   void AddFullScreenObserver(FullScreenObserver* observer);
63   void RemoveFullScreenObserver(FullScreenObserver* observer);
64
65   //
66   // Display Area:
67   //   This is the area of a display (monitor). There could be multiple display
68   //   areas.
69   // Work Area:
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.
73   //
74
75   // Returns the bounds of primary display.
76   virtual gfx::Rect GetPrimaryDisplayArea() const;
77
78   // Returns the bounds of the work area of primary display.
79   virtual gfx::Rect GetPrimaryWorkArea() const;
80
81   // Returns the bounds of the display area that most closely intersects the
82   // provided bounds.
83   virtual gfx::Rect GetDisplayAreaMatching(const gfx::Rect& bounds) const;
84
85   // Returns the bounds of the work area that most closely intersects the
86   // provided bounds.
87   virtual gfx::Rect GetWorkAreaMatching(const gfx::Rect& bounds) const;
88
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();
94
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);
98
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;
104
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;
109
110   ObserverList<DisplayObserver>& display_observers() {
111     return display_observers_;
112   }
113
114   ObserverList<DesktopBarObserver>& desktop_bar_observers() {
115     return desktop_bar_observers_;
116   }
117
118   ObserverList<FullScreenObserver>& full_screen_observers() {
119     return full_screen_observers_;
120   }
121
122   bool is_full_screen() const { return is_full_screen_; }
123
124  protected:
125   enum FullScreenCheckMode {
126     ASSUME_FULLSCREEN_ON,
127     ASSUME_FULLSCREEN_OFF,
128     PERFORM_FULLSCREEN_CHECK
129   };
130
131   DisplaySettingsProvider();
132
133   // Returns true if we need to perform fullscreen check periodically.
134   virtual bool NeedsPeriodicFullScreenCheck() const;
135
136   // Returns true if full screen or presentation mode in main screen is entered.
137   virtual bool IsFullScreen();
138
139   // Callback to perform periodic check for full screen mode changes.
140   void CheckFullScreenMode(FullScreenCheckMode check_mode);
141
142  private:
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_;
147
148   // True if full screen mode or presentation mode is entered.
149   bool is_full_screen_;
150
151   // Timer used to detect full-screen mode change.
152   base::RepeatingTimer<DisplaySettingsProvider> full_screen_mode_timer_;
153
154   DISALLOW_COPY_AND_ASSIGN(DisplaySettingsProvider);
155 };
156
157 #endif  // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_