| OLD | NEW | 
|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be | 
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. | 
| 4 | 4 | 
| 5 // For WinDDK ATL compatibility, these ATL headers must come first. | 5 // For WinDDK ATL compatibility, these ATL headers must come first. | 
| 6 #include "build/build_config.h" | 6 #include "build/build_config.h" | 
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) | 
| 8 #include <atlbase.h>  // NOLINT | 8 #include <atlbase.h>  // NOLINT | 
| 9 #include <atlwin.h>  // NOLINT | 9 #include <atlwin.h>  // NOLINT | 
| 10 #endif | 10 #endif | 
| 11 | 11 | 
| 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 12 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 
| 13 | 13 | 
| 14 #include <algorithm>  // NOLINT | 14 #include <algorithm>  // NOLINT | 
| 15 | 15 | 
| 16 #include "base/i18n/bidi_line_iterator.h" | 16 #include "base/i18n/bidi_line_iterator.h" | 
| 17 #include "base/memory/scoped_vector.h" | 17 #include "base/memory/scoped_vector.h" | 
| 18 #include "base/strings/string_number_conversions.h" | 18 #include "base/strings/string_number_conversions.h" | 
| 19 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" | 
| 20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" | 20 #include "chrome/browser/bitmap_fetcher/bitmap_fetcher_service_factory.h" | 
| 21 #include "chrome/browser/profiles/profile.h" | 21 #include "chrome/browser/profiles/profile.h" | 
| 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 22 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 
| 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 23 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 
| 24 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 24 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 
| 25 #include "chrome/grit/generated_resources.h" | 25 #include "chrome/grit/generated_resources.h" | 
|  | 26 #include "components/omnibox/omnibox_field_trial.h" | 
| 26 #include "components/omnibox/suggestion_answer.h" | 27 #include "components/omnibox/suggestion_answer.h" | 
| 27 #include "grit/components_scaled_resources.h" | 28 #include "grit/components_scaled_resources.h" | 
| 28 #include "grit/theme_resources.h" | 29 #include "grit/theme_resources.h" | 
|  | 30 #include "third_party/skia/include/core/SkColor.h" | 
| 29 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" | 
|  | 32 #include "ui/base/resource/resource_bundle.h" | 
| 30 #include "ui/base/theme_provider.h" | 33 #include "ui/base/theme_provider.h" | 
| 31 #include "ui/gfx/canvas.h" | 34 #include "ui/gfx/canvas.h" | 
| 32 #include "ui/gfx/color_utils.h" | 35 #include "ui/gfx/color_utils.h" | 
| 33 #include "ui/gfx/image/image.h" | 36 #include "ui/gfx/image/image.h" | 
| 34 #include "ui/gfx/range/range.h" | 37 #include "ui/gfx/range/range.h" | 
| 35 #include "ui/gfx/render_text.h" | 38 #include "ui/gfx/render_text.h" | 
| 36 #include "ui/gfx/text_utils.h" | 39 #include "ui/gfx/text_utils.h" | 
| 37 #include "ui/native_theme/native_theme.h" | 40 #include "ui/native_theme/native_theme.h" | 
| 38 | 41 | 
| 39 using ui::NativeTheme; | 42 using ui::NativeTheme; | 
| 40 | 43 struct TextStyle { | 
|  | 44   ui::ResourceBundle::FontStyle font; | 
|  | 45   NativeTheme::ColorId color; | 
|  | 46   NativeTheme::ColorId color_hovered; | 
|  | 47   NativeTheme::ColorId color_selected; | 
|  | 48   gfx::BaselineStyle baseline; | 
|  | 49 }; | 
| 41 namespace { | 50 namespace { | 
| 42 | 51 | 
| 43 // Calls back to the OmniboxResultView when the requested image is downloaded. | 52 // Calls back to the OmniboxResultView when the requested image is downloaded. | 
| 44 // This is a separate class instead of being implemented on OmniboxResultView | 53 // This is a separate class instead of being implemented on OmniboxResultView | 
| 45 // because BitmapFetcherService currently takes ownership of this object. | 54 // because BitmapFetcherService currently takes ownership of this object. | 
| 46 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning | 55 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning | 
| 47 // ObserverList pattern and have OmniboxResultView implement the Observer call | 56 // ObserverList pattern and have OmniboxResultView implement the Observer call | 
| 48 // directly. | 57 // directly. | 
| 49 class AnswerImageObserver : public BitmapFetcherService::Observer { | 58 class AnswerImageObserver : public BitmapFetcherService::Observer { | 
| 50  public: | 59  public: | 
| (...skipping 10 matching lines...) Expand all  Loading... | 
| 61 }; | 70 }; | 
| 62 | 71 | 
| 63 void AnswerImageObserver::OnImageChanged( | 72 void AnswerImageObserver::OnImageChanged( | 
| 64     BitmapFetcherService::RequestId request_id, | 73     BitmapFetcherService::RequestId request_id, | 
| 65     const SkBitmap& image) { | 74     const SkBitmap& image) { | 
| 66   DCHECK(!image.empty()); | 75   DCHECK(!image.empty()); | 
| 67   if (view_) | 76   if (view_) | 
| 68     view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image)); | 77     view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image)); | 
| 69 } | 78 } | 
| 70 | 79 | 
| 71 // The minimum distance between the top and bottom of the {icon|text} and the |  | 
| 72 // top or bottom of the row. |  | 
| 73 const int kMinimumIconVerticalPadding = 2; |  | 
| 74 const int kMinimumTextVerticalPadding = 3; |  | 
| 75 |  | 
| 76 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to | 80 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to | 
| 77 // NativeTheme colors. | 81 // NativeTheme colors. | 
| 78 struct TranslationTable { | 82 struct TranslationTable { | 
| 79   ui::NativeTheme::ColorId id; | 83   ui::NativeTheme::ColorId id; | 
| 80   OmniboxResultView::ResultViewState state; | 84   OmniboxResultView::ResultViewState state; | 
| 81   OmniboxResultView::ColorKind kind; | 85   OmniboxResultView::ColorKind kind; | 
| 82 } static const kTranslationTable[] = { | 86 } static const kTranslationTable[] = { | 
| 83   { NativeTheme::kColorId_ResultsTableNormalBackground, | 87   { NativeTheme::kColorId_ResultsTableNormalBackground, | 
| 84     OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, | 88     OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, | 
| 85   { NativeTheme::kColorId_ResultsTableHoveredBackground, | 89   { NativeTheme::kColorId_ResultsTableHoveredBackground, | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 105   { NativeTheme::kColorId_ResultsTableSelectedUrl, | 109   { NativeTheme::kColorId_ResultsTableSelectedUrl, | 
| 106     OmniboxResultView::SELECTED, OmniboxResultView::URL }, | 110     OmniboxResultView::SELECTED, OmniboxResultView::URL }, | 
| 107   { NativeTheme::kColorId_ResultsTableNormalDivider, | 111   { NativeTheme::kColorId_ResultsTableNormalDivider, | 
| 108     OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, | 112     OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, | 
| 109   { NativeTheme::kColorId_ResultsTableHoveredDivider, | 113   { NativeTheme::kColorId_ResultsTableHoveredDivider, | 
| 110     OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, | 114     OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, | 
| 111   { NativeTheme::kColorId_ResultsTableSelectedDivider, | 115   { NativeTheme::kColorId_ResultsTableSelectedDivider, | 
| 112     OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, | 116     OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, | 
| 113 }; | 117 }; | 
| 114 | 118 | 
|  | 119 const TextStyle kTextStyles[] = { | 
|  | 120     // 1  ANSWER_TEXT | 
|  | 121     {ui::ResourceBundle::LargeFont, | 
|  | 122      NativeTheme::kColorId_ResultsTableNormalText, | 
|  | 123      NativeTheme::kColorId_ResultsTableHoveredText, | 
|  | 124      NativeTheme::kColorId_ResultsTableSelectedText, | 
|  | 125      gfx::NORMAL_BASELINE}, | 
|  | 126     // 2  HEADLINE_TEXT | 
|  | 127     {ui::ResourceBundle::LargeFont, | 
|  | 128      NativeTheme::kColorId_ResultsTableNormalDimmedText, | 
|  | 129      NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 
|  | 130      NativeTheme::kColorId_ResultsTableSelectedDimmedText, | 
|  | 131      gfx::NORMAL_BASELINE}, | 
|  | 132     // 3  TOP_ALIGNED_TEXT | 
|  | 133     {ui::ResourceBundle::LargeFont, | 
|  | 134      NativeTheme::kColorId_ResultsTableNormalDimmedText, | 
|  | 135      NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 
|  | 136      NativeTheme::kColorId_ResultsTableSelectedDimmedText, | 
|  | 137      gfx::SUPERIOR}, | 
|  | 138     // 4  DESCRIPTION_TEXT | 
|  | 139     {ui::ResourceBundle::BaseFont, | 
|  | 140      NativeTheme::kColorId_ResultsTableNormalDimmedText, | 
|  | 141      NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 
|  | 142      NativeTheme::kColorId_ResultsTableSelectedDimmedText, | 
|  | 143      gfx::NORMAL_BASELINE}, | 
|  | 144     // 5  DESCRIPTION_TEXT_NEGATIVE | 
|  | 145     {ui::ResourceBundle::LargeFont, | 
|  | 146      NativeTheme::kColorId_ResultsTableNegativeText, | 
|  | 147      NativeTheme::kColorId_ResultsTableNegativeHoveredText, | 
|  | 148      NativeTheme::kColorId_ResultsTableNegativeSelectedText, | 
|  | 149      gfx::INFERIOR}, | 
|  | 150     // 6  DESCRIPTION_TEXT_POSITIVE | 
|  | 151     {ui::ResourceBundle::LargeFont, | 
|  | 152      NativeTheme::kColorId_ResultsTablePositiveText, | 
|  | 153      NativeTheme::kColorId_ResultsTablePositiveHoveredText, | 
|  | 154      NativeTheme::kColorId_ResultsTablePositiveSelectedText, | 
|  | 155      gfx::INFERIOR}, | 
|  | 156     // 7  MORE_INFO_TEXT | 
|  | 157     {ui::ResourceBundle::SmallFont, | 
|  | 158      NativeTheme::kColorId_ResultsTableNormalDimmedText, | 
|  | 159      NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 
|  | 160      NativeTheme::kColorId_ResultsTableSelectedDimmedText, | 
|  | 161      gfx::NORMAL_BASELINE}, | 
|  | 162     // 8  SUGGESTION_TEXT | 
|  | 163     {ui::ResourceBundle::BaseFont, | 
|  | 164      NativeTheme::kColorId_ResultsTableNormalText, | 
|  | 165      NativeTheme::kColorId_ResultsTableHoveredText, | 
|  | 166      NativeTheme::kColorId_ResultsTableSelectedText, | 
|  | 167      gfx::NORMAL_BASELINE}, | 
|  | 168     // 9  SUGGESTION_TEXT_POSITIVE | 
|  | 169     {ui::ResourceBundle::BaseFont, | 
|  | 170      NativeTheme::kColorId_ResultsTablePositiveText, | 
|  | 171      NativeTheme::kColorId_ResultsTablePositiveHoveredText, | 
|  | 172      NativeTheme::kColorId_ResultsTablePositiveSelectedText, | 
|  | 173      gfx::NORMAL_BASELINE}, | 
|  | 174     // 10 SUGGESTION_TEXT_NEGATIVE | 
|  | 175     {ui::ResourceBundle::BaseFont, | 
|  | 176      NativeTheme::kColorId_ResultsTableNegativeText, | 
|  | 177      NativeTheme::kColorId_ResultsTableNegativeHoveredText, | 
|  | 178      NativeTheme::kColorId_ResultsTableNegativeSelectedText, | 
|  | 179      gfx::NORMAL_BASELINE}, | 
|  | 180     // 11 SUGGESTION_LINK_COLOR | 
|  | 181     {ui::ResourceBundle::BaseFont, | 
|  | 182      NativeTheme::kColorId_ResultsTableNormalUrl, | 
|  | 183      NativeTheme::kColorId_ResultsTableHoveredUrl, | 
|  | 184      NativeTheme::kColorId_ResultsTableSelectedUrl, | 
|  | 185      gfx::NORMAL_BASELINE}, | 
|  | 186     // 12 STATUS_TEXT | 
|  | 187     {ui::ResourceBundle::LargeFont, | 
|  | 188      NativeTheme::kColorId_ResultsTableNormalDimmedText, | 
|  | 189      NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 
|  | 190      NativeTheme::kColorId_ResultsTableSelectedDimmedText, | 
|  | 191      gfx::INFERIOR}, | 
|  | 192     // 13 PERSONALIZED_SUGGESTION_TEXT | 
|  | 193     {ui::ResourceBundle::BaseFont, | 
|  | 194      NativeTheme::kColorId_ResultsTableNormalText, | 
|  | 195      NativeTheme::kColorId_ResultsTableHoveredText, | 
|  | 196      NativeTheme::kColorId_ResultsTableSelectedText, | 
|  | 197      gfx::NORMAL_BASELINE}, | 
|  | 198 }; | 
|  | 199 | 
|  | 200 const TextStyle& GetTextStyle(size_t type) { | 
|  | 201   if (type > arraysize(kTextStyles)) | 
|  | 202     type = 1; | 
|  | 203   // Subtract one because the types are one based (not zero based). | 
|  | 204   return kTextStyles[type - 1]; | 
|  | 205 } | 
|  | 206 | 
| 115 }  // namespace | 207 }  // namespace | 
| 116 | 208 | 
| 117 //////////////////////////////////////////////////////////////////////////////// | 209 //////////////////////////////////////////////////////////////////////////////// | 
| 118 // OmniboxResultView, public: | 210 // OmniboxResultView, public: | 
| 119 | 211 | 
| 120 // This class is a utility class for calculations affected by whether the result | 212 // This class is a utility class for calculations affected by whether the result | 
| 121 // view is horizontally mirrored.  The drawing functions can be written as if | 213 // view is horizontally mirrored.  The drawing functions can be written as if | 
| 122 // all drawing occurs left-to-right, and then use this class to get the actual | 214 // all drawing occurs left-to-right, and then use this class to get the actual | 
| 123 // coordinates to begin drawing onscreen. | 215 // coordinates to begin drawing onscreen. | 
| 124 class OmniboxResultView::MirroringContext { | 216 class OmniboxResultView::MirroringContext { | 
| (...skipping 27 matching lines...) Expand all  Loading... | 
| 152 | 244 | 
| 153   DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 245   DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 
| 154 }; | 246 }; | 
| 155 | 247 | 
| 156 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, | 248 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, | 
| 157                                      int model_index, | 249                                      int model_index, | 
| 158                                      LocationBarView* location_bar_view, | 250                                      LocationBarView* location_bar_view, | 
| 159                                      const gfx::FontList& font_list) | 251                                      const gfx::FontList& font_list) | 
| 160     : edge_item_padding_(LocationBarView::kItemPadding), | 252     : edge_item_padding_(LocationBarView::kItemPadding), | 
| 161       item_padding_(LocationBarView::kItemPadding), | 253       item_padding_(LocationBarView::kItemPadding), | 
| 162       minimum_text_vertical_padding_(kMinimumTextVerticalPadding), |  | 
| 163       model_(model), | 254       model_(model), | 
| 164       model_index_(model_index), | 255       model_index_(model_index), | 
| 165       location_bar_view_(location_bar_view), | 256       location_bar_view_(location_bar_view), | 
| 166       image_service_(BitmapFetcherServiceFactory::GetForBrowserContext( | 257       image_service_(BitmapFetcherServiceFactory::GetForBrowserContext( | 
| 167           location_bar_view_->profile())), | 258           location_bar_view_->profile())), | 
| 168       font_list_(font_list), | 259       font_list_(font_list), | 
| 169       font_height_( | 260       font_height_( | 
| 170           std::max(font_list.GetHeight(), | 261           std::max(font_list.GetHeight(), | 
| 171                    font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())), | 262                    font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())), | 
| 172       mirroring_context_(new MirroringContext()), | 263       mirroring_context_(new MirroringContext()), | 
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 243 void OmniboxResultView::Invalidate() { | 334 void OmniboxResultView::Invalidate() { | 
| 244   keyword_icon_->SetImage(GetKeywordIcon()); | 335   keyword_icon_->SetImage(GetKeywordIcon()); | 
| 245   // While the text in the RenderTexts may not have changed, the styling | 336   // While the text in the RenderTexts may not have changed, the styling | 
| 246   // (color/bold) may need to change. So we reset them to cause them to be | 337   // (color/bold) may need to change. So we reset them to cause them to be | 
| 247   // recomputed in OnPaint(). | 338   // recomputed in OnPaint(). | 
| 248   ResetRenderTexts(); | 339   ResetRenderTexts(); | 
| 249   SchedulePaint(); | 340   SchedulePaint(); | 
| 250 } | 341 } | 
| 251 | 342 | 
| 252 gfx::Size OmniboxResultView::GetPreferredSize() const { | 343 gfx::Size OmniboxResultView::GetPreferredSize() const { | 
| 253   return gfx::Size(0, std::max( | 344   if (!match_.answer) | 
| 254       default_icon_size_ + (kMinimumIconVerticalPadding * 2), | 345     return gfx::Size(0, GetContentLineHeight()); | 
| 255       GetTextHeight() + (minimum_text_vertical_padding_ * 2))); | 346   // An answer implies a match and a description in a large font. | 
|  | 347   return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); | 
| 256 } | 348 } | 
| 257 | 349 | 
| 258 //////////////////////////////////////////////////////////////////////////////// | 350 //////////////////////////////////////////////////////////////////////////////// | 
| 259 // OmniboxResultView, protected: | 351 // OmniboxResultView, protected: | 
| 260 | 352 | 
| 261 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { | 353 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { | 
| 262   if (model_->IsSelectedIndex(model_index_)) | 354   if (model_->IsSelectedIndex(model_index_)) | 
| 263     return SELECTED; | 355     return SELECTED; | 
| 264   return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; | 356   return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; | 
| 265 } | 357 } | 
| (...skipping 20 matching lines...) Expand all  Loading... | 
| 286   int contents_max_width, description_max_width; | 378   int contents_max_width, description_max_width; | 
| 287   OmniboxPopupModel::ComputeMatchMaxWidths( | 379   OmniboxPopupModel::ComputeMatchMaxWidths( | 
| 288       contents->GetContentWidth(), | 380       contents->GetContentWidth(), | 
| 289       separator_width_, | 381       separator_width_, | 
| 290       description ? description->GetContentWidth() : 0, | 382       description ? description->GetContentWidth() : 0, | 
| 291       mirroring_context_->remaining_width(x), | 383       mirroring_context_->remaining_width(x), | 
| 292       !AutocompleteMatch::IsSearchType(match.type), | 384       !AutocompleteMatch::IsSearchType(match.type), | 
| 293       &contents_max_width, | 385       &contents_max_width, | 
| 294       &description_max_width); | 386       &description_max_width); | 
| 295 | 387 | 
| 296   x = DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); | 388   int after_contents_x = | 
|  | 389       DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); | 
| 297 | 390 | 
| 298   if (description_max_width != 0) { | 391   if (description_max_width != 0) { | 
| 299     x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, x, y, | 392     if (match.answer) { | 
| 300                        separator_width_); | 393       y += GetContentLineHeight(); | 
| 301 | 394       if (!answer_image_.isNull()) { | 
| 302     if (!answer_image_.isNull()) { | 395         int answer_icon_size = GetAnswerLineHeight(); | 
| 303       canvas->DrawImageInt(answer_image_, | 396         canvas->DrawImageInt( | 
| 304                            // Source x, y, w, h. | 397             answer_image_, | 
| 305                            0, 0, answer_image_.width(), answer_image_.height(), | 398             // Source x, y, w, h. | 
| 306                            // Destination x, y, w, h. | 399             0, 0, answer_image_.width(), answer_image_.height(), | 
| 307                            GetMirroredXInView(x), | 400             // Destination x, y, w, h. | 
| 308                            y + kMinimumIconVerticalPadding, default_icon_size_, | 401             GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); | 
| 309                            default_icon_size_, true); | 402         x += answer_icon_size + LocationBarView::kIconInternalPadding; | 
| 310       x += default_icon_size_ + LocationBarView::kIconInternalPadding; | 403       } | 
|  | 404     } else { | 
|  | 405       x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, | 
|  | 406                          after_contents_x, y, separator_width_); | 
| 311     } | 407     } | 
| 312 | 408 | 
| 313     DrawRenderText(match, description, false, canvas, x, y, | 409     DrawRenderText(match, description, false, canvas, x, y, | 
| 314                    description_max_width); | 410                    description_max_width); | 
| 315   } | 411   } | 
| 316 } | 412 } | 
| 317 | 413 | 
| 318 int OmniboxResultView::DrawRenderText( | 414 int OmniboxResultView::DrawRenderText( | 
| 319     const AutocompleteMatch& match, | 415     const AutocompleteMatch& match, | 
| 320     gfx::RenderText* render_text, | 416     gfx::RenderText* render_text, | 
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 371       const int start_offset = std::max(prefix_width, | 467       const int start_offset = std::max(prefix_width, | 
| 372           std::min(remaining_width - max_match_contents_width, offset)); | 468           std::min(remaining_width - max_match_contents_width, offset)); | 
| 373       right_x = x + std::min(remaining_width, start_offset + max_width); | 469       right_x = x + std::min(remaining_width, start_offset + max_width); | 
| 374       x += start_offset; | 470       x += start_offset; | 
| 375       prefix_x = x - prefix_width; | 471       prefix_x = x - prefix_width; | 
| 376     } | 472     } | 
| 377     prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? | 473     prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? | 
| 378         gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); | 474         gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); | 
| 379     prefix_render_text->SetHorizontalAlignment( | 475     prefix_render_text->SetHorizontalAlignment( | 
| 380           is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); | 476           is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); | 
| 381     prefix_render_text->SetDisplayRect(gfx::Rect( | 477     prefix_render_text->SetDisplayRect( | 
| 382           mirroring_context_->mirrored_left_coord( | 478         gfx::Rect(mirroring_context_->mirrored_left_coord( | 
| 383               prefix_x, prefix_x + prefix_width), y, | 479                       prefix_x, prefix_x + prefix_width), | 
| 384           prefix_width, height())); | 480                   y, prefix_width, GetContentLineHeight())); | 
| 385     prefix_render_text->Draw(canvas); | 481     prefix_render_text->Draw(canvas); | 
| 386   } | 482   } | 
| 387 | 483 | 
| 388   // Set the display rect to trigger eliding. | 484   // Set the display rect to trigger eliding. | 
| 389   render_text->SetDisplayRect(gfx::Rect( | 485   render_text->SetDisplayRect( | 
| 390       mirroring_context_->mirrored_left_coord(x, right_x), y, | 486       gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, | 
| 391       right_x - x, height())); | 487                 right_x - x, GetContentLineHeight())); | 
| 392   render_text->Draw(canvas); | 488   render_text->Draw(canvas); | 
| 393   return right_x; | 489   return right_x; | 
| 394 } | 490 } | 
| 395 | 491 | 
| 396 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 492 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 
| 397     const base::string16& text) const { | 493     const base::string16& text) const { | 
| 398   scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 494   scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 
| 399   render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 495   render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 
| 400   render_text->SetCursorEnabled(false); | 496   render_text->SetCursorEnabled(false); | 
| 401   render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 497   render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 547   if (!contents_rendertext_) { | 643   if (!contents_rendertext_) { | 
| 548     contents_rendertext_.reset( | 644     contents_rendertext_.reset( | 
| 549         CreateClassifiedRenderText( | 645         CreateClassifiedRenderText( | 
| 550             match_.contents, match_.contents_class, false).release()); | 646             match_.contents, match_.contents_class, false).release()); | 
| 551   } | 647   } | 
| 552 } | 648 } | 
| 553 | 649 | 
| 554 void OmniboxResultView::Layout() { | 650 void OmniboxResultView::Layout() { | 
| 555   const gfx::ImageSkia icon = GetIcon(); | 651   const gfx::ImageSkia icon = GetIcon(); | 
| 556 | 652 | 
| 557   icon_bounds_.SetRect(edge_item_padding_ + | 653   icon_bounds_.SetRect( | 
| 558       ((icon.width() == default_icon_size_) ? | 654       edge_item_padding_ + ((icon.width() == default_icon_size_) | 
| 559           0 : LocationBarView::kIconInternalPadding), | 655                                 ? 0 | 
| 560       (height() - icon.height()) / 2, icon.width(), icon.height()); | 656                                 : LocationBarView::kIconInternalPadding), | 
|  | 657       (GetContentLineHeight() - icon.height()) / 2, icon.width(), | 
|  | 658       icon.height()); | 
| 561 | 659 | 
| 562   int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; | 660   int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; | 
| 563   int text_width = width() - text_x - edge_item_padding_; | 661   int text_width = width() - text_x - edge_item_padding_; | 
| 564 | 662 | 
| 565   if (match_.associated_keyword.get()) { | 663   if (match_.associated_keyword.get()) { | 
| 566     const int kw_collapsed_size = | 664     const int kw_collapsed_size = | 
| 567         keyword_icon_->width() + edge_item_padding_; | 665         keyword_icon_->width() + edge_item_padding_; | 
| 568     const int max_kw_x = width() - kw_collapsed_size; | 666     const int max_kw_x = width() - kw_collapsed_size; | 
| 569     const int kw_x = | 667     const int kw_x = | 
| 570         animation_->CurrentValueBetween(max_kw_x, edge_item_padding_); | 668         animation_->CurrentValueBetween(max_kw_x, edge_item_padding_); | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
| 595   if (!ShowOnlyKeywordMatch()) { | 693   if (!ShowOnlyKeywordMatch()) { | 
| 596     canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 694     canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 
| 597                          icon_bounds_.y()); | 695                          icon_bounds_.y()); | 
| 598     int x = GetMirroredXForRect(text_bounds_); | 696     int x = GetMirroredXForRect(text_bounds_); | 
| 599     mirroring_context_->Initialize(x, text_bounds_.width()); | 697     mirroring_context_->Initialize(x, text_bounds_.width()); | 
| 600     InitContentsRenderTextIfNecessary(); | 698     InitContentsRenderTextIfNecessary(); | 
| 601 | 699 | 
| 602     if (!description_rendertext_) { | 700     if (!description_rendertext_) { | 
| 603       if (match_.answer) { | 701       if (match_.answer) { | 
| 604         base::string16 text; | 702         base::string16 text; | 
| 605         for (const auto& textfield : match_.answer->second_line().text_fields()) |  | 
| 606           text += textfield.text(); |  | 
| 607         description_rendertext_ = CreateRenderText(text); | 703         description_rendertext_ = CreateRenderText(text); | 
|  | 704         for (const SuggestionAnswer::TextField& textfield : | 
|  | 705              match_.answer->second_line().text_fields()) | 
|  | 706           AppendAnswerText(description_rendertext_.get(), textfield); | 
|  | 707         if (match_.answer->second_line().additional_text()) { | 
|  | 708           AppendAnswerText(description_rendertext_.get(), | 
|  | 709                            *match_.answer->second_line().additional_text()); | 
|  | 710         } | 
|  | 711         if (match_.answer->second_line().status_text()) { | 
|  | 712           AppendAnswerText(description_rendertext_.get(), | 
|  | 713                            *match_.answer->second_line().status_text()); | 
|  | 714         } | 
| 608       } else if (!match_.description.empty()) { | 715       } else if (!match_.description.empty()) { | 
| 609         description_rendertext_ = CreateClassifiedRenderText( | 716         description_rendertext_ = CreateClassifiedRenderText( | 
| 610             match_.description, match_.description_class, true); | 717             match_.description, match_.description_class, true); | 
| 611       } | 718       } | 
| 612     } | 719     } | 
| 613     PaintMatch(match_, contents_rendertext_.get(), | 720     PaintMatch(match_, contents_rendertext_.get(), | 
| 614                description_rendertext_.get(), canvas, x); | 721                description_rendertext_.get(), canvas, x); | 
| 615   } | 722   } | 
| 616 | 723 | 
| 617   AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 724   AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
| 633     } | 740     } | 
| 634     PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 741     PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 
| 635                keyword_description_rendertext_.get(), canvas, x); | 742                keyword_description_rendertext_.get(), canvas, x); | 
| 636   } | 743   } | 
| 637 } | 744 } | 
| 638 | 745 | 
| 639 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 746 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 
| 640   Layout(); | 747   Layout(); | 
| 641   SchedulePaint(); | 748   SchedulePaint(); | 
| 642 } | 749 } | 
|  | 750 | 
|  | 751 int OmniboxResultView::GetAnswerLineHeight() const { | 
|  | 752   // GetTextStyle(1) is the largest fonts used and so set the boundary that all | 
|  | 753   // the other answer styles fit within. | 
|  | 754   return ui::ResourceBundle::GetSharedInstance() | 
|  | 755       .GetFontList(GetTextStyle(1).font) | 
|  | 756       .GetHeight(); | 
|  | 757 } | 
|  | 758 | 
|  | 759 int OmniboxResultView::GetContentLineHeight() const { | 
|  | 760   return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), | 
|  | 761                   GetTextHeight() + (kMinimumTextVerticalPadding * 2)); | 
|  | 762 } | 
|  | 763 | 
|  | 764 SkColor OmniboxResultView::GetStateColor(const TextStyle& text_style) const { | 
|  | 765   switch (GetState()) { | 
|  | 766     case SELECTED: | 
|  | 767       return GetNativeTheme()->GetSystemColor(text_style.color_selected); | 
|  | 768     case HOVERED: | 
|  | 769       GetNativeTheme()->GetSystemColor(text_style.color_hovered); | 
|  | 770     default: | 
|  | 771       return GetNativeTheme()->GetSystemColor(text_style.color); | 
|  | 772   } | 
|  | 773 } | 
|  | 774 | 
|  | 775 void OmniboxResultView::AppendAnswerText( | 
|  | 776     gfx::RenderText* render_text, | 
|  | 777     const SuggestionAnswer::TextField& text_field) { | 
|  | 778   int offset = render_text->text().length(); | 
|  | 779   gfx::Range range(offset, offset + text_field.text().length()); | 
|  | 780   render_text->AppendText(text_field.text()); | 
|  | 781   const TextStyle& text_style = GetTextStyle(text_field.type()); | 
|  | 782   render_text->SetFontList( | 
|  | 783       ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font)); | 
|  | 784   render_text->ApplyColor(GetStateColor(text_style), range); | 
|  | 785   render_text->ApplyBaselineStyle(text_style.baseline, range); | 
|  | 786 } | 
| OLD | NEW | 
|---|