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 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 Profile* profile, | 134 Profile* profile, |
135 CommandUpdater* command_updater, | 135 CommandUpdater* command_updater, |
136 bool popup_window_mode, | 136 bool popup_window_mode, |
137 LocationBarView* location_bar, | 137 LocationBarView* location_bar, |
138 const gfx::FontList& font_list) | 138 const gfx::FontList& font_list) |
139 : OmniboxView( | 139 : OmniboxView( |
140 controller, | 140 controller, |
141 make_scoped_ptr(new ChromeOmniboxClient(controller, profile))), | 141 make_scoped_ptr(new ChromeOmniboxClient(controller, profile))), |
142 profile_(profile), | 142 profile_(profile), |
143 popup_window_mode_(popup_window_mode), | 143 popup_window_mode_(popup_window_mode), |
144 security_level_(connection_security::NONE), | 144 security_level_(SecurityStateModel::NONE), |
145 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), | 145 saved_selection_for_focus_change_(gfx::Range::InvalidRange()), |
146 ime_composing_before_change_(false), | 146 ime_composing_before_change_(false), |
147 delete_at_end_pressed_(false), | 147 delete_at_end_pressed_(false), |
148 location_bar_view_(location_bar), | 148 location_bar_view_(location_bar), |
149 ime_candidate_window_open_(false), | 149 ime_candidate_window_open_(false), |
150 select_all_on_mouse_release_(false), | 150 select_all_on_mouse_release_(false), |
151 select_all_on_gesture_tap_(false), | 151 select_all_on_gesture_tap_(false), |
152 weak_ptr_factory_(this) { | 152 weak_ptr_factory_(this) { |
153 SetBorder(views::Border::NullBorder()); | 153 SetBorder(views::Border::NullBorder()); |
154 set_id(VIEW_ID_OMNIBOX); | 154 set_id(VIEW_ID_OMNIBOX); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 | 219 |
220 // TODO(msw|oshima): Consider saving/restoring edit history. | 220 // TODO(msw|oshima): Consider saving/restoring edit history. |
221 ClearEditHistory(); | 221 ClearEditHistory(); |
222 } | 222 } |
223 | 223 |
224 void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) { | 224 void OmniboxViewViews::ResetTabState(content::WebContents* web_contents) { |
225 web_contents->SetUserData(OmniboxState::kKey, nullptr); | 225 web_contents->SetUserData(OmniboxState::kKey, nullptr); |
226 } | 226 } |
227 | 227 |
228 void OmniboxViewViews::Update() { | 228 void OmniboxViewViews::Update() { |
229 const connection_security::SecurityLevel old_security_level = security_level_; | 229 const SecurityStateModel::SecurityLevel old_security_level = security_level_; |
230 UpdateSecurityLevel(); | 230 UpdateSecurityLevel(); |
231 if (model()->UpdatePermanentText()) { | 231 if (model()->UpdatePermanentText()) { |
232 // Something visibly changed. Re-enable URL replacement. | 232 // Something visibly changed. Re-enable URL replacement. |
233 controller()->GetToolbarModel()->set_url_replacement_enabled(true); | 233 controller()->GetToolbarModel()->set_url_replacement_enabled(true); |
234 model()->UpdatePermanentText(); | 234 model()->UpdatePermanentText(); |
235 | 235 |
236 // Select all the new text if the user had all the old text selected, or if | 236 // Select all the new text if the user had all the old text selected, or if |
237 // there was no previous text (for new tab page URL replacement extensions). | 237 // there was no previous text (for new tab page URL replacement extensions). |
238 // This makes one particular case better: the user clicks in the box to | 238 // This makes one particular case better: the user clicks in the box to |
239 // change it right before the permanent URL is changed. Since the new URL | 239 // 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... |
321 const int kMinCharacters = 10; | 321 const int kMinCharacters = 10; |
322 return gfx::Size( | 322 return gfx::Size( |
323 GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets().width(), | 323 GetFontList().GetExpectedTextWidth(kMinCharacters) + GetInsets().width(), |
324 GetPreferredSize().height()); | 324 GetPreferredSize().height()); |
325 } | 325 } |
326 | 326 |
327 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 327 void OmniboxViewViews::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
328 views::Textfield::OnNativeThemeChanged(theme); | 328 views::Textfield::OnNativeThemeChanged(theme); |
329 if (location_bar_view_) { | 329 if (location_bar_view_) { |
330 SetBackgroundColor(location_bar_view_->GetColor( | 330 SetBackgroundColor(location_bar_view_->GetColor( |
331 connection_security::NONE, LocationBarView::BACKGROUND)); | 331 SecurityStateModel::NONE, LocationBarView::BACKGROUND)); |
332 } | 332 } |
333 EmphasizeURLComponents(); | 333 EmphasizeURLComponents(); |
334 } | 334 } |
335 | 335 |
336 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { | 336 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { |
337 Textfield::OnPaint(canvas); | 337 Textfield::OnPaint(canvas); |
338 if (!insert_char_time_.is_null()) { | 338 if (!insert_char_time_.is_null()) { |
339 UMA_HISTOGRAM_TIMES("Omnibox.CharTypedToRepaintLatency", | 339 UMA_HISTOGRAM_TIMES("Omnibox.CharTypedToRepaintLatency", |
340 base::TimeTicks::Now() - insert_char_time_); | 340 base::TimeTicks::Now() - insert_char_time_); |
341 insert_char_time_ = base::TimeTicks(); | 341 insert_char_time_ = base::TimeTicks(); |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 gfx::Range(host.begin, host.end())); | 640 gfx::Range(host.begin, host.end())); |
641 } | 641 } |
642 | 642 |
643 // Emphasize the scheme for security UI display purposes (if necessary). | 643 // Emphasize the scheme for security UI display purposes (if necessary). |
644 // Note that we check CurrentTextIsURL() because if we're replacing search | 644 // Note that we check CurrentTextIsURL() because if we're replacing search |
645 // URLs with search terms, we may have a non-URL even when the user is not | 645 // URLs with search terms, we may have a non-URL even when the user is not |
646 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser | 646 // editing; and in some cases, e.g. for "site:foo.com" searches, the parser |
647 // may have incorrectly identified a qualifier as a scheme. | 647 // may have incorrectly identified a qualifier as a scheme. |
648 SetStyle(gfx::DIAGONAL_STRIKE, false); | 648 SetStyle(gfx::DIAGONAL_STRIKE, false); |
649 if (!model()->user_input_in_progress() && text_is_url && | 649 if (!model()->user_input_in_progress() && text_is_url && |
650 scheme.is_nonempty() && (security_level_ != connection_security::NONE)) { | 650 scheme.is_nonempty() && (security_level_ != SecurityStateModel::NONE)) { |
651 SkColor security_color = location_bar_view_->GetColor( | 651 SkColor security_color = location_bar_view_->GetColor( |
652 security_level_, LocationBarView::SECURITY_TEXT); | 652 security_level_, LocationBarView::SECURITY_TEXT); |
653 const bool strike = | 653 const bool strike = (security_level_ == SecurityStateModel::SECURITY_ERROR); |
654 (security_level_ == connection_security::SECURITY_ERROR); | |
655 const gfx::Range scheme_range(scheme.begin, scheme.end()); | 654 const gfx::Range scheme_range(scheme.begin, scheme.end()); |
656 ApplyColor(security_color, scheme_range); | 655 ApplyColor(security_color, scheme_range); |
657 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); | 656 ApplyStyle(gfx::DIAGONAL_STRIKE, strike, scheme_range); |
658 } | 657 } |
659 } | 658 } |
660 | 659 |
661 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { | 660 bool OmniboxViewViews::OnKeyReleased(const ui::KeyEvent& event) { |
662 // The omnibox contents may change while the control key is pressed. | 661 // The omnibox contents may change while the control key is pressed. |
663 if (event.key_code() == ui::VKEY_CONTROL) | 662 if (event.key_code() == ui::VKEY_CONTROL) |
664 model()->OnControlKeyChanged(false); | 663 model()->OnControlKeyChanged(false); |
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1070 menu_contents->InsertItemWithStringIdAt( | 1069 menu_contents->InsertItemWithStringIdAt( |
1071 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1070 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
1072 } | 1071 } |
1073 | 1072 |
1074 // 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 |
1075 // 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 |
1076 // on IDC_ for now. | 1075 // on IDC_ for now. |
1077 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1076 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1078 IDS_EDIT_SEARCH_ENGINES); | 1077 IDS_EDIT_SEARCH_ENGINES); |
1079 } | 1078 } |
OLD | NEW |