Chromium Code Reviews| 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 |
| 44 // TODO(dschuyler): Look into moving this back into the unnamed namespace. | |
|
Peter Kasting
2015/03/17 23:18:06
I'm not sure why you TODOd this when I had a very
dschuyler
2015/03/18 00:13:36
I didn't mean to TODO it indefinitely. Only that
| |
| 45 struct TextStyle { | |
| 46 ui::ResourceBundle::FontStyle font; | |
| 47 NativeTheme::ColorId color; | |
| 48 NativeTheme::ColorId color_hovered; | |
| 49 NativeTheme::ColorId color_selected; | |
| 50 gfx::BaselineStyle baseline; | |
| 51 }; | |
| 52 | |
| 41 namespace { | 53 namespace { |
| 42 | 54 |
| 55 // The minimum distance between the top and bottom of the icon and the | |
| 56 // top or bottom of the row. | |
| 57 const int kMinimumIconVerticalPadding = 2; | |
| 58 | |
| 43 // Calls back to the OmniboxResultView when the requested image is downloaded. | 59 // Calls back to the OmniboxResultView when the requested image is downloaded. |
| 44 // This is a separate class instead of being implemented on OmniboxResultView | 60 // This is a separate class instead of being implemented on OmniboxResultView |
| 45 // because BitmapFetcherService currently takes ownership of this object. | 61 // because BitmapFetcherService currently takes ownership of this object. |
| 46 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning | 62 // TODO(dschuyler): Make BitmapFetcherService use the more typical non-owning |
| 47 // ObserverList pattern and have OmniboxResultView implement the Observer call | 63 // ObserverList pattern and have OmniboxResultView implement the Observer call |
| 48 // directly. | 64 // directly. |
| 49 class AnswerImageObserver : public BitmapFetcherService::Observer { | 65 class AnswerImageObserver : public BitmapFetcherService::Observer { |
| 50 public: | 66 public: |
| 51 explicit AnswerImageObserver( | 67 explicit AnswerImageObserver( |
| 52 const base::WeakPtr<OmniboxResultView>& view) | 68 const base::WeakPtr<OmniboxResultView>& view) |
| 53 : view_(view) {} | 69 : view_(view) {} |
| 54 | 70 |
| 55 void OnImageChanged(BitmapFetcherService::RequestId request_id, | 71 void OnImageChanged(BitmapFetcherService::RequestId request_id, |
| 56 const SkBitmap& image) override; | 72 const SkBitmap& image) override; |
| 57 | 73 |
| 58 private: | 74 private: |
| 59 const base::WeakPtr<OmniboxResultView> view_; | 75 const base::WeakPtr<OmniboxResultView> view_; |
| 60 DISALLOW_COPY_AND_ASSIGN(AnswerImageObserver); | 76 DISALLOW_COPY_AND_ASSIGN(AnswerImageObserver); |
| 61 }; | 77 }; |
| 62 | 78 |
| 63 void AnswerImageObserver::OnImageChanged( | 79 void AnswerImageObserver::OnImageChanged( |
| 64 BitmapFetcherService::RequestId request_id, | 80 BitmapFetcherService::RequestId request_id, |
| 65 const SkBitmap& image) { | 81 const SkBitmap& image) { |
| 66 DCHECK(!image.empty()); | 82 DCHECK(!image.empty()); |
| 67 if (view_) | 83 if (view_) |
| 68 view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image)); | 84 view_->SetAnswerImage(gfx::ImageSkia::CreateFrom1xBitmap(image)); |
| 69 } | 85 } |
| 70 | 86 |
| 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 | 87 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
| 77 // NativeTheme colors. | 88 // NativeTheme colors. |
| 78 struct TranslationTable { | 89 struct TranslationTable { |
| 79 ui::NativeTheme::ColorId id; | 90 ui::NativeTheme::ColorId id; |
| 80 OmniboxResultView::ResultViewState state; | 91 OmniboxResultView::ResultViewState state; |
| 81 OmniboxResultView::ColorKind kind; | 92 OmniboxResultView::ColorKind kind; |
| 82 } static const kTranslationTable[] = { | 93 } static const kTranslationTable[] = { |
| 83 { NativeTheme::kColorId_ResultsTableNormalBackground, | 94 { NativeTheme::kColorId_ResultsTableNormalBackground, |
| 84 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, | 95 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, |
| 85 { NativeTheme::kColorId_ResultsTableHoveredBackground, | 96 { NativeTheme::kColorId_ResultsTableHoveredBackground, |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 105 { NativeTheme::kColorId_ResultsTableSelectedUrl, | 116 { NativeTheme::kColorId_ResultsTableSelectedUrl, |
| 106 OmniboxResultView::SELECTED, OmniboxResultView::URL }, | 117 OmniboxResultView::SELECTED, OmniboxResultView::URL }, |
| 107 { NativeTheme::kColorId_ResultsTableNormalDivider, | 118 { NativeTheme::kColorId_ResultsTableNormalDivider, |
| 108 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, | 119 OmniboxResultView::NORMAL, OmniboxResultView::DIVIDER }, |
| 109 { NativeTheme::kColorId_ResultsTableHoveredDivider, | 120 { NativeTheme::kColorId_ResultsTableHoveredDivider, |
| 110 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, | 121 OmniboxResultView::HOVERED, OmniboxResultView::DIVIDER }, |
| 111 { NativeTheme::kColorId_ResultsTableSelectedDivider, | 122 { NativeTheme::kColorId_ResultsTableSelectedDivider, |
| 112 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, | 123 OmniboxResultView::SELECTED, OmniboxResultView::DIVIDER }, |
| 113 }; | 124 }; |
| 114 | 125 |
| 126 const TextStyle kTextStyles[] = { | |
| 127 // 1 ANSWER_TEXT | |
| 128 {ui::ResourceBundle::LargeFont, | |
| 129 NativeTheme::kColorId_ResultsTableNormalText, | |
| 130 NativeTheme::kColorId_ResultsTableHoveredText, | |
| 131 NativeTheme::kColorId_ResultsTableSelectedText, | |
| 132 gfx::NORMAL_BASELINE}, | |
| 133 // 2 HEADLINE_TEXT | |
| 134 {ui::ResourceBundle::LargeFont, | |
| 135 NativeTheme::kColorId_ResultsTableNormalDimmedText, | |
| 136 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | |
| 137 NativeTheme::kColorId_ResultsTableSelectedDimmedText, | |
| 138 gfx::NORMAL_BASELINE}, | |
| 139 // 3 TOP_ALIGNED_TEXT | |
| 140 {ui::ResourceBundle::LargeFont, | |
| 141 NativeTheme::kColorId_ResultsTableNormalDimmedText, | |
| 142 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | |
| 143 NativeTheme::kColorId_ResultsTableSelectedDimmedText, | |
| 144 gfx::SUPERIOR}, | |
| 145 // 4 DESCRIPTION_TEXT | |
| 146 {ui::ResourceBundle::BaseFont, | |
| 147 NativeTheme::kColorId_ResultsTableNormalDimmedText, | |
| 148 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | |
| 149 NativeTheme::kColorId_ResultsTableSelectedDimmedText, | |
| 150 gfx::NORMAL_BASELINE}, | |
| 151 // 5 DESCRIPTION_TEXT_NEGATIVE | |
| 152 {ui::ResourceBundle::LargeFont, | |
| 153 NativeTheme::kColorId_ResultsTableNegativeText, | |
| 154 NativeTheme::kColorId_ResultsTableNegativeHoveredText, | |
| 155 NativeTheme::kColorId_ResultsTableNegativeSelectedText, | |
| 156 gfx::INFERIOR}, | |
| 157 // 6 DESCRIPTION_TEXT_POSITIVE | |
| 158 {ui::ResourceBundle::LargeFont, | |
| 159 NativeTheme::kColorId_ResultsTablePositiveText, | |
| 160 NativeTheme::kColorId_ResultsTablePositiveHoveredText, | |
| 161 NativeTheme::kColorId_ResultsTablePositiveSelectedText, | |
| 162 gfx::INFERIOR}, | |
| 163 // 7 MORE_INFO_TEXT | |
| 164 {ui::ResourceBundle::SmallFont, | |
| 165 NativeTheme::kColorId_ResultsTableNormalDimmedText, | |
| 166 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | |
| 167 NativeTheme::kColorId_ResultsTableSelectedDimmedText, | |
| 168 gfx::NORMAL_BASELINE}, | |
| 169 // 8 SUGGESTION_TEXT | |
| 170 {ui::ResourceBundle::BaseFont, | |
| 171 NativeTheme::kColorId_ResultsTableNormalText, | |
| 172 NativeTheme::kColorId_ResultsTableHoveredText, | |
| 173 NativeTheme::kColorId_ResultsTableSelectedText, | |
| 174 gfx::NORMAL_BASELINE}, | |
| 175 // 9 SUGGESTION_TEXT_POSITIVE | |
| 176 {ui::ResourceBundle::BaseFont, | |
| 177 NativeTheme::kColorId_ResultsTablePositiveText, | |
| 178 NativeTheme::kColorId_ResultsTablePositiveHoveredText, | |
| 179 NativeTheme::kColorId_ResultsTablePositiveSelectedText, | |
| 180 gfx::NORMAL_BASELINE}, | |
| 181 // 10 SUGGESTION_TEXT_NEGATIVE | |
| 182 {ui::ResourceBundle::BaseFont, | |
| 183 NativeTheme::kColorId_ResultsTableNegativeText, | |
| 184 NativeTheme::kColorId_ResultsTableNegativeHoveredText, | |
| 185 NativeTheme::kColorId_ResultsTableNegativeSelectedText, | |
| 186 gfx::NORMAL_BASELINE}, | |
| 187 // 11 SUGGESTION_LINK_COLOR | |
| 188 {ui::ResourceBundle::BaseFont, | |
| 189 NativeTheme::kColorId_ResultsTableNormalUrl, | |
| 190 NativeTheme::kColorId_ResultsTableHoveredUrl, | |
| 191 NativeTheme::kColorId_ResultsTableSelectedUrl, | |
| 192 gfx::NORMAL_BASELINE}, | |
| 193 // 12 STATUS_TEXT | |
| 194 {ui::ResourceBundle::LargeFont, | |
| 195 NativeTheme::kColorId_ResultsTableNormalDimmedText, | |
| 196 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | |
| 197 NativeTheme::kColorId_ResultsTableSelectedDimmedText, | |
| 198 gfx::INFERIOR}, | |
| 199 // 13 PERSONALIZED_SUGGESTION_TEXT | |
| 200 {ui::ResourceBundle::BaseFont, | |
| 201 NativeTheme::kColorId_ResultsTableNormalText, | |
| 202 NativeTheme::kColorId_ResultsTableHoveredText, | |
| 203 NativeTheme::kColorId_ResultsTableSelectedText, | |
| 204 gfx::NORMAL_BASELINE}, | |
| 205 }; | |
| 206 | |
| 207 const TextStyle& GetTextStyle(size_t type) { | |
| 208 if (type > arraysize(kTextStyles)) | |
| 209 type = 1; | |
| 210 // Subtract one because the types are one based (not zero based). | |
| 211 return kTextStyles[type - 1]; | |
| 212 } | |
| 213 | |
| 115 } // namespace | 214 } // namespace |
| 116 | 215 |
| 117 //////////////////////////////////////////////////////////////////////////////// | 216 //////////////////////////////////////////////////////////////////////////////// |
| 118 // OmniboxResultView, public: | 217 // OmniboxResultView, public: |
| 119 | 218 |
| 120 // This class is a utility class for calculations affected by whether the result | 219 // 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 | 220 // 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 | 221 // all drawing occurs left-to-right, and then use this class to get the actual |
| 123 // coordinates to begin drawing onscreen. | 222 // coordinates to begin drawing onscreen. |
| 124 class OmniboxResultView::MirroringContext { | 223 class OmniboxResultView::MirroringContext { |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 152 | 251 |
| 153 DISALLOW_COPY_AND_ASSIGN(MirroringContext); | 252 DISALLOW_COPY_AND_ASSIGN(MirroringContext); |
| 154 }; | 253 }; |
| 155 | 254 |
| 156 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, | 255 OmniboxResultView::OmniboxResultView(OmniboxPopupContentsView* model, |
| 157 int model_index, | 256 int model_index, |
| 158 LocationBarView* location_bar_view, | 257 LocationBarView* location_bar_view, |
| 159 const gfx::FontList& font_list) | 258 const gfx::FontList& font_list) |
| 160 : edge_item_padding_(LocationBarView::kItemPadding), | 259 : edge_item_padding_(LocationBarView::kItemPadding), |
| 161 item_padding_(LocationBarView::kItemPadding), | 260 item_padding_(LocationBarView::kItemPadding), |
| 162 minimum_text_vertical_padding_(kMinimumTextVerticalPadding), | |
| 163 model_(model), | 261 model_(model), |
| 164 model_index_(model_index), | 262 model_index_(model_index), |
| 165 location_bar_view_(location_bar_view), | 263 location_bar_view_(location_bar_view), |
| 166 image_service_(BitmapFetcherServiceFactory::GetForBrowserContext( | 264 image_service_(BitmapFetcherServiceFactory::GetForBrowserContext( |
| 167 location_bar_view_->profile())), | 265 location_bar_view_->profile())), |
| 168 font_list_(font_list), | 266 font_list_(font_list), |
| 169 font_height_( | 267 font_height_( |
| 170 std::max(font_list.GetHeight(), | 268 std::max(font_list.GetHeight(), |
| 171 font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())), | 269 font_list.DeriveWithStyle(gfx::Font::BOLD).GetHeight())), |
| 172 mirroring_context_(new MirroringContext()), | 270 mirroring_context_(new MirroringContext()), |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 void OmniboxResultView::Invalidate() { | 341 void OmniboxResultView::Invalidate() { |
| 244 keyword_icon_->SetImage(GetKeywordIcon()); | 342 keyword_icon_->SetImage(GetKeywordIcon()); |
| 245 // While the text in the RenderTexts may not have changed, the styling | 343 // 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 | 344 // (color/bold) may need to change. So we reset them to cause them to be |
| 247 // recomputed in OnPaint(). | 345 // recomputed in OnPaint(). |
| 248 ResetRenderTexts(); | 346 ResetRenderTexts(); |
| 249 SchedulePaint(); | 347 SchedulePaint(); |
| 250 } | 348 } |
| 251 | 349 |
| 252 gfx::Size OmniboxResultView::GetPreferredSize() const { | 350 gfx::Size OmniboxResultView::GetPreferredSize() const { |
| 253 return gfx::Size(0, std::max( | 351 if (!match_.answer) |
| 254 default_icon_size_ + (kMinimumIconVerticalPadding * 2), | 352 return gfx::Size(0, GetContentLineHeight()); |
| 255 GetTextHeight() + (minimum_text_vertical_padding_ * 2))); | 353 // An answer implies a match and a description in a large font. |
| 354 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); | |
| 256 } | 355 } |
| 257 | 356 |
| 258 //////////////////////////////////////////////////////////////////////////////// | 357 //////////////////////////////////////////////////////////////////////////////// |
| 259 // OmniboxResultView, protected: | 358 // OmniboxResultView, protected: |
| 260 | 359 |
| 261 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { | 360 OmniboxResultView::ResultViewState OmniboxResultView::GetState() const { |
| 262 if (model_->IsSelectedIndex(model_index_)) | 361 if (model_->IsSelectedIndex(model_index_)) |
| 263 return SELECTED; | 362 return SELECTED; |
| 264 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; | 363 return model_->IsHoveredIndex(model_index_) ? HOVERED : NORMAL; |
| 265 } | 364 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 286 int contents_max_width, description_max_width; | 385 int contents_max_width, description_max_width; |
| 287 OmniboxPopupModel::ComputeMatchMaxWidths( | 386 OmniboxPopupModel::ComputeMatchMaxWidths( |
| 288 contents->GetContentWidth(), | 387 contents->GetContentWidth(), |
| 289 separator_width_, | 388 separator_width_, |
| 290 description ? description->GetContentWidth() : 0, | 389 description ? description->GetContentWidth() : 0, |
| 291 mirroring_context_->remaining_width(x), | 390 mirroring_context_->remaining_width(x), |
| 292 !AutocompleteMatch::IsSearchType(match.type), | 391 !AutocompleteMatch::IsSearchType(match.type), |
| 293 &contents_max_width, | 392 &contents_max_width, |
| 294 &description_max_width); | 393 &description_max_width); |
| 295 | 394 |
| 296 x = DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); | 395 int after_contents_x = |
| 396 DrawRenderText(match, contents, true, canvas, x, y, contents_max_width); | |
| 297 | 397 |
| 298 if (description_max_width != 0) { | 398 if (description_max_width != 0) { |
| 299 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, x, y, | 399 if (match.answer) { |
| 300 separator_width_); | 400 y += GetContentLineHeight(); |
| 301 | 401 if (!answer_image_.isNull()) { |
| 302 if (!answer_image_.isNull()) { | 402 int answer_icon_size = GetAnswerLineHeight(); |
| 303 canvas->DrawImageInt(answer_image_, | 403 canvas->DrawImageInt( |
| 304 // Source x, y, w, h. | 404 answer_image_, |
| 305 0, 0, answer_image_.width(), answer_image_.height(), | 405 // Source x, y, w, h. |
| 306 // Destination x, y, w, h. | 406 0, 0, answer_image_.width(), answer_image_.height(), |
| 307 GetMirroredXInView(x), | 407 // Destination x, y, w, h. |
| 308 y + kMinimumIconVerticalPadding, default_icon_size_, | 408 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); |
| 309 default_icon_size_, true); | 409 x += answer_icon_size + LocationBarView::kIconInternalPadding; |
| 310 x += default_icon_size_ + LocationBarView::kIconInternalPadding; | 410 } |
| 411 } else { | |
| 412 x = DrawRenderText(match, separator_rendertext_.get(), false, canvas, | |
| 413 after_contents_x, y, separator_width_); | |
| 311 } | 414 } |
| 312 | 415 |
| 313 DrawRenderText(match, description, false, canvas, x, y, | 416 DrawRenderText(match, description, false, canvas, x, y, |
| 314 description_max_width); | 417 description_max_width); |
| 315 } | 418 } |
| 316 } | 419 } |
| 317 | 420 |
| 318 int OmniboxResultView::DrawRenderText( | 421 int OmniboxResultView::DrawRenderText( |
| 319 const AutocompleteMatch& match, | 422 const AutocompleteMatch& match, |
| 320 gfx::RenderText* render_text, | 423 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, | 474 const int start_offset = std::max(prefix_width, |
| 372 std::min(remaining_width - max_match_contents_width, offset)); | 475 std::min(remaining_width - max_match_contents_width, offset)); |
| 373 right_x = x + std::min(remaining_width, start_offset + max_width); | 476 right_x = x + std::min(remaining_width, start_offset + max_width); |
| 374 x += start_offset; | 477 x += start_offset; |
| 375 prefix_x = x - prefix_width; | 478 prefix_x = x - prefix_width; |
| 376 } | 479 } |
| 377 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? | 480 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? |
| 378 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); | 481 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); |
| 379 prefix_render_text->SetHorizontalAlignment( | 482 prefix_render_text->SetHorizontalAlignment( |
| 380 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); | 483 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); |
| 381 prefix_render_text->SetDisplayRect(gfx::Rect( | 484 prefix_render_text->SetDisplayRect( |
| 382 mirroring_context_->mirrored_left_coord( | 485 gfx::Rect(mirroring_context_->mirrored_left_coord( |
| 383 prefix_x, prefix_x + prefix_width), y, | 486 prefix_x, prefix_x + prefix_width), |
| 384 prefix_width, height())); | 487 y, prefix_width, GetContentLineHeight())); |
| 385 prefix_render_text->Draw(canvas); | 488 prefix_render_text->Draw(canvas); |
| 386 } | 489 } |
| 387 | 490 |
| 388 // Set the display rect to trigger eliding. | 491 // Set the display rect to trigger eliding. |
| 389 render_text->SetDisplayRect(gfx::Rect( | 492 render_text->SetDisplayRect( |
| 390 mirroring_context_->mirrored_left_coord(x, right_x), y, | 493 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, |
| 391 right_x - x, height())); | 494 right_x - x, GetContentLineHeight())); |
| 392 render_text->Draw(canvas); | 495 render_text->Draw(canvas); |
| 393 return right_x; | 496 return right_x; |
| 394 } | 497 } |
| 395 | 498 |
| 396 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 499 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( |
| 397 const base::string16& text) const { | 500 const base::string16& text) const { |
| 398 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 501 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); |
| 399 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 502 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
| 400 render_text->SetCursorEnabled(false); | 503 render_text->SetCursorEnabled(false); |
| 401 render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 504 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 if (!contents_rendertext_) { | 650 if (!contents_rendertext_) { |
| 548 contents_rendertext_.reset( | 651 contents_rendertext_.reset( |
| 549 CreateClassifiedRenderText( | 652 CreateClassifiedRenderText( |
| 550 match_.contents, match_.contents_class, false).release()); | 653 match_.contents, match_.contents_class, false).release()); |
| 551 } | 654 } |
| 552 } | 655 } |
| 553 | 656 |
| 554 void OmniboxResultView::Layout() { | 657 void OmniboxResultView::Layout() { |
| 555 const gfx::ImageSkia icon = GetIcon(); | 658 const gfx::ImageSkia icon = GetIcon(); |
| 556 | 659 |
| 557 icon_bounds_.SetRect(edge_item_padding_ + | 660 icon_bounds_.SetRect( |
| 558 ((icon.width() == default_icon_size_) ? | 661 edge_item_padding_ + ((icon.width() == default_icon_size_) |
| 559 0 : LocationBarView::kIconInternalPadding), | 662 ? 0 |
| 560 (height() - icon.height()) / 2, icon.width(), icon.height()); | 663 : LocationBarView::kIconInternalPadding), |
| 664 (GetContentLineHeight() - icon.height()) / 2, icon.width(), | |
| 665 icon.height()); | |
| 561 | 666 |
| 562 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; | 667 int text_x = edge_item_padding_ + default_icon_size_ + item_padding_; |
| 563 int text_width = width() - text_x - edge_item_padding_; | 668 int text_width = width() - text_x - edge_item_padding_; |
| 564 | 669 |
| 565 if (match_.associated_keyword.get()) { | 670 if (match_.associated_keyword.get()) { |
| 566 const int kw_collapsed_size = | 671 const int kw_collapsed_size = |
| 567 keyword_icon_->width() + edge_item_padding_; | 672 keyword_icon_->width() + edge_item_padding_; |
| 568 const int max_kw_x = width() - kw_collapsed_size; | 673 const int max_kw_x = width() - kw_collapsed_size; |
| 569 const int kw_x = | 674 const int kw_x = |
| 570 animation_->CurrentValueBetween(max_kw_x, edge_item_padding_); | 675 animation_->CurrentValueBetween(max_kw_x, edge_item_padding_); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 595 if (!ShowOnlyKeywordMatch()) { | 700 if (!ShowOnlyKeywordMatch()) { |
| 596 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 701 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), |
| 597 icon_bounds_.y()); | 702 icon_bounds_.y()); |
| 598 int x = GetMirroredXForRect(text_bounds_); | 703 int x = GetMirroredXForRect(text_bounds_); |
| 599 mirroring_context_->Initialize(x, text_bounds_.width()); | 704 mirroring_context_->Initialize(x, text_bounds_.width()); |
| 600 InitContentsRenderTextIfNecessary(); | 705 InitContentsRenderTextIfNecessary(); |
| 601 | 706 |
| 602 if (!description_rendertext_) { | 707 if (!description_rendertext_) { |
| 603 if (match_.answer) { | 708 if (match_.answer) { |
| 604 base::string16 text; | 709 base::string16 text; |
| 605 for (const auto& textfield : match_.answer->second_line().text_fields()) | |
| 606 text += textfield.text(); | |
| 607 description_rendertext_ = CreateRenderText(text); | 710 description_rendertext_ = CreateRenderText(text); |
| 711 for (const SuggestionAnswer::TextField& textfield : | |
| 712 match_.answer->second_line().text_fields()) | |
| 713 AppendAnswerText(description_rendertext_.get(), textfield); | |
| 714 if (match_.answer->second_line().additional_text()) { | |
| 715 AppendAnswerText(description_rendertext_.get(), | |
| 716 *match_.answer->second_line().additional_text()); | |
| 717 } | |
| 718 if (match_.answer->second_line().status_text()) { | |
| 719 AppendAnswerText(description_rendertext_.get(), | |
| 720 *match_.answer->second_line().status_text()); | |
| 721 } | |
| 608 } else if (!match_.description.empty()) { | 722 } else if (!match_.description.empty()) { |
| 609 description_rendertext_ = CreateClassifiedRenderText( | 723 description_rendertext_ = CreateClassifiedRenderText( |
| 610 match_.description, match_.description_class, true); | 724 match_.description, match_.description_class, true); |
| 611 } | 725 } |
| 612 } | 726 } |
| 613 PaintMatch(match_, contents_rendertext_.get(), | 727 PaintMatch(match_, contents_rendertext_.get(), |
| 614 description_rendertext_.get(), canvas, x); | 728 description_rendertext_.get(), canvas, x); |
| 615 } | 729 } |
| 616 | 730 |
| 617 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 731 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 633 } | 747 } |
| 634 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 748 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), |
| 635 keyword_description_rendertext_.get(), canvas, x); | 749 keyword_description_rendertext_.get(), canvas, x); |
| 636 } | 750 } |
| 637 } | 751 } |
| 638 | 752 |
| 639 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 753 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
| 640 Layout(); | 754 Layout(); |
| 641 SchedulePaint(); | 755 SchedulePaint(); |
| 642 } | 756 } |
| 757 | |
| 758 int OmniboxResultView::GetAnswerLineHeight() const { | |
| 759 // GetTextStyle(1) is the largest font used and so defines the boundary that | |
| 760 // all the other answer styles fit within. | |
| 761 return ui::ResourceBundle::GetSharedInstance() | |
| 762 .GetFontList(GetTextStyle(1).font) | |
| 763 .GetHeight(); | |
| 764 } | |
| 765 | |
| 766 int OmniboxResultView::GetContentLineHeight() const { | |
| 767 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), | |
| 768 GetTextHeight() + (kMinimumTextVerticalPadding * 2)); | |
| 769 } | |
| 770 | |
| 771 SkColor OmniboxResultView::GetStateColor(const TextStyle& text_style) const { | |
| 772 switch (GetState()) { | |
| 773 case SELECTED: | |
| 774 return GetNativeTheme()->GetSystemColor(text_style.color_selected); | |
| 775 case HOVERED: | |
| 776 return GetNativeTheme()->GetSystemColor(text_style.color_hovered); | |
| 777 default: | |
| 778 return GetNativeTheme()->GetSystemColor(text_style.color); | |
| 779 } | |
| 780 } | |
| 781 | |
| 782 void OmniboxResultView::AppendAnswerText( | |
| 783 gfx::RenderText* render_text, | |
| 784 const SuggestionAnswer::TextField& text_field) { | |
| 785 int offset = render_text->text().length(); | |
| 786 gfx::Range range(offset, offset + text_field.text().length()); | |
| 787 render_text->AppendText(text_field.text()); | |
| 788 const TextStyle& text_style = GetTextStyle(text_field.type()); | |
| 789 // TODO(dschuyler): Replace SetFontList with a feature to set the font size | |
| 790 // for a sub-range within RenderText. | |
|
Peter Kasting
2015/03/17 23:18:06
You said this is "not currently showing issues".
dschuyler
2015/03/18 00:13:36
The UI font info seems to cover more text options
| |
| 791 // render_text->ApplyFontSize(text_style.font_size, range); | |
| 792 render_text->SetFontList( | |
| 793 ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font)); | |
| 794 render_text->ApplyColor(GetStateColor(text_style), range); | |
| 795 render_text->ApplyBaselineStyle(text_style.baseline, range); | |
| 796 } | |
| OLD | NEW |