Commit 9eb0f911 authored by jamescook's avatar jamescook Committed by Commit bot

ash: Clean up shelf GetAlignment() and IsHorizontalAlignment() calls

This resolves some TODOs left over from shelf refactoring.

Eliminate various GetAlignment() utility functions and instead call into
WmShelf::GetAlignment() directory.

Prefer WmShelf::IsHorizontalAlignment() to the bare utility fuction.

Fix IWYU violations.

BUG=635963
TEST=ash_unittests
TBR=dmazzoni@chromium.org for IWYU in c/b/chromeos/accessibility

Review-Url: https://codereview.chromium.org/2676673005
Cr-Commit-Position: refs/heads/master@{#448035}
parent e8bd03d5
......@@ -7,6 +7,7 @@
#include "ash/common/ash_switches.h"
#include "ash/common/shelf/app_list_button.h"
#include "ash/common/shelf/shelf_layout_manager.h"
#include "ash/common/shelf/shelf_widget.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
#include "ash/common/wm/wm_screen_util.h"
......
......@@ -20,6 +20,7 @@ OverflowBubble::OverflowBubble(WmShelf* wm_shelf)
bubble_(nullptr),
overflow_button_(nullptr),
shelf_view_(nullptr) {
DCHECK(wm_shelf_);
WmShell::Get()->AddPointerWatcher(this,
views::PointerWatcherEventTypes::BASIC);
}
......
......@@ -9,7 +9,6 @@
#include "ash/common/material_design/material_design_controller.h"
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shelf/wm_shelf_util.h"
#include "ash/common/wm_lookup.h"
#include "ash/common/wm_window.h"
#include "ash/public/cpp/shell_window_ids.h"
......@@ -37,7 +36,9 @@ const int kShelfViewLeadingInset = 8;
} // namespace
OverflowBubbleView::OverflowBubbleView(WmShelf* wm_shelf)
: wm_shelf_(wm_shelf), shelf_view_(nullptr) {}
: wm_shelf_(wm_shelf), shelf_view_(nullptr) {
DCHECK(wm_shelf_);
}
OverflowBubbleView::~OverflowBubbleView() {}
......@@ -69,10 +70,6 @@ void OverflowBubbleView::InitOverflowBubble(views::View* anchor,
AddChildView(shelf_view_);
}
bool OverflowBubbleView::IsHorizontalAlignment() const {
return ::ash::IsHorizontalAlignment(wm_shelf_->GetAlignment());
}
const gfx::Size OverflowBubbleView::GetContentsSize() const {
return shelf_view_->GetPreferredSize();
}
......@@ -120,7 +117,7 @@ gfx::Size OverflowBubbleView::GetPreferredSize() const {
->GetDisplayNearestPoint(GetAnchorRect().CenterPoint())
.work_area();
if (!monitor_rect.IsEmpty()) {
if (IsHorizontalAlignment()) {
if (wm_shelf_->IsHorizontalAlignment()) {
preferred_size.set_width(
std::min(preferred_size.width(),
static_cast<int>(monitor_rect.width() *
......@@ -147,7 +144,7 @@ void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) {
SizeToContents();
// Ensures |shelf_view_| is still visible.
if (IsHorizontalAlignment())
if (wm_shelf_->IsHorizontalAlignment())
ScrollByXOffset(0);
else
ScrollByYOffset(0);
......@@ -159,7 +156,7 @@ bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) {
// recently, but the behavior of this function was retained to continue
// using Y offsets only. Might be good to simply scroll in both
// directions as in OverflowBubbleView::OnScrollEvent.
if (IsHorizontalAlignment())
if (wm_shelf_->IsHorizontalAlignment())
ScrollByXOffset(-event.y_offset());
else
ScrollByYOffset(-event.y_offset());
......
......@@ -40,8 +40,6 @@ class ASH_EXPORT OverflowBubbleView : public views::BubbleDialogDelegateView {
private:
friend class test::OverflowBubbleViewTestAPI;
bool IsHorizontalAlignment() const;
const gfx::Size GetContentsSize() const;
// Gets arrow location based on shelf alignment.
......
......@@ -12,7 +12,6 @@
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/shelf_view.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shelf/wm_shelf_util.h"
#include "base/memory/ptr_util.h"
#include "base/time/time.h"
#include "grit/ash_resources.h"
......@@ -208,7 +207,7 @@ class ShelfButton::BarView : public views::ImageView,
animating_ ? ShelfButtonAnimation::GetInstance()->GetAnimation()
: 1.0;
double scale = .35 + .65 * animation;
if (IsHorizontalAlignment(wm_shelf_->GetAlignment())) {
if (wm_shelf_->IsHorizontalAlignment()) {
int width = base_bounds_.width() * scale;
bounds.set_width(std::min(width, kIconSize));
int x_offset = (base_bounds_.width() - bounds.width()) / 2;
......@@ -403,8 +402,7 @@ void ShelfButton::GetAccessibleNodeData(ui::AXNodeData* node_data) {
void ShelfButton::Layout() {
const gfx::Rect button_bounds(GetContentsBounds());
WmShelf* wm_shelf = shelf_view_->wm_shelf();
const bool is_horizontal_shelf =
IsHorizontalAlignment(wm_shelf->GetAlignment());
const bool is_horizontal_shelf = wm_shelf->IsHorizontalAlignment();
const int icon_pad = ash::MaterialDesignController::IsShelfMaterial()
? (is_horizontal_shelf ? kIconPaddingHorizontalMD
: kIconPaddingVerticalMD)
......@@ -536,7 +534,7 @@ void ShelfButton::NotifyClick(const ui::Event& event) {
void ShelfButton::UpdateState() {
UpdateBar();
const bool is_horizontal_shelf =
IsHorizontalAlignment(shelf_view_->wm_shelf()->GetAlignment());
shelf_view_->wm_shelf()->IsHorizontalAlignment();
icon_view_->SetHorizontalAlignment(is_horizontal_shelf
? views::ImageView::CENTER
: views::ImageView::LEADING);
......@@ -576,7 +574,7 @@ void ShelfButton::UpdateBar() {
image = *rb->GetImageNamed(bar_id).ToImageSkia();
}
ShelfAlignment shelf_alignment = wm_shelf->GetAlignment();
if (!IsHorizontalAlignment(shelf_alignment)) {
if (!wm_shelf->IsHorizontalAlignment()) {
image = gfx::ImageSkiaOperations::CreateRotatedImage(
image, shelf_alignment == SHELF_ALIGNMENT_LEFT
? SkBitmapOperations::ROTATION_90_CW
......
......@@ -13,8 +13,8 @@
#include "ash/common/session/session_state_delegate.h"
#include "ash/common/shelf/shelf_constants.h"
#include "ash/common/shelf/shelf_layout_manager_observer.h"
#include "ash/common/shelf/shelf_widget.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shelf/wm_shelf_util.h"
#include "ash/common/system/status_area_widget.h"
#include "ash/common/wm/fullscreen_window_finder.h"
#include "ash/common/wm/mru_window_tracker.h"
......@@ -435,10 +435,6 @@ void ShelfLayoutManager::OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) {
void ShelfLayoutManager::OnKeyboardClosed() {}
bool ShelfLayoutManager::IsHorizontalAlignment() const {
return ::ash::IsHorizontalAlignment(GetAlignment());
}
ShelfBackgroundType ShelfLayoutManager::GetShelfBackgroundType() const {
if (state_.pre_lock_screen_animation_active)
return SHELF_BACKGROUND_DEFAULT;
......@@ -612,7 +608,7 @@ void ShelfLayoutManager::UpdateBoundsAndOpacity(
// For crbug.com/622431, when the shelf alignment is BOTTOM_LOCKED, we
// don't set display work area, as it is not real user-set alignment.
if (!state_.IsScreenLocked() &&
shelf_widget_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED &&
wm_shelf_->GetAlignment() != SHELF_ALIGNMENT_BOTTOM_LOCKED &&
change_work_area) {
gfx::Insets insets;
// If user session is blocked (login to new user session or add user to
......@@ -677,7 +673,7 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
gfx::Size status_size(
shelf_widget_->status_area_widget()->GetWindowBoundsInScreen().size());
if (IsHorizontalAlignment())
if (wm_shelf_->IsHorizontalAlignment())
status_size.set_height(GetShelfConstant(SHELF_SIZE));
else
status_size.set_width(GetShelfConstant(SHELF_SIZE));
......@@ -686,7 +682,7 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
gfx::Point(0, 0), gfx::Point(shelf_width - status_size.width(),
shelf_height - status_size.height()),
gfx::Point(0, shelf_height - status_size.height()));
if (IsHorizontalAlignment() && !base::i18n::IsRTL())
if (wm_shelf_->IsHorizontalAlignment() && !base::i18n::IsRTL())
status_origin.set_x(shelf_width - status_size.width());
target_bounds->status_bounds_in_shelf = gfx::Rect(status_origin, status_size);
......@@ -750,7 +746,7 @@ void ShelfLayoutManager::CalculateTargetBounds(const State& state,
void ShelfLayoutManager::UpdateTargetBoundsForGesture(
TargetBounds* target_bounds) const {
CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_);
bool horizontal = IsHorizontalAlignment();
bool horizontal = wm_shelf_->IsHorizontalAlignment();
WmWindow* window = WmLookup::Get()->GetWindowForWidget(shelf_widget_);
gfx::Rect available_bounds = wm::GetDisplayBoundsWithShelf(window);
int resistance_free_region = 0;
......@@ -787,7 +783,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
int shelf_height = target_bounds->shelf_bounds_in_root.height() - translate;
shelf_height = std::max(shelf_height, shelf_insets);
target_bounds->shelf_bounds_in_root.set_height(shelf_height);
if (IsHorizontalAlignment()) {
if (wm_shelf_->IsHorizontalAlignment()) {
target_bounds->shelf_bounds_in_root.set_y(available_bounds.bottom() -
shelf_height);
}
......@@ -796,7 +792,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture(
} else {
// Move and size the shelf with the gesture.
int shelf_width = target_bounds->shelf_bounds_in_root.width();
bool right_aligned = GetAlignment() == SHELF_ALIGNMENT_RIGHT;
bool right_aligned = wm_shelf_->GetAlignment() == SHELF_ALIGNMENT_RIGHT;
if (right_aligned)
shelf_width -= translate;
else
......@@ -851,7 +847,7 @@ gfx::Rect ShelfLayoutManager::GetAutoHideShowShelfRegionInScreen() const {
gfx::Rect show_shelf_region_in_screen = shelf_bounds_in_screen;
show_shelf_region_in_screen += offset;
if (IsHorizontalAlignment())
if (wm_shelf_->IsHorizontalAlignment())
show_shelf_region_in_screen.set_height(kMaxAutoHideShowShelfRegionSize);
else
show_shelf_region_in_screen.set_width(kMaxAutoHideShowShelfRegionSize);
......@@ -922,10 +918,10 @@ ShelfAutoHideState ShelfLayoutManager::CalculateAutoHideState(
IsVisible()) {
// Increase the the hit test area to prevent the shelf from disappearing
// when the mouse is over the bubble gap.
ShelfAlignment alignment = GetAlignment();
ShelfAlignment alignment = wm_shelf_->GetAlignment();
shelf_region.Inset(
alignment == SHELF_ALIGNMENT_RIGHT ? -kNotificationBubbleGapHeight : 0,
IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0,
wm_shelf_->IsHorizontalAlignment() ? -kNotificationBubbleGapHeight : 0,
alignment == SHELF_ALIGNMENT_LEFT ? -kNotificationBubbleGapHeight : 0,
0);
}
......@@ -1074,7 +1070,7 @@ void ShelfLayoutManager::UpdateGestureDrag(const ui::GestureEvent& gesture) {
}
void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
bool horizontal = IsHorizontalAlignment();
bool horizontal = wm_shelf_->IsHorizontalAlignment();
bool should_change = false;
if (gesture.type() == ui::ET_GESTURE_SCROLL_END) {
// The visibility of the shelf changes only if the shelf was dragged X%
......@@ -1088,7 +1084,7 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) {
should_change = drag_ratio > kDragHideThreshold;
} else {
bool correct_direction = false;
switch (GetAlignment()) {
switch (wm_shelf_->GetAlignment()) {
case SHELF_ALIGNMENT_BOTTOM:
case SHELF_ALIGNMENT_BOTTOM_LOCKED:
case SHELF_ALIGNMENT_RIGHT:
......
......@@ -9,7 +9,7 @@
#include "ash/ash_export.h"
#include "ash/common/session/session_state_observer.h"
#include "ash/common/shelf/shelf_widget.h"
#include "ash/common/shelf/wm_shelf.h"
#include "ash/common/shell_observer.h"
#include "ash/common/wm/background_animator.h"
#include "ash/common/wm/dock/docked_window_layout_manager_observer.h"
......@@ -27,6 +27,7 @@
namespace ui {
class ImplicitAnimationObserver;
class MouseEvent;
}
namespace ash {
......@@ -149,14 +150,11 @@ class ASH_EXPORT ShelfLayoutManager
// Overridden from SessionStateObserver:
void SessionStateChanged(session_manager::SessionState state) override;
// TODO(msw): Remove these accessors, kept temporarily to simplify changes.
ShelfAlignment GetAlignment() const { return shelf_widget_->GetAlignment(); }
// TODO(harrym|oshima): These templates will be moved to a new Shelf class.
// A helper function for choosing values specific to a shelf alignment.
template <typename T>
T SelectValueForShelfAlignment(T bottom, T left, T right) const {
switch (GetAlignment()) {
switch (wm_shelf_->GetAlignment()) {
case SHELF_ALIGNMENT_BOTTOM:
case SHELF_ALIGNMENT_BOTTOM_LOCKED:
return bottom;
......@@ -171,12 +169,9 @@ class ASH_EXPORT ShelfLayoutManager
template <typename T>
T PrimaryAxisValue(T horizontal, T vertical) const {
return IsHorizontalAlignment() ? horizontal : vertical;
return wm_shelf_->IsHorizontalAlignment() ? horizontal : vertical;
}
// Is the shelf's alignment horizontal?
bool IsHorizontalAlignment() const;
// Returns how the shelf background should be painted.
ShelfBackgroundType GetShelfBackgroundType() const;
......
......@@ -220,6 +220,7 @@ ShelfWidget::ShelfWidget(WmWindow* shelf_container, WmShelf* wm_shelf)
shelf_view_(nullptr),
background_animator_(SHELF_BACKGROUND_DEFAULT, wm_shelf_),
activating_as_fallback_(false) {
DCHECK(wm_shelf_);
background_animator_.AddObserver(this);
background_animator_.AddObserver(delegate_view_);
......@@ -304,13 +305,10 @@ bool ShelfWidget::IsShelfHiddenBehindBlackBar() const {
return delegate_view_->opaque_foreground()->GetTargetOpacity() != 0.0f;
}
ShelfAlignment ShelfWidget::GetAlignment() const {
return wm_shelf_->GetAlignment();
}
void ShelfWidget::OnShelfAlignmentChanged() {
shelf_view_->OnShelfAlignmentChanged();
status_area_widget_->SetShelfAlignment(GetAlignment());
// TODO(jamescook): Status area should not cache alignment.
status_area_widget_->SetShelfAlignment(wm_shelf_->GetAlignment());
delegate_view_->SchedulePaint();
}
......
......@@ -44,9 +44,6 @@ class ASH_EXPORT ShelfWidget : public views::Widget,
void OnShelfAlignmentChanged();
// DEPRECATED: Prefer WmShelf::GetAlignment().
ShelfAlignment GetAlignment() const;
// Sets the shelf's background type.
void SetPaintsBackground(ShelfBackgroundType background_type,
BackgroundAnimatorChangeType change_type);
......
......@@ -601,7 +601,7 @@ void PanelLayoutManager::Relayout() {
base::AutoReset<bool> auto_reset_in_layout(&in_layout_, true);
const ShelfAlignment alignment = shelf_->GetAlignment();
const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
const bool horizontal = shelf_->IsHorizontalAlignment();
gfx::Rect shelf_bounds = panel_container_->ConvertRectFromScreen(
shelf_->GetWindow()->GetBoundsInScreen());
int panel_start_bounds = kPanelIdealSpacing;
......@@ -764,7 +764,7 @@ void PanelLayoutManager::UpdateStacking(WmWindow* active_panel) {
// the titlebar--even though it doesn't update the shelf icon positions, we
// still want the visual effect.
std::map<int, WmWindow*> window_ordering;
const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
const bool horizontal = shelf_->IsHorizontalAlignment();
for (PanelList::const_iterator it = panel_windows_.begin();
it != panel_windows_.end(); ++it) {
gfx::Rect bounds = it->window->GetBounds();
......@@ -803,7 +803,7 @@ void PanelLayoutManager::UpdateCallouts() {
if (!shelf_)
return;
const bool horizontal = IsHorizontalAlignment(shelf_->GetAlignment());
const bool horizontal = shelf_->IsHorizontalAlignment();
for (PanelList::iterator iter = panel_windows_.begin();
iter != panel_windows_.end(); ++iter) {
WmWindow* panel = iter->window;
......
......@@ -156,17 +156,16 @@ class ShelfDragCallback {
if (type == ui::ET_GESTURE_SCROLL_UPDATE)
scroll_.Add(delta);
WmShelf* shelf = test::AshTestBase::GetPrimaryShelf();
gfx::Rect shelf_bounds = GetShelfWidget()->GetWindowBoundsInScreen();
if (GetShelfLayoutManager()->IsHorizontalAlignment()) {
if (shelf->IsHorizontalAlignment()) {
EXPECT_EQ(auto_hidden_shelf_widget_bounds_.bottom(),
shelf_bounds.bottom());
EXPECT_EQ(shelf_widget_bounds_.bottom(), shelf_bounds.bottom());
} else if (SHELF_ALIGNMENT_RIGHT ==
GetShelfLayoutManager()->GetAlignment()) {
} else if (SHELF_ALIGNMENT_RIGHT == shelf->GetAlignment()) {
EXPECT_EQ(auto_hidden_shelf_widget_bounds_.right(), shelf_bounds.right());
EXPECT_EQ(shelf_widget_bounds_.right(), shelf_bounds.right());
} else if (SHELF_ALIGNMENT_LEFT ==
GetShelfLayoutManager()->GetAlignment()) {
} else if (SHELF_ALIGNMENT_LEFT == shelf->GetAlignment()) {
EXPECT_EQ(auto_hidden_shelf_widget_bounds_.x(), shelf_bounds.x());
EXPECT_EQ(shelf_widget_bounds_.x(), shelf_bounds.x());
}
......@@ -174,7 +173,6 @@ class ShelfDragCallback {
// Auto hidden shelf has a visible height of 0 in MD (where this inequality
// does not apply); whereas auto hidden shelf has a visible height of 3 in
// non-MD.
WmShelf* shelf = test::AshTestBase::GetPrimaryShelf();
if (!ash::MaterialDesignController::IsImmersiveModeMaterial() ||
shelf->GetAutoHideState() != ash::SHELF_AUTO_HIDE_HIDDEN) {
EXPECT_GE(shelf_bounds.height(),
......@@ -398,11 +396,11 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
base::Unretained(&handler)));
// Swipe down very little. It shouldn't change any state.
if (GetShelfLayoutManager()->IsHorizontalAlignment())
if (shelf->IsHorizontalAlignment())
end.set_y(start.y() + shelf_shown.height() * 3 / 10);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_LEFT == shelf->GetAlignment())
end.set_x(start.x() - shelf_shown.width() * 3 / 10);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_RIGHT == shelf->GetAlignment())
end.set_x(start.x() + shelf_shown.width() * 3 / 10);
generator.GestureScrollSequence(start, end, kTimeDelta, 5);
EXPECT_EQ(SHELF_VISIBLE, shelf->GetVisibilityState());
......@@ -426,12 +424,12 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe up in extended hit region to show it.
gfx::Point extended_start = start;
if (GetShelfLayoutManager()->IsHorizontalAlignment())
if (shelf->IsHorizontalAlignment())
extended_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().y() - 1);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_LEFT == shelf->GetAlignment())
extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() +
1);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_RIGHT == shelf->GetAlignment())
extended_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
end = extended_start - delta;
generator.GestureScrollSequenceWithCallback(
......@@ -475,11 +473,11 @@ void ShelfLayoutManagerTest::RunGestureDragTests(gfx::Vector2d delta) {
// Swipe up from below the shelf where a bezel would be, this should show the
// shelf.
gfx::Point below_start = start;
if (GetShelfLayoutManager()->IsHorizontalAlignment())
if (shelf->IsHorizontalAlignment())
below_start.set_y(GetShelfWidget()->GetWindowBoundsInScreen().bottom() + 1);
else if (SHELF_ALIGNMENT_LEFT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_LEFT == shelf->GetAlignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().x() - 1);
else if (SHELF_ALIGNMENT_RIGHT == GetShelfLayoutManager()->GetAlignment())
else if (SHELF_ALIGNMENT_RIGHT == shelf->GetAlignment())
below_start.set_x(GetShelfWidget()->GetWindowBoundsInScreen().right() + 1);
end = below_start - delta;
generator.GestureScrollSequence(below_start, end, kTimeDelta,
......
......@@ -84,6 +84,7 @@
#include "ui/base/resource/resource_bundle.h"
#include "ui/keyboard/keyboard_controller.h"
#include "ui/keyboard/keyboard_util.h"
#include "ui/views/widget/widget_observer.h"
using content::BrowserThread;
using extensions::api::braille_display_private::BrailleController;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment