Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(92)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 11535014: Replace StyleRange with BreakList; update RenderText, etc. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 const ViewState& view_state) 74 const ViewState& view_state)
75 : model_state(model_state), 75 : model_state(model_state),
76 view_state(view_state) { 76 view_state(view_state) {
77 } 77 }
78 virtual ~AutocompleteEditState() {} 78 virtual ~AutocompleteEditState() {}
79 79
80 const OmniboxEditModel::State model_state; 80 const OmniboxEditModel::State model_state;
81 const ViewState view_state; 81 const ViewState view_state;
82 }; 82 };
83 83
84 // A convenience method for applying URL styles.
85 void ApplyURLStyle(views::Textfield* textfield,
86 size_t start,
87 size_t end,
88 SkColor color,
89 bool diagonal_strike) {
90 gfx::StyleRange style;
91 style.foreground = color;
92 style.range = ui::Range(start, end);
93 style.diagonal_strike = diagonal_strike;
94 textfield->ApplyStyleRange(style);
95 }
96
97 // The following const value is the same as in browser_defaults. 84 // The following const value is the same as in browser_defaults.
98 const int kAutocompleteEditFontPixelSize = 15; 85 const int kAutocompleteEditFontPixelSize = 15;
99 // Font size 10px (as defined in browser_defaults) is too small for many 86 // Font size 10px (as defined in browser_defaults) is too small for many
100 // non-Latin/Greek/Cyrillic (non-LGC) scripts. For pop-up window, the total 87 // non-Latin/Greek/Cyrillic (non-LGC) scripts. For pop-up window, the total
101 // rectangle is 21px tall and the height available for "ink" is 17px (please 88 // rectangle is 21px tall and the height available for "ink" is 17px (please
102 // refer to kAutocompleteVerticalMarginInPopup). With 12px font size, the 89 // refer to kAutocompleteVerticalMarginInPopup). With 12px font size, the
103 // tallest glyphs in UI fonts we're building for ChromeOS (across all scripts) 90 // tallest glyphs in UI fonts we're building for ChromeOS (across all scripts)
104 // still fit within 17px "ink" height. 91 // still fit within 17px "ink" height.
105 const int kAutocompleteEditFontPixelSizeInPopup = 12; 92 const int kAutocompleteEditFontPixelSizeInPopup = 12;
106 93
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
905 // should emphasize. To check for a URL, rather than using the type returned 892 // should emphasize. To check for a URL, rather than using the type returned
906 // by Parse(), ask the model, which will check the desired page transition for 893 // by Parse(), ask the model, which will check the desired page transition for
907 // this input. This can tell us whether an UNKNOWN input string is going to 894 // this input. This can tell us whether an UNKNOWN input string is going to
908 // be treated as a search or a navigation, and is the same method the Paste 895 // be treated as a search or a navigation, and is the same method the Paste
909 // And Go system uses. 896 // And Go system uses.
910 string16 text = GetText(); 897 string16 text = GetText();
911 url_parse::Component scheme, host; 898 url_parse::Component scheme, host;
912 AutocompleteInput::ParseForEmphasizeComponents(text, model()->GetDesiredTLD(), 899 AutocompleteInput::ParseForEmphasizeComponents(text, model()->GetDesiredTLD(),
913 &scheme, &host); 900 &scheme, &host);
914 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); 901 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0);
915 902 textfield_->SetColor(location_bar_view_->GetColor(security_level_,
916 SkColor base_color = location_bar_view_->GetColor( 903 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT));
917 security_level_,
918 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT);
919 ApplyURLStyle(textfield_, 0, text.length(), base_color, false);
920
921 if (emphasize) { 904 if (emphasize) {
922 SkColor normal_color = location_bar_view_->GetColor( 905 textfield_->ApplyColor(
923 security_level_, LocationBarView::TEXT); 906 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT),
924 ApplyURLStyle(textfield_, host.begin, host.end(), normal_color, false); 907 ui::Range(host.begin, host.end()));
925 } 908 }
926 909
927 // Emphasize the scheme for security UI display purposes (if necessary). 910 // Emphasize the scheme for security UI display purposes (if necessary).
928 // Note that we check CurrentTextIsURL() because if we're replacing search 911 // Note that we check CurrentTextIsURL() because if we're replacing search
929 // URLs with search terms, we may have a non-URL even when the user is not 912 // URLs with search terms, we may have a non-URL even when the user is not
930 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser 913 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser
931 // may have incorrectly identified a qualifier as a scheme. 914 // may have incorrectly identified a qualifier as a scheme.
932 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && 915 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() &&
933 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { 916 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) {
934 SkColor security_color = location_bar_view_->GetColor( 917 SkColor security_color = location_bar_view_->GetColor(
935 security_level_, LocationBarView::SECURITY_TEXT); 918 security_level_, LocationBarView::SECURITY_TEXT);
936 bool use_strikethrough = (security_level_ == ToolbarModel::SECURITY_ERROR); 919 const bool strike = (security_level_ == ToolbarModel::SECURITY_ERROR);
937 ApplyURLStyle(textfield_, scheme.begin, scheme.end(), 920 const ui::Range scheme_range(scheme.begin, scheme.end());
938 security_color, use_strikethrough); 921 textfield_->ApplyColor(security_color, scheme_range);
922 textfield_->ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range);
939 } 923 }
940 } 924 }
941 925
942 void OmniboxViewViews::SetTextAndSelectedRange(const string16& text, 926 void OmniboxViewViews::SetTextAndSelectedRange(const string16& text,
943 const ui::Range& range) { 927 const ui::Range& range) {
944 if (text != GetText()) 928 if (text != GetText())
945 textfield_->SetText(text); 929 textfield_->SetText(text);
946 textfield_->SelectRange(range); 930 textfield_->SelectRange(range);
947 } 931 }
948 932
(...skipping 12 matching lines...) Expand all
961 if (!text.empty()) { 945 if (!text.empty()) {
962 // Record this paste, so we can do different behavior. 946 // Record this paste, so we can do different behavior.
963 model()->on_paste(); 947 model()->on_paste();
964 // Force a Paste operation to trigger the text_changed code in 948 // Force a Paste operation to trigger the text_changed code in
965 // OnAfterPossibleChange(), even if identical contents are pasted into the 949 // OnAfterPossibleChange(), even if identical contents are pasted into the
966 // text box. 950 // text box.
967 text_before_change_.clear(); 951 text_before_change_.clear();
968 textfield_->ReplaceSelection(text); 952 textfield_->ReplaceSelection(text);
969 } 953 }
970 } 954 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698