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 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
190 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, | 190 NativeTheme::kColorId_ResultsTableSelectedDimmedText}, |
191 gfx::INFERIOR}, | 191 gfx::INFERIOR}, |
192 // 13 PERSONALIZED_SUGGESTION_TEXT | 192 // 13 PERSONALIZED_SUGGESTION_TEXT |
193 {ui::ResourceBundle::BaseFont, | 193 {ui::ResourceBundle::BaseFont, |
194 {NativeTheme::kColorId_ResultsTableNormalText, | 194 {NativeTheme::kColorId_ResultsTableNormalText, |
195 NativeTheme::kColorId_ResultsTableHoveredText, | 195 NativeTheme::kColorId_ResultsTableHoveredText, |
196 NativeTheme::kColorId_ResultsTableSelectedText}, | 196 NativeTheme::kColorId_ResultsTableSelectedText}, |
197 gfx::NORMAL_BASELINE}, | 197 gfx::NORMAL_BASELINE}, |
198 }; | 198 }; |
199 | 199 |
200 const TextStyle& GetTextStyle(size_t type) { | 200 const TextStyle& GetTextStyle(int type) { |
201 if (type > arraysize(kTextStyles)) | 201 if (type < 1 || static_cast<size_t>(type) > arraysize(kTextStyles)) |
202 type = 1; | 202 type = 1; |
203 // Subtract one because the types are one based (not zero based). | 203 // Subtract one because the types are one based (not zero based). |
204 return kTextStyles[type - 1]; | 204 return kTextStyles[type - 1]; |
205 } | 205 } |
206 | 206 |
207 } // namespace | 207 } // namespace |
208 | 208 |
209 //////////////////////////////////////////////////////////////////////////////// | 209 //////////////////////////////////////////////////////////////////////////////// |
210 // OmniboxResultView, public: | 210 // OmniboxResultView, public: |
211 | 211 |
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
692 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 692 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), |
693 icon_bounds_.y()); | 693 icon_bounds_.y()); |
694 int x = GetMirroredXForRect(text_bounds_); | 694 int x = GetMirroredXForRect(text_bounds_); |
695 mirroring_context_->Initialize(x, text_bounds_.width()); | 695 mirroring_context_->Initialize(x, text_bounds_.width()); |
696 InitContentsRenderTextIfNecessary(); | 696 InitContentsRenderTextIfNecessary(); |
697 | 697 |
698 if (!description_rendertext_) { | 698 if (!description_rendertext_) { |
699 if (match_.answer) { | 699 if (match_.answer) { |
700 base::string16 text; | 700 base::string16 text; |
701 description_rendertext_ = CreateRenderText(text); | 701 description_rendertext_ = CreateRenderText(text); |
702 for (const SuggestionAnswer::TextField& textfield : | 702 for (const SuggestionAnswer::TextField& text_field : |
703 match_.answer->second_line().text_fields()) | 703 match_.answer->second_line().text_fields()) |
704 AppendAnswerText(textfield); | 704 AppendAnswerText(text_field.text(), text_field.type()); |
705 if (match_.answer->second_line().additional_text()) | 705 const base::char16 space(' '); |
Peter Kasting
2015/03/24 20:55:35
Nit: I personally like const (non-pointer) locals
| |
706 AppendAnswerText(*match_.answer->second_line().additional_text()); | 706 const auto* text_field = match_.answer->second_line().additional_text(); |
707 if (match_.answer->second_line().status_text()) | 707 if (text_field) |
708 AppendAnswerText(*match_.answer->second_line().status_text()); | 708 AppendAnswerText(space + text_field->text(), text_field->type()); |
709 text_field = match_.answer->second_line().status_text(); | |
710 if (text_field) | |
711 AppendAnswerText(space + text_field->text(), text_field->type()); | |
709 } else if (!match_.description.empty()) { | 712 } else if (!match_.description.empty()) { |
710 description_rendertext_ = CreateClassifiedRenderText( | 713 description_rendertext_ = CreateClassifiedRenderText( |
711 match_.description, match_.description_class, true); | 714 match_.description, match_.description_class, true); |
712 } | 715 } |
713 } | 716 } |
714 PaintMatch(match_, contents_rendertext_.get(), | 717 PaintMatch(match_, contents_rendertext_.get(), |
715 description_rendertext_.get(), canvas, x); | 718 description_rendertext_.get(), canvas, x); |
716 } | 719 } |
717 | 720 |
718 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 721 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); |
(...skipping 29 matching lines...) Expand all Loading... | |
748 return ui::ResourceBundle::GetSharedInstance() | 751 return ui::ResourceBundle::GetSharedInstance() |
749 .GetFontList(GetTextStyle(1).font) | 752 .GetFontList(GetTextStyle(1).font) |
750 .GetHeight(); | 753 .GetHeight(); |
751 } | 754 } |
752 | 755 |
753 int OmniboxResultView::GetContentLineHeight() const { | 756 int OmniboxResultView::GetContentLineHeight() const { |
754 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), | 757 return std::max(default_icon_size_ + (kMinimumIconVerticalPadding * 2), |
755 GetTextHeight() + (kMinimumTextVerticalPadding * 2)); | 758 GetTextHeight() + (kMinimumTextVerticalPadding * 2)); |
756 } | 759 } |
757 | 760 |
758 void OmniboxResultView::AppendAnswerText( | 761 void OmniboxResultView::AppendAnswerText(const base::string16& text, |
759 const SuggestionAnswer::TextField& text_field) { | 762 int text_type) { |
760 int offset = description_rendertext_->text().length(); | 763 int offset = description_rendertext_->text().length(); |
761 gfx::Range range(offset, offset + text_field.text().length()); | 764 gfx::Range range(offset, offset + text.length()); |
762 description_rendertext_->AppendText(text_field.text()); | 765 description_rendertext_->AppendText(text); |
763 const TextStyle& text_style = GetTextStyle(text_field.type()); | 766 const TextStyle& text_style = GetTextStyle(text_type); |
764 // TODO(dschuyler): follow up on the problem of different font sizes within | 767 // TODO(dschuyler): follow up on the problem of different font sizes within |
765 // one RenderText. | 768 // one RenderText. |
766 description_rendertext_->SetFontList( | 769 description_rendertext_->SetFontList( |
767 ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font)); | 770 ui::ResourceBundle::GetSharedInstance().GetFontList(text_style.font)); |
768 description_rendertext_->ApplyColor( | 771 description_rendertext_->ApplyColor( |
769 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); | 772 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); |
770 description_rendertext_->ApplyBaselineStyle(text_style.baseline, range); | 773 description_rendertext_->ApplyBaselineStyle(text_style.baseline, range); |
771 } | 774 } |
OLD | NEW |