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

Side by Side Diff: ash/shelf/shelf_widget.cc

Issue 448493002: Avoiding double resize of maximized windows upon user switch due to showing and hiding of the shelf (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 4 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 | « ash/shelf/shelf_widget.h ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller.h » ('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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "ash/shelf/shelf_widget.h" 5 #include "ash/shelf/shelf_widget.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/focus_cycler.h" 8 #include "ash/focus_cycler.h"
9 #include "ash/root_window_controller.h" 9 #include "ash/root_window_controller.h"
10 #include "ash/session/session_state_delegate.h" 10 #include "ash/session/session_state_delegate.h"
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 public: 318 public:
319 explicit DelegateView(ShelfWidget* shelf); 319 explicit DelegateView(ShelfWidget* shelf);
320 virtual ~DelegateView(); 320 virtual ~DelegateView();
321 321
322 void set_focus_cycler(FocusCycler* focus_cycler) { 322 void set_focus_cycler(FocusCycler* focus_cycler) {
323 focus_cycler_ = focus_cycler; 323 focus_cycler_ = focus_cycler;
324 } 324 }
325 FocusCycler* focus_cycler() { return focus_cycler_; } 325 FocusCycler* focus_cycler() { return focus_cycler_; }
326 326
327 ui::Layer* opaque_background() { return &opaque_background_; } 327 ui::Layer* opaque_background() { return &opaque_background_; }
328 ui::Layer* opaque_foreground() { return &opaque_foreground_; }
328 329
329 // Set if the shelf area is dimmed (eg when a window is maximized). 330 // Set if the shelf area is dimmed (eg when a window is maximized).
330 void SetDimmed(bool dimmed); 331 void SetDimmed(bool dimmed);
331 bool GetDimmed() const; 332 bool GetDimmed() const;
332 333
333 void SetParentLayer(ui::Layer* layer); 334 void SetParentLayer(ui::Layer* layer);
334 335
335 // views::View overrides: 336 // views::View overrides:
336 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE; 337 virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
337 338
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 // prior to the creation of of the |dimmer_|. 377 // prior to the creation of of the |dimmer_|.
377 void disable_dimming_animations_for_test() { 378 void disable_dimming_animations_for_test() {
378 disable_dimming_animations_for_test_ = true; 379 disable_dimming_animations_for_test_ = true;
379 } 380 }
380 381
381 private: 382 private:
382 ShelfWidget* shelf_; 383 ShelfWidget* shelf_;
383 scoped_ptr<views::Widget> dimmer_; 384 scoped_ptr<views::Widget> dimmer_;
384 FocusCycler* focus_cycler_; 385 FocusCycler* focus_cycler_;
385 int alpha_; 386 int alpha_;
387 // A black background layer which is shown when a maximized window is visible.
386 ui::Layer opaque_background_; 388 ui::Layer opaque_background_;
389 // A black foreground layer which is shown while transitioning between users.
390 // Note: Since the back- and foreground layers have different functions they
391 // can be used simultaneously - so no repurposing possible.
392 ui::Layer opaque_foreground_;
387 393
388 // The view which does the dimming. 394 // The view which does the dimming.
389 DimmerView* dimmer_view_; 395 DimmerView* dimmer_view_;
390 396
391 // True if dimming animations should be turned off. 397 // True if dimming animations should be turned off.
392 bool disable_dimming_animations_for_test_; 398 bool disable_dimming_animations_for_test_;
393 399
394 DISALLOW_COPY_AND_ASSIGN(DelegateView); 400 DISALLOW_COPY_AND_ASSIGN(DelegateView);
395 }; 401 };
396 402
397 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf) 403 ShelfWidget::DelegateView::DelegateView(ShelfWidget* shelf)
398 : shelf_(shelf), 404 : shelf_(shelf),
399 focus_cycler_(NULL), 405 focus_cycler_(NULL),
400 alpha_(0), 406 alpha_(0),
401 opaque_background_(ui::LAYER_SOLID_COLOR), 407 opaque_background_(ui::LAYER_SOLID_COLOR),
408 opaque_foreground_(ui::LAYER_SOLID_COLOR),
402 dimmer_view_(NULL), 409 dimmer_view_(NULL),
403 disable_dimming_animations_for_test_(false) { 410 disable_dimming_animations_for_test_(false) {
404 set_allow_deactivate_on_esc(true); 411 set_allow_deactivate_on_esc(true);
405 opaque_background_.SetColor(SK_ColorBLACK); 412 opaque_background_.SetColor(SK_ColorBLACK);
406 opaque_background_.SetBounds(GetLocalBounds()); 413 opaque_background_.SetBounds(GetLocalBounds());
407 opaque_background_.SetOpacity(0.0f); 414 opaque_background_.SetOpacity(0.0f);
415 opaque_foreground_.SetColor(SK_ColorBLACK);
416 opaque_foreground_.SetBounds(GetLocalBounds());
417 opaque_foreground_.SetOpacity(0.0f);
408 } 418 }
409 419
410 ShelfWidget::DelegateView::~DelegateView() { 420 ShelfWidget::DelegateView::~DelegateView() {
411 // Make sure that the dimmer goes away since it might have set an observer. 421 // Make sure that the dimmer goes away since it might have set an observer.
412 SetDimmed(false); 422 SetDimmed(false);
413 } 423 }
414 424
415 void ShelfWidget::DelegateView::SetDimmed(bool value) { 425 void ShelfWidget::DelegateView::SetDimmed(bool value) {
416 if (value == (dimmer_.get() != NULL)) 426 if (value == (dimmer_.get() != NULL))
417 return; 427 return;
(...skipping 25 matching lines...) Expand all
443 dimmer_.reset(NULL); 453 dimmer_.reset(NULL);
444 } 454 }
445 } 455 }
446 456
447 bool ShelfWidget::DelegateView::GetDimmed() const { 457 bool ShelfWidget::DelegateView::GetDimmed() const {
448 return dimmer_.get() && dimmer_->IsVisible(); 458 return dimmer_.get() && dimmer_->IsVisible();
449 } 459 }
450 460
451 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) { 461 void ShelfWidget::DelegateView::SetParentLayer(ui::Layer* layer) {
452 layer->Add(&opaque_background_); 462 layer->Add(&opaque_background_);
463 layer->Add(&opaque_foreground_);
453 ReorderLayers(); 464 ReorderLayers();
454 } 465 }
455 466
456 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { 467 void ShelfWidget::DelegateView::OnPaintBackground(gfx::Canvas* canvas) {
457 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 468 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
458 gfx::ImageSkia shelf_background = 469 gfx::ImageSkia shelf_background =
459 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); 470 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
460 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment()) 471 if (SHELF_ALIGNMENT_BOTTOM != shelf_->GetAlignment())
461 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage( 472 shelf_background = gfx::ImageSkiaOperations::CreateRotatedImage(
462 shelf_background, 473 shelf_background,
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
549 } else { 560 } else {
550 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(), 561 child_at(i)->SetBounds(child_at(i)->x(), child_at(i)->y(),
551 width(), child_at(i)->height()); 562 width(), child_at(i)->height());
552 } 563 }
553 } 564 }
554 } 565 }
555 566
556 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) { 567 void ShelfWidget::DelegateView::ReorderChildLayers(ui::Layer* parent_layer) {
557 views::View::ReorderChildLayers(parent_layer); 568 views::View::ReorderChildLayers(parent_layer);
558 parent_layer->StackAtBottom(&opaque_background_); 569 parent_layer->StackAtBottom(&opaque_background_);
570 parent_layer->StackAtTop(&opaque_foreground_);
559 } 571 }
560 572
561 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) { 573 void ShelfWidget::DelegateView::OnBoundsChanged(const gfx::Rect& old_bounds) {
562 opaque_background_.SetBounds(GetLocalBounds()); 574 opaque_background_.SetBounds(GetLocalBounds());
575 opaque_foreground_.SetBounds(GetLocalBounds());
563 if (dimmer_) 576 if (dimmer_)
564 dimmer_->SetBounds(GetBoundsInScreen()); 577 dimmer_->SetBounds(GetBoundsInScreen());
565 } 578 }
566 579
567 void ShelfWidget::DelegateView::OnWindowBoundsChanged( 580 void ShelfWidget::DelegateView::OnWindowBoundsChanged(
568 aura::Window* window, 581 aura::Window* window,
569 const gfx::Rect& old_bounds, 582 const gfx::Rect& old_bounds,
570 const gfx::Rect& new_bounds) { 583 const gfx::Rect& new_bounds) {
571 // Coming here the shelf got repositioned and since the |dimmer_| is placed 584 // Coming here the shelf got repositioned and since the |dimmer_| is placed
572 // in screen coordinates and not relative to the parent it needs to be 585 // in screen coordinates and not relative to the parent it needs to be
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
671 684
672 ShelfBackgroundType ShelfWidget::GetBackgroundType() const { 685 ShelfBackgroundType ShelfWidget::GetBackgroundType() const {
673 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f) 686 if (delegate_view_->opaque_background()->GetTargetOpacity() == 1.0f)
674 return SHELF_BACKGROUND_MAXIMIZED; 687 return SHELF_BACKGROUND_MAXIMIZED;
675 if (background_animator_.paints_background()) 688 if (background_animator_.paints_background())
676 return SHELF_BACKGROUND_OVERLAP; 689 return SHELF_BACKGROUND_OVERLAP;
677 690
678 return SHELF_BACKGROUND_DEFAULT; 691 return SHELF_BACKGROUND_DEFAULT;
679 } 692 }
680 693
694 void ShelfWidget::HideShelfBehindBlackBar(bool hide, int animation_time_ms) {
695 if (IsShelfHiddenBehindBlackBar() == hide)
696 return;
697
698 ui::Layer* opaque_foreground = delegate_view_->opaque_foreground();
699 float target_opacity = hide ? 1.0f : 0.0f;
700 scoped_ptr<ui::ScopedLayerAnimationSettings> opaque_foreground_animation;
701 opaque_foreground_animation.reset(new ui::ScopedLayerAnimationSettings(
702 opaque_foreground->GetAnimator()));
703 opaque_foreground_animation->SetTransitionDuration(
704 base::TimeDelta::FromMilliseconds(animation_time_ms));
705 opaque_foreground_animation->SetPreemptionStrategy(
706 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
707
708 opaque_foreground->SetOpacity(target_opacity);
709 }
710
711 bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
712 return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
713 }
714
681 // static 715 // static
682 bool ShelfWidget::ShelfAlignmentAllowed() { 716 bool ShelfWidget::ShelfAlignmentAllowed() {
683 user::LoginStatus login_status = 717 user::LoginStatus login_status =
684 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus(); 718 Shell::GetInstance()->system_tray_delegate()->GetUserLoginStatus();
685 719
686 switch (login_status) { 720 switch (login_status) {
687 case user::LOGGED_IN_USER: 721 case user::LOGGED_IN_USER:
688 case user::LOGGED_IN_OWNER: 722 case user::LOGGED_IN_OWNER:
689 return true; 723 return true;
690 case user::LOGGED_IN_LOCKED: 724 case user::LOGGED_IN_LOCKED:
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
802 DCHECK(delegate_view_); 836 DCHECK(delegate_view_);
803 return delegate_view_->disable_dimming_animations_for_test(); 837 return delegate_view_->disable_dimming_animations_for_test();
804 } 838 }
805 839
806 void ShelfWidget::WillDeleteShelf() { 840 void ShelfWidget::WillDeleteShelf() {
807 shelf_layout_manager_->RemoveObserver(this); 841 shelf_layout_manager_->RemoveObserver(this);
808 shelf_layout_manager_ = NULL; 842 shelf_layout_manager_ = NULL;
809 } 843 }
810 844
811 } // namespace ash 845 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_widget.h ('k') | chrome/browser/ui/ash/launcher/chrome_launcher_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698