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

Side by Side Diff: ash/common/shelf/shelf_layout_manager.cc

Issue 2414303002: Remove usage of FOR_EACH_OBSERVER macro in ash/common (Closed)
Patch Set: Created 4 years, 2 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/common/shelf/shelf_button.cc ('k') | ash/common/shelf/shelf_model.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 (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/common/shelf/shelf_layout_manager.h" 5 #include "ash/common/shelf/shelf_layout_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 WmShell::Get()->AddShellObserver(this); 124 WmShell::Get()->AddShellObserver(this);
125 WmShell::Get()->AddLockStateObserver(this); 125 WmShell::Get()->AddLockStateObserver(this);
126 WmShell::Get()->AddActivationObserver(this); 126 WmShell::Get()->AddActivationObserver(this);
127 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this); 127 WmShell::Get()->GetSessionStateDelegate()->AddSessionStateObserver(this);
128 } 128 }
129 129
130 ShelfLayoutManager::~ShelfLayoutManager() { 130 ShelfLayoutManager::~ShelfLayoutManager() {
131 if (update_shelf_observer_) 131 if (update_shelf_observer_)
132 update_shelf_observer_->Detach(); 132 update_shelf_observer_->Detach();
133 133
134 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 134 for (auto& observer : observers_)
135 WillDeleteShelfLayoutManager()); 135 observer.WillDeleteShelfLayoutManager();
136 WmShell::Get()->RemoveShellObserver(this); 136 WmShell::Get()->RemoveShellObserver(this);
137 WmShell::Get()->RemoveLockStateObserver(this); 137 WmShell::Get()->RemoveLockStateObserver(this);
138 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this); 138 WmShell::Get()->GetSessionStateDelegate()->RemoveSessionStateObserver(this);
139 } 139 }
140 140
141 void ShelfLayoutManager::PrepareForShutdown() { 141 void ShelfLayoutManager::PrepareForShutdown() {
142 in_shutdown_ = true; 142 in_shutdown_ = true;
143 // Stop observing changes to avoid updating a partially destructed shelf. 143 // Stop observing changes to avoid updating a partially destructed shelf.
144 WmShell::Get()->RemoveActivationObserver(this); 144 WmShell::Get()->RemoveActivationObserver(this);
145 } 145 }
(...skipping 23 matching lines...) Expand all
169 CalculateTargetBounds(state_, &target_bounds); 169 CalculateTargetBounds(state_, &target_bounds);
170 return target_bounds.shelf_bounds_in_root.size(); 170 return target_bounds.shelf_bounds_in_root.size();
171 } 171 }
172 172
173 void ShelfLayoutManager::LayoutShelfAndUpdateBounds(bool change_work_area) { 173 void ShelfLayoutManager::LayoutShelfAndUpdateBounds(bool change_work_area) {
174 TargetBounds target_bounds; 174 TargetBounds target_bounds;
175 CalculateTargetBounds(state_, &target_bounds); 175 CalculateTargetBounds(state_, &target_bounds);
176 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, NULL); 176 UpdateBoundsAndOpacity(target_bounds, false, change_work_area, NULL);
177 177
178 // Update insets in ShelfWindowTargeter when shelf bounds change. 178 // Update insets in ShelfWindowTargeter when shelf bounds change.
179 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 179 for (auto& observer : observers_)
180 WillChangeVisibilityState(visibility_state())); 180 observer.WillChangeVisibilityState(visibility_state());
181 } 181 }
182 182
183 void ShelfLayoutManager::LayoutShelf() { 183 void ShelfLayoutManager::LayoutShelf() {
184 LayoutShelfAndUpdateBounds(true); 184 LayoutShelfAndUpdateBounds(true);
185 } 185 }
186 186
187 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() { 187 ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() {
188 switch (wm_shelf_->auto_hide_behavior()) { 188 switch (wm_shelf_->auto_hide_behavior()) {
189 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS: 189 case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
190 return SHELF_AUTO_HIDE; 190 return SHELF_AUTO_HIDE;
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 454
455 // Force an update because gesture drags affect the shelf bounds and we 455 // Force an update because gesture drags affect the shelf bounds and we
456 // should animate back to the normal bounds at the end of a gesture. 456 // should animate back to the normal bounds at the end of a gesture.
457 bool force_update = 457 bool force_update =
458 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS || 458 (gesture_drag_status_ == GESTURE_DRAG_CANCEL_IN_PROGRESS ||
459 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS); 459 gesture_drag_status_ == GESTURE_DRAG_COMPLETE_IN_PROGRESS);
460 460
461 if (!force_update && state_.Equals(state)) 461 if (!force_update && state_.Equals(state))
462 return; // Nothing changed. 462 return; // Nothing changed.
463 463
464 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 464 for (auto& observer : observers_)
465 WillChangeVisibilityState(visibility_state)); 465 observer.WillChangeVisibilityState(visibility_state);
466 466
467 StopAutoHideTimer(); 467 StopAutoHideTimer();
468 468
469 State old_state = state_; 469 State old_state = state_;
470 state_ = state; 470 state_ = state;
471 471
472 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE; 472 BackgroundAnimatorChangeType change_type = BACKGROUND_CHANGE_ANIMATE;
473 bool delay_background_change = false; 473 bool delay_background_change = false;
474 474
475 // Do not animate the background when: 475 // Do not animate the background when:
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 UpdateBoundsAndOpacity( 509 UpdateBoundsAndOpacity(
510 target_bounds, true /* animate */, true /* change_work_area */, 510 target_bounds, true /* animate */, true /* change_work_area */,
511 delay_background_change ? update_shelf_observer_ : NULL); 511 delay_background_change ? update_shelf_observer_ : NULL);
512 512
513 // OnAutoHideStateChanged Should be emitted when: 513 // OnAutoHideStateChanged Should be emitted when:
514 // - firstly state changed to auto-hide from other state 514 // - firstly state changed to auto-hide from other state
515 // - or, auto_hide_state has changed 515 // - or, auto_hide_state has changed
516 if ((old_state.visibility_state != state_.visibility_state && 516 if ((old_state.visibility_state != state_.visibility_state &&
517 state_.visibility_state == SHELF_AUTO_HIDE) || 517 state_.visibility_state == SHELF_AUTO_HIDE) ||
518 old_state.auto_hide_state != state_.auto_hide_state) { 518 old_state.auto_hide_state != state_.auto_hide_state) {
519 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 519 for (auto& observer : observers_)
520 OnAutoHideStateChanged(state_.auto_hide_state)); 520 observer.OnAutoHideStateChanged(state_.auto_hide_state);
521 } 521 }
522 } 522 }
523 523
524 void ShelfLayoutManager::UpdateBoundsAndOpacity( 524 void ShelfLayoutManager::UpdateBoundsAndOpacity(
525 const TargetBounds& target_bounds, 525 const TargetBounds& target_bounds,
526 bool animate, 526 bool animate,
527 bool change_work_area, 527 bool change_work_area,
528 ui::ImplicitAnimationObserver* observer) { 528 ui::ImplicitAnimationObserver* observer) {
529 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true); 529 base::AutoReset<bool> auto_reset_updating_bounds(&updating_bounds_, true);
530 { 530 {
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 target_bounds->status_bounds_in_shelf.set_x( 783 target_bounds->status_bounds_in_shelf.set_x(
784 target_bounds->shelf_bounds_in_root.width() - 784 target_bounds->shelf_bounds_in_root.width() -
785 GetShelfConstant(SHELF_SIZE)); 785 GetShelfConstant(SHELF_SIZE));
786 } 786 }
787 } 787 }
788 } 788 }
789 789
790 void ShelfLayoutManager::UpdateShelfBackground( 790 void ShelfLayoutManager::UpdateShelfBackground(
791 BackgroundAnimatorChangeType type) { 791 BackgroundAnimatorChangeType type) {
792 const ShelfBackgroundType background_type(GetShelfBackgroundType()); 792 const ShelfBackgroundType background_type(GetShelfBackgroundType());
793 FOR_EACH_OBSERVER(ShelfLayoutManagerObserver, observers_, 793 for (auto& observer : observers_)
794 OnBackgroundUpdated(background_type, type)); 794 observer.OnBackgroundUpdated(background_type, type);
795 } 795 }
796 796
797 void ShelfLayoutManager::UpdateAutoHideStateNow() { 797 void ShelfLayoutManager::UpdateAutoHideStateNow() {
798 SetState(state_.visibility_state); 798 SetState(state_.visibility_state);
799 799
800 // If the state did not change, the auto hide timer may still be running. 800 // If the state did not change, the auto hide timer may still be running.
801 StopAutoHideTimer(); 801 StopAutoHideTimer();
802 } 802 }
803 803
804 void ShelfLayoutManager::StopAutoHideTimer() { 804 void ShelfLayoutManager::StopAutoHideTimer() {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
1102 gesture_drag_status_ = GESTURE_DRAG_NONE; 1102 gesture_drag_status_ = GESTURE_DRAG_NONE;
1103 } 1103 }
1104 1104
1105 void ShelfLayoutManager::CancelGestureDrag() { 1105 void ShelfLayoutManager::CancelGestureDrag() {
1106 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS; 1106 gesture_drag_status_ = GESTURE_DRAG_CANCEL_IN_PROGRESS;
1107 UpdateVisibilityState(); 1107 UpdateVisibilityState();
1108 gesture_drag_status_ = GESTURE_DRAG_NONE; 1108 gesture_drag_status_ = GESTURE_DRAG_NONE;
1109 } 1109 }
1110 1110
1111 } // namespace ash 1111 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/shelf/shelf_button.cc ('k') | ash/common/shelf/shelf_model.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698