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

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

Issue 6685002: Wires up ability for page to specify instant auto complete (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix unit test and stray char Created 9 years, 9 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
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 373 matching lines...) Expand 10 before | Expand all | Expand 10 after
384 gfx::Point origin(location_entry_view_->bounds().origin()); 384 gfx::Point origin(location_entry_view_->bounds().origin());
385 // If the UI layout is RTL, the coordinate system is not transformed and 385 // If the UI layout is RTL, the coordinate system is not transformed and
386 // therefore we need to adjust the X coordinate so that bubble appears on the 386 // therefore we need to adjust the X coordinate so that bubble appears on the
387 // right hand side of the location bar. 387 // right hand side of the location bar.
388 if (base::i18n::IsRTL()) 388 if (base::i18n::IsRTL())
389 origin.set_x(width() - origin.x()); 389 origin.set_x(width() - origin.x());
390 views::View::ConvertPointToScreen(this, &origin); 390 views::View::ConvertPointToScreen(this, &origin);
391 return origin; 391 return origin;
392 } 392 }
393 393
394 #if defined(OS_WIN)
395 void LocationBarView::SetInstantSuggestion(const string16& text,
396 bool animate_to_complete) {
397 // Don't show the suggested text if inline autocomplete is prevented.
398 if (!text.empty()) {
399 if (!suggested_text_view_) {
400 suggested_text_view_ = new SuggestedTextView(location_entry_->model());
401 suggested_text_view_->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
402 suggested_text_view_->SetColor(
403 GetColor(ToolbarModel::NONE,
404 LocationBarView::DEEMPHASIZED_TEXT));
405 suggested_text_view_->SetText(UTF16ToWide(text));
406 suggested_text_view_->SetFont(location_entry_->GetFont());
407 AddChildView(suggested_text_view_);
408 } else if (suggested_text_view_->GetText() != UTF16ToWide(text)) {
409 suggested_text_view_->SetText(UTF16ToWide(text));
410 }
411 if (animate_to_complete && !location_entry_->IsImeComposing())
412 suggested_text_view_->StartAnimation();
413 } else if (suggested_text_view_) {
414 delete suggested_text_view_;
415 suggested_text_view_ = NULL;
416 } else {
417 return;
418 }
419
420 Layout();
421 SchedulePaint();
422 }
423
394 string16 LocationBarView::GetInstantSuggestion() const { 424 string16 LocationBarView::GetInstantSuggestion() const {
395 #if defined(OS_WIN)
396 return HasValidSuggestText() ? suggested_text_view_->GetText() : string16(); 425 return HasValidSuggestText() ? suggested_text_view_->GetText() : string16();
397 #else 426 }
398 // On linux the edit shows the suggested text.
399 NOTREACHED();
400 return string16();
401 #endif 427 #endif
402 }
403 428
404 gfx::Size LocationBarView::GetPreferredSize() { 429 gfx::Size LocationBarView::GetPreferredSize() {
405 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ? 430 return gfx::Size(0, GetThemeProvider()->GetBitmapNamed(mode_ == POPUP ?
406 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height()); 431 IDR_LOCATIONBG_POPUPMODE_CENTER : IDR_LOCATIONBG_C)->height());
407 } 432 }
408 433
409 void LocationBarView::Layout() { 434 void LocationBarView::Layout() {
410 if (!location_entry_.get()) 435 if (!location_entry_.get())
411 return; 436 return;
412 437
(...skipping 642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1055 if (!profile_->GetTemplateURLModel()->loaded()) { 1080 if (!profile_->GetTemplateURLModel()->loaded()) {
1056 bubble_type_ = bubble_type; 1081 bubble_type_ = bubble_type;
1057 template_url_model_ = profile_->GetTemplateURLModel(); 1082 template_url_model_ = profile_->GetTemplateURLModel();
1058 template_url_model_->AddObserver(this); 1083 template_url_model_->AddObserver(this);
1059 template_url_model_->Load(); 1084 template_url_model_->Load();
1060 return; 1085 return;
1061 } 1086 }
1062 ShowFirstRunBubbleInternal(bubble_type); 1087 ShowFirstRunBubbleInternal(bubble_type);
1063 } 1088 }
1064 1089
1065 void LocationBarView::SetSuggestedText(const string16& text) { 1090 void LocationBarView::SetSuggestedText(const string16& text,
1066 location_entry_->model()->SetSuggestedText(text); 1091 InstantCompleteBehavior behavior) {
1092 location_entry_->model()->SetSuggestedText(text, behavior);
1067 } 1093 }
1068 1094
1069 std::wstring LocationBarView::GetInputString() const { 1095 std::wstring LocationBarView::GetInputString() const {
1070 return location_input_; 1096 return location_input_;
1071 } 1097 }
1072 1098
1073 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const { 1099 WindowOpenDisposition LocationBarView::GetWindowOpenDisposition() const {
1074 return disposition_; 1100 return disposition_;
1075 } 1101 }
1076 1102
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1171 template_url_model_ = NULL; 1197 template_url_model_ = NULL;
1172 ShowFirstRunBubble(bubble_type_); 1198 ShowFirstRunBubble(bubble_type_);
1173 } 1199 }
1174 1200
1175 #if defined(OS_WIN) 1201 #if defined(OS_WIN)
1176 bool LocationBarView::HasValidSuggestText() const { 1202 bool LocationBarView::HasValidSuggestText() const {
1177 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() && 1203 return suggested_text_view_ && !suggested_text_view_->size().IsEmpty() &&
1178 !suggested_text_view_->GetText().empty(); 1204 !suggested_text_view_->GetText().empty();
1179 } 1205 }
1180 #endif 1206 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698