Chromium Code Reviews| Index: chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc |
| =================================================================== |
| --- chrome/browser/ui/views/autocomplete/autocomplete_result_view.cc (revision 117356) |
| +++ 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,7 +112,8 @@ |
| 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( |
| @@ -173,9 +175,41 @@ |
| void AutocompleteResultView::SetMatch(const AutocompleteMatch& match) { |
| match_ = match; |
| + animation_->Reset(); |
| + |
| + if (match.associated_keyword.get()) { |
|
Peter Kasting
2012/01/12 22:59:59
There is a memory safety issue here, as well as a
aaron.randolph
2012/01/13 00:03:48
I'm not following how this eliminates the Invalida
Peter Kasting
2012/01/13 00:36:41
You're right, I missed the normal vs. selected par
|
| + keyword_icon_.reset(new views::ImageView()); |
| + keyword_icon_->EnableCanvasFlippingForRTLUI(true); |
| + keyword_icon_->SetImage(GetKeywordIcon()); |
| + AddChildView(keyword_icon_.get()); |
| + } else if (keyword_icon_.get()) { |
| + RemoveChildView(keyword_icon_.get()); |
| + keyword_icon_.reset(); |
| + } |
| + |
| Layout(); |
| } |
| +void AutocompleteResultView::ShowKeyword(bool show_keyword) { |
| + if (show_keyword) |
| + animation_->Show(); |
| + else |
| + animation_->Hide(); |
| +} |
| + |
| +void AutocompleteResultView::Invalidate() { |
| + if (keyword_icon_.get()) |
| + keyword_icon_->SetImage(GetKeywordIcon()); |
| + |
| + SchedulePaint(); |
| +} |
| + |
| +gfx::Size AutocompleteResultView::GetPreferredSize() { |
| + return gfx::Size(0, std::max( |
| + default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
| + GetTextHeight() + (kMinimumTextVerticalPadding * 2))); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // AutocompleteResultView, protected: |
| @@ -263,6 +297,12 @@ |
| return ResourceBundle::GetSharedInstance().GetBitmapNamed(icon); |
| } |
| +const SkBitmap* AutocompleteResultView::GetKeywordIcon() const { |
| + return ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| + model_->IsSelectedIndex(model_index_) ? IDR_OMNIBOX_TTS_SELECTED : |
|
Peter Kasting
2012/01/12 22:59:59
Nit: Break after '?' rather than ':'
Peter Kasting
2012/01/13 00:36:41
Nit: (GetState() == SELECTED) seems fractionally c
|
| + IDR_OMNIBOX_TTS); |
| +} |
| + |
| int AutocompleteResultView::DrawString( |
| gfx::Canvas* canvas, |
| const string16& text, |
| @@ -493,14 +533,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,22 +544,65 @@ |
| 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(); |
|
Peter Kasting
2012/01/13 00:36:41
Nit: Rather than calling GetKeywordIcon() here, it
aaron.randolph
2012/01/13 03:08:07
Actually, it doesn't appear that ImageView sets th
|
| + 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_->SetBounds(kw_x, (height() - kw_icon->height()) / 2, |
|
Peter Kasting
2012/01/13 00:36:41
Nit: This can just be SetPosition().
|
| + 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::OnBoundsChanged( |
| + const gfx::Rect& previous_bounds) { |
| + animation_->SetSlideDuration(width() / 4); |
| +} |
| + |
| void AutocompleteResultView::OnPaint(gfx::Canvas* canvas) { |
| const ResultViewState state = GetState(); |
| if (state != NORMAL) |
| canvas->GetSkCanvas()->drawColor(GetColor(state, BACKGROUND)); |
| - // Paint the icon. |
| - canvas->DrawBitmapInt(*GetIcon(), GetMirroredXForRect(icon_bounds_), |
| - icon_bounds_.y()); |
| + if (!match_.associated_keyword.get() || |
| + keyword_icon_->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 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(); |
| +} |
| + |