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

Side by Side 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: Disabled coalescing for all scroll events Created 5 years 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/views/frame/browser_root_view.h" 5 #include "chrome/browser/ui/views/frame/browser_root_view.h"
6 6
7 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 7 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
8 #include "chrome/browser/defaults.h" 8 #include "chrome/browser/defaults.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser_commands.h" 10 #include "chrome/browser/ui/browser_commands.h"
(...skipping 10 matching lines...) Expand all
21 #include "ui/base/hit_test.h" 21 #include "ui/base/hit_test.h"
22 22
23 // static 23 // static
24 const char BrowserRootView::kViewClassName[] = 24 const char BrowserRootView::kViewClassName[] =
25 "browser/ui/views/frame/BrowserRootView"; 25 "browser/ui/views/frame/BrowserRootView";
26 26
27 BrowserRootView::BrowserRootView(BrowserView* browser_view, 27 BrowserRootView::BrowserRootView(BrowserView* browser_view,
28 views::Widget* widget) 28 views::Widget* widget)
29 : views::internal::RootView(widget), 29 : views::internal::RootView(widget),
30 browser_view_(browser_view), 30 browser_view_(browser_view),
31 forwarding_to_tab_strip_(false) { } 31 forwarding_to_tab_strip_(false),
32 scroll_amount_x_(0),
33 scroll_amount_y_(0) {}
32 34
33 bool BrowserRootView::GetDropFormats( 35 bool BrowserRootView::GetDropFormats(
34 int* formats, 36 int* formats,
35 std::set<ui::Clipboard::FormatType>* format_types) { 37 std::set<ui::Clipboard::FormatType>* format_types) {
36 if (tabstrip() && tabstrip()->visible()) { 38 if (tabstrip() && tabstrip()->visible()) {
37 *formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING; 39 *formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING;
38 return true; 40 return true;
39 } 41 }
40 return false; 42 return false;
41 } 43 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { 125 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
124 if (browser_defaults::kScrollEventChangesTab) { 126 if (browser_defaults::kScrollEventChangesTab) {
125 // Switch to the left/right tab if the wheel-scroll happens over the 127 // Switch to the left/right tab if the wheel-scroll happens over the
126 // tabstrip, or the empty space beside the tabstrip. 128 // tabstrip, or the empty space beside the tabstrip.
127 views::View* hit_view = GetEventHandlerForPoint(event.location()); 129 views::View* hit_view = GetEventHandlerForPoint(event.location());
128 int hittest = 130 int hittest =
129 GetWidget()->non_client_view()->NonClientHitTest(event.location()); 131 GetWidget()->non_client_view()->NonClientHitTest(event.location());
130 if (tabstrip()->Contains(hit_view) || 132 if (tabstrip()->Contains(hit_view) ||
131 hittest == HTCAPTION || 133 hittest == HTCAPTION ||
132 hittest == HTTOP) { 134 hittest == HTTOP) {
133 int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ? 135 scroll_amount_x_ += event.x_offset();
134 event.y_offset() : event.x_offset(); 136 scroll_amount_y_ += event.y_offset();
137 int scroll_offset = abs(scroll_amount_y_) > abs(scroll_amount_x_)
138 ? scroll_amount_y_
139 : scroll_amount_x_;
140
141 // Number of integer scroll events that have passed
142 int whole_scroll_offset = round((double)scroll_offset /
143 (double)ui::MouseWheelEvent::kWheelDelta);
144
145 if (whole_scroll_offset != 0) {
146 // Re-adjust back towards 0
147 if (abs(scroll_amount_y_) > abs(scroll_amount_x_)) {
148 scroll_amount_y_ -=
149 whole_scroll_offset * ui::MouseWheelEvent::kWheelDelta;
150 } else {
151 scroll_amount_x_ -=
152 whole_scroll_offset * ui::MouseWheelEvent::kWheelDelta;
153 }
154 }
155
135 Browser* browser = browser_view_->browser(); 156 Browser* browser = browser_view_->browser();
136 TabStripModel* model = browser->tab_strip_model(); 157 TabStripModel* model = browser->tab_strip_model();
137 // Switch to the next tab only if not at the end of the tab-strip. 158 // Switch to the next tab only if not at the end of the tab-strip.
138 if (scroll_offset < 0 && model->active_index() + 1 < model->count()) { 159 if (whole_scroll_offset < 0 &&
160 model->active_index() + 1 < model->count()) {
139 chrome::SelectNextTab(browser); 161 chrome::SelectNextTab(browser);
140 return true; 162 return true;
141 } 163 }
142 164
143 // Switch to the previous tab only if not at the beginning of the 165 // Switch to the previous tab only if not at the beginning of the
144 // tab-strip. 166 // tab-strip.
145 if (scroll_offset > 0 && model->active_index() > 0) { 167 if (whole_scroll_offset > 0 && model->active_index() > 0) {
146 chrome::SelectPreviousTab(browser); 168 chrome::SelectPreviousTab(browser);
147 return true; 169 return true;
148 } 170 }
149 } 171 }
150 } 172 }
151 return RootView::OnMouseWheel(event); 173 return RootView::OnMouseWheel(event);
152 } 174 }
153 175
176 void BrowserRootView::OnMouseExited(const ui::MouseEvent& event) {
177 // Reset such that the tab switch always occurs halfway through a smooth
178 // scroll
179 scroll_amount_x_ = 0;
180 scroll_amount_y_ = 0;
181 }
182
154 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) { 183 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) {
155 if (event->IsGestureEvent()) { 184 if (event->IsGestureEvent()) {
156 ui::GestureEvent* gesture_event = event->AsGestureEvent(); 185 ui::GestureEvent* gesture_event = event->AsGestureEvent();
157 if (gesture_event->type() == ui::ET_GESTURE_TAP && 186 if (gesture_event->type() == ui::ET_GESTURE_TAP &&
158 gesture_event->location().y() <= 0 && 187 gesture_event->location().y() <= 0 &&
159 gesture_event->location().x() <= browser_view_->GetBounds().width()) { 188 gesture_event->location().x() <= browser_view_->GetBounds().width()) {
160 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP); 189 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP);
161 } 190 }
162 } 191 }
163 192
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 browser_view_->browser()->profile())->Classify( 233 browser_view_->browser()->profile())->Classify(
205 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match, 234 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match,
206 nullptr); 235 nullptr);
207 if (!match.destination_url.is_valid()) 236 if (!match.destination_url.is_valid())
208 return false; 237 return false;
209 238
210 if (url) 239 if (url)
211 *url = match.destination_url; 240 *url = match.destination_url;
212 return true; 241 return true;
213 } 242 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698