| 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 23 matching lines...) Expand all Loading... |
| 34 #include "ui/views/background.h" | 34 #include "ui/views/background.h" |
| 35 #include "ui/views/mus/mus_client.h" | 35 #include "ui/views/mus/mus_client.h" |
| 36 #include "ui/views/view.h" | 36 #include "ui/views/view.h" |
| 37 #include "ui/views/widget/native_widget_aura.h" | 37 #include "ui/views/widget/native_widget_aura.h" |
| 38 #include "ui/views/widget/widget.h" | 38 #include "ui/views/widget/widget.h" |
| 39 #include "ui/views/window/non_client_view.h" | 39 #include "ui/views/window/non_client_view.h" |
| 40 #include "ui/wm/core/window_util.h" | 40 #include "ui/wm/core/window_util.h" |
| 41 | 41 |
| 42 namespace { | 42 namespace { |
| 43 | 43 |
| 44 // Revealing the TopContainerView looks better if the animation starts and ends | |
| 45 // just a few pixels before the view goes offscreen, which reduces the visual | |
| 46 // "pop" as the 3-pixel tall "light bar" style tab strip becomes visible. | |
| 47 const int kAnimationOffsetY = 3; | |
| 48 | |
| 49 // Converts from ImmersiveModeController::AnimateReveal to | 44 // Converts from ImmersiveModeController::AnimateReveal to |
| 50 // ash::ImmersiveFullscreenController::AnimateReveal. | 45 // ash::ImmersiveFullscreenController::AnimateReveal. |
| 51 ash::ImmersiveFullscreenController::AnimateReveal | 46 ash::ImmersiveFullscreenController::AnimateReveal |
| 52 ToImmersiveFullscreenControllerAnimateReveal( | 47 ToImmersiveFullscreenControllerAnimateReveal( |
| 53 ImmersiveModeController::AnimateReveal animate_reveal) { | 48 ImmersiveModeController::AnimateReveal animate_reveal) { |
| 54 switch (animate_reveal) { | 49 switch (animate_reveal) { |
| 55 case ImmersiveModeController::ANIMATE_REVEAL_YES: | 50 case ImmersiveModeController::ANIMATE_REVEAL_YES: |
| 56 return ash::ImmersiveFullscreenController::ANIMATE_REVEAL_YES; | 51 return ash::ImmersiveFullscreenController::ANIMATE_REVEAL_YES; |
| 57 case ImmersiveModeController::ANIMATE_REVEAL_NO: | 52 case ImmersiveModeController::ANIMATE_REVEAL_NO: |
| 58 return ash::ImmersiveFullscreenController::ANIMATE_REVEAL_NO; | 53 return ash::ImmersiveFullscreenController::ANIMATE_REVEAL_NO; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 }; | 103 }; |
| 109 | 104 |
| 110 } // namespace | 105 } // namespace |
| 111 | 106 |
| 112 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 107 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
| 113 : ImmersiveModeController(Type::ASH), | 108 : ImmersiveModeController(Type::ASH), |
| 114 controller_(new ash::ImmersiveFullscreenController), | 109 controller_(new ash::ImmersiveFullscreenController), |
| 115 browser_view_(nullptr), | 110 browser_view_(nullptr), |
| 116 native_window_(nullptr), | 111 native_window_(nullptr), |
| 117 observers_enabled_(false), | 112 observers_enabled_(false), |
| 118 use_tab_indicators_(false), | |
| 119 visible_fraction_(1) {} | 113 visible_fraction_(1) {} |
| 120 | 114 |
| 121 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { | 115 ImmersiveModeControllerAsh::~ImmersiveModeControllerAsh() { |
| 122 EnableWindowObservers(false); | 116 EnableWindowObservers(false); |
| 123 } | 117 } |
| 124 | 118 |
| 125 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { | 119 void ImmersiveModeControllerAsh::Init(BrowserView* browser_view) { |
| 126 browser_view_ = browser_view; | 120 browser_view_ = browser_view; |
| 127 native_window_ = browser_view_->GetNativeWindow(); | 121 native_window_ = browser_view_->GetNativeWindow(); |
| 128 controller_->Init(this, browser_view_->frame(), | 122 controller_->Init(this, browser_view_->frame(), |
| 129 browser_view_->top_container()); | 123 browser_view_->top_container()); |
| 130 } | 124 } |
| 131 | 125 |
| 132 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { | 126 void ImmersiveModeControllerAsh::SetEnabled(bool enabled) { |
| 133 if (controller_->IsEnabled() == enabled) | 127 if (controller_->IsEnabled() == enabled) |
| 134 return; | 128 return; |
| 135 | 129 |
| 136 EnableWindowObservers(enabled); | 130 EnableWindowObservers(enabled); |
| 137 | 131 |
| 138 controller_->SetEnabled(browser_view_->browser()->is_app() ? | 132 controller_->SetEnabled(browser_view_->browser()->is_app() ? |
| 139 ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP : | 133 ash::ImmersiveFullscreenController::WINDOW_TYPE_HOSTED_APP : |
| 140 ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER | 134 ash::ImmersiveFullscreenController::WINDOW_TYPE_BROWSER |
| 141 , enabled); | 135 , enabled); |
| 142 } | 136 } |
| 143 | 137 |
| 144 bool ImmersiveModeControllerAsh::IsEnabled() const { | 138 bool ImmersiveModeControllerAsh::IsEnabled() const { |
| 145 return controller_->IsEnabled(); | 139 return controller_->IsEnabled(); |
| 146 } | 140 } |
| 147 | 141 |
| 148 bool ImmersiveModeControllerAsh::ShouldHideTabIndicators() const { | |
| 149 return !use_tab_indicators_; | |
| 150 } | |
| 151 | |
| 152 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { | 142 bool ImmersiveModeControllerAsh::ShouldHideTopViews() const { |
| 153 return controller_->IsEnabled() && !controller_->IsRevealed(); | 143 return controller_->IsEnabled() && !controller_->IsRevealed(); |
| 154 } | 144 } |
| 155 | 145 |
| 156 bool ImmersiveModeControllerAsh::IsRevealed() const { | 146 bool ImmersiveModeControllerAsh::IsRevealed() const { |
| 157 return controller_->IsRevealed(); | 147 return controller_->IsRevealed(); |
| 158 } | 148 } |
| 159 | 149 |
| 160 int ImmersiveModeControllerAsh::GetTopContainerVerticalOffset( | 150 int ImmersiveModeControllerAsh::GetTopContainerVerticalOffset( |
| 161 const gfx::Size& top_container_size) const { | 151 const gfx::Size& top_container_size) const { |
| 162 if (!IsEnabled()) | 152 if (!IsEnabled()) |
| 163 return 0; | 153 return 0; |
| 164 | 154 |
| 165 // The TopContainerView is flush with the top of |browser_view_| when the | 155 return static_cast<int>(top_container_size.height() * |
| 166 // top-of-window views are fully closed so that when the tab indicators are | 156 (visible_fraction_ - 1)); |
| 167 // used, the "light bar" style tab strip is flush with the top of | |
| 168 // |browser_view_|. | |
| 169 if (!IsRevealed()) | |
| 170 return 0; | |
| 171 | |
| 172 int height = top_container_size.height() - kAnimationOffsetY; | |
| 173 return static_cast<int>(height * (visible_fraction_ - 1)); | |
| 174 } | 157 } |
| 175 | 158 |
| 176 ImmersiveRevealedLock* ImmersiveModeControllerAsh::GetRevealedLock( | 159 ImmersiveRevealedLock* ImmersiveModeControllerAsh::GetRevealedLock( |
| 177 AnimateReveal animate_reveal) { | 160 AnimateReveal animate_reveal) { |
| 178 return new ImmersiveRevealedLockAsh(controller_->GetRevealedLock( | 161 return new ImmersiveRevealedLockAsh(controller_->GetRevealedLock( |
| 179 ToImmersiveFullscreenControllerAnimateReveal(animate_reveal))); | 162 ToImmersiveFullscreenControllerAnimateReveal(animate_reveal))); |
| 180 } | 163 } |
| 181 | 164 |
| 182 void ImmersiveModeControllerAsh::OnFindBarVisibleBoundsChanged( | 165 void ImmersiveModeControllerAsh::OnFindBarVisibleBoundsChanged( |
| 183 const gfx::Rect& new_visible_bounds_in_screen) { | 166 const gfx::Rect& new_visible_bounds_in_screen) { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 | 206 |
| 224 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { | 207 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { |
| 225 views::Widget* widget = browser_view_->frame(); | 208 views::Widget* widget = browser_view_->frame(); |
| 226 // Update the window caption buttons. | 209 // Update the window caption buttons. |
| 227 widget->non_client_view()->frame_view()->ResetWindowControls(); | 210 widget->non_client_view()->frame_view()->ResetWindowControls(); |
| 228 widget->non_client_view()->frame_view()->InvalidateLayout(); | 211 widget->non_client_view()->frame_view()->InvalidateLayout(); |
| 229 browser_view_->InvalidateLayout(); | 212 browser_view_->InvalidateLayout(); |
| 230 widget->GetRootView()->Layout(); | 213 widget->GetRootView()->Layout(); |
| 231 } | 214 } |
| 232 | 215 |
| 233 // TODO(yiyix|tdanderson): Once Chrome OS material design is enabled by default, | |
| 234 // remove all code related to immersive mode hints (here, in TabStrip and | |
| 235 // BrowserNonClientFrameViewAsh::OnPaint()). See crbug.com/614453. | |
| 236 bool ImmersiveModeControllerAsh::UpdateTabIndicators() { | |
| 237 if (ash::MaterialDesignController::IsImmersiveModeMaterial()) | |
| 238 return false; | |
| 239 | |
| 240 bool has_tabstrip = browser_view_->IsBrowserTypeNormal(); | |
| 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 } | |
| 258 | |
| 259 void ImmersiveModeControllerAsh::CreateMashRevealWidget() { | 216 void ImmersiveModeControllerAsh::CreateMashRevealWidget() { |
| 260 if (!chrome::IsRunningInMash()) | 217 if (!chrome::IsRunningInMash()) |
| 261 return; | 218 return; |
| 262 | 219 |
| 263 DCHECK(!mash_reveal_widget_); | 220 DCHECK(!mash_reveal_widget_); |
| 264 mash_reveal_widget_ = base::MakeUnique<views::Widget>(); | 221 mash_reveal_widget_ = base::MakeUnique<views::Widget>(); |
| 265 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_POPUP); | 222 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_POPUP); |
| 266 init_params.mus_properties | 223 init_params.mus_properties |
| 267 [ui::mojom::WindowManager::kRenderParentTitleArea_Property] = | 224 [ui::mojom::WindowManager::kRenderParentTitleArea_Property] = |
| 268 mojo::ConvertTo<std::vector<uint8_t>>( | 225 mojo::ConvertTo<std::vector<uint8_t>>( |
| (...skipping 29 matching lines...) Expand all Loading... |
| 298 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { | 255 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { |
| 299 DestroyMashRevealWidget(); | 256 DestroyMashRevealWidget(); |
| 300 | 257 |
| 301 visible_fraction_ = 0; | 258 visible_fraction_ = 0; |
| 302 browser_view_->top_container()->SetPaintToLayer(); | 259 browser_view_->top_container()->SetPaintToLayer(); |
| 303 // In mash the window manager (ash) also renders to the non-client area. In | 260 // In mash the window manager (ash) also renders to the non-client area. In |
| 304 // order to see the decorations drawn by ash the layer needs to be marked as | 261 // order to see the decorations drawn by ash the layer needs to be marked as |
| 305 // not filling bounds opaquely. | 262 // not filling bounds opaquely. |
| 306 if (chrome::IsRunningInMash()) | 263 if (chrome::IsRunningInMash()) |
| 307 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); | 264 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); |
| 308 UpdateTabIndicators(); | |
| 309 LayoutBrowserRootView(); | 265 LayoutBrowserRootView(); |
| 310 CreateMashRevealWidget(); | 266 CreateMashRevealWidget(); |
| 311 for (Observer& observer : observers_) | 267 for (Observer& observer : observers_) |
| 312 observer.OnImmersiveRevealStarted(); | 268 observer.OnImmersiveRevealStarted(); |
| 313 } | 269 } |
| 314 | 270 |
| 315 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { | 271 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { |
| 316 DestroyMashRevealWidget(); | 272 DestroyMashRevealWidget(); |
| 317 visible_fraction_ = 0; | 273 visible_fraction_ = 0; |
| 318 browser_view_->top_container()->DestroyLayer(); | 274 browser_view_->top_container()->DestroyLayer(); |
| 319 UpdateTabIndicators(); | |
| 320 LayoutBrowserRootView(); | 275 LayoutBrowserRootView(); |
| 321 for (Observer& observer : observers_) | 276 for (Observer& observer : observers_) |
| 322 observer.OnImmersiveRevealEnded(); | 277 observer.OnImmersiveRevealEnded(); |
| 323 } | 278 } |
| 324 | 279 |
| 325 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { | 280 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { |
| 326 DestroyMashRevealWidget(); | 281 DestroyMashRevealWidget(); |
| 327 browser_view_->top_container()->DestroyLayer(); | 282 browser_view_->top_container()->DestroyLayer(); |
| 328 UpdateTabIndicators(); | |
| 329 LayoutBrowserRootView(); | 283 LayoutBrowserRootView(); |
| 330 } | 284 } |
| 331 | 285 |
| 332 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { | 286 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { |
| 333 if (visible_fraction_ == visible_fraction) | 287 if (visible_fraction_ == visible_fraction) |
| 334 return; | 288 return; |
| 335 | 289 |
| 336 visible_fraction_ = visible_fraction; | 290 visible_fraction_ = visible_fraction; |
| 337 browser_view_->Layout(); | 291 browser_view_->Layout(); |
| 338 browser_view_->frame()->GetFrameView()->UpdateClientArea(); | 292 browser_view_->frame()->GetFrameView()->UpdateClientArea(); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 337 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
| 384 if (!controller_->IsEnabled()) | 338 if (!controller_->IsEnabled()) |
| 385 return; | 339 return; |
| 386 | 340 |
| 387 if (chrome::IsRunningInMash()) { | 341 if (chrome::IsRunningInMash()) { |
| 388 // TODO: http://crbug.com/640384. | 342 // TODO: http://crbug.com/640384. |
| 389 NOTIMPLEMENTED(); | 343 NOTIMPLEMENTED(); |
| 390 return; | 344 return; |
| 391 } | 345 } |
| 392 | 346 |
| 393 bool tab_indicator_visibility_changed = UpdateTabIndicators(); | 347 // Auto hide the shelf in immersive browser fullscreen. |
| 394 | |
| 395 // Auto hide the shelf in immersive browser fullscreen. When auto hidden and | |
| 396 // Material Design is not enabled, the shelf displays a 3px 'light bar' when | |
| 397 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide | |
| 398 // the shelf completely and prevent it from being revealed. | |
| 399 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> | 348 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> |
| 400 IsWindowFullscreenForTabOrPending(); | 349 IsWindowFullscreenForTabOrPending(); |
| 401 ash::wm::GetWindowState(native_window_) | 350 ash::wm::GetWindowState(native_window_) |
| 402 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); | 351 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); |
| 403 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 352 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
| 404 | |
| 405 if (tab_indicator_visibility_changed) | |
| 406 LayoutBrowserRootView(); | |
| 407 } | 353 } |
| 408 | 354 |
| 409 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, | 355 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, |
| 410 const void* key, | 356 const void* key, |
| 411 intptr_t old) { | 357 intptr_t old) { |
| 412 // In mash the window manager may move us out of immersive mode by changing | 358 // In mash the window manager may move us out of immersive mode by changing |
| 413 // the show state. When this happens notify the controller. | 359 // the show state. When this happens notify the controller. |
| 414 DCHECK(chrome::IsRunningInMash()); | 360 DCHECK(chrome::IsRunningInMash()); |
| 415 if (key == aura::client::kShowStateKey && | 361 if (key == aura::client::kShowStateKey && |
| 416 !browser_view_->GetWidget()->IsFullscreen()) { | 362 !browser_view_->GetWidget()->IsFullscreen()) { |
| 417 SetEnabled(false); | 363 SetEnabled(false); |
| 418 } | 364 } |
| 419 } | 365 } |
| OLD | NEW |