Index: ash/launcher/launcher_view.cc |
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc |
index f844b7ed87658bc4dd270de6ec7ca4b4de6bfad5..0d373d5404f6e1e13a3809a23d70049cd07ce34e 100644 |
--- a/ash/launcher/launcher_view.cc |
+++ b/ash/launcher/launcher_view.cc |
@@ -6,6 +6,7 @@ |
#include "ash/launcher/launcher_button.h" |
#include "ash/launcher/launcher_delegate.h" |
+#include "ash/launcher/launcher_icon_observer.h" |
#include "ash/launcher/launcher_model.h" |
#include "ash/launcher/tabbed_launcher_button.h" |
#include "ash/shell.h" |
@@ -255,6 +256,7 @@ LauncherView::LauncherView(LauncherModel* model, LauncherDelegate* delegate) |
: model_(model), |
delegate_(delegate), |
view_model_(new views::ViewModel), |
+ last_visible_index_(-1), |
overflow_button_(NULL), |
dragging_(NULL), |
drag_view_(NULL), |
@@ -305,7 +307,7 @@ void LauncherView::Init() { |
gfx::Rect LauncherView::GetIdealBoundsOfItemIcon(LauncherID id) { |
int index = model_->ItemIndexByID(id); |
- if (index == -1 || !view_model_->view_at(index)->visible()) |
+ if (index == -1 || index > last_visible_index_) |
return gfx::Rect(); |
const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); |
DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); |
@@ -347,6 +349,8 @@ void LauncherView::LayoutToIdealBounds() { |
CalculateIdealBounds(&ideal_bounds); |
views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
+ OnLauncherIconPositionsChanged()); |
} |
void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
@@ -364,19 +368,19 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
} |
bounds->overflow_bounds.set_size(gfx::Size(kButtonWidth, kButtonHeight)); |
- int last_visible_index = DetermineLastVisibleIndex( |
+ last_visible_index_ = DetermineLastVisibleIndex( |
available_width - kLeadingInset - bounds->overflow_bounds.width() - |
kButtonSpacing - kButtonWidth); |
bool show_overflow = |
- (last_visible_index + 1 != view_model_->view_size()); |
+ (last_visible_index_ + 1 != view_model_->view_size()); |
int app_list_index = view_model_->view_size() - 1; |
if (overflow_button_->visible() != show_overflow) { |
// Only change visibility of the views if the visibility of the overflow |
// button changes. Otherwise we'll effect the insertion animation, which |
// changes the visibility. |
- for (int i = 0; i <= last_visible_index; ++i) |
+ for (int i = 0; i <= last_visible_index_; ++i) |
view_model_->view_at(i)->SetVisible(true); |
- for (int i = last_visible_index + 1; i < view_model_->view_size(); ++i) { |
+ for (int i = last_visible_index_ + 1; i < view_model_->view_size(); ++i) { |
if (i != app_list_index) |
view_model_->view_at(i)->SetVisible(false); |
} |
@@ -386,8 +390,8 @@ void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { |
DCHECK_NE(0, view_model_->view_size()); |
// We always want the app list visible. |
gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index); |
- x = last_visible_index == -1 ? |
- kLeadingInset : view_model_->ideal_bounds(last_visible_index).right(); |
+ x = last_visible_index_ == -1 ? |
+ kLeadingInset : view_model_->ideal_bounds(last_visible_index_).right(); |
app_list_bounds.set_x(x); |
view_model_->set_ideal_bounds(app_list_index, app_list_bounds); |
x = app_list_bounds.right() + kButtonSpacing; |
@@ -404,6 +408,14 @@ int LauncherView::DetermineLastVisibleIndex(int max_x) { |
return index; |
} |
+void LauncherView::AddIconObserver(LauncherIconObserver* observer) { |
+ observers_.AddObserver(observer); |
+} |
+ |
+void LauncherView::RemoveIconObserver(LauncherIconObserver* observer) { |
+ observers_.RemoveObserver(observer); |
+} |
+ |
void LauncherView::AnimateToIdealBounds() { |
IdealBounds ideal_bounds; |
CalculateIdealBounds(&ideal_bounds); |
@@ -412,6 +424,8 @@ void LauncherView::AnimateToIdealBounds() { |
view_model_->ideal_bounds(i)); |
} |
overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_, |
+ OnLauncherIconPositionsChanged()); |
} |
views::View* LauncherView::CreateViewForItem(const LauncherItem& item) { |