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