summaryrefslogtreecommitdiffstats
path: root/athena
diff options
context:
space:
mode:
authormukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 21:52:53 +0000
committermukai@chromium.org <mukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-13 21:52:53 +0000
commit59828d3af3f80d5d88c669f58a731a0283864d12 (patch)
tree88eaf68db32ce79c54ba2265f633a6c4ed2e5e66 /athena
parent9c67c2986d663cd3556326e84bcbba465bde6ad6 (diff)
downloadchromium_src-59828d3af3f80d5d88c669f58a731a0283864d12.zip
chromium_src-59828d3af3f80d5d88c669f58a731a0283864d12.tar.gz
chromium_src-59828d3af3f80d5d88c669f58a731a0283864d12.tar.bz2
Export SearchProvider interface to ui/app_list and use it in athena.
BUG=380444, 380875 R=oshima@chromium.org, xiyuan@chromium.org TEST=compile succeeds, manually check behavior Review URL: https://codereview.chromium.org/331523002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@277094 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'athena')
-rw-r--r--athena/home/app_list_view_delegate.cc32
-rw-r--r--athena/home/app_list_view_delegate.h10
-rw-r--r--athena/home/home_card_impl.cc31
-rw-r--r--athena/home/public/home_card.h12
-rw-r--r--athena/main/DEPS1
-rw-r--r--athena/main/athena_main.cc4
-rw-r--r--athena/main/athena_main.gyp3
-rw-r--r--athena/main/url_search_provider.cc61
-rw-r--r--athena/main/url_search_provider.h34
9 files changed, 181 insertions, 7 deletions
diff --git a/athena/home/app_list_view_delegate.cc b/athena/home/app_list_view_delegate.cc
index 1fd57c9..2bd79ae 100644
--- a/athena/home/app_list_view_delegate.cc
+++ b/athena/home/app_list_view_delegate.cc
@@ -8,12 +8,14 @@
#include "athena/home/public/app_model_builder.h"
#include "base/basictypes.h"
+#include "base/bind.h"
#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/strings/utf_string_conversions.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/app_list/app_list_model.h"
#include "ui/app_list/search_box_model.h"
+#include "ui/app_list/search_provider.h"
#include "ui/app_list/search_result.h"
#include "ui/app_list/speech_ui_model.h"
#include "ui/gfx/image/image_skia.h"
@@ -30,6 +32,28 @@ AppListViewDelegate::AppListViewDelegate(AppModelBuilder* model_builder)
}
AppListViewDelegate::~AppListViewDelegate() {
+ for (size_t i = 0; i < search_providers_.size(); ++i)
+ search_providers_[i]->set_result_changed_callback(base::Closure());
+}
+
+void AppListViewDelegate::RegisterSearchProvider(
+ app_list::SearchProvider* search_provider) {
+ // Right now we allow only one provider.
+ // TODO(mukai): port app-list's mixer and remove this restriction.
+ DCHECK(search_providers_.empty());
+ search_provider->set_result_changed_callback(base::Bind(
+ &AppListViewDelegate::SearchResultChanged, base::Unretained(this)));
+ search_providers_.push_back(search_provider);
+}
+
+void AppListViewDelegate::SearchResultChanged() {
+ // TODO(mukai): port app-list's Mixer to reorder the results properly.
+ app_list::SearchProvider* search_provider = search_providers_[0];
+ std::vector<app_list::SearchResult*> results;
+ search_provider->ReleaseResult(&results);
+ model_->results()->DeleteAll();
+ for (size_t i = 0; i < results.size(); ++i)
+ model_->results()->Add(results[i]);
}
bool AppListViewDelegate::ForceNativeDesktop() const {
@@ -55,17 +79,19 @@ void AppListViewDelegate::GetShortcutPathForApp(
}
void AppListViewDelegate::StartSearch() {
- // TODO(mukai): implement this.
+ for (size_t i = 0; i < search_providers_.size(); ++i)
+ search_providers_[i]->Start(model_->search_box()->text());
}
void AppListViewDelegate::StopSearch() {
- // TODO(mukai): implement this.
+ for (size_t i = 0; i < search_providers_.size(); ++i)
+ search_providers_[i]->Stop();
}
void AppListViewDelegate::OpenSearchResult(app_list::SearchResult* result,
bool auto_launch,
int event_flags) {
- // TODO(mukai): implement this.
+ result->Open(event_flags);
}
void AppListViewDelegate::InvokeSearchResultAction(
diff --git a/athena/home/app_list_view_delegate.h b/athena/home/app_list_view_delegate.h
index e9f37b4..752eb78 100644
--- a/athena/home/app_list_view_delegate.h
+++ b/athena/home/app_list_view_delegate.h
@@ -9,6 +9,10 @@
#include "base/memory/scoped_ptr.h"
#include "ui/app_list/app_list_view_delegate.h"
+namespace app_list {
+class SearchProvider;
+}
+
namespace athena {
class AppModelBuilder;
@@ -17,7 +21,11 @@ class AppListViewDelegate : public app_list::AppListViewDelegate {
explicit AppListViewDelegate(AppModelBuilder* model_builder);
virtual ~AppListViewDelegate();
+ void RegisterSearchProvider(app_list::SearchProvider* search_provider);
+
private:
+ void SearchResultChanged();
+
// Overridden from app_list::AppListViewDelegate:
virtual bool ForceNativeDesktop() const OVERRIDE;
virtual void SetProfileByPath(const base::FilePath& profile_path) OVERRIDE;
@@ -55,6 +63,8 @@ class AppListViewDelegate : public app_list::AppListViewDelegate {
scoped_ptr<app_list::SpeechUIModel> speech_ui_;
Users users_;
+ std::vector<app_list::SearchProvider*> search_providers_;
+
DISALLOW_COPY_AND_ASSIGN(AppListViewDelegate);
};
diff --git a/athena/home/home_card_impl.cc b/athena/home/home_card_impl.cc
index ff51ca8..aa60554 100644
--- a/athena/home/home_card_impl.cc
+++ b/athena/home/home_card_impl.cc
@@ -8,7 +8,7 @@
#include "athena/home/public/app_model_builder.h"
#include "athena/input/public/accelerator_manager.h"
#include "athena/screen/public/screen_manager.h"
-#include "ui/app_list/pagination_model.h"
+#include "ui/app_list/search_provider.h"
#include "ui/app_list/views/app_list_view.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/window.h"
@@ -83,6 +83,10 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
};
void InstallAccelerators();
+ // Overridden from HomeCard:
+ virtual void RegisterSearchProvider(
+ app_list::SearchProvider* search_provider) OVERRIDE;
+
// AcceleratorHandler:
virtual bool IsCommandEnabled(int command_id) const OVERRIDE { return true; }
virtual bool OnAcceleratorFired(int command_id,
@@ -98,6 +102,11 @@ class HomeCardImpl : public HomeCard, public AcceleratorHandler {
scoped_ptr<AppModelBuilder> model_builder_;
views::Widget* home_card_widget_;
+ AppListViewDelegate* view_delegate_;
+
+ // Right now HomeCard allows only one search provider.
+ // TODO(mukai): port app-list's SearchController and Mixer.
+ scoped_ptr<app_list::SearchProvider> search_provider_;
DISALLOW_COPY_AND_ASSIGN(HomeCardImpl);
};
@@ -112,9 +121,17 @@ HomeCardImpl::HomeCardImpl(AppModelBuilder* model_builder)
HomeCardImpl::~HomeCardImpl() {
DCHECK(instance);
home_card_widget_->CloseNow();
+ view_delegate_ = NULL;
instance = NULL;
}
+void HomeCardImpl::RegisterSearchProvider(
+ app_list::SearchProvider* search_provider) {
+ DCHECK(!search_provider_);
+ search_provider_.reset(search_provider);
+ view_delegate_->RegisterSearchProvider(search_provider_.get());
+}
+
void HomeCardImpl::Init() {
InstallAccelerators();
@@ -123,8 +140,10 @@ void HomeCardImpl::Init() {
container->SetLayoutManager(new HomeCardLayoutManager(container));
wm::SetChildWindowVisibilityChangesAnimated(container);
- app_list::AppListView* view = new app_list::AppListView(
- new AppListViewDelegate(model_builder_.get()));
+ view_delegate_ = new AppListViewDelegate(model_builder_.get());
+ if (search_provider_)
+ view_delegate_->RegisterSearchProvider(search_provider_.get());
+ app_list::AppListView* view = new app_list::AppListView(view_delegate_);
view->InitAsBubbleAtFixedLocation(
container,
0 /* initial_apps_page */,
@@ -160,4 +179,10 @@ void HomeCard::Shutdown() {
instance = NULL;
}
+// static
+HomeCard* HomeCard::Get() {
+ DCHECK(instance);
+ return instance;
+}
+
} // namespace athena
diff --git a/athena/home/public/home_card.h b/athena/home/public/home_card.h
index 55e463b..6438d4f 100644
--- a/athena/home/public/home_card.h
+++ b/athena/home/public/home_card.h
@@ -7,17 +7,27 @@
#include "athena/athena_export.h"
+namespace app_list {
+class SearchProvider;
+}
+
namespace athena {
class AppModelBuilder;
class ATHENA_EXPORT HomeCard {
public:
- // Creates and deletes the singleton object of the HomeCard
+ // Creates/deletes/gets the singleton object of the HomeCard
// implementation. Takes the ownership of |model_builder|.
static HomeCard* Create(AppModelBuilder* model_builder);
static void Shutdown();
+ static HomeCard* Get();
virtual ~HomeCard() {}
+
+ // Registers a search_provider to the HomeCard. Receiver will take
+ // the ownership of the specified provider.
+ virtual void RegisterSearchProvider(
+ app_list::SearchProvider* search_provider) = 0;
};
} // namespace athena
diff --git a/athena/main/DEPS b/athena/main/DEPS
index 2f77e06..4bd3069 100644
--- a/athena/main/DEPS
+++ b/athena/main/DEPS
@@ -8,6 +8,7 @@ include_rules = [
"+athena/wm/public",
"+content/public",
"+ui/aura",
+ "+ui/app_list",
"+ui/base",
"+ui/compositor",
"+ui/events",
diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc
index 537e662..4a69779 100644
--- a/athena/main/athena_main.cc
+++ b/athena/main/athena_main.cc
@@ -8,8 +8,10 @@
#include "apps/shell/browser/shell_extension_system.h"
#include "athena/content/public/content_activity_factory.h"
#include "athena/content/public/content_app_model_builder.h"
+#include "athena/home/public/home_card.h"
#include "athena/main/athena_launcher.h"
#include "athena/main/placeholder.h"
+#include "athena/main/url_search_provider.h"
#include "base/command_line.h"
#include "base/file_util.h"
#include "content/public/app/content_main.h"
@@ -31,6 +33,8 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
apps::ShellDesktopController::instance()->host()->window(),
new athena::ContentActivityFactory(),
new athena::ContentAppModelBuilder(context));
+ athena::HomeCard::Get()->RegisterSearchProvider(
+ new athena::UrlSearchProvider(context));
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
if (command_line->HasSwitch(kAppSwitch)) {
base::FilePath app_dir(command_line->GetSwitchValueNative(kAppSwitch));
diff --git a/athena/main/athena_main.gyp b/athena/main/athena_main.gyp
index ed1904e..87a0f37 100644
--- a/athena/main/athena_main.gyp
+++ b/athena/main/athena_main.gyp
@@ -16,6 +16,7 @@
'../../apps/shell/app_shell.gyp:app_shell_lib',
'../../skia/skia.gyp:skia',
'../../ui/accessibility/accessibility.gyp:ax_gen',
+ '../../ui/app_list/app_list.gyp:app_list',
'../../ui/views/views.gyp:views',
'../../url/url.gyp:url_lib',
],
@@ -25,6 +26,8 @@
'sources': [
'athena_launcher.cc',
'athena_launcher.h',
+ 'url_search_provider.cc',
+ 'url_search_provider.h',
'athena_main.cc',
'placeholder.cc',
'placeholder.h',
diff --git a/athena/main/url_search_provider.cc b/athena/main/url_search_provider.cc
new file mode 100644
index 0000000..ce386ea
--- /dev/null
+++ b/athena/main/url_search_provider.cc
@@ -0,0 +1,61 @@
+// Copyright 2014 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 "athena/main/url_search_provider.h"
+
+#include "athena/activity/public/activity_factory.h"
+#include "athena/activity/public/activity_manager.h"
+#include "base/strings/utf_string_conversions.h"
+#include "ui/app_list/search_result.h"
+#include "url/gurl.h"
+
+namespace athena {
+
+namespace {
+
+class UrlSearchResult : public app_list::SearchResult {
+ public:
+ UrlSearchResult(content::BrowserContext* browser_context,
+ const base::string16& query)
+ : browser_context_(browser_context), url_(query) {
+ set_title(query);
+ app_list::SearchResult::Tags title_tags;
+ title_tags.push_back(app_list::SearchResult::Tag(
+ app_list::SearchResult::Tag::URL, 0, query.size()));
+ set_title_tags(title_tags);
+ set_id(base::UTF16ToUTF8(query));
+ }
+
+ private:
+ // Overriddenn from app_list::SearchResult:
+ virtual void Open(int event_flags) OVERRIDE {
+ ActivityManager::Get()->AddActivity(
+ ActivityFactory::Get()->CreateWebActivity(browser_context_, url_));
+ }
+
+ content::BrowserContext* browser_context_;
+ const GURL url_;
+
+ DISALLOW_COPY_AND_ASSIGN(UrlSearchResult);
+};
+
+} // namespace
+
+UrlSearchProvider::UrlSearchProvider(content::BrowserContext* browser_context)
+ : browser_context_(browser_context) {
+}
+
+UrlSearchProvider::~UrlSearchProvider() {
+}
+
+void UrlSearchProvider::Start(const base::string16& query) {
+ ClearResults();
+ Add(scoped_ptr<app_list::SearchResult>(
+ new UrlSearchResult(browser_context_, query)));
+}
+
+void UrlSearchProvider::Stop() {
+}
+
+} // namespace athena
diff --git a/athena/main/url_search_provider.h b/athena/main/url_search_provider.h
new file mode 100644
index 0000000..6ee8301
--- /dev/null
+++ b/athena/main/url_search_provider.h
@@ -0,0 +1,34 @@
+// Copyright 2014 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.
+
+#ifndef ATHENA_MAIN_URL_SEARCH_PROVIDER_H_
+#define ATHENA_MAIN_URL_SEARCH_PROVIDER_H_
+
+#include "ui/app_list/search_provider.h"
+
+namespace content {
+class BrowserContext;
+}
+
+namespace athena {
+
+// A sample search provider.
+class UrlSearchProvider : public app_list::SearchProvider {
+ public:
+ UrlSearchProvider(content::BrowserContext* browser_context);
+ virtual ~UrlSearchProvider();
+
+ // Overridden from app_list::SearchProvider
+ virtual void Start(const base::string16& query) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+
+ private:
+ content::BrowserContext* browser_context_;
+
+ DISALLOW_COPY_AND_ASSIGN(UrlSearchProvider);
+};
+
+} // namespace athena
+
+#endif // ATHENA_MAIN_URL_SEARCH_PROVIDER_H_