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

Unified Diff: ash/launcher/launcher_view.cc

Issue 10116011: Add LauncherIconObserver. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Fix CrOS build Created 8 years, 8 months 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
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ash/launcher/launcher_view.cc
diff --git a/ash/launcher/launcher_view.cc b/ash/launcher/launcher_view.cc
index f844b7ed87658bc4dd270de6ec7ca4b4de6bfad5..d19d334b3d75d0e7beff0cb2be1d2602cde0c713 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);
@@ -364,19 +366,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 +388,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 +406,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);
@@ -541,6 +551,9 @@ void LauncherView::ContinueDrag(const views::MouseEvent& event) {
view_model_->Move(current_index, target_index);
AnimateToIdealBounds();
bounds_animator_->StopAnimatingView(drag_view_);
+
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
+ OnLauncherIconPositionsChanged());
}
bool LauncherView::SameDragType(LauncherItemType typea,
@@ -662,6 +675,8 @@ gfx::Size LauncherView::GetPreferredSize() {
void LauncherView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
LayoutToIdealBounds();
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
+ OnLauncherIconPositionsChanged());
}
views::FocusTraversable* LauncherView::GetPaneFocusTraversable() {
@@ -693,6 +708,9 @@ void LauncherView::LauncherItemAdded(int model_index) {
bounds_animator_->SetAnimationDelegate(
view, new StartFadeAnimationDelegate(this, view), true);
}
+
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
+ OnLauncherIconPositionsChanged());
}
void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) {
@@ -708,6 +726,14 @@ void LauncherView::LauncherItemRemoved(int model_index, LauncherID id) {
bounds_animator_->AnimateViewTo(view, view->bounds());
bounds_animator_->SetAnimationDelegate(
view, new FadeOutAnimationDelegate(this, view), true);
+
+ // The animation will eventually update the ideal bounds, but we want to
+ // force an update immediately so we can notify launcher icon observers.
+ IdealBounds ideal_bounds;
+ CalculateIdealBounds(&ideal_bounds);
+
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
+ OnLauncherIconPositionsChanged());
}
void LauncherView::LauncherItemChanged(int model_index,
@@ -757,6 +783,8 @@ void LauncherView::LauncherItemChanged(int model_index,
void LauncherView::LauncherItemMoved(int start_index, int target_index) {
view_model_->Move(start_index, target_index);
AnimateToIdealBounds();
+ FOR_EACH_OBSERVER(LauncherIconObserver, observers_,
+ OnLauncherIconPositionsChanged());
}
void LauncherView::LauncherItemWillChange(int index) {
« no previous file with comments | « ash/launcher/launcher_view.h ('k') | ash/launcher/launcher_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698