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

Side by Side Diff: chrome/browser/instant/instant_controller.cc

Issue 12047107: Change the SearchBox API from using the start/end margins of the location bar to using the start ma… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplified LocationBarView::OnBoundsChanged Created 7 years, 10 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 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/instant/instant_controller.h" 5 #include "chrome/browser/instant/instant_controller.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/metrics/histogram.h" 8 #include "base/metrics/histogram.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
196 : browser_(browser), 196 : browser_(browser),
197 extended_enabled_(extended_enabled), 197 extended_enabled_(extended_enabled),
198 instant_enabled_(false), 198 instant_enabled_(false),
199 use_local_preview_only_(true), 199 use_local_preview_only_(true),
200 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 200 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
201 last_omnibox_text_has_inline_autocompletion_(false), 201 last_omnibox_text_has_inline_autocompletion_(false),
202 last_verbatim_(false), 202 last_verbatim_(false),
203 last_transition_type_(content::PAGE_TRANSITION_LINK), 203 last_transition_type_(content::PAGE_TRANSITION_LINK),
204 last_match_was_search_(false), 204 last_match_was_search_(false),
205 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 205 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
206 start_margin_(0), 206 omnibox_start_margin_(0),
207 end_margin_(0), 207 omnibox_width_(0),
208 allow_preview_to_show_search_suggestions_(false), 208 allow_preview_to_show_search_suggestions_(false),
209 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 209 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
210 } 210 }
211 211
212 InstantController::~InstantController() { 212 InstantController::~InstantController() {
213 } 213 }
214 214
215 bool InstantController::Update(const AutocompleteMatch& match, 215 bool InstantController::Update(const AutocompleteMatch& match,
216 const string16& user_text, 216 const string16& user_text,
217 const string16& full_text, 217 const string16& full_text,
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
460 if (popup_bounds_.height() > last_popup_bounds_.height()) { 460 if (popup_bounds_.height() > last_popup_bounds_.height()) {
461 update_bounds_timer_.Stop(); 461 update_bounds_timer_.Stop();
462 SendPopupBoundsToPage(); 462 SendPopupBoundsToPage();
463 } else if (!update_bounds_timer_.IsRunning()) { 463 } else if (!update_bounds_timer_.IsRunning()) {
464 update_bounds_timer_.Start(FROM_HERE, 464 update_bounds_timer_.Start(FROM_HERE,
465 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 465 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
466 &InstantController::SendPopupBoundsToPage); 466 &InstantController::SendPopupBoundsToPage);
467 } 467 }
468 } 468 }
469 469
470 void InstantController::SetMarginSize(int start, int end) { 470 void InstantController::SetStartMarginAndWidth(int margin, int width) {
471 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) 471 if (!extended_enabled_ ||
472 (omnibox_start_margin_ == margin && omnibox_width_ == width))
472 return; 473 return;
473 474
474 start_margin_ = start; 475 omnibox_start_margin_ = margin;
475 end_margin_ = end; 476 omnibox_width_ = width;
476 if (overlay_) 477 if (overlay_)
477 overlay_->SetMarginSize(start_margin_, end_margin_); 478 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
478 if (ntp_) 479 if (ntp_)
479 ntp_->SetMarginSize(start_margin_, end_margin_); 480 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
480 if (instant_tab_) 481 if (instant_tab_)
481 instant_tab_->SetMarginSize(start_margin_, end_margin_); 482 instant_tab_->SetStartMarginAndWidth(margin, width);
482 } 483 }
483 484
484 void InstantController::HandleAutocompleteResults( 485 void InstantController::HandleAutocompleteResults(
485 const std::vector<AutocompleteProvider*>& providers) { 486 const std::vector<AutocompleteProvider*>& providers) {
486 if (!extended_enabled_) 487 if (!extended_enabled_)
487 return; 488 return;
488 489
489 if (!instant_tab_ && !overlay_) 490 if (!instant_tab_ && !overlay_)
490 return; 491 return;
491 492
(...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after
889 return; 890 return;
890 891
891 // Update theme info so that the page picks it up. 892 // Update theme info so that the page picks it up.
892 browser_->UpdateThemeInfo(false); 893 browser_->UpdateThemeInfo(false);
893 894
894 // Ensure the searchbox API has the correct initial state. 895 // Ensure the searchbox API has the correct initial state.
895 if (IsContentsFrom(overlay(), contents)) { 896 if (IsContentsFrom(overlay(), contents)) {
896 overlay_->SetDisplayInstantResults(instant_enabled_); 897 overlay_->SetDisplayInstantResults(instant_enabled_);
897 overlay_->KeyCaptureChanged( 898 overlay_->KeyCaptureChanged(
898 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 899 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
899 overlay_->SetMarginSize(start_margin_, end_margin_); 900 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
900 overlay_->InitializeFonts(); 901 overlay_->InitializeFonts();
901 } else if (IsContentsFrom(ntp(), contents)) { 902 } else if (IsContentsFrom(ntp(), contents)) {
902 ntp_->SetDisplayInstantResults(instant_enabled_); 903 ntp_->SetDisplayInstantResults(instant_enabled_);
903 ntp_->SetMarginSize(start_margin_, end_margin_); 904 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
904 ntp_->InitializeFonts(); 905 ntp_->InitializeFonts();
905 } else { 906 } else {
906 NOTREACHED(); 907 NOTREACHED();
907 } 908 }
908 StartListeningToMostVisitedChanges(); 909 StartListeningToMostVisitedChanges();
909 } 910 }
910 911
911 void InstantController::InstantSupportDetermined( 912 void InstantController::InstantSupportDetermined(
912 const content::WebContents* contents, 913 const content::WebContents* contents,
913 bool supports_instant) { 914 bool supports_instant) {
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
1209 // Do not wire up the InstantTab if instant should only use local previews, to 1210 // Do not wire up the InstantTab if instant should only use local previews, to
1210 // prevent it from sending data to the page. 1211 // prevent it from sending data to the page.
1211 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { 1212 if (!search_mode_.is_origin_default() && !use_local_preview_only_) {
1212 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1213 content::WebContents* active_tab = browser_->GetActiveWebContents();
1213 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1214 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1214 instant_tab_.reset(new InstantTab(this)); 1215 instant_tab_.reset(new InstantTab(this));
1215 instant_tab_->Init(active_tab); 1216 instant_tab_->Init(active_tab);
1216 // Update theme info for this tab. 1217 // Update theme info for this tab.
1217 browser_->UpdateThemeInfo(false); 1218 browser_->UpdateThemeInfo(false);
1218 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1219 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1219 instant_tab_->SetMarginSize(start_margin_, end_margin_); 1220 instant_tab_->SetStartMarginAndWidth(
1221 omnibox_start_margin_, omnibox_width_);
1220 instant_tab_->InitializeFonts(); 1222 instant_tab_->InitializeFonts();
1221 StartListeningToMostVisitedChanges(); 1223 StartListeningToMostVisitedChanges();
1222 instant_tab_->KeyCaptureChanged( 1224 instant_tab_->KeyCaptureChanged(
1223 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 1225 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
1224 } 1226 }
1225 1227
1226 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1228 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1227 HideOverlay(); 1229 HideOverlay();
1228 } else { 1230 } else {
1229 instant_tab_.reset(); 1231 instant_tab_.reset();
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 overlay_->SendMostVisitedItems(items); 1510 overlay_->SendMostVisitedItems(items);
1509 if (ntp_) 1511 if (ntp_)
1510 ntp_->SendMostVisitedItems(items); 1512 ntp_->SendMostVisitedItems(items);
1511 if (instant_tab_) 1513 if (instant_tab_)
1512 instant_tab_->SendMostVisitedItems(items); 1514 instant_tab_->SendMostVisitedItems(items);
1513 content::NotificationService::current()->Notify( 1515 content::NotificationService::current()->Notify(
1514 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, 1516 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS,
1515 content::Source<InstantController>(this), 1517 content::Source<InstantController>(this),
1516 content::NotificationService::NoDetails()); 1518 content::NotificationService::NoDetails());
1517 } 1519 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698