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 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
595 } | 595 } |
596 | 596 |
597 int OmniboxViewViews::GetOmniboxTextLength() const { | 597 int OmniboxViewViews::GetOmniboxTextLength() const { |
598 // TODO(oshima): Support IME. | 598 // TODO(oshima): Support IME. |
599 return static_cast<int>(text().length()); | 599 return static_cast<int>(text().length()); |
600 } | 600 } |
601 | 601 |
602 void OmniboxViewViews::EmphasizeURLComponents() { | 602 void OmniboxViewViews::EmphasizeURLComponents() { |
603 if (!location_bar_view_) | 603 if (!location_bar_view_) |
604 return; | 604 return; |
605 | |
606 // If the current contents is a URL, force left-to-right rendering at the | |
607 // paragraph level. This still allows text to be rendered from right to left, | |
608 // but any LTR or neutral characters (e.g. digits) at the start will always be | |
609 // rendered on the left. | |
Peter Kasting
2015/06/15 22:39:24
This second sentence is a bit unclear. If you nee
Matt Giuca
2015/06/16 00:21:32
Done.
| |
610 bool text_is_url = model()->CurrentTextIsURL(); | |
611 GetRenderText()->SetDirectionalityMode(text_is_url | |
612 ? gfx::DIRECTIONALITY_FORCE_LTR | |
613 : gfx::DIRECTIONALITY_FROM_TEXT); | |
614 | |
605 // See whether the contents are a URL with a non-empty host portion, which we | 615 // See whether the contents are a URL with a non-empty host portion, which we |
606 // should emphasize. To check for a URL, rather than using the type returned | 616 // should emphasize. To check for a URL, rather than using the type returned |
607 // by Parse(), ask the model, which will check the desired page transition for | 617 // by Parse(), ask the model, which will check the desired page transition for |
608 // this input. This can tell us whether an UNKNOWN input string is going to | 618 // this input. This can tell us whether an UNKNOWN input string is going to |
609 // be treated as a search or a navigation, and is the same method the Paste | 619 // be treated as a search or a navigation, and is the same method the Paste |
610 // And Go system uses. | 620 // And Go system uses. |
611 url::Component scheme, host; | 621 url::Component scheme, host; |
612 AutocompleteInput::ParseForEmphasizeComponents( | 622 AutocompleteInput::ParseForEmphasizeComponents( |
613 text(), ChromeAutocompleteSchemeClassifier(profile()), &scheme, &host); | 623 text(), ChromeAutocompleteSchemeClassifier(profile()), &scheme, &host); |
614 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | 624 bool grey_out_url = text().substr(scheme.begin, scheme.len) == |
615 base::UTF8ToUTF16(extensions::kExtensionScheme); | 625 base::UTF8ToUTF16(extensions::kExtensionScheme); |
616 bool grey_base = model()->CurrentTextIsURL() && | 626 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); |
617 (host.is_nonempty() || grey_out_url); | |
618 SetColor(location_bar_view_->GetColor( | 627 SetColor(location_bar_view_->GetColor( |
619 security_level_, | 628 security_level_, |
620 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 629 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
621 if (grey_base && !grey_out_url) { | 630 if (grey_base && !grey_out_url) { |
622 ApplyColor( | 631 ApplyColor( |
623 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), | 632 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), |
624 gfx::Range(host.begin, host.end())); | 633 gfx::Range(host.begin, host.end())); |
625 } | 634 } |
626 | 635 |
627 // Emphasize the scheme for security UI display purposes (if necessary). | 636 // Emphasize the scheme for security UI display purposes (if necessary). |
628 // Note that we check CurrentTextIsURL() because if we're replacing search | 637 // Note that we check CurrentTextIsURL() because if we're replacing search |
629 // URLs with search terms, we may have a non-URL even when the user is not | 638 // URLs with search terms, we may have a non-URL even when the user is not |
630 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | 639 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
631 // may have incorrectly identified a qualifier as a scheme. | 640 // may have incorrectly identified a qualifier as a scheme. |
632 SetStyle(gfx::DIAGONAL_STRIKE, false); | 641 SetStyle(gfx::DIAGONAL_STRIKE, false); |
633 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 642 if (!model()->user_input_in_progress() && text_is_url && |
634 scheme.is_nonempty() && | 643 scheme.is_nonempty() && |
635 (security_level_ != ConnectionSecurityHelper::NONE)) { | 644 (security_level_ != ConnectionSecurityHelper::NONE)) { |
636 SkColor security_color = location_bar_view_->GetColor( | 645 SkColor security_color = location_bar_view_->GetColor( |
637 security_level_, LocationBarView::SECURITY_TEXT); | 646 security_level_, LocationBarView::SECURITY_TEXT); |
638 const bool strike = | 647 const bool strike = |
639 (security_level_ == ConnectionSecurityHelper::SECURITY_ERROR); | 648 (security_level_ == ConnectionSecurityHelper::SECURITY_ERROR); |
640 const gfx::Range scheme_range(scheme.begin, scheme.end()); | 649 const gfx::Range scheme_range(scheme.begin, scheme.end()); |
641 ApplyColor(security_color, scheme_range); | 650 ApplyColor(security_color, scheme_range); |
642 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | 651 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); |
643 } | 652 } |
(...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1055 menu_contents->InsertItemWithStringIdAt( | 1064 menu_contents->InsertItemWithStringIdAt( |
1056 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1065 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
1057 } | 1066 } |
1058 | 1067 |
1059 // Minor note: We use IDC_ for command id here while the underlying textfield | 1068 // Minor note: We use IDC_ for command id here while the underlying textfield |
1060 // is using IDS_ for all its command ids. This is because views cannot depend | 1069 // is using IDS_ for all its command ids. This is because views cannot depend |
1061 // on IDC_ for now. | 1070 // on IDC_ for now. |
1062 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1071 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1063 IDS_EDIT_SEARCH_ENGINES); | 1072 IDS_EDIT_SEARCH_ENGINES); |
1064 } | 1073 } |
OLD | NEW |