diff options
Diffstat (limited to 'chrome/browser/instant')
-rw-r--r-- | chrome/browser/instant/instant_controller.cc | 34 | ||||
-rw-r--r-- | chrome/browser/instant/instant_controller.h | 19 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.cc | 52 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader.h | 8 | ||||
-rw-r--r-- | chrome/browser/instant/instant_loader_delegate.h | 5 |
5 files changed, 64 insertions, 54 deletions
diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index e0f7125..51b26cc 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -38,7 +38,7 @@ InstantController::InstantController(InstantControllerDelegate* delegate, : delegate_(delegate), is_displayable_(false), is_out_of_date_(true), - commit_on_mouse_up_(false), + commit_on_pointer_release_(false), last_transition_type_(content::PAGE_TRANSITION_LINK), ALLOW_THIS_IN_INITIALIZER_LIST(weak_factory_(this)), mode_(mode) { @@ -103,7 +103,7 @@ bool InstantController::Update(const AutocompleteMatch& match, suggested_text->clear(); is_out_of_date_ = false; - commit_on_mouse_up_ = false; + commit_on_pointer_release_ = false; last_transition_type_ = match.transition; last_url_ = match.destination_url; last_user_text_ = user_text; @@ -171,7 +171,7 @@ void InstantController::DestroyPreviewContents() { void InstantController::Hide() { is_out_of_date_ = true; - commit_on_mouse_up_ = false; + commit_on_pointer_release_ = false; if (is_displayable_) { is_displayable_ = false; delegate_->HideInstant(); @@ -241,25 +241,25 @@ bool InstantController::CommitIfCurrent() { return false; } -void InstantController::SetCommitOnMouseUp() { - commit_on_mouse_up_ = true; +void InstantController::SetCommitOnPointerRelease() { + commit_on_pointer_release_ = true; } -bool InstantController::IsMouseDownFromActivate() { +bool InstantController::IsPointerDownFromActivate() { DCHECK(loader_.get()); - return loader_->IsMouseDownFromActivate(); + return loader_->IsPointerDownFromActivate(); } #if defined(OS_MACOSX) void InstantController::OnAutocompleteLostFocus( gfx::NativeView view_gaining_focus) { - // If |IsMouseDownFromActivate()| returns false, the RenderWidgetHostView did - // not receive a mouseDown event. Therefore, we should destroy the preview. - // Otherwise, the RWHV was clicked, so we commit the preview. - if (!IsCurrent() || !IsMouseDownFromActivate()) + // If |IsPointerDownFromActivate()| returns false, the RenderWidgetHostView + // did not receive a mouseDown event. Therefore, we should destroy the + // preview. Otherwise, the RWHV was clicked, so we commit the preview. + if (!IsCurrent() || !IsPointerDownFromActivate()) DestroyPreviewContents(); else - SetCommitOnMouseUp(); + SetCommitOnPointerRelease(); } #else void InstantController::OnAutocompleteLostFocus( @@ -298,7 +298,7 @@ void InstantController::OnAutocompleteLostFocus( // Focus is going to the renderer. if (rwhv->GetNativeView() == view_gaining_focus || tab_view == view_gaining_focus) { - if (!IsMouseDownFromActivate()) { + if (!IsPointerDownFromActivate()) { // If the mouse is not down, focus is not going to the renderer. Someone // else moved focus and we shouldn't commit. DestroyPreviewContents(); @@ -308,7 +308,7 @@ void InstantController::OnAutocompleteLostFocus( // We're showing instant results. As instant results may shift when // committing we commit on the mouse up. This way a slow click still works // fine. - SetCommitOnMouseUp(); + SetCommitOnPointerRelease(); return; } @@ -358,7 +358,7 @@ TabContents* InstantController::ReleasePreviewContents( ClearBlacklist(); is_out_of_date_ = true; is_displayable_ = false; - commit_on_mouse_up_ = false; + commit_on_pointer_release_ = false; omnibox_bounds_ = gfx::Rect(); loader_.reset(); return tab; @@ -392,8 +392,8 @@ gfx::Rect InstantController::GetInstantBounds() { return delegate_->GetInstantBounds(); } -bool InstantController::ShouldCommitInstantOnMouseUp() { - return commit_on_mouse_up_; +bool InstantController::ShouldCommitInstantOnPointerRelease() { + return commit_on_pointer_release_; } void InstantController::CommitInstantLoader(InstantLoader* loader) { diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 8f2a844..b6ad248 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -128,15 +128,14 @@ class InstantController : public InstantLoaderDelegate { // Returns false if there is no instant preview showing. bool CommitIfCurrent(); - // Sets InstantController so that when the mouse is released the preview is - // committed. - void SetCommitOnMouseUp(); + // Sets InstantController so that when the mouse is released or the + // touch-gesture ends, the preview is committed. + void SetCommitOnPointerRelease(); - bool commit_on_mouse_up() const { return commit_on_mouse_up_; } + bool commit_on_pointer_release() const { return commit_on_pointer_release_; } - // Returns true if the mouse is down as the result of activating the preview - // content. - bool IsMouseDownFromActivate(); + // Calls through to method of same name on loader. + bool IsPointerDownFromActivate(); // The autocomplete edit that was initiating the current instant session has // lost focus. Commit or discard the preview accordingly. @@ -179,7 +178,7 @@ class InstantController : public InstantLoaderDelegate { const string16& text, InstantCompleteBehavior behavior) OVERRIDE; virtual gfx::Rect GetInstantBounds() OVERRIDE; - virtual bool ShouldCommitInstantOnMouseUp() OVERRIDE; + virtual bool ShouldCommitInstantOnPointerRelease() OVERRIDE; virtual void CommitInstantLoader(InstantLoader* loader) OVERRIDE; virtual void InstantLoaderDoesntSupportInstant( InstantLoader* loader) OVERRIDE; @@ -243,8 +242,8 @@ class InstantController : public InstantLoaderDelegate { // See description above setter. gfx::Rect omnibox_bounds_; - // See description above CommitOnMouseUp. - bool commit_on_mouse_up_; + // See descritopn above for SetCommitOnPointerRelease. + bool commit_on_pointer_release_; // See description above getter. content::PageTransition last_transition_type_; diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 195495f..a6fae58 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -197,8 +197,8 @@ class InstantLoader::WebContentsDelegateImpl // Invoked when the preview paints. Invokes PreviewPainted on the loader. void PreviewPainted(); - bool is_mouse_down_from_activate() const { - return is_mouse_down_from_activate_; + bool is_pointer_down_from_activate() const { + return is_pointer_down_from_activate_; } void set_user_typed_before_load() { user_typed_before_load_ = true; } @@ -240,7 +240,9 @@ class InstantLoader::WebContentsDelegateImpl int request_id, const std::string& request_method) OVERRIDE; virtual void HandleMouseUp() OVERRIDE; - virtual void HandleMouseActivate() OVERRIDE; + virtual void HandlePointerActivate() OVERRIDE; + virtual void HandleGestureBegin() OVERRIDE; + virtual void HandleGestureEnd() OVERRIDE; virtual bool OnGoToEntryOffset(int offset) OVERRIDE; virtual bool ShouldAddNavigationToHistory( const history::HistoryAddPageArgs& add_page_args, @@ -278,7 +280,8 @@ class InstantLoader::WebContentsDelegateImpl // instant. void OnInstantSupportDetermined(int32 page_id, bool result); - void CommitFromMouseReleaseIfNecessary(); + // Commits, if applicable, on mouse is released, or a gesture ends. + void CommitOnPointerReleaseIfNecessary(); InstantLoader* loader_; @@ -298,8 +301,8 @@ class InstantLoader::WebContentsDelegateImpl // NEW_PAGE navigation we don't add history items to add_page_vector_. bool waiting_for_new_page_; - // True if the mouse is down from an activate. - bool is_mouse_down_from_activate_; + // True if mouse-pointer or a touch-pointer is down from an activate. + bool is_pointer_down_from_activate_; // True if the user typed in the search box before the page loaded. bool user_typed_before_load_; @@ -313,7 +316,7 @@ InstantLoader::WebContentsDelegateImpl::WebContentsDelegateImpl( loader_(loader), registered_render_widget_host_(NULL), waiting_for_new_page_(true), - is_mouse_down_from_activate_(false), + is_pointer_down_from_activate_(false), user_typed_before_load_(false) { DCHECK(loader->preview_contents()); registrar_.Add(this, content::NOTIFICATION_INTERSTITIAL_ATTACHED, @@ -492,11 +495,11 @@ void InstantLoader::WebContentsDelegateImpl::WebContentsFocused( } void InstantLoader::WebContentsDelegateImpl::LostCapture() { - CommitFromMouseReleaseIfNecessary(); + CommitOnPointerReleaseIfNecessary(); } void InstantLoader::WebContentsDelegateImpl::DragEnded() { - CommitFromMouseReleaseIfNecessary(); + CommitOnPointerReleaseIfNecessary(); } bool InstantLoader::WebContentsDelegateImpl::CanDownload( @@ -508,11 +511,18 @@ bool InstantLoader::WebContentsDelegateImpl::CanDownload( } void InstantLoader::WebContentsDelegateImpl::HandleMouseUp() { - CommitFromMouseReleaseIfNecessary(); + CommitOnPointerReleaseIfNecessary(); } -void InstantLoader::WebContentsDelegateImpl::HandleMouseActivate() { - is_mouse_down_from_activate_ = true; +void InstantLoader::WebContentsDelegateImpl::HandlePointerActivate() { + is_pointer_down_from_activate_ = true; +} + +void InstantLoader::WebContentsDelegateImpl::HandleGestureBegin() { +} + +void InstantLoader::WebContentsDelegateImpl::HandleGestureEnd() { + CommitOnPointerReleaseIfNecessary(); } bool InstantLoader::WebContentsDelegateImpl::OnGoToEntryOffset(int offset) { @@ -623,10 +633,10 @@ void InstantLoader::WebContentsDelegateImpl::OnInstantSupportDetermined( } void InstantLoader::WebContentsDelegateImpl - ::CommitFromMouseReleaseIfNecessary() { - bool was_down = is_mouse_down_from_activate_; - is_mouse_down_from_activate_ = false; - if (was_down && loader_->ShouldCommitInstantOnMouseUp()) + ::CommitOnPointerReleaseIfNecessary() { + bool was_down = is_pointer_down_from_activate_; + is_pointer_down_from_activate_ = false; + if (was_down && loader_->ShouldCommitInstantOnPointerRelease()) loader_->CommitInstantLoader(); } @@ -758,7 +768,7 @@ void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { return; // Don't update the page while the mouse is down. http://crbug.com/71952 - if (IsMouseDownFromActivate()) + if (IsPointerDownFromActivate()) return; omnibox_bounds_ = bounds; @@ -779,9 +789,9 @@ void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { } } -bool InstantLoader::IsMouseDownFromActivate() { +bool InstantLoader::IsPointerDownFromActivate() { return preview_tab_contents_delegate_.get() && - preview_tab_contents_delegate_->is_mouse_down_from_activate(); + preview_tab_contents_delegate_->is_pointer_down_from_activate(); } TabContents* InstantLoader::ReleasePreviewContents( @@ -854,8 +864,8 @@ TabContents* InstantLoader::ReleasePreviewContents( return preview_contents_.release(); } -bool InstantLoader::ShouldCommitInstantOnMouseUp() { - return delegate_->ShouldCommitInstantOnMouseUp(); +bool InstantLoader::ShouldCommitInstantOnPointerRelease() { + return delegate_->ShouldCommitInstantOnPointerRelease(); } void InstantLoader::CommitInstantLoader() { diff --git a/chrome/browser/instant/instant_loader.h b/chrome/browser/instant/instant_loader.h index 38e1f1d..43f74fb 100644 --- a/chrome/browser/instant/instant_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -69,9 +69,9 @@ class InstantLoader : public content::NotificationObserver { // when showing results for a search provider that supports instant. void SetOmniboxBounds(const gfx::Rect& bounds); - // Returns true if the mouse is down as the result of activating the preview - // content. - bool IsMouseDownFromActivate(); + // Returns true if the mouse or a touch-pointer is down as the result of + // activating the preview content. + bool IsPointerDownFromActivate(); // Releases the preview TabContents passing ownership to the caller. // This is intended to be called when the preview TabContents is @@ -83,7 +83,7 @@ class InstantLoader : public content::NotificationObserver { TabContents* tab_contents); // Calls through to method of same name on delegate. - bool ShouldCommitInstantOnMouseUp(); + bool ShouldCommitInstantOnPointerRelease(); void CommitInstantLoader(); // Preload |template_url|'s instant URL, if the loader doesn't already have diff --git a/chrome/browser/instant/instant_loader_delegate.h b/chrome/browser/instant/instant_loader_delegate.h index bf393a1..9de5171 100644 --- a/chrome/browser/instant/instant_loader_delegate.h +++ b/chrome/browser/instant/instant_loader_delegate.h @@ -31,8 +31,9 @@ class InstantLoaderDelegate { // Returns the bounds of instant. virtual gfx::Rect GetInstantBounds() = 0; - // Returns true if instant should be committed on mouse up. - virtual bool ShouldCommitInstantOnMouseUp() = 0; + // Returns true if instant should be committed on mouse up or at the end of a + // touch-gesture. + virtual bool ShouldCommitInstantOnPointerRelease() = 0; // Invoked when the the loader should be committed. virtual void CommitInstantLoader(InstantLoader* loader) = 0; |