OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/location_bar/location_bar_view.h" | 5 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
6 | 6 |
7 #if defined(OS_LINUX) | 7 #if defined(OS_LINUX) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
392 gfx::Point origin(location_entry_view_->bounds().origin()); | 392 gfx::Point origin(location_entry_view_->bounds().origin()); |
393 // If the UI layout is RTL, the coordinate system is not transformed and | 393 // If the UI layout is RTL, the coordinate system is not transformed and |
394 // therefore we need to adjust the X coordinate so that bubble appears on the | 394 // therefore we need to adjust the X coordinate so that bubble appears on the |
395 // right hand side of the location bar. | 395 // right hand side of the location bar. |
396 if (base::i18n::IsRTL()) | 396 if (base::i18n::IsRTL()) |
397 origin.set_x(width() - origin.x()); | 397 origin.set_x(width() - origin.x()); |
398 views::View::ConvertPointToScreen(this, &origin); | 398 views::View::ConvertPointToScreen(this, &origin); |
399 return origin; | 399 return origin; |
400 } | 400 } |
401 | 401 |
402 #if defined(OS_WIN) | |
403 void LocationBarView::OnCommitSuggestedText() { | |
404 InstantController* instant = delegate_->GetInstant(); | |
405 DCHECK(instant); | |
406 DCHECK(suggested_text_view_); | |
407 OnCommitSuggestedText(location_entry_->GetText()); | |
408 } | |
409 #endif | |
410 | |
411 gfx::Size LocationBarView::GetPreferredSize() { | 402 gfx::Size LocationBarView::GetPreferredSize() { |
412 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? | 403 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? |
413 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); | 404 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); |
414 } | 405 } |
415 | 406 |
416 void LocationBarView::Layout() { | 407 void LocationBarView::Layout() { |
417 if (!location_entry_.get()) | 408 if (!location_entry_.get()) |
418 return; | 409 return; |
419 | 410 |
420 // TODO(sky): baseline layout. | 411 // TODO(sky): baseline layout. |
(...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 | 752 |
762 InstantController* instant = delegate_->GetInstant(); | 753 InstantController* instant = delegate_->GetInstant(); |
763 if (instant) | 754 if (instant) |
764 instant->OnAutocompleteLostFocus(view_gaining_focus); | 755 instant->OnAutocompleteLostFocus(view_gaining_focus); |
765 } | 756 } |
766 | 757 |
767 void LocationBarView::OnAutocompleteWillAccept() { | 758 void LocationBarView::OnAutocompleteWillAccept() { |
768 update_instant_ = false; | 759 update_instant_ = false; |
769 } | 760 } |
770 | 761 |
771 bool LocationBarView::OnCommitSuggestedText(const string16& typed_text) { | 762 bool LocationBarView::OnCommitSuggestedText(bool skip_inline_autocomplete) { |
772 InstantController* instant = delegate_->GetInstant(); | 763 if (!delegate_->GetInstant()) |
773 if (!instant) | |
774 return false; | 764 return false; |
| 765 |
775 string16 suggestion; | 766 string16 suggestion; |
776 #if defined(OS_WIN) | 767 #if defined(OS_WIN) |
777 if (!HasValidSuggestText()) | 768 if (HasValidSuggestText()) |
| 769 suggestion = suggested_text_view_->GetText(); |
| 770 #else |
| 771 suggestion = location_entry_->GetInstantSuggestion(); |
| 772 #endif |
| 773 |
| 774 if (suggestion.empty()) |
778 return false; | 775 return false; |
779 suggestion = suggested_text_view_->GetText(); | 776 |
780 #endif | 777 location_entry_->model()->FinalizeInstantQuery( |
781 return location_entry_->CommitInstantSuggestion(typed_text, suggestion); | 778 location_entry_->GetText(), suggestion, skip_inline_autocomplete); |
| 779 return true; |
782 } | 780 } |
783 | 781 |
784 bool LocationBarView::AcceptCurrentInstantPreview() { | 782 bool LocationBarView::AcceptCurrentInstantPreview() { |
785 return InstantController::CommitIfCurrent(delegate_->GetInstant()); | 783 return InstantController::CommitIfCurrent(delegate_->GetInstant()); |
786 } | 784 } |
787 | 785 |
788 void LocationBarView::OnPopupBoundsChanged(const gfx::Rect& bounds) { | 786 void LocationBarView::OnPopupBoundsChanged(const gfx::Rect& bounds) { |
789 InstantController* instant = delegate_->GetInstant(); | 787 InstantController* instant = delegate_->GetInstant(); |
790 if (instant) | 788 if (instant) |
791 instant->SetOmniboxBounds(bounds); | 789 instant->SetOmniboxBounds(bounds); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 string16 suggested_text; | 843 string16 suggested_text; |
846 if (update_instant_ && instant && GetTabContentsWrapper()) { | 844 if (update_instant_ && instant && GetTabContentsWrapper()) { |
847 if (location_entry_->model()->user_input_in_progress() && | 845 if (location_entry_->model()->user_input_in_progress() && |
848 location_entry_->model()->popup_model()->IsOpen()) { | 846 location_entry_->model()->popup_model()->IsOpen()) { |
849 instant->Update(GetTabContentsWrapper(), | 847 instant->Update(GetTabContentsWrapper(), |
850 location_entry_->model()->CurrentMatch(), | 848 location_entry_->model()->CurrentMatch(), |
851 location_entry_->GetText(), | 849 location_entry_->GetText(), |
852 location_entry_->model()->UseVerbatimInstant(), | 850 location_entry_->model()->UseVerbatimInstant(), |
853 &suggested_text); | 851 &suggested_text); |
854 if (!instant->MightSupportInstant()) { | 852 if (!instant->MightSupportInstant()) { |
855 location_entry_->model()->FinalizeInstantQuery(string16(), | 853 location_entry_->model()->FinalizeInstantQuery( |
856 string16()); | 854 string16(), string16(), false); |
857 } | 855 } |
858 } else { | 856 } else { |
859 instant->DestroyPreviewContents(); | 857 instant->DestroyPreviewContents(); |
860 location_entry_->model()->FinalizeInstantQuery(string16(), | 858 location_entry_->model()->FinalizeInstantQuery( |
861 string16()); | 859 string16(), string16(), false); |
862 } | 860 } |
863 } | 861 } |
864 | 862 |
865 SetSuggestedText(suggested_text); | 863 SetSuggestedText(suggested_text); |
866 } | 864 } |
867 | 865 |
868 void LocationBarView::OnSelectionBoundsChanged() { | 866 void LocationBarView::OnSelectionBoundsChanged() { |
869 #if defined(OS_WIN) | 867 #if defined(OS_WIN) |
870 if (suggested_text_view_) | 868 if (suggested_text_view_) |
871 suggested_text_view_->StopAnimation(); | 869 suggested_text_view_->StopAnimation(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1051 if (views::FocusManager::IsTabTraversalKeyEvent(e)) { | 1049 if (views::FocusManager::IsTabTraversalKeyEvent(e)) { |
1052 if (HasValidSuggestText()) { | 1050 if (HasValidSuggestText()) { |
1053 // Return true so that the edit sees the tab and commits the suggestion. | 1051 // Return true so that the edit sees the tab and commits the suggestion. |
1054 return true; | 1052 return true; |
1055 } | 1053 } |
1056 if (keyword_hint_view_->IsVisible() && !e.IsShiftDown()) { | 1054 if (keyword_hint_view_->IsVisible() && !e.IsShiftDown()) { |
1057 // Return true so the edit gets the tab event and enters keyword mode. | 1055 // Return true so the edit gets the tab event and enters keyword mode. |
1058 return true; | 1056 return true; |
1059 } | 1057 } |
1060 | 1058 |
| 1059 // If the caret is not at the end, then tab moves the caret to the end. |
| 1060 if (!location_entry_->IsCaretAtEnd()) |
| 1061 return true; |
| 1062 |
1061 // Tab while showing instant commits instant immediately. | 1063 // Tab while showing instant commits instant immediately. |
1062 // Return true so that focus traversal isn't attempted. The edit ends | 1064 // Return true so that focus traversal isn't attempted. The edit ends |
1063 // up doing nothing in this case. | 1065 // up doing nothing in this case. |
1064 if (AcceptCurrentInstantPreview()) | 1066 if (AcceptCurrentInstantPreview()) |
1065 return true; | 1067 return true; |
1066 } | 1068 } |
1067 | 1069 |
1068 return location_entry_->SkipDefaultKeyEventProcessing(e); | 1070 return location_entry_->SkipDefaultKeyEventProcessing(e); |
1069 #else | 1071 #else |
1070 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in | 1072 // This method is not used for Linux ports. See FocusManager::OnKeyEvent() in |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1121 } | 1123 } |
1122 | 1124 |
1123 void LocationBarView::SetSuggestedText(const string16& input) { | 1125 void LocationBarView::SetSuggestedText(const string16& input) { |
1124 if (CommandLine::ForCurrentProcess()->HasSwitch( | 1126 if (CommandLine::ForCurrentProcess()->HasSwitch( |
1125 switches::kInstantAutocompleteImmediately)) { | 1127 switches::kInstantAutocompleteImmediately)) { |
1126 // This method is internally invoked to reset suggest text, so we only do | 1128 // This method is internally invoked to reset suggest text, so we only do |
1127 // anything if the text isn't empty. | 1129 // anything if the text isn't empty. |
1128 // TODO: if we keep autocomplete, make it so this isn't invoked with empty | 1130 // TODO: if we keep autocomplete, make it so this isn't invoked with empty |
1129 // text. | 1131 // text. |
1130 if (!input.empty()) { | 1132 if (!input.empty()) { |
1131 location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), | 1133 location_entry_->model()->FinalizeInstantQuery( |
1132 input); | 1134 location_entry_->GetText(), input, false); |
1133 } | 1135 } |
1134 return; | 1136 return; |
1135 } | 1137 } |
1136 #if defined(OS_WIN) | 1138 #if defined(OS_WIN) |
1137 // Don't show the suggested text if inline autocomplete is prevented. | 1139 // Don't show the suggested text if inline autocomplete is prevented. |
1138 string16 text = location_entry_->model()->UseVerbatimInstant() ? | 1140 string16 text = location_entry_->model()->UseVerbatimInstant() ? |
1139 string16() : input; | 1141 string16() : input; |
1140 if (!text.empty()) { | 1142 if (!text.empty()) { |
1141 if (!suggested_text_view_) { | 1143 if (!suggested_text_view_) { |
1142 suggested_text_view_ = new SuggestedTextView(this); | 1144 suggested_text_view_ = new SuggestedTextView(this); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1255 template_url_model_ = NULL; | 1257 template_url_model_ = NULL; |
1256 ShowFirstRunBubble(bubble_type_); | 1258 ShowFirstRunBubble(bubble_type_); |
1257 } | 1259 } |
1258 | 1260 |
1259 #if defined(OS_WIN) | 1261 #if defined(OS_WIN) |
1260 bool LocationBarView::HasValidSuggestText() { | 1262 bool LocationBarView::HasValidSuggestText() { |
1261 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && | 1263 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && |
1262 !suggested_text_view_->GetText().empty(); | 1264 !suggested_text_view_->GetText().empty(); |
1263 } | 1265 } |
1264 #endif | 1266 #endif |
OLD | NEW |