OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" | 5 #include "chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.
h" |
6 | 6 |
7 #include "app/bidi_line_iterator.h" | |
8 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
9 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
10 #include "app/text_elider.h" | |
11 #include "app/theme_provider.h" | |
12 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
13 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
14 #include "base/utf_string_conversions.h" | 11 #include "base/utf_string_conversions.h" |
15 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" | 12 #include "chrome/browser/autocomplete/autocomplete_edit_view.h" |
16 #include "chrome/browser/autocomplete/autocomplete_match.h" | 13 #include "chrome/browser/autocomplete/autocomplete_match.h" |
17 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" | 14 #include "chrome/browser/autocomplete/autocomplete_popup_model.h" |
18 #include "chrome/browser/instant/instant_confirm_dialog.h" | 15 #include "chrome/browser/instant/instant_confirm_dialog.h" |
19 #include "chrome/browser/instant/promo_counter.h" | 16 #include "chrome/browser/instant/promo_counter.h" |
20 #include "chrome/browser/profiles/profile.h" | 17 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/ui/views/bubble_border.h" | 18 #include "chrome/browser/ui/views/bubble_border.h" |
22 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 19 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
23 #include "gfx/canvas_skia.h" | 20 #include "gfx/canvas_skia.h" |
24 #include "gfx/color_utils.h" | 21 #include "gfx/color_utils.h" |
25 #include "gfx/insets.h" | 22 #include "gfx/insets.h" |
26 #include "gfx/path.h" | 23 #include "gfx/path.h" |
27 #include "grit/chromium_strings.h" | 24 #include "grit/chromium_strings.h" |
28 #include "grit/generated_resources.h" | 25 #include "grit/generated_resources.h" |
29 #include "grit/theme_resources.h" | 26 #include "grit/theme_resources.h" |
30 #include "third_party/skia/include/core/SkShader.h" | 27 #include "third_party/skia/include/core/SkShader.h" |
| 28 #include "ui/base/text/bidi_line_iterator.h" |
| 29 #include "ui/base/text/text_elider.h" |
| 30 #include "ui/base/theme_provider.h" |
31 #include "unicode/ubidi.h" | 31 #include "unicode/ubidi.h" |
32 #include "views/controls/button/text_button.h" | 32 #include "views/controls/button/text_button.h" |
33 #include "views/controls/label.h" | 33 #include "views/controls/label.h" |
34 #include "views/grid_layout.h" | 34 #include "views/grid_layout.h" |
35 #include "views/painter.h" | 35 #include "views/painter.h" |
36 #include "views/standard_layout.h" | 36 #include "views/standard_layout.h" |
37 #include "views/widget/widget.h" | 37 #include "views/widget/widget.h" |
38 #include "views/window/window.h" | 38 #include "views/window/window.h" |
39 | 39 |
40 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 if (!(i->style & ACMatchClassification::URL)) { | 551 if (!(i->style & ACMatchClassification::URL)) { |
552 is_url = false; | 552 is_url = false; |
553 break; | 553 break; |
554 } | 554 } |
555 } | 555 } |
556 | 556 |
557 // Split the text into visual runs. We do this first so that we don't need to | 557 // Split the text into visual runs. We do this first so that we don't need to |
558 // worry about whether our eliding might change the visual display in | 558 // worry about whether our eliding might change the visual display in |
559 // unintended ways, e.g. by removing directional markings or by adding an | 559 // unintended ways, e.g. by removing directional markings or by adding an |
560 // ellipsis that's not enclosed in appropriate markings. | 560 // ellipsis that's not enclosed in appropriate markings. |
561 BiDiLineIterator bidi_line; | 561 ui::BiDiLineIterator bidi_line; |
562 if (!bidi_line.Open(WideToUTF16Hack(text), base::i18n::IsRTL(), is_url)) | 562 if (!bidi_line.Open(WideToUTF16Hack(text), base::i18n::IsRTL(), is_url)) |
563 return x; | 563 return x; |
564 const int num_runs = bidi_line.CountRuns(); | 564 const int num_runs = bidi_line.CountRuns(); |
565 Runs runs; | 565 Runs runs; |
566 for (int run = 0; run < num_runs; ++run) { | 566 for (int run = 0; run < num_runs; ++run) { |
567 int run_start_int = 0, run_length_int = 0; | 567 int run_start_int = 0, run_length_int = 0; |
568 // The index we pass to GetVisualRun corresponds to the position of the run | 568 // The index we pass to GetVisualRun corresponds to the position of the run |
569 // in the displayed text. For example, the string "Google in HEBREW" (where | 569 // in the displayed text. For example, the string "Google in HEBREW" (where |
570 // HEBREW is text in the Hebrew language) has two runs: "Google in " which | 570 // HEBREW is text in the Hebrew language) has two runs: "Google in " which |
571 // is an LTR run, and "HEBREW" which is an RTL run. In an LTR context, the | 571 // is an LTR run, and "HEBREW" which is an RTL run. In an LTR context, the |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
704 | 704 |
705 // We also add this classification's width (sans ellipsis) back to the | 705 // We also add this classification's width (sans ellipsis) back to the |
706 // available width since we want to consider the available space we'll | 706 // available width since we want to consider the available space we'll |
707 // have when we draw this classification. | 707 // have when we draw this classification. |
708 remaining_width += j->pixel_width; | 708 remaining_width += j->pixel_width; |
709 } | 709 } |
710 first_classification = false; | 710 first_classification = false; |
711 | 711 |
712 // Can we fit at least an ellipsis? | 712 // Can we fit at least an ellipsis? |
713 std::wstring elided_text(UTF16ToWideHack( | 713 std::wstring elided_text(UTF16ToWideHack( |
714 gfx::ElideText(WideToUTF16Hack(j->text), *j->font, remaining_width, | 714 ui::ElideText(WideToUTF16Hack(j->text), *j->font, remaining_width, |
715 false))); | 715 false))); |
716 Classifications::reverse_iterator prior_classification(j); | 716 Classifications::reverse_iterator prior_classification(j); |
717 ++prior_classification; | 717 ++prior_classification; |
718 const bool on_first_classification = | 718 const bool on_first_classification = |
719 (prior_classification == i->classifications.rend()); | 719 (prior_classification == i->classifications.rend()); |
720 if (elided_text.empty() && (remaining_width >= ellipsis_width_) && | 720 if (elided_text.empty() && (remaining_width >= ellipsis_width_) && |
721 on_first_classification) { | 721 on_first_classification) { |
722 // Edge case: This classification is bold, we can't fit a bold ellipsis | 722 // Edge case: This classification is bold, we can't fit a bold ellipsis |
723 // but we can fit a normal one, and this is the first classification in | 723 // but we can fit a normal one, and this is the first classification in |
724 // the run. We should display a lone normal ellipsis, because appending | 724 // the run. We should display a lone normal ellipsis, because appending |
725 // one to the end of the previous run might put it in the wrong visual | 725 // one to the end of the previous run might put it in the wrong visual |
(...skipping 478 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1204 opt_in_view_ = NULL; | 1204 opt_in_view_ = NULL; |
1205 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); | 1205 PromoCounter* counter = model_->profile()->GetInstantPromoCounter(); |
1206 DCHECK(counter); | 1206 DCHECK(counter); |
1207 counter->Hide(); | 1207 counter->Hide(); |
1208 if (opt_in) { | 1208 if (opt_in) { |
1209 browser::ShowInstantConfirmDialogIfNecessary( | 1209 browser::ShowInstantConfirmDialogIfNecessary( |
1210 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); | 1210 location_bar_->GetWindow()->GetNativeWindow(), model_->profile()); |
1211 } | 1211 } |
1212 UpdatePopupAppearance(); | 1212 UpdatePopupAppearance(); |
1213 } | 1213 } |
OLD | NEW |