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

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, 1 month 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/i18n/case_conversion.h" 8 #include "base/i18n/case_conversion.h"
9 #include "base/metrics/histogram.h" 9 #include "base/metrics/histogram.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 browser_->SetInstantSuggestion(last_suggestion_); 252 browser_->SetInstantSuggestion(last_suggestion_);
253 253
254 // Though we may have handled a URL match above, we return false here, so that 254 // Though we may have handled a URL match above, we return false here, so that
255 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always 255 // omnibox prerendering can kick in. TODO(sreeram): Remove this (and always
256 // return true) once we are able to commit URLs as well. 256 // return true) once we are able to commit URLs as well.
257 return last_match_was_search_; 257 return last_match_was_search_;
258 } 258 }
259 259
260 // TODO(tonyg): This method only fires when the omnibox bounds change. It also 260 // TODO(tonyg): This method only fires when the omnibox bounds change. It also
261 // needs to fire when the preview bounds change (e.g.: open/close info bar). 261 // needs to fire when the preview bounds change (e.g.: open/close info bar).
262 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { 262 void InstantController::SetPopupBounds(const gfx::Rect& bounds) {
263 if (omnibox_bounds_ == bounds) 263 if (popup_bounds_ == bounds)
264 return; 264 return;
265 265
266 omnibox_bounds_ = bounds; 266 popup_bounds_ = bounds;
267 if (omnibox_bounds_.height() > last_omnibox_bounds_.height()) { 267 if (popup_bounds_.height() > last_popup_bounds_.height()) {
268 update_bounds_timer_.Stop(); 268 update_bounds_timer_.Stop();
269 SendBoundsToPage(); 269 SendBoundsToPage();
270 } else if (!update_bounds_timer_.IsRunning()) { 270 } else if (!update_bounds_timer_.IsRunning()) {
271 update_bounds_timer_.Start(FROM_HERE, 271 update_bounds_timer_.Start(FROM_HERE,
272 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this, 272 base::TimeDelta::FromMilliseconds(kUpdateBoundsDelayMS), this,
273 &InstantController::SendBoundsToPage); 273 &InstantController::SendBoundsToPage);
274 } 274 }
275 } 275 }
276 276
277 void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) {
278 if (omnibox_bounds_ == bounds ||
279 model_.preview_state() == InstantModel::NOT_READY ||
280 !GetPreviewContents() || loader_->IsPointerDownFromActivate())
281 return;
282
283 omnibox_bounds_ = bounds;
284 loader_->SetOmniboxBounds(bounds);
285 }
286
277 void InstantController::HandleAutocompleteResults( 287 void InstantController::HandleAutocompleteResults(
278 const std::vector<AutocompleteProvider*>& providers) { 288 const std::vector<AutocompleteProvider*>& providers) {
279 if (mode_ != EXTENDED || !GetPreviewContents()) 289 if (mode_ != EXTENDED || !GetPreviewContents())
280 return; 290 return;
281 291
282 std::vector<InstantAutocompleteResult> results; 292 std::vector<InstantAutocompleteResult> results;
283 for (ACProviders::const_iterator provider = providers.begin(); 293 for (ACProviders::const_iterator provider = providers.begin();
284 provider != providers.end(); ++provider) { 294 provider != providers.end(); ++provider) {
285 for (ACMatches::const_iterator match = (*provider)->matches().begin(); 295 for (ACMatches::const_iterator match = (*provider)->matches().begin();
286 match != (*provider)->matches().end(); ++match) { 296 match != (*provider)->matches().end(); ++match) {
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 if (!stale_loader_timer_.IsRunning()) 719 if (!stale_loader_timer_.IsRunning())
710 OnStaleLoader(); 720 OnStaleLoader();
711 } 721 }
712 722
713 void InstantController::DeleteLoader() { 723 void InstantController::DeleteLoader() {
714 last_full_text_.clear(); 724 last_full_text_.clear();
715 last_user_text_.clear(); 725 last_user_text_.clear();
716 last_verbatim_ = false; 726 last_verbatim_ = false;
717 last_suggestion_ = InstantSuggestion(); 727 last_suggestion_ = InstantSuggestion();
718 last_match_was_search_ = false; 728 last_match_was_search_ = false;
719 last_omnibox_bounds_ = gfx::Rect(); 729 last_popup_bounds_ = gfx::Rect();
720 url_for_history_ = GURL(); 730 url_for_history_ = GURL();
721 if (GetPreviewContents()) 731 if (GetPreviewContents())
722 model_.SetPreviewState(InstantModel::NOT_READY, 0, INSTANT_SIZE_PERCENT); 732 model_.SetPreviewState(InstantModel::NOT_READY, 0, INSTANT_SIZE_PERCENT);
723 733
724 // Schedule the deletion for later, since we may have gotten here from a call 734 // Schedule the deletion for later, since we may have gotten here from a call
725 // within a |loader_| method (i.e., it's still on the stack). If we deleted 735 // within a |loader_| method (i.e., it's still on the stack). If we deleted
726 // the loader immediately, things would still be fine so long as the caller 736 // the loader immediately, things would still be fine so long as the caller
727 // doesn't access any instance members after we return, but why rely on that? 737 // doesn't access any instance members after we return, but why rely on that?
728 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release()); 738 MessageLoop::current()->DeleteSoon(FROM_HERE, loader_.release());
729 } 739 }
730 740
731 void InstantController::Show(InstantShownReason reason, 741 void InstantController::Show(InstantShownReason reason,
732 int height, 742 int height,
733 InstantSizeUnits units) { 743 InstantSizeUnits units) {
734 // Must be on NTP to show NTP content. 744 // Must be on NTP to show NTP content.
735 if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT && !active_tab_is_ntp_) 745 if (reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT && !active_tab_is_ntp_)
736 return; 746 return;
737 747
738 // Must have updated omnibox after most recent Hide() to show suggestions. 748 // Must have updated omnibox after most recent Hide() to show suggestions.
739 if (reason == INSTANT_SHOWN_QUERY_SUGGESTIONS && 749 if (reason == INSTANT_SHOWN_QUERY_SUGGESTIONS &&
740 model_.preview_state() == InstantModel::NOT_READY) 750 model_.preview_state() == InstantModel::NOT_READY)
741 return; 751 return;
742 752
743 model_.SetPreviewState(GetNewPreviewState(reason), height, units); 753 model_.SetPreviewState(GetNewPreviewState(reason), height, units);
744 } 754 }
745 755
746 void InstantController::SendBoundsToPage() { 756 void InstantController::SendBoundsToPage() {
747 if (last_omnibox_bounds_ == omnibox_bounds_ || 757 if (last_popup_bounds_ == popup_bounds_ ||
748 model_.preview_state() == InstantModel::NOT_READY || 758 model_.preview_state() == InstantModel::NOT_READY ||
749 !GetPreviewContents() || loader_->IsPointerDownFromActivate()) 759 !GetPreviewContents() || loader_->IsPointerDownFromActivate())
750 return; 760 return;
751 761
752 last_omnibox_bounds_ = omnibox_bounds_; 762 last_popup_bounds_ = popup_bounds_;
753 gfx::Rect preview_bounds = browser_->GetInstantBounds(); 763 gfx::Rect preview_bounds = browser_->GetInstantBounds();
754 gfx::Rect intersection = gfx::IntersectRects(omnibox_bounds_, preview_bounds); 764 gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds);
755 765
756 // Translate into window coordinates. 766 // Translate into window coordinates.
757 if (!intersection.IsEmpty()) { 767 if (!intersection.IsEmpty()) {
758 intersection.Offset(-preview_bounds.origin().x(), 768 intersection.Offset(-preview_bounds.origin().x(),
759 -preview_bounds.origin().y()); 769 -preview_bounds.origin().y());
760 } 770 }
761 771
762 // In the current Chrome UI, these must always be true so they sanity check 772 // In the current Chrome UI, these must always be true so they sanity check
763 // the above operations. In a future UI, these may be removed or adjusted. 773 // the above operations. In a future UI, these may be removed or adjusted.
764 // There is no point in sanity-checking |intersection.y()| because the omnibox 774 // There is no point in sanity-checking |intersection.y()| because the omnibox
765 // can be placed anywhere vertically relative to the preview (for example, in 775 // can be placed anywhere vertically relative to the preview (for example, in
766 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). 776 // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds).
767 DCHECK_LE(0, intersection.x()); 777 DCHECK_LE(0, intersection.x());
768 DCHECK_LE(0, intersection.width()); 778 DCHECK_LE(0, intersection.width());
769 DCHECK_LE(0, intersection.height()); 779 DCHECK_LE(0, intersection.height());
770 780
771 loader_->SetOmniboxBounds(intersection); 781 loader_->SetPopupBounds(intersection);
772 } 782 }
773 783
774 bool InstantController::GetInstantURL(const TemplateURL* template_url, 784 bool InstantController::GetInstantURL(const TemplateURL* template_url,
775 const GURL& tab_url, 785 const GURL& tab_url,
776 std::string* instant_url) const { 786 std::string* instant_url) const {
777 CommandLine* command_line = CommandLine::ForCurrentProcess(); 787 CommandLine* command_line = CommandLine::ForCurrentProcess();
778 if (command_line->HasSwitch(switches::kInstantURL)) { 788 if (command_line->HasSwitch(switches::kInstantURL)) {
779 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL); 789 *instant_url = command_line->GetSwitchValueASCII(switches::kInstantURL);
780 return template_url != NULL; 790 return template_url != NULL;
781 } 791 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
816 } 826 }
817 827
818 std::map<std::string, int>::const_iterator iter = 828 std::map<std::string, int>::const_iterator iter =
819 blacklisted_urls_.find(*instant_url); 829 blacklisted_urls_.find(*instant_url);
820 if (iter != blacklisted_urls_.end() && 830 if (iter != blacklisted_urls_.end() &&
821 iter->second > kMaxInstantSupportFailures) 831 iter->second > kMaxInstantSupportFailures)
822 return false; 832 return false;
823 833
824 return true; 834 return true;
825 } 835 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698