summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 13:06:10 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-07 13:06:10 +0000
commit54acdbf5115fb8ff7484a822ee98af1615977da0 (patch)
tree11867565beacd1fa8f73a2887601d183d02795c4
parentdc211cf425bcee745bad2a175ab95ceacbb8223e (diff)
downloadchromium_src-54acdbf5115fb8ff7484a822ee98af1615977da0.zip
chromium_src-54acdbf5115fb8ff7484a822ee98af1615977da0.tar.gz
chromium_src-54acdbf5115fb8ff7484a822ee98af1615977da0.tar.bz2
autocomplete: Add support for gesture events.
It is possible to tap-down on the omnibox dropdown and scroll to change the selection, and then lift to open the selected page. BUG=124277 TEST=manually Review URL: https://chromiumcodereview.appspot.com/10537040 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140999 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc59
-rw-r--r--chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h12
2 files changed, 54 insertions, 17 deletions
diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
index afcbe29..7ab2c25 100644
--- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
+++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc
@@ -329,23 +329,15 @@ views::View* AutocompletePopupContentsView::GetEventHandlerForPoint(
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);
- if (HasMatchAt(index) && event.IsLeftMouseButton())
- model_->SetSelectedLine(index, false, false);
- }
+ if (event.IsLeftMouseButton() || event.IsMiddleMouseButton())
+ UpdateLineEvent(event, event.IsLeftMouseButton());
return true;
}
bool AutocompletePopupContentsView::OnMouseDragged(
const views::MouseEvent& event) {
- if (event.IsLeftMouseButton() || event.IsMiddleMouseButton()) {
- size_t index = GetIndexForPoint(event.location());
- model_->SetHoveredLine(index);
- if (!ignore_mouse_drag_ && HasMatchAt(index) && event.IsLeftMouseButton())
- model_->SetSelectedLine(index, false, false);
- }
+ if (event.IsLeftMouseButton() || event.IsMiddleMouseButton())
+ UpdateLineEvent(event, !ignore_mouse_drag_ && event.IsLeftMouseButton());
return true;
}
@@ -356,11 +348,10 @@ void AutocompletePopupContentsView::OnMouseReleased(
return;
}
- size_t index = GetIndexForPoint(event.location());
- if (event.IsOnlyMiddleMouseButton())
- OpenIndex(index, NEW_BACKGROUND_TAB);
- else if (event.IsOnlyLeftMouseButton())
- OpenIndex(index, CURRENT_TAB);
+ if (event.IsOnlyMiddleMouseButton() || event.IsOnlyLeftMouseButton()) {
+ OpenSelectedLine(event, event.IsOnlyLeftMouseButton() ? CURRENT_TAB :
+ NEW_BACKGROUND_TAB);
+ }
}
void AutocompletePopupContentsView::OnMouseCaptureLost() {
@@ -382,6 +373,24 @@ void AutocompletePopupContentsView::OnMouseExited(
model_->SetHoveredLine(AutocompletePopupModel::kNoMatch);
}
+ui::GestureStatus AutocompletePopupContentsView::OnGestureEvent(
+ const views::GestureEvent& event) {
+ switch (event.type()) {
+ case ui::ET_GESTURE_TAP_DOWN:
+ case ui::ET_GESTURE_SCROLL_BEGIN:
+ case ui::ET_GESTURE_SCROLL_UPDATE:
+ UpdateLineEvent(event, true);
+ break;
+ case ui::ET_GESTURE_TAP:
+ case ui::ET_GESTURE_SCROLL_END:
+ OpenSelectedLine(event, CURRENT_TAB);
+ break;
+ default:
+ return ui::GESTURE_STATUS_UNKNOWN;
+ }
+ return ui::GESTURE_STATUS_CONSUMED;
+}
+
////////////////////////////////////////////////////////////////////////////////
// AutocompletePopupContentsView, protected:
@@ -547,3 +556,19 @@ gfx::Rect AutocompletePopupContentsView::CalculateTargetBounds(int h) {
return bubble_border_->GetBounds(
location_bar_bounds, gfx::Size(location_bar_bounds.width(), h));
}
+
+void AutocompletePopupContentsView::UpdateLineEvent(
+ const views::LocatedEvent& event,
+ bool should_set_selected_line) {
+ size_t index = GetIndexForPoint(event.location());
+ model_->SetHoveredLine(index);
+ if (HasMatchAt(index) && should_set_selected_line)
+ model_->SetSelectedLine(index, false, false);
+}
+
+void AutocompletePopupContentsView::OpenSelectedLine(
+ const views::LocatedEvent& event,
+ WindowOpenDisposition disposition) {
+ size_t index = GetIndexForPoint(event.location());
+ OpenIndex(index, disposition);
+}
diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h
index e05f29f..a8f89cb 100644
--- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h
+++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.h
@@ -73,6 +73,8 @@ class AutocompletePopupContentsView : public views::View,
virtual void OnMouseMoved(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseEntered(const views::MouseEvent& event) OVERRIDE;
virtual void OnMouseExited(const views::MouseEvent& event) OVERRIDE;
+ virtual ui::GestureStatus OnGestureEvent(
+ const views::GestureEvent& event) OVERRIDE;
protected:
AutocompletePopupContentsView(const gfx::Font& font,
@@ -132,6 +134,16 @@ class AutocompletePopupContentsView : public views::View,
// match at the specified point.
size_t GetIndexForPoint(const gfx::Point& point);
+ // Processes a located event (e.g. mouse/gesture) and sets the selection/hover
+ // state of a line in the list.
+ void UpdateLineEvent(const views::LocatedEvent& event,
+ bool should_set_selected_line);
+
+ // Opens an entry from the list depending on the event and the selected
+ // disposition.
+ void OpenSelectedLine(const views::LocatedEvent& event,
+ WindowOpenDisposition disposition);
+
// Returns the target bounds given the specified content height.
gfx::Rect CalculateTargetBounds(int h);