diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 19:31:30 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-01 19:31:30 +0000 |
commit | 4ab8cebe271e942522ddf739102e6211c1325565 (patch) | |
tree | ce22f1c57eabc1231d77b4b1a513634f19dd4e89 /chrome/browser/views/autocomplete | |
parent | c9d7c211e90e2f811a03d25542afb4302c47525e (diff) | |
download | chromium_src-4ab8cebe271e942522ddf739102e6211c1325565.zip chromium_src-4ab8cebe271e942522ddf739102e6211c1325565.tar.gz chromium_src-4ab8cebe271e942522ddf739102e6211c1325565.tar.bz2 |
Make pressing <esc> while dragging in the omnibox correctly cancel dragging. Original patch by Philippe Beaudoin (see http://codereview.chromium.org/554143 ), r=me, tweaked.
BUG=33460
TEST=Write goog in the omnibox, drag around, while pressing the left mouse button hit ESC. The selection should return to the first entry and not move as you continue to drag.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@37724 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views/autocomplete')
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc | 12 | ||||
-rw-r--r-- | chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h | 9 |
2 files changed, 19 insertions, 2 deletions
diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc index 5e2a91d..ef89905 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.cc @@ -562,6 +562,7 @@ AutocompletePopupContentsView::AutocompletePopupContentsView( edit_view_(edit_view), bubble_positioner_(bubble_positioner), result_font_(font.DeriveFont(kEditFontAdjust)), + ignore_mouse_drag_(false), ALLOW_THIS_IN_INITIALIZER_LIST(size_animation_(this)) { // The following little dance is required because set_border() requires a // pointer to a non-const object. @@ -659,6 +660,10 @@ void AutocompletePopupContentsView::PaintUpdatesNow() { // TODO(beng): remove this from the interface. } +void AutocompletePopupContentsView::OnDragCanceled() { + ignore_mouse_drag_ = true; +} + AutocompletePopupModel* AutocompletePopupContentsView::GetModel() { return model_.get(); } @@ -765,6 +770,7 @@ void AutocompletePopupContentsView::OnMouseExited( bool AutocompletePopupContentsView::OnMousePressed( const views::MouseEvent& event) { + ignore_mouse_drag_ = false; // See comment on |ignore_mouse_drag_| in header. if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { size_t index = GetIndexForPoint(event.location()); model_->SetHoveredLine(index); @@ -777,8 +783,10 @@ bool AutocompletePopupContentsView::OnMousePressed( void AutocompletePopupContentsView::OnMouseReleased( const views::MouseEvent& event, bool canceled) { - if (canceled) + if (canceled || ignore_mouse_drag_) { + ignore_mouse_drag_ = false; return; + } size_t index = GetIndexForPoint(event.location()); if (event.IsOnlyMiddleMouseButton()) @@ -792,7 +800,7 @@ bool AutocompletePopupContentsView::OnMouseDragged( if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) { size_t index = GetIndexForPoint(event.location()); model_->SetHoveredLine(index); - if (HasMatchAt(index) && event.IsLeftMouseButton()) + if (!ignore_mouse_drag_ && HasMatchAt(index) && event.IsLeftMouseButton()) model_->SetSelectedLine(index, false); } return true; diff --git a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h index 7e83d2f..553a75a 100644 --- a/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h +++ b/chrome/browser/views/autocomplete/autocomplete_popup_contents_view.h @@ -57,6 +57,7 @@ class AutocompletePopupContentsView : public views::View, virtual void InvalidateLine(size_t line); virtual void UpdatePopupAppearance(); virtual void PaintUpdatesNow(); + virtual void OnDragCanceled(); virtual AutocompletePopupModel* GetModel(); // Overridden from AutocompleteResultViewModel: @@ -131,6 +132,14 @@ class AutocompletePopupContentsView : public views::View, // by the edit that created us. gfx::Font result_font_; + // If the user cancels a dragging action (i.e. by pressing ESC), we don't have + // a convenient way to release mouse capture. Instead we use this flag to + // simply ignore all remaining drag events, and the eventual mouse release + // event. Since OnDragCanceled() can be called when we're not dragging, this + // flag is reset to false on a mouse pressed event, to make sure we don't + // erroneously ignore the next drag. + bool ignore_mouse_drag_; + // The popup sizes vertically using an animation when the popup is getting // shorter (not larger, that makes it look "slow"). SlideAnimation size_animation_; |