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