| OLD | NEW |
| 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 Loading... |
| 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), | |
| 207 end_margin_(0), | |
| 208 allow_preview_to_show_search_suggestions_(false), | 206 allow_preview_to_show_search_suggestions_(false), |
| 209 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 207 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
| 210 } | 208 } |
| 211 | 209 |
| 212 InstantController::~InstantController() { | 210 InstantController::~InstantController() { |
| 213 } | 211 } |
| 214 | 212 |
| 215 bool InstantController::Update(const AutocompleteMatch& match, | 213 bool InstantController::Update(const AutocompleteMatch& match, |
| 216 const string16& user_text, | 214 const string16& user_text, |
| 217 const string16& full_text, | 215 const string16& full_text, |
| (...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 460 if (popup_bounds_.height() > last_popup_bounds_.height()) { | 458 if (popup_bounds_.height() > last_popup_bounds_.height()) { |
| 461 update_bounds_timer_.Stop(); | 459 update_bounds_timer_.Stop(); |
| 462 SendPopupBoundsToPage(); | 460 SendPopupBoundsToPage(); |
| 463 } else if (!update_bounds_timer_.IsRunning()) { | 461 } else if (!update_bounds_timer_.IsRunning()) { |
| 464 update_bounds_timer_.Start(FROM_HERE, | 462 update_bounds_timer_.Start(FROM_HERE, |
| 465 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 463 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
| 466 &InstantController::SendPopupBoundsToPage); | 464 &InstantController::SendPopupBoundsToPage); |
| 467 } | 465 } |
| 468 } | 466 } |
| 469 | 467 |
| 470 void InstantController::SetMarginSize(int start, int end) { | 468 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { |
| 471 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end)) | 469 if (!extended_enabled_ || omnibox_bounds_ == bounds) |
| 472 return; | 470 return; |
| 473 | 471 |
| 474 start_margin_ = start; | 472 omnibox_bounds_ = bounds; |
| 475 end_margin_ = end; | |
| 476 if (overlay_) | 473 if (overlay_) |
| 477 overlay_->SetMarginSize(start_margin_, end_margin_); | 474 overlay_->SetOmniboxBounds(omnibox_bounds_); |
| 478 if (ntp_) | 475 if (ntp_) |
| 479 ntp_->SetMarginSize(start_margin_, end_margin_); | 476 ntp_->SetOmniboxBounds(omnibox_bounds_); |
| 480 if (instant_tab_) | 477 if (instant_tab_) |
| 481 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 478 instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
| 482 } | 479 } |
| 483 | 480 |
| 484 void InstantController::HandleAutocompleteResults( | 481 void InstantController::HandleAutocompleteResults( |
| 485 const std::vector<AutocompleteProvider*>& providers) { | 482 const std::vector<AutocompleteProvider*>& providers) { |
| 486 if (!extended_enabled_) | 483 if (!extended_enabled_) |
| 487 return; | 484 return; |
| 488 | 485 |
| 489 if (!instant_tab_ && !overlay_) | 486 if (!instant_tab_ && !overlay_) |
| 490 return; | 487 return; |
| 491 | 488 |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 889 return; | 886 return; |
| 890 | 887 |
| 891 // Update theme info so that the page picks it up. | 888 // Update theme info so that the page picks it up. |
| 892 browser_->UpdateThemeInfo(false); | 889 browser_->UpdateThemeInfo(false); |
| 893 | 890 |
| 894 // Ensure the searchbox API has the correct initial state. | 891 // Ensure the searchbox API has the correct initial state. |
| 895 if (IsContentsFrom(overlay(), contents)) { | 892 if (IsContentsFrom(overlay(), contents)) { |
| 896 overlay_->SetDisplayInstantResults(instant_enabled_); | 893 overlay_->SetDisplayInstantResults(instant_enabled_); |
| 897 overlay_->KeyCaptureChanged( | 894 overlay_->KeyCaptureChanged( |
| 898 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 895 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 899 overlay_->SetMarginSize(start_margin_, end_margin_); | 896 overlay_->SetOmniboxBounds(omnibox_bounds_); |
| 900 overlay_->InitializeFonts(); | 897 overlay_->InitializeFonts(); |
| 901 } else if (IsContentsFrom(ntp(), contents)) { | 898 } else if (IsContentsFrom(ntp(), contents)) { |
| 902 ntp_->SetDisplayInstantResults(instant_enabled_); | 899 ntp_->SetDisplayInstantResults(instant_enabled_); |
| 903 ntp_->SetMarginSize(start_margin_, end_margin_); | 900 ntp_->SetOmniboxBounds(omnibox_bounds_); |
| 904 ntp_->InitializeFonts(); | 901 ntp_->InitializeFonts(); |
| 905 } else { | 902 } else { |
| 906 NOTREACHED(); | 903 NOTREACHED(); |
| 907 } | 904 } |
| 908 StartListeningToMostVisitedChanges(); | 905 StartListeningToMostVisitedChanges(); |
| 909 } | 906 } |
| 910 | 907 |
| 911 void InstantController::InstantSupportDetermined( | 908 void InstantController::InstantSupportDetermined( |
| 912 const content::WebContents* contents, | 909 const content::WebContents* contents, |
| 913 bool supports_instant) { | 910 bool supports_instant) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 // Do not wire up the InstantTab if instant should only use local previews, to | 1220 // Do not wire up the InstantTab if instant should only use local previews, to |
| 1224 // prevent it from sending data to the page. | 1221 // prevent it from sending data to the page. |
| 1225 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { | 1222 if (!search_mode_.is_origin_default() && !use_local_preview_only_) { |
| 1226 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 1223 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
| 1227 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 1224 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
| 1228 instant_tab_.reset(new InstantTab(this)); | 1225 instant_tab_.reset(new InstantTab(this)); |
| 1229 instant_tab_->Init(active_tab); | 1226 instant_tab_->Init(active_tab); |
| 1230 // Update theme info for this tab. | 1227 // Update theme info for this tab. |
| 1231 browser_->UpdateThemeInfo(false); | 1228 browser_->UpdateThemeInfo(false); |
| 1232 instant_tab_->SetDisplayInstantResults(instant_enabled_); | 1229 instant_tab_->SetDisplayInstantResults(instant_enabled_); |
| 1233 instant_tab_->SetMarginSize(start_margin_, end_margin_); | 1230 instant_tab_->SetOmniboxBounds(omnibox_bounds_); |
| 1234 instant_tab_->InitializeFonts(); | 1231 instant_tab_->InitializeFonts(); |
| 1235 StartListeningToMostVisitedChanges(); | 1232 StartListeningToMostVisitedChanges(); |
| 1236 instant_tab_->KeyCaptureChanged( | 1233 instant_tab_->KeyCaptureChanged( |
| 1237 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); | 1234 omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE); |
| 1238 } | 1235 } |
| 1239 | 1236 |
| 1240 // Hide the |overlay_| since we are now using |instant_tab_| instead. | 1237 // Hide the |overlay_| since we are now using |instant_tab_| instead. |
| 1241 HideOverlay(); | 1238 HideOverlay(); |
| 1242 } else { | 1239 } else { |
| 1243 instant_tab_.reset(); | 1240 instant_tab_.reset(); |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1522 overlay_->SendMostVisitedItems(items); | 1519 overlay_->SendMostVisitedItems(items); |
| 1523 if (ntp_) | 1520 if (ntp_) |
| 1524 ntp_->SendMostVisitedItems(items); | 1521 ntp_->SendMostVisitedItems(items); |
| 1525 if (instant_tab_) | 1522 if (instant_tab_) |
| 1526 instant_tab_->SendMostVisitedItems(items); | 1523 instant_tab_->SendMostVisitedItems(items); |
| 1527 content::NotificationService::current()->Notify( | 1524 content::NotificationService::current()->Notify( |
| 1528 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, | 1525 chrome::NOTIFICATION_INSTANT_SENT_MOST_VISITED_ITEMS, |
| 1529 content::Source<InstantController>(this), | 1526 content::Source<InstantController>(this), |
| 1530 content::NotificationService::NoDetails()); | 1527 content::NotificationService::NoDetails()); |
| 1531 } | 1528 } |
| OLD | NEW |