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

Side by Side Diff: ash/wm/panels/panel_layout_manager.cc

Issue 196723009: Not submitted - Fixing invalid visibility states with layers which showed up in unittests ... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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
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/wm/panels/panel_layout_manager.h" 5 #include "ash/wm/panels/panel_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 9
10 #include "ash/screen_util.h" 10 #include "ash/screen_util.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
50 const int kCalloutFadeDurationMilliseconds = 50; 50 const int kCalloutFadeDurationMilliseconds = 50;
51 51
52 // Offset used when sliding panel in/out of the shelf. Used for minimizing, 52 // Offset used when sliding panel in/out of the shelf. Used for minimizing,
53 // restoring and the initial showing of a panel. 53 // restoring and the initial showing of a panel.
54 const int kPanelSlideInOffset = 20; 54 const int kPanelSlideInOffset = 20;
55 55
56 // Callout arrow dimensions. 56 // Callout arrow dimensions.
57 const int kArrowWidth = 18; 57 const int kArrowWidth = 18;
58 const int kArrowHeight = 9; 58 const int kArrowHeight = 9;
59 59
60 // When a window layer gets hidden, and the window remains "logically visible",
61 // it is illegal to fade the layer to 0. We therefore use a fraction which is
62 // resolving to an alpha of 0 but tells a comparison otherwise.
63 const float kWindowLayerNotShown = 0.001f;
64
60 class CalloutWidgetBackground : public views::Background { 65 class CalloutWidgetBackground : public views::Background {
61 public: 66 public:
62 CalloutWidgetBackground() : alignment_(SHELF_ALIGNMENT_BOTTOM) { 67 CalloutWidgetBackground() : alignment_(SHELF_ALIGNMENT_BOTTOM) {
63 } 68 }
64 69
65 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { 70 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
66 SkPath path; 71 SkPath path;
67 switch (alignment_) { 72 switch (alignment_) {
68 case SHELF_ALIGNMENT_BOTTOM: 73 case SHELF_ALIGNMENT_BOTTOM:
69 path.moveTo(SkIntToScalar(0), SkIntToScalar(0)); 74 path.moveTo(SkIntToScalar(0), SkIntToScalar(0));
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 params.bounds.set_width(kArrowWidth); 241 params.bounds.set_width(kArrowWidth);
237 params.bounds.set_height(kArrowHeight); 242 params.bounds.set_height(kArrowHeight);
238 // Why do we need this and can_activate = false? 243 // Why do we need this and can_activate = false?
239 set_focus_on_creation(false); 244 set_focus_on_creation(false);
240 Init(params); 245 Init(params);
241 DCHECK_EQ(GetNativeView()->GetRootWindow(), parent->GetRootWindow()); 246 DCHECK_EQ(GetNativeView()->GetRootWindow(), parent->GetRootWindow());
242 views::View* content_view = new views::View; 247 views::View* content_view = new views::View;
243 background_ = new CalloutWidgetBackground; 248 background_ = new CalloutWidgetBackground;
244 content_view->set_background(background_); 249 content_view->set_background(background_);
245 SetContentsView(content_view); 250 SetContentsView(content_view);
246 GetNativeWindow()->layer()->SetOpacity(0); 251 GetNativeWindow()->layer()->SetOpacity(kWindowLayerNotShown);
247 } 252 }
248 253
249 // Weak pointer owned by this widget's content view. 254 // Weak pointer owned by this widget's content view.
250 CalloutWidgetBackground* background_; 255 CalloutWidgetBackground* background_;
251 256
252 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget); 257 DISALLOW_COPY_AND_ASSIGN(PanelCalloutWidget);
253 }; 258 };
254 259
255 //////////////////////////////////////////////////////////////////////////////// 260 ////////////////////////////////////////////////////////////////////////////////
256 // PanelLayoutManager public implementation: 261 // PanelLayoutManager public implementation:
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
359 wm::ReparentTransientChildrenOfChild(child, old_parent, child->parent()); 364 wm::ReparentTransientChildrenOfChild(child, old_parent, child->parent());
360 DCHECK(child->parent()->id() != kShellWindowId_PanelContainer); 365 DCHECK(child->parent()->id() != kShellWindowId_PanelContainer);
361 return; 366 return;
362 } 367 }
363 PanelInfo panel_info; 368 PanelInfo panel_info;
364 panel_info.window = child; 369 panel_info.window = child;
365 panel_info.callout_widget = new PanelCalloutWidget(panel_container_); 370 panel_info.callout_widget = new PanelCalloutWidget(panel_container_);
366 if (child != dragged_panel_) { 371 if (child != dragged_panel_) {
367 // Set the panel to 0 opacity until it has been positioned to prevent it 372 // Set the panel to 0 opacity until it has been positioned to prevent it
368 // from flashing briefly at position (0, 0). 373 // from flashing briefly at position (0, 0).
369 child->layer()->SetOpacity(0); 374 child->layer()->SetOpacity(kWindowLayerNotShown);
370 panel_info.slide_in = true; 375 panel_info.slide_in = true;
371 } 376 }
372 panel_windows_.push_back(panel_info); 377 panel_windows_.push_back(panel_info);
373 child->AddObserver(this); 378 child->AddObserver(this);
374 wm::GetWindowState(child)->AddObserver(this); 379 wm::GetWindowState(child)->AddObserver(this);
375 Relayout(); 380 Relayout();
376 } 381 }
377 382
378 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) { 383 void PanelLayoutManager::OnWillRemoveWindowFromLayout(aura::Window* child) {
379 } 384 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
554 panel_slide_settings.SetTransitionDuration( 559 panel_slide_settings.SetTransitionDuration(
555 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds)); 560 base::TimeDelta::FromMilliseconds(kPanelSlideDurationMilliseconds));
556 gfx::Rect bounds(panel->bounds()); 561 gfx::Rect bounds(panel->bounds());
557 bounds.Offset(GetSlideInAnimationOffset( 562 bounds.Offset(GetSlideInAnimationOffset(
558 shelf_->shelf_widget()->GetAlignment())); 563 shelf_->shelf_widget()->GetAlignment()));
559 SetChildBoundsDirect(panel, bounds); 564 SetChildBoundsDirect(panel, bounds);
560 panel->Hide(); 565 panel->Hide();
561 PanelList::iterator found = 566 PanelList::iterator found =
562 std::find(panel_windows_.begin(), panel_windows_.end(), panel); 567 std::find(panel_windows_.begin(), panel_windows_.end(), panel);
563 if (found != panel_windows_.end()) { 568 if (found != panel_windows_.end()) {
564 layer->SetOpacity(0); 569 layer->SetOpacity(kWindowLayerNotShown);
565 // The next time the window is visible it should slide into place. 570 // The next time the window is visible it should slide into place.
566 found->slide_in = true; 571 found->slide_in = true;
567 } 572 }
568 if (wm::IsActiveWindow(panel)) 573 if (wm::IsActiveWindow(panel))
569 wm::DeactivateWindow(panel); 574 wm::DeactivateWindow(panel);
570 Relayout(); 575 Relayout();
571 } 576 }
572 577
573 void PanelLayoutManager::RestorePanel(aura::Window* panel) { 578 void PanelLayoutManager::RestorePanel(aura::Window* panel) {
574 panel->Show(); 579 panel->Show();
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 panel); 855 panel);
851 callout_widget->Show(); 856 callout_widget->Show();
852 857
853 ui::Layer* layer = callout_widget->GetNativeWindow()->layer(); 858 ui::Layer* layer = callout_widget->GetNativeWindow()->layer();
854 // If the panel is not over the callout position or has just become visible 859 // If the panel is not over the callout position or has just become visible
855 // then fade in the callout. 860 // then fade in the callout.
856 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1) && 861 if ((distance_until_over_panel > 0 || layer->GetTargetOpacity() < 1) &&
857 panel->layer()->GetTargetTransform().IsIdentity()) { 862 panel->layer()->GetTargetTransform().IsIdentity()) {
858 if (distance_until_over_panel > 0 && 863 if (distance_until_over_panel > 0 &&
859 slide_distance >= distance_until_over_panel) { 864 slide_distance >= distance_until_over_panel) {
860 layer->SetOpacity(0); 865 layer->SetOpacity(kWindowLayerNotShown);
861 // If the panel is not yet over the callout, then delay fading in 866 // If the panel is not yet over the callout, then delay fading in
862 // the callout until after the panel should be over it. 867 // the callout until after the panel should be over it.
863 int delay = kPanelSlideDurationMilliseconds * 868 int delay = kPanelSlideDurationMilliseconds *
864 distance_until_over_panel / slide_distance; 869 distance_until_over_panel / slide_distance;
865 layer->SetOpacity(0); 870 layer->SetOpacity(kWindowLayerNotShown);
866 layer->GetAnimator()->StopAnimating(); 871 layer->GetAnimator()->StopAnimating();
867 layer->GetAnimator()->SchedulePauseForProperties( 872 layer->GetAnimator()->SchedulePauseForProperties(
868 base::TimeDelta::FromMilliseconds(delay), 873 base::TimeDelta::FromMilliseconds(delay),
869 ui::LayerAnimationElement::OPACITY); 874 ui::LayerAnimationElement::OPACITY);
870 } 875 }
871 { 876 {
872 ui::ScopedLayerAnimationSettings callout_settings(layer->GetAnimator()); 877 ui::ScopedLayerAnimationSettings callout_settings(layer->GetAnimator());
873 callout_settings.SetPreemptionStrategy( 878 callout_settings.SetPreemptionStrategy(
874 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS); 879 ui::LayerAnimator::REPLACE_QUEUED_ANIMATIONS);
875 callout_settings.SetTransitionDuration( 880 callout_settings.SetTransitionDuration(
(...skipping 10 matching lines...) Expand all
886 891
887 void PanelLayoutManager::OnKeyboardBoundsChanging( 892 void PanelLayoutManager::OnKeyboardBoundsChanging(
888 const gfx::Rect& keyboard_bounds) { 893 const gfx::Rect& keyboard_bounds) {
889 // This bounds change will have caused a change to the Shelf which does not 894 // This bounds change will have caused a change to the Shelf which does not
890 // propogate automatically to this class, so manually recalculate bounds. 895 // propogate automatically to this class, so manually recalculate bounds.
891 OnWindowResized(); 896 OnWindowResized();
892 } 897 }
893 898
894 } // namespace internal 899 } // namespace internal
895 } // namespace ash 900 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698