| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/wm_shelf.h" | 5 #include "ash/common/shelf/wm_shelf.h" |
| 6 | 6 #include "ash/common/shelf/wm_shelf_observer.h" |
| 7 #include "ash/common/wm_lookup.h" |
| 8 #include "ash/shelf/shelf.h" |
| 9 #include "ash/shelf/shelf_layout_manager.h" |
| 7 #include "base/logging.h" | 10 #include "base/logging.h" |
| 8 | 11 |
| 9 namespace ash { | 12 namespace ash { |
| 10 | 13 |
| 14 void WmShelf::SetShelf(Shelf* shelf) { |
| 15 DCHECK(!shelf_); |
| 16 DCHECK(shelf); |
| 17 shelf_ = shelf; |
| 18 } |
| 19 |
| 20 void WmShelf::ClearShelf() { |
| 21 DCHECK(shelf_); |
| 22 shelf_ = nullptr; |
| 23 } |
| 24 |
| 25 void WmShelf::SetShelfLayoutManager(ShelfLayoutManager* manager) { |
| 26 DCHECK(!shelf_layout_manager_); |
| 27 DCHECK(manager); |
| 28 shelf_layout_manager_ = manager; |
| 29 shelf_layout_manager_->AddObserver(this); |
| 30 } |
| 31 |
| 32 WmWindow* WmShelf::GetWindow() { |
| 33 // Use |shelf_layout_manager_| to access ShelfWidget because it is set before |
| 34 // before the Shelf instance is available. |
| 35 return WmLookup::Get()->GetWindowForWidget( |
| 36 shelf_layout_manager_->shelf_widget()); |
| 37 } |
| 38 |
| 39 ShelfAlignment WmShelf::GetAlignment() const { |
| 40 return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; |
| 41 } |
| 42 |
| 43 void WmShelf::SetAlignment(ShelfAlignment alignment) { |
| 44 shelf_->SetAlignment(alignment); |
| 45 } |
| 46 |
| 11 bool WmShelf::IsHorizontalAlignment() const { | 47 bool WmShelf::IsHorizontalAlignment() const { |
| 12 switch (GetAlignment()) { | 48 switch (GetAlignment()) { |
| 13 case SHELF_ALIGNMENT_BOTTOM: | 49 case SHELF_ALIGNMENT_BOTTOM: |
| 14 case SHELF_ALIGNMENT_BOTTOM_LOCKED: | 50 case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| 15 return true; | 51 return true; |
| 16 case SHELF_ALIGNMENT_LEFT: | 52 case SHELF_ALIGNMENT_LEFT: |
| 17 case SHELF_ALIGNMENT_RIGHT: | 53 case SHELF_ALIGNMENT_RIGHT: |
| 18 return false; | 54 return false; |
| 19 } | 55 } |
| 20 NOTREACHED(); | 56 NOTREACHED(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 34 return right; | 70 return right; |
| 35 } | 71 } |
| 36 NOTREACHED(); | 72 NOTREACHED(); |
| 37 return bottom; | 73 return bottom; |
| 38 } | 74 } |
| 39 | 75 |
| 40 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { | 76 int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { |
| 41 return IsHorizontalAlignment() ? horizontal : vertical; | 77 return IsHorizontalAlignment() ? horizontal : vertical; |
| 42 } | 78 } |
| 43 | 79 |
| 80 ShelfAutoHideBehavior WmShelf::GetAutoHideBehavior() const { |
| 81 return shelf_->auto_hide_behavior(); |
| 82 } |
| 83 |
| 84 void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| 85 shelf_->SetAutoHideBehavior(behavior); |
| 86 } |
| 87 |
| 88 ShelfAutoHideState WmShelf::GetAutoHideState() const { |
| 89 return shelf_layout_manager_->auto_hide_state(); |
| 90 } |
| 91 |
| 92 void WmShelf::UpdateAutoHideState() { |
| 93 shelf_layout_manager_->UpdateAutoHideState(); |
| 94 } |
| 95 |
| 96 ShelfBackgroundType WmShelf::GetBackgroundType() const { |
| 97 return shelf_layout_manager_->shelf_widget()->GetBackgroundType(); |
| 98 } |
| 99 |
| 100 WmDimmerView* WmShelf::CreateDimmerView(bool disable_animations_for_test) { |
| 101 return nullptr; |
| 102 } |
| 103 |
| 104 bool WmShelf::IsDimmed() const { |
| 105 return shelf_layout_manager_->shelf_widget()->GetDimsShelf(); |
| 106 } |
| 107 |
| 108 void WmShelf::SchedulePaint() { |
| 109 // Can be called during shutdown if the overflow bubble is visible. |
| 110 if (shelf_) |
| 111 shelf_->SchedulePaint(); |
| 112 } |
| 113 |
| 114 bool WmShelf::IsVisible() const { |
| 115 return shelf_->IsVisible(); |
| 116 } |
| 117 |
| 118 void WmShelf::UpdateVisibilityState() { |
| 119 if (shelf_layout_manager_) |
| 120 shelf_layout_manager_->UpdateVisibilityState(); |
| 121 } |
| 122 |
| 123 ShelfVisibilityState WmShelf::GetVisibilityState() const { |
| 124 return shelf_layout_manager_ ? shelf_layout_manager_->visibility_state() |
| 125 : SHELF_HIDDEN; |
| 126 } |
| 127 |
| 128 gfx::Rect WmShelf::GetIdealBounds() { |
| 129 return shelf_layout_manager_->GetIdealBounds(); |
| 130 } |
| 131 |
| 132 gfx::Rect WmShelf::GetUserWorkAreaBounds() const { |
| 133 return shelf_layout_manager_ ? shelf_layout_manager_->user_work_area_bounds() |
| 134 : gfx::Rect(); |
| 135 } |
| 136 |
| 137 void WmShelf::UpdateIconPositionForWindow(WmWindow* window) { |
| 138 shelf_->UpdateIconPositionForWindow(window); |
| 139 } |
| 140 |
| 141 gfx::Rect WmShelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) { |
| 142 return shelf_->GetScreenBoundsOfItemIconForWindow(window); |
| 143 } |
| 144 |
| 145 bool WmShelf::ProcessGestureEvent(const ui::GestureEvent& event) { |
| 146 // Can be called at login screen. |
| 147 if (!shelf_layout_manager_) |
| 148 return false; |
| 149 return shelf_layout_manager_->ProcessGestureEvent(event); |
| 150 } |
| 151 |
| 152 void WmShelf::AddObserver(WmShelfObserver* observer) { |
| 153 observers_.AddObserver(observer); |
| 154 } |
| 155 |
| 156 void WmShelf::RemoveObserver(WmShelfObserver* observer) { |
| 157 observers_.RemoveObserver(observer); |
| 158 } |
| 159 |
| 160 void WmShelf::NotifyShelfIconPositionsChanged() { |
| 161 FOR_EACH_OBSERVER(WmShelfObserver, observers_, OnShelfIconPositionsChanged()); |
| 162 } |
| 163 |
| 164 void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { |
| 165 shelf_layout_manager_->OnKeyboardBoundsChanging(bounds); |
| 166 } |
| 167 |
| 168 ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { |
| 169 return shelf_->shelf_locking_manager_for_testing(); |
| 170 } |
| 171 |
| 172 ShelfView* WmShelf::GetShelfViewForTesting() { |
| 173 return shelf_->shelf_view_for_testing(); |
| 174 } |
| 175 |
| 176 WmShelf::WmShelf() {} |
| 177 |
| 178 WmShelf::~WmShelf() {} |
| 179 |
| 180 void WmShelf::WillDeleteShelfLayoutManager() { |
| 181 DCHECK(shelf_layout_manager_); |
| 182 shelf_layout_manager_->RemoveObserver(this); |
| 183 shelf_layout_manager_ = nullptr; |
| 184 } |
| 185 |
| 186 void WmShelf::WillChangeVisibilityState(ShelfVisibilityState new_state) { |
| 187 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 188 WillChangeVisibilityState(new_state)); |
| 189 } |
| 190 |
| 191 void WmShelf::OnAutoHideStateChanged(ShelfAutoHideState new_state) { |
| 192 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 193 OnAutoHideStateChanged(new_state)); |
| 194 } |
| 195 |
| 196 void WmShelf::OnBackgroundUpdated(ShelfBackgroundType background_type, |
| 197 BackgroundAnimatorChangeType change_type) { |
| 198 if (background_type == GetBackgroundType()) |
| 199 return; |
| 200 FOR_EACH_OBSERVER(WmShelfObserver, observers_, |
| 201 OnBackgroundTypeChanged(background_type, change_type)); |
| 202 } |
| 203 |
| 44 } // namespace ash | 204 } // namespace ash |
| OLD | NEW |