// found in the LICENSE file.
#include <string>
+#include <vector>
-#include "ash/session_state_delegate.h"
+#include "ash/session/session_state_delegate.h"
#include "ash/shell.h"
#include "ash/shell/example_factory.h"
#include "ash/shell/toplevel_window.h"
#include "ui/app_list/search_result.h"
#include "ui/app_list/speech_ui_model.h"
#include "ui/gfx/canvas.h"
-#include "ui/gfx/font.h"
+#include "ui/gfx/font_list.h"
+#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image_skia.h"
-#include "ui/gfx/rect.h"
#include "ui/views/examples/examples_window_with_content.h"
namespace ash {
namespace {
-// WindowTypeLauncherItem is an app item of app list. It carries a window
+// WindowTypeShelfItem is an app item of app list. It carries a window
// launch type and launches corresponding example window when activated.
-class WindowTypeLauncherItem : public app_list::AppListItem {
+class WindowTypeShelfItem : public app_list::AppListItem {
public:
enum Type {
TOPLEVEL_WINDOW = 0,
LAST_TYPE,
};
- explicit WindowTypeLauncherItem(const std::string& id, Type type)
+ explicit WindowTypeShelfItem(const std::string& id, Type type)
: app_list::AppListItem(id),
type_(type) {
std::string title(GetTitle(type));
SetIcon(GetIcon(type), false);
- SetTitleAndFullName(title, title);
+ SetName(title);
}
static gfx::ImageSkia GetIcon(Type type) {
const int kIconSize = 128;
SkBitmap icon;
- icon.setConfig(SkBitmap::kARGB_8888_Config, kIconSize, kIconSize);
- icon.allocPixels();
+ icon.allocN32Pixels(kIconSize, kIconSize);
icon.eraseColor(kColors[static_cast<int>(type) % arraysize(kColors)]);
return gfx::ImageSkia::CreateFrom1xBitmap(icon);
}
private:
Type type_;
- DISALLOW_COPY_AND_ASSIGN(WindowTypeLauncherItem);
+ DISALLOW_COPY_AND_ASSIGN(WindowTypeShelfItem);
};
// ExampleSearchResult is an app list search result. It provides what icon to
// it.
class ExampleSearchResult : public app_list::SearchResult {
public:
- ExampleSearchResult(WindowTypeLauncherItem::Type type,
+ ExampleSearchResult(WindowTypeShelfItem::Type type,
const base::string16& query)
: type_(type) {
- SetIcon(WindowTypeLauncherItem::GetIcon(type_));
+ SetIcon(WindowTypeShelfItem::GetIcon(type_));
base::string16 title =
- base::UTF8ToUTF16(WindowTypeLauncherItem::GetTitle(type_));
+ base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type_));
set_title(title);
Tags title_tags;
set_title_tags(title_tags);
base::string16 details =
- base::UTF8ToUTF16(WindowTypeLauncherItem::GetDetails(type_));
+ base::UTF8ToUTF16(WindowTypeShelfItem::GetDetails(type_));
set_details(details);
Tags details_tags;
details_tags.push_back(Tag(Tag::DIM, 0, details.length()));
set_details_tags(details_tags);
}
- WindowTypeLauncherItem::Type type() const { return type_; }
+ WindowTypeShelfItem::Type type() const { return type_; }
private:
- WindowTypeLauncherItem::Type type_;
+ WindowTypeShelfItem::Type type_;
DISALLOW_COPY_AND_ASSIGN(ExampleSearchResult);
};
class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
public:
ExampleAppListViewDelegate()
- : model_(new app_list::AppListModel) {
- PopulateApps(model_->item_list());
+ : model_(new app_list::AppListModel),
+ speech_ui_(app_list::SPEECH_RECOGNITION_OFF) {
+ PopulateApps();
DecorateSearchBox(model_->search_box());
}
private:
- void PopulateApps(app_list::AppListItemList* item_list) {
- for (int i = 0;
- i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE);
- ++i) {
- WindowTypeLauncherItem::Type type =
- static_cast<WindowTypeLauncherItem::Type>(i);
+ void PopulateApps() {
+ for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) {
+ WindowTypeShelfItem::Type type =
+ static_cast<WindowTypeShelfItem::Type>(i);
std::string id = base::StringPrintf("%d", i);
- item_list->AddItem(new WindowTypeLauncherItem(id, type));
+ scoped_ptr<WindowTypeShelfItem> shelf_item(
+ new WindowTypeShelfItem(id, type));
+ model_->AddItem(shelf_item.PassAs<app_list::AppListItem>());
}
}
const gfx::Size icon_size(32, 32);
gfx::Canvas canvas(icon_size, 1.0f, false /* is_opaque */);
- canvas.DrawStringInt(icon_text,
- gfx::Font(),
- SK_ColorBLACK,
- 0, 0, icon_size.width(), icon_size.height(),
- gfx::Canvas::TEXT_ALIGN_CENTER |
- gfx::Canvas::NO_SUBPIXEL_RENDERING);
+ canvas.DrawStringRectWithFlags(
+ icon_text,
+ gfx::FontList(),
+ SK_ColorBLACK,
+ gfx::Rect(icon_size),
+ gfx::Canvas::TEXT_ALIGN_CENTER | gfx::Canvas::NO_SUBPIXEL_RENDERING);
return gfx::ImageSkia(canvas.ExtractImageRep());
}
return users_;
}
- virtual app_list::AppListModel* GetModel() OVERRIDE { return model_.get(); }
-
- virtual app_list::SigninDelegate* GetSigninDelegate() OVERRIDE {
- return NULL;
+ virtual bool ShouldCenterWindow() const OVERRIDE {
+ return false;
}
+ virtual app_list::AppListModel* GetModel() OVERRIDE { return model_.get(); }
+
virtual app_list::SpeechUIModel* GetSpeechUI() OVERRIDE {
return &speech_ui_;
}
}
virtual void OpenSearchResult(app_list::SearchResult* result,
+ bool auto_launch,
int event_flags) OVERRIDE {
const ExampleSearchResult* example_result =
static_cast<const ExampleSearchResult*>(result);
- WindowTypeLauncherItem::ActivateItem(example_result->type(), event_flags);
+ WindowTypeShelfItem::ActivateItem(example_result->type(), event_flags);
}
virtual void InvokeSearchResultAction(app_list::SearchResult* result,
virtual void StartSearch() OVERRIDE {
base::string16 query;
- TrimWhitespace(model_->search_box()->text(), TRIM_ALL, &query);
+ base::TrimWhitespace(model_->search_box()->text(), base::TRIM_ALL, &query);
query = base::i18n::ToLower(query);
model_->results()->DeleteAll();
if (query.empty())
return;
- for (int i = 0;
- i < static_cast<int>(WindowTypeLauncherItem::LAST_TYPE);
- ++i) {
- WindowTypeLauncherItem::Type type =
- static_cast<WindowTypeLauncherItem::Type>(i);
+ for (int i = 0; i < static_cast<int>(WindowTypeShelfItem::LAST_TYPE); ++i) {
+ WindowTypeShelfItem::Type type =
+ static_cast<WindowTypeShelfItem::Type>(i);
base::string16 title =
- base::UTF8ToUTF16(WindowTypeLauncherItem::GetTitle(type));
+ base::UTF8ToUTF16(WindowTypeShelfItem::GetTitle(type));
if (base::i18n::StringSearchIgnoringCaseAndAccents(
query, title, NULL, NULL)) {
model_->results()->Add(new ExampleSearchResult(type, query));
virtual void Dismiss() OVERRIDE {
DCHECK(ash::Shell::HasInstance());
- if (Shell::GetInstance()->GetAppListTargetVisibility())
- Shell::GetInstance()->ToggleAppList(NULL);
+ Shell::GetInstance()->DismissAppList();
}
virtual void ViewClosing() OVERRIDE {
// Nothing needs to be done.
}
- virtual content::WebContents* GetStartPageContents() OVERRIDE {
+ virtual views::View* CreateStartPageWebView(const gfx::Size& size) OVERRIDE {
return NULL;
}
- virtual content::WebContents* GetSpeechRecognitionContents() OVERRIDE {
- return NULL;
+ virtual std::vector<views::View*> CreateCustomPageWebViews(
+ const gfx::Size& size) OVERRIDE {
+ return std::vector<views::View*>();
+ }
+
+ virtual bool IsSpeechRecognitionEnabled() OVERRIDE {
+ return false;
}
scoped_ptr<app_list::AppListModel> model_;