Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / ash / shell / app_list.cc
index 72a0777..bf5a44b 100644 (file)
@@ -3,8 +3,9 @@
 // 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"
@@ -25,9 +26,9 @@
 #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 {
@@ -35,9 +36,9 @@ namespace shell {
 
 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,
@@ -48,12 +49,12 @@ class WindowTypeLauncherItem : public app_list::AppListItem {
     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) {
@@ -67,8 +68,7 @@ class WindowTypeLauncherItem : public app_list::AppListItem {
 
     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);
   }
@@ -145,7 +145,7 @@ class WindowTypeLauncherItem : public app_list::AppListItem {
  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
@@ -154,13 +154,13 @@ class WindowTypeLauncherItem : public app_list::AppListItem {
 // 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;
@@ -179,17 +179,17 @@ class ExampleSearchResult : public app_list::SearchResult {
     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);
 };
@@ -197,20 +197,21 @@ class ExampleSearchResult : public app_list::SearchResult {
 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>());
     }
   }
 
@@ -219,12 +220,12 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
     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());
   }
@@ -247,12 +248,12 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
     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_;
   }
@@ -264,10 +265,11 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
   }
 
   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,
@@ -285,21 +287,19 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
 
   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));
@@ -317,8 +317,7 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
 
   virtual void Dismiss() OVERRIDE {
     DCHECK(ash::Shell::HasInstance());
-    if (Shell::GetInstance()->GetAppListTargetVisibility())
-      Shell::GetInstance()->ToggleAppList(NULL);
+    Shell::GetInstance()->DismissAppList();
   }
 
   virtual void ViewClosing() OVERRIDE {
@@ -350,12 +349,17 @@ class ExampleAppListViewDelegate : public app_list::AppListViewDelegate {
     // 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_;