Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: chrome/browser/ui/views/location_bar/location_bar_view.cc

Issue 6256010: Revert 72380 - Remove wstring from autocomplete.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:mergeinfo
OLDNEW
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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 440
441 // Start by reserving the padding at the right edge. 441 // Start by reserving the padding at the right edge.
442 int entry_width = width() - kEdgeThickness - kEdgeItemPadding; 442 int entry_width = width() - kEdgeThickness - kEdgeItemPadding;
443 443
444 // |location_icon_view_| is visible except when |ev_bubble_view_| or 444 // |location_icon_view_| is visible except when |ev_bubble_view_| or
445 // |selected_keyword_view_| are visible. 445 // |selected_keyword_view_| are visible.
446 int location_icon_width = 0; 446 int location_icon_width = 0;
447 int ev_bubble_width = 0; 447 int ev_bubble_width = 0;
448 location_icon_view_->SetVisible(false); 448 location_icon_view_->SetVisible(false);
449 ev_bubble_view_->SetVisible(false); 449 ev_bubble_view_->SetVisible(false);
450 const string16 keyword(location_entry_->model()->keyword()); 450 const std::wstring keyword(location_entry_->model()->keyword());
451 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint()); 451 const bool is_keyword_hint(location_entry_->model()->is_keyword_hint());
452 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint; 452 const bool show_selected_keyword = !keyword.empty() && !is_keyword_hint;
453 if (show_selected_keyword) { 453 if (show_selected_keyword) {
454 // Assume the keyword might be hidden. 454 // Assume the keyword might be hidden.
455 entry_width -= (kEdgeThickness + kEdgeEditPadding); 455 entry_width -= (kEdgeThickness + kEdgeEditPadding);
456 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) { 456 } else if (model_->GetSecurityLevel() == ToolbarModel::EV_SECURE) {
457 ev_bubble_view_->SetVisible(true); 457 ev_bubble_view_->SetVisible(true);
458 ev_bubble_view_->SetLabel(model_->GetEVCertName()); 458 ev_bubble_view_->SetLabel(model_->GetEVCertName());
459 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width(); 459 ev_bubble_width = ev_bubble_view_->GetPreferredSize().width();
460 // We'll adjust this width and take it out of |entry_width| below. 460 // We'll adjust this width and take it out of |entry_width| below.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 return; 509 return;
510 const int available_width = AvailableWidth(max_edit_width); 510 const int available_width = AvailableWidth(max_edit_width);
511 511
512 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint; 512 const bool show_keyword_hint = !keyword.empty() && is_keyword_hint;
513 selected_keyword_view_->SetVisible(show_selected_keyword); 513 selected_keyword_view_->SetVisible(show_selected_keyword);
514 keyword_hint_view_->SetVisible(show_keyword_hint); 514 keyword_hint_view_->SetVisible(show_keyword_hint);
515 if (show_selected_keyword) { 515 if (show_selected_keyword) {
516 if (selected_keyword_view_->keyword() != keyword) { 516 if (selected_keyword_view_->keyword() != keyword) {
517 selected_keyword_view_->SetKeyword(keyword); 517 selected_keyword_view_->SetKeyword(keyword);
518 const TemplateURL* template_url = 518 const TemplateURL* template_url =
519 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); 519 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(
520 WideToUTF16Hack(keyword));
520 if (template_url && template_url->IsExtensionKeyword()) { 521 if (template_url && template_url->IsExtensionKeyword()) {
521 const SkBitmap& bitmap = profile_->GetExtensionService()-> 522 const SkBitmap& bitmap = profile_->GetExtensionService()->
522 GetOmniboxIcon(template_url->GetExtensionId()); 523 GetOmniboxIcon(template_url->GetExtensionId());
523 selected_keyword_view_->SetImage(bitmap); 524 selected_keyword_view_->SetImage(bitmap);
524 selected_keyword_view_->SetItemPadding(kExtensionItemPadding); 525 selected_keyword_view_->SetItemPadding(kExtensionItemPadding);
525 } else { 526 } else {
526 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance(). 527 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance().
527 GetBitmapNamed(IDR_OMNIBOX_SEARCH)); 528 GetBitmapNamed(IDR_OMNIBOX_SEARCH));
528 selected_keyword_view_->SetItemPadding(kItemPadding); 529 selected_keyword_view_->SetItemPadding(kItemPadding);
529 } 530 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
761 762
762 InstantController* instant = delegate_->GetInstant(); 763 InstantController* instant = delegate_->GetInstant();
763 if (instant) 764 if (instant)
764 instant->OnAutocompleteLostFocus(view_gaining_focus); 765 instant->OnAutocompleteLostFocus(view_gaining_focus);
765 } 766 }
766 767
767 void LocationBarView::OnAutocompleteWillAccept() { 768 void LocationBarView::OnAutocompleteWillAccept() {
768 update_instant_ = false; 769 update_instant_ = false;
769 } 770 }
770 771
771 bool LocationBarView::OnCommitSuggestedText(const string16& typed_text) { 772 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) {
772 InstantController* instant = delegate_->GetInstant(); 773 InstantController* instant = delegate_->GetInstant();
773 if (!instant) 774 if (!instant)
774 return false; 775 return false;
775 string16 suggestion; 776 std::wstring suggestion;
776 #if defined(OS_WIN) 777 #if defined(OS_WIN)
777 if (!HasValidSuggestText()) 778 if (!HasValidSuggestText())
778 return false; 779 return false;
779 suggestion = suggested_text_view_->GetText(); 780 suggestion = suggested_text_view_->GetText();
780 #endif 781 #endif
781 return location_entry_->CommitInstantSuggestion(typed_text, suggestion); 782 return location_entry_->CommitInstantSuggestion(typed_text, suggestion);
782 } 783 }
783 784
784 bool LocationBarView::AcceptCurrentInstantPreview() { 785 bool LocationBarView::AcceptCurrentInstantPreview() {
785 return InstantController::CommitIfCurrent(delegate_->GetInstant()); 786 return InstantController::CommitIfCurrent(delegate_->GetInstant());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
841 842
842 // TODO(sky): code for updating instant is nearly identical on all platforms. 843 // TODO(sky): code for updating instant is nearly identical on all platforms.
843 // It sould be pushed to a common place. 844 // It sould be pushed to a common place.
844 InstantController* instant = delegate_->GetInstant(); 845 InstantController* instant = delegate_->GetInstant();
845 string16 suggested_text; 846 string16 suggested_text;
846 if (update_instant_ && instant && GetTabContentsWrapper()) { 847 if (update_instant_ && instant && GetTabContentsWrapper()) {
847 if (location_entry_->model()->user_input_in_progress() && 848 if (location_entry_->model()->user_input_in_progress() &&
848 location_entry_->model()->popup_model()->IsOpen()) { 849 location_entry_->model()->popup_model()->IsOpen()) {
849 instant->Update(GetTabContentsWrapper(), 850 instant->Update(GetTabContentsWrapper(),
850 location_entry_->model()->CurrentMatch(), 851 location_entry_->model()->CurrentMatch(),
851 location_entry_->GetText(), 852 WideToUTF16(location_entry_->GetText()),
852 location_entry_->model()->UseVerbatimInstant(), 853 location_entry_->model()->UseVerbatimInstant(),
853 &suggested_text); 854 &suggested_text);
854 if (!instant->MightSupportInstant()) { 855 if (!instant->MightSupportInstant()) {
855 location_entry_->model()->FinalizeInstantQuery(string16(), 856 location_entry_->model()->FinalizeInstantQuery(std::wstring(),
856 string16()); 857 std::wstring());
857 } 858 }
858 } else { 859 } else {
859 instant->DestroyPreviewContents(); 860 instant->DestroyPreviewContents();
860 location_entry_->model()->FinalizeInstantQuery(string16(), 861 location_entry_->model()->FinalizeInstantQuery(std::wstring(),
861 string16()); 862 std::wstring());
862 } 863 }
863 } 864 }
864 865
865 SetSuggestedText(suggested_text); 866 SetSuggestedText(suggested_text);
866 } 867 }
867 868
868 void LocationBarView::OnSelectionBoundsChanged() { 869 void LocationBarView::OnSelectionBoundsChanged() {
869 #if defined(OS_WIN) 870 #if defined(OS_WIN)
870 if (suggested_text_view_) 871 if (suggested_text_view_)
871 suggested_text_view_->StopAnimation(); 872 suggested_text_view_->StopAnimation();
(...skipping 15 matching lines...) Expand all
887 NOTREACHED(); 888 NOTREACHED();
888 return; 889 return;
889 } 890 }
890 focus_manager->SetFocusedView(this); 891 focus_manager->SetFocusedView(this);
891 } 892 }
892 893
893 SkBitmap LocationBarView::GetFavIcon() const { 894 SkBitmap LocationBarView::GetFavIcon() const {
894 return GetTabContentsFromDelegate(delegate_)->GetFavIcon(); 895 return GetTabContentsFromDelegate(delegate_)->GetFavIcon();
895 } 896 }
896 897
897 string16 LocationBarView::GetTitle() const { 898 std::wstring LocationBarView::GetTitle() const {
898 return GetTabContentsFromDelegate(delegate_)->GetTitle(); 899 return UTF16ToWideHack(GetTabContentsFromDelegate(delegate_)->GetTitle());
899 } 900 }
900 901
901 int LocationBarView::AvailableWidth(int location_bar_width) { 902 int LocationBarView::AvailableWidth(int location_bar_width) {
902 return location_bar_width - location_entry_->TextWidth(); 903 return location_bar_width - location_entry_->TextWidth();
903 } 904 }
904 905
905 void LocationBarView::LayoutView(views::View* view, 906 void LocationBarView::LayoutView(views::View* view,
906 int padding, 907 int padding,
907 int available_width, 908 int available_width,
908 bool leading, 909 bool leading,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1122 1123
1123 void LocationBarView::SetSuggestedText(const string16& input) { 1124 void LocationBarView::SetSuggestedText(const string16& input) {
1124 if (CommandLine::ForCurrentProcess()->HasSwitch( 1125 if (CommandLine::ForCurrentProcess()->HasSwitch(
1125 switches::kInstantAutocompleteImmediately)) { 1126 switches::kInstantAutocompleteImmediately)) {
1126 // This method is internally invoked to reset suggest text, so we only do 1127 // This method is internally invoked to reset suggest text, so we only do
1127 // anything if the text isn't empty. 1128 // anything if the text isn't empty.
1128 // TODO: if we keep autocomplete, make it so this isn't invoked with empty 1129 // TODO: if we keep autocomplete, make it so this isn't invoked with empty
1129 // text. 1130 // text.
1130 if (!input.empty()) { 1131 if (!input.empty()) {
1131 location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), 1132 location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(),
1132 input); 1133 UTF16ToWide(input));
1133 } 1134 }
1134 return; 1135 return;
1135 } 1136 }
1136 #if defined(OS_WIN) 1137 #if defined(OS_WIN)
1137 // Don't show the suggested text if inline autocomplete is prevented. 1138 // Don't show the suggested text if inline autocomplete is prevented.
1138 string16 text = location_entry_->model()->UseVerbatimInstant() ? 1139 string16 text = location_entry_->model()->UseVerbatimInstant() ?
1139 string16() : input; 1140 string16() : input;
1140 if (!text.empty()) { 1141 if (!text.empty()) {
1141 if (!suggested_text_view_) { 1142 if (!suggested_text_view_) {
1142 suggested_text_view_ = new SuggestedTextView(this); 1143 suggested_text_view_ = new SuggestedTextView(this);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1255 template_url_model_ = NULL; 1256 template_url_model_ = NULL;
1256 ShowFirstRunBubble(bubble_type_); 1257 ShowFirstRunBubble(bubble_type_);
1257 } 1258 }
1258 1259
1259 #if defined(OS_WIN) 1260 #if defined(OS_WIN)
1260 bool LocationBarView::HasValidSuggestText() { 1261 bool LocationBarView::HasValidSuggestText() {
1261 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1262 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1262 !suggested_text_view_->GetText().empty(); 1263 !suggested_text_view_->GetText().empty();
1263 } 1264 }
1264 #endif 1265 #endif
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/location_bar/location_bar_view.h ('k') | chrome/browser/ui/views/location_bar/selected_keyword_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698