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

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: Sync 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 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 : browser_(browser), 194 : browser_(browser),
195 extended_enabled_(extended_enabled), 195 extended_enabled_(extended_enabled),
196 instant_enabled_(false), 196 instant_enabled_(false),
197 use_local_preview_only_(true), 197 use_local_preview_only_(true),
198 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 198 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
199 last_omnibox_text_has_inline_autocompletion_(false), 199 last_omnibox_text_has_inline_autocompletion_(false),
200 last_verbatim_(false), 200 last_verbatim_(false),
201 last_transition_type_(content::PAGE_TRANSITION_LINK), 201 last_transition_type_(content::PAGE_TRANSITION_LINK),
202 last_match_was_search_(false), 202 last_match_was_search_(false),
203 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 203 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
204 start_margin_(0), 204 omnibox_start_margin_(0),
205 end_margin_(0), 205 omnibox_width_(0),
206 allow_preview_to_show_search_suggestions_(false) { 206 allow_preview_to_show_search_suggestions_(false) {
207 } 207 }
208 208
209 InstantController::~InstantController() { 209 InstantController::~InstantController() {
210 } 210 }
211 211
212 bool InstantController::Update(const AutocompleteMatch& match, 212 bool InstantController::Update(const AutocompleteMatch& match,
213 const string16& user_text, 213 const string16& user_text,
214 const string16& full_text, 214 const string16& full_text,
215 size_t selection_start, 215 size_t selection_start,
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
457 if (popup_bounds_.height() > last_popup_bounds_.height()) { 457 if (popup_bounds_.height() > last_popup_bounds_.height()) {
458 update_bounds_timer_.Stop(); 458 update_bounds_timer_.Stop();
459 SendPopupBoundsToPage(); 459 SendPopupBoundsToPage();
460 } else if (!update_bounds_timer_.IsRunning()) { 460 } else if (!update_bounds_timer_.IsRunning()) {
461 update_bounds_timer_.Start(FROM_HERE, 461 update_bounds_timer_.Start(FROM_HERE,
462 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 462 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
463 &InstantController::SendPopupBoundsToPage); 463 &InstantController::SendPopupBoundsToPage);
464 } 464 }
465 } 465 }
466 466
467 void InstantController::SetMarginSize(int start, int end) { 467 void InstantController::SetStartMarginAndWidth(int margin, int width) {
468 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) 468 if (!extended_enabled_ ||
469 (omnibox_start_margin_ == margin && omnibox_width_ == width))
469 return; 470 return;
470 471
471 start_margin_ = start; 472 omnibox_start_margin_ = margin;
472 end_margin_ = end; 473 omnibox_width_ = width;
473 if (overlay_) 474 if (overlay_)
474 overlay_->SetMarginSize(start_margin_, end_margin_); 475 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
475 if (ntp_) 476 if (ntp_)
476 ntp_->SetMarginSize(start_margin_, end_margin_); 477 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
477 if (instant_tab_) 478 if (instant_tab_)
478 instant_tab_->SetMarginSize(start_margin_, end_margin_); 479 instant_tab_->SetStartMarginAndWidth(margin, width);
479 } 480 }
480 481
481 void InstantController::HandleAutocompleteResults( 482 void InstantController::HandleAutocompleteResults(
482 const std::vector<AutocompleteProvider*>& providers) { 483 const std::vector<AutocompleteProvider*>& providers) {
483 if (!extended_enabled_) 484 if (!extended_enabled_)
484 return; 485 return;
485 486
486 if (!instant_tab_ && !overlay_) 487 if (!instant_tab_ && !overlay_)
487 return; 488 return;
488 489
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
855 return; 856 return;
856 857
857 // Update theme info so that the page picks it up. 858 // Update theme info so that the page picks it up.
858 browser_->UpdateThemeInfo(false); 859 browser_->UpdateThemeInfo(false);
859 860
860 // Ensure the searchbox API has the correct initial state. 861 // Ensure the searchbox API has the correct initial state.
861 if (IsContentsFrom(overlay(), contents)) { 862 if (IsContentsFrom(overlay(), contents)) {
862 overlay_->SetDisplayInstantResults(instant_enabled_); 863 overlay_->SetDisplayInstantResults(instant_enabled_);
863 overlay_->KeyCaptureChanged( 864 overlay_->KeyCaptureChanged(
864 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 865 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
865 overlay_->SetMarginSize(start_margin_, end_margin_); 866 overlay_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
866 overlay_->InitializeFonts(); 867 overlay_->InitializeFonts();
867 } else if (IsContentsFrom(ntp(), contents)) { 868 } else if (IsContentsFrom(ntp(), contents)) {
868 ntp_->SetDisplayInstantResults(instant_enabled_); 869 ntp_->SetDisplayInstantResults(instant_enabled_);
869 ntp_->SetMarginSize(start_margin_, end_margin_); 870 ntp_->SetStartMarginAndWidth(omnibox_start_margin_, omnibox_width_);
870 ntp_->InitializeFonts(); 871 ntp_->InitializeFonts();
871 } else { 872 } else {
872 NOTREACHED(); 873 NOTREACHED();
873 } 874 }
874 } 875 }
875 876
876 void InstantController::InstantSupportDetermined( 877 void InstantController::InstantSupportDetermined(
877 const content::WebContents* contents, 878 const content::WebContents* contents,
878 bool supports_instant) { 879 bool supports_instant) {
879 if (IsContentsFrom(instant_tab(), contents)) { 880 if (IsContentsFrom(instant_tab(), contents)) {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1167 // Do not wire up the InstantTab if instant should only use local previews, to 1168 // Do not wire up the InstantTab if instant should only use local previews, to
1168 // prevent it from sending data to the page. 1169 // prevent it from sending data to the page.
1169 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { 1170 if (!search_mode_.is_origin_default() && !use_local_preview_only_) {
1170 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1171 content::WebContents* active_tab = browser_->GetActiveWebContents();
1171 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1172 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1172 instant_tab_.reset(new InstantTab(this)); 1173 instant_tab_.reset(new InstantTab(this));
1173 instant_tab_->Init(active_tab); 1174 instant_tab_->Init(active_tab);
1174 // Update theme info for this tab. 1175 // Update theme info for this tab.
1175 browser_->UpdateThemeInfo(false); 1176 browser_->UpdateThemeInfo(false);
1176 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1177 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1177 instant_tab_->SetMarginSize(start_margin_, end_margin_); 1178 instant_tab_->SetStartMarginAndWidth(
1179 omnibox_start_margin_, omnibox_width_);
1178 instant_tab_->InitializeFonts(); 1180 instant_tab_->InitializeFonts();
1179 instant_tab_->KeyCaptureChanged( 1181 instant_tab_->KeyCaptureChanged(
1180 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 1182 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
1181 } 1183 }
1182 1184
1183 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1185 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1184 HideOverlay(); 1186 HideOverlay();
1185 } else { 1187 } else {
1186 instant_tab_.reset(); 1188 instant_tab_.reset();
1187 } 1189 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1404 delete overlay_->ReleaseContents().release(); 1406 delete overlay_->ReleaseContents().release();
1405 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); 1407 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release());
1406 EnsureOverlayIsCurrent(false); 1408 EnsureOverlayIsCurrent(false);
1407 } 1409 }
1408 1410
1409 void InstantController::RemoveFromBlacklist(const std::string& url) { 1411 void InstantController::RemoveFromBlacklist(const std::string& url) {
1410 if (blacklisted_urls_.erase(url)) { 1412 if (blacklisted_urls_.erase(url)) {
1411 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); 1413 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST);
1412 } 1414 }
1413 } 1415 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698