| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 Profile* profile, | 135 Profile* profile, |
| 136 CommandUpdater* command_updater, | 136 CommandUpdater* command_updater, |
| 137 bool popup_window_mode, | 137 bool popup_window_mode, |
| 138 LocationBarView* location_bar, | 138 LocationBarView* location_bar, |
| 139 const gfx::FontList& font_list) | 139 const gfx::FontList& font_list) |
| 140 : OmniboxView( | 140 : OmniboxView( |
| 141 controller, | 141 controller, |
| 142 make_scoped_ptr(new ChromeOmniboxClient(controller, profile))), | 142 make_scoped_ptr(new ChromeOmniboxClient(controller, profile))), |
| 143 profile_(profile), | 143 profile_(profile), |
| 144 popup_window_mode_(popup_window_mode), | 144 popup_window_mode_(popup_window_mode), |
| 145 security_level_(connection_security::NONE), | 145 security_level_(SecurityStateModel::NONE), |
| 146 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), | 146 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), |
| 147 ime_composing_before_change_(false), | 147 ime_composing_before_change_(false), |
| 148 delete_at_end_pressed_(false), | 148 delete_at_end_pressed_(false), |
| 149 location_bar_view_(location_bar), | 149 location_bar_view_(location_bar), |
| 150 ime_candidate_window_open_(false), | 150 ime_candidate_window_open_(false), |
| 151 select_all_on_mouse_release_(false), | 151 select_all_on_mouse_release_(false), |
| 152 select_all_on_gesture_tap_(false), | 152 select_all_on_gesture_tap_(false), |
| 153 weak_ptr_factory_(this) { | 153 weak_ptr_factory_(this) { |
| 154 SetBorder(views::Border::NullBorder()); | 154 SetBorder(views::Border::NullBorder()); |
| 155 set_id(VIEW_ID_OMNIBOX); | 155 set_id(VIEW_ID_OMNIBOX); |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 | 220 |
| 221 // TODO(msw|oshima): Consider saving/restoring edit history. | 221 // TODO(msw|oshima): Consider saving/restoring edit history. |
| 222 ClearEditHistory(); | 222 ClearEditHistory(); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) { | 225 void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) { |
| 226 web_contents->SetUserData(OmniboxState::kKey, nullptr); | 226 web_contents->SetUserData(OmniboxState::kKey, nullptr); |
| 227 } | 227 } |
| 228 | 228 |
| 229 void OmniboxViewViews::Update() { | 229 void OmniboxViewViews::Update() { |
| 230 const connection_security::SecurityLevel old_security_level = security_level_; | 230 const SecurityStateModel::SecurityLevel old_security_level = security_level_; |
| 231 UpdateSecurityLevel(); | 231 UpdateSecurityLevel(); |
| 232 if (model()->UpdatePermanentText()) { | 232 if (model()->UpdatePermanentText()) { |
| 233 // Something visibly changed. Re-enable URL replacement. | 233 // Something visibly changed. Re-enable URL replacement. |
| 234 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | 234 controller()->GetToolbarModel()->set_url_replacement_enabled(true); |
| 235 model()->UpdatePermanentText(); | 235 model()->UpdatePermanentText(); |
| 236 | 236 |
| 237 // Select all the new text if the user had all the old text selected, or if | 237 // Select all the new text if the user had all the old text selected, or if |
| 238 // there was no previous text (for new tab page URL replacement extensions). | 238 // there was no previous text (for new tab page URL replacement extensions). |
| 239 // This makes one particular case better: the user clicks in the box to | 239 // This makes one particular case better: the user clicks in the box to |
| 240 // change it right before the permanent URL is changed. Since the new URL | 240 // change it right before the permanent URL is changed. Since the new URL |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(location_bar_view_->GetColor( |
| 332 connection_security::NONE, LocationBarView::BACKGROUND)); | 332 SecurityStateModel::NONE, 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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 641 gfx::Range(host.begin, host.end())); | 641 gfx::Range(host.begin, host.end())); |
| 642 } | 642 } |
| 643 | 643 |
| 644 // Emphasize the scheme for security UI display purposes (if necessary). | 644 // Emphasize the scheme for security UI display purposes (if necessary). |
| 645 // Note that we check CurrentTextIsURL() because if we're replacing search | 645 // 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 | 646 // 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 | 647 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
| 648 // may have incorrectly identified a qualifier as a scheme. | 648 // may have incorrectly identified a qualifier as a scheme. |
| 649 SetStyle(gfx::DIAGONAL_STRIKE, false); | 649 SetStyle(gfx::DIAGONAL_STRIKE, false); |
| 650 if (!model()->user_input_in_progress() && text_is_url && | 650 if (!model()->user_input_in_progress() && text_is_url && |
| 651 scheme.is_nonempty() && (security_level_ != connection_security::NONE)) { | 651 scheme.is_nonempty() && (security_level_ != SecurityStateModel::NONE)) { |
| 652 SkColor security_color = location_bar_view_->GetColor( | 652 SkColor security_color = location_bar_view_->GetColor( |
| 653 security_level_, LocationBarView::SECURITY_TEXT); | 653 security_level_, LocationBarView::SECURITY_TEXT); |
| 654 const bool strike = | 654 const bool strike = (security_level_ == SecurityStateModel::SECURITY_ERROR); |
| 655 (security_level_ == connection_security::SECURITY_ERROR); | |
| 656 const gfx::Range scheme_range(scheme.begin, scheme.end()); | 655 const gfx::Range scheme_range(scheme.begin, scheme.end()); |
| 657 ApplyColor(security_color, scheme_range); | 656 ApplyColor(security_color, scheme_range); |
| 658 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | 657 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); |
| 659 } | 658 } |
| 660 } | 659 } |
| 661 | 660 |
| 662 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { | 661 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { |
| 663 // The omnibox contents may change while the control key is pressed. | 662 // The omnibox contents may change while the control key is pressed. |
| 664 if (event.key_code() == ui::VKEY_CONTROL) | 663 if (event.key_code() == ui::VKEY_CONTROL) |
| 665 model()->OnControlKeyChanged(false); | 664 model()->OnControlKeyChanged(false); |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1071 menu_contents->InsertItemWithStringIdAt( | 1070 menu_contents->InsertItemWithStringIdAt( |
| 1072 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1071 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
| 1073 } | 1072 } |
| 1074 | 1073 |
| 1075 // Minor note: We use IDC_ for command id here while the underlying textfield | 1074 // 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 | 1075 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1077 // on IDC_ for now. | 1076 // on IDC_ for now. |
| 1078 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1077 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1079 IDS_EDIT_SEARCH_ENGINES); | 1078 IDS_EDIT_SEARCH_ENGINES); |
| 1080 } | 1079 } |
| OLD | NEW |