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 "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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 //////////////////////////////////////////////////////////////////////////////// | 233 //////////////////////////////////////////////////////////////////////////////// |
234 // OmniboxViewViews public: | 234 // OmniboxViewViews public: |
235 | 235 |
236 void OmniboxViewViews::Init() { | 236 void OmniboxViewViews::Init() { |
237 // The height of the text view is going to change based on the font used. We | 237 // The height of the text view is going to change based on the font used. We |
238 // don't want to stretch the height, and we want it vertically centered. | 238 // don't want to stretch the height, and we want it vertically centered. |
239 // TODO(oshima): make sure the above happens with views. | 239 // TODO(oshima): make sure the above happens with views. |
240 textfield_ = new AutocompleteTextfield(this, location_bar_view_); | 240 textfield_ = new AutocompleteTextfield(this, location_bar_view_); |
241 textfield_->SetController(this); | 241 textfield_->SetController(this); |
242 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 242 textfield_->SetTextInputType(ui::TEXT_INPUT_TYPE_URL); |
243 textfield_->SetBackgroundColor(LocationBarView::GetColor( | 243 textfield_->SetBackgroundColor(location_bar_view_->GetColor( |
244 ToolbarModel::NONE, LocationBarView::BACKGROUND)); | 244 ToolbarModel::NONE, LocationBarView::BACKGROUND)); |
245 | 245 |
246 if (popup_window_mode_) | 246 if (popup_window_mode_) |
247 textfield_->SetReadOnly(true); | 247 textfield_->SetReadOnly(true); |
248 | 248 |
249 const int font_size = GetEditFontPixelSize(popup_window_mode_); | 249 const int font_size = GetEditFontPixelSize(popup_window_mode_); |
250 const int old_size = textfield_->font().GetFontSize(); | 250 const int old_size = textfield_->font().GetFontSize(); |
251 if (font_size != old_size) | 251 if (font_size != old_size) |
252 textfield_->SetFont(textfield_->font().DeriveFont(font_size - old_size)); | 252 textfield_->SetFont(textfield_->font().DeriveFont(font_size - old_size)); |
253 | 253 |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
852 // by Parse(), ask the model, which will check the desired page transition for | 852 // by Parse(), ask the model, which will check the desired page transition for |
853 // this input. This can tell us whether an UNKNOWN input string is going to | 853 // this input. This can tell us whether an UNKNOWN input string is going to |
854 // be treated as a search or a navigation, and is the same method the Paste | 854 // be treated as a search or a navigation, and is the same method the Paste |
855 // And Go system uses. | 855 // And Go system uses. |
856 string16 text = GetText(); | 856 string16 text = GetText(); |
857 url_parse::Component scheme, host; | 857 url_parse::Component scheme, host; |
858 AutocompleteInput::ParseForEmphasizeComponents(text, model()->GetDesiredTLD(), | 858 AutocompleteInput::ParseForEmphasizeComponents(text, model()->GetDesiredTLD(), |
859 &scheme, &host); | 859 &scheme, &host); |
860 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); | 860 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
861 | 861 |
862 SkColor base_color = LocationBarView::GetColor( | 862 SkColor base_color = location_bar_view_->GetColor( |
863 security_level_, | 863 security_level_, |
864 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT); | 864 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT); |
865 ApplyURLStyle(textfield_, 0, text.length(), base_color, false); | 865 ApplyURLStyle(textfield_, 0, text.length(), base_color, false); |
866 | 866 |
867 if (emphasize) { | 867 if (emphasize) { |
868 SkColor normal_color = | 868 SkColor normal_color = location_bar_view_->GetColor( |
869 LocationBarView::GetColor(security_level_, LocationBarView::TEXT); | 869 security_level_, LocationBarView::TEXT); |
870 ApplyURLStyle(textfield_, host.begin, host.end(), normal_color, false); | 870 ApplyURLStyle(textfield_, host.begin, host.end(), normal_color, false); |
871 } | 871 } |
872 | 872 |
873 // Emphasize the scheme for security UI display purposes (if necessary). | 873 // Emphasize the scheme for security UI display purposes (if necessary). |
874 // Note that we check CurrentTextIsURL() because if we're replacing search | 874 // Note that we check CurrentTextIsURL() because if we're replacing search |
875 // URLs with search terms, we may have a non-URL even when the user is not | 875 // URLs with search terms, we may have a non-URL even when the user is not |
876 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | 876 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
877 // may have incorrectly identified a qualifier as a scheme. | 877 // may have incorrectly identified a qualifier as a scheme. |
878 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && | 878 if (!model()->user_input_in_progress() && model()->CurrentTextIsURL() && |
879 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { | 879 scheme.is_nonempty() && (security_level_ != ToolbarModel::NONE)) { |
880 SkColor security_color = LocationBarView::GetColor( | 880 SkColor security_color = location_bar_view_->GetColor( |
881 security_level_, LocationBarView::SECURITY_TEXT); | 881 security_level_, LocationBarView::SECURITY_TEXT); |
882 bool use_strikethrough = (security_level_ == ToolbarModel::SECURITY_ERROR); | 882 bool use_strikethrough = (security_level_ == ToolbarModel::SECURITY_ERROR); |
883 ApplyURLStyle(textfield_, scheme.begin, scheme.end(), | 883 ApplyURLStyle(textfield_, scheme.begin, scheme.end(), |
884 security_color, use_strikethrough); | 884 security_color, use_strikethrough); |
885 } | 885 } |
886 } | 886 } |
887 | 887 |
888 void OmniboxViewViews::SetTextAndSelectedRange(const string16& text, | 888 void OmniboxViewViews::SetTextAndSelectedRange(const string16& text, |
889 const ui::Range& range) { | 889 const ui::Range& range) { |
890 if (text != GetText()) | 890 if (text != GetText()) |
891 textfield_->SetText(text); | 891 textfield_->SetText(text); |
892 textfield_->SelectRange(range); | 892 textfield_->SelectRange(range); |
893 } | 893 } |
894 | 894 |
895 string16 OmniboxViewViews::GetSelectedText() const { | 895 string16 OmniboxViewViews::GetSelectedText() const { |
896 // TODO(oshima): Support instant, IME. | 896 // TODO(oshima): Support instant, IME. |
897 return textfield_->GetSelectedText(); | 897 return textfield_->GetSelectedText(); |
898 } | 898 } |
899 | 899 |
900 void OmniboxViewViews::CopyURL() { | 900 void OmniboxViewViews::CopyURL() { |
901 const string16& text = toolbar_model()->GetText(false); | 901 const string16& text = toolbar_model()->GetText(false); |
902 DoCopy(text, true, toolbar_model()->GetURL(), text); | 902 DoCopy(text, true, toolbar_model()->GetURL(), text); |
903 } | 903 } |
OLD | NEW |