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 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
321 gfx::Size OmniboxViewViews::GetMinimumSize() const { | 321 gfx::Size OmniboxViewViews::GetMinimumSize() const { |
322 const int kMinCharacters = 10; | 322 const int kMinCharacters = 10; |
323 return gfx::Size( | 323 return gfx::Size( |
324 GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets().width(), | 324 GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets().width(), |
325 GetPreferredSize().height()); | 325 GetPreferredSize().height()); |
326 } | 326 } |
327 | 327 |
328 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 328 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
329 views::Textfield::OnNativeThemeChanged(theme); | 329 views::Textfield::OnNativeThemeChanged(theme); |
330 if (location_bar_view_) { | 330 if (location_bar_view_) { |
331 SetBackgroundColor(location_bar_view_->GetColor( | 331 SetBackgroundColor( |
332 SecurityStateModel::NONE, LocationBarView::BACKGROUND)); | 332 location_bar_view_->GetColor(LocationBarView::BACKGROUND)); |
333 } | 333 } |
334 EmphasizeURLComponents(); | 334 EmphasizeURLComponents(); |
335 } | 335 } |
336 | 336 |
337 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { | 337 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { |
338 Textfield::OnPaint(canvas); | 338 Textfield::OnPaint(canvas); |
339 if (!insert_char_time_.is_null()) { | 339 if (!insert_char_time_.is_null()) { |
340 UMA_HISTOGRAM_TIMES("Omnibox.CharTypedToRepaintLatency", | 340 UMA_HISTOGRAM_TIMES("Omnibox.CharTypedToRepaintLatency", |
341 base::TimeTicks::Now() - insert_char_time_); | 341 base::TimeTicks::Now() - insert_char_time_); |
342 insert_char_time_ = base::TimeTicks(); | 342 insert_char_time_ = base::TimeTicks(); |
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
626 // this input. This can tell us whether an UNKNOWN input string is going to | 626 // this input. This can tell us whether an UNKNOWN input string is going to |
627 // be treated as a search or a navigation, and is the same method the Paste | 627 // be treated as a search or a navigation, and is the same method the Paste |
628 // And Go system uses. | 628 // And Go system uses. |
629 url::Component scheme, host; | 629 url::Component scheme, host; |
630 AutocompleteInput::ParseForEmphasizeComponents( | 630 AutocompleteInput::ParseForEmphasizeComponents( |
631 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host); | 631 text(), ChromeAutocompleteSchemeClassifier(profile_), &scheme, &host); |
632 bool grey_out_url = text().substr(scheme.begin, scheme.len) == | 632 bool grey_out_url = text().substr(scheme.begin, scheme.len) == |
633 base::UTF8ToUTF16(extensions::kExtensionScheme); | 633 base::UTF8ToUTF16(extensions::kExtensionScheme); |
634 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); | 634 bool grey_base = text_is_url && (host.is_nonempty() || grey_out_url); |
635 SetColor(location_bar_view_->GetColor( | 635 SetColor(location_bar_view_->GetColor( |
636 security_level_, | |
637 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 636 grey_base ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
638 if (grey_base && !grey_out_url) { | 637 if (grey_base && !grey_out_url) { |
639 ApplyColor( | 638 ApplyColor(location_bar_view_->GetColor(LocationBarView::TEXT), |
640 location_bar_view_->GetColor(security_level_, LocationBarView::TEXT), | 639 gfx::Range(host.begin, host.end())); |
641 gfx::Range(host.begin, host.end())); | |
642 } | 640 } |
643 | 641 |
644 // Emphasize the scheme for security UI display purposes (if necessary). | 642 // Emphasize the scheme for security UI display purposes (if necessary). |
645 // Note that we check CurrentTextIsURL() because if we're replacing search | 643 // Note that we check CurrentTextIsURL() because if we're replacing search |
646 // URLs with search terms, we may have a non-URL even when the user is not | 644 // URLs with search terms, we may have a non-URL even when the user is not |
647 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | 645 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
648 // may have incorrectly identified a qualifier as a scheme. | 646 // may have incorrectly identified a qualifier as a scheme. |
649 SetStyle(gfx::DIAGONAL_STRIKE, false); | 647 SetStyle(gfx::DIAGONAL_STRIKE, false); |
650 if (!model()->user_input_in_progress() && text_is_url && | 648 if (!model()->user_input_in_progress() && text_is_url && |
651 scheme.is_nonempty() && (security_level_ != SecurityStateModel::NONE)) { | 649 scheme.is_nonempty() && (security_level_ != SecurityStateModel::NONE)) { |
652 SkColor security_color = location_bar_view_->GetColor( | 650 SkColor security_color = |
653 security_level_, LocationBarView::SECURITY_TEXT); | 651 location_bar_view_->GetSecureTextColor(security_level_); |
654 const bool strike = (security_level_ == SecurityStateModel::SECURITY_ERROR); | 652 const bool strike = (security_level_ == SecurityStateModel::SECURITY_ERROR); |
655 const gfx::Range scheme_range(scheme.begin, scheme.end()); | 653 const gfx::Range scheme_range(scheme.begin, scheme.end()); |
656 ApplyColor(security_color, scheme_range); | 654 ApplyColor(security_color, scheme_range); |
657 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | 655 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); |
658 } | 656 } |
659 } | 657 } |
660 | 658 |
661 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { | 659 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { |
662 // The omnibox contents may change while the control key is pressed. | 660 // The omnibox contents may change while the control key is pressed. |
663 if (event.key_code() == ui::VKEY_CONTROL) | 661 if (event.key_code() == ui::VKEY_CONTROL) |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 menu_contents->InsertItemWithStringIdAt( | 1069 menu_contents->InsertItemWithStringIdAt( |
1072 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1070 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
1073 } | 1071 } |
1074 | 1072 |
1075 // Minor note: We use IDC_ for command id here while the underlying textfield | 1073 // Minor note: We use IDC_ for command id here while the underlying textfield |
1076 // is using IDS_ for all its command ids. This is because views cannot depend | 1074 // is using IDS_ for all its command ids. This is because views cannot depend |
1077 // on IDC_ for now. | 1075 // on IDC_ for now. |
1078 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1076 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1079 IDS_EDIT_SEARCH_ENGINES); | 1077 IDS_EDIT_SEARCH_ENGINES); |
1080 } | 1078 } |
OLD | NEW |