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

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

Issue 6306011: Remove wstring from autocomplete. (Closed) Base URL: svn://chrome-svn/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:
Deleted: 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 std::wstring keyword(location_entry_->model()->keyword()); 450 const string16 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( 519 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword);
520 WideToUTF16Hack(keyword));
521 if (template_url && template_url->IsExtensionKeyword()) { 520 if (template_url && template_url->IsExtensionKeyword()) {
522 const SkBitmap& bitmap = profile_->GetExtensionService()-> 521 const SkBitmap& bitmap = profile_->GetExtensionService()->
523 GetOmniboxIcon(template_url->GetExtensionId()); 522 GetOmniboxIcon(template_url->GetExtensionId());
524 selected_keyword_view_->SetImage(bitmap); 523 selected_keyword_view_->SetImage(bitmap);
525 selected_keyword_view_->SetItemPadding(kExtensionItemPadding); 524 selected_keyword_view_->SetItemPadding(kExtensionItemPadding);
526 } else { 525 } else {
527 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance(). 526 selected_keyword_view_->SetImage(*ResourceBundle::GetSharedInstance().
528 GetBitmapNamed(IDR_OMNIBOX_SEARCH)); 527 GetBitmapNamed(IDR_OMNIBOX_SEARCH));
529 selected_keyword_view_->SetItemPadding(kItemPadding); 528 selected_keyword_view_->SetItemPadding(kItemPadding);
530 } 529 }
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 761
763 InstantController* instant = delegate_->GetInstant(); 762 InstantController* instant = delegate_->GetInstant();
764 if (instant) 763 if (instant)
765 instant->OnAutocompleteLostFocus(view_gaining_focus); 764 instant->OnAutocompleteLostFocus(view_gaining_focus);
766 } 765 }
767 766
768 void LocationBarView::OnAutocompleteWillAccept() { 767 void LocationBarView::OnAutocompleteWillAccept() {
769 update_instant_ = false; 768 update_instant_ = false;
770 } 769 }
771 770
772 bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { 771 bool LocationBarView::OnCommitSuggestedText(const string16& typed_text) {
773 InstantController* instant = delegate_->GetInstant(); 772 InstantController* instant = delegate_->GetInstant();
774 if (!instant) 773 if (!instant)
775 return false; 774 return false;
776 std::wstring suggestion; 775 string16 suggestion;
777 #if defined(OS_WIN) 776 #if defined(OS_WIN)
778 if (!HasValidSuggestText()) 777 if (!HasValidSuggestText())
779 return false; 778 return false;
780 suggestion = suggested_text_view_->GetText(); 779 suggestion = suggested_text_view_->GetText();
781 #endif 780 #endif
782 return location_entry_->CommitInstantSuggestion(typed_text, suggestion); 781 return location_entry_->CommitInstantSuggestion(typed_text, suggestion);
783 } 782 }
784 783
785 bool LocationBarView::AcceptCurrentInstantPreview() { 784 bool LocationBarView::AcceptCurrentInstantPreview() {
786 return InstantController::CommitIfCurrent(delegate_->GetInstant()); 785 return InstantController::CommitIfCurrent(delegate_->GetInstant());
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 841
843 // TODO(sky): code for updating instant is nearly identical on all platforms. 842 // TODO(sky): code for updating instant is nearly identical on all platforms.
844 // It sould be pushed to a common place. 843 // It sould be pushed to a common place.
845 InstantController* instant = delegate_->GetInstant(); 844 InstantController* instant = delegate_->GetInstant();
846 string16 suggested_text; 845 string16 suggested_text;
847 if (update_instant_ && instant && GetTabContentsWrapper()) { 846 if (update_instant_ && instant && GetTabContentsWrapper()) {
848 if (location_entry_->model()->user_input_in_progress() && 847 if (location_entry_->model()->user_input_in_progress() &&
849 location_entry_->model()->popup_model()->IsOpen()) { 848 location_entry_->model()->popup_model()->IsOpen()) {
850 instant->Update(GetTabContentsWrapper(), 849 instant->Update(GetTabContentsWrapper(),
851 location_entry_->model()->CurrentMatch(), 850 location_entry_->model()->CurrentMatch(),
852 WideToUTF16(location_entry_->GetText()), 851 location_entry_->GetText(),
853 location_entry_->model()->UseVerbatimInstant(), 852 location_entry_->model()->UseVerbatimInstant(),
854 &suggested_text); 853 &suggested_text);
855 if (!instant->MightSupportInstant()) { 854 if (!instant->MightSupportInstant()) {
856 location_entry_->model()->FinalizeInstantQuery(std::wstring(), 855 location_entry_->model()->FinalizeInstantQuery(string16(),
857 std::wstring()); 856 string16());
858 } 857 }
859 } else { 858 } else {
860 instant->DestroyPreviewContents(); 859 instant->DestroyPreviewContents();
861 location_entry_->model()->FinalizeInstantQuery(std::wstring(), 860 location_entry_->model()->FinalizeInstantQuery(string16(),
862 std::wstring()); 861 string16());
863 } 862 }
864 } 863 }
865 864
866 SetSuggestedText(suggested_text); 865 SetSuggestedText(suggested_text);
867 } 866 }
868 867
869 void LocationBarView::OnSelectionBoundsChanged() { 868 void LocationBarView::OnSelectionBoundsChanged() {
870 #if defined(OS_WIN) 869 #if defined(OS_WIN)
871 if (suggested_text_view_) 870 if (suggested_text_view_)
872 suggested_text_view_->StopAnimation(); 871 suggested_text_view_->StopAnimation();
(...skipping 15 matching lines...) Expand all
888 NOTREACHED(); 887 NOTREACHED();
889 return; 888 return;
890 } 889 }
891 focus_manager->SetFocusedView(this); 890 focus_manager->SetFocusedView(this);
892 } 891 }
893 892
894 SkBitmap LocationBarView::GetFavIcon() const { 893 SkBitmap LocationBarView::GetFavIcon() const {
895 return GetTabContentsFromDelegate(delegate_)->GetFavIcon(); 894 return GetTabContentsFromDelegate(delegate_)->GetFavIcon();
896 } 895 }
897 896
898 std::wstring LocationBarView::GetTitle() const { 897 string16 LocationBarView::GetTitle() const {
899 return UTF16ToWideHack(GetTabContentsFromDelegate(delegate_)->GetTitle()); 898 return GetTabContentsFromDelegate(delegate_)->GetTitle();
900 } 899 }
901 900
902 int LocationBarView::AvailableWidth(int location_bar_width) { 901 int LocationBarView::AvailableWidth(int location_bar_width) {
903 return location_bar_width - location_entry_->TextWidth(); 902 return location_bar_width - location_entry_->TextWidth();
904 } 903 }
905 904
906 void LocationBarView::LayoutView(views::View* view, 905 void LocationBarView::LayoutView(views::View* view,
907 int padding, 906 int padding,
908 int available_width, 907 int available_width,
909 bool leading, 908 bool leading,
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 1122
1124 void LocationBarView::SetSuggestedText(const string16& input) { 1123 void LocationBarView::SetSuggestedText(const string16& input) {
1125 if (CommandLine::ForCurrentProcess()->HasSwitch( 1124 if (CommandLine::ForCurrentProcess()->HasSwitch(
1126 switches::kInstantAutocompleteImmediately)) { 1125 switches::kInstantAutocompleteImmediately)) {
1127 // This method is internally invoked to reset suggest text, so we only do 1126 // This method is internally invoked to reset suggest text, so we only do
1128 // anything if the text isn't empty. 1127 // anything if the text isn't empty.
1129 // TODO: if we keep autocomplete, make it so this isn't invoked with empty 1128 // TODO: if we keep autocomplete, make it so this isn't invoked with empty
1130 // text. 1129 // text.
1131 if (!input.empty()) { 1130 if (!input.empty()) {
1132 location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(), 1131 location_entry_->model()->FinalizeInstantQuery(location_entry_->GetText(),
1133 UTF16ToWide(input)); 1132 input);
1134 } 1133 }
1135 return; 1134 return;
1136 } 1135 }
1137 #if defined(OS_WIN) 1136 #if defined(OS_WIN)
1138 // Don't show the suggested text if inline autocomplete is prevented. 1137 // Don't show the suggested text if inline autocomplete is prevented.
1139 string16 text = location_entry_->model()->UseVerbatimInstant() ? 1138 string16 text = location_entry_->model()->UseVerbatimInstant() ?
1140 string16() : input; 1139 string16() : input;
1141 if (!text.empty()) { 1140 if (!text.empty()) {
1142 if (!suggested_text_view_) { 1141 if (!suggested_text_view_) {
1143 suggested_text_view_ = new SuggestedTextView(this); 1142 suggested_text_view_ = new SuggestedTextView(this);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
1256 template_url_model_ = NULL; 1255 template_url_model_ = NULL;
1257 ShowFirstRunBubble(bubble_type_); 1256 ShowFirstRunBubble(bubble_type_);
1258 } 1257 }
1259 1258
1260 #if defined(OS_WIN) 1259 #if defined(OS_WIN)
1261 bool LocationBarView::HasValidSuggestText() { 1260 bool LocationBarView::HasValidSuggestText() {
1262 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1261 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1263 !suggested_text_view_->GetText().empty(); 1262 !suggested_text_view_->GetText().empty();
1264 } 1263 }
1265 #endif 1264 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698