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" |
11 #include "ash/wm/window_state_aura.h" | 11 #include "ash/wm/window_state_aura.h" |
12 #include "base/macros.h" | 12 #include "base/macros.h" |
13 #include "chrome/browser/chrome_notification_types.h" | 13 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/ui/ash/ash_util.h" |
14 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" | 15 #include "chrome/browser/ui/exclusive_access/exclusive_access_manager.h" |
15 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" | 16 #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" |
16 #include "chrome/browser/ui/views/frame/browser_view.h" | 17 #include "chrome/browser/ui/views/frame/browser_view.h" |
17 #include "chrome/browser/ui/views/frame/top_container_view.h" | 18 #include "chrome/browser/ui/views/frame/top_container_view.h" |
18 #include "chrome/browser/ui/views/tabs/tab_strip.h" | 19 #include "chrome/browser/ui/views/tabs/tab_strip.h" |
19 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
20 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
| 22 #include "services/ui/public/cpp/property_type_converters.h" |
| 23 #include "services/ui/public/cpp/window_tree_client.h" |
| 24 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 25 #include "ui/aura/mus/mus_util.h" |
21 #include "ui/aura/window.h" | 26 #include "ui/aura/window.h" |
| 27 #include "ui/compositor/paint_context.h" |
| 28 #include "ui/compositor/paint_recorder.h" |
| 29 #include "ui/views/mus/native_widget_mus.h" |
| 30 #include "ui/views/mus/window_manager_connection.h" |
22 #include "ui/views/view.h" | 31 #include "ui/views/view.h" |
23 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
24 #include "ui/views/window/non_client_view.h" | 33 #include "ui/views/window/non_client_view.h" |
25 | 34 |
26 namespace { | 35 namespace { |
27 | 36 |
28 // Revealing the TopContainerView looks better if the animation starts and ends | 37 // Revealing the TopContainerView looks better if the animation starts and ends |
29 // just a few pixels before the view goes offscreen, which reduces the visual | 38 // just a few pixels before the view goes offscreen, which reduces the visual |
30 // "pop" as the 3-pixel tall "light bar" style tab strip becomes visible. | 39 // "pop" as the 3-pixel tall "light bar" style tab strip becomes visible. |
31 const int kAnimationOffsetY = 3; | 40 const int kAnimationOffsetY = 3; |
(...skipping 17 matching lines...) Expand all Loading... |
49 public: | 58 public: |
50 explicit ImmersiveRevealedLockAsh(ash::ImmersiveRevealedLock* lock) | 59 explicit ImmersiveRevealedLockAsh(ash::ImmersiveRevealedLock* lock) |
51 : lock_(lock) {} | 60 : lock_(lock) {} |
52 | 61 |
53 private: | 62 private: |
54 std::unique_ptr<ash::ImmersiveRevealedLock> lock_; | 63 std::unique_ptr<ash::ImmersiveRevealedLock> lock_; |
55 | 64 |
56 DISALLOW_COPY_AND_ASSIGN(ImmersiveRevealedLockAsh); | 65 DISALLOW_COPY_AND_ASSIGN(ImmersiveRevealedLockAsh); |
57 }; | 66 }; |
58 | 67 |
| 68 // TODO(sky): remove this, should instead create a layer that is clone of |
| 69 // existing layers. http://crbug.com/640378. |
| 70 class DelegatingPaintView : public views::View { |
| 71 public: |
| 72 explicit DelegatingPaintView(views::View* view) : view_(view) {} |
| 73 |
| 74 ~DelegatingPaintView() override {} |
| 75 |
| 76 // views::View: |
| 77 void PaintChildren(const ui::PaintContext& context) override { |
| 78 view_->Paint(ui::PaintContext( |
| 79 context, ui::PaintContext::CLONE_WITHOUT_INVALIDATION)); |
| 80 } |
| 81 |
| 82 private: |
| 83 views::View* view_; |
| 84 |
| 85 DISALLOW_COPY_AND_ASSIGN(DelegatingPaintView); |
| 86 }; |
| 87 |
59 } // namespace | 88 } // namespace |
60 | 89 |
61 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() | 90 ImmersiveModeControllerAsh::ImmersiveModeControllerAsh() |
62 : ImmersiveModeController(Type::ASH), | 91 : ImmersiveModeController(Type::ASH), |
63 controller_(new ash::ImmersiveFullscreenController), | 92 controller_(new ash::ImmersiveFullscreenController), |
64 browser_view_(nullptr), | 93 browser_view_(nullptr), |
65 native_window_(nullptr), | 94 native_window_(nullptr), |
66 observers_enabled_(false), | 95 observers_enabled_(false), |
67 use_tab_indicators_(false), | 96 use_tab_indicators_(false), |
68 visible_fraction_(1) {} | 97 visible_fraction_(1) {} |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 | 164 |
136 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { | 165 void ImmersiveModeControllerAsh::EnableWindowObservers(bool enable) { |
137 if (observers_enabled_ == enable) | 166 if (observers_enabled_ == enable) |
138 return; | 167 return; |
139 observers_enabled_ = enable; | 168 observers_enabled_ = enable; |
140 | 169 |
141 content::Source<FullscreenController> source(browser_view_->browser() | 170 content::Source<FullscreenController> source(browser_view_->browser() |
142 ->exclusive_access_manager() | 171 ->exclusive_access_manager() |
143 ->fullscreen_controller()); | 172 ->fullscreen_controller()); |
144 if (enable) { | 173 if (enable) { |
145 ash::wm::GetWindowState(native_window_)->AddObserver(this); | 174 if (chrome::IsRunningInMash()) { |
| 175 // TODO: http://crbug.com/640381. |
| 176 NOTIMPLEMENTED(); |
| 177 } else { |
| 178 ash::wm::GetWindowState(native_window_)->AddObserver(this); |
| 179 } |
146 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source); | 180 registrar_.Add(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source); |
147 } else { | 181 } else { |
148 ash::wm::GetWindowState(native_window_)->RemoveObserver(this); | 182 if (chrome::IsRunningInMash()) { |
| 183 // TODO: http://crbug.com/640381. |
| 184 NOTIMPLEMENTED(); |
| 185 } else { |
| 186 ash::wm::GetWindowState(native_window_)->RemoveObserver(this); |
| 187 } |
149 registrar_.Remove(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source); | 188 registrar_.Remove(this, chrome::NOTIFICATION_FULLSCREEN_CHANGED, source); |
150 } | 189 } |
151 } | 190 } |
152 | 191 |
153 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { | 192 void ImmersiveModeControllerAsh::LayoutBrowserRootView() { |
154 views::Widget* widget = browser_view_->frame(); | 193 views::Widget* widget = browser_view_->frame(); |
155 // Update the window caption buttons. | 194 // Update the window caption buttons. |
156 widget->non_client_view()->frame_view()->ResetWindowControls(); | 195 widget->non_client_view()->frame_view()->ResetWindowControls(); |
157 widget->non_client_view()->frame_view()->InvalidateLayout(); | 196 widget->non_client_view()->frame_view()->InvalidateLayout(); |
158 browser_view_->InvalidateLayout(); | 197 browser_view_->InvalidateLayout(); |
(...skipping 19 matching lines...) Expand all Loading... |
178 } | 217 } |
179 | 218 |
180 bool show_tab_indicators = use_tab_indicators_ && !IsRevealed(); | 219 bool show_tab_indicators = use_tab_indicators_ && !IsRevealed(); |
181 if (show_tab_indicators != browser_view_->tabstrip()->IsImmersiveStyle()) { | 220 if (show_tab_indicators != browser_view_->tabstrip()->IsImmersiveStyle()) { |
182 browser_view_->tabstrip()->SetImmersiveStyle(show_tab_indicators); | 221 browser_view_->tabstrip()->SetImmersiveStyle(show_tab_indicators); |
183 return true; | 222 return true; |
184 } | 223 } |
185 return false; | 224 return false; |
186 } | 225 } |
187 | 226 |
| 227 void ImmersiveModeControllerAsh::CreateMashRevealWidget() { |
| 228 if (!chrome::IsRunningInMash()) |
| 229 return; |
| 230 |
| 231 DCHECK(!mash_reveal_widget_); |
| 232 mash_reveal_widget_.reset(new views::Widget); |
| 233 views::Widget::InitParams init_params(views::Widget::InitParams::TYPE_POPUP); |
| 234 std::map<std::string, std::vector<uint8_t>> window_properties; |
| 235 window_properties |
| 236 [ui::mojom::WindowManager::kRendererParentTitleArea_Property] = |
| 237 mojo::ConvertTo<std::vector<uint8_t>>(true); |
| 238 window_properties[ui::mojom::WindowManager::kName_Property] = |
| 239 mojo::ConvertTo<std::vector<uint8_t>>( |
| 240 std::string("ChromeImmersiveRevealWindow")); |
| 241 init_params.native_widget = new views::NativeWidgetMus( |
| 242 mash_reveal_widget_.get(), |
| 243 views::WindowManagerConnection::Get()->client()->NewWindow( |
| 244 &window_properties), |
| 245 ui::mojom::SurfaceType::DEFAULT); |
| 246 init_params.accept_events = false; |
| 247 init_params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
| 248 init_params.activatable = views::Widget::InitParams::ACTIVATABLE_NO; |
| 249 init_params.parent_mus = GetMusWindow(native_window_); |
| 250 const gfx::Rect& top_container_bounds = |
| 251 browser_view_->top_container()->bounds(); |
| 252 init_params.bounds = |
| 253 gfx::Rect(0, -top_container_bounds.height(), top_container_bounds.width(), |
| 254 top_container_bounds.height()); |
| 255 mash_reveal_widget_->Init(init_params); |
| 256 mash_reveal_widget_->SetContentsView( |
| 257 new DelegatingPaintView(browser_view_->top_container())); |
| 258 mash_reveal_widget_->StackAtTop(); |
| 259 mash_reveal_widget_->Show(); |
| 260 } |
| 261 |
| 262 void ImmersiveModeControllerAsh::DestroyMashRevealWidget() { |
| 263 mash_reveal_widget_.reset(); |
| 264 } |
| 265 |
188 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { | 266 void ImmersiveModeControllerAsh::OnImmersiveRevealStarted() { |
| 267 DestroyMashRevealWidget(); |
| 268 |
189 visible_fraction_ = 0; | 269 visible_fraction_ = 0; |
190 browser_view_->top_container()->SetPaintToLayer(true); | 270 browser_view_->top_container()->SetPaintToLayer(true); |
191 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); | 271 browser_view_->top_container()->layer()->SetFillsBoundsOpaquely(false); |
192 UpdateTabIndicators(); | 272 UpdateTabIndicators(); |
193 LayoutBrowserRootView(); | 273 LayoutBrowserRootView(); |
| 274 CreateMashRevealWidget(); |
194 FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted()); | 275 FOR_EACH_OBSERVER(Observer, observers_, OnImmersiveRevealStarted()); |
195 } | 276 } |
196 | 277 |
197 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { | 278 void ImmersiveModeControllerAsh::OnImmersiveRevealEnded() { |
| 279 DestroyMashRevealWidget(); |
198 visible_fraction_ = 0; | 280 visible_fraction_ = 0; |
199 browser_view_->top_container()->SetPaintToLayer(false); | 281 browser_view_->top_container()->SetPaintToLayer(false); |
200 UpdateTabIndicators(); | 282 UpdateTabIndicators(); |
201 LayoutBrowserRootView(); | 283 LayoutBrowserRootView(); |
202 } | 284 } |
203 | 285 |
204 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { | 286 void ImmersiveModeControllerAsh::OnImmersiveFullscreenExited() { |
| 287 DestroyMashRevealWidget(); |
205 browser_view_->top_container()->SetPaintToLayer(false); | 288 browser_view_->top_container()->SetPaintToLayer(false); |
206 UpdateTabIndicators(); | 289 UpdateTabIndicators(); |
207 LayoutBrowserRootView(); | 290 LayoutBrowserRootView(); |
208 } | 291 } |
209 | 292 |
210 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { | 293 void ImmersiveModeControllerAsh::SetVisibleFraction(double visible_fraction) { |
211 if (visible_fraction_ != visible_fraction) { | 294 if (visible_fraction_ != visible_fraction) { |
212 visible_fraction_ = visible_fraction; | 295 visible_fraction_ = visible_fraction; |
213 browser_view_->Layout(); | 296 browser_view_->Layout(); |
| 297 |
| 298 if (mash_reveal_widget_) { |
| 299 gfx::Rect bounds = mash_reveal_widget_->GetNativeWindow()->bounds(); |
| 300 bounds.set_y(visible_fraction * bounds.height() - bounds.height()); |
| 301 mash_reveal_widget_->SetBounds(bounds); |
| 302 } |
214 } | 303 } |
215 } | 304 } |
216 | 305 |
217 std::vector<gfx::Rect> | 306 std::vector<gfx::Rect> |
218 ImmersiveModeControllerAsh::GetVisibleBoundsInScreen() const { | 307 ImmersiveModeControllerAsh::GetVisibleBoundsInScreen() const { |
219 views::View* top_container_view = browser_view_->top_container(); | 308 views::View* top_container_view = browser_view_->top_container(); |
220 gfx::Rect top_container_view_bounds = top_container_view->GetVisibleBounds(); | 309 gfx::Rect top_container_view_bounds = top_container_view->GetVisibleBounds(); |
221 // TODO(tdanderson): Implement View::ConvertRectToScreen(). | 310 // TODO(tdanderson): Implement View::ConvertRectToScreen(). |
222 gfx::Point top_container_view_bounds_in_screen_origin( | 311 gfx::Point top_container_view_bounds_in_screen_origin( |
223 top_container_view_bounds.origin()); | 312 top_container_view_bounds.origin()); |
(...skipping 23 matching lines...) Expand all Loading... |
247 } | 336 } |
248 | 337 |
249 void ImmersiveModeControllerAsh::Observe( | 338 void ImmersiveModeControllerAsh::Observe( |
250 int type, | 339 int type, |
251 const content::NotificationSource& source, | 340 const content::NotificationSource& source, |
252 const content::NotificationDetails& details) { | 341 const content::NotificationDetails& details) { |
253 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); | 342 DCHECK_EQ(chrome::NOTIFICATION_FULLSCREEN_CHANGED, type); |
254 if (!controller_->IsEnabled()) | 343 if (!controller_->IsEnabled()) |
255 return; | 344 return; |
256 | 345 |
| 346 if (chrome::IsRunningInMash()) { |
| 347 // TODO: http://crbug.com/640384. |
| 348 NOTIMPLEMENTED(); |
| 349 return; |
| 350 } |
| 351 |
257 bool tab_indicator_visibility_changed = UpdateTabIndicators(); | 352 bool tab_indicator_visibility_changed = UpdateTabIndicators(); |
258 | 353 |
259 // Auto hide the shelf in immersive browser fullscreen. When auto hidden and | 354 // Auto hide the shelf in immersive browser fullscreen. When auto hidden and |
260 // Material Design is not enabled, the shelf displays a 3px 'light bar' when | 355 // Material Design is not enabled, the shelf displays a 3px 'light bar' when |
261 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide | 356 // it is closed. When in immersive browser fullscreen and tab fullscreen, hide |
262 // the shelf completely and prevent it from being revealed. | 357 // the shelf completely and prevent it from being revealed. |
263 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> | 358 bool in_tab_fullscreen = content::Source<FullscreenController>(source)-> |
264 IsWindowFullscreenForTabOrPending(); | 359 IsWindowFullscreenForTabOrPending(); |
265 ash::wm::GetWindowState(native_window_) | 360 ash::wm::GetWindowState(native_window_) |
266 ->set_shelf_mode_in_fullscreen( | 361 ->set_shelf_mode_in_fullscreen( |
267 in_tab_fullscreen ? ash::wm::WindowState::SHELF_HIDDEN | 362 in_tab_fullscreen ? ash::wm::WindowState::SHELF_HIDDEN |
268 : ash::wm::WindowState::SHELF_AUTO_HIDE_VISIBLE); | 363 : ash::wm::WindowState::SHELF_AUTO_HIDE_VISIBLE); |
269 ash::Shell::GetInstance()->UpdateShelfVisibility(); | 364 ash::Shell::GetInstance()->UpdateShelfVisibility(); |
270 | 365 |
271 if (tab_indicator_visibility_changed) | 366 if (tab_indicator_visibility_changed) |
272 LayoutBrowserRootView(); | 367 LayoutBrowserRootView(); |
273 } | 368 } |
OLD | NEW |