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" |
11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 11 #include "chrome/browser/autocomplete/autocomplete_input.h" |
12 #include "chrome/browser/autocomplete/autocomplete_match.h" | 12 #include "chrome/browser/autocomplete/autocomplete_match.h" |
13 #include "chrome/browser/bookmarks/bookmark_node_data.h" | 13 #include "chrome/browser/bookmarks/bookmark_node_data.h" |
14 #include "chrome/browser/command_updater.h" | 14 #include "chrome/browser/command_updater.h" |
15 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" | 15 #include "chrome/browser/ui/omnibox/omnibox_edit_controller.h" |
16 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" | 16 #include "chrome/browser/ui/omnibox/omnibox_popup_model.h" |
17 #include "chrome/browser/ui/omnibox/omnibox_types.h" | |
17 #include "chrome/browser/ui/search/search.h" | 18 #include "chrome/browser/ui/search/search.h" |
18 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 19 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
19 #include "chrome/browser/ui/view_ids.h" | 20 #include "chrome/browser/ui/view_ids.h" |
20 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 21 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
21 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" | 22 #include "chrome/browser/ui/views/omnibox/omnibox_popup_contents_view.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
23 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
24 #include "grit/app_locale_settings.h" | 25 #include "grit/app_locale_settings.h" |
25 #include "grit/generated_resources.h" | 26 #include "grit/generated_resources.h" |
26 #include "grit/ui_strings.h" | 27 #include "grit/ui_strings.h" |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
354 // controls. | 355 // controls. |
355 model()->OnControlKeyChanged(false); | 356 model()->OnControlKeyChanged(false); |
356 return true; | 357 return true; |
357 } | 358 } |
358 return false; | 359 return false; |
359 } | 360 } |
360 | 361 |
361 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { | 362 void OmniboxViewViews::HandleMousePressEvent(const ui::MouseEvent& event) { |
362 select_all_on_mouse_release_ = | 363 select_all_on_mouse_release_ = |
363 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 364 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
364 !textfield_->HasFocus(); | 365 (!textfield_->HasFocus() || |
365 // Restore caret visibility whenever the user clicks in the the omnibox. This | 366 model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE); |
Peter Kasting
2012/12/11 19:20:50
Nit: Really minor, but I prefer to put parens arou
samarth
2012/12/12 01:11:26
Done.
| |
366 // is not always covered by OnSetFocus() because when clicking while the | 367 // Restore caret visibility whenever the user clicks in the omnibox in a way |
367 // omnibox has invisible focus does not trigger a new OnSetFocus() call. | 368 // that would give it focus. We must handle this case separately here because |
368 model()->SetCaretVisibility(true); | 369 // if the omnibox currently has invisible focus, the mouse event won't trigger |
370 // either SetFocus() or OmniboxEditModel::OnSetFocus(). | |
371 if (select_all_on_mouse_release_) | |
372 model()->SetCaretVisibility(true); | |
369 } | 373 } |
370 | 374 |
371 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { | 375 void OmniboxViewViews::HandleMouseDragEvent(const ui::MouseEvent& event) { |
372 select_all_on_mouse_release_ = false; | 376 select_all_on_mouse_release_ = false; |
373 } | 377 } |
374 | 378 |
375 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { | 379 void OmniboxViewViews::HandleMouseReleaseEvent(const ui::MouseEvent& event) { |
376 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 380 if ((event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
377 select_all_on_mouse_release_) { | 381 select_all_on_mouse_release_) { |
378 // Select all in the reverse direction so as not to scroll the caret | 382 // Select all in the reverse direction so as not to scroll the caret |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 // the text, or in the middle of composition. | 569 // the text, or in the middle of composition. |
566 ui::Range sel; | 570 ui::Range sel; |
567 textfield_->GetSelectedRange(&sel); | 571 textfield_->GetSelectedRange(&sel); |
568 bool no_inline_autocomplete = | 572 bool no_inline_autocomplete = |
569 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); | 573 sel.GetMax() < GetTextLength() || textfield_->IsIMEComposing(); |
570 | 574 |
571 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); | 575 model()->StartAutocomplete(!sel.is_empty(), no_inline_autocomplete); |
572 } | 576 } |
573 | 577 |
574 void OmniboxViewViews::SetFocus() { | 578 void OmniboxViewViews::SetFocus() { |
575 // Restore caret visibility if focused explicitly. We need to do this here | |
576 // because if we already have invisible focus, the RequestFocus() call below | |
577 // will short-circuit, preventing us from reaching | |
578 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when we | |
579 // didn't previously have focus. | |
580 model()->SetCaretVisibility(true); | |
581 // In views-implementation, the focus is on textfield rather than OmniboxView. | 579 // In views-implementation, the focus is on textfield rather than OmniboxView. |
582 textfield_->RequestFocus(); | 580 textfield_->RequestFocus(); |
581 // Restore caret visibility if focus is explicitly requested. This is | |
582 // necessary because if we already have invisible focus, the RequestFocus() | |
583 // call above will short-circuit, preventing us from reaching | |
584 // OmniboxEditModel::OnSetFocus(), which handles restoring visibility when the | |
585 // omnibox regains focus after losing focus. | |
586 model()->SetCaretVisibility(true); | |
583 } | 587 } |
584 | 588 |
585 void OmniboxViewViews::ApplyCaretVisibility() { | 589 void OmniboxViewViews::ApplyCaretVisibility() { |
586 textfield_->SetCursorEnabled(model()->is_caret_visible()); | 590 textfield_->SetCursorEnabled(model()->is_caret_visible()); |
587 } | 591 } |
588 | 592 |
589 void OmniboxViewViews::OnTemporaryTextMaybeChanged( | 593 void OmniboxViewViews::OnTemporaryTextMaybeChanged( |
590 const string16& display_text, | 594 const string16& display_text, |
591 bool save_original_selection) { | 595 bool save_original_selection) { |
592 if (save_original_selection) | 596 if (save_original_selection) |
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
963 if (!text.empty()) { | 967 if (!text.empty()) { |
964 // Record this paste, so we can do different behavior. | 968 // Record this paste, so we can do different behavior. |
965 model()->on_paste(); | 969 model()->on_paste(); |
966 // Force a Paste operation to trigger the text_changed code in | 970 // Force a Paste operation to trigger the text_changed code in |
967 // OnAfterPossibleChange(), even if identical contents are pasted into the | 971 // OnAfterPossibleChange(), even if identical contents are pasted into the |
968 // text box. | 972 // text box. |
969 text_before_change_.clear(); | 973 text_before_change_.clear(); |
970 textfield_->ReplaceSelection(text); | 974 textfield_->ReplaceSelection(text); |
971 } | 975 } |
972 } | 976 } |
OLD | NEW |