Index: chrome/browser/ui/views/frame/browser_root_view.cc |
diff --git a/chrome/browser/ui/views/frame/browser_root_view.cc b/chrome/browser/ui/views/frame/browser_root_view.cc |
index 8eaba179f86a695221aa7829c3ef50b382a47018..7f0b5bd4672a5cade3d67330fe2051d07c6d335e 100644 |
--- a/chrome/browser/ui/views/frame/browser_root_view.cc |
+++ b/chrome/browser/ui/views/frame/browser_root_view.cc |
@@ -28,7 +28,9 @@ BrowserRootView::BrowserRootView(BrowserView* browser_view, |
views::Widget* widget) |
: views::internal::RootView(widget), |
browser_view_(browser_view), |
- forwarding_to_tab_strip_(false) { } |
+ forwarding_to_tab_strip_(false), |
+ scroll_amount_x_(0), |
+ scroll_amount_y_(0) {} |
bool BrowserRootView::GetDropFormats( |
int* formats, |
@@ -130,19 +132,35 @@ bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
if (tabstrip()->Contains(hit_view) || |
hittest == HTCAPTION || |
hittest == HTTOP) { |
- int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ? |
- event.y_offset() : event.x_offset(); |
+ scroll_amount_x_ += event.x_offset(); |
+ scroll_amount_y_ += event.y_offset(); |
+ |
+ // Number of integer scroll events that have passed in each direction |
+ int whole_scroll_amount_x = round( |
+ (double)scroll_amount_x_ / (double)ui::MouseWheelEvent::kWheelDelta); |
+ int whole_scroll_amount_y = round( |
+ (double)scroll_amount_y_ / (double)ui::MouseWheelEvent::kWheelDelta); |
sadrul
2016/01/05 16:46:23
Use std::lround() (like in https://codereview.chro
Will Shackleton
2016/01/05 21:27:02
Done.
|
+ |
+ scroll_amount_x_ -= |
+ whole_scroll_amount_x * ui::MouseWheelEvent::kWheelDelta; |
+ scroll_amount_y_ -= |
+ whole_scroll_amount_y * ui::MouseWheelEvent::kWheelDelta; |
+ |
+ // Count a scroll in either axis - summing the axes works for this. |
+ int whole_scroll_offset = whole_scroll_amount_x + whole_scroll_amount_y; |
+ |
Browser* browser = browser_view_->browser(); |
TabStripModel* model = browser->tab_strip_model(); |
// Switch to the next tab only if not at the end of the tab-strip. |
- if (scroll_offset < 0 && model->active_index() + 1 < model->count()) { |
+ if (whole_scroll_offset < 0 && |
+ model->active_index() + 1 < model->count()) { |
chrome::SelectNextTab(browser); |
return true; |
} |
// Switch to the previous tab only if not at the beginning of the |
// tab-strip. |
- if (scroll_offset > 0 && model->active_index() > 0) { |
+ if (whole_scroll_offset > 0 && model->active_index() > 0) { |
chrome::SelectPreviousTab(browser); |
return true; |
} |
@@ -151,6 +169,13 @@ bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
return RootView::OnMouseWheel(event); |
} |
+void BrowserRootView::OnMouseExited(const ui::MouseEvent& event) { |
+ // Reset such that the tab switch always occurs halfway through a smooth |
+ // scroll |
+ scroll_amount_x_ = 0; |
+ scroll_amount_y_ = 0; |
+} |
+ |
void BrowserRootView::OnEventProcessingStarted(ui::Event* event) { |
if (event->IsGestureEvent()) { |
ui::GestureEvent* gesture_event = event->AsGestureEvent(); |