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

Side by Side Diff: ash/common/wm/dock/docked_window_layout_manager.cc

Issue 2036353002: mash: Move ash/common/wm/shelf to ash/common/shelf (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: gyp Created 4 years, 6 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/common/wm/dock/docked_window_layout_manager.h" 5 #include "ash/common/wm/dock/docked_window_layout_manager.h"
6 6
7 #include "ash/common/shelf/shelf_constants.h"
8 #include "ash/common/shelf/wm_shelf.h"
9 #include "ash/common/shelf/wm_shelf_observer.h"
7 #include "ash/common/shell_window_ids.h" 10 #include "ash/common/shell_window_ids.h"
8 #include "ash/common/wm/shelf/wm_shelf.h"
9 #include "ash/common/wm/shelf/wm_shelf_constants.h"
10 #include "ash/common/wm/shelf/wm_shelf_observer.h"
11 #include "ash/common/wm/window_animation_types.h" 11 #include "ash/common/wm/window_animation_types.h"
12 #include "ash/common/wm/window_parenting_utils.h" 12 #include "ash/common/wm/window_parenting_utils.h"
13 #include "ash/common/wm/window_resizer.h" 13 #include "ash/common/wm/window_resizer.h"
14 #include "ash/common/wm/window_state.h" 14 #include "ash/common/wm/window_state.h"
15 #include "ash/common/wm/wm_globals.h" 15 #include "ash/common/wm/wm_globals.h"
16 #include "ash/common/wm/wm_lookup.h" 16 #include "ash/common/wm/wm_lookup.h"
17 #include "ash/common/wm/wm_root_window_controller.h" 17 #include "ash/common/wm/wm_root_window_controller.h"
18 #include "ash/common/wm/wm_window.h" 18 #include "ash/common/wm/wm_window.h"
19 #include "base/auto_reset.h" 19 #include "base/auto_reset.h"
20 #include "base/metrics/histogram.h" 20 #include "base/metrics/histogram.h"
(...skipping 19 matching lines...) Expand all
40 const int DockedWindowLayoutManager::kMinDockGap = 2; 40 const int DockedWindowLayoutManager::kMinDockGap = 2;
41 // static 41 // static
42 const int DockedWindowLayoutManager::kIdealWidth = 250; 42 const int DockedWindowLayoutManager::kIdealWidth = 250;
43 const int kMinimumHeight = 250; 43 const int kMinimumHeight = 250;
44 const int kSlideDurationMs = 120; 44 const int kSlideDurationMs = 120;
45 const int kFadeDurationMs = 60; 45 const int kFadeDurationMs = 60;
46 const int kMinimizeDurationMs = 720; 46 const int kMinimizeDurationMs = 720;
47 47
48 class DockedBackgroundWidget : public views::Widget, 48 class DockedBackgroundWidget : public views::Widget,
49 public BackgroundAnimatorDelegate, 49 public BackgroundAnimatorDelegate,
50 public wm::WmShelfObserver { 50 public WmShelfObserver {
51 public: 51 public:
52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager) 52 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager)
53 : manager_(manager), 53 : manager_(manager),
54 alignment_(DOCKED_ALIGNMENT_NONE), 54 alignment_(DOCKED_ALIGNMENT_NONE),
55 background_animator_(this, 0, wm::kShelfBackgroundAlpha), 55 background_animator_(this, 0, kShelfBackgroundAlpha),
56 alpha_(0), 56 alpha_(0),
57 opaque_background_(ui::LAYER_SOLID_COLOR), 57 opaque_background_(ui::LAYER_SOLID_COLOR),
58 visible_background_type_(manager_->shelf()->GetBackgroundType()), 58 visible_background_type_(manager_->shelf()->GetBackgroundType()),
59 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { 59 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) {
60 manager_->shelf()->AddObserver(this); 60 manager_->shelf()->AddObserver(this);
61 InitWidget(manager_->dock_container()); 61 InitWidget(manager_->dock_container());
62 } 62 }
63 63
64 ~DockedBackgroundWidget() override { 64 ~DockedBackgroundWidget() override {
65 manager_->shelf()->RemoveObserver(this); 65 manager_->shelf()->RemoveObserver(this);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
104 local_window_bounds.height(), false, paint); 104 local_window_bounds.height(), false, paint);
105 } 105 }
106 106
107 // BackgroundAnimatorDelegate: 107 // BackgroundAnimatorDelegate:
108 void UpdateBackground(int alpha) override { 108 void UpdateBackground(int alpha) override {
109 alpha_ = alpha; 109 alpha_ = alpha;
110 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 110 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
111 } 111 }
112 112
113 // ShelfLayoutManagerObserver: 113 // ShelfLayoutManagerObserver:
114 void OnBackgroundUpdated(wm::ShelfBackgroundType background_type, 114 void OnBackgroundUpdated(ShelfBackgroundType background_type,
115 BackgroundAnimatorChangeType change_type) override { 115 BackgroundAnimatorChangeType change_type) override {
116 // Sets the background type. Starts an animation to transition to 116 // Sets the background type. Starts an animation to transition to
117 // |background_type| if the widget is visible. If the widget is not visible, 117 // |background_type| if the widget is visible. If the widget is not visible,
118 // the animation is postponed till the widget becomes visible. 118 // the animation is postponed till the widget becomes visible.
119 visible_background_type_ = background_type; 119 visible_background_type_ = background_type;
120 visible_background_change_type_ = change_type; 120 visible_background_change_type_ = change_type;
121 if (IsVisible()) 121 if (IsVisible())
122 UpdateBackground(); 122 UpdateBackground();
123 } 123 }
124 124
(...skipping 27 matching lines...) Expand all
152 // This background should be explicitly stacked below any windows already in 152 // This background should be explicitly stacked below any windows already in
153 // the dock, otherwise the z-order is set by the order in which windows were 153 // the dock, otherwise the z-order is set by the order in which windows were
154 // added to the container, and UpdateStacking only manages user windows, not 154 // added to the container, and UpdateStacking only manages user windows, not
155 // the background widget. 155 // the background widget.
156 parent->StackChildAtBottom(wm_window); 156 parent->StackChildAtBottom(wm_window);
157 } 157 }
158 158
159 // Transitions to |visible_background_type_| if the widget is visible and to 159 // Transitions to |visible_background_type_| if the widget is visible and to
160 // SHELF_BACKGROUND_DEFAULT if it is not. 160 // SHELF_BACKGROUND_DEFAULT if it is not.
161 void UpdateBackground() { 161 void UpdateBackground() {
162 wm::ShelfBackgroundType background_type = 162 ShelfBackgroundType background_type =
163 IsVisible() ? visible_background_type_ : wm::SHELF_BACKGROUND_DEFAULT; 163 IsVisible() ? visible_background_type_ : SHELF_BACKGROUND_DEFAULT;
164 BackgroundAnimatorChangeType change_type = 164 BackgroundAnimatorChangeType change_type =
165 IsVisible() ? visible_background_change_type_ 165 IsVisible() ? visible_background_change_type_
166 : BACKGROUND_CHANGE_IMMEDIATE; 166 : BACKGROUND_CHANGE_IMMEDIATE;
167 167
168 float target_opacity = 168 float target_opacity =
169 (background_type == wm::SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f; 169 (background_type == SHELF_BACKGROUND_MAXIMIZED) ? 1.0f : 0.0f;
170 std::unique_ptr<ui::ScopedLayerAnimationSettings> 170 std::unique_ptr<ui::ScopedLayerAnimationSettings>
171 opaque_background_animation; 171 opaque_background_animation;
172 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) { 172 if (change_type != BACKGROUND_CHANGE_IMMEDIATE) {
173 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings( 173 opaque_background_animation.reset(new ui::ScopedLayerAnimationSettings(
174 opaque_background_.GetAnimator())); 174 opaque_background_.GetAnimator()));
175 opaque_background_animation->SetTransitionDuration( 175 opaque_background_animation->SetTransitionDuration(
176 base::TimeDelta::FromMilliseconds(wm::kTimeToSwitchBackgroundMs)); 176 base::TimeDelta::FromMilliseconds(kTimeToSwitchBackgroundMs));
177 } 177 }
178 opaque_background_.SetOpacity(target_opacity); 178 opaque_background_.SetOpacity(target_opacity);
179 179
180 // TODO(varkha): use ui::Layer on both opaque_background and normal 180 // TODO(varkha): use ui::Layer on both opaque_background and normal
181 // background retire background_animator_ at all. It would be simpler. 181 // background retire background_animator_ at all. It would be simpler.
182 // See also ShelfWidget::SetPaintsBackground. 182 // See also ShelfWidget::SetPaintsBackground.
183 background_animator_.SetPaintsBackground( 183 background_animator_.SetPaintsBackground(
184 background_type != wm::SHELF_BACKGROUND_DEFAULT, change_type); 184 background_type != SHELF_BACKGROUND_DEFAULT, change_type);
185 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 185 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
186 } 186 }
187 187
188 DockedWindowLayoutManager* manager_; 188 DockedWindowLayoutManager* manager_;
189 189
190 DockedAlignment alignment_; 190 DockedAlignment alignment_;
191 191
192 // The animator for the background transitions. 192 // The animator for the background transitions.
193 BackgroundAnimator background_animator_; 193 BackgroundAnimator background_animator_;
194 194
195 // The alpha to use for drawing image assets covering the docked background. 195 // The alpha to use for drawing image assets covering the docked background.
196 int alpha_; 196 int alpha_;
197 197
198 // Solid black background that can be made fully opaque. 198 // Solid black background that can be made fully opaque.
199 ui::Layer opaque_background_; 199 ui::Layer opaque_background_;
200 200
201 // Backgrounds created from shelf background by 90 or 270 degree rotation. 201 // Backgrounds created from shelf background by 90 or 270 degree rotation.
202 gfx::ImageSkia shelf_background_left_; 202 gfx::ImageSkia shelf_background_left_;
203 gfx::ImageSkia shelf_background_right_; 203 gfx::ImageSkia shelf_background_right_;
204 204
205 // The background type to use when the widget is visible. When not visible, 205 // The background type to use when the widget is visible. When not visible,
206 // the widget uses SHELF_BACKGROUND_DEFAULT. 206 // the widget uses SHELF_BACKGROUND_DEFAULT.
207 wm::ShelfBackgroundType visible_background_type_; 207 ShelfBackgroundType visible_background_type_;
208 208
209 // Whether the widget should animate to |visible_background_type_|. 209 // Whether the widget should animate to |visible_background_type_|.
210 BackgroundAnimatorChangeType visible_background_change_type_; 210 BackgroundAnimatorChangeType visible_background_change_type_;
211 211
212 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget); 212 DISALLOW_COPY_AND_ASSIGN(DockedBackgroundWidget);
213 }; 213 };
214 214
215 namespace { 215 namespace {
216 216
217 // Returns true if a window is a popup or a transient child. 217 // Returns true if a window is a popup or a transient child.
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // count limit so do it here. 533 // count limit so do it here.
534 MaybeMinimizeChildrenExcept(dragged_window_); 534 MaybeMinimizeChildrenExcept(dragged_window_);
535 } 535 }
536 dragged_window_ = nullptr; 536 dragged_window_ = nullptr;
537 dragged_bounds_ = gfx::Rect(); 537 dragged_bounds_ = gfx::Rect();
538 Relayout(); 538 Relayout();
539 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); 539 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
540 RecordUmaAction(action, source); 540 RecordUmaAction(action, source);
541 } 541 }
542 542
543 void DockedWindowLayoutManager::SetShelf(wm::WmShelf* shelf) { 543 void DockedWindowLayoutManager::SetShelf(WmShelf* shelf) {
544 DCHECK(!shelf_); 544 DCHECK(!shelf_);
545 shelf_ = shelf; 545 shelf_ = shelf;
546 shelf_observer_.reset(new ShelfWindowObserver(this)); 546 shelf_observer_.reset(new ShelfWindowObserver(this));
547 } 547 }
548 548
549 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( 549 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow(
550 const wm::WmWindow* window) const { 550 const wm::WmWindow* window) const {
551 const gfx::Rect& bounds(window->GetBoundsInScreen()); 551 const gfx::Rect& bounds(window->GetBoundsInScreen());
552 552
553 // Test overlap with an existing docked area first. 553 // Test overlap with an existing docked area first.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
621 if (desired_alignment != DOCKED_ALIGNMENT_NONE && 621 if (desired_alignment != DOCKED_ALIGNMENT_NONE &&
622 alignment != DOCKED_ALIGNMENT_NONE && alignment != desired_alignment) { 622 alignment != DOCKED_ALIGNMENT_NONE && alignment != desired_alignment) {
623 return false; 623 return false;
624 } 624 }
625 // Do not allow docking on the same side as shelf. 625 // Do not allow docking on the same side as shelf.
626 return IsDockedAlignmentValid(desired_alignment); 626 return IsDockedAlignmentValid(desired_alignment);
627 } 627 }
628 628
629 bool DockedWindowLayoutManager::IsDockedAlignmentValid( 629 bool DockedWindowLayoutManager::IsDockedAlignmentValid(
630 DockedAlignment alignment) const { 630 DockedAlignment alignment) const {
631 wm::ShelfAlignment shelf_alignment = 631 ShelfAlignment shelf_alignment =
632 shelf_ ? shelf_->GetAlignment() : wm::SHELF_ALIGNMENT_BOTTOM; 632 shelf_ ? shelf_->GetAlignment() : SHELF_ALIGNMENT_BOTTOM;
633 if ((alignment == DOCKED_ALIGNMENT_LEFT && 633 if ((alignment == DOCKED_ALIGNMENT_LEFT &&
634 shelf_alignment == wm::SHELF_ALIGNMENT_LEFT) || 634 shelf_alignment == SHELF_ALIGNMENT_LEFT) ||
635 (alignment == DOCKED_ALIGNMENT_RIGHT && 635 (alignment == DOCKED_ALIGNMENT_RIGHT &&
636 shelf_alignment == wm::SHELF_ALIGNMENT_RIGHT)) { 636 shelf_alignment == SHELF_ALIGNMENT_RIGHT)) {
637 return false; 637 return false;
638 } 638 }
639 return true; 639 return true;
640 } 640 }
641 641
642 void DockedWindowLayoutManager::MaybeSetDesiredDockedAlignment( 642 void DockedWindowLayoutManager::MaybeSetDesiredDockedAlignment(
643 DockedAlignment alignment) { 643 DockedAlignment alignment) {
644 // If the requested alignment is |NONE| or there are no 644 // If the requested alignment is |NONE| or there are no
645 // docked windows return early as we can't change whether there is a 645 // docked windows return early as we can't change whether there is a
646 // dock or not. If the requested alignment is the same as the current 646 // dock or not. If the requested alignment is the same as the current
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 Relayout(); 789 Relayout();
790 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); 790 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
791 } 791 }
792 792
793 void DockedWindowLayoutManager::OnShelfAlignmentChanged() { 793 void DockedWindowLayoutManager::OnShelfAlignmentChanged() {
794 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE) 794 if (!shelf_ || alignment_ == DOCKED_ALIGNMENT_NONE)
795 return; 795 return;
796 796
797 // Do not allow shelf and dock on the same side. Switch side that 797 // Do not allow shelf and dock on the same side. Switch side that
798 // the dock is attached to and move all dock windows to that new side. 798 // the dock is attached to and move all dock windows to that new side.
799 wm::ShelfAlignment shelf_alignment = shelf_->GetAlignment(); 799 ShelfAlignment shelf_alignment = shelf_->GetAlignment();
800 if (alignment_ == DOCKED_ALIGNMENT_LEFT && 800 if (alignment_ == DOCKED_ALIGNMENT_LEFT &&
801 shelf_alignment == wm::SHELF_ALIGNMENT_LEFT) { 801 shelf_alignment == SHELF_ALIGNMENT_LEFT) {
802 alignment_ = DOCKED_ALIGNMENT_RIGHT; 802 alignment_ = DOCKED_ALIGNMENT_RIGHT;
803 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && 803 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT &&
804 shelf_alignment == wm::SHELF_ALIGNMENT_RIGHT) { 804 shelf_alignment == SHELF_ALIGNMENT_RIGHT) {
805 alignment_ = DOCKED_ALIGNMENT_LEFT; 805 alignment_ = DOCKED_ALIGNMENT_LEFT;
806 } 806 }
807 Relayout(); 807 Relayout();
808 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); 808 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED);
809 } 809 }
810 810
811 ///////////////////////////////////////////////////////////////////////////// 811 /////////////////////////////////////////////////////////////////////////////
812 // DockedWindowLayoutManager, WindowStateObserver implementation: 812 // DockedWindowLayoutManager, WindowStateObserver implementation:
813 813
814 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( 814 void DockedWindowLayoutManager::OnPreWindowStateTypeChange(
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
1320 1320
1321 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( 1321 void DockedWindowLayoutManager::OnKeyboardBoundsChanging(
1322 const gfx::Rect& keyboard_bounds) { 1322 const gfx::Rect& keyboard_bounds) {
1323 // This bounds change will have caused a change to the Shelf which does not 1323 // This bounds change will have caused a change to the Shelf which does not
1324 // propagate automatically to this class, so manually recalculate bounds. 1324 // propagate automatically to this class, so manually recalculate bounds.
1325 Relayout(); 1325 Relayout();
1326 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); 1326 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING);
1327 } 1327 }
1328 1328
1329 } // namespace ash 1329 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698