summaryrefslogtreecommitdiffstats
path: root/ash/launcher/launcher_model.cc
blob: ec19026d513f3dceb661cc92147c83412b48fbbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright (c) 2011 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 "ui/aura/window.h"
#include "ash/launcher/launcher_model_observer.h"

namespace aura_shell {

LauncherModel::LauncherModel() {
}

LauncherModel::~LauncherModel() {
}

void LauncherModel::Add(int index, const LauncherItem& item) {
  DCHECK(index >= 0 && index <= item_count());
  items_.insert(items_.begin() + index, item);
  FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
                    LauncherItemAdded(index));
}

void LauncherModel::RemoveItemAt(int index) {
  DCHECK(index >= 0 && index < item_count());
  items_.erase(items_.begin() + index);
  FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
                    LauncherItemRemoved(index));
}

void LauncherModel::Move(int index, int target_index) {
  if (index == target_index)
    return;
  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::SetTabbedImages(int index,
                                    const LauncherTabbedImages& images) {
  DCHECK(index >= 0 && index < item_count());
  DCHECK_EQ(TYPE_TABBED, items_[index].type);
  items_[index].tab_images = images;
  FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
                    LauncherItemImagesChanged(index));
}

void LauncherModel::SetAppImage(int index, const SkBitmap& image) {
  DCHECK(index >= 0 && index < item_count());
  DCHECK_EQ(TYPE_APP, items_[index].type);
  items_[index].app_image = image;
  FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
                    LauncherItemImagesChanged(index));
}

void LauncherModel::SetPendingUpdate(int index) {
  FOR_EACH_OBSERVER(LauncherModelObserver, observers_,
                    LauncherItemImagesWillChange(index));
}

int LauncherModel::ItemIndexByWindow(aura::Window* window) {
  LauncherItems::const_iterator i = ItemByWindow(window);
  return i == items_.end() ? -1 : static_cast<int>((i - items_.begin()));
}

LauncherItems::const_iterator LauncherModel::ItemByWindow(
    aura::Window* window) const {
  for (LauncherItems::const_iterator i = items_.begin();
       i != items_.end(); ++i) {
    if (i->window == window)
      return i;
  }
  return items_.end();
}

void LauncherModel::AddObserver(LauncherModelObserver* observer) {
  observers_.AddObserver(observer);
}

void LauncherModel::RemoveObserver(LauncherModelObserver* observer) {
  observers_.RemoveObserver(observer);
}

}  // namespace aura_shell