Chromium Code Reviews| Index: ash/common/shelf/wm_shelf.cc |
| diff --git a/ash/common/shelf/wm_shelf.cc b/ash/common/shelf/wm_shelf.cc |
| index 5406d0704e10500eb78c906c539532690d311a99..e72b5644d8bdabb1db5663a5ab951eb047ca1af7 100644 |
| --- a/ash/common/shelf/wm_shelf.cc |
| +++ b/ash/common/shelf/wm_shelf.cc |
| @@ -3,10 +3,15 @@ |
| // found in the LICENSE file. |
| #include "ash/common/shelf/shelf.h" |
| +#include "ash/common/shelf/shelf_delegate.h" |
| #include "ash/common/shelf/shelf_layout_manager.h" |
| +#include "ash/common/shelf/shelf_locking_manager.h" |
| +#include "ash/common/shelf/shelf_widget.h" |
| #include "ash/common/shelf/wm_shelf.h" |
| #include "ash/common/shelf/wm_shelf_observer.h" |
| #include "ash/common/wm_lookup.h" |
| +#include "ash/common/wm_shell.h" |
| +#include "ash/common/wm_window.h" |
| #include "base/logging.h" |
| namespace ash { |
| @@ -15,10 +20,15 @@ void WmShelf::SetShelf(Shelf* shelf) { |
| DCHECK(!shelf_); |
| DCHECK(shelf); |
| shelf_ = shelf; |
| + shelf_locking_manager_.reset(new ShelfLockingManager(this)); |
|
msw
2016/08/24 00:18:59
Should this DCHECK that the ShelfLayoutManager is
James Cook
2016/08/24 04:19:08
Good idea. Done.
|
| + // When the shelf is created the alignment is unlocked. Chrome will update the |
| + // alignment later from preferences. |
| + alignment_ = SHELF_ALIGNMENT_BOTTOM; |
| } |
| void WmShelf::ClearShelf() { |
| DCHECK(shelf_); |
| + shelf_locking_manager_.reset(); |
| shelf_ = nullptr; |
| } |
| @@ -36,16 +46,26 @@ WmWindow* WmShelf::GetWindow() { |
| shelf_layout_manager_->shelf_widget()); |
| } |
| -ShelfAlignment WmShelf::GetAlignment() const { |
| - return shelf_ ? shelf_->alignment() : SHELF_ALIGNMENT_BOTTOM_LOCKED; |
| -} |
| - |
| void WmShelf::SetAlignment(ShelfAlignment alignment) { |
| - shelf_->SetAlignment(alignment); |
| + if (alignment_ == alignment) |
| + return; |
| + |
| + if (shelf_locking_manager_->is_locked() && |
| + alignment != SHELF_ALIGNMENT_BOTTOM_LOCKED) { |
| + shelf_locking_manager_->set_stored_alignment(alignment); |
| + return; |
| + } |
| + |
| + alignment_ = alignment; |
| + // The ShelfWidget notifies the ShelfView of the alignment change. |
| + shelf_layout_manager_->shelf_widget()->OnShelfAlignmentChanged(); |
| + WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(shelf_); |
| + WmShell::Get()->NotifyShelfAlignmentChanged(GetWindow()->GetRootWindow()); |
| + // ShelfLayoutManager will resize the shelf. |
| } |
| bool WmShelf::IsHorizontalAlignment() const { |
| - switch (GetAlignment()) { |
| + switch (alignment_) { |
| case SHELF_ALIGNMENT_BOTTOM: |
| case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| return true; |
| @@ -60,7 +80,7 @@ bool WmShelf::IsHorizontalAlignment() const { |
| int WmShelf::SelectValueForShelfAlignment(int bottom, |
| int left, |
| int right) const { |
| - switch (GetAlignment()) { |
| + switch (alignment_) { |
| case SHELF_ALIGNMENT_BOTTOM: |
| case SHELF_ALIGNMENT_BOTTOM_LOCKED: |
| return bottom; |
| @@ -77,12 +97,14 @@ int WmShelf::PrimaryAxisValue(int horizontal, int vertical) const { |
| return IsHorizontalAlignment() ? horizontal : vertical; |
| } |
| -ShelfAutoHideBehavior WmShelf::GetAutoHideBehavior() const { |
| - return shelf_->auto_hide_behavior(); |
| -} |
| +void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) { |
| + if (auto_hide_behavior_ == auto_hide_behavior) |
| + return; |
| -void WmShelf::SetAutoHideBehavior(ShelfAutoHideBehavior behavior) { |
| - shelf_->SetAutoHideBehavior(behavior); |
| + auto_hide_behavior_ = auto_hide_behavior; |
| + WmShell::Get()->shelf_delegate()->OnShelfAutoHideBehaviorChanged(shelf_); |
| + WmShell::Get()->NotifyShelfAutoHideBehaviorChanged( |
| + GetWindow()->GetRootWindow()); |
| } |
| ShelfAutoHideState WmShelf::GetAutoHideState() const { |
| @@ -164,13 +186,17 @@ void WmShelf::SetVirtualKeyboardBoundsForTesting(const gfx::Rect& bounds) { |
| } |
| ShelfLockingManager* WmShelf::GetShelfLockingManagerForTesting() { |
| - return shelf_->shelf_locking_manager_for_testing(); |
| + return shelf_locking_manager_.get(); |
| } |
| ShelfView* WmShelf::GetShelfViewForTesting() { |
| return shelf_->shelf_view_for_testing(); |
| } |
| +ShelfWidget* WmShelf::GetShelfWidgetForTesting() { |
| + return shelf_layout_manager_->shelf_widget(); |
| +} |
| + |
| WmShelf::WmShelf() {} |
| WmShelf::~WmShelf() {} |