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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
448 if (render_text_type == CONTENTS && | 448 if (render_text_type == CONTENTS && |
449 match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { | 449 match.type == AutocompleteMatchType::SEARCH_SUGGEST_TAIL) { |
450 // When the directionality of suggestion doesn't match the UI, we try to | 450 // When the directionality of suggestion doesn't match the UI, we try to |
451 // vertically stack the ellipsis by restricting the end edge (right_x). | 451 // vertically stack the ellipsis by restricting the end edge (right_x). |
452 const bool is_ui_rtl = base::i18n::IsRTL(); | 452 const bool is_ui_rtl = base::i18n::IsRTL(); |
453 const bool is_match_contents_rtl = | 453 const bool is_match_contents_rtl = |
454 (render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT); | 454 (render_text->GetDisplayTextDirection() == base::i18n::RIGHT_TO_LEFT); |
455 const int offset = | 455 const int offset = |
456 GetDisplayOffset(match, is_ui_rtl, is_match_contents_rtl); | 456 GetDisplayOffset(match, is_ui_rtl, is_match_contents_rtl); |
457 | 457 |
458 scoped_ptr<gfx::RenderText> prefix_render_text( | 458 std::unique_ptr<gfx::RenderText> prefix_render_text( |
459 CreateRenderText(base::UTF8ToUTF16( | 459 CreateRenderText(base::UTF8ToUTF16( |
460 match.GetAdditionalInfo(kACMatchPropertyContentsPrefix)))); | 460 match.GetAdditionalInfo(kACMatchPropertyContentsPrefix)))); |
461 const int prefix_width = prefix_render_text->GetContentWidth(); | 461 const int prefix_width = prefix_render_text->GetContentWidth(); |
462 int prefix_x = x; | 462 int prefix_x = x; |
463 | 463 |
464 const int max_match_contents_width = model_->max_match_contents_width(); | 464 const int max_match_contents_width = model_->max_match_contents_width(); |
465 | 465 |
466 if (is_ui_rtl != is_match_contents_rtl) { | 466 if (is_ui_rtl != is_match_contents_rtl) { |
467 // RTL infinite suggestions appear near the left edge in LTR UI, while LTR | 467 // RTL infinite suggestions appear near the left edge in LTR UI, while LTR |
468 // infinite suggestions appear near the right edge in RTL UI. This is | 468 // infinite suggestions appear near the right edge in RTL UI. This is |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 // Set the display rect to trigger eliding. | 503 // Set the display rect to trigger eliding. |
504 const int height = (render_text_type == DESCRIPTION && match.answer) ? | 504 const int height = (render_text_type == DESCRIPTION && match.answer) ? |
505 GetAnswerLineHeight() : GetContentLineHeight(); | 505 GetAnswerLineHeight() : GetContentLineHeight(); |
506 render_text->SetDisplayRect( | 506 render_text->SetDisplayRect( |
507 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, | 507 gfx::Rect(mirroring_context_->mirrored_left_coord(x, right_x), y, |
508 right_x - x, height)); | 508 right_x - x, height)); |
509 render_text->Draw(canvas); | 509 render_text->Draw(canvas); |
510 return right_x; | 510 return right_x; |
511 } | 511 } |
512 | 512 |
513 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( | 513 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateRenderText( |
514 const base::string16& text) const { | 514 const base::string16& text) const { |
515 scoped_ptr<gfx::RenderText> render_text(gfx::RenderText::CreateInstance()); | 515 std::unique_ptr<gfx::RenderText> render_text( |
| 516 gfx::RenderText::CreateInstance()); |
516 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); | 517 render_text->SetDisplayRect(gfx::Rect(gfx::Size(INT_MAX, 0))); |
517 render_text->SetCursorEnabled(false); | 518 render_text->SetCursorEnabled(false); |
518 render_text->SetElideBehavior(gfx::ELIDE_TAIL); | 519 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
519 render_text->SetFontList(font_list_); | 520 render_text->SetFontList(font_list_); |
520 render_text->SetText(text); | 521 render_text->SetText(text); |
521 return render_text; | 522 return render_text; |
522 } | 523 } |
523 | 524 |
524 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateClassifiedRenderText( | 525 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateClassifiedRenderText( |
525 const base::string16& text, | 526 const base::string16& text, |
526 const ACMatchClassifications& classifications, | 527 const ACMatchClassifications& classifications, |
527 bool force_dim) const { | 528 bool force_dim) const { |
528 scoped_ptr<gfx::RenderText> render_text(CreateRenderText(text)); | 529 std::unique_ptr<gfx::RenderText> render_text(CreateRenderText(text)); |
529 const size_t text_length = render_text->text().length(); | 530 const size_t text_length = render_text->text().length(); |
530 for (size_t i = 0; i < classifications.size(); ++i) { | 531 for (size_t i = 0; i < classifications.size(); ++i) { |
531 const size_t text_start = classifications[i].offset; | 532 const size_t text_start = classifications[i].offset; |
532 if (text_start >= text_length) | 533 if (text_start >= text_length) |
533 break; | 534 break; |
534 | 535 |
535 const size_t text_end = (i < (classifications.size() - 1)) ? | 536 const size_t text_end = (i < (classifications.size() - 1)) ? |
536 std::min(classifications[i + 1].offset, text_length) : | 537 std::min(classifications[i + 1].offset, text_length) : |
537 text_length; | 538 text_length; |
538 const gfx::Range current_range(text_start, text_end); | 539 const gfx::Range current_range(text_start, text_end); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 bool is_match_contents_rtl) const { | 585 bool is_match_contents_rtl) const { |
585 if (match.type != AutocompleteMatchType::SEARCH_SUGGEST_TAIL) | 586 if (match.type != AutocompleteMatchType::SEARCH_SUGGEST_TAIL) |
586 return 0; | 587 return 0; |
587 | 588 |
588 const base::string16& input_text = | 589 const base::string16& input_text = |
589 base::UTF8ToUTF16(match.GetAdditionalInfo(kACMatchPropertyInputText)); | 590 base::UTF8ToUTF16(match.GetAdditionalInfo(kACMatchPropertyInputText)); |
590 int contents_start_index = 0; | 591 int contents_start_index = 0; |
591 base::StringToInt(match.GetAdditionalInfo(kACMatchPropertyContentsStartIndex), | 592 base::StringToInt(match.GetAdditionalInfo(kACMatchPropertyContentsStartIndex), |
592 &contents_start_index); | 593 &contents_start_index); |
593 | 594 |
594 scoped_ptr<gfx::RenderText> input_render_text(CreateRenderText(input_text)); | 595 std::unique_ptr<gfx::RenderText> input_render_text( |
| 596 CreateRenderText(input_text)); |
595 const gfx::Range& glyph_bounds = | 597 const gfx::Range& glyph_bounds = |
596 input_render_text->GetGlyphBounds(contents_start_index); | 598 input_render_text->GetGlyphBounds(contents_start_index); |
597 const int start_padding = is_match_contents_rtl ? | 599 const int start_padding = is_match_contents_rtl ? |
598 std::max(glyph_bounds.start(), glyph_bounds.end()) : | 600 std::max(glyph_bounds.start(), glyph_bounds.end()) : |
599 std::min(glyph_bounds.start(), glyph_bounds.end()); | 601 std::min(glyph_bounds.start(), glyph_bounds.end()); |
600 | 602 |
601 return is_ui_rtl ? | 603 return is_ui_rtl ? |
602 (input_render_text->GetContentWidth() - start_padding) : start_padding; | 604 (input_render_text->GetContentWidth() - start_padding) : start_padding; |
603 } | 605 } |
604 | 606 |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
788 .GetFontList(GetTextStyle(1).font) | 790 .GetFontList(GetTextStyle(1).font) |
789 .GetHeight(); | 791 .GetHeight(); |
790 } | 792 } |
791 | 793 |
792 int OmniboxResultView::GetContentLineHeight() const { | 794 int OmniboxResultView::GetContentLineHeight() const { |
793 return std::max( | 795 return std::max( |
794 default_icon_size_ + GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(), | 796 default_icon_size_ + GetLayoutInsets(OMNIBOX_DROPDOWN_ICON).height(), |
795 GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height()); | 797 GetTextHeight() + GetLayoutInsets(OMNIBOX_DROPDOWN_TEXT).height()); |
796 } | 798 } |
797 | 799 |
798 scoped_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( | 800 std::unique_ptr<gfx::RenderText> OmniboxResultView::CreateAnswerLine( |
799 const SuggestionAnswer::ImageLine& line, | 801 const SuggestionAnswer::ImageLine& line, |
800 gfx::FontList font_list) { | 802 gfx::FontList font_list) { |
801 scoped_ptr<gfx::RenderText> destination = CreateRenderText(base::string16()); | 803 std::unique_ptr<gfx::RenderText> destination = |
| 804 CreateRenderText(base::string16()); |
802 destination->SetFontList(font_list); | 805 destination->SetFontList(font_list); |
803 | 806 |
804 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) | 807 for (const SuggestionAnswer::TextField& text_field : line.text_fields()) |
805 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); | 808 AppendAnswerText(destination.get(), text_field.text(), text_field.type()); |
806 const base::char16 space(' '); | 809 const base::char16 space(' '); |
807 const auto* text_field = line.additional_text(); | 810 const auto* text_field = line.additional_text(); |
808 if (text_field) { | 811 if (text_field) { |
809 AppendAnswerText(destination.get(), space + text_field->text(), | 812 AppendAnswerText(destination.get(), space + text_field->text(), |
810 text_field->type()); | 813 text_field->type()); |
811 } | 814 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
865 | 868 |
866 int OmniboxResultView::StartMargin() const { | 869 int OmniboxResultView::StartMargin() const { |
867 return ui::MaterialDesignController::IsModeMaterial() ? | 870 return ui::MaterialDesignController::IsModeMaterial() ? |
868 model_->start_margin() : 0; | 871 model_->start_margin() : 0; |
869 } | 872 } |
870 | 873 |
871 int OmniboxResultView::EndMargin() const { | 874 int OmniboxResultView::EndMargin() const { |
872 return ui::MaterialDesignController::IsModeMaterial() ? | 875 return ui::MaterialDesignController::IsModeMaterial() ? |
873 model_->end_margin() : 0; | 876 model_->end_margin() : 0; |
874 } | 877 } |
OLD | NEW |