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

Side by Side Diff: chrome/browser/ui/fullscreen/fullscreen_controller.h

Issue 10825115: Clean up FullscreenController. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: WeakPtrFactory Created 8 years, 4 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
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/fullscreen/fullscreen_controller.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_FULLSCREEN_FULLSCREEN_CONTROLLER_H_ 5 #ifndef CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_ 6 #define CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_
7 7
8 #include "base/basictypes.h" 8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h" 9 #include "base/memory/weak_ptr.h"
10 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h" 10 #include "chrome/browser/ui/fullscreen/fullscreen_exit_bubble_type.h"
11 #include "chrome/common/content_settings.h" 11 #include "chrome/common/content_settings.h"
12 #include "content/public/browser/notification_observer.h" 12 #include "content/public/browser/notification_observer.h"
13 #include "content/public/browser/notification_registrar.h" 13 #include "content/public/browser/notification_registrar.h"
14 14
15 class Browser; 15 class Browser;
16 class BrowserWindow; 16 class BrowserWindow;
17 class GURL; 17 class GURL;
18 class Profile; 18 class Profile;
19 class TabContents; 19 class TabContents;
20 20
21 namespace content { 21 namespace content {
22 class WebContents; 22 class WebContents;
23 } 23 }
24 24
25 // There are two different kinds of fullscreen mode - "tab fullscreen" and 25 // There are two different kinds of fullscreen mode - "tab fullscreen" and
26 // "browser fullscreen". "Tab fullscreen" refers to when a tab enters 26 // "browser fullscreen". "Tab fullscreen" refers to when a tab enters
27 // fullscreen mode via the JS fullscreen API, and "browser fullscreen" refers 27 // fullscreen mode via the JS fullscreen API, and "browser fullscreen" refers
28 // to the user putting the browser itself into fullscreen mode from the UI. The 28 // to the user putting the browser itself into fullscreen mode from the UI. The
29 // difference is that tab fullscreen has implications for how the contents of 29 // difference is that tab fullscreen has implications for how the contents of
30 // the tab render (eg: a video element may grow to consume the whole tab), 30 // the tab render (eg: a video element may grow to consume the whole tab),
31 // whereas browser fullscreen mode doesn't. Therefore if a user forces an exit 31 // whereas browser fullscreen mode doesn't. Therefore if a user forces an exit
32 // from tab fullscreen, we need to notify the tab so it can stop rendering in 32 // from tab fullscreen, we need to notify the tab so it can stop rendering in
33 // its fullscreen mode. 33 // its fullscreen mode.
34 34
35 // This class implements fullscreen and mouselock behaviour. 35 // This class implements fullscreen and mouselock behaviour.
36 class FullscreenController : public base::RefCounted<FullscreenController>, 36 class FullscreenController : public content::NotificationObserver {
37 public content::NotificationObserver {
38 public: 37 public:
39 FullscreenController(BrowserWindow* window, 38 explicit FullscreenController(Browser* browser);
40 Profile* profile, 39 virtual ~FullscreenController();
41 Browser* browser);
42 40
43 // Querying. 41 // Browser/User Fullscreen ///////////////////////////////////////////////////
44 42
45 // Returns true if the window is currently fullscreen and was initially 43 // Returns true if the window is currently fullscreen and was initially
46 // transitioned to fullscreen by a browser (vs tab) mode transition. 44 // transitioned to fullscreen by a browser (vs tab) mode transition.
47 bool IsFullscreenForBrowser() const; 45 bool IsFullscreenForBrowser() const;
48 46
47 void ToggleFullscreenMode();
48
49 // Tab/HTML Fullscreen ///////////////////////////////////////////////////////
50
49 // Returns true if fullscreen has been caused by a tab. 51 // Returns true if fullscreen has been caused by a tab.
50 // The window may still be transitioning, and window_->IsFullscreen() 52 // The window may still be transitioning, and window_->IsFullscreen()
51 // may still return false. 53 // may still return false.
52 bool IsFullscreenForTabOrPending() const; 54 bool IsFullscreenForTabOrPending() const;
53 bool IsFullscreenForTabOrPending( 55 bool IsFullscreenForTabOrPending(
54 const content::WebContents* web_contents) const; 56 const content::WebContents* web_contents) const;
55 57
56 #if defined(OS_WIN)
57 // Returns whether we are currently in a Metro snap view.
58 bool IsInMetroSnapMode();
59 #endif
60
61 bool IsMouseLockRequested() const;
62 bool IsMouseLocked() const;
63
64 // Requests.
65 void RequestToLockMouse(content::WebContents* web_contents,
66 bool user_gesture,
67 bool last_unlocked_by_target);
68 void ToggleFullscreenModeForTab(content::WebContents* web_contents, 58 void ToggleFullscreenModeForTab(content::WebContents* web_contents,
69 bool enter_fullscreen); 59 bool enter_fullscreen);
70 #if defined(OS_WIN) 60
71 // API that puts the window into a mode suitable for rendering when Chrome
72 // is rendered in a 20% screen-width Metro snap view on Windows 8.
73 void SetMetroSnapMode(bool enable);
74 #endif
75 #if defined(OS_MACOSX)
76 void TogglePresentationMode();
77 #endif
78 void ToggleFullscreenMode();
79 // Extension API implementation uses this method to toggle fullscreen mode. 61 // Extension API implementation uses this method to toggle fullscreen mode.
80 // The extension's name is displayed in the full screen bubble UI to attribute 62 // The extension's name is displayed in the full screen bubble UI to attribute
81 // the cause of the full screen state change. 63 // the cause of the full screen state change.
82 void ToggleFullscreenModeWithExtension(const GURL& extension_url); 64 void ToggleFullscreenModeWithExtension(const GURL& extension_url);
83 65
84 // Notifications. 66 // Platform Fullscreen ///////////////////////////////////////////////////////
85 void LostMouseLock(); 67
68 #if defined(OS_WIN)
69 // Returns whether we are currently in a Metro snap view.
70 bool IsInMetroSnapMode();
71
72 // API that puts the window into a mode suitable for rendering when Chrome
73 // is rendered in a 20% screen-width Metro snap view on Windows 8.
74 void SetMetroSnapMode(bool enable);
75 #endif
76
77 #if defined(OS_MACOSX)
78 void TogglePresentationMode();
79 #endif
80
81 // Mouse Lock ////////////////////////////////////////////////////////////////
82
83 bool IsMouseLockRequested() const;
84 bool IsMouseLocked() const;
85
86 void RequestToLockMouse(content::WebContents* web_contents,
87 bool user_gesture,
88 bool last_unlocked_by_target);
89
90 // Callbacks /////////////////////////////////////////////////////////////////
91
92 // Called by Browser::TabDeactivated.
93 void OnTabDeactivated(TabContents* contents);
94
95 // Called by Browser::TabClosingAt.
86 void OnTabClosing(content::WebContents* web_contents); 96 void OnTabClosing(content::WebContents* web_contents);
87 void OnTabDeactivated(TabContents* contents); 97
98 // Called by Browser::WindowFullscreenStateChanged.
99 void WindowFullscreenStateChanged();
100
101 // Called by Browser::PreHandleKeyboardEvent.
102 bool HandleUserPressedEscape();
103
104 // Called by platform FullscreenExitBubble.
88 void OnAcceptFullscreenPermission(const GURL& url, 105 void OnAcceptFullscreenPermission(const GURL& url,
89 FullscreenExitBubbleType bubble_type); 106 FullscreenExitBubbleType bubble_type);
90 void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type); 107 void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type);
91 void WindowFullscreenStateChanged();
92 bool HandleUserPressedEscape();
93 108
94 FullscreenExitBubbleType GetFullscreenExitBubbleType() const; 109 // Called by Browser::LostMouseLock.
110 void LostMouseLock();
95 111
96 // content::NotificationObserver 112 // content::NotificationObserver:
97 virtual void Observe(int type, 113 virtual void Observe(int type,
98 const content::NotificationSource& source, 114 const content::NotificationSource& source,
99 const content::NotificationDetails& details) OVERRIDE; 115 const content::NotificationDetails& details) OVERRIDE;
100 116
117 FullscreenExitBubbleType GetFullscreenExitBubbleType() const;
118
101 private: 119 private:
102 friend class base::RefCounted<FullscreenController>;
103
104 enum MouseLockState { 120 enum MouseLockState {
105 MOUSELOCK_NOT_REQUESTED, 121 MOUSELOCK_NOT_REQUESTED,
106 // The page requests to lock the mouse and the user hasn't responded to the 122 // The page requests to lock the mouse and the user hasn't responded to the
107 // request. 123 // request.
108 MOUSELOCK_REQUESTED, 124 MOUSELOCK_REQUESTED,
109 // Mouse lock has been allowed by the user. 125 // Mouse lock has been allowed by the user.
110 MOUSELOCK_ACCEPTED, 126 MOUSELOCK_ACCEPTED,
111 // Mouse lock has been silently accepted, no notification to user. 127 // Mouse lock has been silently accepted, no notification to user.
112 MOUSELOCK_ACCEPTED_SILENTLY 128 MOUSELOCK_ACCEPTED_SILENTLY
113 }; 129 };
114 130
115 virtual ~FullscreenController(); 131 void UpdateNotificationRegistrations();
116 132
133 void NotifyFullscreenChange(bool is_fullscreen);
117 // Notifies the tab that it has been forced out of fullscreen and mouse lock 134 // Notifies the tab that it has been forced out of fullscreen and mouse lock
118 // mode if necessary. 135 // mode if necessary.
119 void NotifyTabOfExitIfNecessary(); 136 void NotifyTabOfExitIfNecessary();
137 void NotifyMouseLockChange();
120 138
121 void UpdateNotificationRegistrations(); 139 // TODO(koz): Change |for_tab| to an enum.
scheib 2012/08/01 17:33:27 I think we can drop this comment, koz is not going
Robert Sesek 2012/08/01 18:36:38 I'll remove it when I do more cleanup.
140 void ToggleFullscreenModeInternal(bool for_tab);
141 #if defined(OS_MACOSX)
142 void TogglePresentationModeInternal(bool for_tab);
143 #endif
144 void SetFullscreenedTab(TabContents* tab);
145 void SetMouseLockTab(TabContents* tab);
122 146
123 // Make the current tab exit fullscreen mode or mouse lock if it is in it. 147 // Make the current tab exit fullscreen mode or mouse lock if it is in it.
124 void ExitTabFullscreenOrMouseLockIfNecessary(); 148 void ExitTabFullscreenOrMouseLockIfNecessary();
125 void UpdateFullscreenExitBubbleContent(); 149 void UpdateFullscreenExitBubbleContent();
126 void NotifyFullscreenChange(bool is_fullscreen); 150
127 void NotifyMouseLockChange();
128 ContentSetting GetFullscreenSetting(const GURL& url) const; 151 ContentSetting GetFullscreenSetting(const GURL& url) const;
129 ContentSetting GetMouseLockSetting(const GURL& url) const; 152 ContentSetting GetMouseLockSetting(const GURL& url) const;
130 153
131 #if defined(OS_MACOSX) 154 base::WeakPtrFactory<FullscreenController> ptr_factory_;
132 void TogglePresentationModeInternal(bool for_tab);
133 #endif
134 // TODO(koz): Change |for_tab| to an enum.
135 void ToggleFullscreenModeInternal(bool for_tab);
136 155
137 void SetFullscreenedTab(TabContents* tab); 156 Browser* browser_;
138 void SetMouseLockTab(TabContents* tab);
139
140 BrowserWindow* window_; 157 BrowserWindow* window_;
141 Profile* profile_; 158 Profile* profile_;
142 Browser* browser_;
143 159
144 // If there is currently a tab in fullscreen mode (entered via 160 // If there is currently a tab in fullscreen mode (entered via
145 // webkitRequestFullScreen), this is its TabContents. 161 // webkitRequestFullScreen), this is its TabContents.
146 // Assign using SetFullscreenedTab(). 162 // Assign using SetFullscreenedTab().
147 TabContents* fullscreened_tab_; 163 TabContents* fullscreened_tab_;
148 164
149 // The URL of the extension which trigerred "browser fullscreen" mode. 165 // The URL of the extension which trigerred "browser fullscreen" mode.
150 GURL extension_caused_fullscreen_; 166 GURL extension_caused_fullscreen_;
151 167
152 // True if the current tab entered fullscreen mode via webkitRequestFullScreen 168 // True if the current tab entered fullscreen mode via webkitRequestFullScreen
(...skipping 10 matching lines...) Expand all
163 TabContents* mouse_lock_tab_; 179 TabContents* mouse_lock_tab_;
164 180
165 MouseLockState mouse_lock_state_; 181 MouseLockState mouse_lock_state_;
166 182
167 content::NotificationRegistrar registrar_; 183 content::NotificationRegistrar registrar_;
168 184
169 DISALLOW_COPY_AND_ASSIGN(FullscreenController); 185 DISALLOW_COPY_AND_ASSIGN(FullscreenController);
170 }; 186 };
171 187
172 #endif // CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_ 188 #endif // CHROME_BROWSER_UI_FULLSCREEN_FULLSCREEN_CONTROLLER_H_
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.cc ('k') | chrome/browser/ui/fullscreen/fullscreen_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698