summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 21:13:47 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-15 21:13:47 +0000
commitb671760bb1967f74d584c7790af86a5aee6fd43c (patch)
tree293ed23ee335c9300dbf72b679cbaf083b41bb4f /chrome/browser/views
parentf9a2b2fe071c001a6864e527fd7035489a985243 (diff)
downloadchromium_src-b671760bb1967f74d584c7790af86a5aee6fd43c.zip
chromium_src-b671760bb1967f74d584c7790af86a5aee6fd43c.tar.gz
chromium_src-b671760bb1967f74d584c7790af86a5aee6fd43c.tar.bz2
Use the extension icon for extension omnibox results instead of the generic
search icon. I refactored the extension menu manager to separate the icon-specific bits. BUG=46479 TEST=load the chrome search extension at src/chrome/common/extensions/docs/examples/extensions/chrome_search/ and type "src foo" into the omnibox. You should see the extension icon instead of the magnifying glass. Switch back and forth between the "src" keyword result, other results, and other keywords and the icons should update properly. Review URL: http://codereview.chromium.org/2973006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@52535 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc15
-rw-r--r--chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h5
-rw-r--r--chrome/browser/views/location_bar/icon_label_bubble_view.cc4
-rw-r--r--chrome/browser/views/location_bar/icon_label_bubble_view.h3
-rw-r--r--chrome/browser/views/location_bar/location_bar_view.cc15
5 files changed, 39 insertions, 3 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
index 17d243c..45a10bf 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -153,7 +153,7 @@ class AutocompleteResultView : public views::View {
ResultViewState GetState() const;
- SkBitmap* GetIcon() const;
+ const SkBitmap* GetIcon() const;
// Draws the specified |text| into the canvas, using highlighting provided by
// |classifications|. If |force_dim| is true, ACMatchClassification::DIM is
@@ -339,7 +339,11 @@ ResultViewState AutocompleteResultView::GetState() const {
return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL;
}
-SkBitmap* AutocompleteResultView::GetIcon() const {
+const SkBitmap* AutocompleteResultView::GetIcon() const {
+ const SkBitmap* bitmap = model_->GetSpecialIcon(model_index_);
+ if (bitmap)
+ return bitmap;
+
int icon = match_.starred ?
IDR_OMNIBOX_STAR : AutocompleteMatch::TypeToIcon(match_.type);
if (model_->IsSelectedIndex(model_index_)) {
@@ -740,6 +744,13 @@ bool AutocompletePopupContentsView::IsHoveredIndex(size_t index) const {
return HasMatchAt(index) ? index == model_->hovered_line() : false;
}
+const SkBitmap* AutocompletePopupContentsView::GetSpecialIcon(
+ size_t index) const {
+ if (!HasMatchAt(index))
+ return NULL;
+ return model_->GetSpecialIconForMatch(GetMatchAtIndex(index));
+}
+
////////////////////////////////////////////////////////////////////////////////
// AutocompletePopupContentsView, AnimationDelegate implementation:
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
index d814206..80704cd 100644
--- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
+++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h
@@ -33,6 +33,10 @@ class AutocompleteResultViewModel {
// Returns true if the index is hovered.
virtual bool IsHoveredIndex(size_t index) const = 0;
+
+ // Returns the special-case icon we should use for the given index, or NULL
+ // if we should use the default icon.
+ virtual const SkBitmap* GetSpecialIcon(size_t index) const = 0;
};
// A view representing the contents of the autocomplete popup.
@@ -63,6 +67,7 @@ class AutocompletePopupContentsView : public views::View,
// Overridden from AutocompleteResultViewModel:
virtual bool IsSelectedIndex(size_t index) const;
virtual bool IsHoveredIndex(size_t index) const;
+ virtual const SkBitmap* GetSpecialIcon(size_t index) const;
// Overridden from AnimationDelegate:
virtual void AnimationProgressed(const Animation* animation);
diff --git a/chrome/browser/views/location_bar/icon_label_bubble_view.cc b/chrome/browser/views/location_bar/icon_label_bubble_view.cc
index 729c9a1..4e92ac0 100644
--- a/chrome/browser/views/location_bar/icon_label_bubble_view.cc
+++ b/chrome/browser/views/location_bar/icon_label_bubble_view.cc
@@ -43,6 +43,10 @@ void IconLabelBubbleView::SetLabel(const std::wstring& label) {
label_->SetText(label);
}
+void IconLabelBubbleView::SetImage(const SkBitmap& bitmap) {
+ image_->SetImage(bitmap);
+}
+
void IconLabelBubbleView::Paint(gfx::Canvas* canvas) {
int y_offset = (GetParent()->height() - height()) / 2;
canvas->TranslateInt(0, y_offset);
diff --git a/chrome/browser/views/location_bar/icon_label_bubble_view.h b/chrome/browser/views/location_bar/icon_label_bubble_view.h
index 53b0b33..dd5b196 100644
--- a/chrome/browser/views/location_bar/icon_label_bubble_view.h
+++ b/chrome/browser/views/location_bar/icon_label_bubble_view.h
@@ -20,6 +20,8 @@ class ImageView;
class Label;
}
+class SkBitmap;
+
// View used to draw a bubble to the left of the address, containing an icon and
// a label. We use this as a base for the classes that handle the EV bubble and
// tab-to-search UI.
@@ -32,6 +34,7 @@ class IconLabelBubbleView : public views::View {
void SetFont(const gfx::Font& font);
void SetLabel(const std::wstring& label);
+ void SetImage(const SkBitmap& bitmap);
virtual void Paint(gfx::Canvas* canvas);
virtual gfx::Size GetPreferredSize();
diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc
index 8ed874d..4dffa4e 100644
--- a/chrome/browser/views/location_bar/location_bar_view.cc
+++ b/chrome/browser/views/location_bar/location_bar_view.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/extensions/extension_browser_event_router.h"
#include "chrome/browser/extensions/extensions_service.h"
#include "chrome/browser/profile.h"
+#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/view_ids.h"
#include "chrome/browser/views/browser_dialogs.h"
#include "chrome/browser/views/location_bar/content_setting_image_view.h"
@@ -457,8 +458,20 @@ void LocationBarView::Layout() {
selected_keyword_view_->SetVisible(show_selected_keyword);
keyword_hint_view_->SetVisible(show_keyword_hint);
if (show_selected_keyword) {
- if (selected_keyword_view_->keyword() != keyword)
+ if (selected_keyword_view_->keyword() != keyword) {
selected_keyword_view_->SetKeyword(keyword);
+
+ const TemplateURL* template_url =
+ profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
+ if (template_url && template_url->IsExtensionKeyword()) {
+ const SkBitmap& bitmap = profile_->GetExtensionsService()->
+ GetOmniboxIcon(template_url->GetExtensionId());
+ selected_keyword_view_->SetImage(bitmap);
+ } else {
+ selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance().
+ GetBitmapNamed(IDR_OMNIBOX_SEARCH));
+ }
+ }
} else if (show_keyword_hint) {
if (keyword_hint_view_->keyword() != keyword)
keyword_hint_view_->SetKeyword(keyword);