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

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: Applied @msw's comments - renamed amount to remainder Created 4 years, 11 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/ui/views/frame/browser_root_view.h ('k') | ui/base/x/x11_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <cmath>
8
7 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" 9 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h"
8 #include "chrome/browser/defaults.h" 10 #include "chrome/browser/defaults.h"
9 #include "chrome/browser/profiles/profile.h" 11 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/browser_commands.h" 12 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" 13 #include "chrome/browser/ui/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/views/frame/browser_frame.h" 14 #include "chrome/browser/ui/views/frame/browser_frame.h"
13 #include "chrome/browser/ui/views/frame/browser_view.h" 15 #include "chrome/browser/ui/views/frame/browser_view.h"
14 #include "chrome/browser/ui/views/tabs/tab_strip.h" 16 #include "chrome/browser/ui/views/tabs/tab_strip.h"
15 #include "chrome/browser/ui/views/touch_uma/touch_uma.h" 17 #include "chrome/browser/ui/views/touch_uma/touch_uma.h"
16 #include "components/metrics/proto/omnibox_event.pb.h" 18 #include "components/metrics/proto/omnibox_event.pb.h"
17 #include "components/omnibox/browser/autocomplete_classifier.h" 19 #include "components/omnibox/browser/autocomplete_classifier.h"
18 #include "components/omnibox/browser/autocomplete_match.h" 20 #include "components/omnibox/browser/autocomplete_match.h"
19 #include "ui/base/dragdrop/drag_drop_types.h" 21 #include "ui/base/dragdrop/drag_drop_types.h"
20 #include "ui/base/dragdrop/os_exchange_data.h" 22 #include "ui/base/dragdrop/os_exchange_data.h"
21 #include "ui/base/hit_test.h" 23 #include "ui/base/hit_test.h"
22 24
23 // static 25 // static
24 const char BrowserRootView::kViewClassName[] = 26 const char BrowserRootView::kViewClassName[] =
25 "browser/ui/views/frame/BrowserRootView"; 27 "browser/ui/views/frame/BrowserRootView";
26 28
27 BrowserRootView::BrowserRootView(BrowserView* browser_view, 29 BrowserRootView::BrowserRootView(BrowserView* browser_view,
28 views::Widget* widget) 30 views::Widget* widget)
29 : views::internal::RootView(widget), 31 : views::internal::RootView(widget),
30 browser_view_(browser_view), 32 browser_view_(browser_view),
31 forwarding_to_tab_strip_(false) { } 33 forwarding_to_tab_strip_(false),
34 scroll_remainder_x_(0),
35 scroll_remainder_y_(0) {}
32 36
33 bool BrowserRootView::GetDropFormats( 37 bool BrowserRootView::GetDropFormats(
34 int* formats, 38 int* formats,
35 std::set<ui::Clipboard::FormatType>* format_types) { 39 std::set<ui::Clipboard::FormatType>* format_types) {
36 if (tabstrip() && tabstrip()->visible()) { 40 if (tabstrip() && tabstrip()->visible()) {
37 *formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING; 41 *formats = ui::OSExchangeData::URL | ui::OSExchangeData::STRING;
38 return true; 42 return true;
39 } 43 }
40 return false; 44 return false;
41 } 45 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { 127 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) {
124 if (browser_defaults::kScrollEventChangesTab) { 128 if (browser_defaults::kScrollEventChangesTab) {
125 // Switch to the left/right tab if the wheel-scroll happens over the 129 // Switch to the left/right tab if the wheel-scroll happens over the
126 // tabstrip, or the empty space beside the tabstrip. 130 // tabstrip, or the empty space beside the tabstrip.
127 views::View* hit_view = GetEventHandlerForPoint(event.location()); 131 views::View* hit_view = GetEventHandlerForPoint(event.location());
128 int hittest = 132 int hittest =
129 GetWidget()->non_client_view()->NonClientHitTest(event.location()); 133 GetWidget()->non_client_view()->NonClientHitTest(event.location());
130 if (tabstrip()->Contains(hit_view) || 134 if (tabstrip()->Contains(hit_view) ||
131 hittest == HTCAPTION || 135 hittest == HTCAPTION ||
132 hittest == HTTOP) { 136 hittest == HTTOP) {
133 int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ? 137 scroll_remainder_x_ += event.x_offset();
134 event.y_offset() : event.x_offset(); 138 scroll_remainder_y_ += event.y_offset();
139
140 // Number of integer scroll events that have passed in each direction.
141 int whole_scroll_amount_x =
142 std::lround(static_cast<double>(scroll_remainder_x_) /
143 ui::MouseWheelEvent::kWheelDelta);
144 int whole_scroll_amount_y =
145 std::lround(static_cast<double>(scroll_remainder_y_) /
146 ui::MouseWheelEvent::kWheelDelta);
147
148 // Adjust the remainder such that any whole scrolls we have taken action
149 // for don't count towards the scroll remainder.
150 scroll_remainder_x_ -=
151 whole_scroll_amount_x * ui::MouseWheelEvent::kWheelDelta;
152 scroll_remainder_y_ -=
153 whole_scroll_amount_y * ui::MouseWheelEvent::kWheelDelta;
154
155 // Count a scroll in either axis - summing the axes works for this.
156 int whole_scroll_offset = whole_scroll_amount_x + whole_scroll_amount_y;
157
135 Browser* browser = browser_view_->browser(); 158 Browser* browser = browser_view_->browser();
136 TabStripModel* model = browser->tab_strip_model(); 159 TabStripModel* model = browser->tab_strip_model();
137 // Switch to the next tab only if not at the end of the tab-strip. 160 // 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()) { 161 if (whole_scroll_offset < 0 &&
162 model->active_index() + 1 < model->count()) {
139 chrome::SelectNextTab(browser); 163 chrome::SelectNextTab(browser);
140 return true; 164 return true;
141 } 165 }
142 166
143 // Switch to the previous tab only if not at the beginning of the 167 // Switch to the previous tab only if not at the beginning of the
144 // tab-strip. 168 // tab-strip.
145 if (scroll_offset > 0 && model->active_index() > 0) { 169 if (whole_scroll_offset > 0 && model->active_index() > 0) {
146 chrome::SelectPreviousTab(browser); 170 chrome::SelectPreviousTab(browser);
147 return true; 171 return true;
148 } 172 }
149 } 173 }
150 } 174 }
151 return RootView::OnMouseWheel(event); 175 return RootView::OnMouseWheel(event);
152 } 176 }
153 177
178 void BrowserRootView::OnMouseExited(const ui::MouseEvent& event) {
msw 2016/02/02 19:00:57 This should probably be calling views::internal::R
179 // Reset such that the tab switch always occurs halfway through a smooth
180 // scroll.
181 scroll_remainder_x_ = 0;
182 scroll_remainder_y_ = 0;
183 }
184
154 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) { 185 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) {
155 if (event->IsGestureEvent()) { 186 if (event->IsGestureEvent()) {
156 ui::GestureEvent* gesture_event = event->AsGestureEvent(); 187 ui::GestureEvent* gesture_event = event->AsGestureEvent();
157 if (gesture_event->type() == ui::ET_GESTURE_TAP && 188 if (gesture_event->type() == ui::ET_GESTURE_TAP &&
158 gesture_event->location().y() <= 0 && 189 gesture_event->location().y() <= 0 &&
159 gesture_event->location().x() <= browser_view_->GetBounds().width()) { 190 gesture_event->location().x() <= browser_view_->GetBounds().width()) {
160 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP); 191 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP);
161 } 192 }
162 } 193 }
163 194
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 browser_view_->browser()->profile())->Classify( 235 browser_view_->browser()->profile())->Classify(
205 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match, 236 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match,
206 nullptr); 237 nullptr);
207 if (!match.destination_url.is_valid()) 238 if (!match.destination_url.is_valid())
208 return false; 239 return false;
209 240
210 if (url) 241 if (url)
211 *url = match.destination_url; 242 *url = match.destination_url;
212 return true; 243 return true;
213 } 244 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/frame/browser_root_view.h ('k') | ui/base/x/x11_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698