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