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 |
| 154 private: |
140 // Overridden from ash::wm::WindowStateDelegate. | 155 // Overridden from ash::wm::WindowStateDelegate. |
141 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { | 156 virtual bool ToggleFullscreen(ash::wm::WindowState* window_state) OVERRIDE { |
142 // Windows which cannot be maximized should not be fullscreened. | 157 // Windows which cannot be maximized should not be fullscreened. |
143 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); | 158 DCHECK(window_state->IsFullscreen() || window_state->CanMaximize()); |
144 if (window_state->IsFullscreen()) | 159 if (window_state->IsFullscreen()) |
145 shell_window_->Restore(); | 160 shell_window_->Restore(); |
146 else if (window_state->CanMaximize()) | 161 else if (window_state->CanMaximize()) |
147 shell_window_->Fullscreen(); | 162 shell_window_->ImmersiveFullscreen(); |
148 return true; | 163 return true; |
149 } | 164 } |
150 | 165 |
151 private: | 166 // Overridden from ash::wm::WindowStateObserver: |
152 ShellWindow* shell_window_; // not owned. | 167 virtual void OnWindowShowTypeChanged(ash::wm::WindowState* window_state, |
| 168 ash::wm::WindowShowType* old_type) { |
| 169 if (!window_state->IsFullscreen() && |
| 170 !window_state->IsMinimized() && |
| 171 shell_window_->fullscreen_type() != ShellWindow::FULLSCREEN_TYPE_NONE) { |
| 172 shell_window_->Restore(); |
| 173 } |
| 174 } |
| 175 |
| 176 // Not owned. |
| 177 ShellWindow* shell_window_; |
| 178 ash::wm::WindowState* window_state_; |
153 | 179 |
154 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | 180 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
155 }; | 181 }; |
156 #endif // USE_ASH | 182 #endif // USE_ASH |
157 | 183 |
158 } // namespace | 184 } // namespace |
159 | 185 |
160 NativeAppWindowViews::NativeAppWindowViews( | 186 NativeAppWindowViews::NativeAppWindowViews( |
161 ShellWindow* shell_window, | 187 ShellWindow* shell_window, |
162 const ShellWindow::CreateParams& create_params) | 188 const ShellWindow::CreateParams& create_params) |
(...skipping 21 matching lines...) Expand all Loading... |
184 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 210 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
185 shell_window_)); | 211 shell_window_)); |
186 | 212 |
187 OnViewWasResized(); | 213 OnViewWasResized(); |
188 window_->AddObserver(this); | 214 window_->AddObserver(this); |
189 #if defined(USE_ASH) | 215 #if defined(USE_ASH) |
190 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == | 216 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == |
191 chrome::HOST_DESKTOP_TYPE_ASH) { | 217 chrome::HOST_DESKTOP_TYPE_ASH) { |
192 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | 218 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
193 scoped_ptr<ash::wm::WindowStateDelegate>( | 219 scoped_ptr<ash::wm::WindowStateDelegate>( |
194 new NativeAppWindowStateDelegate(shell_window)).Pass()); | 220 new NativeAppWindowStateDelegate(shell_window, this)).Pass()); |
195 } | 221 } |
196 #endif | 222 #endif |
197 } | 223 } |
198 | 224 |
199 NativeAppWindowViews::~NativeAppWindowViews() { | 225 NativeAppWindowViews::~NativeAppWindowViews() { |
200 web_view_->SetWebContents(NULL); | 226 web_view_->SetWebContents(NULL); |
201 } | 227 } |
202 | 228 |
203 void NativeAppWindowViews::InitializeDefaultWindow( | 229 void NativeAppWindowViews::InitializeDefaultWindow( |
204 const ShellWindow::CreateParams& create_params) { | 230 const ShellWindow::CreateParams& create_params) { |
(...skipping 457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
662 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 688 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
663 views::Widget* widget) { | 689 views::Widget* widget) { |
664 #if defined(USE_ASH) | 690 #if defined(USE_ASH) |
665 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 691 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
666 if (shell_window_->window_type_is_panel()) { | 692 if (shell_window_->window_type_is_panel()) { |
667 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 693 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
668 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 694 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
669 return new ash::PanelFrameView(widget, frame_type); | 695 return new ash::PanelFrameView(widget, frame_type); |
670 } | 696 } |
671 if (!frameless_) { | 697 if (!frameless_) { |
672 return new ash::CustomFrameViewAsh(widget); | 698 ash::CustomFrameViewAsh* custom_frame_view = |
| 699 new ash::CustomFrameViewAsh(widget); |
| 700 #if defined(OS_CHROMEOS) |
| 701 // Non-frameless app windows can be put into immersive fullscreen. |
| 702 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for |
| 703 // Windows Ash. |
| 704 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 705 ash::switches::kAshEnableImmersiveFullscreenForAllWindows)) { |
| 706 immersive_fullscreen_controller_.reset( |
| 707 new ash::ImmersiveFullscreenController()); |
| 708 custom_frame_view->InitImmersiveFullscreenControllerForView( |
| 709 immersive_fullscreen_controller_.get()); |
| 710 } |
| 711 #endif |
| 712 return custom_frame_view; |
673 } | 713 } |
674 } | 714 } |
675 #endif | 715 #endif |
676 if (ShouldUseChromeStyleFrame()) | 716 if (ShouldUseChromeStyleFrame()) |
677 return CreateShellWindowFrameView(); | 717 return CreateShellWindowFrameView(); |
678 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 718 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
679 } | 719 } |
680 | 720 |
681 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 721 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
682 return input_region_ != NULL; | 722 return input_region_ != NULL; |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
786 Close(); | 826 Close(); |
787 return true; | 827 return true; |
788 default: | 828 default: |
789 NOTREACHED() << "Unknown accelerator sent to app window."; | 829 NOTREACHED() << "Unknown accelerator sent to app window."; |
790 } | 830 } |
791 return false; | 831 return false; |
792 } | 832 } |
793 | 833 |
794 // NativeAppWindow implementation. | 834 // NativeAppWindow implementation. |
795 | 835 |
796 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 836 void NativeAppWindowViews::SetFullscreen(ShellWindow::FullscreenType type) { |
797 // Fullscreen not supported by panels. | 837 // Fullscreen not supported by panels. |
798 if (shell_window_->window_type_is_panel()) | 838 if (shell_window_->window_type_is_panel()) |
799 return; | 839 return; |
800 is_fullscreen_ = fullscreen; | 840 is_fullscreen_ = (type != ShellWindow::FULLSCREEN_TYPE_NONE); |
801 window_->SetFullscreen(fullscreen); | 841 window_->SetFullscreen(is_fullscreen_); |
| 842 |
| 843 #if defined(USE_ASH) |
| 844 if (immersive_fullscreen_controller_.get()) { |
| 845 bool is_immersive = (type == ShellWindow::FULLSCREEN_TYPE_IMMERSIVE); |
| 846 if (is_immersive != immersive_fullscreen_controller_->IsEnabled()) { |
| 847 immersive_fullscreen_controller_->SetEnabled(is_immersive); |
| 848 shell_window_->OnNativeWindowChanged(); |
| 849 } |
| 850 } |
| 851 #endif |
| 852 |
802 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 853 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
803 // ever drop the window out of fullscreen in response to something that | 854 // ever drop the window out of fullscreen in response to something that |
804 // wasn't the app calling webkitCancelFullScreen(). | 855 // wasn't the app calling webkitCancelFullScreen(). |
805 } | 856 } |
806 | 857 |
807 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 858 bool NativeAppWindowViews::SupportsImmersiveFullscreen() const { |
808 return is_fullscreen_; | 859 #if defined(USE_ASH) |
| 860 return immersive_fullscreen_controller_.get(); |
| 861 #endif |
| 862 return false; |
809 } | 863 } |
810 | 864 |
811 bool NativeAppWindowViews::IsDetached() const { | 865 bool NativeAppWindowViews::IsDetached() const { |
812 if (!shell_window_->window_type_is_panel()) | 866 if (!shell_window_->window_type_is_panel()) |
813 return false; | 867 return false; |
814 #if defined(USE_ASH) | 868 #if defined(USE_ASH) |
815 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); | 869 return !ash::wm::GetWindowState(window_->GetNativeWindow())->panel_attached(); |
816 #else | 870 #else |
817 return false; | 871 return false; |
818 #endif | 872 #endif |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
873 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 927 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
874 gfx::Rect window_bounds = | 928 gfx::Rect window_bounds = |
875 window_->non_client_view()->GetWindowBoundsForClientBounds( | 929 window_->non_client_view()->GetWindowBoundsForClientBounds( |
876 client_bounds); | 930 client_bounds); |
877 return window_bounds.InsetsFrom(client_bounds); | 931 return window_bounds.InsetsFrom(client_bounds); |
878 } | 932 } |
879 | 933 |
880 void NativeAppWindowViews::HideWithApp() {} | 934 void NativeAppWindowViews::HideWithApp() {} |
881 void NativeAppWindowViews::ShowWithApp() {} | 935 void NativeAppWindowViews::ShowWithApp() {} |
882 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 936 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
OLD | NEW |