summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--chrome/app/generated_resources.grd6
-rw-r--r--chrome/browser/about_flags.cc8
-rw-r--r--chrome/browser/ui/app_list/search/omnibox_provider.cc170
-rw-r--r--chrome/browser/ui/app_list/search/omnibox_provider.h48
-rw-r--r--chrome/browser/ui/app_list/search/search_controller.cc4
-rw-r--r--chrome/chrome_browser_ui.gypi2
-rw-r--r--ui/app_list/app_list.gyp2
-rw-r--r--ui/app_list/app_list_switches.cc14
-rw-r--r--ui/app_list/app_list_switches.h18
9 files changed, 224 insertions, 48 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index 1c78937..48b7ced 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -6972,12 +6972,6 @@ Keep your key file in a safe place. You will need it to create new versions of y
<message name="IDS_FLAGS_PINCH_ZOOM_SCROLLBARS_DESCRIPTION" desc="Description for the Pinch Zoom Scrollbars feature.">
While zoomed in, overlay scrollbars will be visible during scrolling.
</message>
- <message name="IDS_FLAGS_ENABLE_APP_LIST_SHOW_APPS_ONLY_NAME" desc="Name of the flag to show only apps in app list search.">
- Enable apps only search for app list.
- </message>
- <message name="IDS_FLAGS_ENABLE_APP_LIST_SHOW_APPS_ONLY_DESCRIPTION" desc="Description of the flag to show only apps in app list search.">
- Shows only apps in app list search.
- </message>
<message name="IDS_FLAGS_NEW_DIALOG_STYLE_NAME" desc="Name of the flag to use the classic or new dialog style.">
New Dialog Style.
</message>
diff --git a/chrome/browser/about_flags.cc b/chrome/browser/about_flags.cc
index c62215f..35662c2 100644
--- a/chrome/browser/about_flags.cc
+++ b/chrome/browser/about_flags.cc
@@ -26,7 +26,6 @@
#include "grit/generated_resources.h"
#include "grit/google_chrome_strings.h"
#include "media/base/media_switches.h"
-#include "ui/app_list/app_list_switches.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/ui_base_switches.h"
#include "ui/gfx/switches.h"
@@ -1003,13 +1002,6 @@ const Experiment kExperiments[] = {
cc::switches::kDisablePinchZoomScrollbars)
},
{
- "app-list-show-apps-only",
- IDS_FLAGS_ENABLE_APP_LIST_SHOW_APPS_ONLY_NAME,
- IDS_FLAGS_ENABLE_APP_LIST_SHOW_APPS_ONLY_DESCRIPTION,
- kOsAll,
- SINGLE_VALUE_TYPE(app_list::switches::kAppListShowAppsOnly),
- },
- {
"forced-maximize-mode",
IDS_FLAGS_FORCE_MAXIMIZE_MODE_NAME,
IDS_FLAGS_FORCE_MAXIMIZE_MODE_DESCRIPTION,
diff --git a/chrome/browser/ui/app_list/search/omnibox_provider.cc b/chrome/browser/ui/app_list/search/omnibox_provider.cc
new file mode 100644
index 0000000..50c470f
--- /dev/null
+++ b/chrome/browser/ui/app_list/search/omnibox_provider.cc
@@ -0,0 +1,170 @@
+// Copyright 2013 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 "chrome/browser/ui/app_list/search/omnibox_provider.h"
+
+#include "chrome/browser/autocomplete/autocomplete_classifier.h"
+#include "chrome/browser/autocomplete/autocomplete_controller.h"
+#include "chrome/browser/autocomplete/autocomplete_match.h"
+#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "grit/theme_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+
+namespace app_list {
+
+namespace {
+
+int ACMatchStyleToTagStyle(int styles) {
+ int tag_styles = 0;
+ if (styles & ACMatchClassification::URL)
+ tag_styles |= SearchResult::Tag::URL;
+ if (styles & ACMatchClassification::MATCH)
+ tag_styles |= SearchResult::Tag::MATCH;
+ if (styles & ACMatchClassification::DIM)
+ tag_styles |= SearchResult::Tag::DIM;
+
+ return tag_styles;
+}
+
+// Translates ACMatchClassifications into SearchResult tags.
+void ACMatchClassificationsToTags(
+ const string16& text,
+ const ACMatchClassifications& text_classes,
+ SearchResult::Tags* tags) {
+ int tag_styles = SearchResult::Tag::NONE;
+ size_t tag_start = 0;
+
+ for (size_t i = 0; i < text_classes.size(); ++i) {
+ const ACMatchClassification& text_class = text_classes[i];
+
+ // Closes current tag.
+ if (tag_styles != SearchResult::Tag::NONE) {
+ tags->push_back(SearchResult::Tag(
+ tag_styles, tag_start, text_class.offset));
+ tag_styles = SearchResult::Tag::NONE;
+ }
+
+ if (text_class.style == ACMatchClassification::NONE)
+ continue;
+
+ tag_start = text_class.offset;
+ tag_styles = ACMatchStyleToTagStyle(text_class.style);
+ }
+
+ if (tag_styles != SearchResult::Tag::NONE) {
+ tags->push_back(SearchResult::Tag(
+ tag_styles, tag_start, text.length()));
+ }
+}
+
+class OmniboxResult : public ChromeSearchResult {
+ public:
+ OmniboxResult(Profile* profile, const AutocompleteMatch& match)
+ : profile_(profile),
+ match_(match) {
+ set_id(match.destination_url.spec());
+
+ // Derive relevance from omnibox relevance and normalize it to [0, 1].
+ // The magic number 1500 is the highest score of an omnibox result.
+ // See comments in autocomplete_provider.h.
+ set_relevance(match.relevance / 1500.0);
+
+ UpdateIcon();
+ UpdateTitleAndDetails();
+ }
+ virtual ~OmniboxResult() {}
+
+ // ChromeSearchResult overides:
+ virtual void Open(int event_flags) OVERRIDE {
+ chrome::NavigateParams params(profile_,
+ match_.destination_url,
+ match_.transition);
+ params.disposition = ui::DispositionFromEventFlags(event_flags);
+ chrome::Navigate(&params);
+ }
+
+ virtual void InvokeAction(int action_index, int event_flags) OVERRIDE {}
+
+ virtual scoped_ptr<ChromeSearchResult> Duplicate() OVERRIDE {
+ return scoped_ptr<ChromeSearchResult>(
+ new OmniboxResult(profile_, match_)).Pass();
+ }
+
+ private:
+ void UpdateIcon() {
+ int resource_id = match_.starred ?
+ IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
+ SetIcon(*ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ resource_id));
+ }
+
+ void UpdateTitleAndDetails() {
+ set_title(match_.contents);
+ SearchResult::Tags title_tags;
+ ACMatchClassificationsToTags(match_.contents,
+ match_.contents_class,
+ &title_tags);
+ set_title_tags(title_tags);
+
+ set_details(match_.description);
+ SearchResult::Tags details_tags;
+ ACMatchClassificationsToTags(match_.description,
+ match_.description_class,
+ &details_tags);
+ set_details_tags(details_tags);
+ }
+
+ Profile* profile_;
+ AutocompleteMatch match_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmniboxResult);
+};
+
+} // namespace
+
+OmniboxProvider::OmniboxProvider(Profile* profile)
+ : profile_(profile),
+ controller_(new AutocompleteController(
+ profile,
+ this,
+ AutocompleteClassifier::kDefaultOmniboxProviders)) {
+}
+
+OmniboxProvider::~OmniboxProvider() {}
+
+void OmniboxProvider::Start(const base::string16& query) {
+ controller_->Start(AutocompleteInput(query,
+ base::string16::npos,
+ base::string16(),
+ GURL(),
+ false,
+ false,
+ true,
+ AutocompleteInput::ALL_MATCHES));
+}
+
+void OmniboxProvider::Stop() {
+ controller_->Stop(false);
+}
+
+void OmniboxProvider::PopulateFromACResult(const AutocompleteResult& result) {
+ ClearResults();
+ for (ACMatches::const_iterator it = result.begin();
+ it != result.end();
+ ++it) {
+ if (!it->destination_url.is_valid())
+ continue;
+
+ Add(scoped_ptr<ChromeSearchResult>(
+ new OmniboxResult(profile_, *it)).Pass());
+ }
+}
+
+void OmniboxProvider::OnResultChanged(bool default_match_changed) {
+ const AutocompleteResult& result = controller_->result();
+ PopulateFromACResult(result);
+}
+
+} // namespace app_list
diff --git a/chrome/browser/ui/app_list/search/omnibox_provider.h b/chrome/browser/ui/app_list/search/omnibox_provider.h
new file mode 100644
index 0000000..7c07b7f
--- /dev/null
+++ b/chrome/browser/ui/app_list/search/omnibox_provider.h
@@ -0,0 +1,48 @@
+// Copyright 2013 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 CHROME_BROWSER_UI_APP_LIST_SEARCH_OMNIBOX_PROVIDER_H_
+#define CHROME_BROWSER_UI_APP_LIST_SEARCH_OMNIBOX_PROVIDER_H_
+
+#include "base/basictypes.h"
+#include "base/memory/scoped_ptr.h"
+#include "chrome/browser/autocomplete/autocomplete_controller_delegate.h"
+#include "chrome/browser/ui/app_list/search/search_provider.h"
+
+class AutocompleteController;
+class AutocompleteResult;
+class Profile;
+
+namespace app_list {
+
+// OmniboxProvider wraps AutocompleteController to provide omnibox results.
+class OmniboxProvider : public SearchProvider,
+ public AutocompleteControllerDelegate {
+ public:
+ explicit OmniboxProvider(Profile* profile);
+ virtual ~OmniboxProvider();
+
+ // SearchProvider overrides:
+ virtual void Start(const base::string16& query) OVERRIDE;
+ virtual void Stop() OVERRIDE;
+
+ private:
+ // Populates result list from AutocompleteResult.
+ void PopulateFromACResult(const AutocompleteResult& result);
+
+ // AutocompleteControllerDelegate overrides:
+ virtual void OnResultChanged(bool default_match_changed) OVERRIDE;
+
+ Profile* profile_;
+
+ // The omnibox AutocompleteController that collects/sorts/dup-
+ // eliminates the results as they come in.
+ scoped_ptr<AutocompleteController> controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(OmniboxProvider);
+};
+
+} // namespace app_list
+
+#endif // CHROME_BROWSER_UI_APP_LIST_SEARCH_OMNIBOX_PROVIDER_H_
diff --git a/chrome/browser/ui/app_list/search/search_controller.cc b/chrome/browser/ui/app_list/search/search_controller.cc
index 415b45c..3014465 100644
--- a/chrome/browser/ui/app_list/search/search_controller.cc
+++ b/chrome/browser/ui/app_list/search/search_controller.cc
@@ -8,10 +8,12 @@
#include <vector>
#include "base/bind.h"
+#include "base/command_line.h"
#include "base/memory/scoped_ptr.h"
#include "base/string_util.h"
#include "chrome/browser/ui/app_list/search/app_search_provider.h"
#include "chrome/browser/ui/app_list/search/chrome_search_result.h"
+#include "chrome/browser/ui/app_list/search/omnibox_provider.h"
#include "chrome/browser/ui/app_list/search/search_provider.h"
#include "ui/app_list/search_box_model.h"
@@ -37,6 +39,8 @@ void SearchController::Init() {
AddProvider(Mixer::MAIN_GROUP,
scoped_ptr<SearchProvider>(
new AppSearchProvider(profile_, list_controller_)).Pass());
+ AddProvider(Mixer::OMNIBOX_GROUP,
+ scoped_ptr<SearchProvider>(new OmniboxProvider(profile_)).Pass());
// TODO(xiyuan): Add providers.
}
diff --git a/chrome/chrome_browser_ui.gypi b/chrome/chrome_browser_ui.gypi
index 5308473..8e1452f 100644
--- a/chrome/chrome_browser_ui.gypi
+++ b/chrome/chrome_browser_ui.gypi
@@ -137,6 +137,8 @@
'browser/ui/app_list/search/chrome_search_result.h',
'browser/ui/app_list/search/mixer.cc',
'browser/ui/app_list/search/mixer.h',
+ 'browser/ui/app_list/search/omnibox_provider.cc',
+ 'browser/ui/app_list/search/omnibox_provider.h',
'browser/ui/app_list/search/search_controller.cc',
'browser/ui/app_list/search/search_controller.h',
'browser/ui/app_list/search/search_provider.cc',
diff --git a/ui/app_list/app_list.gyp b/ui/app_list/app_list.gyp
index ff67214..8479ff7 100644
--- a/ui/app_list/app_list.gyp
+++ b/ui/app_list/app_list.gyp
@@ -35,8 +35,6 @@
'app_list_model.cc',
'app_list_model.h',
'app_list_model_observer.h',
- 'app_list_switches.cc',
- 'app_list_switches.h',
'app_list_view_delegate.h',
'apps_grid_view_delegate.h',
'cocoa/app_list_pager_view.h',
diff --git a/ui/app_list/app_list_switches.cc b/ui/app_list/app_list_switches.cc
deleted file mode 100644
index 2c99374..0000000
--- a/ui/app_list/app_list_switches.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-// 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.
-
-#include "ui/app_list/app_list_switches.h"
-
-namespace app_list {
-namespace switches {
-
-// Show only apps result in app list search.
-const char kAppListShowAppsOnly[] = "app-list-show-apps-only";
-
-} // namespace switches
-} // namespace app_list
diff --git a/ui/app_list/app_list_switches.h b/ui/app_list/app_list_switches.h
deleted file mode 100644
index 267830a..0000000
--- a/ui/app_list/app_list_switches.h
+++ /dev/null
@@ -1,18 +0,0 @@
-// 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.
-
-#ifndef UI_APP_LIST_APP_LIST_SWITCHES_H_
-#define UI_APP_LIST_APP_LIST_SWITCHES_H_
-
-#include "ui/app_list/app_list_export.h"
-
-namespace app_list {
-namespace switches {
-
-APP_LIST_EXPORT extern const char kAppListShowAppsOnly[];
-
-} // namespace switches
-} // namespace app_list
-
-#endif // UI_APP_LIST_APP_LIST_SWITCHES_H_