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/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
337 browser_->SetInstantSuggestion(last_suggestion_); | 339 browser_->SetInstantSuggestion(last_suggestion_); |
338 | 340 |
339 // Though we may have handled a URL match above, we return false here, so that | 341 // Though we may have handled a URL match above, we return false here, so that |
340 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always | 342 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always |
341 // return true) once we are able to commit URLs as well. | 343 // return true) once we are able to commit URLs as well. |
342 return last_match_was_search_; | 344 return last_match_was_search_; |
343 } | 345 } |
344 | 346 |
345 // TODO(tonyg): This method only fires when the omnibox bounds change. It also | 347 // TODO(tonyg): This method only fires when the omnibox bounds change. It also |
346 // needs to fire when the preview bounds change (e.g.: open/close info bar). | 348 // needs to fire when the preview bounds change (e.g.: open/close info bar). |
347 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { | 349 void InstantController::SetPopupBounds(const gfx::Rect& bounds) { |
348 if (!extended_enabled_ && !instant_enabled_) | 350 if (!extended_enabled_ && !instant_enabled_) |
349 return; | 351 return; |
350 | 352 |
351 if (omnibox_bounds_ == bounds) | 353 if (popup_bounds_ == bounds) |
352 return; | 354 return; |
353 | 355 |
354 omnibox_bounds_ = bounds; | 356 popup_bounds_ = bounds; |
355 if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { | 357 if (popup_bounds_.height() > last_popup_bounds_.height()) { |
356 update_bounds_timer_.Stop(); | 358 update_bounds_timer_.Stop(); |
357 SendBoundsToPage(); | 359 SendPopupBoundsToPage(); |
358 } else if (!update_bounds_timer_.IsRunning()) { | 360 } else if (!update_bounds_timer_.IsRunning()) { |
359 update_bounds_timer_.Start(FROM_HERE, | 361 update_bounds_timer_.Start(FROM_HERE, |
360 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, | 362 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, |
361 &InstantController::SendBoundsToPage); | 363 &InstantController::SendPopupBoundsToPage); |
362 } | 364 } |
363 } | 365 } |
364 | 366 |
367 void InstantController::SetMarginSize(int start, int end) { | |
368 if (!extended_enabled_ || (start_margin_ == start && end_margin_ == end) || | |
369 !GetPreviewContents()) | |
370 return; | |
sreeram
2012/12/05 00:14:46
The margin should be sent to committed tabs too. I
melevin
2012/12/06 23:13:00
Done.
| |
371 | |
372 start_margin_ = start; | |
373 end_margin_ = end; | |
374 loader_->SetMarginSize(start_margin_, end_margin_); | |
375 } | |
376 | |
365 void InstantController::HandleAutocompleteResults( | 377 void InstantController::HandleAutocompleteResults( |
366 const std::vector<AutocompleteProvider*>& providers) { | 378 const std::vector<AutocompleteProvider*>& providers) { |
367 if (!extended_enabled_) | 379 if (!extended_enabled_) |
368 return; | 380 return; |
369 | 381 |
370 if (!instant_tab_ && !loader_) | 382 if (!instant_tab_ && !loader_) |
371 return; | 383 return; |
372 | 384 |
373 DVLOG(1) << "AutocompleteResults:"; | 385 DVLOG(1) << "AutocompleteResults:"; |
374 std::vector<InstantAutocompleteResult> results; | 386 std::vector<InstantAutocompleteResult> results; |
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
766 | 778 |
767 HideInternal(); | 779 HideInternal(); |
768 loader_.reset(new InstantLoader(this, instant_url)); | 780 loader_.reset(new InstantLoader(this, instant_url)); |
769 loader_->InitContents(active_tab); | 781 loader_->InitContents(active_tab); |
770 | 782 |
771 // Ensure the searchbox API has the correct initial state. | 783 // Ensure the searchbox API has the correct initial state. |
772 if (extended_enabled_) { | 784 if (extended_enabled_) { |
773 browser_->UpdateThemeInfoForPreview(); | 785 browser_->UpdateThemeInfoForPreview(); |
774 loader_->SetDisplayInstantResults(instant_enabled_); | 786 loader_->SetDisplayInstantResults(instant_enabled_); |
775 loader_->SearchModeChanged(search_mode_); | 787 loader_->SearchModeChanged(search_mode_); |
788 loader_->SetMarginSize(start_margin_, end_margin_); | |
776 } | 789 } |
777 | 790 |
778 // Restart the stale loader timer. | 791 // Restart the stale loader timer. |
779 stale_loader_timer_.Start(FROM_HERE, | 792 stale_loader_timer_.Start(FROM_HERE, |
780 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, | 793 base::TimeDelta::FromMilliseconds(kStaleLoaderTimeoutMS), this, |
781 &InstantController::OnStaleLoader); | 794 &InstantController::OnStaleLoader); |
782 | 795 |
783 return true; | 796 return true; |
784 } | 797 } |
785 | 798 |
(...skipping 19 matching lines...) Expand all Loading... | |
805 loader_.reset(); | 818 loader_.reset(); |
806 CreateDefaultLoader(); | 819 CreateDefaultLoader(); |
807 } | 820 } |
808 } | 821 } |
809 | 822 |
810 void InstantController::ResetInstantTab() { | 823 void InstantController::ResetInstantTab() { |
811 if (search_mode_.is_origin_search()) { | 824 if (search_mode_.is_origin_search()) { |
812 content::WebContents* active_tab = browser_->GetActiveWebContents(); | 825 content::WebContents* active_tab = browser_->GetActiveWebContents(); |
813 if (!instant_tab_ || active_tab != instant_tab_->contents()) { | 826 if (!instant_tab_ || active_tab != instant_tab_->contents()) { |
814 instant_tab_.reset(new InstantTab(this, active_tab)); | 827 instant_tab_.reset(new InstantTab(this, active_tab)); |
815 instant_tab_->Init(); | 828 instant_tab_->Init(); |
sreeram
2012/12/05 00:14:46
Similar to ResetLoader(), you should do this here:
melevin
2012/12/06 23:13:00
Added this but I'm not sure what it's doing. Once
samarth
2012/12/07 01:44:49
Yes, why not? Search pages can be committed and t
melevin
2012/12/08 00:04:09
Oops, it wasn't working due to a copy-paste error.
| |
816 } | 829 } |
817 | 830 |
818 // Hide the |loader_| since we are now using |instant_tab_| instead. | 831 // Hide the |loader_| since we are now using |instant_tab_| instead. |
819 HideLoader(); | 832 HideLoader(); |
820 } else { | 833 } else { |
821 instant_tab_.reset(); | 834 instant_tab_.reset(); |
822 } | 835 } |
823 } | 836 } |
824 | 837 |
825 bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { | 838 bool InstantController::ResetLoaderForMatch(const AutocompleteMatch& match) { |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
916 // already showing at 100% height. | 929 // already showing at 100% height. |
917 bool is_full_height = model_.height() == 100 && | 930 bool is_full_height = model_.height() == 100 && |
918 model_.height_units() == INSTANT_SIZE_PERCENT; | 931 model_.height_units() == INSTANT_SIZE_PERCENT; |
919 if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || | 932 if (!instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || |
920 (search_mode_.is_origin_default() && !is_full_height)) | 933 (search_mode_.is_origin_default() && !is_full_height)) |
921 model_.SetPreviewState(search_mode_, height, units); | 934 model_.SetPreviewState(search_mode_, height, units); |
922 else | 935 else |
923 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); | 936 model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); |
924 } | 937 } |
925 | 938 |
926 void InstantController::SendBoundsToPage() { | 939 void InstantController::SendPopupBoundsToPage() { |
927 if (last_omnibox_bounds_ == omnibox_bounds_ || !loader_ || | 940 if (last_omnibox_bounds_ == omnibox_bounds_ || !loader_ || |
sreeram
2012/12/05 00:14:46
Shouldn't this be "last_popup_bounds_ == popup_bou
melevin
2012/12/06 23:13:00
Done.
| |
928 loader_->is_pointer_down_from_activate()) | 941 loader_->is_pointer_down_from_activate()) |
929 return; | 942 return; |
930 | 943 |
931 last_omnibox_bounds_ = omnibox_bounds_; | 944 last_popup_bounds_ = popup_bounds_; |
932 gfx::Rect preview_bounds = browser_->GetInstantBounds(); | 945 gfx::Rect preview_bounds = browser_->GetInstantBounds(); |
933 gfx::Rect intersection = gfx::IntersectRects(omnibox_bounds_, preview_bounds); | 946 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); |
934 | 947 |
935 // Translate into window coordinates. | 948 // Translate into window coordinates. |
936 if (!intersection.IsEmpty()) { | 949 if (!intersection.IsEmpty()) { |
937 intersection.Offset(-preview_bounds.origin().x(), | 950 intersection.Offset(-preview_bounds.origin().x(), |
938 -preview_bounds.origin().y()); | 951 -preview_bounds.origin().y()); |
939 } | 952 } |
940 | 953 |
941 // In the current Chrome UI, these must always be true so they sanity check | 954 // In the current Chrome UI, these must always be true so they sanity check |
942 // the above operations. In a future UI, these may be removed or adjusted. | 955 // the above operations. In a future UI, these may be removed or adjusted. |
943 // There is no point in sanity-checking |intersection.y()| because the omnibox | 956 // There is no point in sanity-checking |intersection.y()| because the omnibox |
944 // can be placed anywhere vertically relative to the preview (for example, in | 957 // can be placed anywhere vertically relative to the preview (for example, in |
945 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). | 958 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). |
946 DCHECK_LE(0, intersection.x()); | 959 DCHECK_LE(0, intersection.x()); |
947 DCHECK_LE(0, intersection.width()); | 960 DCHECK_LE(0, intersection.width()); |
948 DCHECK_LE(0, intersection.height()); | 961 DCHECK_LE(0, intersection.height()); |
949 | 962 |
950 loader_->SetOmniboxBounds(intersection); | 963 loader_->SetPopupBounds(intersection); |
951 } | 964 } |
952 | 965 |
953 bool InstantController::GetInstantURL(const TemplateURL* template_url, | 966 bool InstantController::GetInstantURL(const TemplateURL* template_url, |
954 std::string* instant_url) const { | 967 std::string* instant_url) const { |
955 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 968 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
956 if (command_line->HasSwitch(switches::kInstantURL)) { | 969 if (command_line->HasSwitch(switches::kInstantURL)) { |
957 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); | 970 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); |
958 return template_url != NULL; | 971 return template_url != NULL; |
959 } | 972 } |
960 | 973 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
994 } | 1007 } |
995 | 1008 |
996 std::map<std::string, int>::const_iterator iter = | 1009 std::map<std::string, int>::const_iterator iter = |
997 blacklisted_urls_.find(*instant_url); | 1010 blacklisted_urls_.find(*instant_url); |
998 if (iter != blacklisted_urls_.end() && | 1011 if (iter != blacklisted_urls_.end() && |
999 iter->second > kMaxInstantSupportFailures) | 1012 iter->second > kMaxInstantSupportFailures) |
1000 return false; | 1013 return false; |
1001 | 1014 |
1002 return true; | 1015 return true; |
1003 } | 1016 } |
OLD | NEW |