Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(501)

Side by Side Diff: chrome/browser/ui/panels/display_settings_provider.h

Issue 10051020: Move full-screen detection logic from PanelManager to DisplaySettingsProvider. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ 5 #ifndef CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
6 #define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ 6 #define CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/observer_list.h"
10 #include "base/timer.h"
9 #include "ui/gfx/rect.h" 11 #include "ui/gfx/rect.h"
10 12
11 // Encapsulates the logic to provide display settings support, including the 13 // Encapsulates the logic to provide display settings support, including the
12 // information for: 14 // information for:
13 // 1) Work area 15 // 1) Work area
14 // 2) Auto-hiding desktop bars, like Windows taskbar and MacOSX dock. 16 // 2) Auto-hiding desktop bars, like Windows taskbar and MacOSX dock.
15 class DisplaySettingsProvider { 17 class DisplaySettingsProvider {
18 private:
19 enum ObserverType {
Dmitry Titov 2012/04/12 00:08:51 I think it would be simpler to have no base type f
jianli 2012/04/12 00:45:17 Done.
20 DISPLAY_AREA_OBSERVER,
21 DESKTOP_BAR_OBSERVER,
22 FULL_SCREEN_OBSERVER
23 };
24
25 // Base class for different kinds of observers.
26 class Observer {
27 public:
28 virtual ObserverType type() const = 0;
29 };
30
16 public: 31 public:
17 // Indicates which screen edge the desktop bar is aligned to. 32 // Indicates which screen edge the desktop bar is aligned to.
18 // We do not care about the desktop aligned to the top screen edge. 33 // We do not care about the desktop aligned to the top screen edge.
19 enum DesktopBarAlignment { 34 enum DesktopBarAlignment {
20 DESKTOP_BAR_ALIGNED_BOTTOM = 0, 35 DESKTOP_BAR_ALIGNED_BOTTOM = 0,
21 DESKTOP_BAR_ALIGNED_LEFT = 1, 36 DESKTOP_BAR_ALIGNED_LEFT = 1,
22 DESKTOP_BAR_ALIGNED_RIGHT = 2 37 DESKTOP_BAR_ALIGNED_RIGHT = 2
23 }; 38 };
24 39
25 // Indicates current visibility state of the desktop bar. 40 // Indicates current visibility state of the desktop bar.
26 enum DesktopBarVisibility { 41 enum DesktopBarVisibility {
27 DESKTOP_BAR_VISIBLE, 42 DESKTOP_BAR_VISIBLE,
28 DESKTOP_BAR_ANIMATING, 43 DESKTOP_BAR_ANIMATING,
29 DESKTOP_BAR_HIDDEN 44 DESKTOP_BAR_HIDDEN
30 }; 45 };
31 46
32 // Observer can listen to the event regarding the display area change. 47 class DisplayAreaObserver : public Observer {
33 class DisplayAreaObserver {
34 public: 48 public:
35 virtual void OnDisplayAreaChanged(const gfx::Rect& display_area) = 0; 49 virtual void OnDisplayAreaChanged(const gfx::Rect& display_area) = 0;
50 private:
51 virtual ObserverType type() const OVERRIDE { return DISPLAY_AREA_OBSERVER; }
36 }; 52 };
37 53
38 // Observer can listen to the event regarding the desktop bar change. 54 class DesktopBarObserver : public Observer {
39 class DesktopBarObserver {
40 public: 55 public:
41 virtual void OnAutoHidingDesktopBarVisibilityChanged( 56 virtual void OnAutoHidingDesktopBarVisibilityChanged(
42 DesktopBarAlignment alignment, DesktopBarVisibility visibility) = 0; 57 DesktopBarAlignment alignment, DesktopBarVisibility visibility) = 0;
58 private:
59 virtual ObserverType type() const OVERRIDE { return DESKTOP_BAR_OBSERVER; }
60 };
61
62 class FullScreenObserver : public Observer {
63 public:
64 virtual void OnFullScreenModeChanged(bool is_full_screen) = 0;
65 private:
66 virtual ObserverType type() const OVERRIDE { return FULL_SCREEN_OBSERVER; }
43 }; 67 };
44 68
45 static DisplaySettingsProvider* Create(); 69 static DisplaySettingsProvider* Create();
46 70
47 virtual ~DisplaySettingsProvider(); 71 virtual ~DisplaySettingsProvider();
48 72
73 // Subscribes/unsubscribes from the display settings change notification.
74 void AddObserver(Observer* observer);
75 void RemoveObserver(Observer* observer);
76
49 // Returns the bounds of the display area. 77 // Returns the bounds of the display area.
50 gfx::Rect GetDisplayArea(); 78 gfx::Rect GetDisplayArea();
51 79
52 // Invoked when the display settings has changed, due to any of the following: 80 // Invoked when the display settings has changed, due to any of the following:
53 // 1) screen resolution changes 81 // 1) screen resolution changes
54 // 2) the thickness of desktop bar changes 82 // 2) the thickness of desktop bar changes
55 // 3) desktop bar switches between auto-hiding and non-auto-hiding 83 // 3) desktop bar switches between auto-hiding and non-auto-hiding
56 virtual void OnDisplaySettingsChanged(); 84 virtual void OnDisplaySettingsChanged();
57 85
58 // Returns true if there is a desktop bar that is aligned to the specified 86 // Returns true if there is a desktop bar that is aligned to the specified
59 // screen edge and set to auto-hide. 87 // screen edge and set to auto-hide.
60 virtual bool IsAutoHidingDesktopBarEnabled(DesktopBarAlignment alignment); 88 virtual bool IsAutoHidingDesktopBarEnabled(DesktopBarAlignment alignment);
61 89
62 // Returns the thickness of the desktop bar that is aligned to the specified 90 // Returns the thickness of the desktop bar that is aligned to the specified
63 // screen edge, when it is visible. When the desktop bar is aligned to bottom 91 // screen edge, when it is visible. When the desktop bar is aligned to bottom
64 // edge, this is the height of the bar. If the desktop bar is aligned to 92 // edge, this is the height of the bar. If the desktop bar is aligned to
65 // left or right edge, this is the width of the bar. 93 // left or right edge, this is the width of the bar.
66 virtual int GetDesktopBarThickness(DesktopBarAlignment alignment) const; 94 virtual int GetDesktopBarThickness(DesktopBarAlignment alignment) const;
67 95
68 // Returns the visibility state of the desktop bar that is aligned to the 96 // Returns the visibility state of the desktop bar that is aligned to the
69 // specified screen edge. 97 // specified screen edge.
70 virtual DesktopBarVisibility GetDesktopBarVisibility( 98 virtual DesktopBarVisibility GetDesktopBarVisibility(
71 DesktopBarAlignment alignment) const; 99 DesktopBarAlignment alignment) const;
72 100
73 DisplayAreaObserver* display_area_observer() const { 101 ObserverList<DisplayAreaObserver>& display_area_observers() {
74 return display_area_observer_; 102 return display_area_observers_;
75 }
76 void set_display_area_observer(DisplayAreaObserver* display_area_observer) {
77 display_area_observer_ = display_area_observer;
78 } 103 }
79 104
80 DesktopBarObserver* desktop_bar_observer() const { 105 ObserverList<DesktopBarObserver>& desktop_bar_observers() {
81 return desktop_bar_observer_; 106 return desktop_bar_observers_;
82 } 107 }
83 void set_desktop_bar_observer(DesktopBarObserver* desktop_bar_observer) { 108
84 desktop_bar_observer_ = desktop_bar_observer; 109 ObserverList<FullScreenObserver>& full_screen_observers() {
110 return full_screen_observers_;
85 } 111 }
86 112
87 gfx::Rect work_area() const { return work_area_; } 113 gfx::Rect work_area() const { return work_area_; }
114 bool is_full_screen() const { return is_full_screen_; }
88 115
89 protected: 116 protected:
90 DisplaySettingsProvider(); 117 DisplaySettingsProvider();
91 118
92 // Returns the bounds of the work area that has not been adjusted to take 119 // Returns the bounds of the work area that has not been adjusted to take
93 // auto-hiding desktop bars into account. This can be overridden by the 120 // auto-hiding desktop bars into account. This can be overridden by the
94 // testing code. 121 // testing code.
95 virtual gfx::Rect GetWorkArea() const; 122 virtual gfx::Rect GetWorkArea() const;
96 123
124 // Callback to perform periodic check for full screen mode changes.
125 virtual void CheckFullScreenMode();
126
97 void OnAutoHidingDesktopBarChanged(); 127 void OnAutoHidingDesktopBarChanged();
98 128
99 private: 129 private:
100 // Adjusts the work area to exclude the influence of auto-hiding desktop bars. 130 // Adjusts the work area to exclude the influence of auto-hiding desktop bars.
101 void AdjustWorkAreaForAutoHidingDesktopBars(); 131 void AdjustWorkAreaForAutoHidingDesktopBars();
102 132
103 DisplayAreaObserver* display_area_observer_; 133 // Observers that listen to various display settings changes.
104 DesktopBarObserver* desktop_bar_observer_; 134 ObserverList<DisplayAreaObserver> display_area_observers_;
135 ObserverList<DesktopBarObserver> desktop_bar_observers_;
136 ObserverList<FullScreenObserver> full_screen_observers_;
105 137
106 // The maximum work area avaialble. This area does not include the area taken 138 // The maximum work area avaialble. This area does not include the area taken
107 // by the always-visible (non-auto-hiding) desktop bars. 139 // by the always-visible (non-auto-hiding) desktop bars.
108 gfx::Rect work_area_; 140 gfx::Rect work_area_;
109 141
110 // The useable work area for computing the panel bounds. This area excludes 142 // The useable work area for computing the panel bounds. This area excludes
111 // the potential area that could be taken by the auto-hiding desktop 143 // the potential area that could be taken by the auto-hiding desktop
112 // bars (we only consider those bars that are aligned to bottom, left, and 144 // bars (we only consider those bars that are aligned to bottom, left, and
113 // right of the screen edges) when they become fully visible. 145 // right of the screen edges) when they become fully visible.
114 gfx::Rect adjusted_work_area_; 146 gfx::Rect adjusted_work_area_;
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_;
dcheng 2012/04/12 00:18:28 Minor nit: DISALLOW_COPY_AND_ASSIGN should be used
jianli 2012/04/12 00:45:17 Done.
115 }; 153 };
116 154
117 #endif // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_ 155 #endif // CHROME_BROWSER_UI_PANELS_DISPLAY_SETTINGS_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/panels/display_settings_provider.cc » ('j') | chrome/browser/ui/panels/panel_manager.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698