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. | |
|
benwells
2013/11/14 00:06:54
Could you file a bug for this?
pkotwicz
2013/11/14 01:05:24
Done.
| |
| 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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 667 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( | 694 views::NonClientFrameView* NativeAppWindowViews::CreateNonClientFrameView( |
| 668 views::Widget* widget) { | 695 views::Widget* widget) { |
| 669 #if defined(USE_ASH) | 696 #if defined(USE_ASH) |
| 670 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { | 697 if (chrome::IsNativeViewInAsh(widget->GetNativeView())) { |
| 671 if (shell_window_->window_type_is_panel()) { | 698 if (shell_window_->window_type_is_panel()) { |
| 672 ash::PanelFrameView::FrameType frame_type = frameless_ ? | 699 ash::PanelFrameView::FrameType frame_type = frameless_ ? |
| 673 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; | 700 ash::PanelFrameView::FRAME_NONE : ash::PanelFrameView::FRAME_ASH; |
| 674 return new ash::PanelFrameView(widget, frame_type); | 701 return new ash::PanelFrameView(widget, frame_type); |
| 675 } | 702 } |
| 676 if (!frameless_) { | 703 if (!frameless_) { |
| 677 return new ash::CustomFrameViewAsh(widget); | 704 ash::CustomFrameViewAsh* custom_frame_view = |
| 705 new ash::CustomFrameViewAsh(widget); | |
| 706 #if defined(OS_CHROMEOS) | |
| 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::kAshEnableImmersiveFullscreenForAllWindows)) { | |
| 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; | |
| 678 } | 719 } |
| 679 } | 720 } |
| 680 #endif | 721 #endif |
| 681 if (ShouldUseChromeStyleFrame()) | 722 if (ShouldUseChromeStyleFrame()) |
| 682 return CreateShellWindowFrameView(); | 723 return CreateShellWindowFrameView(); |
| 683 return views::WidgetDelegateView::CreateNonClientFrameView(widget); | 724 return views::WidgetDelegateView::CreateNonClientFrameView(widget); |
| 684 } | 725 } |
| 685 | 726 |
| 686 bool NativeAppWindowViews::WidgetHasHitTestMask() const { | 727 bool NativeAppWindowViews::WidgetHasHitTestMask() const { |
| 687 return input_region_ != NULL; | 728 return input_region_ != NULL; |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 791 Close(); | 832 Close(); |
| 792 return true; | 833 return true; |
| 793 default: | 834 default: |
| 794 NOTREACHED() << "Unknown accelerator sent to app window."; | 835 NOTREACHED() << "Unknown accelerator sent to app window."; |
| 795 } | 836 } |
| 796 return false; | 837 return false; |
| 797 } | 838 } |
| 798 | 839 |
| 799 // NativeAppWindow implementation. | 840 // NativeAppWindow implementation. |
| 800 | 841 |
| 801 void NativeAppWindowViews::SetFullscreen(bool fullscreen) { | 842 void NativeAppWindowViews::SetFullscreen(int fullscreen_types) { |
| 802 // Fullscreen not supported by panels. | 843 // Fullscreen not supported by panels. |
| 803 if (shell_window_->window_type_is_panel()) | 844 if (shell_window_->window_type_is_panel()) |
| 804 return; | 845 return; |
| 805 is_fullscreen_ = fullscreen; | 846 is_fullscreen_ = (fullscreen_types != ShellWindow::FULLSCREEN_TYPE_NONE); |
| 806 window_->SetFullscreen(fullscreen); | 847 window_->SetFullscreen(is_fullscreen_); |
| 848 | |
| 849 #if defined(USE_ASH) | |
| 850 if (immersive_fullscreen_controller_.get()) { | |
| 851 // |immersive_fullscreen_controller_| should only be set if immersive | |
| 852 // fullscreen is the fullscreen type used by the OS. | |
| 853 immersive_fullscreen_controller_->SetEnabled( | |
| 854 fullscreen_types & ShellWindow::FULLSCREEN_TYPE_OS); | |
| 855 // Autohide the shelf instead of hiding the shelf completely when only in | |
| 856 // OS fullscreen. | |
| 857 ash::wm::WindowState* window_state = | |
| 858 ash::wm::GetWindowState(window_->GetNativeWindow()); | |
| 859 window_state->set_hide_shelf_when_fullscreen( | |
| 860 fullscreen_types != ShellWindow::FULLSCREEN_TYPE_OS); | |
| 861 DCHECK(ash::Shell::HasInstance()); | |
| 862 ash::Shell::GetInstance()->UpdateShelfVisibility(); | |
| 863 } | |
| 864 #endif | |
| 865 | |
| 807 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we | 866 // TODO(jeremya) we need to call RenderViewHost::ExitFullscreen() if we |
| 808 // ever drop the window out of fullscreen in response to something that | 867 // ever drop the window out of fullscreen in response to something that |
| 809 // wasn't the app calling webkitCancelFullScreen(). | 868 // wasn't the app calling webkitCancelFullScreen(). |
| 810 } | 869 } |
| 811 | 870 |
| 812 bool NativeAppWindowViews::IsFullscreenOrPending() const { | 871 bool NativeAppWindowViews::IsFullscreenOrPending() const { |
| 813 return is_fullscreen_; | 872 return is_fullscreen_; |
| 814 } | 873 } |
| 815 | 874 |
| 816 bool NativeAppWindowViews::IsDetached() const { | 875 bool NativeAppWindowViews::IsDetached() const { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 878 gfx::Rect client_bounds = gfx::Rect(1000, 1000); | 937 gfx::Rect client_bounds = gfx::Rect(1000, 1000); |
| 879 gfx::Rect window_bounds = | 938 gfx::Rect window_bounds = |
| 880 window_->non_client_view()->GetWindowBoundsForClientBounds( | 939 window_->non_client_view()->GetWindowBoundsForClientBounds( |
| 881 client_bounds); | 940 client_bounds); |
| 882 return window_bounds.InsetsFrom(client_bounds); | 941 return window_bounds.InsetsFrom(client_bounds); |
| 883 } | 942 } |
| 884 | 943 |
| 885 void NativeAppWindowViews::HideWithApp() {} | 944 void NativeAppWindowViews::HideWithApp() {} |
| 886 void NativeAppWindowViews::ShowWithApp() {} | 945 void NativeAppWindowViews::ShowWithApp() {} |
| 887 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} | 946 void NativeAppWindowViews::UpdateWindowMinMaxSize() {} |
| OLD | NEW |