Index: chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc |
=================================================================== |
--- chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (revision 116848) |
+++ chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (working copy) |
@@ -14,6 +14,7 @@ |
#include <algorithm> // NOLINT |
#include "base/i18n/bidi_line_iterator.h" |
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
#include "chrome/browser/ui/views/autocomplete/autocomplete_result_view_model.h" |
#include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
#include "grit/generated_resources.h" |
@@ -111,13 +112,16 @@ |
normal_font_(font), |
bold_font_(bold_font), |
ellipsis_width_(font.GetStringWidth(string16(kEllipsis))), |
- mirroring_context_(new MirroringContext()) { |
+ mirroring_context_(new MirroringContext()), |
+ ALLOW_THIS_IN_INITIALIZER_LIST(animation_(new ui::SlideAnimation(this))) { |
CHECK_GE(model_index, 0); |
if (default_icon_size_ == 0) { |
default_icon_size_ = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
AutocompleteMatch::TypeToIcon(AutocompleteMatch::URL_WHAT_YOU_TYPED))-> |
width(); |
} |
+ |
+ animation_->SetDuration(500); |
Peter Kasting
2012/01/11 03:00:16
I suspect this will be too slow, but I should patc
|
} |
AutocompleteResultView::~AutocompleteResultView() { |
@@ -173,9 +177,26 @@ |
void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { |
match_ = match; |
+ animation_->Reset(); |
+ keyword_icon_bounds_.SetRect(0, 0, 0, 0); |
+ |
Layout(); |
} |
+void AutocompleteResultView::ShowKeyword(bool show_keyword) { |
+ if (show_keyword) { |
Peter Kasting
2012/01/11 03:00:16
Nit: No {} necessary
|
+ animation_->Show(); |
+ } else { |
+ animation_->Hide(); |
+ } |
+} |
+ |
+gfx::Size AutocompleteResultView::GetPreferredSize() { |
+ return gfx::Size(0, std::max( |
+ default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
+ GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
+} |
+ |
//////////////////////////////////////////////////////////////////////////////// |
// AutocompleteResultView, protected: |
@@ -263,6 +284,21 @@ |
return ResourceBundle::GetSharedInstance().GetBitmapNamed(icon); |
} |
+const SkBitmap* AutocompleteResultView::GetKeywordIcon() const { |
+ int icon = IDR_OMNIBOX_TTS_NORMAL; |
+ |
+ if (model_->IsSelectedIndex(model_index_)) { |
+ icon = !animation_->IsShowing() ? IDR_OMNIBOX_TTS_NORMAL_SELECTED : |
+#if defined(TOOLKIT_USES_GTK) |
+ IDR_OMNIBOX_TTS_KEYWORD_DARK; |
Peter Kasting
2012/01/11 03:00:16
We don't actually use the DARK variants for GTK-vi
|
+#else |
+ IDR_OMNIBOX_TTS_KEYWORD_SELECTED; |
+#endif |
+ } |
+ |
+ return ResourceBundle::GetSharedInstance().GetBitmapNamed(icon); |
+} |
+ |
int AutocompleteResultView::DrawString( |
gfx::Canvas* canvas, |
const string16& text, |
@@ -493,14 +529,9 @@ |
runs->clear(); |
} |
-gfx::Size AutocompleteResultView::GetPreferredSize() { |
- return gfx::Size(0, std::max( |
- default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
- GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
-} |
- |
void AutocompleteResultView::Layout() { |
const SkBitmap* icon = GetIcon(); |
+ |
icon_bounds_.SetRect(LocationBarView::kEdgeItemPadding + |
((icon->width() == default_icon_size_) ? |
0 : LocationBarView::kIconInternalPadding), |
@@ -509,9 +540,31 @@ |
int text_x = LocationBarView::kEdgeItemPadding + default_icon_size_ + |
LocationBarView::kItemPadding; |
int text_height = GetTextHeight(); |
+ int text_width; |
+ |
+ if (match_.associated_keyword.get()) { |
+ const SkBitmap* kw_icon = GetKeywordIcon(); |
+ const int kw_collapsed_size = kw_icon->width() + |
+ LocationBarView::kEdgeItemPadding; |
+ const int max_kw_x = bounds().width() - kw_collapsed_size; |
+ const int kw_x = animation_->CurrentValueBetween(max_kw_x, |
+ LocationBarView::kEdgeItemPadding); |
+ const int kw_text_x = kw_x + kw_icon->width() + |
+ LocationBarView::kItemPadding; |
+ |
+ text_width = kw_x - text_x - LocationBarView::kItemPadding; |
+ keyword_text_bounds_.SetRect(kw_text_x, 0, std::max( |
+ bounds().width() - kw_text_x - LocationBarView::kEdgeItemPadding, 0), |
+ text_height); |
+ keyword_icon_bounds_.SetRect(GetMirroredXInView(kw_x), |
+ (height() - kw_icon->height()) / 2, |
+ kw_icon->width(), kw_icon->height()); |
+ } else { |
+ text_width = bounds().width() - text_x - LocationBarView::kEdgeItemPadding; |
+ } |
+ |
text_bounds_.SetRect(text_x, std::max(0, (height() - text_height) / 2), |
- std::max(bounds().width() - text_x - LocationBarView::kEdgeItemPadding, |
- 0), text_height); |
+ std::max(text_width, 0), text_height); |
} |
void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { |
@@ -519,12 +572,33 @@ |
if (state != NORMAL) |
canvas->GetSkCanvas()->drawColor(GetColor(state, BACKGROUND)); |
- // Paint the icon. |
- canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
- icon_bounds_.y()); |
+ if (keyword_icon_bounds_.IsEmpty() || |
+ keyword_icon_bounds_.x() > icon_bounds_.right()) { |
+ // Paint the icon. |
+ canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
+ icon_bounds_.y()); |
- // Paint the text. |
- int x = GetMirroredXForRect(text_bounds_); |
- mirroring_context_->Initialize(x, text_bounds_.width()); |
- PaintMatch(canvas, match_, x); |
+ // Paint the text. |
+ int x = GetMirroredXForRect(text_bounds_); |
+ mirroring_context_->Initialize(x, text_bounds_.width()); |
+ PaintMatch(canvas, match_, x); |
+ } |
+ |
+ if (match_.associated_keyword.get()) { |
+ // Paint the keyword icon. |
+ canvas->DrawBitmapInt(*GetKeywordIcon(), keyword_icon_bounds_.x(), |
+ keyword_icon_bounds_.y()); |
+ |
+ // Paint the keyword text. |
+ int x = GetMirroredXForRect(keyword_text_bounds_); |
+ mirroring_context_->Initialize(x, keyword_text_bounds_.width()); |
+ PaintMatch(canvas, *match_.associated_keyword.get(), x); |
+ } |
} |
+ |
+void AutocompleteResultView::AnimationProgressed( |
+ const ui::Animation* animation) { |
+ Layout(); |
+ SchedulePaint(); |
+} |
+ |