| 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 30 matching lines...) Expand all Loading... |
| 41 #include "ui/gfx/paint_vector_icon.h" | 41 #include "ui/gfx/paint_vector_icon.h" |
| 42 #include "ui/gfx/range/range.h" | 42 #include "ui/gfx/range/range.h" |
| 43 #include "ui/gfx/render_text.h" | 43 #include "ui/gfx/render_text.h" |
| 44 #include "ui/gfx/text_utils.h" | 44 #include "ui/gfx/text_utils.h" |
| 45 #include "ui/native_theme/native_theme.h" | 45 #include "ui/native_theme/native_theme.h" |
| 46 | 46 |
| 47 using ui::NativeTheme; | 47 using ui::NativeTheme; |
| 48 | 48 |
| 49 namespace { | 49 namespace { |
| 50 | 50 |
| 51 // The padding that should be placed between content and description in a |
| 52 // vertical layout. |
| 53 static const int kVerticalPadding = 3; |
| 54 |
| 51 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to | 55 // A mapping from OmniboxResultView's ResultViewState/ColorKind types to |
| 52 // NativeTheme colors. | 56 // NativeTheme colors. |
| 53 struct TranslationTable { | 57 struct TranslationTable { |
| 54 ui::NativeTheme::ColorId id; | 58 ui::NativeTheme::ColorId id; |
| 55 OmniboxResultView::ResultViewState state; | 59 OmniboxResultView::ResultViewState state; |
| 56 OmniboxResultView::ColorKind kind; | 60 OmniboxResultView::ColorKind kind; |
| 57 } static const kTranslationTable[] = { | 61 } static const kTranslationTable[] = { |
| 58 { NativeTheme::kColorId_ResultsTableNormalBackground, | 62 { NativeTheme::kColorId_ResultsTableNormalBackground, |
| 59 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, | 63 OmniboxResultView::NORMAL, OmniboxResultView::BACKGROUND }, |
| 60 { NativeTheme::kColorId_ResultsTableHoveredBackground, | 64 { NativeTheme::kColorId_ResultsTableHoveredBackground, |
| (...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 | 291 |
| 288 // Notify assistive technology when results with answers attached are | 292 // Notify assistive technology when results with answers attached are |
| 289 // selected. The non-answer text is already accessible as a consequence of | 293 // selected. The non-answer text is already accessible as a consequence of |
| 290 // updating the text in the omnibox but this alert and GetAccessibleNodeData | 294 // updating the text in the omnibox but this alert and GetAccessibleNodeData |
| 291 // below make the answer contents accessible. | 295 // below make the answer contents accessible. |
| 292 if (match_.answer) | 296 if (match_.answer) |
| 293 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 297 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
| 294 } | 298 } |
| 295 | 299 |
| 296 gfx::Size OmniboxResultView::GetPreferredSize() const { | 300 gfx::Size OmniboxResultView::GetPreferredSize() const { |
| 297 if (!match_.answer) | 301 int height = GetTextHeight() + (2 * GetVerticalMargin()); |
| 298 return gfx::Size(0, GetContentLineHeight()); | 302 if (match_.answer) |
| 299 if (match_.answer->second_line().num_text_lines() == 1) | 303 height += GetAnswerHeight() + kVerticalPadding; |
| 300 return gfx::Size(0, GetContentLineHeight() + GetAnswerLineHeight()); | 304 return gfx::Size(0, height); |
| 301 if (!description_rendertext_) { | |
| 302 description_rendertext_ = | |
| 303 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont()); | |
| 304 } | |
| 305 description_rendertext_->SetDisplayRect( | |
| 306 gfx::Rect(text_bounds_.width(), 0)); | |
| 307 description_rendertext_->GetStringSize(); | |
| 308 return gfx::Size( | |
| 309 0, GetContentLineHeight() + | |
| 310 GetAnswerLineHeight() * description_rendertext_->GetNumLines()); | |
| 311 } | 305 } |
| 312 | 306 |
| 313 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { | 307 void OmniboxResultView::GetAccessibleNodeData(ui::AXNodeData* node_data) { |
| 314 node_data->SetName(match_.answer | 308 node_data->SetName(match_.answer |
| 315 ? l10n_util::GetStringFUTF16( | 309 ? l10n_util::GetStringFUTF16( |
| 316 IDS_OMNIBOX_ACCESSIBLE_ANSWER, match_.contents, | 310 IDS_OMNIBOX_ACCESSIBLE_ANSWER, match_.contents, |
| 317 match_.answer->second_line().AccessibleText()) | 311 match_.answer->second_line().AccessibleText()) |
| 318 : match_.contents); | 312 : match_.contents); |
| 319 } | 313 } |
| 320 | 314 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 334 | 328 |
| 335 int OmniboxResultView::GetTextHeight() const { | 329 int OmniboxResultView::GetTextHeight() const { |
| 336 return font_height_; | 330 return font_height_; |
| 337 } | 331 } |
| 338 | 332 |
| 339 void OmniboxResultView::PaintMatch(const AutocompleteMatch& match, | 333 void OmniboxResultView::PaintMatch(const AutocompleteMatch& match, |
| 340 gfx::RenderText* contents, | 334 gfx::RenderText* contents, |
| 341 gfx::RenderText* description, | 335 gfx::RenderText* description, |
| 342 gfx::Canvas* canvas, | 336 gfx::Canvas* canvas, |
| 343 int x) const { | 337 int x) const { |
| 344 int y = text_bounds_.y(); | 338 int y = text_bounds_.y() + GetVerticalMargin(); |
| 345 | 339 |
| 346 if (!separator_rendertext_) { | 340 if (!separator_rendertext_) { |
| 347 const base::string16& separator = | 341 const base::string16& separator = |
| 348 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); | 342 l10n_util::GetStringUTF16(IDS_AUTOCOMPLETE_MATCH_DESCRIPTION_SEPARATOR); |
| 349 separator_rendertext_ = CreateRenderText(separator); | 343 separator_rendertext_ = CreateRenderText(separator); |
| 350 separator_rendertext_->SetColor(GetColor(GetState(), DIMMED_TEXT)); | 344 separator_rendertext_->SetColor(GetColor(GetState(), DIMMED_TEXT)); |
| 351 separator_width_ = separator_rendertext_->GetContentWidth(); | 345 separator_width_ = separator_rendertext_->GetContentWidth(); |
| 352 } | 346 } |
| 353 | 347 |
| 354 contents->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 348 contents->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
| 355 if (description) | 349 if (description) |
| 356 description->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 350 description->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
| 357 int contents_max_width, description_max_width; | 351 int contents_max_width, description_max_width; |
| 358 OmniboxPopupModel::ComputeMatchMaxWidths( | 352 OmniboxPopupModel::ComputeMatchMaxWidths( |
| 359 contents->GetContentWidth(), | 353 contents->GetContentWidth(), |
| 360 separator_width_, | 354 separator_width_, |
| 361 description ? description->GetContentWidth() : 0, | 355 description ? description->GetContentWidth() : 0, |
| 362 mirroring_context_->remaining_width(x), | 356 mirroring_context_->remaining_width(x), |
| 363 match.answer != nullptr, | 357 match.answer != nullptr, |
| 364 !AutocompleteMatch::IsSearchType(match.type), | 358 !AutocompleteMatch::IsSearchType(match.type), |
| 365 &contents_max_width, | 359 &contents_max_width, |
| 366 &description_max_width); | 360 &description_max_width); |
| 367 | 361 |
| 368 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas, | 362 int after_contents_x = DrawRenderText(match, contents, CONTENTS, canvas, |
| 369 x, y, contents_max_width); | 363 x, y, contents_max_width); |
| 370 | 364 |
| 371 if (description_max_width != 0) { | 365 if (description_max_width != 0) { |
| 372 if (match.answer) { | 366 if (match.answer) { |
| 373 y += GetContentLineHeight(); | 367 y += GetTextHeight() + kVerticalPadding; |
| 374 if (!answer_image_.isNull()) { | 368 if (!answer_image_.isNull()) { |
| 375 int answer_icon_size = GetAnswerLineHeight(); | 369 int answer_icon_size = GetAnswerHeight(); |
| 376 canvas->DrawImageInt( | 370 canvas->DrawImageInt( |
| 377 answer_image_, | 371 answer_image_, |
| 378 0, 0, answer_image_.width(), answer_image_.height(), | 372 0, 0, answer_image_.width(), answer_image_.height(), |
| 379 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); | 373 GetMirroredXInView(x), y, answer_icon_size, answer_icon_size, true); |
| 380 // TODO(dschuyler): Perhaps this should be based on the font size | 374 // TODO(dschuyler): Perhaps this should be based on the font size |
| 381 // instead of hardcoded to 2 dp (e.g. by adding a space in an | 375 // instead of hardcoded to 2 dp (e.g. by adding a space in an |
| 382 // appropriate font to the beginning of the description, then reducing | 376 // appropriate font to the beginning of the description, then reducing |
| 383 // the additional padding here to zero). | 377 // the additional padding here to zero). |
| 384 const int kAnswerIconToTextPadding = 2; | 378 const int kAnswerIconToTextPadding = 2; |
| 385 x += answer_icon_size + kAnswerIconToTextPadding; | 379 x += answer_icon_size + kAnswerIconToTextPadding; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 x += start_offset; | 447 x += start_offset; |
| 454 prefix_x = x - prefix_width; | 448 prefix_x = x - prefix_width; |
| 455 } | 449 } |
| 456 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? | 450 prefix_render_text->SetDirectionalityMode(is_match_contents_rtl ? |
| 457 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); | 451 gfx::DIRECTIONALITY_FORCE_RTL : gfx::DIRECTIONALITY_FORCE_LTR); |
| 458 prefix_render_text->SetHorizontalAlignment( | 452 prefix_render_text->SetHorizontalAlignment( |
| 459 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); | 453 is_match_contents_rtl ? gfx::ALIGN_RIGHT : gfx::ALIGN_LEFT); |
| 460 prefix_render_text->SetDisplayRect( | 454 prefix_render_text->SetDisplayRect( |
| 461 gfx::Rect(mirroring_context_->mirrored_left_coord( | 455 gfx::Rect(mirroring_context_->mirrored_left_coord( |
| 462 prefix_x, prefix_x + prefix_width), | 456 prefix_x, prefix_x + prefix_width), |
| 463 y, prefix_width, GetContentLineHeight())); | 457 y, prefix_width, GetTextHeight())); |
| 464 prefix_render_text->Draw(canvas); | 458 prefix_render_text->Draw(canvas); |
| 465 } | 459 } |
| 466 | 460 |
| 467 // Set the display rect to trigger elision. | 461 // Set the display rect to trigger elision. |
| 468 const int final_width = right_x - x; | 462 int height = (render_text_type == DESCRIPTION && match.answer) |
| 469 int height = GetContentLineHeight(); | 463 ? GetAnswerHeight() |
| 470 if (render_text_type == DESCRIPTION && match.answer) { | 464 : GetTextHeight(); |
| 471 render_text->SetDisplayRect(gfx::Rect(gfx::Size(final_width, 0))); | |
| 472 render_text->GetStringSize(); | |
| 473 height = GetAnswerLineHeight() * render_text->GetNumLines(); | |
| 474 } | |
| 475 render_text->SetDisplayRect( | 465 render_text->SetDisplayRect( |
| 476 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, | 466 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, |
| 477 final_width, height)); | 467 right_x - x, height)); |
| 478 render_text->Draw(canvas); | 468 render_text->Draw(canvas); |
| 479 return right_x; | 469 return right_x; |
| 480 } | 470 } |
| 481 | 471 |
| 482 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 472 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( |
| 483 const base::string16& text) const { | 473 const base::string16& text) const { |
| 484 std::unique_ptr<gfx::RenderText> render_text( | 474 std::unique_ptr<gfx::RenderText> render_text( |
| 485 gfx::RenderText::CreateInstance()); | 475 gfx::RenderText::CreateInstance()); |
| 486 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 476 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
| 487 render_text->SetCursorEnabled(false); | 477 render_text->SetCursorEnabled(false); |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 | 588 |
| 599 bool OmniboxResultView::ShowOnlyKeywordMatch() const { | 589 bool OmniboxResultView::ShowOnlyKeywordMatch() const { |
| 600 return match_.associated_keyword && | 590 return match_.associated_keyword && |
| 601 (keyword_icon_->x() <= icon_bounds_.right()); | 591 (keyword_icon_->x() <= icon_bounds_.right()); |
| 602 } | 592 } |
| 603 | 593 |
| 604 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { | 594 void OmniboxResultView::InitContentsRenderTextIfNecessary() const { |
| 605 if (!contents_rendertext_) { | 595 if (!contents_rendertext_) { |
| 606 if (match_.answer) { | 596 if (match_.answer) { |
| 607 contents_rendertext_ = | 597 contents_rendertext_ = |
| 608 CreateAnswerLine(match_.answer->first_line(), font_list_); | 598 CreateAnswerText(match_.answer->first_line(), font_list_); |
| 609 } else { | 599 } else { |
| 610 contents_rendertext_ = CreateClassifiedRenderText( | 600 contents_rendertext_ = CreateClassifiedRenderText( |
| 611 match_.contents, match_.contents_class, false); | 601 match_.contents, match_.contents_class, false); |
| 612 } | 602 } |
| 613 } | 603 } |
| 614 } | 604 } |
| 615 | 605 |
| 616 void OmniboxResultView::Layout() { | 606 void OmniboxResultView::Layout() { |
| 617 const int horizontal_padding = | 607 const int horizontal_padding = |
| 618 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + | 608 GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING) + |
| 619 LocationBarView::kIconInteriorPadding; | 609 LocationBarView::kIconInteriorPadding; |
| 620 // The horizontal bounds we're given are the outside bounds, so we can match | 610 // The horizontal bounds we're given are the outside bounds, so we can match |
| 621 // the omnibox border outline shape exactly in OnPaint(). We have to inset | 611 // the omnibox border outline shape exactly in OnPaint(). We have to inset |
| 622 // here to keep the icons lined up. | 612 // here to keep the icons lined up. |
| 623 const int start_x = BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + | 613 const int start_x = BackgroundWith1PxBorder::kLocationBarBorderThicknessDip + |
| 624 horizontal_padding; | 614 horizontal_padding; |
| 625 const int end_x = width() - start_x; | 615 const int end_x = width() - start_x; |
| 626 | 616 |
| 627 const gfx::ImageSkia icon = GetIcon(); | 617 const gfx::ImageSkia icon = GetIcon(); |
| 628 icon_bounds_.SetRect(start_x, (GetContentLineHeight() - icon.height()) / 2, | 618 const int icon_y = |
| 629 icon.width(), icon.height()); | 619 GetVerticalMargin() + (GetTextHeight() - icon.height()) / 2; |
| 620 icon_bounds_.SetRect(start_x, icon_y, icon.width(), icon.height()); |
| 630 | 621 |
| 631 const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding; | 622 const int text_x = start_x + LocationBarView::kIconWidth + horizontal_padding; |
| 632 int text_width = end_x - text_x; | 623 int text_width = end_x - text_x; |
| 633 | 624 |
| 634 if (match_.associated_keyword.get()) { | 625 if (match_.associated_keyword.get()) { |
| 635 const int max_kw_x = end_x - keyword_icon_->width(); | 626 const int max_kw_x = end_x - keyword_icon_->width(); |
| 636 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x); | 627 const int kw_x = animation_->CurrentValueBetween(max_kw_x, start_x); |
| 637 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding; | 628 const int kw_text_x = kw_x + keyword_icon_->width() + horizontal_padding; |
| 638 | 629 |
| 639 text_width = kw_x - text_x - horizontal_padding; | 630 text_width = kw_x - text_x - horizontal_padding; |
| (...skipping 18 matching lines...) Expand all Loading... |
| 658 if (!ShowOnlyKeywordMatch()) { | 649 if (!ShowOnlyKeywordMatch()) { |
| 659 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), | 650 canvas->DrawImageInt(GetIcon(), GetMirroredXForRect(icon_bounds_), |
| 660 icon_bounds_.y()); | 651 icon_bounds_.y()); |
| 661 int x = GetMirroredXForRect(text_bounds_); | 652 int x = GetMirroredXForRect(text_bounds_); |
| 662 mirroring_context_->Initialize(x, text_bounds_.width()); | 653 mirroring_context_->Initialize(x, text_bounds_.width()); |
| 663 InitContentsRenderTextIfNecessary(); | 654 InitContentsRenderTextIfNecessary(); |
| 664 | 655 |
| 665 if (!description_rendertext_) { | 656 if (!description_rendertext_) { |
| 666 if (match_.answer) { | 657 if (match_.answer) { |
| 667 description_rendertext_ = | 658 description_rendertext_ = |
| 668 CreateAnswerLine(match_.answer->second_line(), GetAnswerLineFont()); | 659 CreateAnswerText(match_.answer->second_line(), GetAnswerFont()); |
| 669 } else if (!match_.description.empty()) { | 660 } else if (!match_.description.empty()) { |
| 670 description_rendertext_ = CreateClassifiedRenderText( | 661 description_rendertext_ = CreateClassifiedRenderText( |
| 671 match_.description, match_.description_class, true); | 662 match_.description, match_.description_class, true); |
| 672 } | 663 } |
| 673 } | 664 } |
| 674 PaintMatch(match_, contents_rendertext_.get(), | 665 PaintMatch(match_, contents_rendertext_.get(), |
| 675 description_rendertext_.get(), canvas, x); | 666 description_rendertext_.get(), canvas, x); |
| 676 } | 667 } |
| 677 | 668 |
| 678 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); | 669 AutocompleteMatch* keyword_match = match_.associated_keyword.get(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 691 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), | 682 PaintMatch(*keyword_match, keyword_contents_rendertext_.get(), |
| 692 keyword_description_rendertext_.get(), canvas, x); | 683 keyword_description_rendertext_.get(), canvas, x); |
| 693 } | 684 } |
| 694 } | 685 } |
| 695 | 686 |
| 696 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { | 687 void OmniboxResultView::AnimationProgressed(const gfx::Animation* animation) { |
| 697 Layout(); | 688 Layout(); |
| 698 SchedulePaint(); | 689 SchedulePaint(); |
| 699 } | 690 } |
| 700 | 691 |
| 701 const gfx::FontList& OmniboxResultView::GetAnswerLineFont() const { | 692 const gfx::FontList& OmniboxResultView::GetAnswerFont() const { |
| 702 // This assumes that the first text type in the second answer line can be used | 693 // This assumes that the first text type in the second answer line can be used |
| 703 // to specify the font for all the text fields in the line. For now this works | 694 // to specify the font for all the text fields in the line. For now this works |
| 704 // but eventually it will be necessary to get RenderText to support multiple | 695 // but eventually it will be necessary to get RenderText to support multiple |
| 705 // font sizes or use multiple RenderTexts. | 696 // font sizes or use multiple RenderTexts. |
| 706 int text_type = | 697 int text_type = |
| 707 match_.answer && !match_.answer->second_line().text_fields().empty() | 698 match_.answer && !match_.answer->second_line().text_fields().empty() |
| 708 ? match_.answer->second_line().text_fields()[0].type() | 699 ? match_.answer->second_line().text_fields()[0].type() |
| 709 : SuggestionAnswer::SUGGESTION; | 700 : SuggestionAnswer::SUGGESTION; |
| 710 return ui::ResourceBundle::GetSharedInstance().GetFontList( | 701 return ui::ResourceBundle::GetSharedInstance().GetFontList( |
| 711 GetTextStyle(text_type).font); | 702 GetTextStyle(text_type).font); |
| 712 } | 703 } |
| 713 | 704 |
| 714 int OmniboxResultView::GetAnswerLineHeight() const { | 705 int OmniboxResultView::GetAnswerHeight() const { |
| 715 return GetAnswerLineFont().GetHeight(); | 706 // If the answer specifies a maximum of 1 line we can simply return the answer |
| 707 // font height. |
| 708 if (match_.answer->second_line().num_text_lines() == 1) |
| 709 return GetAnswerFont().GetHeight(); |
| 710 |
| 711 // Multi-line answers require layout in order to determine the number of lines |
| 712 // the RenderText will use. |
| 713 if (!description_rendertext_) { |
| 714 description_rendertext_ = |
| 715 CreateAnswerText(match_.answer->second_line(), GetAnswerFont()); |
| 716 } |
| 717 description_rendertext_->SetDisplayRect(gfx::Rect(text_bounds_.width(), 0)); |
| 718 description_rendertext_->GetStringSize(); |
| 719 return GetAnswerFont().GetHeight() * description_rendertext_->GetNumLines(); |
| 716 } | 720 } |
| 717 | 721 |
| 718 int OmniboxResultView::GetContentLineHeight() const { | 722 int OmniboxResultView::GetVerticalMargin() const { |
| 723 // Regardless of the text size, we ensure a minimum size for the content line |
| 724 // here. This minimum is larger for hybrid mouse/touch devices to ensure an |
| 725 // adequately sized touch target. |
| 719 using Md = ui::MaterialDesignController; | 726 using Md = ui::MaterialDesignController; |
| 720 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; | 727 const int kIconVerticalPad = Md::GetMode() == Md::MATERIAL_HYBRID ? 8 : 4; |
| 721 const int kTextVerticalPad = 3; | 728 const int min_height = LocationBarView::kIconWidth + 2 * kIconVerticalPad; |
| 722 return std::max( | 729 |
| 723 LocationBarView::kIconWidth + 2 * kIconVerticalPad, | 730 return std::max(kVerticalPadding, (min_height - GetTextHeight()) / 2); |
| 724 GetTextHeight() + 2 * kTextVerticalPad); | |
| 725 } | 731 } |
| 726 | 732 |
| 727 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( | 733 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerText( |
| 728 const SuggestionAnswer::ImageLine& line, | 734 const SuggestionAnswer::ImageLine& line, |
| 729 const gfx::FontList& font_list) const { | 735 const gfx::FontList& font_list) const { |
| 730 std::unique_ptr<gfx::RenderText> destination = | 736 std::unique_ptr<gfx::RenderText> destination = |
| 731 CreateRenderText(base::string16()); | 737 CreateRenderText(base::string16()); |
| 732 destination->SetFontList(font_list); | 738 destination->SetFontList(font_list); |
| 733 | 739 |
| 734 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) | 740 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) |
| 735 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); | 741 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); |
| 736 if (!line.text_fields().empty()) { | 742 if (!line.text_fields().empty()) { |
| 737 constexpr int kMaxDisplayLines = 3; | 743 constexpr int kMaxDisplayLines = 3; |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 destination->AppendText(text); | 802 destination->AppendText(text); |
| 797 const TextStyle& text_style = GetTextStyle(text_type); | 803 const TextStyle& text_style = GetTextStyle(text_type); |
| 798 // TODO(dschuyler): follow up on the problem of different font sizes within | 804 // TODO(dschuyler): follow up on the problem of different font sizes within |
| 799 // one RenderText. Maybe with destination->SetFontList(...). | 805 // one RenderText. Maybe with destination->SetFontList(...). |
| 800 destination->ApplyWeight( | 806 destination->ApplyWeight( |
| 801 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); | 807 is_bold ? gfx::Font::Weight::BOLD : gfx::Font::Weight::NORMAL, range); |
| 802 destination->ApplyColor( | 808 destination->ApplyColor( |
| 803 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); | 809 GetNativeTheme()->GetSystemColor(text_style.colors[GetState()]), range); |
| 804 destination->ApplyBaselineStyle(text_style.baseline, range); | 810 destination->ApplyBaselineStyle(text_style.baseline, range); |
| 805 } | 811 } |
| OLD | NEW |