| 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 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 { NativeTheme::kColorId_ResultsTableSelectedUrl, | 79 { NativeTheme::kColorId_ResultsTableSelectedUrl, |
| 80 OmniboxResultView::SELECTED, OmniboxResultView::URL }, | 80 OmniboxResultView::SELECTED, OmniboxResultView::URL }, |
| 81 }; | 81 }; |
| 82 | 82 |
| 83 struct TextStyle { | 83 struct TextStyle { |
| 84 ui::ResourceBundle::FontStyle font; | 84 ui::ResourceBundle::FontStyle font; |
| 85 ui::NativeTheme::ColorId colors[OmniboxResultView::NUM_STATES]; | 85 ui::NativeTheme::ColorId colors[OmniboxResultView::NUM_STATES]; |
| 86 gfx::BaselineStyle baseline; | 86 gfx::BaselineStyle baseline; |
| 87 }; | 87 }; |
| 88 | 88 |
| 89 // Returns the styles that should be applied to the specified answer text type. |
| 90 // |
| 91 // Note that the font value is only consulted for the first text type that |
| 92 // appears on an answer line, because RenderText does not yet support multiple |
| 93 // font sizes. Subsequent text types on the same line will share the text size |
| 94 // of the first type, while the color and baseline styles specified here will |
| 95 // always apply. The gfx::INFERIOR baseline style is used as a workaround to |
| 96 // produce smaller text on the same line. The way this is used in the current |
| 97 // set of answers is that the small types (TOP_ALIGNED, DESCRIPTION_NEGATIVE, |
| 98 // DESCRIPTION_POSITIVE and SUGGESTION_SECONDARY_TEXT_SMALL) only ever appear |
| 99 // following LargeFont text, so for consistency they specify LargeFont for the |
| 100 // first value even though this is not actually used (since they're not the |
| 101 // first value). |
| 89 TextStyle GetTextStyle(int type) { | 102 TextStyle GetTextStyle(int type) { |
| 90 switch (type) { | 103 switch (type) { |
| 91 case SuggestionAnswer::TOP_ALIGNED: | 104 case SuggestionAnswer::TOP_ALIGNED: |
| 92 return {ui::ResourceBundle::LargeFont, | 105 return {ui::ResourceBundle::LargeFont, |
| 93 {NativeTheme::kColorId_ResultsTableNormalDimmedText, | 106 {NativeTheme::kColorId_ResultsTableNormalDimmedText, |
| 94 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 107 NativeTheme::kColorId_ResultsTableHoveredDimmedText, |
| 95 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, | 108 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, |
| 96 gfx::SUPERIOR}; | 109 gfx::SUPERIOR}; |
| 97 case SuggestionAnswer::DESCRIPTION_NEGATIVE: | 110 case SuggestionAnswer::DESCRIPTION_NEGATIVE: |
| 98 return {ui::ResourceBundle::LargeFont, | 111 return {ui::ResourceBundle::LargeFont, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 117 {NativeTheme::kColorId_ResultsTableNormalText, | 130 {NativeTheme::kColorId_ResultsTableNormalText, |
| 118 NativeTheme::kColorId_ResultsTableHoveredText, | 131 NativeTheme::kColorId_ResultsTableHoveredText, |
| 119 NativeTheme::kColorId_ResultsTableSelectedText}, | 132 NativeTheme::kColorId_ResultsTableSelectedText}, |
| 120 gfx::NORMAL_BASELINE}; | 133 gfx::NORMAL_BASELINE}; |
| 121 case SuggestionAnswer::ANSWER_TEXT_LARGE: | 134 case SuggestionAnswer::ANSWER_TEXT_LARGE: |
| 122 return {ui::ResourceBundle::LargeFont, | 135 return {ui::ResourceBundle::LargeFont, |
| 123 {NativeTheme::kColorId_ResultsTableNormalText, | 136 {NativeTheme::kColorId_ResultsTableNormalText, |
| 124 NativeTheme::kColorId_ResultsTableHoveredText, | 137 NativeTheme::kColorId_ResultsTableHoveredText, |
| 125 NativeTheme::kColorId_ResultsTableSelectedText}, | 138 NativeTheme::kColorId_ResultsTableSelectedText}, |
| 126 gfx::NORMAL_BASELINE}; | 139 gfx::NORMAL_BASELINE}; |
| 127 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: // Fall through. | 140 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_SMALL: |
| 141 return {ui::ResourceBundle::LargeFont, |
| 142 {NativeTheme::kColorId_ResultsTableNormalDimmedText, |
| 143 NativeTheme::kColorId_ResultsTableHoveredDimmedText, |
| 144 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, |
| 145 gfx::INFERIOR}; |
| 128 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: | 146 case SuggestionAnswer::SUGGESTION_SECONDARY_TEXT_MEDIUM: |
| 129 return {ui::ResourceBundle::BaseFont, | 147 return {ui::ResourceBundle::BaseFont, |
| 130 {NativeTheme::kColorId_ResultsTableNormalDimmedText, | 148 {NativeTheme::kColorId_ResultsTableNormalDimmedText, |
| 131 NativeTheme::kColorId_ResultsTableHoveredDimmedText, | 149 NativeTheme::kColorId_ResultsTableHoveredDimmedText, |
| 132 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, | 150 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, |
| 133 gfx::NORMAL_BASELINE}; | 151 gfx::NORMAL_BASELINE}; |
| 134 case SuggestionAnswer::SUGGESTION: // Fall through. | 152 case SuggestionAnswer::SUGGESTION: // Fall through. |
| 135 default: | 153 default: |
| 136 return {ui::ResourceBundle::BaseFont, | 154 return {ui::ResourceBundle::BaseFont, |
| 137 {NativeTheme::kColorId_ResultsTableNormalText, | 155 {NativeTheme::kColorId_ResultsTableNormalText, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 // selected. The non-answer text is already accessible as a consequence of | 289 // selected. The non-answer text is already accessible as a consequence of |
| 272 // updating the text in the omnibox but this alert and GetAccessibleNodeData | 290 // updating the text in the omnibox but this alert and GetAccessibleNodeData |
| 273 // below make the answer contents accessible. | 291 // below make the answer contents accessible. |
| 274 if (match_.answer) | 292 if (match_.answer) |
| 275 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 293 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 276 } | 294 } |
| 277 | 295 |
| 278 gfx::Size OmniboxResultView::GetPreferredSize() const { | 296 gfx::Size OmniboxResultView::GetPreferredSize() const { |
| 279 if (!match_.answer) | 297 if (!match_.answer) |
| 280 return gfx::Size(0, GetContentLineHeight()); | 298 return gfx::Size(0, GetContentLineHeight()); |
| 281 // An answer implies a match and a description in a large font. | |
| 282 if (match_.answer->second_line().num_text_lines() == 1) | 299 if (match_.answer->second_line().num_text_lines() == 1) |
| 283 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); | 300 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); |
| 284 if (!description_rendertext_) { | 301 if (!description_rendertext_) { |
| 285 description_rendertext_ = | 302 description_rendertext_ = |
| 286 CreateAnswerLine(match_.answer->second_line(), font_list_); | 303 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont()); |
| 287 } | 304 } |
| 288 description_rendertext_->SetDisplayRect( | 305 description_rendertext_->SetDisplayRect( |
| 289 gfx::Rect(text_bounds_.width(), 0)); | 306 gfx::Rect(text_bounds_.width(), 0)); |
| 290 description_rendertext_->GetStringSize(); | 307 description_rendertext_->GetStringSize(); |
| 291 return gfx::Size( | 308 return gfx::Size( |
| 292 0, GetContentLineHeight() + | 309 0, GetContentLineHeight() + |
| 293 GetAnswerLineHeight() * description_rendertext_->GetNumLines()); | 310 GetAnswerLineHeight() * description_rendertext_->GetNumLines()); |
| 294 } | 311 } |
| 295 | 312 |
| 296 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 313 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 640 icon_bounds_.y()); | 657 icon_bounds_.y()); |
| 641 int x = GetMirroredXForRect(text_bounds_); | 658 int x = GetMirroredXForRect(text_bounds_); |
| 642 mirroring_context_->Initialize(x, text_bounds_.width()); | 659 mirroring_context_->Initialize(x, text_bounds_.width()); |
| 643 InitContentsRenderTextIfNecessary(); | 660 InitContentsRenderTextIfNecessary(); |
| 644 | 661 |
| 645 if (!description_rendertext_) { | 662 if (!description_rendertext_) { |
| 646 if (match_.answer) { | 663 if (match_.answer) { |
| 647 contents_rendertext_ = | 664 contents_rendertext_ = |
| 648 CreateAnswerLine(match_.answer->first_line(), font_list_); | 665 CreateAnswerLine(match_.answer->first_line(), font_list_); |
| 649 description_rendertext_ = | 666 description_rendertext_ = |
| 650 CreateAnswerLine(match_.answer->second_line(), font_list_); | 667 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont()); |
| 651 } else if (!match_.description.empty()) { | 668 } else if (!match_.description.empty()) { |
| 652 description_rendertext_ = CreateClassifiedRenderText( | 669 description_rendertext_ = CreateClassifiedRenderText( |
| 653 match_.description, match_.description_class, true); | 670 match_.description, match_.description_class, true); |
| 654 } | 671 } |
| 655 } | 672 } |
| 656 PaintMatch(match_, contents_rendertext_.get(), | 673 PaintMatch(match_, contents_rendertext_.get(), |
| 657 description_rendertext_.get(), canvas, x); | 674 description_rendertext_.get(), canvas, x); |
| 658 } | 675 } |
| 659 | 676 |
| 660 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 677 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 677 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 694 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), |
| 678 keyword_description_rendertext_.get(), canvas, x); | 695 keyword_description_rendertext_.get(), canvas, x); |
| 679 } | 696 } |
| 680 } | 697 } |
| 681 | 698 |
| 682 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 699 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
| 683 Layout(); | 700 Layout(); |
| 684 SchedulePaint(); | 701 SchedulePaint(); |
| 685 } | 702 } |
| 686 | 703 |
| 704 const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const { |
| 705 // This assumes that the first text type in the second answer line can be used |
| 706 // to specify the font for all the text fields in the line. For now this works |
| 707 // but eventually it will be necessary to get RenderText to support multiple |
| 708 // font sizes or use multiple RenderTexts. |
| 709 int text_type = |
| 710 match_.answer && !match_.answer->second_line().text_fields().empty() |
| 711 ? match_.answer->second_line().text_fields()[0].type() |
| 712 : SuggestionAnswer::SUGGESTION; |
| 713 return ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 714 GetTextStyle(text_type).font); |
| 715 } |
| 716 |
| 687 int OmniboxResultView::GetAnswerLineHeight() const { | 717 int OmniboxResultView::GetAnswerLineHeight() const { |
| 688 // ANSWER_TEXT_LARGE is the largest font used and so defines the boundary that | 718 return GetAnswerLineFont().GetHeight(); |
| 689 // all the other answer styles fit within. | |
| 690 return ui::ResourceBundle::GetSharedInstance() | |
| 691 .GetFontList(GetTextStyle(SuggestionAnswer::ANSWER_TEXT_LARGE).font) | |
| 692 .GetHeight(); | |
| 693 } | 719 } |
| 694 | 720 |
| 695 int OmniboxResultView::GetContentLineHeight() const { | 721 int OmniboxResultView::GetContentLineHeight() const { |
| 696 using Md = ui::MaterialDesignController; | 722 using Md = ui::MaterialDesignController; |
| 697 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; | 723 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; |
| 698 const int kTextVerticalPad = 3; | 724 const int kTextVerticalPad = 3; |
| 699 return std::max( | 725 return std::max( |
| 700 LocationBarView::kIconWidth + 2 * kIconVerticalPad, | 726 LocationBarView::kIconWidth + 2 * kIconVerticalPad, |
| 701 GetTextHeight() + 2 * kTextVerticalPad); | 727 GetTextHeight() + 2 * kTextVerticalPad); |
| 702 } | 728 } |
| 703 | 729 |
| 704 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( | 730 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( |
| 705 const SuggestionAnswer::ImageLine& line, | 731 const SuggestionAnswer::ImageLine& line, |
| 706 gfx::FontList font_list) const { | 732 const gfx::FontList& font_list) const { |
| 707 std::unique_ptr<gfx::RenderText> destination = | 733 std::unique_ptr<gfx::RenderText> destination = |
| 708 CreateRenderText(base::string16()); | 734 CreateRenderText(base::string16()); |
| 709 destination->SetFontList(font_list); | 735 destination->SetFontList(font_list); |
| 710 | 736 |
| 711 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) | 737 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) |
| 712 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); | 738 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); |
| 713 if (!line.text_fields().empty()) { | 739 if (!line.text_fields().empty()) { |
| 714 constexpr int kMaxDisplayLines = 3; | 740 constexpr int kMaxDisplayLines = 3; |
| 715 const SuggestionAnswer::TextField& first_field = line.text_fields().front(); | 741 const SuggestionAnswer::TextField& first_field = line.text_fields().front(); |
| 716 if (first_field.has_num_lines() && first_field.num_lines() > 1 && | 742 if (first_field.has_num_lines() && first_field.num_lines() > 1 && |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 773 destination->AppendText(text); | 799 destination->AppendText(text); |
| 774 const TextStyle& text_style = GetTextStyle(text_type); | 800 const TextStyle& text_style = GetTextStyle(text_type); |
| 775 // TODO(dschuyler): follow up on the problem of different font sizes within | 801 // TODO(dschuyler): follow up on the problem of different font sizes within |
| 776 // one RenderText. Maybe with destination->SetFontList(...). | 802 // one RenderText. Maybe with destination->SetFontList(...). |
| 777 destination->ApplyWeight( | 803 destination->ApplyWeight( |
| 778 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); | 804 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); |
| 779 destination->ApplyColor( | 805 destination->ApplyColor( |
| 780 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); | 806 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); |
| 781 destination->ApplyBaselineStyle(text_style.baseline, range); | 807 destination->ApplyBaselineStyle(text_style.baseline, range); |
| 782 } | 808 } |
| OLD | NEW |