Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(8794)

Unified Diff: chrome/browser/ui/views/frame/browser_root_view.cc

Issue 688253002: Implemented smooth scrolling using xinput2 in X11. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Applied comments, moved zoom handling to issue 1554253004 Created 4 years, 12 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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();

Powered by Google App Engine
This is Rietveld 408576698