summaryrefslogtreecommitdiff
path: root/chromium/ash/launcher/launcher_model.cc
diff options
context:
space:
mode:
authorAndras Becsi <andras.becsi@digia.com>2013-12-11 21:33:03 +0100
committerAndras Becsi <andras.becsi@digia.com>2013-12-13 12:34:07 +0100
commitf2a33ff9cbc6d19943f1c7fbddd1f23d23975577 (patch)
tree0586a32aa390ade8557dfd6b4897f43a07449578 /chromium/ash/launcher/launcher_model.cc
parent5362912cdb5eea702b68ebe23702468d17c3017a (diff)
downloadqtwebengine-chromium-f2a33ff9cbc6d19943f1c7fbddd1f23d23975577.tar.gz
Update Chromium to branch 1650 (31.0.1650.63)
Change-Id: I57d8c832eaec1eb2364e0a8e7352a6dd354db99f Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
Diffstat (limited to 'chromium/ash/launcher/launcher_model.cc')
-rw-r--r--chromium/ash/launcher/launcher_model.cc184
1 files changed, 0 insertions, 184 deletions
diff --git a/chromium/ash/launcher/launcher_model.cc b/chromium/ash/launcher/launcher_model.cc
deleted file mode 100644
index 9607de6fcfe..00000000000
--- a/chromium/ash/launcher/launcher_model.cc
+++ /dev/null
@@ -1,184 +0,0 @@
-// Copyright (c) 2012 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "ash/launcher/launcher_model.h"
-
-#include <algorithm>
-
-#include "ash/ash_switches.h"
-#include "ash/launcher/launcher_model_observer.h"
-
-namespace ash {
-
-namespace {
-
-int LauncherItemTypeToWeight(LauncherItemType type) {
- if (ash::switches::UseAlternateShelfLayout()) {
- switch (type) {
- case TYPE_APP_LIST:
- return 0;
- case TYPE_BROWSER_SHORTCUT:
- case TYPE_APP_SHORTCUT:
- case TYPE_WINDOWED_APP:
- return 1;
- case TYPE_TABBED:
- case TYPE_PLATFORM_APP:
- return 2;
- case TYPE_APP_PANEL:
- return 3;
- }
- } else {
- switch (type) {
- case TYPE_BROWSER_SHORTCUT:
- case TYPE_APP_SHORTCUT:
- case TYPE_WINDOWED_APP:
- return 0;
- case TYPE_TABBED:
- case TYPE_PLATFORM_APP:
- return 1;
- case TYPE_APP_LIST:
- return 2;
- case TYPE_APP_PANEL:
- return 3;
- }
- }
-
- NOTREACHED() << "Invalid type " << type;
- return 1;
-}
-
-bool CompareByWeight(const LauncherItem& a, const LauncherItem& b) {
- return LauncherItemTypeToWeight(a.type) < LauncherItemTypeToWeight(b.type);
-}
-
-} // namespace
-
-LauncherModel::LauncherModel() : next_id_(1), status_(STATUS_NORMAL) {
- LauncherItem app_list;
- app_list.type = TYPE_APP_LIST;
- app_list.is_incognito = false;
- AddAt(0, app_list);
-}
-
-LauncherModel::~LauncherModel() {
-}
-
-int LauncherModel::Add(const LauncherItem& item) {
- return AddAt(items_.size(), item);
-}
-
-int LauncherModel::AddAt(int index, const LauncherItem& item) {
- index = ValidateInsertionIndex(item.type, index);
- items_.insert(items_.begin() + index, item);
- items_[index].id = next_id_++;
- FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
- LauncherItemAdded(index));
- return index;
-}
-
-void LauncherModel::RemoveItemAt(int index) {
- DCHECK(index >= 0 && index < item_count());
- // The app list and browser shortcut can't be removed.
- DCHECK(items_[index].type != TYPE_APP_LIST &&
- items_[index].type != TYPE_BROWSER_SHORTCUT);
- LauncherID id = items_[index].id;
- items_.erase(items_.begin() + index);
- FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
- LauncherItemRemoved(index, id));
-}
-
-void LauncherModel::Move(int index, int target_index) {
- if (index == target_index)
- return;
- // TODO: this needs to enforce valid ranges.
- LauncherItem item(items_[index]);
- items_.erase(items_.begin() + index);
- items_.insert(items_.begin() + target_index, item);
- FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
- LauncherItemMoved(index, target_index));
-}
-
-void LauncherModel::Set(int index, const LauncherItem& item) {
- DCHECK(index >= 0 && index < item_count());
- int new_index = item.type == items_[index].type ?
- index : ValidateInsertionIndex(item.type, index);
-
- LauncherItem old_item(items_[index]);
- items_[index] = item;
- items_[index].id = old_item.id;
- FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
- LauncherItemChanged(index, old_item));
-
- // If the type changes confirm that the item is still in the right order.
- if (new_index != index) {
- // The move function works by removing one item and then inserting it at the
- // new location. However - by removing the item first the order will change
- // so that our target index needs to be corrected.
- // TODO(skuhne): Moving this into the Move function breaks lots of unit
- // tests. So several functions were already using this incorrectly.
- // That needs to be cleaned up.
- if (index < new_index)
- new_index--;
-
- Move(index, new_index);
- }
-}
-
-int LauncherModel::ItemIndexByID(LauncherID id) const {
- LauncherItems::const_iterator i = ItemByID(id);
- return i == items_.end() ? -1 : static_cast<int>(i - items_.begin());
-}
-
-LauncherItems::const_iterator LauncherModel::ItemByID(int id) const {
- for (LauncherItems::const_iterator i = items_.begin();
- i != items_.end(); ++i) {
- if (i->id == id)
- return i;
- }
- return items_.end();
-}
-
-int LauncherModel::FirstPanelIndex() const {
- LauncherItem weight_dummy;
- weight_dummy.type = TYPE_APP_PANEL;
- return std::lower_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin();
-}
-
-void LauncherModel::SetStatus(Status status) {
- if (status_ == status)
- return;
-
- status_ = status;
- FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
- LauncherStatusChanged());
-}
-
-void LauncherModel::AddObserver(LauncherModelObserver* observer) {
- observers_.AddObserver(observer);
-}
-
-void LauncherModel::RemoveObserver(LauncherModelObserver* observer) {
- observers_.RemoveObserver(observer);
-}
-
-int LauncherModel::ValidateInsertionIndex(LauncherItemType type,
- int index) const {
- DCHECK(index >= 0 && index <= item_count() +
- (ash::switches::UseAlternateShelfLayout() ? 1 : 0));
-
- // Clamp |index| to the allowed range for the type as determined by |weight|.
- LauncherItem weight_dummy;
- weight_dummy.type = type;
- index = std::max(std::lower_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin(),
- static_cast<LauncherItems::difference_type>(index));
- index = std::min(std::upper_bound(items_.begin(), items_.end(), weight_dummy,
- CompareByWeight) - items_.begin(),
- static_cast<LauncherItems::difference_type>(index));
-
- return index;
-}
-
-} // namespace ash