diff options
author | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 01:47:23 +0000 |
---|---|---|
committer | oshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-12-05 01:47:23 +0000 |
commit | 1fcfb9986bb54e8a8b8f98b3eefcf99486f70bf7 (patch) | |
tree | 7f8d2de39c9774a1f45afda0345b3aee83f38025 | |
parent | 51772fa550db198e7741414aeded8848191b6308 (diff) | |
download | chromium_src-1fcfb9986bb54e8a8b8f98b3eefcf99486f70bf7.zip chromium_src-1fcfb9986bb54e8a8b8f98b3eefcf99486f70bf7.tar.gz chromium_src-1fcfb9986bb54e8a8b8f98b3eefcf99486f70bf7.tar.bz2 |
Use the correct launcher assets for shelf alignment.
Cleanup: remove redundant shelf code.
- replaces switch to get values for alignment with template
- eliminate alignment member variables and use shelf_layout_manager where possible.
other minor clean ups: remove unnecessary namespace, use member variable.
BUG=151417
TEST=none
Review URL: https://chromiumcodereview.appspot.com/11434099
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171120 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | ash/launcher/launcher.cc | 14 | ||||
-rw-r--r-- | ash/launcher/launcher_alignment_menu.cc | 20 | ||||
-rw-r--r-- | ash/launcher/launcher_button.cc | 68 | ||||
-rw-r--r-- | ash/launcher/launcher_button.h | 10 | ||||
-rw-r--r-- | ash/launcher/launcher_button_host.h | 3 | ||||
-rw-r--r-- | ash/launcher/launcher_tooltip_manager.cc | 30 | ||||
-rw-r--r-- | ash/launcher/launcher_tooltip_manager.h | 10 | ||||
-rw-r--r-- | ash/launcher/launcher_tooltip_manager_unittest.cc | 1 | ||||
-rw-r--r-- | ash/launcher/launcher_view.cc | 90 | ||||
-rw-r--r-- | ash/launcher/launcher_view.h | 16 | ||||
-rw-r--r-- | ash/launcher/launcher_view_unittest.cc | 5 | ||||
-rw-r--r-- | ash/launcher/overflow_bubble.cc | 52 | ||||
-rw-r--r-- | ash/launcher/overflow_bubble.h | 2 | ||||
-rw-r--r-- | ash/launcher/overflow_button.cc | 20 | ||||
-rw-r--r-- | ash/launcher/overflow_button.h | 3 | ||||
-rw-r--r-- | ash/launcher/tabbed_launcher_button.cc | 15 | ||||
-rw-r--r-- | ash/launcher/tabbed_launcher_button.h | 2 | ||||
-rw-r--r-- | ash/root_window_controller.cc | 2 | ||||
-rw-r--r-- | ash/wm/app_list_controller.cc | 18 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager.cc | 45 | ||||
-rw-r--r-- | ash/wm/shelf_layout_manager.h | 37 |
21 files changed, 246 insertions, 217 deletions
diff --git a/ash/launcher/launcher.cc b/ash/launcher/launcher.cc index f38b567..69de8e1 100644 --- a/ash/launcher/launcher.cc +++ b/ash/launcher/launcher.cc @@ -167,12 +167,13 @@ void Launcher::DelegateView::Layout() { void Launcher::DelegateView::OnPaintBackground(gfx::Canvas* canvas) { if (launcher_->alignment_ == SHELF_ALIGNMENT_BOTTOM) { SkPaint paint; - static const gfx::ImageSkia* launcher_background = NULL; - if (!launcher_background) { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - launcher_background = - rb.GetImageNamed(IDR_AURA_LAUNCHER_BACKGROUND_BOTTOM).ToImageSkia(); - } + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + const gfx::ImageSkia* launcher_background = rb.GetImageSkiaNamed( + internal::ShelfLayoutManager::ForLauncher( + launcher_->widget()->GetNativeView())-> + SelectValueForShelfAlignment(IDR_AURA_LAUNCHER_BACKGROUND_BOTTOM, + IDR_AURA_LAUNCHER_BACKGROUND_LEFT, + IDR_AURA_LAUNCHER_BACKGROUND_RIGHT)); paint.setAlpha(alpha_); canvas->DrawImageInt( *launcher_background, @@ -230,6 +231,7 @@ Launcher::Launcher(aura::Window* window_container, widget_->GetNativeView()->SetName("LauncherView"); widget_->GetNativeView()->SetProperty(internal::kStayInSameRootWindowKey, true); + // SetBounds() has to be called after kStayInSameRootWindowKey is set. gfx::Size pref = static_cast<views::View*>(launcher_view_)->GetPreferredSize(); diff --git a/ash/launcher/launcher_alignment_menu.cc b/ash/launcher/launcher_alignment_menu.cc index cfa242c..1136baa 100644 --- a/ash/launcher/launcher_alignment_menu.cc +++ b/ash/launcher/launcher_alignment_menu.cc @@ -6,7 +6,9 @@ #include "ash/shelf_types.h" #include "ash/shell.h" +#include "ash/wm/shelf_layout_manager.h" #include "grit/ash_strings.h" +#include "ui/aura/root_window.h" #include "ui/base/l10n/l10n_util.h" namespace ash { @@ -33,19 +35,11 @@ LauncherAlignmentMenu::~LauncherAlignmentMenu() { } bool LauncherAlignmentMenu::IsCommandIdChecked(int command_id) const { - switch (command_id) { - case MENU_ALIGN_LEFT: - return Shell::GetInstance()->GetShelfAlignment(root_window_) == - SHELF_ALIGNMENT_LEFT; - case MENU_ALIGN_BOTTOM: - return Shell::GetInstance()->GetShelfAlignment(root_window_) == - SHELF_ALIGNMENT_BOTTOM; - case MENU_ALIGN_RIGHT: - return Shell::GetInstance()->GetShelfAlignment(root_window_) == - SHELF_ALIGNMENT_RIGHT; - default: - return false; - } + return internal::ShelfLayoutManager::ForLauncher(root_window_)-> + SelectValueForShelfAlignment( + MENU_ALIGN_BOTTOM == command_id, + MENU_ALIGN_LEFT == command_id, + MENU_ALIGN_RIGHT == command_id); } bool LauncherAlignmentMenu::IsCommandIdEnabled(int command_id) const { diff --git a/ash/launcher/launcher_button.cc b/ash/launcher/launcher_button.cc index be5e381..77546f8 100644 --- a/ash/launcher/launcher_button.cc +++ b/ash/launcher/launcher_button.cc @@ -7,6 +7,7 @@ #include <algorithm> #include "ash/launcher/launcher_button_host.h" +#include "ash/wm/shelf_layout_manager.h" #include "grit/ash_resources.h" #include "skia/ext/image_operations.h" #include "ui/base/accessibility/accessible_view_state.h" @@ -112,20 +113,25 @@ bool LauncherButton::IconView::HitTestRect(const gfx::Rect& rect) const { //////////////////////////////////////////////////////////////////////////////// // LauncherButton -LauncherButton* LauncherButton::Create(views::ButtonListener* listener, - LauncherButtonHost* host) { - LauncherButton* button = new LauncherButton(listener, host); +LauncherButton* LauncherButton::Create( + views::ButtonListener* listener, + LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager) { + LauncherButton* button = + new LauncherButton(listener, host, shelf_layout_manager); button->Init(); return button; } LauncherButton::LauncherButton(views::ButtonListener* listener, - LauncherButtonHost* host) + LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager) : CustomButton(listener), host_(host), icon_view_(NULL), bar_(new BarView), - state_(STATE_NORMAL) { + state_(STATE_NORMAL), + shelf_layout_manager_(shelf_layout_manager) { set_accessibility_focusable(true); const gfx::ShadowValue kShadows[] = { @@ -269,7 +275,7 @@ void LauncherButton::Layout() { int x_offset = 0, y_offset = 0; gfx::Rect icon_bounds; - if (host_->GetShelfAlignment() == SHELF_ALIGNMENT_BOTTOM) { + if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { icon_bounds.SetRect( button_bounds.x(), button_bounds.y() + kIconPad, button_bounds.width(), kIconSize); @@ -283,7 +289,7 @@ void LauncherButton::Layout() { x_offset += kHopSpacing; } - if (host_->GetShelfAlignment() == SHELF_ALIGNMENT_LEFT) + if (shelf_layout_manager_->GetAlignment() == SHELF_ALIGNMENT_LEFT) x_offset = -x_offset; icon_bounds.Offset(x_offset, y_offset); icon_view_->SetBoundsRect(icon_bounds); @@ -347,7 +353,7 @@ LauncherButton::IconView* LauncherButton::CreateIconView() { } bool LauncherButton::IsShelfHorizontal() const { - return host_->GetShelfAlignment() == SHELF_ALIGNMENT_BOTTOM; + return shelf_layout_manager_->IsHorizontalAlignment(); } void LauncherButton::UpdateState() { @@ -355,28 +361,39 @@ void LauncherButton::UpdateState() { bar_->SetVisible(false); } else { int bar_id; - if (IsShelfHorizontal()) { - if (state_ & STATE_ACTIVE) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_ACTIVE; - else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_HOVER; - else - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_RUNNING; + if (state_ & STATE_ACTIVE) { + bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( + IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_ACTIVE, + IDR_AURA_LAUNCHER_UNDERLINE_LEFT_ACTIVE, + IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_ACTIVE); + } else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) { + bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( + IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_HOVER, + IDR_AURA_LAUNCHER_UNDERLINE_LEFT_HOVER, + IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_HOVER); } else { - if (state_ & STATE_ACTIVE) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_ACTIVE; - else if (state_ & (STATE_HOVERED | STATE_FOCUSED | STATE_ATTENTION)) - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_HOVER; - else - bar_id = IDR_AURA_LAUNCHER_UNDERLINE_LEFT_RUNNING; + bar_id = shelf_layout_manager_->SelectValueForShelfAlignment( + IDR_AURA_LAUNCHER_UNDERLINE_BOTTOM_RUNNING, + IDR_AURA_LAUNCHER_UNDERLINE_LEFT_RUNNING, + IDR_AURA_LAUNCHER_UNDERLINE_RIGHT_RUNNING); } - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); bar_->SetImage(rb.GetImageNamed(bar_id).ToImageSkia()); bar_->SetVisible(true); } - - switch (host_->GetShelfAlignment()) { + bool rtl = base::i18n::IsRTL(); + bar_->SetHorizontalAlignment( + shelf_layout_manager_->SelectValueForShelfAlignment( + views::ImageView::CENTER, + rtl ? views::ImageView::TRAILING : views::ImageView::LEADING, + rtl ? views::ImageView::LEADING : views::ImageView::TRAILING)); + bar_->SetVerticalAlignment( + shelf_layout_manager_->SelectValueForShelfAlignment( + views::ImageView::TRAILING, + views::ImageView::CENTER, + views::ImageView::CENTER)); + + switch (shelf_layout_manager_->GetAlignment()) { case SHELF_ALIGNMENT_BOTTOM: bar_->SetHorizontalAlignment(views::ImageView::CENTER); bar_->SetVerticalAlignment(views::ImageView::TRAILING); @@ -395,7 +412,10 @@ void LauncherButton::UpdateState() { break; } + // Force bar to layout as alignment may have changed but not bounds. + bar_->Layout(); Layout(); + bar_->SchedulePaint(); SchedulePaint(); } diff --git a/ash/launcher/launcher_button.h b/ash/launcher/launcher_button.h index c46b209..934fc9a 100644 --- a/ash/launcher/launcher_button.h +++ b/ash/launcher/launcher_button.h @@ -13,6 +13,7 @@ namespace ash { namespace internal { class LauncherButtonHost; +class ShelfLayoutManager; // Button used for items on the launcher, except for the AppList. class LauncherButton : public views::CustomButton { @@ -38,7 +39,8 @@ class LauncherButton : public views::CustomButton { // Called to create an instance of a LauncherButton. static LauncherButton* Create(views::ButtonListener* listener, - LauncherButtonHost* host); + LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager); // Sets the image to display for this entry. void SetImage(const gfx::ImageSkia& image); @@ -52,7 +54,9 @@ class LauncherButton : public views::CustomButton { gfx::Rect GetIconBounds() const; protected: - LauncherButton(views::ButtonListener* listener, LauncherButtonHost* host); + LauncherButton(views::ButtonListener* listener, + LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager); // Class that draws the icon part of a button, so it can be animated // independently of the rest. This can be subclassed to provide a custom @@ -121,6 +125,8 @@ class LauncherButton : public views::CustomButton { // together. int state_; + ShelfLayoutManager* shelf_layout_manager_; + gfx::ShadowValues icon_shadows_; DISALLOW_COPY_AND_ASSIGN(LauncherButton); diff --git a/ash/launcher/launcher_button_host.h b/ash/launcher/launcher_button_host.h index c088533..37ed07a 100644 --- a/ash/launcher/launcher_button_host.h +++ b/ash/launcher/launcher_button_host.h @@ -6,7 +6,6 @@ #define ASH_LAUNCHER_LAUNCHER_BUTTON_HOST_H_ #include "ash/ash_export.h" -#include "ash/shelf_types.h" #include "base/string16.h" namespace ui { @@ -54,8 +53,6 @@ class ASH_EXPORT LauncherButtonHost { // Invoked when the mouse exits the item. virtual void MouseExitedButton(views::View* view) = 0; - virtual ShelfAlignment GetShelfAlignment() const = 0; - // Invoked to get the accessible name of the item. virtual string16 GetAccessibleName(const views::View* view) = 0; diff --git a/ash/launcher/launcher_tooltip_manager.cc b/ash/launcher/launcher_tooltip_manager.cc index aa48c5c..f99e552 100644 --- a/ash/launcher/launcher_tooltip_manager.cc +++ b/ash/launcher/launcher_tooltip_manager.cc @@ -9,6 +9,7 @@ #include "ash/shell_window_ids.h" #include "ash/wm/session_state_controller.h" #include "ash/wm/session_state_observer.h" +#include "ash/wm/shelf_layout_manager.h" #include "ash/wm/window_animations.h" #include "base/bind.h" #include "base/message_loop.h" @@ -41,18 +42,6 @@ const int kTooltipMaxWidth = 250; // The distance between the arrow tip and edge of the anchor view. const int kArrowOffset = 10; -views::BubbleBorder::ArrowLocation GetArrowLocation(ShelfAlignment alignment) { - switch (alignment) { - case SHELF_ALIGNMENT_LEFT: - return views::BubbleBorder::LEFT_CENTER; - case SHELF_ALIGNMENT_RIGHT: - return views::BubbleBorder::RIGHT_CENTER; - case SHELF_ALIGNMENT_BOTTOM: - return views::BubbleBorder::BOTTOM_CENTER; - } - - return views::BubbleBorder::NONE; -} } // namespace // The implementation of tooltip of the launcher. @@ -139,13 +128,11 @@ gfx::Size LauncherTooltipManager::LauncherTooltipBubble::GetPreferredSize() { } LauncherTooltipManager::LauncherTooltipManager( - ShelfAlignment alignment, ShelfLayoutManager* shelf_layout_manager, LauncherView* launcher_view) : view_(NULL), widget_(NULL), anchor_(NULL), - alignment_(alignment), shelf_layout_manager_(shelf_layout_manager), launcher_view_(launcher_view) { if (shelf_layout_manager) @@ -217,11 +204,7 @@ void LauncherTooltipManager::OnBubbleClosed(views::BubbleDelegateView* view) { } } -void LauncherTooltipManager::SetArrowLocation(ShelfAlignment alignment) { - if (alignment_ == alignment) - return; - - alignment_ = alignment; +void LauncherTooltipManager::UpdateArrowLocation() { if (view_) { CancelHidingAnimation(); Close(); @@ -368,8 +351,13 @@ void LauncherTooltipManager::CreateBubble(views::View* anchor, anchor_ = anchor; text_ = text; - view_ = new LauncherTooltipBubble( - anchor, GetArrowLocation(alignment_), this); + views::BubbleBorder::ArrowLocation arrow_location = + shelf_layout_manager_->SelectValueForShelfAlignment( + views::BubbleBorder::BOTTOM_CENTER, + views::BubbleBorder::LEFT_CENTER, + views::BubbleBorder::RIGHT_CENTER); + + view_ = new LauncherTooltipBubble(anchor, arrow_location, this); widget_ = view_->GetWidget(); view_->SetText(text_); diff --git a/ash/launcher/launcher_tooltip_manager.h b/ash/launcher/launcher_tooltip_manager.h index 0e2c660..8bb764f 100644 --- a/ash/launcher/launcher_tooltip_manager.h +++ b/ash/launcher/launcher_tooltip_manager.h @@ -40,11 +40,14 @@ class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler, public ShelfLayoutManager::Observer, public SessionStateObserver { public: - LauncherTooltipManager(ShelfAlignment alignment, - ShelfLayoutManager* shelf_layout_manager, + LauncherTooltipManager(ShelfLayoutManager* shelf_layout_manager, LauncherView* launcher_view); virtual ~LauncherTooltipManager(); + ShelfLayoutManager* shelf_layout_manager() { + return shelf_layout_manager_; + } + // Called when the bubble is closed. void OnBubbleClosed(views::BubbleDelegateView* view); @@ -59,7 +62,7 @@ class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler, // Changes the arrow location of the tooltip in case that the launcher // arrangement has changed. - void SetArrowLocation(ShelfAlignment alignment); + void UpdateArrowLocation(); // Resets the timer for the delayed showing |view_|. If the timer isn't // running, it starts a new timer. @@ -101,7 +104,6 @@ protected: views::Widget* widget_; views::View* anchor_; string16 text_; - ShelfAlignment alignment_; scoped_ptr<base::Timer> timer_; ShelfLayoutManager* shelf_layout_manager_; diff --git a/ash/launcher/launcher_tooltip_manager_unittest.cc b/ash/launcher/launcher_tooltip_manager_unittest.cc index 0d0617a..c6d81dd 100644 --- a/ash/launcher/launcher_tooltip_manager_unittest.cc +++ b/ash/launcher/launcher_tooltip_manager_unittest.cc @@ -41,7 +41,6 @@ class LauncherTooltipManagerTest : public AshTestBase { internal::RootWindowController* controller = Shell::GetPrimaryRootWindowController(); tooltip_manager_.reset(new internal::LauncherTooltipManager( - SHELF_ALIGNMENT_BOTTOM, controller->shelf(), controller->launcher()->GetLauncherViewForTest())); } diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc index 4148c87..18c9e9d 100644 --- a/ash/launcher/launcher_view.cc +++ b/ash/launcher/launcher_view.cc @@ -16,8 +16,8 @@ #include "ash/launcher/overflow_bubble.h" #include "ash/launcher/overflow_button.h" #include "ash/launcher/tabbed_launcher_button.h" -#include "ash/shell.h" #include "ash/shell_delegate.h" +#include "ash/wm/shelf_layout_manager.h" #include "base/auto_reset.h" #include "base/memory/scoped_ptr.h" #include "grit/ash_strings.h" @@ -282,7 +282,6 @@ LauncherView::LauncherView(LauncherModel* model, drag_offset_(0), start_drag_index_(-1), context_menu_id_(0), - alignment_(SHELF_ALIGNMENT_BOTTOM), leading_inset_(kDefaultLeadingInset) { DCHECK(model_); bounds_animator_.reset(new views::BoundsAnimator(this)); @@ -290,7 +289,7 @@ LauncherView::LauncherView(LauncherModel* model, set_context_menu_controller(this); focus_search_.reset(new LauncherFocusSearch(view_model_.get())); tooltip_.reset(new LauncherTooltipManager( - alignment_, shelf_layout_manager, this)); + shelf_layout_manager, this)); } LauncherView::~LauncherView() { @@ -324,9 +323,9 @@ void LauncherView::SetAlignment(ShelfAlignment alignment) { return; alignment_ = alignment; UpdateFirstButtonPadding(); - overflow_button_->SetShelfAlignment(alignment_); + overflow_button_->OnShelfAlignmentChanged(); LayoutToIdealBounds(); - tooltip_->SetArrowLocation(alignment_); + tooltip_->UpdateArrowLocation(); if (overflow_bubble_.get()) overflow_bubble_->Hide(); } @@ -395,29 +394,32 @@ void LauncherView::LayoutToIdealBounds() { } void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { - int available_size = primary_axis_coordinate(width(), height()); + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + + int available_size = shelf->PrimaryAxisValue(width(), height()); if (!available_size) return; // Initial x,y values account both leading_inset in primary // coordinate and secondary coordinate based on the dynamic edge of the // launcher (eg top edge on bottom-aligned launcher). - int x = alignment_based_value(leading_inset(), + int x = shelf->SelectValueForShelfAlignment( + leading_inset(), width() - kLauncherPreferredSize, std::max(width() - kLauncherPreferredSize, - ShelfLayoutManager::kAutoHideSize + 1)); - int y = primary_axis_coordinate(0, leading_inset()); + ShelfLayoutManager::kAutoHideSize + 1)); + int y = shelf->PrimaryAxisValue(0, leading_inset()); for (int i = 0; i < view_model_->view_size(); ++i) { if (i < first_visible_index_) { view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); continue; } - int w = primary_axis_coordinate(kLauncherPreferredSize, width()); - int h = primary_axis_coordinate(height(), kLauncherPreferredSize); + int w = shelf->PrimaryAxisValue(kLauncherPreferredSize, width()); + int h = shelf->PrimaryAxisValue(height(), kLauncherPreferredSize); view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); - x = primary_axis_coordinate(x + w + kButtonSpacing, x); - y = primary_axis_coordinate(y, y + h + kButtonSpacing); + x = shelf->PrimaryAxisValue(x + w + kButtonSpacing, x); + y = shelf->PrimaryAxisValue(y, y + h + kButtonSpacing); } int app_list_index = view_model_->view_size() - 1; @@ -431,8 +433,8 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { } bounds->overflow_bounds.set_size(gfx::Size( - primary_axis_coordinate(kLauncherPreferredSize, width()), - primary_axis_coordinate(height(), kLauncherPreferredSize))); + shelf->PrimaryAxisValue(kLauncherPreferredSize, width()), + shelf->PrimaryAxisValue(height(), kLauncherPreferredSize))); last_visible_index_ = DetermineLastVisibleIndex( available_size - leading_inset() - kLauncherPreferredSize - kButtonSpacing - kLauncherPreferredSize); @@ -447,24 +449,25 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { if (show_overflow) { DCHECK_NE(0, view_model_->view_size()); if (last_visible_index_ == -1) { - x = alignment_based_value(leading_inset(), - width() - kLauncherPreferredSize, - std::max(width() - kLauncherPreferredSize, - ShelfLayoutManager::kAutoHideSize + 1)); - y = primary_axis_coordinate(0, leading_inset()); + x = shelf->SelectValueForShelfAlignment( + leading_inset(), + width() - kLauncherPreferredSize, + std::max(width() - kLauncherPreferredSize, + ShelfLayoutManager::kAutoHideSize + 1)); + y = shelf->PrimaryAxisValue(0, leading_inset()); } else { - x = primary_axis_coordinate( + x = shelf->PrimaryAxisValue( view_model_->ideal_bounds(last_visible_index_).right(), view_model_->ideal_bounds(last_visible_index_).x()); - y = primary_axis_coordinate( + y = shelf->PrimaryAxisValue( view_model_->ideal_bounds(last_visible_index_).y(), view_model_->ideal_bounds(last_visible_index_).bottom()); } gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); bounds->overflow_bounds.set_x(x); bounds->overflow_bounds.set_y(y); - x = primary_axis_coordinate(x + kLauncherPreferredSize + kButtonSpacing, x); - y = primary_axis_coordinate(y, y + kLauncherPreferredSize + kButtonSpacing); + x = shelf->PrimaryAxisValue(x + kLauncherPreferredSize + kButtonSpacing, x); + y = shelf->PrimaryAxisValue(y, y + kLauncherPreferredSize + kButtonSpacing); app_list_bounds.set_x(x); app_list_bounds.set_y(y); view_model_->set_ideal_bounds(app_list_index, app_list_bounds); @@ -475,9 +478,11 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { } int LauncherView::DetermineLastVisibleIndex(int max_value) { + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + int index = view_model_->view_size() - 1; while (index >= 0 && - primary_axis_coordinate( + shelf->PrimaryAxisValue( view_model_->ideal_bounds(index).right(), view_model_->ideal_bounds(index).bottom()) > max_value) { index--; @@ -511,6 +516,7 @@ views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { TabbedLauncherButton::Create( this, this, + tooltip_->shelf_layout_manager(), item.is_incognito ? TabbedLauncherButton::STATE_INCOGNITO : TabbedLauncherButton::STATE_NOT_INCOGNITO); @@ -523,7 +529,8 @@ views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { case TYPE_APP_SHORTCUT: case TYPE_PLATFORM_APP: case TYPE_APP_PANEL: { - LauncherButton* button = LauncherButton::Create(this, this); + LauncherButton* button = LauncherButton::Create( + this, this, tooltip_->shelf_layout_manager()); button->SetImage(item.image); ReflectItemStatus(item, button); view = button; @@ -539,7 +546,8 @@ views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { case TYPE_BROWSER_SHORTCUT: { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - LauncherButton* button = LauncherButton::Create(this, this); + LauncherButton* button = LauncherButton::Create( + this, this, tooltip_->shelf_layout_manager()); int image_id = delegate_ ? delegate_->GetBrowserShortcutResourceId() : IDR_AURA_LAUNCHER_BROWSER_SHORTCUT; @@ -587,6 +595,8 @@ void LauncherView::PrepareForDrag(Pointer pointer, } void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + // TODO: I don't think this works correctly with RTL. gfx::Point drag_point(event.location()); views::View::ConvertPointToTarget(drag_view_, this, &drag_point); @@ -608,7 +618,7 @@ void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { if (last_drag_index > last_visible_index_) last_drag_index = last_visible_index_; int x = 0, y = 0; - if (is_horizontal_alignment()) { + if (shelf->IsHorizontalAlignment()) { x = std::max(view_model_->ideal_bounds(indices.first).x(), drag_point.x() - drag_offset_); x = std::min(view_model_->ideal_bounds(last_drag_index).right() - @@ -631,7 +641,7 @@ void LauncherView::ContinueDrag(const ui::LocatedEvent& event) { int target_index = views::ViewModelUtils::DetermineMoveIndex( *view_model_, drag_view_, - is_horizontal_alignment() ? + shelf->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL : views::ViewModelUtils::VERTICAL, x, y); @@ -693,20 +703,21 @@ void LauncherView::ShowOverflowBubble() { overflow_bubble_->Show(delegate_, model_, overflow_button_, - alignment_, first_overflow_index); Shell::GetInstance()->UpdateShelfVisibility(); } void LauncherView::UpdateFirstButtonPadding() { + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + // Creates an empty border for first launcher button to make included leading // inset act as the button's padding. This is only needed on button creation // and when shelf alignment changes. if (view_model_->view_size() > 0) { view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( - primary_axis_coordinate(0, leading_inset()), - primary_axis_coordinate(leading_inset(), 0), + shelf->PrimaryAxisValue(0, leading_inset()), + shelf->PrimaryAxisValue(leading_inset(), 0), 0, 0)); } @@ -766,7 +777,9 @@ gfx::Size LauncherView::GetPreferredSize() { gfx::Rect(gfx::Size(kLauncherPreferredSize, kLauncherPreferredSize)); - if (is_horizontal_alignment()) { + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + + if (shelf->IsHorizontalAlignment()) { return gfx::Size(last_button_bounds.right() + leading_inset(), kLauncherPreferredSize); } @@ -911,15 +924,18 @@ void LauncherView::PointerPressedOnButton(views::View* view, !delegate_->IsDraggable(model_->items()[index])) return; // View is being deleted or not draggable, ignore request. + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); + drag_view_ = view; - drag_offset_ = primary_axis_coordinate(event.x(), event.y()); + drag_offset_ = shelf->PrimaryAxisValue(event.x(), event.y()); } void LauncherView::PointerDraggedOnButton(views::View* view, Pointer pointer, const ui::LocatedEvent& event) { + ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); if (!dragging() && drag_view_ && - primary_axis_coordinate(abs(event.x() - drag_offset_), + shelf->PrimaryAxisValue(abs(event.x() - drag_offset_), abs(event.y() - drag_offset_)) >= kMinimumDragDistance) { PrepareForDrag(pointer, event); @@ -970,10 +986,6 @@ void LauncherView::MouseExitedButton(views::View* view) { tooltip_->StopTimer(); } -ShelfAlignment LauncherView::GetShelfAlignment() const { - return alignment_; -} - string16 LauncherView::GetAccessibleName(const views::View* view) { int view_index = view_model_->GetIndexOfView(view); // May be -1 while in the process of animating closed. diff --git a/ash/launcher/launcher_view.h b/ash/launcher/launcher_view.h index f52bb8d..563577f 100644 --- a/ash/launcher/launcher_view.h +++ b/ash/launcher/launcher_view.h @@ -106,21 +106,6 @@ class ASH_EXPORT LauncherView : public views::View, gfx::Rect overflow_bounds; }; - // Used in calculating ideal bounds. - int primary_axis_coordinate(int x, int y) const { - return is_horizontal_alignment() ? x : y; - } - - bool is_horizontal_alignment() const { - return alignment_ == SHELF_ALIGNMENT_BOTTOM; - } - - // Used in calculating ideal bounds. - int alignment_based_value(int bottom, int left, int right) const { - return (SHELF_ALIGNMENT_BOTTOM == alignment_ ? bottom : - (SHELF_ALIGNMENT_LEFT == alignment_ ? left : right)); - } - bool is_overflow_mode() const { return first_visible_index_ > 0; } @@ -209,7 +194,6 @@ class ASH_EXPORT LauncherView : public views::View, virtual void MouseMovedOverButton(views::View* view) OVERRIDE; virtual void MouseEnteredButton(views::View* view) OVERRIDE; virtual void MouseExitedButton(views::View* view) OVERRIDE; - virtual ShelfAlignment GetShelfAlignment() const OVERRIDE; virtual string16 GetAccessibleName(const views::View* view) OVERRIDE; // Overridden from views::ButtonListener: diff --git a/ash/launcher/launcher_view_unittest.cc b/ash/launcher/launcher_view_unittest.cc index 468e8f9..727d0ff 100644 --- a/ash/launcher/launcher_view_unittest.cc +++ b/ash/launcher/launcher_view_unittest.cc @@ -12,6 +12,7 @@ #include "ash/launcher/launcher_icon_observer.h" #include "ash/launcher/launcher_model.h" #include "ash/launcher/launcher_tooltip_manager.h" +#include "ash/root_window_controller.h" #include "ash/shell.h" #include "ash/test/ash_test_base.h" #include "ash/test/launcher_view_test_api.h" @@ -178,7 +179,9 @@ class LauncherViewTest : public AshTestBase { model_.reset(new LauncherModel); launcher_view_.reset(new internal::LauncherView( - model_.get(), &delegate_, NULL)); + model_.get(), + &delegate_, + Shell::GetPrimaryRootWindowController()->shelf())); launcher_view_->Init(); // The bounds should be big enough for 4 buttons + overflow chevron. launcher_view_->SetBounds(0, 0, 500, 50); diff --git a/ash/launcher/overflow_bubble.cc b/ash/launcher/overflow_bubble.cc index b5a1be5e..75d28af 100644 --- a/ash/launcher/overflow_bubble.cc +++ b/ash/launcher/overflow_bubble.cc @@ -10,6 +10,7 @@ #include "ash/launcher/launcher_view.h" #include "ash/system/tray/system_tray.h" #include "ash/shell.h" +#include "ash/wm/shelf_layout_manager.h" #include "ui/gfx/insets.h" #include "ui/gfx/screen.h" #include "ui/views/bubble/bubble_delegate.h" @@ -30,22 +31,6 @@ const int kPadding = 2; // Padding space in pixels between LauncherView's left/top edge to its contents. const int kLauncherViewLeadingInset = 8; -// Gets arrow location based on shelf alignment. -views::BubbleBorder::ArrowLocation GetBubbleArrowLocation( - ShelfAlignment shelf_alignment) { - switch (shelf_alignment) { - case ash::SHELF_ALIGNMENT_BOTTOM: - return views::BubbleBorder::BOTTOM_LEFT; - case ash::SHELF_ALIGNMENT_LEFT: - return views::BubbleBorder::LEFT_TOP; - case ash::SHELF_ALIGNMENT_RIGHT: - return views::BubbleBorder::RIGHT_TOP; - default: - NOTREACHED() << "Unknown shelf alignment " << shelf_alignment; - return views::BubbleBorder::BOTTOM_LEFT; - } -} - //////////////////////////////////////////////////////////////////////////////// // OverflowBubbleView // OverflowBubbleView hosts a LauncherView to display overflown items. @@ -58,18 +43,25 @@ class OverflowBubbleView : public views::BubbleDelegateView { void InitOverflowBubble(LauncherDelegate* delegate, LauncherModel* model, views::View* anchor, - ShelfAlignment shelf_alignment, int overflow_start_index); private: - bool is_horizontal_alignment() const { - return shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM; + bool IsHorizontalAlignment() const { + return GetShelfLayoutManagerForLauncher()->IsHorizontalAlignment(); } const gfx::Size GetContentsSize() const { return static_cast<views::View*>(launcher_view_)->GetPreferredSize(); } + // Gets arrow location based on shelf alignment. + views::BubbleBorder::ArrowLocation GetBubbleArrowLocation() const { + return GetShelfLayoutManagerForLauncher()->SelectValueForShelfAlignment( + views::BubbleBorder::BOTTOM_LEFT, + views::BubbleBorder::LEFT_TOP, + views::BubbleBorder::RIGHT_TOP); + } + void ScrollByXOffset(int x_offset); void ScrollByYOffset(int y_offset); @@ -85,7 +77,11 @@ class OverflowBubbleView : public views::BubbleDelegateView { // views::BubbleDelegate overrides: virtual gfx::Rect GetBubbleBounds() OVERRIDE; - ShelfAlignment shelf_alignment_; + ShelfLayoutManager* GetShelfLayoutManagerForLauncher() const { + return ShelfLayoutManager::ForLauncher( + anchor_view()->GetWidget()->GetNativeView()); + } + LauncherView* launcher_view_; // Owned by views hierarchy. gfx::Vector2d scroll_offset_; @@ -93,8 +89,7 @@ class OverflowBubbleView : public views::BubbleDelegateView { }; OverflowBubbleView::OverflowBubbleView() - : shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), - launcher_view_(NULL) { + : launcher_view_(NULL) { } OverflowBubbleView::~OverflowBubbleView() { @@ -103,14 +98,13 @@ OverflowBubbleView::~OverflowBubbleView() { void OverflowBubbleView::InitOverflowBubble(LauncherDelegate* delegate, LauncherModel* model, views::View* anchor, - ShelfAlignment shelf_alignment, int overflow_start_index) { - shelf_alignment_ = shelf_alignment; - // Makes bubble view has a layer and clip its children layers. SetPaintToLayer(true); SetFillsBoundsOpaquely(false); layer()->SetMasksToBounds(true); + ShelfAlignment shelf_alignment = GetShelfLayoutManagerForLauncher()-> + GetAlignment(); launcher_view_ = new LauncherView(model, delegate, NULL); launcher_view_->set_first_visible_index(overflow_start_index); @@ -120,7 +114,7 @@ void OverflowBubbleView::InitOverflowBubble(LauncherDelegate* delegate, AddChildView(launcher_view_); set_anchor_view(anchor); - set_arrow_location(GetBubbleArrowLocation(shelf_alignment)); + set_arrow_location(GetBubbleArrowLocation()); set_background(NULL); set_color(SkColorSetARGB(kLauncherBackgroundAlpha, 0, 0, 0)); set_margins(gfx::Insets(kPadding, kPadding, kPadding, kPadding)); @@ -152,7 +146,7 @@ gfx::Size OverflowBubbleView::GetPreferredSize() { const gfx::Rect monitor_rect = Shell::GetScreen()->GetDisplayNearestPoint( GetAnchorRect().CenterPoint()).work_area(); if (!monitor_rect.IsEmpty()) { - if (is_horizontal_alignment()) { + if (IsHorizontalAlignment()) { preferred_size.set_width(std::min( preferred_size.width(), static_cast<int>(monitor_rect.width() * @@ -183,7 +177,7 @@ void OverflowBubbleView::ChildPreferredSizeChanged(views::View* child) { } bool OverflowBubbleView::OnMouseWheel(const ui::MouseWheelEvent& event) { - if (is_horizontal_alignment()) + if (IsHorizontalAlignment()) ScrollByXOffset(-event.offset()); else ScrollByYOffset(-event.offset()); @@ -257,7 +251,6 @@ OverflowBubble::~OverflowBubble() { void OverflowBubble::Show(LauncherDelegate* delegate, LauncherModel* model, views::View* anchor, - ShelfAlignment shelf_alignment, int overflow_start_index) { Hide(); @@ -265,7 +258,6 @@ void OverflowBubble::Show(LauncherDelegate* delegate, bubble_view->InitOverflowBubble(delegate, model, anchor, - shelf_alignment, overflow_start_index); bubble_ = bubble_view; diff --git a/ash/launcher/overflow_bubble.h b/ash/launcher/overflow_bubble.h index 5d5e747..b1ea42e 100644 --- a/ash/launcher/overflow_bubble.h +++ b/ash/launcher/overflow_bubble.h @@ -5,7 +5,6 @@ #ifndef ASH_LAUNCHER_OVERFLOW_BUBBLE_H_ #define ASH_LAUNCHER_OVERFLOW_BUBBLE_H_ -#include "ash/shelf_types.h" #include "base/basictypes.h" #include "base/compiler_specific.h" #include "ui/views/widget/widget_observer.h" @@ -32,7 +31,6 @@ class OverflowBubble : public views::WidgetObserver { void Show(LauncherDelegate* delegate, LauncherModel* model, views::View* anchor, - ShelfAlignment shelf_alignment, int overflow_start_index); void Hide(); diff --git a/ash/launcher/overflow_button.cc b/ash/launcher/overflow_button.cc index 0a853bb..6f007bf 100644 --- a/ash/launcher/overflow_button.cc +++ b/ash/launcher/overflow_button.cc @@ -4,6 +4,7 @@ #include "ash/launcher/overflow_button.h" +#include "ash/wm/shelf_layout_manager.h" #include "grit/ash_resources.h" #include "grit/ash_strings.h" #include "third_party/skia/include/core/SkPaint.h" @@ -14,6 +15,7 @@ #include "ui/gfx/canvas.h" #include "ui/gfx/skia_util.h" #include "ui/gfx/transform.h" +#include "ui/views/widget/widget.h" namespace ash { namespace internal { @@ -48,7 +50,6 @@ void RotateClockwise(gfx::Transform* transform) { OverflowButton::OverflowButton(views::ButtonListener* listener) : CustomButton(listener), - alignment_(SHELF_ALIGNMENT_BOTTOM), image_(NULL) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); image_ = rb.GetImageNamed(IDR_AURA_LAUNCHER_OVERFLOW).ToImageSkia(); @@ -62,20 +63,18 @@ OverflowButton::OverflowButton(views::ButtonListener* listener) OverflowButton::~OverflowButton() { } -void OverflowButton::SetShelfAlignment(ShelfAlignment alignment) { - if (alignment_ == alignment) - return; - - alignment_ = alignment; +void OverflowButton::OnShelfAlignmentChanged() { SchedulePaint(); } void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { gfx::Rect bounds(GetContentsBounds()); gfx::Rect rect(0, 0, kButtonHoverSize, kButtonHoverSize); + ShelfLayoutManager* shelf = + ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); // Nudge the background a little to line up right. - if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { + if (shelf->GetAlignment() == SHELF_ALIGNMENT_BOTTOM) { rect.set_origin(gfx::Point( bounds.x() + ((bounds.width() - kButtonHoverSize) / 2) - 1, bounds.y() + kBackgroundOffset - 1)); @@ -100,6 +99,9 @@ void OverflowButton::PaintBackground(gfx::Canvas* canvas, int alpha) { } void OverflowButton::OnPaint(gfx::Canvas* canvas) { + ShelfAlignment alignment = ShelfLayoutManager::ForLauncher( + GetWidget()->GetNativeView())->GetAlignment(); + if (hover_animation_->is_animating()) { PaintBackground( canvas, @@ -113,7 +115,7 @@ void OverflowButton::OnPaint(gfx::Canvas* canvas) { gfx::Transform transform; - switch (alignment_) { + switch (alignment) { case SHELF_ALIGNMENT_BOTTOM: // Shift 1 pixel left to align with overflow bubble tip. transform.Translate(-1, kBackgroundOffset); @@ -132,7 +134,7 @@ void OverflowButton::OnPaint(gfx::Canvas* canvas) { canvas->Transform(transform); gfx::Rect rect(GetContentsBounds()); - if (alignment_ == SHELF_ALIGNMENT_BOTTOM) { + if (alignment == SHELF_ALIGNMENT_BOTTOM) { canvas->DrawImageInt(*image_, rect.x() + (rect.width() - image_->width()) / 2, kButtonHoverSize - image_->height()); diff --git a/ash/launcher/overflow_button.h b/ash/launcher/overflow_button.h index be24ba6..69cc795 100644 --- a/ash/launcher/overflow_button.h +++ b/ash/launcher/overflow_button.h @@ -23,7 +23,7 @@ class OverflowButton : public views::CustomButton { explicit OverflowButton(views::ButtonListener* listener); virtual ~OverflowButton(); - void SetShelfAlignment(ShelfAlignment alignment); + void OnShelfAlignmentChanged(); private: void PaintBackground(gfx::Canvas* canvas, int alpha); @@ -31,7 +31,6 @@ class OverflowButton : public views::CustomButton { // views::View overrides: virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; - ShelfAlignment alignment_; const gfx::ImageSkia* image_; DISALLOW_COPY_AND_ASSIGN(OverflowButton); diff --git a/ash/launcher/tabbed_launcher_button.cc b/ash/launcher/tabbed_launcher_button.cc index 7bd5682..517607c 100644 --- a/ash/launcher/tabbed_launcher_button.cc +++ b/ash/launcher/tabbed_launcher_button.cc @@ -115,17 +115,20 @@ const gfx::ImageSkia* TabbedLauncherButton* TabbedLauncherButton::Create( views::ButtonListener* listener, LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager, IncognitoState is_incognito) { - TabbedLauncherButton* button = - new TabbedLauncherButton(listener, host, is_incognito); + TabbedLauncherButton* button = new TabbedLauncherButton( + listener, host, shelf_layout_manager, is_incognito); button->Init(); return button; } -TabbedLauncherButton::TabbedLauncherButton(views::ButtonListener* listener, - LauncherButtonHost* host, - IncognitoState is_incognito) - : LauncherButton(listener, host), +TabbedLauncherButton::TabbedLauncherButton( + views::ButtonListener* listener, + LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager, + IncognitoState is_incognito) + : LauncherButton(listener, host, shelf_layout_manager), is_incognito_(is_incognito) { set_accessibility_focusable(true); } diff --git a/ash/launcher/tabbed_launcher_button.h b/ash/launcher/tabbed_launcher_button.h index f78ec07..6eb0b9e 100644 --- a/ash/launcher/tabbed_launcher_button.h +++ b/ash/launcher/tabbed_launcher_button.h @@ -37,6 +37,7 @@ class TabbedLauncherButton : public LauncherButton { static TabbedLauncherButton* Create(views::ButtonListener* listener, LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager, IncognitoState is_incognito); virtual ~TabbedLauncherButton(); @@ -49,6 +50,7 @@ class TabbedLauncherButton : public LauncherButton { protected: TabbedLauncherButton(views::ButtonListener* listener, LauncherButtonHost* host, + ShelfLayoutManager* shelf_layout_manager, IncognitoState is_incognito); // View override. virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE; diff --git a/ash/root_window_controller.cc b/ash/root_window_controller.cc index 7911f89..14b2006 100644 --- a/ash/root_window_controller.cc +++ b/ash/root_window_controller.cc @@ -483,7 +483,7 @@ bool RootWindowController::SetShelfAlignment(ShelfAlignment alignment) { } ShelfAlignment RootWindowController::GetShelfAlignment() { - return shelf_->alignment(); + return shelf_->GetAlignment(); } //////////////////////////////////////////////////////////////////////////////// diff --git a/ash/wm/app_list_controller.cc b/ash/wm/app_list_controller.cc index e0785c8..bf02979 100644 --- a/ash/wm/app_list_controller.cc +++ b/ash/wm/app_list_controller.cc @@ -45,19 +45,11 @@ ui::Layer* GetLayer(views::Widget* widget) { views::BubbleBorder::ArrowLocation GetBubbleArrowLocation( aura::Window* window) { DCHECK(Shell::HasInstance()); - ShelfAlignment shelf_alignment = Shell::GetInstance()->GetShelfAlignment( - window->GetRootWindow()); - switch (shelf_alignment) { - case ash::SHELF_ALIGNMENT_BOTTOM: - return views::BubbleBorder::BOTTOM_CENTER; - case ash::SHELF_ALIGNMENT_LEFT: - return views::BubbleBorder::LEFT_CENTER; - case ash::SHELF_ALIGNMENT_RIGHT: - return views::BubbleBorder::RIGHT_CENTER; - default: - NOTREACHED() << "Unknown shelf alignment " << shelf_alignment; - return views::BubbleBorder::BOTTOM_CENTER; - } + return ShelfLayoutManager::ForLauncher(window)-> + SelectValueForShelfAlignment( + views::BubbleBorder::BOTTOM_CENTER, + views::BubbleBorder::LEFT_CENTER, + views::BubbleBorder::RIGHT_CENTER); } // Offset given |rect| towards shelf. diff --git a/ash/wm/shelf_layout_manager.cc b/ash/wm/shelf_layout_manager.cc index eec85b4..1937a7e 100644 --- a/ash/wm/shelf_layout_manager.cc +++ b/ash/wm/shelf_layout_manager.cc @@ -124,8 +124,7 @@ class ShelfLayoutManager::UpdateShelfObserver virtual void OnImplicitAnimationsCompleted() OVERRIDE { if (shelf_) { - shelf_->UpdateShelfBackground( - internal::BackgroundAnimator::CHANGE_ANIMATE); + shelf_->UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); } delete this; } @@ -309,7 +308,7 @@ void ShelfLayoutManager::UpdateAutoHideState() { void ShelfLayoutManager::SetWindowOverlapsShelf(bool value) { window_overlaps_shelf_ = value; - UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); + UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); } void ShelfLayoutManager::AddObserver(Observer* observer) { @@ -328,12 +327,12 @@ void ShelfLayoutManager::StartGestureDrag(const ui::GestureEvent& gesture) { gesture_drag_amount_ = 0.f; gesture_drag_auto_hide_state_ = visibility_state() == SHELF_AUTO_HIDE ? auto_hide_state() : SHELF_AUTO_HIDE_SHOWN; - UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); + UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); } ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( const ui::GestureEvent& gesture) { - bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; + bool horizontal = alignment_ == SHELF_ALIGNMENT_BOTTOM; gesture_drag_amount_ += horizontal ? gesture.details().scroll_y() : gesture.details().scroll_x(); LayoutShelf(); @@ -359,7 +358,7 @@ ShelfLayoutManager::DragState ShelfLayoutManager::UpdateGestureDrag( } void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { - bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; + bool horizontal = alignment_ == SHELF_ALIGNMENT_BOTTOM; 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% @@ -373,7 +372,7 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { should_change = drag_ratio > kDragHideThreshold; } else { bool correct_direction = false; - switch (alignment()) { + switch (alignment_) { case SHELF_ALIGNMENT_BOTTOM: case SHELF_ALIGNMENT_RIGHT: correct_direction = gesture_drag_amount_ < 0; @@ -391,7 +390,7 @@ void ShelfLayoutManager::CompleteGestureDrag(const ui::GestureEvent& gesture) { } else { if (horizontal) should_change = gesture.details().velocity_y() < 0; - else if (alignment() == SHELF_ALIGNMENT_LEFT) + else if (alignment_ == SHELF_ALIGNMENT_LEFT) should_change = gesture.details().velocity_x() > 0; else should_change = gesture.details().velocity_x() < 0; @@ -433,7 +432,7 @@ void ShelfLayoutManager::CancelGestureDrag() { status_settings(GetLayer(status_area_widget_)->GetAnimator()); LayoutShelf(); UpdateVisibilityState(); - UpdateShelfBackground(internal::BackgroundAnimator::CHANGE_ANIMATE); + UpdateShelfBackground(BackgroundAnimator::CHANGE_ANIMATE); } //////////////////////////////////////////////////////////////////////////////// @@ -477,6 +476,15 @@ void ShelfLayoutManager::OnWindowActivated(aura::Window* active, UpdateAutoHideStateNow(); } +bool ShelfLayoutManager::IsHorizontalAlignment() const { + return alignment_ == SHELF_ALIGNMENT_BOTTOM; +} + +// static +ShelfLayoutManager* ShelfLayoutManager::ForLauncher(aura::Window* window) { + return RootWindowController::ForLauncher(window)->shelf(); +} + //////////////////////////////////////////////////////////////////////////////// // ShelfLayoutManager, private: @@ -517,12 +525,11 @@ void ShelfLayoutManager::SetState(ShelfVisibilityState visibility_state) { // Animating the background when transitioning from auto-hide & hidden to // visible is janky. Update the background immediately in this case. - internal::BackgroundAnimator::ChangeType change_type = + BackgroundAnimator::ChangeType change_type = (state_.visibility_state == SHELF_AUTO_HIDE && state_.auto_hide_state == SHELF_AUTO_HIDE_HIDDEN && state.visibility_state == SHELF_VISIBLE) ? - internal::BackgroundAnimator::CHANGE_IMMEDIATE : - internal::BackgroundAnimator::CHANGE_ANIMATE; + BackgroundAnimator::CHANGE_IMMEDIATE : BackgroundAnimator::CHANGE_ANIMATE; StopAnimating(); State old_state = state_; @@ -694,7 +701,7 @@ void ShelfLayoutManager::CalculateTargetBounds( void ShelfLayoutManager::UpdateTargetBoundsForGesture( TargetBounds* target_bounds) const { CHECK_EQ(GESTURE_DRAG_IN_PROGRESS, gesture_drag_status_); - bool horizontal = alignment() == SHELF_ALIGNMENT_BOTTOM; + bool horizontal = alignment_ == SHELF_ALIGNMENT_BOTTOM; int resistance_free_region = 0; if (gesture_drag_auto_hide_state_ == SHELF_AUTO_HIDE_HIDDEN && @@ -713,7 +720,7 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( bool resist = false; if (horizontal) resist = gesture_drag_amount_ < -resistance_free_region; - else if (alignment() == SHELF_ALIGNMENT_LEFT) + else if (alignment_ == SHELF_ALIGNMENT_LEFT) resist = gesture_drag_amount_ > resistance_free_region; else resist = gesture_drag_amount_ < -resistance_free_region; @@ -752,20 +759,20 @@ void ShelfLayoutManager::UpdateTargetBoundsForGesture( } } else { // Move the launcher with the gesture. - if (alignment() == SHELF_ALIGNMENT_RIGHT) + if (alignment_ == SHELF_ALIGNMENT_RIGHT) target_bounds->launcher_bounds_in_root.Offset(translate, 0); - if ((translate > 0 && alignment() == SHELF_ALIGNMENT_RIGHT) || - (translate < 0 && alignment() == SHELF_ALIGNMENT_LEFT)) { + if ((translate > 0 && alignment_ == SHELF_ALIGNMENT_RIGHT) || + (translate < 0 && alignment_ == SHELF_ALIGNMENT_LEFT)) { // When dragging towards the edge, the statusbar should move. target_bounds->status_bounds_in_root.Offset(translate, 0); } else { // When dragging away from the edge, the launcher width should increase. - float move = alignment() == SHELF_ALIGNMENT_RIGHT ? + float move = alignment_ == SHELF_ALIGNMENT_RIGHT ? std::max(translate, -static_cast<float>(resistance_free_region)) : std::min(translate, static_cast<float>(resistance_free_region)); - if (alignment() == SHELF_ALIGNMENT_RIGHT) { + if (alignment_ == SHELF_ALIGNMENT_RIGHT) { target_bounds->launcher_bounds_in_root.set_width( target_bounds->launcher_bounds_in_root.width() + move - translate); } else { diff --git a/ash/wm/shelf_layout_manager.h b/ash/wm/shelf_layout_manager.h index 2666e8c..0a4a018 100644 --- a/ash/wm/shelf_layout_manager.h +++ b/ash/wm/shelf_layout_manager.h @@ -11,6 +11,7 @@ #include "ash/shell_observer.h" #include "base/basictypes.h" #include "base/compiler_specific.h" +#include "base/logging.h" #include "base/observer_list.h" #include "base/timer.h" #include "ui/aura/layout_manager.h" @@ -76,7 +77,7 @@ class ASH_EXPORT ShelfLayoutManager : // Sets the alignment. Returns true if the alignment is changed. Otherwise, // returns false. bool SetAlignment(ShelfAlignment alignment); - ShelfAlignment alignment() const { return alignment_; } + ShelfAlignment GetAlignment() const { return alignment_; } void set_workspace_controller(WorkspaceController* controller) { workspace_controller_ = controller; @@ -156,6 +157,36 @@ class ASH_EXPORT ShelfLayoutManager : virtual void OnWindowActivated(aura::Window* active, aura::Window* old_active) OVERRIDE; + // TODO(harrym|oshima): These templates will be moved to + // new Shelf class. + // A helper function that provides a shortcut for choosing + // values specific to a shelf alignment. + template<typename T> + T SelectValueForShelfAlignment(T bottom, T left, T right) const { + switch (alignment_) { + case SHELF_ALIGNMENT_BOTTOM: + return bottom; + case SHELF_ALIGNMENT_LEFT: + return left; + case SHELF_ALIGNMENT_RIGHT: + return right; + } + NOTREACHED(); + return right; + } + + template<typename T> + T PrimaryAxisValue(T horizontal, T vertical) const { + return IsHorizontalAlignment() ? horizontal : vertical; + } + + // Is the shelf's alignment horizontal? + bool IsHorizontalAlignment() const; + + // Returns a ShelfLayoutManager on the display which has a launcher for + // given |window|. See RootWindowController::ForLauncher for more info. + static ShelfLayoutManager* ForLauncher(aura::Window* window); + private: class AutoHideEventFilter; class UpdateShelfObserver; @@ -234,10 +265,6 @@ class ASH_EXPORT ShelfLayoutManager : int GetWorkAreaSize(const State& state, int size) const; - int axis_position(int x, int y) const { - return alignment_ == SHELF_ALIGNMENT_BOTTOM ? y : x; - } - // The RootWindow is cached so that we don't invoke Shell::GetInstance() from // our destructor. We avoid that as at the time we're deleted Shell is being // deleted too. |