Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(35)

Side by Side Diff: chrome/browser/ui/views/frame/immersive_mode_controller_ash.cc

Issue 13942011: Fix bugs wrt to immrsive mode being disabled (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/immersive_mode_controller_ash_browsertest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/wm/window_properties.h" 9 #include "ash/wm/window_properties.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 // If the top-of-window views are revealed (or become revealed), |widget| will 115 // If the top-of-window views are revealed (or become revealed), |widget| will
116 // keep the top-of-window views revealed till |widget| is hidden or 116 // keep the top-of-window views revealed till |widget| is hidden or
117 // RemoveAnchoredWidget() is called. 117 // RemoveAnchoredWidget() is called.
118 void AddAnchoredWidget(views::Widget* widget, int y_offset); 118 void AddAnchoredWidget(views::Widget* widget, int y_offset);
119 119
120 // Stops managing |widget|'s y position. 120 // Stops managing |widget|'s y position.
121 // Closes the top-of-window views if no locks or other anchored widgets are 121 // Closes the top-of-window views if no locks or other anchored widgets are
122 // keeping the top-of-window views revealed. 122 // keeping the top-of-window views revealed.
123 void RemoveAnchoredWidget(views::Widget* widget); 123 void RemoveAnchoredWidget(views::Widget* widget);
124 124
125 // Adjusts the y positions of the anchored widgets for the new top container 125 // Repositions the anchored widgets for the current top container bounds if
126 // bounds. 126 // immersive mode is enabled.
127 void OnTopContainerBoundsChanged(); 127 void MaybeRepositionAnchoredWidgets();
128
129 // Called when immersive mode has been enabled.
130 void OnImmersiveModeEnabled();
128 131
129 const std::set<views::Widget*>& visible_anchored_widgets() const { 132 const std::set<views::Widget*>& visible_anchored_widgets() const {
130 return visible_; 133 return visible_;
131 } 134 }
132 135
133 private: 136 private:
134 // Updates |revealed_lock_| based on the visible anchored widgets. 137 // Updates |revealed_lock_| based on the visible anchored widgets.
135 void UpdateRevealedLock(); 138 void UpdateRevealedLock();
136 139
137 // Updates the y position of |widget| given |y_offset| and the top 140 // Updates the y position of |widget| given |y_offset| and the top
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 return; 199 return;
197 200
198 widget->RemoveObserver(this); 201 widget->RemoveObserver(this);
199 widgets_.erase(widget); 202 widgets_.erase(widget);
200 visible_.erase(widget); 203 visible_.erase(widget);
201 204
202 UpdateRevealedLock(); 205 UpdateRevealedLock();
203 } 206 }
204 207
205 void ImmersiveModeControllerAsh::AnchoredWidgetManager:: 208 void ImmersiveModeControllerAsh::AnchoredWidgetManager::
206 OnTopContainerBoundsChanged() { 209 MaybeRepositionAnchoredWidgets() {
207 for (std::map<views::Widget*, int>::iterator it = widgets_.begin(); 210 for (std::map<views::Widget*, int>::iterator it = widgets_.begin();
208 it != widgets_.end(); ++it) { 211 it != widgets_.end(); ++it) {
209 UpdateWidgetBounds(it->first, it->second); 212 UpdateWidgetBounds(it->first, it->second);
210 } 213 }
211 214
212 UpdateRevealedLock(); 215 UpdateRevealedLock();
213 } 216 }
214 217
218 void ImmersiveModeControllerAsh::AnchoredWidgetManager::
219 OnImmersiveModeEnabled() {
220 UpdateRevealedLock();
221 // The top container bounds may have changed while immersive mode was
222 // disabled.
223 MaybeRepositionAnchoredWidgets();
224 }
225
215 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateRevealedLock() { 226 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateRevealedLock() {
216 if (visible_.empty()) { 227 if (visible_.empty()) {
217 revealed_lock_.reset(); 228 revealed_lock_.reset();
218 } else if (controller_->IsRevealed()) { 229 } else if (controller_->IsRevealed()) {
219 // It is hard to determine the required initial transforms and the required 230 // It is hard to determine the required initial transforms and the required
220 // durations of the animations of |visible_| such that they appear to be 231 // durations of the animations of |visible_| such that they appear to be
221 // anchored to the top-of-window views while the top-of-window views are 232 // anchored to the top-of-window views while the top-of-window views are
222 // animating. Skip to the end of the reveal animation instead. 233 // animating. Skip to the end of the reveal animation instead.
223 // We do not query the controller's reveal state because we may be called 234 // We do not query the controller's reveal state because we may be called
224 // as a result of LayoutBrowserView() in MaybeStartReveal() when 235 // as a result of LayoutBrowserView() in MaybeStartReveal() when
225 // |reveal_state_| is SLIDING_OPEN but no animation is running yet. 236 // |reveal_state_| is SLIDING_OPEN but no animation is running yet.
226 ui::Layer* top_container_layer = 237 ui::Layer* top_container_layer =
227 controller_->browser_view_->top_container()->layer(); 238 controller_->browser_view_->top_container()->layer();
228 if (top_container_layer && 239 if (top_container_layer &&
229 top_container_layer->GetAnimator()->is_animating()) { 240 top_container_layer->GetAnimator()->is_animating()) {
230 controller_->MaybeRevealWithoutAnimation(); 241 controller_->MaybeRevealWithoutAnimation();
231 } 242 }
232 243
233 if (!revealed_lock_.get()) 244 if (!revealed_lock_.get())
234 revealed_lock_.reset(controller_->GetRevealedLock()); 245 revealed_lock_.reset(controller_->GetRevealedLock());
235 } 246 }
236 } 247 }
237 248
238 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateWidgetBounds( 249 void ImmersiveModeControllerAsh::AnchoredWidgetManager::UpdateWidgetBounds(
239 views::Widget* widget, 250 views::Widget* widget,
240 int y_offset) { 251 int y_offset) {
241 if (!widget->IsVisible()) 252 if (!controller_->IsEnabled() || !widget->IsVisible())
242 return; 253 return;
243 254
244 gfx::Rect top_container_target_bounds = 255 gfx::Rect top_container_target_bounds =
245 controller_->browser_view_->top_container()->GetTargetBoundsInScreen(); 256 controller_->browser_view_->top_container()->GetTargetBoundsInScreen();
246 gfx::Rect bounds(widget->GetWindowBoundsInScreen()); 257 gfx::Rect bounds(widget->GetWindowBoundsInScreen());
247 bounds.set_y( 258 bounds.set_y(
248 top_container_target_bounds.bottom() + y_offset); 259 top_container_target_bounds.bottom() + y_offset);
249 widget->SetBounds(bounds); 260 widget->SetBounds(bounds);
250 } 261 }
251 262
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
375 if (enabled_) { 386 if (enabled_) {
376 // Animate enabling immersive mode by sliding out the top-of-window views. 387 // Animate enabling immersive mode by sliding out the top-of-window views.
377 // No animation occurs if a lock is holding the top-of-window views open. 388 // No animation occurs if a lock is holding the top-of-window views open.
378 389
379 // Do a reveal to set the initial state for the animation. (And any 390 // Do a reveal to set the initial state for the animation. (And any
380 // required state in case the animation cannot run because of a lock holding 391 // required state in case the animation cannot run because of a lock holding
381 // the top-of-window views open.) 392 // the top-of-window views open.)
382 MaybeStartReveal(ANIMATE_NO); 393 MaybeStartReveal(ANIMATE_NO);
383 394
384 // Reset the mouse and the focus revealed locks so that they do not affect 395 // Reset the mouse and the focus revealed locks so that they do not affect
385 // whether the top-of-window views are hidden. Reacquire the locks if ending 396 // whether the top-of-window views are hidden.
386 // the reveal is unsuccessful.
387 bool had_mouse_revealed_lock = (mouse_revealed_lock_.get() != NULL);
388 bool had_focus_revealed_lock = (focus_revealed_lock_.get() != NULL);
389 mouse_revealed_lock_.reset(); 397 mouse_revealed_lock_.reset();
390 focus_revealed_lock_.reset(); 398 focus_revealed_lock_.reset();
391 399
392 // Try doing the animation. 400 // Try doing the animation.
393 MaybeEndReveal(ANIMATE_SLOW); 401 MaybeEndReveal(ANIMATE_SLOW);
394 402
395 if (IsRevealed()) { 403 if (reveal_state_ == REVEALED) {
396 if (had_mouse_revealed_lock) 404 // Reveal was unsuccessful. Reacquire the revealed locks if appropriate.
397 mouse_revealed_lock_.reset(GetRevealedLock()); 405 UpdateMouseRevealedLock(true);
398 if (had_focus_revealed_lock) 406 UpdateFocusRevealedLock();
399 focus_revealed_lock_.reset(GetRevealedLock());
400 } 407 }
408 anchored_widget_manager_->OnImmersiveModeEnabled();
401 } else { 409 } else {
402 // Stop cursor-at-top tracking. 410 // Stop cursor-at-top tracking.
403 top_timer_.Stop(); 411 top_timer_.Stop();
404 // Snap immediately to the closed state. 412 // Snap immediately to the closed state.
405 reveal_state_ = CLOSED; 413 reveal_state_ = CLOSED;
406 EnablePaintToLayer(false); 414 EnablePaintToLayer(false);
407 browser_view_->GetWidget()->non_client_view()->frame_view()-> 415 browser_view_->GetWidget()->non_client_view()->frame_view()->
408 ResetWindowControls(); 416 ResetWindowControls();
409 browser_view_->tabstrip()->SetImmersiveStyle(false); 417 browser_view_->tabstrip()->SetImmersiveStyle(false);
410 } 418 }
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 int y_offset) { 462 int y_offset) {
455 anchored_widget_manager_->AddAnchoredWidget(widget, y_offset); 463 anchored_widget_manager_->AddAnchoredWidget(widget, y_offset);
456 } 464 }
457 465
458 void ImmersiveModeControllerAsh::UnanchorWidgetFromTopContainer( 466 void ImmersiveModeControllerAsh::UnanchorWidgetFromTopContainer(
459 views::Widget* widget) { 467 views::Widget* widget) {
460 anchored_widget_manager_->RemoveAnchoredWidget(widget); 468 anchored_widget_manager_->RemoveAnchoredWidget(widget);
461 } 469 }
462 470
463 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() { 471 void ImmersiveModeControllerAsh::OnTopContainerBoundsChanged() {
464 anchored_widget_manager_->OnTopContainerBoundsChanged(); 472 anchored_widget_manager_->MaybeRepositionAnchoredWidgets();
465 } 473 }
466 474
467 //////////////////////////////////////////////////////////////////////////////// 475 ////////////////////////////////////////////////////////////////////////////////
468 // Observers: 476 // Observers:
469 477
470 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) { 478 void ImmersiveModeControllerAsh::OnMouseEvent(ui::MouseEvent* event) {
471 if (!enabled_) 479 if (!enabled_)
472 return; 480 return;
473 481
474 if (event->flags() & ui::EF_IS_SYNTHESIZED) 482 if (event->flags() & ui::EF_IS_SYNTHESIZED)
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator()); 846 ui::ScopedLayerAnimationSettings settings(layer->GetAnimator());
839 settings.SetTweenType(ui::Tween::EASE_OUT); 847 settings.SetTweenType(ui::Tween::EASE_OUT);
840 settings.SetTransitionDuration( 848 settings.SetTransitionDuration(
841 base::TimeDelta::FromMilliseconds(duration_ms)); 849 base::TimeDelta::FromMilliseconds(duration_ms));
842 settings.SetPreemptionStrategy( 850 settings.SetPreemptionStrategy(
843 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); 851 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
844 if (observer) 852 if (observer)
845 settings.AddObserver(observer); 853 settings.AddObserver(observer);
846 layer->SetTransform(target_transform); 854 layer->SetTransform(target_transform);
847 } 855 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/ui/views/frame/immersive_mode_controller_ash_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698