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

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

Issue 11359198: Implement the Instant extended API startMargin, endMargin, and rtl properties and the onmarginchang… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years 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/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 bool extended_enabled) 146 bool extended_enabled)
147 : browser_(browser), 147 : browser_(browser),
148 extended_enabled_(extended_enabled), 148 extended_enabled_(extended_enabled),
149 instant_enabled_(false), 149 instant_enabled_(false),
150 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), 150 model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)),
151 last_omnibox_text_has_inline_autocompletion_(false), 151 last_omnibox_text_has_inline_autocompletion_(false),
152 last_verbatim_(false), 152 last_verbatim_(false),
153 last_transition_type_(content::PAGE_TRANSITION_LINK), 153 last_transition_type_(content::PAGE_TRANSITION_LINK),
154 last_match_was_search_(false), 154 last_match_was_search_(false),
155 is_omnibox_focused_(false), 155 is_omnibox_focused_(false),
156 start_margin_(0),
157 end_margin_(0),
156 allow_preview_to_show_search_suggestions_(false) { 158 allow_preview_to_show_search_suggestions_(false) {
157 } 159 }
158 160
159 InstantController::~InstantController() { 161 InstantController::~InstantController() {
160 } 162 }
161 163
162 bool InstantController::Update(const AutocompleteMatch& match, 164 bool InstantController::Update(const AutocompleteMatch& match,
163 const string16& user_text, 165 const string16& user_text,
164 const string16& full_text, 166 const string16& full_text,
165 size_t selection_start, 167 size_t selection_start,
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
339 browser_->SetInstantSuggestion(last_suggestion_); 341 browser_->SetInstantSuggestion(last_suggestion_);
340 342
341 // Though we may have handled a URL match above, we return false here, so that 343 // Though we may have handled a URL match above, we return false here, so that
342 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always 344 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always
343 // return true) once we are able to commit URLs as well. 345 // return true) once we are able to commit URLs as well.
344 return last_match_was_search_; 346 return last_match_was_search_;
345 } 347 }
346 348
347 // TODO(tonyg): This method only fires when the omnibox bounds change. It also 349 // TODO(tonyg): This method only fires when the omnibox bounds change. It also
348 // needs to fire when the preview bounds change (e.g.: open/close info bar). 350 // needs to fire when the preview bounds change (e.g.: open/close info bar).
349 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { 351 void InstantController::SetPopupBounds(const gfx::Rect& bounds) {
350 if (!extended_enabled_ && !instant_enabled_) 352 if (!extended_enabled_ && !instant_enabled_)
351 return; 353 return;
352 354
353 if (omnibox_bounds_ == bounds) 355 if (popup_bounds_ == bounds)
354 return; 356 return;
355 357
356 omnibox_bounds_ = bounds; 358 popup_bounds_ = bounds;
357 if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { 359 if (popup_bounds_.height() > last_popup_bounds_.height()) {
358 update_bounds_timer_.Stop(); 360 update_bounds_timer_.Stop();
359 SendBoundsToPage(); 361 SendPopupBoundsToPage();
360 } else if (!update_bounds_timer_.IsRunning()) { 362 } else if (!update_bounds_timer_.IsRunning()) {
361 update_bounds_timer_.Start(FROM_HERE, 363 update_bounds_timer_.Start(FROM_HERE,
362 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 364 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
363 &InstantController::SendBoundsToPage); 365 &InstantController::SendPopupBoundsToPage);
364 } 366 }
365 } 367 }
366 368
369 void InstantController::SetMarginSize(int start, int end) {
370 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end))
371 return;
372
373 start_margin_ = start;
374 end_margin_ = end;
375 if (loader_)
376 loader_->SetMarginSize(start_margin_, end_margin_);
377 if (instant_tab_)
378 instant_tab_->SetMarginSize(start_margin_, end_margin_);
379 }
380
367 void InstantController::HandleAutocompleteResults( 381 void InstantController::HandleAutocompleteResults(
368 const std::vector<AutocompleteProvider*>& providers) { 382 const std::vector<AutocompleteProvider*>& providers) {
369 if (!extended_enabled_) 383 if (!extended_enabled_)
370 return; 384 return;
371 385
372 if (!instant_tab_ && !loader_) 386 if (!instant_tab_ && !loader_)
373 return; 387 return;
374 388
375 DVLOG(1) << "AutocompleteResults:"; 389 DVLOG(1) << "AutocompleteResults:";
376 std::vector<InstantAutocompleteResult> results; 390 std::vector<InstantAutocompleteResult> results;
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 815
802 HideInternal(); 816 HideInternal();
803 loader_.reset(new InstantLoader(this, instant_url)); 817 loader_.reset(new InstantLoader(this, instant_url));
804 loader_->InitContents(active_tab); 818 loader_->InitContents(active_tab);
805 819
806 // Ensure the searchbox API has the correct initial state. 820 // Ensure the searchbox API has the correct initial state.
807 if (extended_enabled_) { 821 if (extended_enabled_) {
808 browser_->UpdateThemeInfoForPreview(); 822 browser_->UpdateThemeInfoForPreview();
809 loader_->SetDisplayInstantResults(instant_enabled_); 823 loader_->SetDisplayInstantResults(instant_enabled_);
810 loader_->SearchModeChanged(search_mode_); 824 loader_->SearchModeChanged(search_mode_);
825 loader_->SetMarginSize(start_margin_, end_margin_);
811 } 826 }
812 827
813 // Restart the stale loader timer. 828 // Restart the stale loader timer.
814 stale_loader_timer_.Start(FROM_HERE, 829 stale_loader_timer_.Start(FROM_HERE,
815 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, 830 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this,
816 &InstantController::OnStaleLoader); 831 &InstantController::OnStaleLoader);
817 832
818 return true; 833 return true;
819 } 834 }
820 835
(...skipping 21 matching lines...) Expand all
842 } 857 }
843 } 858 }
844 859
845 void InstantController::ResetInstantTab() { 860 void InstantController::ResetInstantTab() {
846 if (search_mode_.is_origin_search()) { 861 if (search_mode_.is_origin_search()) {
847 content::WebContents* active_tab = browser_->GetActiveWebContents(); 862 content::WebContents* active_tab = browser_->GetActiveWebContents();
848 if (!instant_tab_ || active_tab != instant_tab_->contents()) { 863 if (!instant_tab_ || active_tab != instant_tab_->contents()) {
849 instant_tab_.reset(new InstantTab(this, active_tab)); 864 instant_tab_.reset(new InstantTab(this, active_tab));
850 instant_tab_->Init(); 865 instant_tab_->Init();
851 instant_tab_->SetDisplayInstantResults(instant_enabled_); 866 instant_tab_->SetDisplayInstantResults(instant_enabled_);
867 instant_tab_->SetMarginSize(start_margin_, end_margin_);
852 } 868 }
853 869
854 // Hide the |loader_| since we are now using |instant_tab_| instead. 870 // Hide the |loader_| since we are now using |instant_tab_| instead.
855 HideLoader(); 871 HideLoader();
856 } else { 872 } else {
857 instant_tab_.reset(); 873 instant_tab_.reset();
858 } 874 }
859 } 875 }
860 876
861 bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { 877 bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) {
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
952 // already showing at 100% height. 968 // already showing at 100% height.
953 bool is_full_height = model_.height() == 100 && 969 bool is_full_height = model_.height() == 100 &&
954 model_.height_units() == INSTANT_SIZE_PERCENT; 970 model_.height_units() == INSTANT_SIZE_PERCENT;
955 if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || 971 if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT ||
956 (search_mode_.is_origin_default() && !is_full_height)) 972 (search_mode_.is_origin_default() && !is_full_height))
957 model_.SetPreviewState(search_mode_, height, units); 973 model_.SetPreviewState(search_mode_, height, units);
958 else 974 else
959 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); 975 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT);
960 } 976 }
961 977
962 void InstantController::SendBoundsToPage() { 978 void InstantController::SendPopupBoundsToPage() {
963 if (last_omnibox_bounds_ == omnibox_bounds_ || !loader_ || 979 if (last_popup_bounds_ == popup_bounds_ || !loader_ ||
964 loader_->is_pointer_down_from_activate()) 980 loader_->is_pointer_down_from_activate())
965 return; 981 return;
966 982
967 last_omnibox_bounds_ = omnibox_bounds_; 983 last_popup_bounds_ = popup_bounds_;
968 gfx::Rect preview_bounds = browser_->GetInstantBounds(); 984 gfx::Rect preview_bounds = browser_->GetInstantBounds();
969 gfx::Rect intersection = gfx::IntersectRects(omnibox_bounds_, preview_bounds); 985 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds);
970 986
971 // Translate into window coordinates. 987 // Translate into window coordinates.
972 if (!intersection.IsEmpty()) { 988 if (!intersection.IsEmpty()) {
973 intersection.Offset(-preview_bounds.origin().x(), 989 intersection.Offset(-preview_bounds.origin().x(),
974 -preview_bounds.origin().y()); 990 -preview_bounds.origin().y());
975 } 991 }
976 992
977 // In the current Chrome UI, these must always be true so they sanity check 993 // In the current Chrome UI, these must always be true so they sanity check
978 // the above operations. In a future UI, these may be removed or adjusted. 994 // the above operations. In a future UI, these may be removed or adjusted.
979 // There is no point in sanity-checking |intersection.y()| because the omnibox 995 // There is no point in sanity-checking |intersection.y()| because the omnibox
980 // can be placed anywhere vertically relative to the preview (for example, in 996 // can be placed anywhere vertically relative to the preview (for example, in
981 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). 997 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds).
982 DCHECK_LE(0, intersection.x()); 998 DCHECK_LE(0, intersection.x());
983 DCHECK_LE(0, intersection.width()); 999 DCHECK_LE(0, intersection.width());
984 DCHECK_LE(0, intersection.height()); 1000 DCHECK_LE(0, intersection.height());
985 1001
986 loader_->SetOmniboxBounds(intersection); 1002 loader_->SetPopupBounds(intersection);
987 } 1003 }
988 1004
989 bool InstantController::GetInstantURL(const TemplateURL* template_url, 1005 bool InstantController::GetInstantURL(const TemplateURL* template_url,
990 std::string* instant_url) const { 1006 std::string* instant_url) const {
991 CommandLine* command_line = CommandLine::ForCurrentProcess(); 1007 CommandLine* command_line = CommandLine::ForCurrentProcess();
992 if (command_line->HasSwitch(switches::kInstantURL)) { 1008 if (command_line->HasSwitch(switches::kInstantURL)) {
993 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); 1009 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);
994 return template_url != NULL; 1010 return template_url != NULL;
995 } 1011 }
996 1012
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1030 } 1046 }
1031 1047
1032 std::map<std::string, int>::const_iterator iter = 1048 std::map<std::string, int>::const_iterator iter =
1033 blacklisted_urls_.find(*instant_url); 1049 blacklisted_urls_.find(*instant_url);
1034 if (iter != blacklisted_urls_.end() && 1050 if (iter != blacklisted_urls_.end() &&
1035 iter->second > kMaxInstantSupportFailures) 1051 iter->second > kMaxInstantSupportFailures)
1036 return false; 1052 return false;
1037 1053
1038 return true; 1054 return true;
1039 } 1055 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698