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)); |
Qiang(Joe) Xu
2017/02/15 23:24:14
I feel it can be just cleaned as this.
| |
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
302 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { | 259 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { |
303 DestroyMashRevealWidget(); | 260 DestroyMashRevealWidget(); |
304 | 261 |
305 visible_fraction_ = 0; | 262 visible_fraction_ = 0; |
306 browser_view_->top_container()->SetPaintToLayer(); | 263 browser_view_->top_container()->SetPaintToLayer(); |
307 // In mash the window manager (ash) also renders to the non-client area. In | 264 // 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 | 265 // order to see the decorations drawn by ash the layer needs to be marked as |
309 // not filling bounds opaquely. | 266 // not filling bounds opaquely. |
310 if (chrome::IsRunningInMash()) | 267 if (chrome::IsRunningInMash()) |
311 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); | 268 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); |
312 UpdateTabIndicators(); | |
313 LayoutBrowserRootView(); | 269 LayoutBrowserRootView(); |
314 CreateMashRevealWidget(); | 270 CreateMashRevealWidget(); |
315 for (Observer& observer : observers_) | 271 for (Observer& observer : observers_) |
316 observer.OnImmersiveRevealStarted(); | 272 observer.OnImmersiveRevealStarted(); |
317 } | 273 } |
318 | 274 |
319 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { | 275 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { |
320 DestroyMashRevealWidget(); | 276 DestroyMashRevealWidget(); |
321 visible_fraction_ = 0; | 277 visible_fraction_ = 0; |
322 browser_view_->top_container()->DestroyLayer(); | 278 browser_view_->top_container()->DestroyLayer(); |
323 UpdateTabIndicators(); | |
324 LayoutBrowserRootView(); | 279 LayoutBrowserRootView(); |
325 for (Observer& observer : observers_) | 280 for (Observer& observer : observers_) |
326 observer.OnImmersiveRevealEnded(); | 281 observer.OnImmersiveRevealEnded(); |
327 } | 282 } |
328 | 283 |
329 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { | 284 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { |
330 DestroyMashRevealWidget(); | 285 DestroyMashRevealWidget(); |
331 browser_view_->top_container()->DestroyLayer(); | 286 browser_view_->top_container()->DestroyLayer(); |
332 UpdateTabIndicators(); | |
333 LayoutBrowserRootView(); | 287 LayoutBrowserRootView(); |
334 } | 288 } |
335 | 289 |
336 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { | 290 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { |
337 if (visible_fraction_ == visible_fraction) | 291 if (visible_fraction_ == visible_fraction) |
338 return; | 292 return; |
339 | 293 |
340 visible_fraction_ = visible_fraction; | 294 visible_fraction_ = visible_fraction; |
341 browser_view_->Layout(); | 295 browser_view_->Layout(); |
342 browser_view_->frame()->GetFrameView()->UpdateClientArea(); | 296 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); | 341 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
388 if (!controller_->IsEnabled()) | 342 if (!controller_->IsEnabled()) |
389 return; | 343 return; |
390 | 344 |
391 if (chrome::IsRunningInMash()) { | 345 if (chrome::IsRunningInMash()) { |
392 // TODO: http://crbug.com/640384. | 346 // TODO: http://crbug.com/640384. |
393 NOTIMPLEMENTED(); | 347 NOTIMPLEMENTED(); |
394 return; | 348 return; |
395 } | 349 } |
396 | 350 |
397 bool tab_indicator_visibility_changed = UpdateTabIndicators(); | 351 // Auto hide the shelf in immersive browser fullscreen. |
398 | |
399 // 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 | |
401 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide | |
402 // the shelf completely and prevent it from being revealed. | |
403 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> | 352 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> |
404 IsWindowFullscreenForTabOrPending(); | 353 IsWindowFullscreenForTabOrPending(); |
405 ash::wm::GetWindowState(native_window_) | 354 ash::wm::GetWindowState(native_window_) |
406 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); | 355 ->set_hide_shelf_when_fullscreen(in_tab_fullscreen); |
407 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 356 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
408 | |
409 if (tab_indicator_visibility_changed) | |
410 LayoutBrowserRootView(); | |
411 } | 357 } |
412 | 358 |
413 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, | 359 void ImmersiveModeControllerAsh::OnWindowPropertyChanged(aura::Window* window, |
414 const void* key, | 360 const void* key, |
415 intptr_t old) { | 361 intptr_t old) { |
416 // In mash the window manager may move us out of immersive mode by changing | 362 // In mash the window manager may move us out of immersive mode by changing |
417 // the show state. When this happens notify the controller. | 363 // the show state. When this happens notify the controller. |
418 DCHECK(chrome::IsRunningInMash()); | 364 DCHECK(chrome::IsRunningInMash()); |
419 if (key == aura::client::kShowStateKey && | 365 if (key == aura::client::kShowStateKey && |
420 !browser_view_->GetWidget()->IsFullscreen()) { | 366 !browser_view_->GetWidget()->IsFullscreen()) { |
421 SetEnabled(false); | 367 SetEnabled(false); |
422 } | 368 } |
423 } | 369 } |
OLD | NEW |