| 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 | 7 |
| 8 #if defined(OS_WIN) | 8 #if defined(OS_WIN) |
| 9 #include <atlbase.h> // NOLINT | 9 #include <atlbase.h> // NOLINT |
| 10 #include <atlwin.h> // NOLINT | 10 #include <atlwin.h> // NOLINT |
| 11 #endif | 11 #endif |
| 12 | 12 |
| 13 #include "base/macros.h" | 13 #include "base/macros.h" |
| 14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" | 14 #include "chrome/browser/ui/views/omnibox/omnibox_result_view.h" |
| 15 | 15 |
| 16 #include <limits.h> | 16 #include <limits.h> |
| 17 | 17 |
| 18 #include <algorithm> // NOLINT | 18 #include <algorithm> // NOLINT |
| 19 | 19 |
| 20 #include "base/i18n/bidi_line_iterator.h" | 20 #include "base/i18n/bidi_line_iterator.h" |
| 21 #include "base/strings/string_number_conversions.h" | 21 #include "base/strings/string_number_conversions.h" |
| 22 #include "base/strings/string_util.h" | 22 #include "base/strings/string_util.h" |
| 23 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" | 23 #include "chrome/browser/ui/views/location_bar/background_with_1_px_border.h" |
| 24 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 24 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 25 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 25 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
| 26 #include "chrome/grit/generated_resources.h" | 26 #include "chrome/grit/generated_resources.h" |
| 27 #include "components/grit/components_scaled_resources.h" | 27 #include "components/grit/components_scaled_resources.h" |
| 28 #include "components/omnibox/browser/omnibox_popup_model.h" | 28 #include "components/omnibox/browser/omnibox_popup_model.h" |
| 29 #include "components/omnibox/browser/vector_icons.h" |
| 29 #include "third_party/skia/include/core/SkColor.h" | 30 #include "third_party/skia/include/core/SkColor.h" |
| 30 #include "ui/accessibility/ax_node_data.h" | 31 #include "ui/accessibility/ax_node_data.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 32 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/base/material_design/material_design_controller.h" | 33 #include "ui/base/material_design/material_design_controller.h" |
| 33 #include "ui/base/resource/resource_bundle.h" | 34 #include "ui/base/resource/resource_bundle.h" |
| 34 #include "ui/base/theme_provider.h" | 35 #include "ui/base/theme_provider.h" |
| 35 #include "ui/gfx/canvas.h" | 36 #include "ui/gfx/canvas.h" |
| 36 #include "ui/gfx/color_palette.h" | 37 #include "ui/gfx/color_palette.h" |
| 37 #include "ui/gfx/color_utils.h" | 38 #include "ui/gfx/color_utils.h" |
| 38 #include "ui/gfx/image/image.h" | 39 #include "ui/gfx/image/image.h" |
| 39 #include "ui/gfx/paint_vector_icon.h" | 40 #include "ui/gfx/paint_vector_icon.h" |
| 40 #include "ui/gfx/range/range.h" | 41 #include "ui/gfx/range/range.h" |
| 41 #include "ui/gfx/render_text.h" | 42 #include "ui/gfx/render_text.h" |
| 42 #include "ui/gfx/text_utils.h" | 43 #include "ui/gfx/text_utils.h" |
| 43 #include "ui/gfx/vector_icons_public.h" | |
| 44 #include "ui/native_theme/native_theme.h" | 44 #include "ui/native_theme/native_theme.h" |
| 45 | 45 |
| 46 using ui::NativeTheme; | 46 using ui::NativeTheme; |
| 47 | 47 |
| 48 namespace { | 48 namespace { |
| 49 | 49 |
| 50 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to | 50 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
| 51 // NativeTheme colors. | 51 // NativeTheme colors. |
| 52 struct TranslationTable { | 52 struct TranslationTable { |
| 53 ui::NativeTheme::ColorId id; | 53 ui::NativeTheme::ColorId id; |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 font_list_(font_list), | 190 font_list_(font_list), |
| 191 font_height_(std::max( | 191 font_height_(std::max( |
| 192 font_list.GetHeight(), | 192 font_list.GetHeight(), |
| 193 font_list.DeriveWithWeight(gfx::Font::Weight::BOLD).GetHeight())), | 193 font_list.DeriveWithWeight(gfx::Font::Weight::BOLD).GetHeight())), |
| 194 mirroring_context_(new MirroringContext()), | 194 mirroring_context_(new MirroringContext()), |
| 195 keyword_icon_(new views::ImageView()), | 195 keyword_icon_(new views::ImageView()), |
| 196 animation_(new gfx::SlideAnimation(this)) { | 196 animation_(new gfx::SlideAnimation(this)) { |
| 197 CHECK_GE(model_index, 0); | 197 CHECK_GE(model_index, 0); |
| 198 keyword_icon_->set_owned_by_client(); | 198 keyword_icon_->set_owned_by_client(); |
| 199 keyword_icon_->EnableCanvasFlippingForRTLUI(true); | 199 keyword_icon_->EnableCanvasFlippingForRTLUI(true); |
| 200 keyword_icon_->SetImage( | 200 keyword_icon_->SetImage(GetVectorIcon(omnibox::kKeywordSearchIcon)); |
| 201 GetVectorIcon(gfx::VectorIconId::OMNIBOX_KEYWORD_SEARCH)); | |
| 202 keyword_icon_->SizeToPreferredSize(); | 201 keyword_icon_->SizeToPreferredSize(); |
| 203 } | 202 } |
| 204 | 203 |
| 205 OmniboxResultView::~OmniboxResultView() { | 204 OmniboxResultView::~OmniboxResultView() { |
| 206 } | 205 } |
| 207 | 206 |
| 208 SkColor OmniboxResultView::GetColor( | 207 SkColor OmniboxResultView::GetColor( |
| 209 ResultViewState state, | 208 ResultViewState state, |
| 210 ColorKind kind) const { | 209 ColorKind kind) const { |
| 211 for (size_t i = 0; i < arraysize(kTranslationTable); ++i) { | 210 for (size_t i = 0; i < arraysize(kTranslationTable); ++i) { |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 558 | 557 |
| 559 const char* OmniboxResultView::GetClassName() const { | 558 const char* OmniboxResultView::GetClassName() const { |
| 560 return "OmniboxResultView"; | 559 return "OmniboxResultView"; |
| 561 } | 560 } |
| 562 | 561 |
| 563 gfx::ImageSkia OmniboxResultView::GetIcon() const { | 562 gfx::ImageSkia OmniboxResultView::GetIcon() const { |
| 564 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); | 563 const gfx::Image image = model_->GetIconIfExtensionMatch(model_index_); |
| 565 if (!image.IsEmpty()) | 564 if (!image.IsEmpty()) |
| 566 return image.AsImageSkia(); | 565 return image.AsImageSkia(); |
| 567 | 566 |
| 568 return GetVectorIcon( | 567 return GetVectorIcon(model_->IsStarredMatch(match_) |
| 569 model_->IsStarredMatch(match_) | 568 ? omnibox::kStarIcon |
| 570 ? gfx::VectorIconId::OMNIBOX_STAR | 569 : AutocompleteMatch::TypeToVectorIcon(match_.type)); |
| 571 : AutocompleteMatch::TypeToVectorIcon(match_.type)); | |
| 572 } | 570 } |
| 573 | 571 |
| 574 gfx::ImageSkia OmniboxResultView::GetVectorIcon( | 572 gfx::ImageSkia OmniboxResultView::GetVectorIcon( |
| 575 gfx::VectorIconId icon_id) const { | 573 const gfx::VectorIcon& icon) const { |
| 576 // For selected rows, paint the icon the same color as the text. | 574 // For selected rows, paint the icon the same color as the text. |
| 577 SkColor color = GetColor(GetState(), TEXT); | 575 SkColor color = GetColor(GetState(), TEXT); |
| 578 if (GetState() != SELECTED) | 576 if (GetState() != SELECTED) |
| 579 color = color_utils::DeriveDefaultIconColor(color); | 577 color = color_utils::DeriveDefaultIconColor(color); |
| 580 return gfx::CreateVectorIcon(icon_id, 16, color); | 578 return gfx::CreateVectorIcon(icon, 16, color); |
| 581 } | 579 } |
| 582 | 580 |
| 583 bool OmniboxResultView::ShowOnlyKeywordMatch() const { | 581 bool OmniboxResultView::ShowOnlyKeywordMatch() const { |
| 584 return match_.associated_keyword && | 582 return match_.associated_keyword && |
| 585 (keyword_icon_->x() <= icon_bounds_.right()); | 583 (keyword_icon_->x() <= icon_bounds_.right()); |
| 586 } | 584 } |
| 587 | 585 |
| 588 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { | 586 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { |
| 589 if (!contents_rendertext_) { | 587 if (!contents_rendertext_) { |
| 590 contents_rendertext_.reset( | 588 contents_rendertext_.reset( |
| (...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 destination->AppendText(text); | 771 destination->AppendText(text); |
| 774 const TextStyle& text_style = GetTextStyle(text_type); | 772 const TextStyle& text_style = GetTextStyle(text_type); |
| 775 // TODO(dschuyler): follow up on the problem of different font sizes within | 773 // TODO(dschuyler): follow up on the problem of different font sizes within |
| 776 // one RenderText. Maybe with destination->SetFontList(...). | 774 // one RenderText. Maybe with destination->SetFontList(...). |
| 777 destination->ApplyWeight( | 775 destination->ApplyWeight( |
| 778 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); | 776 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); |
| 779 destination->ApplyColor( | 777 destination->ApplyColor( |
| 780 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); | 778 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); |
| 781 destination->ApplyBaselineStyle(text_style.baseline, range); | 779 destination->ApplyBaselineStyle(text_style.baseline, range); |
| 782 } | 780 } |
| OLD | NEW |