| 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. http://crbug.com/319048 |
| 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_->OSFullscreen(); |
| 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( |
| 168 ash::wm::WindowState* window_state, |
| 169 ash::wm::WindowShowType old_type) OVERRIDE { |
| 170 if (!window_state->IsFullscreen() && |
| 171 !window_state->IsMinimized() && |
| 172 shell_window_->GetBaseWindow()->IsFullscreenOrPending()) { |
| 173 shell_window_->Restore(); |
| 174 } |
| 175 } |
| 176 |
| 177 // Not owned. |
| 178 ShellWindow* shell_window_; |
| 179 ash::wm::WindowState* window_state_; |
| 153 | 180 |
| 154 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); | 181 DISALLOW_COPY_AND_ASSIGN(NativeAppWindowStateDelegate); |
| 155 }; | 182 }; |
| 156 #endif // USE_ASH | 183 #endif // USE_ASH |
| 157 | 184 |
| 158 } // namespace | 185 } // namespace |
| 159 | 186 |
| 160 NativeAppWindowViews::NativeAppWindowViews( | 187 NativeAppWindowViews::NativeAppWindowViews( |
| 161 ShellWindow* shell_window, | 188 ShellWindow* shell_window, |
| 162 const ShellWindow::CreateParams& create_params) | 189 const ShellWindow::CreateParams& create_params) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 184 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 211 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 185 shell_window_)); | 212 shell_window_)); |
| 186 | 213 |
| 187 OnViewWasResized(); | 214 OnViewWasResized(); |
| 188 window_->AddObserver(this); | 215 window_->AddObserver(this); |
| 189 #if defined(USE_ASH) | 216 #if defined(USE_ASH) |
| 190 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == | 217 if (chrome::GetHostDesktopTypeForNativeView(GetNativeWindow()) == |
| 191 chrome::HOST_DESKTOP_TYPE_ASH) { | 218 chrome::HOST_DESKTOP_TYPE_ASH) { |
| 192 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( | 219 ash::wm::GetWindowState(GetNativeWindow())->SetDelegate( |
| 193 scoped_ptr<ash::wm::WindowStateDelegate>( | 220 scoped_ptr<ash::wm::WindowStateDelegate>( |
| 194 new NativeAppWindowStateDelegate(shell_window)).Pass()); | 221 new NativeAppWindowStateDelegate(shell_window, this)).Pass()); |
| 195 } | 222 } |
| 196 #endif | 223 #endif |
| 197 } | 224 } |
| 198 | 225 |
| 199 NativeAppWindowViews::~NativeAppWindowViews() { | 226 NativeAppWindowViews::~NativeAppWindowViews() { |
| 200 web_view_->SetWebContents(NULL); | 227 web_view_->SetWebContents(NULL); |
| 201 } | 228 } |
| 202 | 229 |
| 203 void NativeAppWindowViews::OnBeforeWidgetInit( | 230 void NativeAppWindowViews::OnBeforeWidgetInit( |
| 204 views::Widget::InitParams* init_params, | 231 views::Widget::InitParams* init_params, |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 669 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 696 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
| 670 views::Widget* widget) { | 697 views::Widget* widget) { |
| 671 #if defined(USE_ASH) | 698 #if defined(USE_ASH) |
| 672 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 699 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 673 if (shell_window_->window_type_is_panel()) { | 700 if (shell_window_->window_type_is_panel()) { |
| 674 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 701 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
| 675 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 702 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 676 return new ash::PanelFrameView(widget, frame_type); | 703 return new ash::PanelFrameView(widget, frame_type); |
| 677 } | 704 } |
| 678 if (!frameless_) { | 705 if (!frameless_) { |
| 679 return new ash::CustomFrameViewAsh(widget); | 706 ash::CustomFrameViewAsh* custom_frame_view = |
| 707 new ash::CustomFrameViewAsh(widget); |
| 708 #if defined(OS_CHROMEOS) |
| 709 // Non-frameless app windows can be put into immersive fullscreen. |
| 710 // TODO(pkotwicz): Investigate if immersive fullscreen can be enabled for |
| 711 // Windows Ash. |
| 712 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 713 ash::switches::kAshEnableImmersiveFullscreenForAllWindows)) { |
| 714 immersive_fullscreen_controller_.reset( |
| 715 new ash::ImmersiveFullscreenController()); |
| 716 custom_frame_view->InitImmersiveFullscreenControllerForView( |
| 717 immersive_fullscreen_controller_.get()); |
| 718 } |
| 719 #endif |
| 720 return custom_frame_view; |
| 680 } | 721 } |
| 681 } | 722 } |
| 682 #endif | 723 #endif |
| 683 if (ShouldUseChromeStyleFrame()) | 724 if (ShouldUseChromeStyleFrame()) |
| 684 return CreateShellWindowFrameView(); | 725 return CreateShellWindowFrameView(); |
| 685 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 726 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 686 } | 727 } |
| 687 | 728 |
| 688 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 729 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 689 return input_region_ != NULL; | 730 return input_region_ != NULL; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 793 Close(); | 834 Close(); |
| 794 return true; | 835 return true; |
| 795 default: | 836 default: |
| 796 NOTREACHED() << "Unknown accelerator sent to app window."; | 837 NOTREACHED() << "Unknown accelerator sent to app window."; |
| 797 } | 838 } |
| 798 return false; | 839 return false; |
| 799 } | 840 } |
| 800 | 841 |
| 801 // NativeAppWindow implementation. | 842 // NativeAppWindow implementation. |
| 802 | 843 |
| 803 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 844 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 804 // Fullscreen not supported by panels. | 845 // Fullscreen not supported by panels. |
| 805 if (shell_window_->window_type_is_panel()) | 846 if (shell_window_->window_type_is_panel()) |
| 806 return; | 847 return; |
| 807 is_fullscreen_ = fullscreen; | 848 is_fullscreen_ = (fullscreen_types != ShellWindow::FULLSCREEN_TYPE_NONE); |
| 808 window_->SetFullscreen(fullscreen); | 849 window_->SetFullscreen(is_fullscreen_); |
| 850 |
| 851 #if defined(USE_ASH) |
| 852 if (immersive_fullscreen_controller_.get()) { |
| 853 // |immersive_fullscreen_controller_| should only be set if immersive |
| 854 // fullscreen is the fullscreen type used by the OS. |
| 855 immersive_fullscreen_controller_->SetEnabled( |
| 856 (fullscreen_types & ShellWindow::FULLSCREEN_TYPE_OS) != 0); |
| 857 // Autohide the shelf instead of hiding the shelf completely when only in |
| 858 // OS fullscreen. |
| 859 ash::wm::WindowState* window_state = |
| 860 ash::wm::GetWindowState(window_->GetNativeWindow()); |
| 861 window_state->set_hide_shelf_when_fullscreen( |
| 862 fullscreen_types != ShellWindow::FULLSCREEN_TYPE_OS); |
| 863 DCHECK(ash::Shell::HasInstance()); |
| 864 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 865 } |
| 866 #endif |
| 867 |
| 809 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 868 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 810 // ever drop the window out of fullscreen in response to something that | 869 // ever drop the window out of fullscreen in response to something that |
| 811 // wasn't the app calling webkitCancelFullScreen(). | 870 // wasn't the app calling webkitCancelFullScreen(). |
| 812 } | 871 } |
| 813 | 872 |
| 814 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 873 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 815 return is_fullscreen_; | 874 return is_fullscreen_; |
| 816 } | 875 } |
| 817 | 876 |
| 818 bool NativeAppWindowViews::IsDetached() const { | 877 bool NativeAppWindowViews::IsDetached() const { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 880 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 939 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 881 gfx::Rect window_bounds = | 940 gfx::Rect window_bounds = |
| 882 window_->non_client_view()->GetWindowBoundsForClientBounds( | 941 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 883 client_bounds); | 942 client_bounds); |
| 884 return window_bounds.InsetsFrom(client_bounds); | 943 return window_bounds.InsetsFrom(client_bounds); |
| 885 } | 944 } |
| 886 | 945 |
| 887 void NativeAppWindowViews::HideWithApp() {} | 946 void NativeAppWindowViews::HideWithApp() {} |
| 888 void NativeAppWindowViews::ShowWithApp() {} | 947 void NativeAppWindowViews::ShowWithApp() {} |
| 889 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 948 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |