| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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/frame/immersive_mode_controller_ash.h" | 5 #include "chrome/browser/ui/views/frame/immersive_mode_controller_ash.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/wm/window_state.h" | 8 #include "ash/common/wm/window_state.h" |
| 9 #include "ash/shared/immersive_revealed_lock.h" | 9 #include "ash/shared/immersive_revealed_lock.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 }; | 108 }; |
| 109 | 109 |
| 110 } // namespace | 110 } // namespace |
| 111 | 111 |
| 112 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 112 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| 113 : ImmersiveModeController(Type::ASH), | 113 : ImmersiveModeController(Type::ASH), |
| 114 controller_(new ash::ImmersiveFullscreenController), | 114 controller_(new ash::ImmersiveFullscreenController), |
| 115 browser_view_(nullptr), | 115 browser_view_(nullptr), |
| 116 native_window_(nullptr), | 116 native_window_(nullptr), |
| 117 observers_enabled_(false), | 117 observers_enabled_(false), |
| 118 use_tab_indicators_(false), | |
| 119 visible_fraction_(1) {} | 118 visible_fraction_(1) {} |
| 120 | 119 |
| 121 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { | 120 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { |
| 122 EnableWindowObservers(false); | 121 EnableWindowObservers(false); |
| 123 } | 122 } |
| 124 | 123 |
| 125 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { | 124 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { |
| 126 browser_view_ = browser_view; | 125 browser_view_ = browser_view; |
| 127 native_window_ = browser_view_->GetNativeWindow(); | 126 native_window_ = browser_view_->GetNativeWindow(); |
| 128 controller_->Init(this, browser_view_->frame(), | 127 controller_->Init(this, browser_view_->frame(), |
| 129 browser_view_->top_container()); | 128 browser_view_->top_container()); |
| 130 } | 129 } |
| 131 | 130 |
| 132 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { | 131 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| 133 if (controller_->IsEnabled() == enabled) | 132 if (controller_->IsEnabled() == enabled) |
| 134 return; | 133 return; |
| 135 | 134 |
| 136 EnableWindowObservers(enabled); | 135 EnableWindowObservers(enabled); |
| 137 | 136 |
| 138 controller_->SetEnabled(browser_view_->browser()->is_app() ? | 137 controller_->SetEnabled(browser_view_->browser()->is_app() ? |
| 139 ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP : | 138 ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP : |
| 140 ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER | 139 ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER |
| 141 , enabled); | 140 , enabled); |
| 142 } | 141 } |
| 143 | 142 |
| 144 bool ImmersiveModeControllerAsh::IsEnabled() const { | 143 bool ImmersiveModeControllerAsh::IsEnabled() const { |
| 145 return controller_->IsEnabled(); | 144 return controller_->IsEnabled(); |
| 146 } | 145 } |
| 147 | 146 |
| 148 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { | |
| 149 return !use_tab_indicators_; | |
| 150 } | |
| 151 | |
| 152 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { | 147 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
| 153 return controller_->IsEnabled() && !controller_->IsRevealed(); | 148 return controller_->IsEnabled() && !controller_->IsRevealed(); |
| 154 } | 149 } |
| 155 | 150 |
| 156 bool ImmersiveModeControllerAsh::IsRevealed() const { | 151 bool ImmersiveModeControllerAsh::IsRevealed() const { |
| 157 return controller_->IsRevealed(); | 152 return controller_->IsRevealed(); |
| 158 } | 153 } |
| 159 | 154 |
| 160 int ImmersiveModeControllerAsh::GetTopContainerVerticalOffset( | 155 int ImmersiveModeControllerAsh::GetTopContainerVerticalOffset( |
| 161 const gfx::Size& top_container_size) const { | 156 const gfx::Size& top_container_size) const { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 218 |
| 224 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { | 219 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { |
| 225 views::Widget* widget = browser_view_->frame(); | 220 views::Widget* widget = browser_view_->frame(); |
| 226 // Update the window caption buttons. | 221 // Update the window caption buttons. |
| 227 widget->non_client_view()->frame_view()->ResetWindowControls(); | 222 widget->non_client_view()->frame_view()->ResetWindowControls(); |
| 228 widget->non_client_view()->frame_view()->InvalidateLayout(); | 223 widget->non_client_view()->frame_view()->InvalidateLayout(); |
| 229 browser_view_->InvalidateLayout(); | 224 browser_view_->InvalidateLayout(); |
| 230 widget->GetRootView()->Layout(); | 225 widget->GetRootView()->Layout(); |
| 231 } | 226 } |
| 232 | 227 |
| 233 // TODO(yiyix|tdanderson): Once Chrome OS material design is enabled by default, | 228 void ImmersiveModeControllerAsh::UpdateTabStrip() { |
| 234 // remove all code related to immersive mode hints (here, in TabStrip and | 229 if (!browser_view_->IsBrowserTypeNormal()) |
| 235 // BrowserNonClientFrameViewAsh::OnPaint()). See crbug.com/614453. | 230 return; |
| 236 bool ImmersiveModeControllerAsh::UpdateTabIndicators() { | |
| 237 if (ash::MaterialDesignController::IsImmersiveModeMaterial()) | |
| 238 return false; | |
| 239 | 231 |
| 240 bool has_tabstrip = browser_view_->IsBrowserTypeNormal(); | 232 browser_view_->tabstrip()->set_offscreen(IsEnabled() && !IsRevealed()); |
| 241 if (!IsEnabled() || !has_tabstrip) { | |
| 242 use_tab_indicators_ = false; | |
| 243 } else { | |
| 244 bool in_tab_fullscreen = browser_view_->browser() | |
| 245 ->exclusive_access_manager() | |
| 246 ->fullscreen_controller() | |
| 247 ->IsWindowFullscreenForTabOrPending(); | |
| 248 use_tab_indicators_ = !in_tab_fullscreen; | |
| 249 } | |
| 250 | |
| 251 bool show_tab_indicators = use_tab_indicators_ && !IsRevealed(); | |
| 252 if (show_tab_indicators != browser_view_->tabstrip()->IsImmersiveStyle()) { | |
| 253 browser_view_->tabstrip()->SetImmersiveStyle(show_tab_indicators); | |
| 254 return true; | |
| 255 } | |
| 256 return false; | |
| 257 } | 233 } |
| 258 | 234 |
| 259 void ImmersiveModeControllerAsh::CreateMashRevealWidget() { | 235 void ImmersiveModeControllerAsh::CreateMashRevealWidget() { |
| 260 if (!chrome::IsRunningInMash()) | 236 if (!chrome::IsRunningInMash()) |
| 261 return; | 237 return; |
| 262 | 238 |
| 263 DCHECK(!mash_reveal_widget_); | 239 DCHECK(!mash_reveal_widget_); |
| 264 mash_reveal_widget_ = base::MakeUnique<views::Widget>(); | 240 mash_reveal_widget_ = base::MakeUnique<views::Widget>(); |
| 265 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_POPUP); | 241 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_POPUP); |
| 266 init_params.mus_properties | 242 init_params.mus_properties |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { | 278 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { |
| 303 DestroyMashRevealWidget(); | 279 DestroyMashRevealWidget(); |
| 304 | 280 |
| 305 visible_fraction_ = 0; | 281 visible_fraction_ = 0; |
| 306 browser_view_->top_container()->SetPaintToLayer(); | 282 browser_view_->top_container()->SetPaintToLayer(); |
| 307 // In mash the window manager (ash) also renders to the non-client area. In | 283 // In mash the window manager (ash) also renders to the non-client area. In |
| 308 // order to see the decorations drawn by ash the layer needs to be marked as | 284 // order to see the decorations drawn by ash the layer needs to be marked as |
| 309 // not filling bounds opaquely. | 285 // not filling bounds opaquely. |
| 310 if (chrome::IsRunningInMash()) | 286 if (chrome::IsRunningInMash()) |
| 311 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); | 287 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); |
| 312 UpdateTabIndicators(); | 288 UpdateTabStrip(); |
| 313 LayoutBrowserRootView(); | 289 LayoutBrowserRootView(); |
| 314 CreateMashRevealWidget(); | 290 CreateMashRevealWidget(); |
| 315 for (Observer& observer : observers_) | 291 for (Observer& observer : observers_) |
| 316 observer.OnImmersiveRevealStarted(); | 292 observer.OnImmersiveRevealStarted(); |
| 317 } | 293 } |
| 318 | 294 |
| 319 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { | 295 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { |
| 320 DestroyMashRevealWidget(); | 296 DestroyMashRevealWidget(); |
| 321 visible_fraction_ = 0; | 297 visible_fraction_ = 0; |
| 322 browser_view_->top_container()->DestroyLayer(); | 298 browser_view_->top_container()->DestroyLayer(); |
| 323 UpdateTabIndicators(); | 299 UpdateTabStrip(); |
| 324 LayoutBrowserRootView(); | 300 LayoutBrowserRootView(); |
| 325 for (Observer& observer : observers_) | 301 for (Observer& observer : observers_) |
| 326 observer.OnImmersiveRevealEnded(); | 302 observer.OnImmersiveRevealEnded(); |
| 327 } | 303 } |
| 328 | 304 |
| 329 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { | 305 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { |
| 330 DestroyMashRevealWidget(); | 306 DestroyMashRevealWidget(); |
| 331 browser_view_->top_container()->DestroyLayer(); | 307 browser_view_->top_container()->DestroyLayer(); |
| 332 UpdateTabIndicators(); | 308 UpdateTabStrip(); |
| 333 LayoutBrowserRootView(); | 309 LayoutBrowserRootView(); |
| 334 } | 310 } |
| 335 | 311 |
| 336 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { | 312 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { |
| 337 if (visible_fraction_ == visible_fraction) | 313 if (visible_fraction_ == visible_fraction) |
| 338 return; | 314 return; |
| 339 | 315 |
| 340 visible_fraction_ = visible_fraction; | 316 visible_fraction_ = visible_fraction; |
| 341 browser_view_->Layout(); | 317 browser_view_->Layout(); |
| 342 browser_view_->frame()->GetFrameView()->UpdateClientArea(); | 318 browser_view_->frame()->GetFrameView()->UpdateClientArea(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 363 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 388 if (!controller_->IsEnabled()) | 364 if (!controller_->IsEnabled()) |
| 389 return; | 365 return; |
| 390 | 366 |
| 391 if (chrome::IsRunningInMash()) { | 367 if (chrome::IsRunningInMash()) { |
| 392 // TODO: http://crbug.com/640384. | 368 // TODO: http://crbug.com/640384. |
| 393 NOTIMPLEMENTED(); | 369 NOTIMPLEMENTED(); |
| 394 return; | 370 return; |
| 395 } | 371 } |
| 396 | 372 |
| 397 bool tab_indicator_visibility_changed = UpdateTabIndicators(); | 373 UpdateTabStrip(); |
| 398 | 374 |
| 399 // Auto hide the shelf in immersive browser fullscreen. When auto hidden and | 375 // Auto hide the shelf in immersive browser fullscreen. When auto hidden and |
| 400 // Material Design is not enabled, the shelf displays a 3px 'light bar' when | 376 // Material Design is not enabled, the shelf displays a 3px 'light bar' when |
| 401 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide | 377 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide |
| 402 // the shelf completely and prevent it from being revealed. | 378 // the shelf completely and prevent it from being revealed. |
| 403 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> | 379 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> |
| 404 IsWindowFullscreenForTabOrPending(); | 380 IsWindowFullscreenForTabOrPending(); |
| 405 ash::wm::GetWindowState(native_window_) | 381 ash::wm::GetWindowState(native_window_) |
| 406 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); | 382 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); |
| 407 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 383 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 408 | |
| 409 if (tab_indicator_visibility_changed) | |
| 410 LayoutBrowserRootView(); | |
| 411 } | 384 } |
| 412 | 385 |
| 413 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, | 386 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, |
| 414 const void* key, | 387 const void* key, |
| 415 intptr_t old) { | 388 intptr_t old) { |
| 416 // In mash the window manager may move us out of immersive mode by changing | 389 // In mash the window manager may move us out of immersive mode by changing |
| 417 // the show state. When this happens notify the controller. | 390 // the show state. When this happens notify the controller. |
| 418 DCHECK(chrome::IsRunningInMash()); | 391 DCHECK(chrome::IsRunningInMash()); |
| 419 if (key == aura::client::kShowStateKey && | 392 if (key == aura::client::kShowStateKey && |
| 420 !browser_view_->GetWidget()->IsFullscreen()) { | 393 !browser_view_->GetWidget()->IsFullscreen()) { |
| 421 SetEnabled(false); | 394 SetEnabled(false); |
| 422 } | 395 } |
| 423 } | 396 } |
| OLD | NEW |