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

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 to r180728 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 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 : browser_(browser), 172 : browser_(browser),
173 extended_enabled_(extended_enabled), 173 extended_enabled_(extended_enabled),
174 instant_enabled_(false), 174 instant_enabled_(false),
175 use_local_preview_only_(use_local_preview_only), 175 use_local_preview_only_(use_local_preview_only),
176 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 176 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
177 last_omnibox_text_has_inline_autocompletion_(false), 177 last_omnibox_text_has_inline_autocompletion_(false),
178 last_verbatim_(false), 178 last_verbatim_(false),
179 last_transition_type_(content::PAGE_TRANSITION_LINK), 179 last_transition_type_(content::PAGE_TRANSITION_LINK),
180 last_match_was_search_(false), 180 last_match_was_search_(false),
181 omnibox_focus_state_(OMNIBOX_FOCUS_NONE), 181 omnibox_focus_state_(OMNIBOX_FOCUS_NONE),
182 start_margin_(0), 182 location_bar_margin_(0),
183 end_margin_(0), 183 location_bar_width_(0),
184 allow_preview_to_show_search_suggestions_(false) { 184 allow_preview_to_show_search_suggestions_(false) {
185 } 185 }
186 186
187 InstantController::~InstantController() { 187 InstantController::~InstantController() {
188 } 188 }
189 189
190 bool InstantController::Update(const AutocompleteMatch& match, 190 bool InstantController::Update(const AutocompleteMatch& match,
191 const string16& user_text, 191 const string16& user_text,
192 const string16& full_text, 192 const string16& full_text,
193 size_t selection_start, 193 size_t selection_start,
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 if (popup_bounds_.height() > last_popup_bounds_.height()) { 422 if (popup_bounds_.height() > last_popup_bounds_.height()) {
423 update_bounds_timer_.Stop(); 423 update_bounds_timer_.Stop();
424 SendPopupBoundsToPage(); 424 SendPopupBoundsToPage();
425 } else if (!update_bounds_timer_.IsRunning()) { 425 } else if (!update_bounds_timer_.IsRunning()) {
426 update_bounds_timer_.Start(FROM_HERE, 426 update_bounds_timer_.Start(FROM_HERE,
427 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 427 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
428 &InstantController::SendPopupBoundsToPage); 428 &InstantController::SendPopupBoundsToPage);
429 } 429 }
430 } 430 }
431 431
432 void InstantController::SetMarginSize(int start, int end) { 432 void InstantController::SetLocationBarMarginAndWidth(int margin, int width) {
433 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) 433 if (!extended_enabled_ ||
434 (location_bar_margin_ == margin && location_bar_width_ == width))
434 return; 435 return;
435 436
436 start_margin_ = start; 437 location_bar_margin_ = margin;
437 end_margin_ = end; 438 location_bar_width_ = width;
438 if (loader_) 439 if (loader_)
439 loader_->SetMarginSize(start_margin_, end_margin_); 440 loader_->SetLocationBarMarginAndWidth(margin, width);
440 if (instant_tab_) 441 if (instant_tab_)
441 instant_tab_->SetMarginSize(start_margin_, end_margin_); 442 instant_tab_->SetLocationBarMarginAndWidth(margin, width);
442 } 443 }
443 444
444 void InstantController::HandleAutocompleteResults( 445 void InstantController::HandleAutocompleteResults(
445 const std::vector<AutocompleteProvider*>& providers) { 446 const std::vector<AutocompleteProvider*>& providers) {
446 if (!extended_enabled_) 447 if (!extended_enabled_)
447 return; 448 return;
448 449
449 if (!instant_tab_ && !loader_) 450 if (!instant_tab_ && !loader_)
450 return; 451 return;
451 452
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after
957 } 958 }
958 959
959 void InstantController::InstantLoaderRenderViewCreated() { 960 void InstantController::InstantLoaderRenderViewCreated() {
960 if (!extended_enabled_) 961 if (!extended_enabled_)
961 return; 962 return;
962 963
963 // Ensure the searchbox API has the correct initial state. 964 // Ensure the searchbox API has the correct initial state.
964 loader_->SetDisplayInstantResults(instant_enabled_); 965 loader_->SetDisplayInstantResults(instant_enabled_);
965 loader_->SearchModeChanged(search_mode_); 966 loader_->SearchModeChanged(search_mode_);
966 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); 967 loader_->KeyCaptureChanged(omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE);
967 loader_->SetMarginSize(start_margin_, end_margin_); 968 loader_->SetLocationBarMarginAndWidth(location_bar_margin_,
969 location_bar_width_);
968 loader_->InitializeFonts(); 970 loader_->InitializeFonts();
969 } 971 }
970 972
971 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { 973 void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) {
972 // If the preview is showing custom NTP content, don't hide it, commit it 974 // If the preview is showing custom NTP content, don't hide it, commit it
973 // (no matter where the user clicked) or try to recreate it. 975 // (no matter where the user clicked) or try to recreate it.
974 if (model_.mode().is_ntp()) 976 if (model_.mode().is_ntp())
975 return; 977 return;
976 978
977 // If the preview is not showing at all, recreate it if it's stale. 979 // If the preview is not showing at all, recreate it if it's stale.
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
1087 1089
1088 void InstantController::ResetInstantTab() { 1090 void InstantController::ResetInstantTab() {
1089 // Do not wire up the InstantTab if instant should only use local previews, to 1091 // Do not wire up the InstantTab if instant should only use local previews, to
1090 // prevent it from sending data to the page. 1092 // prevent it from sending data to the page.
1091 if (search_mode_.is_origin_search() && !use_local_preview_only_) { 1093 if (search_mode_.is_origin_search() && !use_local_preview_only_) {
1092 content::WebContents* active_tab = browser_->GetActiveWebContents(); 1094 content::WebContents* active_tab = browser_->GetActiveWebContents();
1093 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 1095 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
1094 instant_tab_.reset(new InstantTab(this, active_tab)); 1096 instant_tab_.reset(new InstantTab(this, active_tab));
1095 instant_tab_->Init(); 1097 instant_tab_->Init();
1096 instant_tab_->SetDisplayInstantResults(instant_enabled_); 1098 instant_tab_->SetDisplayInstantResults(instant_enabled_);
1097 instant_tab_->SetMarginSize(start_margin_, end_margin_); 1099 instant_tab_->SetLocationBarMarginAndWidth(location_bar_margin_,
1100 location_bar_width_);
1098 instant_tab_->InitializeFonts(); 1101 instant_tab_->InitializeFonts();
1099 } 1102 }
1100 1103
1101 // Hide the |loader_| since we are now using |instant_tab_| instead. 1104 // Hide the |loader_| since we are now using |instant_tab_| instead.
1102 HideLoader(); 1105 HideLoader();
1103 } else { 1106 } else {
1104 instant_tab_.reset(); 1107 instant_tab_.reset();
1105 } 1108 }
1106 } 1109 }
1107 1110
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST); 1302 RecordEventHistogram(INSTANT_CONTROLLER_EVENT_URL_BLOCKED_BY_BLACKLIST);
1300 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( 1303 LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf(
1301 "GetInstantURL: Instant URL blacklisted: url=%s", 1304 "GetInstantURL: Instant URL blacklisted: url=%s",
1302 instant_url->c_str())); 1305 instant_url->c_str()));
1303 return false; 1306 return false;
1304 } 1307 }
1305 } 1308 }
1306 1309
1307 return true; 1310 return true;
1308 } 1311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698