summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 05:21:04 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-16 05:21:04 +0000
commit662b592e04ddcbd7e3e5c3dc7fe09d20852bc8ad (patch)
treea1854f7e4bdf5b15c40c8a77cd9fd685c625b4f6 /ash
parentccf17255c487be73a69c5b45bee7546eb0a03999 (diff)
downloadchromium_src-662b592e04ddcbd7e3e5c3dc7fe09d20852bc8ad.zip
chromium_src-662b592e04ddcbd7e3e5c3dc7fe09d20852bc8ad.tar.gz
chromium_src-662b592e04ddcbd7e3e5c3dc7fe09d20852bc8ad.tar.bz2
ash: Open app list and highlight the installed app.
- Add a NOTIFICATION_APP_INSTALLED_TO_APPLIST similar to NOTIFICATION_APP_INSTALLED_TO_NTP; - OpenAppInstalledNTP -> OpenAppInstalledUI, which opens applist on ash and fires NOTIFICATION_APP_INSTALLED_TO_APPLIST; - Make AppListModelBuilder observes extension loading/unloading and NOTIFICATION_APP_INSTALLED_TO_APPLIST and updates model accordingly; - Make AppListView SetModel on its delegate explicitly; - Make AppListViewDelegate hosts a builder as its member and pass the model used by app list to the builder; BUG=117087 TEST=Install an app and app list should open and highlight the installed app. Review URL: http://codereview.chromium.org/9700066 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@127111 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/app_list/app_list_item_model.cc11
-rw-r--r--ash/app_list/app_list_item_model.h22
-rw-r--r--ash/app_list/app_list_item_model_observer.h9
-rw-r--r--ash/app_list/app_list_item_view.cc16
-rw-r--r--ash/app_list/app_list_item_view.h1
-rw-r--r--ash/app_list/app_list_model.cc8
-rw-r--r--ash/app_list/app_list_model.h5
-rw-r--r--ash/app_list/app_list_model_view.cc13
-rw-r--r--ash/app_list/app_list_view.cc3
-rw-r--r--ash/app_list/app_list_view_delegate.h9
-rw-r--r--ash/shell/app_list.cc15
11 files changed, 85 insertions, 27 deletions
diff --git a/ash/app_list/app_list_item_model.cc b/ash/app_list/app_list_item_model.cc
index 1820913..c8c5938 100644
--- a/ash/app_list/app_list_item_model.cc
+++ b/ash/app_list/app_list_item_model.cc
@@ -8,7 +8,7 @@
namespace ash {
-AppListItemModel::AppListItemModel() {
+AppListItemModel::AppListItemModel() : highlighted_(false) {
}
AppListItemModel::~AppListItemModel() {
@@ -26,6 +26,15 @@ void AppListItemModel::SetTitle(const std::string& title) {
ItemTitleChanged());
}
+void AppListItemModel::SetHighlighted(bool highlighted) {
+ if (highlighted_ == highlighted)
+ return;
+
+ highlighted_ = highlighted;
+ FOR_EACH_OBSERVER(AppListItemModelObserver, observers_,
+ ItemHighlightedChanged());
+}
+
void AppListItemModel::AddObserver(AppListItemModelObserver* observer) {
observers_.AddObserver(observer);
}
diff --git a/ash/app_list/app_list_item_model.h b/ash/app_list/app_list_item_model.h
index ebc24608..9dec482 100644
--- a/ash/app_list/app_list_item_model.h
+++ b/ash/app_list/app_list_item_model.h
@@ -28,9 +28,20 @@ class ASH_EXPORT AppListItemModel {
AppListItemModel();
virtual ~AppListItemModel();
- // Changes icon and title for the model.
void SetIcon(const SkBitmap& icon);
+ const SkBitmap& icon() const {
+ return icon_;
+ }
+
void SetTitle(const std::string& title);
+ const std::string& title() const {
+ return title_;
+ }
+
+ void SetHighlighted(bool highlighted);
+ bool highlighted() const {
+ return highlighted_;
+ }
void AddObserver(AppListItemModelObserver* observer);
void RemoveObserver(AppListItemModelObserver* observer);
@@ -39,17 +50,10 @@ class ASH_EXPORT AppListItemModel {
// Note the menu model is owned by this item.
virtual ui::MenuModel* GetContextMenuModel();
- const SkBitmap& icon() const {
- return icon_;
- }
-
- const std::string& title() const {
- return title_;
- }
-
private:
SkBitmap icon_;
std::string title_;
+ bool highlighted_;
ObserverList<AppListItemModelObserver> observers_;
diff --git a/ash/app_list/app_list_item_model_observer.h b/ash/app_list/app_list_item_model_observer.h
index 7a22fa9..0162a31 100644
--- a/ash/app_list/app_list_item_model_observer.h
+++ b/ash/app_list/app_list_item_model_observer.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// 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.
@@ -12,12 +12,15 @@ namespace ash {
class ASH_EXPORT AppListItemModelObserver {
public:
- // Invoked after app list item's icon is changed.
+ // Invoked after item's icon is changed.
virtual void ItemIconChanged() = 0;
- // Invoked after app list item's title is changed.
+ // Invoked after item's title is changed.
virtual void ItemTitleChanged() = 0;
+ // Invoked after item's highlighted state is changed.
+ virtual void ItemHighlightedChanged() = 0;
+
protected:
virtual ~AppListItemModelObserver() {}
};
diff --git a/ash/app_list/app_list_item_view.cc b/ash/app_list/app_list_item_view.cc
index bac1724..2bd21cc 100644
--- a/ash/app_list/app_list_item_view.cc
+++ b/ash/app_list/app_list_item_view.cc
@@ -34,6 +34,8 @@ const SkColor kHoverAndPushedColor = SkColorSetARGB(0x33, 0xFF, 0xFF, 0xFF);
// 0.1 white
const SkColor kSelectedColor = SkColorSetARGB(0x20, 0xFF, 0xFF, 0xFF);
+const SkColor kHighlightedColor = kHoverAndPushedColor;
+
gfx::Font GetTitleFont() {
static gfx::Font* font = NULL;
if (!font) {
@@ -118,6 +120,10 @@ void AppListItemView::ItemTitleChanged() {
title_->SetText(UTF8ToUTF16(model_->title()));
}
+void AppListItemView::ItemHighlightedChanged() {
+ SchedulePaint();
+}
+
std::string AppListItemView::GetClassName() const {
return kViewClassName;
}
@@ -146,7 +152,9 @@ void AppListItemView::Layout() {
void AppListItemView::OnPaint(gfx::Canvas* canvas) {
gfx::Rect rect(GetContentsBounds());
- if (hover_animation_->is_animating()) {
+ if (model_->highlighted()) {
+ canvas->FillRect(rect, kHighlightedColor);
+ } else if (hover_animation_->is_animating()) {
int alpha = SkColorGetA(kHoverAndPushedColor) *
hover_animation_->GetCurrentValue();
canvas->FillRect(rect, SkColorSetA(kHoverAndPushedColor, alpha));
@@ -175,10 +183,12 @@ void AppListItemView::ShowContextMenuForView(views::View* source,
}
void AppListItemView::StateChanged() {
- if (state() == BS_HOT || state() == BS_PUSHED)
+ if (state() == BS_HOT || state() == BS_PUSHED) {
list_model_view_->SetSelectedItem(this);
- else
+ } else {
list_model_view_->ClearSelectedItem(this);
+ model_->SetHighlighted(false);
+ }
}
} // namespace ash
diff --git a/ash/app_list/app_list_item_view.h b/ash/app_list/app_list_item_view.h
index cdc315a..53ae173 100644
--- a/ash/app_list/app_list_item_view.h
+++ b/ash/app_list/app_list_item_view.h
@@ -55,6 +55,7 @@ class AppListItemView : public views::CustomButton,
// AppListItemModelObserver overrides:
virtual void ItemIconChanged() OVERRIDE;
virtual void ItemTitleChanged() OVERRIDE;
+ virtual void ItemHighlightedChanged() OVERRIDE;
// views::View overrides:
virtual std::string GetClassName() const OVERRIDE;
diff --git a/ash/app_list/app_list_model.cc b/ash/app_list/app_list_model.cc
index 2d93fbe..ff42d92 100644
--- a/ash/app_list/app_list_model.cc
+++ b/ash/app_list/app_list_model.cc
@@ -16,6 +16,14 @@ void AppListModel::AddItem(AppListItemModel* item) {
items_.Add(item);
}
+void AppListModel::AddItemAt(int index, AppListItemModel* item) {
+ items_.AddAt(index, item);
+}
+
+void AppListModel::DeleteItemAt(int index) {
+ items_.DeleteAt(index);
+}
+
AppListItemModel* AppListModel::GetItem(int index) {
return items_.item_at(index);
}
diff --git a/ash/app_list/app_list_model.h b/ash/app_list/app_list_model.h
index fbced97a..6ec296c 100644
--- a/ash/app_list/app_list_model.h
+++ b/ash/app_list/app_list_model.h
@@ -6,9 +6,9 @@
#define ASH_APP_LIST_APP_LIST_MODEL_H_
#pragma once
-#include "base/basictypes.h"
#include "ash/app_list/app_list_item_model.h"
#include "ash/ash_export.h"
+#include "base/basictypes.h"
#include "ui/base/models/list_model.h"
namespace ash {
@@ -23,6 +23,9 @@ class ASH_EXPORT AppListModel {
// Adds an item to the model. The model takes ownership of |item|.
void AddItem(AppListItemModel* item);
+ void AddItemAt(int index, AppListItemModel* item);
+
+ void DeleteItemAt(int index);
AppListItemModel* GetItem(int index);
diff --git a/ash/app_list/app_list_model_view.cc b/ash/app_list/app_list_model_view.cc
index 7ff7741..20248de 100644
--- a/ash/app_list/app_list_model_view.cc
+++ b/ash/app_list/app_list_model_view.cc
@@ -182,11 +182,20 @@ void AppListModelView::OnPaintFocusBorder(gfx::Canvas* canvas) {
}
void AppListModelView::ListItemsAdded(int start, int count) {
- Update();
+ for (int i = start; i < start + count; ++i) {
+ AddChildViewAt(new AppListItemView(this, model_->GetItem(i), listener_),
+ i);
+ }
+ Layout();
+ SchedulePaint();
}
void AppListModelView::ListItemsRemoved(int start, int count) {
- Update();
+ for (int i = 0; i < count; ++i)
+ delete child_at(start);
+
+ Layout();
+ SchedulePaint();
}
void AppListModelView::ListItemsChanged(int start, int count) {
diff --git a/ash/app_list/app_list_view.cc b/ash/app_list/app_list_view.cc
index 83ac1d2..c2eb832 100644
--- a/ash/app_list/app_list_view.cc
+++ b/ash/app_list/app_list_view.cc
@@ -95,7 +95,8 @@ void AppListView::Init(const gfx::Rect& bounds) {
void AppListView::UpdateModel() {
if (delegate_.get()) {
scoped_ptr<AppListModel> new_model(new AppListModel);
- delegate_->BuildAppListModel(std::string(), new_model.get());
+ delegate_->SetModel(new_model.get());
+ delegate_->UpdateModel(std::string());
model_view_->SetModel(new_model.get());
model_.reset(new_model.release());
}
diff --git a/ash/app_list/app_list_view_delegate.h b/ash/app_list/app_list_view_delegate.h
index 112bfcf..1950a12 100644
--- a/ash/app_list/app_list_view_delegate.h
+++ b/ash/app_list/app_list_view_delegate.h
@@ -20,9 +20,12 @@ class ASH_EXPORT AppListViewDelegate {
// AppListView owns the delegate.
virtual ~AppListViewDelegate() {}
- // Invoked to ask the delegate to populate the |model| for given |query|.
- virtual void BuildAppListModel(const std::string& query,
- AppListModel* model) = 0;
+ // Invoked to set the model that AppListView uses.
+ // Note that AppListView owns the model.
+ virtual void SetModel(AppListModel* model) = 0;
+
+ // Invoked to ask the delegate to populate the model for given |query|.
+ virtual void UpdateModel(const std::string& query) = 0;
// Invoked an AppListeItemModelView is activated by click or enter key.
virtual void OnAppListItemActivated(AppListItemModel* item,
diff --git a/ash/shell/app_list.cc b/ash/shell/app_list.cc
index f4f8bd6..80ff70e 100644
--- a/ash/shell/app_list.cc
+++ b/ash/shell/app_list.cc
@@ -106,12 +106,17 @@ class WindowTypeLauncherItem : public ash::AppListItemModel {
class ExampleAppListViewDelegate : public ash::AppListViewDelegate {
public:
- ExampleAppListViewDelegate() {}
+ ExampleAppListViewDelegate() : model_(NULL) {}
private:
// Overridden from ash::AppListViewDelegate:
- virtual void BuildAppListModel(const std::string& query,
- AppListModel* model) OVERRIDE {
+ virtual void SetModel(AppListModel* model) OVERRIDE {
+ model_ = model;
+ }
+
+ virtual void UpdateModel(const std::string& query) OVERRIDE {
+ DCHECK(model_ && model_->item_count() == 0);
+
for (int i = 0;
i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE);
++i) {
@@ -120,7 +125,7 @@ class ExampleAppListViewDelegate : public ash::AppListViewDelegate {
std::string title = WindowTypeLauncherItem::GetTitle(type);
if (title.find(query) != std::string::npos)
- model->AddItem(new WindowTypeLauncherItem(type));
+ model_->AddItem(new WindowTypeLauncherItem(type));
}
}
@@ -129,6 +134,8 @@ class ExampleAppListViewDelegate : public ash::AppListViewDelegate {
static_cast<WindowTypeLauncherItem*>(item)->Activate(event_flags);
}
+ AppListModel* model_;
+
DISALLOW_COPY_AND_ASSIGN(ExampleAppListViewDelegate);
};