Chromium Code Reviews| 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..61bf9d14b035afc2033239f62d7a55f7383b528c 100644 |
| --- a/chrome/browser/ui/views/frame/browser_root_view.cc |
| +++ b/chrome/browser/ui/views/frame/browser_root_view.cc |
| @@ -4,6 +4,8 @@ |
| #include "chrome/browser/ui/views/frame/browser_root_view.h" |
| +#include <cmath> |
| + |
| #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| #include "chrome/browser/defaults.h" |
| #include "chrome/browser/profiles/profile.h" |
| @@ -28,7 +30,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 +134,37 @@ 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 |
|
msw
2016/01/09 05:23:57
nit: trailing period.
Will Shackleton
2016/01/10 14:18:42
Done.
|
| + int whole_scroll_amount_x = |
| + std::lround(static_cast<double>(scroll_amount_x_) / |
| + ui::MouseWheelEvent::kWheelDelta); |
| + int whole_scroll_amount_y = |
| + std::lround(static_cast<double>(scroll_amount_y_) / |
| + ui::MouseWheelEvent::kWheelDelta); |
| + |
| + scroll_amount_x_ -= |
|
msw
2016/01/09 05:23:57
What's going on here? Can you add an explanatory c
Will Shackleton
2016/01/10 14:18:42
Done. Since the incoming scroll events are for sma
|
| + 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; |
|
msw
2016/01/09 05:23:57
Won't positive values in x cancel out negative val
Will Shackleton
2016/01/10 14:18:42
This is what Chrome currently does - there's no ni
|
| + |
| 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 +173,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 |
|
msw
2016/01/09 05:23:57
nit: trailing period
Will Shackleton
2016/01/10 14:18:42
Done.
|
| + scroll_amount_x_ = 0; |
|
msw
2016/01/09 05:23:57
nit: would a gfx::Vector2D be cleaner than a pair
Will Shackleton
2016/01/10 14:18:42
|Length| doesn't help as far as I can see - we sti
|
| + scroll_amount_y_ = 0; |
| +} |
| + |
| void BrowserRootView::OnEventProcessingStarted(ui::Event* event) { |
| if (event->IsGestureEvent()) { |
| ui::GestureEvent* gesture_event = event->AsGestureEvent(); |