Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3269)

Unified Diff: ash/launcher/launcher_view.cc

Issue 11348201: Align panel icons on the right / end. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/launcher/launcher_view.cc
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc
index f51da7a30c5c3d4a2e59100e0c49ce560bfa13d6..b7f4309ebbd0c21727d649f2035178a2cb4c49ef 100644
--- a/ash/launcher/launcher_view.cc
+++ b/ash/launcher/launcher_view.cc
@@ -276,6 +276,7 @@ LauncherView::LauncherView(LauncherModel* model,
view_model_(new views::ViewModel),
first_visible_index_(0),
last_visible_index_(-1),
+ end_align_index_(0),
overflow_button_(NULL),
drag_pointer_(NONE),
drag_view_(NULL),
@@ -301,6 +302,7 @@ LauncherView::~LauncherView() {
void LauncherView::Init() {
model_->AddObserver(this);
+ end_align_index_ = model_->EndAlignedIndex();
const LauncherItems& items(model_->items());
for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
views::View* child = CreateViewForItem(*i);
@@ -310,11 +312,10 @@ void LauncherView::Init() {
}
UpdateFirstButtonPadding();
LauncherStatusChanged();
-
overflow_button_ = new OverflowButton(this);
overflow_button_->set_context_menu_controller(this);
ConfigureChildView(overflow_button_);
- AddChildView(overflow_button_);
+ AddChildViewAt(overflow_button_, end_align_index_);
// We'll layout when our bounds change.
}
@@ -333,7 +334,8 @@ void LauncherView::SetAlignment(ShelfAlignment alignment) {
gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) {
int index = model_->ItemIndexByID(id);
- if (index == -1 || index > last_visible_index_)
+ if (index == -1 || (index > last_visible_index_ &&
+ index < end_align_index_))
return gfx::Rect();
const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index));
DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type);
@@ -407,20 +409,31 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) {
std::max(width() - kLauncherPreferredSize,
ShelfLayoutManager::kAutoHideSize + 1));
int y = primary_axis_coordinate(0, leading_inset());
- for (int i = 0; i < view_model_->view_size(); ++i) {
+ int w = primary_axis_coordinate(kLauncherPreferredSize, width());
+ int h = primary_axis_coordinate(height(), kLauncherPreferredSize);
+ for (int i = 0; i < end_align_index_; ++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);
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);
}
- int app_list_index = view_model_->view_size() - 1;
+ // Right aligned icons
+ int end_position = available_size - kButtonSpacing;
+ x = primary_axis_coordinate(end_position, leading_inset());
+ y = primary_axis_coordinate(0, end_position);
+ for (int i = view_model_->view_size() - 1; i >= end_align_index_; --i) {
+ x = primary_axis_coordinate(x - w - kButtonSpacing, x);
+ y = primary_axis_coordinate(y, y - h - kButtonSpacing);
+ view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
+ end_position = primary_axis_coordinate(x, y);
+ }
+
+ int app_list_index = end_align_index_ - 1;
if (is_overflow_mode()) {
last_visible_index_ = app_list_index - 1;
for (int i = 0; i < view_model_->view_size(); ++i) {
@@ -434,13 +447,12 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) {
primary_axis_coordinate(kLauncherPreferredSize, width()),
primary_axis_coordinate(height(), kLauncherPreferredSize)));
last_visible_index_ = DetermineLastVisibleIndex(
- available_size - leading_inset() - kLauncherPreferredSize -
- kButtonSpacing - kLauncherPreferredSize);
+ end_position - leading_inset() - 2 * kLauncherPreferredSize);
bool show_overflow = (last_visible_index_ + 1 < app_list_index);
for (int i = 0; i < view_model_->view_size(); ++i) {
view_model_->view_at(i)->SetVisible(
- i == app_list_index || i <= last_visible_index_);
+ i <= last_visible_index_ || i >= app_list_index);
}
overflow_button_->SetVisible(show_overflow);
@@ -602,10 +614,12 @@ void LauncherView::ContinueDrag(const ui::LocatedEvent& event) {
// Constrain the location to the range of valid indices for the type.
std::pair<int, int> indices(GetDragRange(current_index));
+ int first_drag_index = indices.first;
int last_drag_index = indices.second;
// If the last index isn't valid, we're overflowing. Constrain to the app list
// (which is the last visible item).
- if (last_drag_index > last_visible_index_)
+ if (first_drag_index < end_align_index_ &&
+ last_drag_index > last_visible_index_)
last_drag_index = last_visible_index_;
int x = 0, y = 0;
if (is_horizontal_alignment()) {
@@ -650,13 +664,12 @@ bool LauncherView::SameDragType(LauncherItemType typea,
LauncherItemType typeb) const {
switch (typea) {
case TYPE_TABBED:
- case TYPE_APP_PANEL:
case TYPE_PLATFORM_APP:
return (typeb == TYPE_TABBED ||
- typeb == TYPE_APP_PANEL ||
typeb == TYPE_PLATFORM_APP);
stevenjb 2012/11/26 18:19:21 nit: one line?
flackr 2012/11/27 18:40:21 Done.
case TYPE_APP_SHORTCUT:
case TYPE_APP_LIST:
+ case TYPE_APP_PANEL:
case TYPE_BROWSER_SHORTCUT:
return typeb == typea;
}
@@ -802,6 +815,7 @@ void LauncherView::LauncherItemAdded(int model_index) {
// the view's visibility.
view->layer()->SetOpacity(0);
view_model_->Add(view, model_index);
+ end_align_index_ = model_->EndAlignedIndex();
// Give the button its ideal bounds. That way if we end up animating the
// button before this animation completes it doesn't appear at some random
@@ -815,7 +829,7 @@ void LauncherView::LauncherItemAdded(int model_index) {
// is hidden, so it visually appears as though we are providing space for
// it. When done we'll fade the view in.
AnimateToIdealBounds();
- if (model_index <= last_visible_index_) {
+ if (model_index <= last_visible_index_ || model_index >= end_align_index_) {
bounds_animator_->SetAnimationDelegate(
view, new StartFadeAnimationDelegate(this, view), true);
} else {
@@ -832,6 +846,7 @@ void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) {
model_index = CancelDrag(model_index);
views::View* view = view_model_->view_at(model_index);
view_model_->Remove(model_index);
+ end_align_index_ = model_->EndAlignedIndex();
// The first animation fades out the view. When done we'll animate the rest of
// the views to their target location.
bounds_animator_->AnimateViewTo(view, view->bounds());

Powered by Google App Engine
This is Rietveld 408576698