Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/ui/views/apps/native_app_window_views.h" | 5 #include "chrome/browser/ui/views/apps/native_app_window_views.h" |
| 6 | 6 |
| 7 #include "apps/shell_window.h" | 7 #include "apps/shell_window.h" |
| 8 #include "apps/ui/views/shell_window_frame_view.h" | 8 #include "apps/ui/views/shell_window_frame_view.h" |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 36 #include "ui/base/win/shell.h" | 36 #include "ui/base/win/shell.h" |
| 37 #include "ui/views/win/hwnd_util.h" | 37 #include "ui/views/win/hwnd_util.h" |
| 38 #endif | 38 #endif |
| 39 | 39 |
| 40 #if defined(OS_LINUX) | 40 #if defined(OS_LINUX) |
| 41 #include "chrome/browser/shell_integration_linux.h" | 41 #include "chrome/browser/shell_integration_linux.h" |
| 42 #endif | 42 #endif |
| 43 | 43 |
| 44 #if defined(USE_ASH) | 44 #if defined(USE_ASH) |
| 45 #include "ash/ash_constants.h" | 45 #include "ash/ash_constants.h" |
| 46 #include "ash/ash_switches.h" | |
| 46 #include "ash/screen_ash.h" | 47 #include "ash/screen_ash.h" |
| 47 #include "ash/shell.h" | 48 #include "ash/shell.h" |
| 48 #include "ash/wm/custom_frame_view_ash.h" | 49 #include "ash/wm/custom_frame_view_ash.h" |
| 50 #include "ash/wm/immersive_fullscreen_controller.h" | |
| 49 #include "ash/wm/panels/panel_frame_view.h" | 51 #include "ash/wm/panels/panel_frame_view.h" |
| 50 #include "ash/wm/window_state.h" | 52 #include "ash/wm/window_state.h" |
| 51 #include "ash/wm/window_state_delegate.h" | 53 #include "ash/wm/window_state_delegate.h" |
| 54 #include "ash/wm/window_state_observer.h" | |
| 52 #include "chrome/browser/ui/ash/ash_util.h" | 55 #include "chrome/browser/ui/ash/ash_util.h" |
| 53 #include "ui/aura/client/aura_constants.h" | 56 #include "ui/aura/client/aura_constants.h" |
| 54 #include "ui/aura/client/window_tree_client.h" | 57 #include "ui/aura/client/window_tree_client.h" |
| 55 #include "ui/aura/window.h" | 58 #include "ui/aura/window.h" |
| 56 #endif | 59 #endif |
| 57 | 60 |
| 58 #if defined(USE_AURA) | 61 #if defined(USE_AURA) |
| 59 #include "ui/aura/window.h" | 62 #include "ui/aura/window.h" |
| 60 #endif | 63 #endif |
| 61 | 64 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 122 !file_util::CreateDirectory(web_app_path)) { | 125 !file_util::CreateDirectory(web_app_path)) { |
| 123 return; | 126 return; |
| 124 } | 127 } |
| 125 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); | 128 ui::win::SetAppIconForWindow(icon_file.value(), hwnd); |
| 126 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); | 129 web_app::internals::CheckAndSaveIcon(icon_file, shortcut_info.favicon); |
| 127 } | 130 } |
| 128 #endif | 131 #endif |
| 129 | 132 |
| 130 #if defined(USE_ASH) | 133 #if defined(USE_ASH) |
| 131 // This class handles a user's fullscreen request (Shift+F4/F4). | 134 // This class handles a user's fullscreen request (Shift+F4/F4). |
| 132 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate { | 135 class NativeAppWindowStateDelegate : public ash::wm::WindowStateDelegate, |
| 136 public ash::wm::WindowStateObserver { | |
| 133 public: | 137 public: |
| 134 explicit NativeAppWindowStateDelegate(ShellWindow* shell_window) | 138 NativeAppWindowStateDelegate(ShellWindow* shell_window, |
| 135 : shell_window_(shell_window) { | 139 apps::NativeAppWindow* native_app_window) |
| 136 DCHECK(shell_window_); | 140 : shell_window_(shell_window), |
| 141 window_state_( | |
| 142 ash::wm::GetWindowState(native_app_window->GetNativeWindow())) { | |
| 143 // Add a window state observer to exit fullscreen properly in case | |
| 144 // fullscreen is exited without going through ShellWindow::Restore(). This | |
| 145 // is the case when exiting immersive fullscreen via the "Restore" window | |
| 146 // control. | |
| 147 // TODO(pkotwicz): This is a hack. Remove ASAP. | |
| 148 window_state_->AddObserver(this); | |
| 137 } | 149 } |
| 138 virtual ~NativeAppWindowStateDelegate(){} | 150 virtual ~NativeAppWindowStateDelegate(){ |
| 151 window_state_->RemoveObserver(this); | |
| 152 } | |
| 139 | 153 |
| 140 // Overridden from ash::wm::WindowStateDelegate. | 154 // Overridden from ash::wm::WindowStateDelegate. |
| 141 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { | 155 virtual bool EnterImmersiveFullscreen( |
| 142 // Windows which cannot be maximized should not be fullscreened. | 156 ash::wm::WindowState* window_state) OVERRIDE { |
| 143 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); | 157 if (!window_state_->IsFullscreen()) { |
| 144 if (window_state->IsFullscreen()) | 158 if (shell_window_->GetBaseWindow()->SupportsImmersiveFullscreen()) |
| 159 shell_window_->ImmersiveFullscreen(); | |
| 160 else | |
| 161 shell_window_->Fullscreen(); | |
|
oshima
2013/11/07 18:56:13
Isn't it better to do all these check and immersiv
| |
| 162 } | |
| 163 return true; | |
| 164 } | |
| 165 virtual bool ExitFullscreen(ash::wm::WindowState* window_state) OVERRIDE { | |
| 166 if (window_state_->IsFullscreen()) | |
| 145 shell_window_->Restore(); | 167 shell_window_->Restore(); |
| 146 else if (window_state->CanMaximize()) | |
| 147 shell_window_->Fullscreen(); | |
| 148 return true; | 168 return true; |
| 149 } | 169 } |
| 150 | 170 |
| 151 private: | 171 private: |
| 152 ShellWindow* shell_window_; // not owned. | 172 // Overridden from ash::wm::WindowStateObserver: |
| 173 virtual void OnWindowShowTypeChanged(ash::wm::WindowState* window_state, | |
| 174 ash::wm::WindowShowType* old_type) { | |
| 175 if (!window_state_->IsFullscreen() && | |
| 176 !window_state_->IsMinimized() && | |
| 177 shell_window_->fullscreen_type() != ShellWindow::FULLSCREEN_TYPE_NONE) { | |
| 178 shell_window_->Restore(); | |
| 179 } | |
| 180 } | |
| 181 | |
| 182 // Not owned. | |
| 183 ShellWindow* shell_window_; | |
| 184 ash::wm::WindowState* window_state_; | |
| 153 | 185 |
| 154 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | 186 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
| 155 }; | 187 }; |
| 156 #endif // USE_ASH | 188 #endif // USE_ASH |
| 157 | 189 |
| 158 } // namespace | 190 } // namespace |
| 159 | 191 |
| 160 NativeAppWindowViews::NativeAppWindowViews( | 192 NativeAppWindowViews::NativeAppWindowViews( |
| 161 ShellWindow* shell_window, | 193 ShellWindow* shell_window, |
| 162 const ShellWindow::CreateParams& create_params) | 194 const ShellWindow::CreateParams& create_params) |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 184 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 216 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 185 shell_window_)); | 217 shell_window_)); |
| 186 | 218 |
| 187 OnViewWasResized(); | 219 OnViewWasResized(); |
| 188 window_->AddObserver(this); | 220 window_->AddObserver(this); |
| 189 #if defined(USE_ASH) | 221 #if defined(USE_ASH) |
| 190 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == | 222 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == |
| 191 chrome::HOST_DESKTOP_TYPE_ASH) { | 223 chrome::HOST_DESKTOP_TYPE_ASH) { |
| 192 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | 224 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
| 193 scoped_ptr<ash::wm::WindowStateDelegate>( | 225 scoped_ptr<ash::wm::WindowStateDelegate>( |
| 194 new NativeAppWindowStateDelegate(shell_window)).Pass()); | 226 new NativeAppWindowStateDelegate(shell_window, this)).Pass()); |
| 195 } | 227 } |
| 196 #endif | 228 #endif |
| 197 } | 229 } |
| 198 | 230 |
| 199 NativeAppWindowViews::~NativeAppWindowViews() { | 231 NativeAppWindowViews::~NativeAppWindowViews() { |
| 200 web_view_->SetWebContents(NULL); | 232 web_view_->SetWebContents(NULL); |
| 201 } | 233 } |
| 202 | 234 |
| 203 void NativeAppWindowViews::InitializeDefaultWindow( | 235 void NativeAppWindowViews::InitializeDefaultWindow( |
| 204 const ShellWindow::CreateParams& create_params) { | 236 const ShellWindow::CreateParams& create_params) { |
| (...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 694 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
| 663 views::Widget* widget) { | 695 views::Widget* widget) { |
| 664 #if defined(USE_ASH) | 696 #if defined(USE_ASH) |
| 665 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 697 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 666 if (shell_window_->window_type_is_panel()) { | 698 if (shell_window_->window_type_is_panel()) { |
| 667 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 699 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
| 668 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 700 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 669 return new ash::PanelFrameView(widget, frame_type); | 701 return new ash::PanelFrameView(widget, frame_type); |
| 670 } | 702 } |
| 671 if (!frameless_) { | 703 if (!frameless_) { |
| 672 return new ash::CustomFrameViewAsh(widget); | 704 ash::CustomFrameViewAsh* custom_frame_view = |
| 705 new ash::CustomFrameViewAsh(widget); | |
| 706 #if defined(OS_CHROMEOS) | |
|
oshima
2013/11/07 18:56:13
why this is chromeos only? shouldn't we use the sa
pkotwicz
2013/11/07 22:21:48
This is chromeos only because browser immersive fu
oshima
2013/11/08 00:26:29
So win8 ash mode doesn't support immersive fullscr
pkotwicz
2013/11/08 01:16:57
No
| |
| 707 // Non-frameless app windows can be put into immersive fullscreen. | |
| 708 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for | |
| 709 // Windows Ash. | |
| 710 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
| 711 ash::switches::kAshEnableAppImmersiveFullscreen)) { | |
| 712 immersive_fullscreen_controller_.reset( | |
| 713 new ash::ImmersiveFullscreenController()); | |
| 714 custom_frame_view->InitImmersiveFullscreenControllerForView( | |
| 715 immersive_fullscreen_controller_.get()); | |
| 716 } | |
| 717 #endif | |
| 718 return custom_frame_view; | |
| 673 } | 719 } |
| 674 } | 720 } |
| 675 #endif | 721 #endif |
| 676 if (ShouldUseChromeStyleFrame()) | 722 if (ShouldUseChromeStyleFrame()) |
| 677 return CreateShellWindowFrameView(); | 723 return CreateShellWindowFrameView(); |
| 678 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 724 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 679 } | 725 } |
| 680 | 726 |
| 681 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 727 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 682 return input_region_ != NULL; | 728 return input_region_ != NULL; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 786 Close(); | 832 Close(); |
| 787 return true; | 833 return true; |
| 788 default: | 834 default: |
| 789 NOTREACHED() << "Unknown accelerator sent to app window."; | 835 NOTREACHED() << "Unknown accelerator sent to app window."; |
| 790 } | 836 } |
| 791 return false; | 837 return false; |
| 792 } | 838 } |
| 793 | 839 |
| 794 // NativeAppWindow implementation. | 840 // NativeAppWindow implementation. |
| 795 | 841 |
| 796 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 842 void NativeAppWindowViews::SetFullscreen(ShellWindow::FullscreenType type) { |
| 797 // Fullscreen not supported by panels. | 843 // Fullscreen not supported by panels. |
| 798 if (shell_window_->window_type_is_panel()) | 844 if (shell_window_->window_type_is_panel()) |
| 799 return; | 845 return; |
| 800 is_fullscreen_ = fullscreen; | 846 is_fullscreen_ = (type != ShellWindow::FULLSCREEN_TYPE_NONE); |
| 801 window_->SetFullscreen(fullscreen); | 847 window_->SetFullscreen(is_fullscreen_); |
| 848 | |
| 849 #if defined(USE_ASH) | |
| 850 if (immersive_fullscreen_controller_.get()) { | |
| 851 bool is_immersive = (type == ShellWindow::FULLSCREEN_TYPE_IMMERSIVE); | |
| 852 if (is_immersive != immersive_fullscreen_controller_->IsEnabled()) { | |
| 853 immersive_fullscreen_controller_->SetEnabled(is_immersive); | |
| 854 shell_window_->OnNativeWindowChanged(); | |
| 855 } | |
| 856 } | |
| 857 #endif | |
| 858 | |
| 802 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 859 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 803 // ever drop the window out of fullscreen in response to something that | 860 // ever drop the window out of fullscreen in response to something that |
| 804 // wasn't the app calling webkitCancelFullScreen(). | 861 // wasn't the app calling webkitCancelFullScreen(). |
| 805 } | 862 } |
| 806 | 863 |
| 807 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 864 bool NativeAppWindowViews::SupportsImmersiveFullscreen() const { |
| 808 return is_fullscreen_; | 865 #if defined(USE_ASH) |
| 866 return immersive_fullscreen_controller_.get(); | |
| 867 #endif | |
| 868 return false; | |
| 809 } | 869 } |
| 810 | 870 |
| 811 bool NativeAppWindowViews::IsDetached() const { | 871 bool NativeAppWindowViews::IsDetached() const { |
| 812 if (!shell_window_->window_type_is_panel()) | 872 if (!shell_window_->window_type_is_panel()) |
| 813 return false; | 873 return false; |
| 814 #if defined(USE_ASH) | 874 #if defined(USE_ASH) |
| 815 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); | 875 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); |
| 816 #else | 876 #else |
| 817 return false; | 877 return false; |
| 818 #endif | 878 #endif |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 873 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 933 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 874 gfx::Rect window_bounds = | 934 gfx::Rect window_bounds = |
| 875 window_->non_client_view()->GetWindowBoundsForClientBounds( | 935 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 876 client_bounds); | 936 client_bounds); |
| 877 return window_bounds.InsetsFrom(client_bounds); | 937 return window_bounds.InsetsFrom(client_bounds); |
| 878 } | 938 } |
| 879 | 939 |
| 880 void NativeAppWindowViews::HideWithApp() {} | 940 void NativeAppWindowViews::HideWithApp() {} |
| 881 void NativeAppWindowViews::ShowWithApp() {} | 941 void NativeAppWindowViews::ShowWithApp() {} |
| 882 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 942 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |