diff options
Diffstat (limited to 'ash/app_list')
-rw-r--r-- | ash/app_list/app_list_item_model.cc | 11 | ||||
-rw-r--r-- | ash/app_list/app_list_item_model.h | 22 | ||||
-rw-r--r-- | ash/app_list/app_list_item_model_observer.h | 9 | ||||
-rw-r--r-- | ash/app_list/app_list_item_view.cc | 16 | ||||
-rw-r--r-- | ash/app_list/app_list_item_view.h | 1 | ||||
-rw-r--r-- | ash/app_list/app_list_model.cc | 8 | ||||
-rw-r--r-- | ash/app_list/app_list_model.h | 5 | ||||
-rw-r--r-- | ash/app_list/app_list_model_view.cc | 13 | ||||
-rw-r--r-- | ash/app_list/app_list_view.cc | 3 | ||||
-rw-r--r-- | ash/app_list/app_list_view_delegate.h | 9 |
10 files changed, 74 insertions, 23 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, |