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

Unified Diff: ash/launcher/launcher_model.cc

Issue 10829268: chromeos: Sync animation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: wrap up + rebase Created 8 years, 4 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
Index: ash/launcher/launcher_model.cc
diff --git a/ash/launcher/launcher_model.cc b/ash/launcher/launcher_model.cc
index d9aa8adb3a618709f3763ca10b5ffb61b7be1ece..bc6cb99c5eae83c3ae9d99891dfb78a285edcf3c 100644
--- a/ash/launcher/launcher_model.cc
+++ b/ash/launcher/launcher_model.cc
@@ -7,28 +7,31 @@
#include <algorithm>
#include "ash/launcher/launcher_model_observer.h"
-#include "ui/aura/window.h"
namespace ash {
namespace {
+const int kMaxLoadingPlaceholder = 4;
+
int LauncherItemTypeToWeight(LauncherItemType type) {
switch (type) {
case TYPE_BROWSER_SHORTCUT:
return 0;
case TYPE_APP_SHORTCUT:
return 1;
+ case TYPE_APP_PLACEHOLDER:
+ return 2;
case TYPE_TABBED:
case TYPE_APP_PANEL:
case TYPE_PLATFORM_APP:
- return 2;
- case TYPE_APP_LIST:
return 3;
+ case TYPE_APP_LIST:
+ return 4;
}
NOTREACHED() << "Invalid type " << type;
- return 2;
+ return 3;
}
bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) {
@@ -37,7 +40,7 @@ bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) {
} // namespace
-LauncherModel::LauncherModel() : next_id_(1) {
+LauncherModel::LauncherModel() : next_id_(1), ui_state_(NORMAL) {
LauncherItem app_list;
app_list.type = TYPE_APP_LIST;
app_list.is_incognito = false;
@@ -58,6 +61,13 @@ int LauncherModel::Add(const LauncherItem& item) {
}
int LauncherModel::AddAt(int index, const LauncherItem& item) {
+ // Remove loading placeholders when adding app shortcuts in loading state.
+ if (ui_state_ == LOADING && item.type == TYPE_APP_SHORTCUT) {
+ int placeholders = GetDesiredNumOfPlaceholders();
+ if (placeholders > 0)
+ UpdatePlaceholders(placeholders - 1);
+ }
+
index = ValidateInsertionIndex(item.type, index);
items_.insert(items_.begin() + index, item);
items_[index].id = next_id_++;
@@ -126,6 +136,16 @@ void LauncherModel::RemoveObserver(LauncherModelObserver* observer) {
observers_.RemoveObserver(observer);
}
+void LauncherModel::SetUIState(UIState ui_state) {
+ if (ui_state_ == ui_state)
+ return;
+
+ ui_state_ = ui_state;
+ UpdatePlaceholders(ui_state_ == LOADING ? GetDesiredNumOfPlaceholders() : 0);
+ FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
+ LauncherUIStateChanged());
+}
+
int LauncherModel::ValidateInsertionIndex(LauncherItemType type,
int index) const {
DCHECK(index >= 0 && index <= item_count());
@@ -143,4 +163,37 @@ int LauncherModel::ValidateInsertionIndex(LauncherItemType type,
return index;
}
+int LauncherModel::GetDesiredNumOfPlaceholders() {
+ int desired_placholders = kMaxLoadingPlaceholder;
+
+ for (int i = 0; i < item_count() && desired_placholders; ++i) {
+ if (items_[i].type == TYPE_APP_SHORTCUT)
+ --desired_placholders;
+ }
+
+ return desired_placholders;
+}
+
+void LauncherModel::UpdatePlaceholders(int n) {
+ int count = 0;
+
+ for (int index = item_count() - 1; index >= 0; --index) {
+ if (items_[index].type == TYPE_APP_PLACEHOLDER) {
sky 2012/08/14 20:02:34 Having to toggle the type like this feels hacky. W
xiyuan 2012/08/14 23:11:32 The problem with STATUS_IS_PENDING approach is tha
+ if (count == n)
+ RemoveItemAt(index);
+ else
+ ++count;
+ }
+ }
+
+ while (count < n) {
+ LauncherItem placeholder;
+ placeholder.type = TYPE_APP_PLACEHOLDER;
+ placeholder.is_incognito = false;
+
+ Add(placeholder);
+ ++count;
+ }
+}
+
} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698