Commit 01a5a76d authored by koz@chromium.org's avatar koz@chromium.org

Split out fullscreen logic from Browser into FullscreenController.


Review URL: http://codereview.chromium.org/8423035

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110886 0039d316-1c4b-4281-b951-d872f2087c98
parent f89536a3
This diff is collapsed.
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h" #include "chrome/browser/ui/bookmarks/bookmark_tab_helper_delegate.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/constrained_window_tab_helper_delegate.h" #include "chrome/browser/ui/constrained_window_tab_helper_delegate.h"
#include "chrome/browser/ui/fullscreen_controller.h"
#include "chrome/browser/ui/fullscreen_exit_bubble_type.h" #include "chrome/browser/ui/fullscreen_exit_bubble_type.h"
#include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h" #include "chrome/browser/ui/search_engines/search_engine_tab_helper_delegate.h"
#include "chrome/browser/ui/select_file_dialog.h" #include "chrome/browser/ui/select_file_dialog.h"
...@@ -55,6 +56,7 @@ class BrowserTabRestoreServiceDelegate; ...@@ -55,6 +56,7 @@ class BrowserTabRestoreServiceDelegate;
class BrowserWindow; class BrowserWindow;
class Extension; class Extension;
class FindBarController; class FindBarController;
class FullscreenController;
class HtmlDialogUIDelegate; class HtmlDialogUIDelegate;
class InstantController; class InstantController;
class InstantUnloadHandler; class InstantUnloadHandler;
...@@ -222,6 +224,7 @@ class Browser : public TabHandlerDelegate, ...@@ -222,6 +224,7 @@ class Browser : public TabHandlerDelegate,
void set_window(BrowserWindow* window) { void set_window(BrowserWindow* window) {
DCHECK(!window_); DCHECK(!window_);
window_ = window; window_ = window;
fullscreen_controller_ = new FullscreenController(window_, profile_, this);
} }
#endif #endif
...@@ -499,9 +502,6 @@ class Browser : public TabHandlerDelegate, ...@@ -499,9 +502,6 @@ class Browser : public TabHandlerDelegate,
// fullscreen. // fullscreen.
void WindowFullscreenStateChanged(); void WindowFullscreenStateChanged();
// Sends a notification that the fullscreen state has changed.
void NotifyFullscreenChange();
// Assorted browser commands //////////////////////////////////////////////// // Assorted browser commands ////////////////////////////////////////////////
// NOTE: Within each of the following sections, the IDs are ordered roughly by // NOTE: Within each of the following sections, the IDs are ordered roughly by
...@@ -838,11 +838,10 @@ class Browser : public TabHandlerDelegate, ...@@ -838,11 +838,10 @@ class Browser : public TabHandlerDelegate,
virtual void TabStripEmpty(); virtual void TabStripEmpty();
// Fullscreen permission infobar callbacks. // Fullscreen permission infobar callbacks.
// TODO(koz): Remove this and have callers call FullscreenController directly.
void OnAcceptFullscreenPermission(const GURL& url, void OnAcceptFullscreenPermission(const GURL& url,
FullscreenExitBubbleType bubble_type); FullscreenExitBubbleType bubble_type);
void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type); void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type);
ContentSetting GetFullscreenSetting(const GURL& url);
ContentSetting GetMouseLockSetting(const GURL& url);
// Figure out if there are tabs that have beforeunload handlers. // Figure out if there are tabs that have beforeunload handlers.
bool TabsNeedBeforeUnloadFired(); bool TabsNeedBeforeUnloadFired();
...@@ -856,7 +855,7 @@ class Browser : public TabHandlerDelegate, ...@@ -856,7 +855,7 @@ class Browser : public TabHandlerDelegate,
// True when the current tab is in fullscreen mode, requested by // True when the current tab is in fullscreen mode, requested by
// webkitRequestFullScreen. // webkitRequestFullScreen.
bool is_fullscreen_for_tab() const { return fullscreened_tab_ != NULL; } bool IsFullscreenForTab() const;
// Called each time the browser window is shown. // Called each time the browser window is shown.
void OnWindowDidShow(); void OnWindowDidShow();
...@@ -914,15 +913,6 @@ class Browser : public TabHandlerDelegate, ...@@ -914,15 +913,6 @@ class Browser : public TabHandlerDelegate,
BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN, BOOKMARK_BAR_STATE_CHANGE_TOGGLE_FULLSCREEN,
}; };
enum MouseLockState {
MOUSELOCK_NOT_REQUESTED,
// The page requests to lock the mouse and the user hasn't responded to the
// request.
MOUSELOCK_REQUESTED,
// Mouse lock has been allowed by the user.
MOUSELOCK_ACCEPTED
};
// Overridden from TabContentsDelegate: // Overridden from TabContentsDelegate:
// Deprecated. Please use two-argument variant. // Deprecated. Please use two-argument variant.
// TODO(adriansc): Remove this method once refactoring changed all call sites. // TODO(adriansc): Remove this method once refactoring changed all call sites.
...@@ -1174,25 +1164,6 @@ class Browser : public TabHandlerDelegate, ...@@ -1174,25 +1164,6 @@ class Browser : public TabHandlerDelegate,
// >= index. // >= index.
void SyncHistoryWithTabs(int index); void SyncHistoryWithTabs(int index);
// Tab fullscreen functions /////////////////////////////////////////////////
// There are two different kinds of fullscreen mode - "tab fullscreen" and
// "browser fullscreen". "Tab fullscreen" refers to when a tab enters
// fullscreen mode via the JS fullscreen API, and "browser fullscreen"
// refers to the user putting the browser itself into fullscreen mode from
// the UI. The difference is that tab fullscreen has implications for how
// the contents of the tab render (eg: a video element may grow to consume
// the whole tab), whereas browser fullscreen mode doesn't. Therefore if a
// user forces an exit from fullscreen, we need to notify the tab so it can
// stop rendering in its fullscreen mode.
// Make the current tab exit fullscreen mode if it is in it.
void ExitTabbedFullscreenModeIfNecessary();
// Notifies the tab that it has been forced out of fullscreen mode if
// necessary.
void NotifyTabOfFullscreenExitIfNecessary();
// OnBeforeUnload handling ////////////////////////////////////////////////// // OnBeforeUnload handling //////////////////////////////////////////////////
typedef std::set<TabContents*> UnloadListenerSet; typedef std::set<TabContents*> UnloadListenerSet;
...@@ -1312,12 +1283,6 @@ class Browser : public TabHandlerDelegate, ...@@ -1312,12 +1283,6 @@ class Browser : public TabHandlerDelegate,
// Notifies the tab that it has been forced out of fullscreen mode. // Notifies the tab that it has been forced out of fullscreen mode.
void NotifyTabOfFullscreenExit(); void NotifyTabOfFullscreenExit();
// Determines what should be shown in the fullscreen exit bubble.
FullscreenExitBubbleType GetFullscreenExitBubbleType() const;
// Updates the content of the fullscreen exit bubble.
void UpdateFullscreenExitBubbleContent();
// Data members ///////////////////////////////////////////////////////////// // Data members /////////////////////////////////////////////////////////////
content::NotificationRegistrar registrar_; content::NotificationRegistrar registrar_;
...@@ -1458,17 +1423,7 @@ class Browser : public TabHandlerDelegate, ...@@ -1458,17 +1423,7 @@ class Browser : public TabHandlerDelegate,
BookmarkBar::State bookmark_bar_state_; BookmarkBar::State bookmark_bar_state_;
// If there is currently a tab in fullscreen mode (entered via scoped_refptr<FullscreenController> fullscreen_controller_;
// webkitRequestFullScreen), this is its wrapper.
TabContentsWrapper* fullscreened_tab_;
// True if the current tab entered fullscreen mode via webkitRequestFullScreen
bool tab_caused_fullscreen_;
// True if tab fullscreen has been allowed, either by settings or by user
// clicking the allow button on the fullscreen infobar.
bool tab_fullscreen_accepted_;
MouseLockState mouse_lock_state_;
// True if the browser window has been shown at least once. // True if the browser window has been shown at least once.
bool window_has_shown_; bool window_has_shown_;
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_list.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/fullscreen_controller.h"
#include "chrome/browser/ui/fullscreen_exit_bubble_type.h" #include "chrome/browser/ui/fullscreen_exit_bubble_type.h"
#include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
#include "chrome/common/chrome_notification_types.h" #include "chrome/common/chrome_notification_types.h"
...@@ -905,13 +906,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, TestFullscreenBubbleMouseLockState) { ...@@ -905,13 +906,14 @@ IN_PROC_BROWSER_TEST_F(BrowserTest, TestFullscreenBubbleMouseLockState) {
} }
browser()->RequestToLockMouse(fullscreen_tab); browser()->RequestToLockMouse(fullscreen_tab);
FullscreenExitBubbleType type = browser()->GetFullscreenExitBubbleType(); FullscreenExitBubbleType type =
browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
bool mouse_lock = false; bool mouse_lock = false;
fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock); fullscreen_bubble::PermissionRequestedByType(type, NULL, &mouse_lock);
ASSERT_TRUE(mouse_lock); ASSERT_TRUE(mouse_lock);
browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type); browser()->OnAcceptFullscreenPermission(fullscreen_tab->GetURL(), type);
type = browser()->GetFullscreenExitBubbleType(); type = browser()->fullscreen_controller_->GetFullscreenExitBubbleType();
ASSERT_FALSE(fullscreen_bubble::ShowButtonsForType(type)); ASSERT_FALSE(fullscreen_bubble::ShowButtonsForType(type));
} }
......
...@@ -1988,7 +1988,7 @@ willAnimateFromState:(bookmarks::VisualState)oldState ...@@ -1988,7 +1988,7 @@ willAnimateFromState:(bookmarks::VisualState)oldState
if (presentationMode) { if (presentationMode) {
BOOL fullscreen = [self isFullscreen]; BOOL fullscreen = [self isFullscreen];
BOOL fullscreen_for_tab = browser_->is_fullscreen_for_tab(); BOOL fullscreen_for_tab = browser_->IsFullscreenForTab();
if (!fullscreen_for_tab) if (!fullscreen_for_tab)
[self setShouldUsePresentationModeWhenEnteringFullscreen:YES]; [self setShouldUsePresentationModeWhenEnteringFullscreen:YES];
enteredPresentationModeFromFullscreen_ = fullscreen; enteredPresentationModeFromFullscreen_ = fullscreen;
......
...@@ -672,7 +672,7 @@ willPositionSheet:(NSWindow*)sheet ...@@ -672,7 +672,7 @@ willPositionSheet:(NSWindow*)sheet
return; return;
if (presentationMode) { if (presentationMode) {
BOOL fullscreen_for_tab = browser_->is_fullscreen_for_tab(); BOOL fullscreen_for_tab = browser_->IsFullscreenForTab();
BOOL showDropdown = !fullscreen_for_tab && BOOL showDropdown = !fullscreen_for_tab &&
(forceDropdown || [self floatingBarHasFocus]); (forceDropdown || [self floatingBarHasFocus]);
NSView* contentView = [[self window] contentView]; NSView* contentView = [[self window] contentView];
...@@ -785,7 +785,7 @@ willPositionSheet:(NSWindow*)sheet ...@@ -785,7 +785,7 @@ willPositionSheet:(NSWindow*)sheet
} }
- (void)showFullscreenExitBubbleIfNecessary { - (void)showFullscreenExitBubbleIfNecessary {
if (!browser_->is_fullscreen_for_tab()) { if (!browser_->IsFullscreenForTab()) {
return; return;
} }
...@@ -847,7 +847,7 @@ willPositionSheet:(NSWindow*)sheet ...@@ -847,7 +847,7 @@ willPositionSheet:(NSWindow*)sheet
NSWindow* window = [self window]; NSWindow* window = [self window];
savedRegularWindowFrame_ = [window frame]; savedRegularWindowFrame_ = [window frame];
BOOL mode = [self shouldUsePresentationModeWhenEnteringFullscreen]; BOOL mode = [self shouldUsePresentationModeWhenEnteringFullscreen];
mode = mode || browser_->is_fullscreen_for_tab(); mode = mode || browser_->IsFullscreenForTab();
enteringFullscreen_ = YES; enteringFullscreen_ = YES;
[self setPresentationModeInternal:mode forceDropdown:NO]; [self setPresentationModeInternal:mode forceDropdown:NO];
} }
......
...@@ -688,6 +688,7 @@ static bool IsFrontWindow(NSWindow *window) { ...@@ -688,6 +688,7 @@ static bool IsFrontWindow(NSWindow *window) {
} }
TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreenNotLion) { TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreenNotLion) {
CreateBrowserWindow();
EXPECT_FALSE([controller_ isFullscreen]); EXPECT_FALSE([controller_ isFullscreen]);
[controller_ enterFullscreenForURL:GURL() [controller_ enterFullscreenForURL:GURL()
bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION]; bubbleType:FEB_TYPE_BROWSER_FULLSCREEN_EXIT_INSTRUCTION];
...@@ -701,6 +702,7 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreenNotLion) { ...@@ -701,6 +702,7 @@ TEST_F(BrowserWindowFullScreenControllerTest, TestFullscreenNotLion) {
// please do not mark it as flaky without first verifying that there are no bot // please do not mark it as flaky without first verifying that there are no bot
// problems. // problems.
TEST_F(BrowserWindowFullScreenControllerTest, TestActivateNotLion) { TEST_F(BrowserWindowFullScreenControllerTest, TestActivateNotLion) {
CreateBrowserWindow();
EXPECT_FALSE([controller_ isFullscreen]); EXPECT_FALSE([controller_ isFullscreen]);
[controller_ activate]; [controller_ activate];
......
This diff is collapsed.
// 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_FULLSCREEN_CONTROLLER_H_
#define CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_H_
#pragma once
#include "base/basictypes.h"
#include "base/memory/ref_counted.h"
#include "base/task.h"
#include "chrome/browser/ui/fullscreen_exit_bubble_type.h"
#include "chrome/common/content_settings.h"
class Browser;
class BrowserWindow;
class GURL;
class Profile;
class TabContents;
class TabContentsWrapper;
// There are two different kinds of fullscreen mode - "tab fullscreen" and
// "browser fullscreen". "Tab fullscreen" refers to when a tab enters
// fullscreen mode via the JS fullscreen API, and "browser fullscreen" refers
// to the user putting the browser itself into fullscreen mode from the UI. The
// difference is that tab fullscreen has implications for how the contents of
// the tab render (eg: a video element may grow to consume the whole tab),
// whereas browser fullscreen mode doesn't. Therefore if a user forces an exit
// from tab fullscreen, we need to notify the tab so it can stop rendering in
// its fullscreen mode.
// This class implements fullscreen and mouselock behaviour.
class FullscreenController : public base::RefCounted<FullscreenController> {
public:
FullscreenController(BrowserWindow* window,
Profile* profile,
Browser* browser);
virtual ~FullscreenController();
// Querying.
bool IsFullscreenForTab() const;
bool IsFullscreenForTab(const TabContents* tab) const;
// Requests.
void RequestToLockMouse(TabContents* tab);
void ToggleFullscreenModeForTab(TabContents* tab, bool enter_fullscreen);
#if defined(OS_MACOSX)
void TogglePresentationMode(bool for_tab);
#endif
// TODO(koz): Change |for_tab| to an enum.
void ToggleFullscreenMode(bool for_tab);
// Notifications.
void LostMouseLock();
void OnTabClosing(TabContents* tab_contents);
void OnTabDeactivated(TabContentsWrapper* contents);
void OnAcceptFullscreenPermission(const GURL& url,
FullscreenExitBubbleType bubble_type);
void OnDenyFullscreenPermission(FullscreenExitBubbleType bubble_type);
void WindowFullscreenStateChanged();
bool HandleUserPressedEscape();
FullscreenExitBubbleType GetFullscreenExitBubbleType() const;
private:
enum MouseLockState {
MOUSELOCK_NOT_REQUESTED,
// The page requests to lock the mouse and the user hasn't responded to the
// request.
MOUSELOCK_REQUESTED,
// Mouse lock has been allowed by the user.
MOUSELOCK_ACCEPTED
};
// Notifies the tab that it has been forced out of fullscreen mode if
// necessary.
void NotifyTabOfFullscreenExitIfNecessary();
// Make the current tab exit fullscreen mode if it is in it.
void ExitTabbedFullscreenModeIfNecessary();
void UpdateFullscreenExitBubbleContent();
void NotifyFullscreenChange();
ContentSetting GetFullscreenSetting(const GURL& url) const;
ContentSetting GetMouseLockSetting(const GURL& url) const;
BrowserWindow* window_;
Profile* profile_;
Browser* browser_;
// If there is currently a tab in fullscreen mode (entered via
// webkitRequestFullScreen), this is its wrapper.
TabContentsWrapper* fullscreened_tab_;
// True if the current tab entered fullscreen mode via webkitRequestFullScreen
bool tab_caused_fullscreen_;
// True if tab fullscreen has been allowed, either by settings or by user
// clicking the allow button on the fullscreen infobar.
bool tab_fullscreen_accepted_;
MouseLockState mouse_lock_state_;
DISALLOW_COPY_AND_ASSIGN(FullscreenController);
};
#endif // CHROME_BROWSER_UI_FULLSCREEN_CONTROLLER_H_
...@@ -2403,6 +2403,8 @@ ...@@ -2403,6 +2403,8 @@
'browser/ui/bookmarks/bookmark_tab_helper_delegate.h', 'browser/ui/bookmarks/bookmark_tab_helper_delegate.h',
'browser/ui/browser.cc', 'browser/ui/browser.cc',
'browser/ui/browser.h', 'browser/ui/browser.h',
'browser/ui/fullscreen_controller.cc',
'browser/ui/fullscreen_controller.h',
'browser/ui/browser_dialogs.h', 'browser/ui/browser_dialogs.h',
'browser/ui/browser_init.cc', 'browser/ui/browser_init.cc',
'browser/ui/browser_init.h', 'browser/ui/browser_init.h',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment