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

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: The Great Samarth Merge of 2013 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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 extended_enabled_(extended_enabled), 175 extended_enabled_(extended_enabled),
176 instant_enabled_(false), 176 instant_enabled_(false),
177 use_local_preview_only_(true), 177 use_local_preview_only_(true),
178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 178 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
179 last_omnibox_text_has_inline_autocompletion_(false), 179 last_omnibox_text_has_inline_autocompletion_(false),
180 last_verbatim_(false), 180 last_verbatim_(false),
181 last_transition_type_(content::PAGE_TRANSITION_LINK), 181 last_transition_type_(content::PAGE_TRANSITION_LINK),
182 last_match_was_search_(false), 182 last_match_was_search_(false),
183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 183 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
184 start_margin_(0), 184 start_margin_(0),
185 end_margin_(0), 185 width_(0),
186 allow_preview_to_show_search_suggestions_(false) { 186 allow_preview_to_show_search_suggestions_(false) {
187 } 187 }
188 188
189 InstantController::~InstantController() { 189 InstantController::~InstantController() {
190 } 190 }
191 191
192 bool InstantController::Update(const AutocompleteMatch& match, 192 bool InstantController::Update(const AutocompleteMatch& match,
193 const string16& user_text, 193 const string16& user_text,
194 const string16& full_text, 194 const string16& full_text,
195 size_t selection_start, 195 size_t selection_start,
(...skipping 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
436 if (popup_bounds_.height() > last_popup_bounds_.height()) { 436 if (popup_bounds_.height() > last_popup_bounds_.height()) {
437 update_bounds_timer_.Stop(); 437 update_bounds_timer_.Stop();
438 SendPopupBoundsToPage(); 438 SendPopupBoundsToPage();
439 } else if (!update_bounds_timer_.IsRunning()) { 439 } else if (!update_bounds_timer_.IsRunning()) {
440 update_bounds_timer_.Start(FROM_HERE, 440 update_bounds_timer_.Start(FROM_HERE,
441 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 441 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
442 &InstantController::SendPopupBoundsToPage); 442 &InstantController::SendPopupBoundsToPage);
443 } 443 }
444 } 444 }
445 445
446 void InstantController::SetMarginSize(int start, int end) { 446 void InstantController::SetStartMarginAndWidth(int margin, int width) {
447 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) 447 if (!extended_enabled_ || (start_margin_ == margin && width_ == width))
448 return; 448 return;
449 449
450 start_margin_ = start; 450 start_margin_ = margin;
451 end_margin_ = end; 451 width_ = width;
452 if (overlay_) 452 if (overlay_)
453 overlay_->SetMarginSize(start_margin_, end_margin_); 453 overlay_->SetStartMarginAndWidth(start_margin_, width_);
454 if (ntp_) 454 if (ntp_)
455 ntp_->SetMarginSize(start_margin_, end_margin_); 455 ntp_->SetStartMarginAndWidth(start_margin_, width_);
456 if (instant_tab_) 456 if (instant_tab_)
457 instant_tab_->SetMarginSize(start_margin_, end_margin_); 457 instant_tab_->SetStartMarginAndWidth(margin, width);
458 } 458 }
459 459
460 void InstantController::HandleAutocompleteResults( 460 void InstantController::HandleAutocompleteResults(
461 const std::vector<AutocompleteProvider*>& providers) { 461 const std::vector<AutocompleteProvider*>& providers) {
462 if (!extended_enabled_) 462 if (!extended_enabled_)
463 return; 463 return;
464 464
465 if (!instant_tab_ && !overlay_) 465 if (!instant_tab_ && !overlay_)
466 return; 466 return;
467 467
(...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 849
850 // Update theme info so that the page picks it up. 850 // Update theme info so that the page picks it up.
851 browser_->UpdateThemeInfoForPreview(); 851 browser_->UpdateThemeInfoForPreview();
852 852
853 // Ensure the searchbox API has the correct initial state. 853 // Ensure the searchbox API has the correct initial state.
854 if (IsContentsFrom(overlay(), contents)) { 854 if (IsContentsFrom(overlay(), contents)) {
855 overlay_->SetDisplayInstantResults(instant_enabled_); 855 overlay_->SetDisplayInstantResults(instant_enabled_);
856 overlay_->SearchModeChanged(search_mode_); 856 overlay_->SearchModeChanged(search_mode_);
857 overlay_->KeyCaptureChanged( 857 overlay_->KeyCaptureChanged(
858 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 858 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
859 overlay_->SetMarginSize(start_margin_, end_margin_); 859 overlay_->SetStartMarginAndWidth(start_margin_, width_);
860 overlay_->InitializeFonts(); 860 overlay_->InitializeFonts();
861 } else if (IsContentsFrom(ntp(), contents)) { 861 } else if (IsContentsFrom(ntp(), contents)) {
862 ntp_->SetDisplayInstantResults(instant_enabled_); 862 ntp_->SetDisplayInstantResults(instant_enabled_);
863 ntp_->SetMarginSize(start_margin_, end_margin_); 863 ntp_->SetStartMarginAndWidth(start_margin_, width_);
864 ntp_->InitializeFonts(); 864 ntp_->InitializeFonts();
865 } else { 865 } else {
866 NOTREACHED(); 866 NOTREACHED();
867 } 867 }
868 } 868 }
869 869
870 void InstantController::InstantSupportDetermined( 870 void InstantController::InstantSupportDetermined(
871 const content::WebContents* contents, 871 const content::WebContents* contents,
872 bool supports_instant) { 872 bool supports_instant) {
873 if (IsContentsFrom(instant_tab(), contents)) { 873 if (IsContentsFrom(instant_tab(), contents)) {
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 // Do not wire up the InstantTab if instant should only use local previews, to 1161 // Do not wire up the InstantTab if instant should only use local previews, to
1162 // prevent it from sending data to the page. 1162 // prevent it from sending data to the page.
1163 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { 1163 if (!search_mode_.is_origin_default() && !use_local_preview_only_) {
1164 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1164 content::WebContents* active_tab = browser_->GetActiveWebContents();
1165 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1165 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1166 instant_tab_.reset(new InstantTab(this)); 1166 instant_tab_.reset(new InstantTab(this));
1167 instant_tab_->Init(active_tab); 1167 instant_tab_->Init(active_tab);
1168 // Update theme info for this tab. 1168 // Update theme info for this tab.
1169 browser_->UpdateThemeInfoForPreview(); 1169 browser_->UpdateThemeInfoForPreview();
1170 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1170 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1171 instant_tab_->SetMarginSize(start_margin_, end_margin_); 1171 instant_tab_->SetStartMarginAndWidth(start_margin_, width_);
1172 instant_tab_->InitializeFonts(); 1172 instant_tab_->InitializeFonts();
1173 instant_tab_->KeyCaptureChanged( 1173 instant_tab_->KeyCaptureChanged(
1174 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 1174 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
1175 } 1175 }
1176 1176
1177 // Hide the |overlay_| since we are now using |instant_tab_| instead. 1177 // Hide the |overlay_| since we are now using |instant_tab_| instead.
1178 HideOverlay(); 1178 HideOverlay();
1179 } else { 1179 } else {
1180 instant_tab_.reset(); 1180 instant_tab_.reset();
1181 } 1181 }
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
1398 delete overlay_->ReleaseContents().release(); 1398 delete overlay_->ReleaseContents().release();
1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); 1399 MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release());
1400 EnsureOverlayIsCurrent(false); 1400 EnsureOverlayIsCurrent(false);
1401 } 1401 }
1402 1402
1403 void InstantController::RemoveFromBlacklist(const std::string& url) { 1403 void InstantController::RemoveFromBlacklist(const std::string& url) {
1404 if (blacklisted_urls_.erase(url)) { 1404 if (blacklisted_urls_.erase(url)) {
1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST); 1405 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_REMOVED_FROM_BLACKLIST);
1406 } 1406 }
1407 } 1407 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698