Index: chrome/browser/ui/views/apps/native_app_window_views.cc |
diff --git a/chrome/browser/ui/views/apps/native_app_window_views.cc b/chrome/browser/ui/views/apps/native_app_window_views.cc |
index 090a96acb548d0e35cb9027e5a8688ed489b2ab6..4ffa11fc96a012e47b0ef8c4f56006dfb99f37a4 100644 |
--- a/chrome/browser/ui/views/apps/native_app_window_views.cc |
+++ b/chrome/browser/ui/views/apps/native_app_window_views.cc |
@@ -43,12 +43,15 @@ |
#if defined(USE_ASH) |
#include "ash/ash_constants.h" |
+#include "ash/ash_switches.h" |
#include "ash/screen_ash.h" |
#include "ash/shell.h" |
#include "ash/wm/custom_frame_view_ash.h" |
+#include "ash/wm/immersive_fullscreen_controller.h" |
#include "ash/wm/panels/panel_frame_view.h" |
#include "ash/wm/window_state.h" |
#include "ash/wm/window_state_delegate.h" |
+#include "ash/wm/window_state_observer.h" |
#include "chrome/browser/ui/ash/ash_util.h" |
#include "ui/aura/client/aura_constants.h" |
#include "ui/aura/client/window_tree_client.h" |
@@ -129,14 +132,26 @@ void CreateIconAndSetRelaunchDetails( |
#if defined(USE_ASH) |
// This class handles a user's fullscreen request (Shift+F4/F4). |
-class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate { |
+class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, |
+ public ash::wm::WindowStateObserver { |
public: |
- explicit NativeAppWindowStateDelegate(ShellWindow* shell_window) |
- : shell_window_(shell_window) { |
- DCHECK(shell_window_); |
+ NativeAppWindowStateDelegate(ShellWindow* shell_window, |
+ apps::NativeAppWindow* native_app_window) |
+ : shell_window_(shell_window), |
+ window_state_( |
+ ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { |
+ // Add a window state observer to exit fullscreen properly in case |
+ // fullscreen is exited without going through ShellWindow::Restore(). This |
+ // is the case when exiting immersive fullscreen via the "Restore" window |
+ // control. |
+ // TODO(pkotwicz): This is a hack. Remove ASAP. |
+ window_state_->AddObserver(this); |
+ } |
+ virtual ~NativeAppWindowStateDelegate(){ |
+ window_state_->RemoveObserver(this); |
} |
- virtual ~NativeAppWindowStateDelegate(){} |
+ private: |
// Overridden from ash::wm::WindowStateDelegate. |
virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { |
// Windows which cannot be maximized should not be fullscreened. |
@@ -144,12 +159,23 @@ class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate { |
if (window_state->IsFullscreen()) |
shell_window_->Restore(); |
else if (window_state->CanMaximize()) |
- shell_window_->Fullscreen(); |
+ shell_window_->ImmersiveFullscreen(); |
return true; |
} |
- private: |
- ShellWindow* shell_window_; // not owned. |
+ // Overridden from ash::wm::WindowStateObserver: |
+ virtual void OnWindowShowTypeChanged(ash::wm::WindowState* window_state, |
+ ash::wm::WindowShowType* old_type) { |
+ if (!window_state->IsFullscreen() && |
+ !window_state->IsMinimized() && |
+ shell_window_->fullscreen_type() != ShellWindow::FULLSCREEN_TYPE_NONE) { |
+ shell_window_->Restore(); |
+ } |
+ } |
+ |
+ // Not owned. |
+ ShellWindow* shell_window_; |
+ ash::wm::WindowState* window_state_; |
DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
}; |
@@ -191,7 +217,7 @@ NativeAppWindowViews::NativeAppWindowViews( |
chrome::HOST_DESKTOP_TYPE_ASH) { |
ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
scoped_ptr<ash::wm::WindowStateDelegate>( |
- new NativeAppWindowStateDelegate(shell_window)).Pass()); |
+ new NativeAppWindowStateDelegate(shell_window, this)).Pass()); |
} |
#endif |
} |
@@ -669,7 +695,21 @@ views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
return new ash::PanelFrameView(widget, frame_type); |
} |
if (!frameless_) { |
- return new ash::CustomFrameViewAsh(widget); |
+ ash::CustomFrameViewAsh* custom_frame_view = |
+ new ash::CustomFrameViewAsh(widget); |
+#if defined(OS_CHROMEOS) |
+ // Non-frameless app windows can be put into immersive fullscreen. |
+ // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for |
+ // Windows Ash. |
+ if (CommandLine::ForCurrentProcess()->HasSwitch( |
+ ash::switches::kAshEnableImmersiveFullscreenForAllWindows)) { |
+ immersive_fullscreen_controller_.reset( |
+ new ash::ImmersiveFullscreenController()); |
+ custom_frame_view->InitImmersiveFullscreenControllerForView( |
+ immersive_fullscreen_controller_.get()); |
+ } |
+#endif |
+ return custom_frame_view; |
} |
} |
#endif |
@@ -793,19 +833,33 @@ bool NativeAppWindowViews::AcceleratorPressed( |
// NativeAppWindow implementation. |
-void NativeAppWindowViews::SetFullscreen(bool fullscreen) { |
+void NativeAppWindowViews::SetFullscreen(ShellWindow::FullscreenType type) { |
// Fullscreen not supported by panels. |
if (shell_window_->window_type_is_panel()) |
return; |
- is_fullscreen_ = fullscreen; |
- window_->SetFullscreen(fullscreen); |
+ is_fullscreen_ = (type != ShellWindow::FULLSCREEN_TYPE_NONE); |
+ window_->SetFullscreen(is_fullscreen_); |
+ |
+#if defined(USE_ASH) |
+ if (immersive_fullscreen_controller_.get()) { |
+ bool is_immersive = (type == ShellWindow::FULLSCREEN_TYPE_IMMERSIVE); |
+ if (is_immersive != immersive_fullscreen_controller_->IsEnabled()) { |
+ immersive_fullscreen_controller_->SetEnabled(is_immersive); |
+ shell_window_->OnNativeWindowChanged(); |
+ } |
+ } |
+#endif |
+ |
// TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
// ever drop the window out of fullscreen in response to something that |
// wasn't the app calling webkitCancelFullScreen(). |
} |
-bool NativeAppWindowViews::IsFullscreenOrPending() const { |
- return is_fullscreen_; |
+bool NativeAppWindowViews::SupportsImmersiveFullscreen() const { |
+#if defined(USE_ASH) |
+ return immersive_fullscreen_controller_.get(); |
+#endif |
+ return false; |
} |
bool NativeAppWindowViews::IsDetached() const { |