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

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

Issue 1882713004: Only create DockedBackgroundWidget as needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use a more verbose comment. Created 4 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
« no previous file with comments | « ash/wm/dock/docked_window_layout_manager.h ('k') | no next file » | 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) 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/wm/dock/docked_window_layout_manager.h" 5 #include "ash/wm/dock/docked_window_layout_manager.h"
6 6
7 #include "ash/screen_util.h" 7 #include "ash/screen_util.h"
8 #include "ash/shelf/shelf.h" 8 #include "ash/shelf/shelf.h"
9 #include "ash/shelf/shelf_constants.h" 9 #include "ash/shelf/shelf_constants.h"
10 #include "ash/shelf/shelf_layout_manager.h" 10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_layout_manager_observer.h"
11 #include "ash/shelf/shelf_types.h" 12 #include "ash/shelf/shelf_types.h"
12 #include "ash/shelf/shelf_widget.h" 13 #include "ash/shelf/shelf_widget.h"
13 #include "ash/shell.h" 14 #include "ash/shell.h"
14 #include "ash/shell_window_ids.h" 15 #include "ash/shell_window_ids.h"
15 #include "ash/wm/coordinate_conversion.h" 16 #include "ash/wm/coordinate_conversion.h"
16 #include "ash/wm/window_animations.h" 17 #include "ash/wm/window_animations.h"
17 #include "ash/wm/window_properties.h" 18 #include "ash/wm/window_properties.h"
18 #include "ash/wm/window_resizer.h" 19 #include "ash/wm/window_resizer.h"
19 #include "ash/wm/window_state.h" 20 #include "ash/wm/window_state.h"
20 #include "ash/wm/window_util.h" 21 #include "ash/wm/window_util.h"
(...skipping 29 matching lines...) Expand all
50 // static 51 // static
51 const int DockedWindowLayoutManager::kMinDockGap = 2; 52 const int DockedWindowLayoutManager::kMinDockGap = 2;
52 // static 53 // static
53 const int DockedWindowLayoutManager::kIdealWidth = 250; 54 const int DockedWindowLayoutManager::kIdealWidth = 250;
54 const int kMinimumHeight = 250; 55 const int kMinimumHeight = 250;
55 const int kSlideDurationMs = 120; 56 const int kSlideDurationMs = 120;
56 const int kFadeDurationMs = 60; 57 const int kFadeDurationMs = 60;
57 const int kMinimizeDurationMs = 720; 58 const int kMinimizeDurationMs = 720;
58 59
59 class DockedBackgroundWidget : public views::Widget, 60 class DockedBackgroundWidget : public views::Widget,
60 public BackgroundAnimatorDelegate { 61 public BackgroundAnimatorDelegate,
62 public ShelfLayoutManagerObserver {
61 public: 63 public:
62 explicit DockedBackgroundWidget(aura::Window* container) 64 explicit DockedBackgroundWidget(DockedWindowLayoutManager* manager)
63 : alignment_(DOCKED_ALIGNMENT_NONE), 65 : manager_(manager),
66 alignment_(DOCKED_ALIGNMENT_NONE),
64 background_animator_(this, 0, kShelfBackgroundAlpha), 67 background_animator_(this, 0, kShelfBackgroundAlpha),
65 alpha_(0), 68 alpha_(0),
66 opaque_background_(ui::LAYER_SOLID_COLOR), 69 opaque_background_(ui::LAYER_SOLID_COLOR),
67 visible_background_type_(SHELF_BACKGROUND_DEFAULT), 70 visible_background_type_(
71 manager_->shelf()->shelf_widget()->GetBackgroundType()),
68 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) { 72 visible_background_change_type_(BACKGROUND_CHANGE_IMMEDIATE) {
69 InitWidget(container); 73 manager_->shelf()->shelf_layout_manager()->AddObserver(this);
74 InitWidget(manager_->dock_container());
75 }
76
77 ~DockedBackgroundWidget() override {
78 manager_->shelf()->shelf_layout_manager()->RemoveObserver(this);
70 } 79 }
71 80
72 // Sets widget bounds and sizes opaque background layer to fill the widget. 81 // Sets widget bounds and sizes opaque background layer to fill the widget.
73 void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) { 82 void SetBackgroundBounds(const gfx::Rect bounds, DockedAlignment alignment) {
74 SetBounds(bounds); 83 SetBounds(bounds);
75 opaque_background_.SetBounds(gfx::Rect(bounds.size())); 84 opaque_background_.SetBounds(gfx::Rect(bounds.size()));
76 alignment_ = alignment; 85 alignment_ = alignment;
77 } 86 }
78 87
79 // Sets the background type. Starts an animation to transition to 88 private:
80 // |background_type| if the widget is visible. If the widget is not visible,
81 // the animation is postponed till the widget becomes visible.
82 void SetBackgroundType(ShelfBackgroundType background_type,
83 BackgroundAnimatorChangeType change_type) {
84 visible_background_type_ = background_type;
85 visible_background_change_type_ = change_type;
86 if (IsVisible())
87 UpdateBackground();
88 }
89
90 // views::Widget: 89 // views::Widget:
91 void OnNativeWidgetVisibilityChanged(bool visible) override { 90 void OnNativeWidgetVisibilityChanged(bool visible) override {
92 views::Widget::OnNativeWidgetVisibilityChanged(visible); 91 views::Widget::OnNativeWidgetVisibilityChanged(visible);
93 UpdateBackground(); 92 UpdateBackground();
94 } 93 }
95 94
96 void OnNativeWidgetPaint(const ui::PaintContext& context) override { 95 void OnNativeWidgetPaint(const ui::PaintContext& context) override {
97 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size()); 96 gfx::Rect local_window_bounds(GetWindowBoundsInScreen().size());
98 ui::PaintRecorder recorder(context, local_window_bounds.size()); 97 ui::PaintRecorder recorder(context, local_window_bounds.size());
99 const gfx::ImageSkia& shelf_background( 98 const gfx::ImageSkia& shelf_background(
(...skipping 17 matching lines...) Expand all
117 local_window_bounds.width() - shelf_background.width(), 116 local_window_bounds.width() - shelf_background.width(),
118 local_window_bounds.height(), false, paint); 117 local_window_bounds.height(), false, paint);
119 } 118 }
120 119
121 // BackgroundAnimatorDelegate: 120 // BackgroundAnimatorDelegate:
122 void UpdateBackground(int alpha) override { 121 void UpdateBackground(int alpha) override {
123 alpha_ = alpha; 122 alpha_ = alpha;
124 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 123 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
125 } 124 }
126 125
127 private: 126 // ShelfLayoutManagerObserver:
127 void OnBackgroundUpdated(ShelfBackgroundType background_type,
128 BackgroundAnimatorChangeType change_type) override {
129 // Sets the background type. Starts an animation to transition to
130 // |background_type| if the widget is visible. If the widget is not visible,
131 // the animation is postponed till the widget becomes visible.
132 visible_background_type_ = background_type;
133 visible_background_change_type_ = change_type;
134 if (IsVisible())
135 UpdateBackground();
136 }
137
128 void InitWidget(aura::Window* parent) { 138 void InitWidget(aura::Window* parent) {
129 views::Widget::InitParams params; 139 views::Widget::InitParams params;
130 params.type = views::Widget::InitParams::TYPE_POPUP; 140 params.type = views::Widget::InitParams::TYPE_POPUP;
131 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; 141 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
132 params.keep_on_top = false; 142 params.keep_on_top = false;
133 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 143 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
134 params.parent = parent; 144 params.parent = parent;
135 params.accept_events = false; 145 params.accept_events = false;
136 set_focus_on_creation(false); 146 set_focus_on_creation(false);
137 Init(params); 147 Init(params);
138 SetVisibilityChangedAnimationsEnabled(false); 148 SetVisibilityChangedAnimationsEnabled(false);
139 GetNativeWindow()->SetProperty(kStayInSameRootWindowKey, true); 149 GetNativeWindow()->SetProperty(kStayInSameRootWindowKey, true);
140 opaque_background_.SetColor(SK_ColorBLACK); 150 opaque_background_.SetColor(SK_ColorBLACK);
141 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size())); 151 opaque_background_.SetBounds(gfx::Rect(GetWindowBoundsInScreen().size()));
142 opaque_background_.SetOpacity(0.0f); 152 opaque_background_.SetOpacity(0.0f);
143 GetNativeWindow()->layer()->Add(&opaque_background_); 153 GetNativeWindow()->layer()->Add(&opaque_background_);
144 Hide();
145 154
146 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 155 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
147 gfx::ImageSkia shelf_background = 156 gfx::ImageSkia shelf_background =
148 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND); 157 *rb.GetImageSkiaNamed(IDR_ASH_SHELF_BACKGROUND);
149 shelf_background_left_ = gfx::ImageSkiaOperations::CreateRotatedImage( 158 shelf_background_left_ = gfx::ImageSkiaOperations::CreateRotatedImage(
150 shelf_background, SkBitmapOperations::ROTATION_90_CW); 159 shelf_background, SkBitmapOperations::ROTATION_90_CW);
151 shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage( 160 shelf_background_right_ = gfx::ImageSkiaOperations::CreateRotatedImage(
152 shelf_background, SkBitmapOperations::ROTATION_270_CW); 161 shelf_background, SkBitmapOperations::ROTATION_270_CW);
162
163 // This background should be explicitly stacked below any windows already in
164 // the dock, otherwise the z-order is set by the order in which windows were
165 // added to the container, and UpdateStacking only manages user windows, not
166 // the background widget.
167 parent->StackChildAtBottom(GetNativeWindow());
153 } 168 }
154 169
155 // Transitions to |visible_background_type_| if the widget is visible and to 170 // Transitions to |visible_background_type_| if the widget is visible and to
156 // SHELF_BACKGROUND_DEFAULT if it is not. 171 // SHELF_BACKGROUND_DEFAULT if it is not.
157 void UpdateBackground() { 172 void UpdateBackground() {
158 ShelfBackgroundType background_type = IsVisible() ? 173 ShelfBackgroundType background_type = IsVisible() ?
159 visible_background_type_ : SHELF_BACKGROUND_DEFAULT; 174 visible_background_type_ : SHELF_BACKGROUND_DEFAULT;
160 BackgroundAnimatorChangeType change_type = IsVisible() ? 175 BackgroundAnimatorChangeType change_type = IsVisible() ?
161 visible_background_change_type_ : BACKGROUND_CHANGE_IMMEDIATE; 176 visible_background_change_type_ : BACKGROUND_CHANGE_IMMEDIATE;
162 177
(...skipping 11 matching lines...) Expand all
174 189
175 // TODO(varkha): use ui::Layer on both opaque_background and normal 190 // TODO(varkha): use ui::Layer on both opaque_background and normal
176 // background retire background_animator_ at all. It would be simpler. 191 // background retire background_animator_ at all. It would be simpler.
177 // See also ShelfWidget::SetPaintsBackground. 192 // See also ShelfWidget::SetPaintsBackground.
178 background_animator_.SetPaintsBackground( 193 background_animator_.SetPaintsBackground(
179 background_type != SHELF_BACKGROUND_DEFAULT, 194 background_type != SHELF_BACKGROUND_DEFAULT,
180 change_type); 195 change_type);
181 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size())); 196 SchedulePaintInRect(gfx::Rect(GetWindowBoundsInScreen().size()));
182 } 197 }
183 198
199 DockedWindowLayoutManager* manager_;
200
184 DockedAlignment alignment_; 201 DockedAlignment alignment_;
185 202
186 // The animator for the background transitions. 203 // The animator for the background transitions.
187 BackgroundAnimator background_animator_; 204 BackgroundAnimator background_animator_;
188 205
189 // The alpha to use for drawing image assets covering the docked background. 206 // The alpha to use for drawing image assets covering the docked background.
190 int alpha_; 207 int alpha_;
191 208
192 // Solid black background that can be made fully opaque. 209 // Solid black background that can be made fully opaque.
193 ui::Layer opaque_background_; 210 ui::Layer opaque_background_;
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 }; 411 };
395 412
396 //////////////////////////////////////////////////////////////////////////////// 413 ////////////////////////////////////////////////////////////////////////////////
397 // DockedWindowLayoutManager public implementation: 414 // DockedWindowLayoutManager public implementation:
398 DockedWindowLayoutManager::DockedWindowLayoutManager( 415 DockedWindowLayoutManager::DockedWindowLayoutManager(
399 aura::Window* dock_container, 416 aura::Window* dock_container,
400 WorkspaceController* workspace_controller) 417 WorkspaceController* workspace_controller)
401 : SnapToPixelLayoutManager(dock_container), 418 : SnapToPixelLayoutManager(dock_container),
402 dock_container_(dock_container), 419 dock_container_(dock_container),
403 in_layout_(false), 420 in_layout_(false),
404 dragged_window_(NULL), 421 dragged_window_(nullptr),
405 is_dragged_window_docked_(false), 422 is_dragged_window_docked_(false),
406 is_dragged_from_dock_(false), 423 is_dragged_from_dock_(false),
407 shelf_(NULL), 424 shelf_(nullptr),
408 workspace_controller_(workspace_controller), 425 workspace_controller_(workspace_controller),
409 in_fullscreen_(workspace_controller_->GetWindowState() == 426 in_fullscreen_(workspace_controller_->GetWindowState() ==
410 WORKSPACE_WINDOW_STATE_FULL_SCREEN), 427 WORKSPACE_WINDOW_STATE_FULL_SCREEN),
411 docked_width_(0), 428 docked_width_(0),
412 alignment_(DOCKED_ALIGNMENT_NONE), 429 alignment_(DOCKED_ALIGNMENT_NONE),
413 preferred_alignment_(DOCKED_ALIGNMENT_NONE), 430 preferred_alignment_(DOCKED_ALIGNMENT_NONE),
414 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN), 431 event_source_(DOCKED_ACTION_SOURCE_UNKNOWN),
415 last_active_window_(NULL), 432 last_active_window_(nullptr),
416 last_action_time_(base::Time::Now()), 433 last_action_time_(base::Time::Now()),
417 background_widget_(new DockedBackgroundWidget(dock_container_)) { 434 background_widget_(nullptr) {
418 DCHECK(dock_container); 435 DCHECK(dock_container);
419 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> 436 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
420 AddObserver(this); 437 AddObserver(this);
421 Shell::GetInstance()->AddShellObserver(this); 438 Shell::GetInstance()->AddShellObserver(this);
422 } 439 }
423 440
424 DockedWindowLayoutManager::~DockedWindowLayoutManager() { 441 DockedWindowLayoutManager::~DockedWindowLayoutManager() {
425 Shutdown(); 442 Shutdown();
426 } 443 }
427 444
428 void DockedWindowLayoutManager::Shutdown() { 445 void DockedWindowLayoutManager::Shutdown() {
429 if (shelf_ && shelf_->shelf_layout_manager()) { 446 background_widget_.reset();
430 shelf_->shelf_layout_manager()->RemoveObserver(this); 447 shelf_observer_.reset();
431 shelf_observer_.reset(); 448 shelf_ = nullptr;
432 }
433 shelf_ = NULL;
434 for (size_t i = 0; i < dock_container_->children().size(); ++i) { 449 for (size_t i = 0; i < dock_container_->children().size(); ++i) {
435 aura::Window* child = dock_container_->children()[i]; 450 aura::Window* child = dock_container_->children()[i];
436 child->RemoveObserver(this); 451 child->RemoveObserver(this);
437 wm::GetWindowState(child)->RemoveObserver(this); 452 wm::GetWindowState(child)->RemoveObserver(this);
438 } 453 }
439 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())-> 454 aura::client::GetActivationClient(Shell::GetPrimaryRootWindow())->
440 RemoveObserver(this); 455 RemoveObserver(this);
441 Shell::GetInstance()->RemoveShellObserver(this); 456 Shell::GetInstance()->RemoveShellObserver(this);
442 } 457 }
443 458
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
510 DCHECK(!IsPopupOrTransient(dragged_window_)); 525 DCHECK(!IsPopupOrTransient(dragged_window_));
511 if (is_dragged_window_docked_) 526 if (is_dragged_window_docked_)
512 OnDraggedWindowUndocked(); 527 OnDraggedWindowUndocked();
513 DCHECK (!is_dragged_window_docked_); 528 DCHECK (!is_dragged_window_docked_);
514 // Stop observing a window unless it is docked container's child in which 529 // Stop observing a window unless it is docked container's child in which
515 // case it needs to keep being observed after the drag completes. 530 // case it needs to keep being observed after the drag completes.
516 if (dragged_window_->parent() != dock_container_) { 531 if (dragged_window_->parent() != dock_container_) {
517 dragged_window_->RemoveObserver(this); 532 dragged_window_->RemoveObserver(this);
518 wm::GetWindowState(dragged_window_)->RemoveObserver(this); 533 wm::GetWindowState(dragged_window_)->RemoveObserver(this);
519 if (last_active_window_ == dragged_window_) 534 if (last_active_window_ == dragged_window_)
520 last_active_window_ = NULL; 535 last_active_window_ = nullptr;
521 } else { 536 } else {
522 // If this is the first window that got docked by a move update alignment. 537 // If this is the first window that got docked by a move update alignment.
523 if (alignment_ == DOCKED_ALIGNMENT_NONE) 538 if (alignment_ == DOCKED_ALIGNMENT_NONE)
524 alignment_ = GetEdgeNearestWindow(dragged_window_); 539 alignment_ = GetEdgeNearestWindow(dragged_window_);
525 // A window is no longer dragged and is a child. 540 // A window is no longer dragged and is a child.
526 // When a window becomes a child at drag start this is 541 // When a window becomes a child at drag start this is
527 // the only opportunity we will have to enforce a window 542 // the only opportunity we will have to enforce a window
528 // count limit so do it here. 543 // count limit so do it here.
529 MaybeMinimizeChildrenExcept(dragged_window_); 544 MaybeMinimizeChildrenExcept(dragged_window_);
530 } 545 }
531 dragged_window_ = NULL; 546 dragged_window_ = nullptr;
532 dragged_bounds_ = gfx::Rect(); 547 dragged_bounds_ = gfx::Rect();
533 Relayout(); 548 Relayout();
534 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); 549 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
535 RecordUmaAction(action, source); 550 RecordUmaAction(action, source);
536 } 551 }
537 552
538 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) { 553 void DockedWindowLayoutManager::SetShelf(Shelf* shelf) {
539 DCHECK(!shelf_); 554 DCHECK(!shelf_);
540 shelf_ = shelf; 555 shelf_ = shelf;
541 if (shelf_->shelf_layout_manager()) { 556 shelf_observer_.reset(new ShelfWindowObserver(this));
542 shelf_->shelf_layout_manager()->AddObserver(this);
543 shelf_observer_.reset(new ShelfWindowObserver(this));
544 }
545 } 557 }
546 558
547 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow( 559 DockedAlignment DockedWindowLayoutManager::GetAlignmentOfWindow(
548 const aura::Window* window) const { 560 const aura::Window* window) const {
549 const gfx::Rect& bounds(window->GetBoundsInScreen()); 561 const gfx::Rect& bounds(window->GetBoundsInScreen());
550 562
551 // Test overlap with an existing docked area first. 563 // Test overlap with an existing docked area first.
552 if (docked_bounds_.Intersects(bounds) && 564 if (docked_bounds_.Intersects(bounds) &&
553 alignment_ != DOCKED_ALIGNMENT_NONE) { 565 alignment_ != DOCKED_ALIGNMENT_NONE) {
554 // A window is being added to other docked windows (on the same side). 566 // A window is being added to other docked windows (on the same side).
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 // change alignment during the drag. They also cannot be set to be the 719 // change alignment during the drag. They also cannot be set to be the
708 // |last_active_window_|. 720 // |last_active_window_|.
709 if (child == dragged_window_) 721 if (child == dragged_window_)
710 return; 722 return;
711 // If this is the last window, set alignment and maximize the workspace. 723 // If this is the last window, set alignment and maximize the workspace.
712 if (!IsAnyWindowDocked()) { 724 if (!IsAnyWindowDocked()) {
713 alignment_ = DOCKED_ALIGNMENT_NONE; 725 alignment_ = DOCKED_ALIGNMENT_NONE;
714 UpdateDockedWidth(0); 726 UpdateDockedWidth(0);
715 } 727 }
716 if (last_active_window_ == child) 728 if (last_active_window_ == child)
717 last_active_window_ = NULL; 729 last_active_window_ = nullptr;
718 child->RemoveObserver(this); 730 child->RemoveObserver(this);
719 wm::GetWindowState(child)->RemoveObserver(this); 731 wm::GetWindowState(child)->RemoveObserver(this);
720 Relayout(); 732 Relayout();
721 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED); 733 UpdateDockBounds(DockedWindowLayoutManagerObserver::CHILD_CHANGED);
722 } 734 }
723 735
724 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged( 736 void DockedWindowLayoutManager::OnChildWindowVisibilityChanged(
725 aura::Window* child, 737 aura::Window* child,
726 bool visible) { 738 bool visible) {
727 if (IsPopupOrTransient(child)) 739 if (IsPopupOrTransient(child))
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 alignment_ = DOCKED_ALIGNMENT_RIGHT; 826 alignment_ = DOCKED_ALIGNMENT_RIGHT;
815 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT && 827 } else if (alignment_ == DOCKED_ALIGNMENT_RIGHT &&
816 shelf_alignment == SHELF_ALIGNMENT_RIGHT) { 828 shelf_alignment == SHELF_ALIGNMENT_RIGHT) {
817 alignment_ = DOCKED_ALIGNMENT_LEFT; 829 alignment_ = DOCKED_ALIGNMENT_LEFT;
818 } 830 }
819 Relayout(); 831 Relayout();
820 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED); 832 UpdateDockBounds(DockedWindowLayoutManagerObserver::SHELF_ALIGNMENT_CHANGED);
821 } 833 }
822 834
823 ///////////////////////////////////////////////////////////////////////////// 835 /////////////////////////////////////////////////////////////////////////////
824 // DockedWindowLayoutManager, ShelfLayoutManagerObserver implementation:
825 void DockedWindowLayoutManager::OnBackgroundUpdated(
826 ShelfBackgroundType background_type,
827 BackgroundAnimatorChangeType change_type) {
828 background_widget_->SetBackgroundType(background_type, change_type);
829 }
830
831 /////////////////////////////////////////////////////////////////////////////
832 // DockedWindowLayoutManager, WindowStateObserver implementation: 836 // DockedWindowLayoutManager, WindowStateObserver implementation:
833 837
834 void DockedWindowLayoutManager::OnPreWindowStateTypeChange( 838 void DockedWindowLayoutManager::OnPreWindowStateTypeChange(
835 wm::WindowState* window_state, 839 wm::WindowState* window_state,
836 wm::WindowStateType old_type) { 840 wm::WindowStateType old_type) {
837 aura::Window* window = window_state->window(); 841 aura::Window* window = window_state->window();
838 if (IsPopupOrTransient(window)) 842 if (IsPopupOrTransient(window))
839 return; 843 return;
840 // The window property will still be set, but no actual change will occur 844 // The window property will still be set, but no actual change will occur
841 // until OnFullscreenStateChange is called when exiting fullscreen. 845 // until OnFullscreenStateChange is called when exiting fullscreen.
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 ::wm::SetWindowVisibilityAnimationType(window, animation_type); 889 ::wm::SetWindowVisibilityAnimationType(window, animation_type);
886 } 890 }
887 891
888 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) { 892 void DockedWindowLayoutManager::OnWindowDestroying(aura::Window* window) {
889 if (dragged_window_ == window) { 893 if (dragged_window_ == window) {
890 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN); 894 FinishDragging(DOCKED_ACTION_NONE, DOCKED_ACTION_SOURCE_UNKNOWN);
891 DCHECK(!dragged_window_); 895 DCHECK(!dragged_window_);
892 DCHECK(!is_dragged_window_docked_); 896 DCHECK(!is_dragged_window_docked_);
893 } 897 }
894 if (window == last_active_window_) 898 if (window == last_active_window_)
895 last_active_window_ = NULL; 899 last_active_window_ = nullptr;
896 RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_); 900 RecordUmaAction(DOCKED_ACTION_CLOSE, event_source_);
897 } 901 }
898 902
899
900 //////////////////////////////////////////////////////////////////////////////// 903 ////////////////////////////////////////////////////////////////////////////////
901 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver 904 // DockedWindowLayoutManager, aura::client::ActivationChangeObserver
902 // implementation: 905 // implementation:
903 906
904 void DockedWindowLayoutManager::OnWindowActivated( 907 void DockedWindowLayoutManager::OnWindowActivated(
905 aura::client::ActivationChangeObserver::ActivationReason reason, 908 aura::client::ActivationChangeObserver::ActivationReason reason,
906 aura::Window* gained_active, 909 aura::Window* gained_active,
907 aura::Window* lost_active) { 910 aura::Window* lost_active) {
908 if (gained_active && IsPopupOrTransient(gained_active)) 911 if (gained_active && IsPopupOrTransient(gained_active))
909 return; 912 return;
910 // Ignore if the window that is not managed by this was activated. 913 // Ignore if the window that is not managed by this was activated.
911 aura::Window* ancestor = NULL; 914 aura::Window* ancestor = nullptr;
912 for (aura::Window* parent = gained_active; 915 for (aura::Window* parent = gained_active;
913 parent; parent = parent->parent()) { 916 parent; parent = parent->parent()) {
914 if (parent->parent() == dock_container_) { 917 if (parent->parent() == dock_container_) {
915 ancestor = parent; 918 ancestor = parent;
916 break; 919 break;
917 } 920 }
918 } 921 }
919 if (ancestor) 922 if (ancestor)
920 UpdateStacking(ancestor); 923 UpdateStacking(ancestor);
921 } 924 }
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1068 } 1071 }
1069 1072
1070 void DockedWindowLayoutManager::Relayout() { 1073 void DockedWindowLayoutManager::Relayout() {
1071 if (in_layout_) 1074 if (in_layout_)
1072 return; 1075 return;
1073 if (alignment_ == DOCKED_ALIGNMENT_NONE && !is_dragged_window_docked_) 1076 if (alignment_ == DOCKED_ALIGNMENT_NONE && !is_dragged_window_docked_)
1074 return; 1077 return;
1075 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true); 1078 base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
1076 1079
1077 gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen(); 1080 gfx::Rect dock_bounds = dock_container_->GetBoundsInScreen();
1078 aura::Window* active_window = NULL; 1081 aura::Window* active_window = nullptr;
1079 std::vector<WindowWithHeight> visible_windows; 1082 std::vector<WindowWithHeight> visible_windows;
1080 for (size_t i = 0; i < dock_container_->children().size(); ++i) { 1083 for (size_t i = 0; i < dock_container_->children().size(); ++i) {
1081 aura::Window* window(dock_container_->children()[i]); 1084 aura::Window* window(dock_container_->children()[i]);
1082 1085
1083 if (!IsWindowDocked(window) || window == dragged_window_) 1086 if (!IsWindowDocked(window) || window == dragged_window_)
1084 continue; 1087 continue;
1085 1088
1086 // If the shelf is currently hidden (full-screen mode), hide window until 1089 // If the shelf is currently hidden (full-screen mode), hide window until
1087 // full-screen mode is exited. 1090 // full-screen mode is exited.
1088 if (in_fullscreen_) { 1091 if (in_fullscreen_) {
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1199 int new_width = ideal_docked_width; 1202 int new_width = ideal_docked_width;
1200 if (visible_windows->empty() || 1203 if (visible_windows->empty() ||
1201 (visible_windows->size() == 1 && 1204 (visible_windows->size() == 1 &&
1202 (*visible_windows)[0].window() == dragged_window_)) { 1205 (*visible_windows)[0].window() == dragged_window_)) {
1203 new_width = 0; 1206 new_width = 0;
1204 } 1207 }
1205 UpdateDockedWidth(new_width); 1208 UpdateDockedWidth(new_width);
1206 // Sort windows by their center positions and fan out overlapping 1209 // Sort windows by their center positions and fan out overlapping
1207 // windows. 1210 // windows.
1208 std::sort(visible_windows->begin(), visible_windows->end(), 1211 std::sort(visible_windows->begin(), visible_windows->end(),
1209 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : NULL, 1212 CompareWindowPos(is_dragged_from_dock_ ? dragged_window_ : nullptr,
1210 dock_container_, 1213 dock_container_, delta));
1211 delta));
1212 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin(); 1214 for (std::vector<WindowWithHeight>::iterator iter = visible_windows->begin();
1213 iter != visible_windows->end(); ++iter) { 1215 iter != visible_windows->end(); ++iter) {
1214 aura::Window* window = iter->window(); 1216 aura::Window* window = iter->window();
1215 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen( 1217 gfx::Rect bounds = ScreenUtil::ConvertRectToScreen(
1216 dock_container_, window->GetTargetBounds()); 1218 dock_container_, window->GetTargetBounds());
1217 // A window is extended or shrunk to be as close as possible to the ideal 1219 // A window is extended or shrunk to be as close as possible to the ideal
1218 // docked area width. Windows that were resized by a user are kept at their 1220 // docked area width. Windows that were resized by a user are kept at their
1219 // existing size. 1221 // existing size.
1220 // This also enforces the min / max restrictions on the docked area width. 1222 // This also enforces the min / max restrictions on the docked area width.
1221 bounds.set_width(GetWindowWidthCloseTo( 1223 bounds.set_width(GetWindowWidthCloseTo(
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 docked_bounds_ = bounds + 1287 docked_bounds_ = bounds +
1286 dock_container_->GetBoundsInScreen().OffsetFromOrigin(); 1288 dock_container_->GetBoundsInScreen().OffsetFromOrigin();
1287 FOR_EACH_OBSERVER( 1289 FOR_EACH_OBSERVER(
1288 DockedWindowLayoutManagerObserver, 1290 DockedWindowLayoutManagerObserver,
1289 observer_list_, 1291 observer_list_,
1290 OnDockBoundsChanging(bounds, reason)); 1292 OnDockBoundsChanging(bounds, reason));
1291 // Show or hide background for docked area. 1293 // Show or hide background for docked area.
1292 gfx::Rect background_bounds(docked_bounds_); 1294 gfx::Rect background_bounds(docked_bounds_);
1293 if (shelf_observer_) 1295 if (shelf_observer_)
1294 background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen()); 1296 background_bounds.Subtract(shelf_observer_->shelf_bounds_in_screen());
1295 background_widget_->SetBackgroundBounds(background_bounds, alignment_); 1297 if (docked_width_ > 0) {
1296 if (docked_width_ > 0) 1298 if (!background_widget_)
1299 background_widget_.reset(new DockedBackgroundWidget(this));
1300 background_widget_->SetBackgroundBounds(background_bounds, alignment_);
1297 background_widget_->Show(); 1301 background_widget_->Show();
1298 else 1302 } else if (background_widget_) {
1299 background_widget_->Hide(); 1303 background_widget_->Hide();
1304 }
1300 } 1305 }
1301 1306
1302 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) { 1307 void DockedWindowLayoutManager::UpdateStacking(aura::Window* active_window) {
1303 if (!active_window) { 1308 if (!active_window) {
1304 if (!last_active_window_) 1309 if (!last_active_window_)
1305 return; 1310 return;
1306 active_window = last_active_window_; 1311 active_window = last_active_window_;
1307 } 1312 }
1308 1313
1309 // Windows are stacked like a deck of cards: 1314 // Windows are stacked like a deck of cards:
(...skipping 15 matching lines...) Expand all
1325 if (!IsWindowDocked(*it) || 1330 if (!IsWindowDocked(*it) ||
1326 ((*it) == dragged_window_ && !is_dragged_window_docked_)) { 1331 ((*it) == dragged_window_ && !is_dragged_window_docked_)) {
1327 continue; 1332 continue;
1328 } 1333 }
1329 gfx::Rect bounds = (*it)->bounds(); 1334 gfx::Rect bounds = (*it)->bounds();
1330 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2, 1335 window_ordering.insert(std::make_pair(bounds.y() + bounds.height() / 2,
1331 *it)); 1336 *it));
1332 } 1337 }
1333 int active_center_y = active_window->bounds().CenterPoint().y(); 1338 int active_center_y = active_window->bounds().CenterPoint().y();
1334 1339
1335 aura::Window* previous_window = NULL; 1340 aura::Window* previous_window = nullptr;
1336 for (std::map<int, aura::Window*>::const_iterator it = 1341 for (std::map<int, aura::Window*>::const_iterator it =
1337 window_ordering.begin(); 1342 window_ordering.begin();
1338 it != window_ordering.end() && it->first < active_center_y; ++it) { 1343 it != window_ordering.end() && it->first < active_center_y; ++it) {
1339 if (previous_window) 1344 if (previous_window)
1340 dock_container_->StackChildAbove(it->second, previous_window); 1345 dock_container_->StackChildAbove(it->second, previous_window);
1341 previous_window = it->second; 1346 previous_window = it->second;
1342 } 1347 }
1343 for (std::map<int, aura::Window*>::const_reverse_iterator it = 1348 for (std::map<int, aura::Window*>::const_reverse_iterator it =
1344 window_ordering.rbegin(); 1349 window_ordering.rbegin();
1345 it != window_ordering.rend() && it->first > active_center_y; ++it) { 1350 it != window_ordering.rend() && it->first > active_center_y; ++it) {
(...skipping 13 matching lines...) Expand all
1359 1364
1360 void DockedWindowLayoutManager::OnKeyboardBoundsChanging( 1365 void DockedWindowLayoutManager::OnKeyboardBoundsChanging(
1361 const gfx::Rect& keyboard_bounds) { 1366 const gfx::Rect& keyboard_bounds) {
1362 // This bounds change will have caused a change to the Shelf which does not 1367 // This bounds change will have caused a change to the Shelf which does not
1363 // propagate automatically to this class, so manually recalculate bounds. 1368 // propagate automatically to this class, so manually recalculate bounds.
1364 Relayout(); 1369 Relayout();
1365 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING); 1370 UpdateDockBounds(DockedWindowLayoutManagerObserver::KEYBOARD_BOUNDS_CHANGING);
1366 } 1371 }
1367 1372
1368 } // namespace ash 1373 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/dock/docked_window_layout_manager.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698