Skip to content

Commit

Permalink
ash: Move alignment and autohide behavior from Shelf to WmShelf
Browse files Browse the repository at this point in the history
This is a step toward replacing Shelf with WmShelf, which has a more sensible
lifetime. It does not change shelf behavior.

* Migrate the various getters and setters.
* Before the shelf is constructed (after login) default the alignment to
bottom-locked. After construction default to bottom. This is weird, but matches
what we had before.
* Add Shelf::wm_shelf() and use it in pieces of code that we know we'll have to
refactor anyway (chrome, some ash/wm pieces we're not converting).
* Move ShelfView::OnShelfAlignmentChanged() call into ShelfWidget. In general
I'm trying to reduce outside access into ShelfView.
* Convert Shelf* to WmShelf* where possible in tests.
* Make AshTestBase::GetPrimaryShelf() public so it can be used in test utility
functions outside of test classes.

BUG=615502
TEST=ash_unittests, chrome unit_tests
TBR=derat@chromium.org

Review-Url: https://codereview.chromium.org/2272793005
Cr-Commit-Position: refs/heads/master@{#413987}
  • Loading branch information
jamescook authored and Commit bot committed Aug 24, 2016
1 parent 8a0c47c commit a18fb17
Show file tree
Hide file tree
Showing 34 changed files with 271 additions and 289 deletions.
6 changes: 4 additions & 2 deletions ash/app_list/app_list_presenter_delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const int kMinimalAnchorPositionOffset = 57;
// Gets arrow location based on shelf alignment.
views::BubbleBorder::Arrow GetBubbleArrow(aura::Window* window) {
DCHECK(Shell::HasInstance());
switch (Shelf::ForWindow(WmWindowAura::Get(window))->alignment()) {
WmShelf* shelf = Shelf::ForWindow(WmWindowAura::Get(window))->wm_shelf();
switch (shelf->alignment()) {
case SHELF_ALIGNMENT_BOTTOM:
case SHELF_ALIGNMENT_BOTTOM_LOCKED:
return views::BubbleBorder::BOTTOM_CENTER;
Expand All @@ -64,6 +65,7 @@ gfx::Vector2d GetAnchorPositionOffsetToShelf(const gfx::Rect& button_bounds,
DCHECK(Shell::HasInstance());
ShelfAlignment shelf_alignment =
Shelf::ForWindow(WmLookup::Get()->GetWindowForWidget(widget))
->wm_shelf()
->alignment();
gfx::Point anchor(button_bounds.CenterPoint());
switch (shelf_alignment) {
Expand Down Expand Up @@ -259,7 +261,7 @@ gfx::Vector2d AppListPresenterDelegate::GetVisibilityAnimationOffset(
Shelf* shelf = Shelf::ForWindow(WmWindowAura::Get(root_window));
shelf->shelf_layout_manager()->UpdateAutoHideState();

switch (shelf->alignment()) {
switch (shelf->wm_shelf()->alignment()) {
case SHELF_ALIGNMENT_BOTTOM:
case SHELF_ALIGNMENT_BOTTOM_LOCKED:
return gfx::Vector2d(0, kAnimationOffset);
Expand Down
56 changes: 3 additions & 53 deletions ash/common/shelf/shelf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,19 @@

#include "ash/common/shelf/shelf.h"

#include <algorithm>
#include <cmath>

#include "ash/common/shelf/shelf_delegate.h"
#include "ash/common/shelf/shelf_item_delegate.h"
#include "ash/common/shelf/shelf_layout_manager.h"
#include "ash/common/shelf/shelf_model.h"
#include "ash/common/shelf/shelf_navigator.h"
#include "ash/common/shelf/shelf_view.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shell_window_ids.h"
#include "ash/common/wm_lookup.h"
#include "ash/common/wm_root_window_controller.h"
#include "ash/common/wm_shell.h"
#include "ash/common/wm_window.h"
#include "ash/common/wm_window_property.h"
#include "ui/compositor/layer.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/image/image_skia_operations.h"
#include "ui/gfx/skbitmap_operations.h"
#include "ui/views/accessible_pane_view.h"
#include "ui/views/widget/widget.h"
#include "ui/views/widget/widget_delegate.h"
#include "ui/wm/public/activation_client.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"

namespace ash {

Expand All @@ -37,8 +25,7 @@ Shelf::Shelf(WmShelf* wm_shelf,
ShelfWidget* shelf_widget)
: wm_shelf_(wm_shelf),
shelf_widget_(shelf_widget),
shelf_view_(shelf_view),
shelf_locking_manager_(wm_shelf) {
shelf_view_(shelf_view) {
DCHECK(wm_shelf_);
DCHECK(shelf_view_);
DCHECK(shelf_widget_);
Expand All @@ -58,43 +45,6 @@ Shelf* Shelf::ForWindow(WmWindow* window) {
return window->GetRootWindowController()->GetShelf()->shelf();
}

void Shelf::SetAlignment(ShelfAlignment 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;
shelf_view_->OnShelfAlignmentChanged();
shelf_widget_->OnShelfAlignmentChanged();
WmShell::Get()->shelf_delegate()->OnShelfAlignmentChanged(this);
WmShell::Get()->NotifyShelfAlignmentChanged(
WmLookup::Get()->GetWindowForWidget(shelf_widget_)->GetRootWindow());
// ShelfLayoutManager will resize the shelf.
}

void Shelf::SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior) {
if (auto_hide_behavior_ == auto_hide_behavior)
return;

auto_hide_behavior_ = auto_hide_behavior;
WmShell::Get()->shelf_delegate()->OnShelfAutoHideBehaviorChanged(this);
WmShell::Get()->NotifyShelfAutoHideBehaviorChanged(
WmLookup::Get()->GetWindowForWidget(shelf_widget_)->GetRootWindow());
}

ShelfAutoHideState Shelf::GetAutoHideState() const {
return shelf_widget_->shelf_layout_manager()->auto_hide_state();
}

ShelfVisibilityState Shelf::GetVisibilityState() const {
return shelf_widget_->shelf_layout_manager()->visibility_state();
}

gfx::Rect Shelf::GetScreenBoundsOfItemIconForWindow(WmWindow* window) {
ShelfID id = window->GetIntProperty(WmWindowProperty::SHELF_ID);
gfx::Rect bounds(shelf_view_->GetIdealBoundsOfItemIcon(id));
Expand Down
38 changes: 3 additions & 35 deletions ash/common/shelf/shelf.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,11 @@
#ifndef ASH_COMMON_SHELF_SHELF_H_
#define ASH_COMMON_SHELF_SHELF_H_

#include <stdint.h>

#include <memory>

#include "ash/ash_export.h"
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/shelf_locking_manager.h"
#include "ash/common/shelf/shelf_types.h"
#include "ash/common/shelf/shelf_widget.h"
#include "base/macros.h"
#include "ui/gfx/geometry/size.h"
#include "ui/views/widget/widget_observer.h"

namespace app_list {
class ApplicationDragAndDropHost;
Expand All @@ -26,14 +19,8 @@ namespace gfx {
class Rect;
}

namespace views {
class View;
}

namespace ash {
class AppListButton;
class FocusCycler;
class ShelfDelegate;
class ShelfView;
class WmShelf;

Expand All @@ -59,20 +46,9 @@ class ASH_EXPORT Shelf {
// user is logged in yet.
static Shelf* ForWindow(WmWindow* window);

// DEPRECATED. Use WmShelf::GetAlignment() and SetAlignment().
void SetAlignment(ShelfAlignment alignment);
ShelfAlignment alignment() const { return alignment_; }

// Sets the ShelfAutoHideBehavior. See enum description for details.
// DEPRECATED. Use WmShelf::GetAutoHideBehavior() and SetAutoHideBehavior().
void SetAutoHideBehavior(ShelfAutoHideBehavior auto_hide_behavior);
ShelfAutoHideBehavior auto_hide_behavior() const {
return auto_hide_behavior_;
}

ShelfAutoHideState GetAutoHideState() const;

ShelfVisibilityState GetVisibilityState() const;
// For porting from Shelf to WmShelf.
// TODO(jamescook): Remove this.
WmShelf* wm_shelf() { return wm_shelf_; }

// Returns the screen bounds of the item for the specified window. If there is
// no item for the specified window an empty rect is returned.
Expand Down Expand Up @@ -112,10 +88,6 @@ class ASH_EXPORT Shelf {
// Updates the background for the shelf items.
void UpdateShelfItemBackground(int alpha);

ShelfLockingManager* shelf_locking_manager_for_testing() {
return &shelf_locking_manager_;
}

ShelfView* shelf_view_for_testing() { return shelf_view_; }

private:
Expand All @@ -125,10 +97,6 @@ class ASH_EXPORT Shelf {
WmShelf* wm_shelf_;
ShelfWidget* shelf_widget_;
ShelfView* shelf_view_;
ShelfLockingManager shelf_locking_manager_;

ShelfAlignment alignment_ = SHELF_ALIGNMENT_BOTTOM;
ShelfAutoHideBehavior auto_hide_behavior_ = SHELF_AUTO_HIDE_BEHAVIOR_NEVER;

DISALLOW_COPY_AND_ASSIGN(Shelf);
};
Expand Down
14 changes: 8 additions & 6 deletions ash/common/shelf/shelf_layout_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@

#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shelf/shelf.h"
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/shelf_delegate.h"
#include "ash/common/shelf/shelf_layout_manager_observer.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shelf/wm_shelf_util.h"
#include "ash/common/shell_window_ids.h"
#include "ash/common/system/status_area_widget.h"
Expand Down Expand Up @@ -144,9 +144,11 @@ class ShelfLayoutManager::RootWindowControllerObserverImpl

// ShelfLayoutManager ----------------------------------------------------------

ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget)
ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget,
WmShelf* wm_shelf)
: updating_bounds_(false),
shelf_widget_(shelf_widget),
wm_shelf_(wm_shelf),
window_overlaps_shelf_(false),
mouse_over_shelf_when_auto_hide_timer_started_(false),
gesture_drag_status_(GESTURE_DRAG_NONE),
Expand All @@ -158,6 +160,7 @@ ShelfLayoutManager::ShelfLayoutManager(ShelfWidget* shelf_widget)
root_window_controller_observer_(
new RootWindowControllerObserverImpl(this)) {
DCHECK(shelf_widget_);
DCHECK(wm_shelf_);
WmShell::Get()->AddShellObserver(this);
WmShell::Get()->AddLockStateObserver(this);
WmShell::Get()->AddActivationObserver(this);
Expand Down Expand Up @@ -222,7 +225,7 @@ void ShelfLayoutManager::LayoutShelf() {
}

ShelfVisibilityState ShelfLayoutManager::CalculateShelfVisibility() {
switch (shelf_widget_->shelf()->auto_hide_behavior()) {
switch (wm_shelf_->auto_hide_behavior()) {
case SHELF_AUTO_HIDE_BEHAVIOR_ALWAYS:
return SHELF_AUTO_HIDE;
case SHELF_AUTO_HIDE_BEHAVIOR_NEVER:
Expand Down Expand Up @@ -1162,9 +1165,8 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
// |gesture_drag_status_| to GESTURE_DRAG_COMPLETE_IN_PROGRESS to set the auto
// hide state to |gesture_drag_auto_hide_state_|.
gesture_drag_status_ = GESTURE_DRAG_COMPLETE_IN_PROGRESS;
Shelf* shelf = shelf_widget_->shelf();
if (shelf->auto_hide_behavior() != new_auto_hide_behavior)
shelf->SetAutoHideBehavior(new_auto_hide_behavior);
if (wm_shelf_->auto_hide_behavior() != new_auto_hide_behavior)
wm_shelf_->SetAutoHideBehavior(new_auto_hide_behavior);
else
UpdateVisibilityState();
gesture_drag_status_ = GESTURE_DRAG_NONE;
Expand Down
4 changes: 3 additions & 1 deletion ash/common/shelf/shelf_layout_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class PanelLayoutManagerTest;
class ShelfLayoutManagerObserver;
class ShelfLayoutManagerTest;
class ShelfWidget;
class WmShelf;

// ShelfLayoutManager is the layout manager responsible for the shelf and
// status widgets. The shelf is given the total available width and told the
Expand All @@ -53,7 +54,7 @@ class ASH_EXPORT ShelfLayoutManager
public wm::WmSnapToPixelLayoutManager,
public SessionStateObserver {
public:
explicit ShelfLayoutManager(ShelfWidget* shelf_widget);
ShelfLayoutManager(ShelfWidget* shelf_widget, WmShelf* wm_shelf);
~ShelfLayoutManager() override;

bool updating_bounds() const { return updating_bounds_; }
Expand Down Expand Up @@ -315,6 +316,7 @@ class ASH_EXPORT ShelfLayoutManager
State state_;

ShelfWidget* shelf_widget_;
WmShelf* wm_shelf_;

// Do any windows overlap the shelf? This is maintained by WorkspaceManager.
bool window_overlaps_shelf_;
Expand Down
3 changes: 2 additions & 1 deletion ash/common/shelf/shelf_widget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ ShelfWidget::ShelfWidget(WmWindow* shelf_container,
SetContentsView(delegate_view_);
delegate_view_->SetParentLayer(GetLayer());

shelf_layout_manager_ = new ShelfLayoutManager(this);
shelf_layout_manager_ = new ShelfLayoutManager(this, wm_shelf_);
shelf_layout_manager_->AddObserver(this);
shelf_container->SetLayoutManager(base::WrapUnique(shelf_layout_manager_));
background_animator_.PaintBackground(
Expand Down Expand Up @@ -407,6 +407,7 @@ ShelfAlignment ShelfWidget::GetAlignment() const {
}

void ShelfWidget::OnShelfAlignmentChanged() {
shelf_view_->OnShelfAlignmentChanged();
status_area_widget_->SetShelfAlignment(GetAlignment());
delegate_view_->SchedulePaint();
}
Expand Down
Loading

0 comments on commit a18fb17

Please sign in to comment.