summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 14:09:09 +0000
committermgiuca@chromium.org <mgiuca@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-24 14:09:09 +0000
commit53df18e579ad264328bd427c6577f96e644f3180 (patch)
tree0b424a73b0e1f4e8b5586babc2e8364d08119a6a
parenta49d690a59e7738d23d2bcf5241994989a029ae6 (diff)
downloadchromium_src-53df18e579ad264328bd427c6577f96e644f3180.zip
chromium_src-53df18e579ad264328bd427c6577f96e644f3180.tar.gz
chromium_src-53df18e579ad264328bd427c6577f96e644f3180.tar.bz2
AppWindow: Abstract over setting and querying fullscreen mode.
Added generic SetFullscreen and various queries about the fullscreen state as public methods of AppWindow. Most of the other code that deals with the fullscreen state now uses these methods instead of directly manipulating |fullscreen_types_|. This saves a lot of code duplication, especially with respect to checking permissions. This refactor is needed for future code reuse of AppWindow (for custom launcher pages), but the simplification is useful regardless. BUG=391137 Review URL: https://codereview.chromium.org/391983003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285243 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--apps/app_window.cc100
-rw-r--r--apps/app_window.h18
2 files changed, 65 insertions, 53 deletions
diff --git a/apps/app_window.cc b/apps/app_window.cc
index 82dbab7..df6eac7 100644
--- a/apps/app_window.cc
+++ b/apps/app_window.cc
@@ -68,10 +68,6 @@ namespace {
const int kDefaultWidth = 512;
const int kDefaultHeight = 384;
-bool IsFullscreen(int fullscreen_types) {
- return fullscreen_types != apps::AppWindow::FULLSCREEN_TYPE_NONE;
-}
-
void SetConstraintProperty(const std::string& name,
int value,
base::DictionaryValue* bounds_properties) {
@@ -442,9 +438,8 @@ bool AppWindow::PreHandleKeyboardEvent(
// ::HandleKeyboardEvent() will only be called if the KeyEvent's default
// action is not prevented.
// Thus, we should handle the KeyEvent here only if the permission is not set.
- if (event.windowsKeyCode == ui::VKEY_ESCAPE &&
- (fullscreen_types_ != FULLSCREEN_TYPE_NONE) &&
- ((fullscreen_types_ & FULLSCREEN_TYPE_FORCED) == 0) &&
+ if (event.windowsKeyCode == ui::VKEY_ESCAPE && IsFullscreen() &&
+ !IsForcedFullscreen() &&
!extension->permissions_data()->HasAPIPermission(
APIPermission::kOverrideEscFullscreen)) {
Restore();
@@ -460,9 +455,8 @@ void AppWindow::HandleKeyboardEvent(
// If the window is currently fullscreen and not forced, ESC should leave
// fullscreen. If this code is being called for ESC, that means that the
// KeyEvent's default behavior was not prevented by the content.
- if (event.windowsKeyCode == ui::VKEY_ESCAPE &&
- (fullscreen_types_ != FULLSCREEN_TYPE_NONE) &&
- ((fullscreen_types_ & FULLSCREEN_TYPE_FORCED) == 0)) {
+ if (event.windowsKeyCode == ui::VKEY_ESCAPE && IsFullscreen() &&
+ !IsForcedFullscreen()) {
Restore();
return;
}
@@ -517,8 +511,8 @@ void AppWindow::OnNativeWindowChanged() {
SaveWindowPosition();
#if defined(OS_WIN)
- if (native_app_window_ && cached_always_on_top_ &&
- !IsFullscreen(fullscreen_types_) && !native_app_window_->IsMaximized() &&
+ if (native_app_window_ && cached_always_on_top_ && !IsFullscreen() &&
+ !native_app_window_->IsMaximized() &&
!native_app_window_->IsMinimized()) {
UpdateNativeAlwaysOnTop();
}
@@ -632,25 +626,51 @@ void AppWindow::UpdateAppIcon(const gfx::Image& image) {
AppWindowRegistry::Get(browser_context_)->AppWindowIconChanged(this);
}
-void AppWindow::Fullscreen() {
+void AppWindow::SetFullscreen(FullscreenType type, bool enable) {
+ DCHECK_NE(FULLSCREEN_TYPE_NONE, type);
+
+ if (enable) {
#if !defined(OS_MACOSX)
- // Do not enter fullscreen mode if disallowed by pref.
- PrefService* prefs =
- extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext(
- browser_context());
- if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed))
- return;
+ // Do not enter fullscreen mode if disallowed by pref.
+ // TODO(bartfab): Add a test once it becomes possible to simulate a user
+ // gesture. http://crbug.com/174178
+ if (type != FULLSCREEN_TYPE_FORCED) {
+ PrefService* prefs =
+ extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext(
+ browser_context());
+ if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed))
+ return;
+ }
#endif
- fullscreen_types_ |= FULLSCREEN_TYPE_WINDOW_API;
+ fullscreen_types_ |= type;
+ } else {
+ fullscreen_types_ &= ~type;
+ }
SetNativeWindowFullscreen();
}
+bool AppWindow::IsFullscreen() const {
+ return fullscreen_types_ != FULLSCREEN_TYPE_NONE;
+}
+
+bool AppWindow::IsForcedFullscreen() const {
+ return (fullscreen_types_ & FULLSCREEN_TYPE_FORCED) != 0;
+}
+
+bool AppWindow::IsHtmlApiFullscreen() const {
+ return (fullscreen_types_ & FULLSCREEN_TYPE_HTML_API) != 0;
+}
+
+void AppWindow::Fullscreen() {
+ SetFullscreen(FULLSCREEN_TYPE_WINDOW_API, true);
+}
+
void AppWindow::Maximize() { GetBaseWindow()->Maximize(); }
void AppWindow::Minimize() { GetBaseWindow()->Minimize(); }
void AppWindow::Restore() {
- if (IsFullscreen(fullscreen_types_)) {
+ if (IsFullscreen()) {
fullscreen_types_ = FULLSCREEN_TYPE_NONE;
SetNativeWindowFullscreen();
} else {
@@ -659,21 +679,11 @@ void AppWindow::Restore() {
}
void AppWindow::OSFullscreen() {
-#if !defined(OS_MACOSX)
- // Do not enter fullscreen mode if disallowed by pref.
- PrefService* prefs =
- extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext(
- browser_context());
- if (!prefs->GetBoolean(prefs::kAppFullscreenAllowed))
- return;
-#endif
- fullscreen_types_ |= FULLSCREEN_TYPE_OS;
- SetNativeWindowFullscreen();
+ SetFullscreen(FULLSCREEN_TYPE_OS, true);
}
void AppWindow::ForcedFullscreen() {
- fullscreen_types_ |= FULLSCREEN_TYPE_FORCED;
- SetNativeWindowFullscreen();
+ SetFullscreen(FULLSCREEN_TYPE_FORCED, true);
}
void AppWindow::SetContentSizeConstraints(const gfx::Size& min_size,
@@ -739,7 +749,7 @@ void AppWindow::SetAlwaysOnTop(bool always_on_top) {
// As a security measure, do not allow fullscreen windows or windows that
// overlap the taskbar to be on top. The property will be applied when the
// window exits fullscreen and moves away from the taskbar.
- if (!IsFullscreen(fullscreen_types_) && !IntersectsWithTaskbar())
+ if (!IsFullscreen() && !IntersectsWithTaskbar())
native_app_window_->SetAlwaysOnTop(always_on_top);
OnNativeWindowChanged();
@@ -897,7 +907,7 @@ bool AppWindow::IntersectsWithTaskbar() const {
void AppWindow::UpdateNativeAlwaysOnTop() {
DCHECK(cached_always_on_top_);
bool is_on_top = native_app_window_->IsAlwaysOnTop();
- bool fullscreen = IsFullscreen(fullscreen_types_);
+ bool fullscreen = IsFullscreen();
bool intersects_taskbar = IntersectsWithTaskbar();
if (is_on_top && (fullscreen || intersects_taskbar)) {
@@ -962,18 +972,6 @@ void AppWindow::NavigationStateChanged(const content::WebContents* source,
void AppWindow::ToggleFullscreenModeForTab(content::WebContents* source,
bool enter_fullscreen) {
-#if !defined(OS_MACOSX)
- // Do not enter fullscreen mode if disallowed by pref.
- // TODO(bartfab): Add a test once it becomes possible to simulate a user
- // gesture. http://crbug.com/174178
- PrefService* prefs =
- extensions::ExtensionsBrowserClient::Get()->GetPrefServiceForContext(
- browser_context());
- if (enter_fullscreen && !prefs->GetBoolean(prefs::kAppFullscreenAllowed)) {
- return;
- }
-#endif
-
const extensions::Extension* extension = GetExtension();
if (!extension)
return;
@@ -983,16 +981,12 @@ void AppWindow::ToggleFullscreenModeForTab(content::WebContents* source,
return;
}
- if (enter_fullscreen)
- fullscreen_types_ |= FULLSCREEN_TYPE_HTML_API;
- else
- fullscreen_types_ &= ~FULLSCREEN_TYPE_HTML_API;
- SetNativeWindowFullscreen();
+ SetFullscreen(FULLSCREEN_TYPE_HTML_API, enter_fullscreen);
}
bool AppWindow::IsFullscreenForTabOrPending(const content::WebContents* source)
const {
- return ((fullscreen_types_ & FULLSCREEN_TYPE_HTML_API) != 0);
+ return IsHtmlApiFullscreen();
}
void AppWindow::Observe(int type,
diff --git a/apps/app_window.h b/apps/app_window.h
index ae51bf8..cbfab8b 100644
--- a/apps/app_window.h
+++ b/apps/app_window.h
@@ -313,6 +313,24 @@ class AppWindow : public content::NotificationObserver,
// callback. Also called externally for v1 apps using Ash Panels.
void UpdateAppIcon(const gfx::Image& image);
+ // Enable or disable fullscreen mode. |type| specifies which type of
+ // fullscreen mode to change (note that disabling one type of fullscreen may
+ // not exit fullscreen mode because a window may have a different type of
+ // fullscreen enabled). If |type| is not FORCED, checks that the extension has
+ // the required permission.
+ void SetFullscreen(FullscreenType type, bool enable);
+
+ // Returns true if the app window is in a fullscreen state.
+ bool IsFullscreen() const;
+
+ // Returns true if the app window is in a forced fullscreen state (one that
+ // cannot be exited by the user).
+ bool IsForcedFullscreen() const;
+
+ // Returns true if the app window is in a fullscreen state entered from an
+ // HTML API request.
+ bool IsHtmlApiFullscreen() const;
+
// Transitions window into fullscreen, maximized, minimized or restores based
// on chrome.app.window API.
void Fullscreen();