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

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 comments, moved zoom handling to issue 1554253004 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
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
138 // Number of integer scroll events that have passed in each direction
139 int whole_scroll_amount_x = round(
140 (double)scroll_amount_x_ / (double)ui::MouseWheelEvent::kWheelDelta);
141 int whole_scroll_amount_y = round(
142 (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.
143
144 scroll_amount_x_ -=
145 whole_scroll_amount_x * ui::MouseWheelEvent::kWheelDelta;
146 scroll_amount_y_ -=
147 whole_scroll_amount_y * ui::MouseWheelEvent::kWheelDelta;
148
149 // Count a scroll in either axis - summing the axes works for this.
150 int whole_scroll_offset = whole_scroll_amount_x + whole_scroll_amount_y;
151
135 Browser* browser = browser_view_->browser(); 152 Browser* browser = browser_view_->browser();
136 TabStripModel* model = browser->tab_strip_model(); 153 TabStripModel* model = browser->tab_strip_model();
137 // Switch to the next tab only if not at the end of the tab-strip. 154 // 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()) { 155 if (whole_scroll_offset < 0 &&
156 model->active_index() + 1 < model->count()) {
139 chrome::SelectNextTab(browser); 157 chrome::SelectNextTab(browser);
140 return true; 158 return true;
141 } 159 }
142 160
143 // Switch to the previous tab only if not at the beginning of the 161 // Switch to the previous tab only if not at the beginning of the
144 // tab-strip. 162 // tab-strip.
145 if (scroll_offset > 0 && model->active_index() > 0) { 163 if (whole_scroll_offset > 0 && model->active_index() > 0) {
146 chrome::SelectPreviousTab(browser); 164 chrome::SelectPreviousTab(browser);
147 return true; 165 return true;
148 } 166 }
149 } 167 }
150 } 168 }
151 return RootView::OnMouseWheel(event); 169 return RootView::OnMouseWheel(event);
152 } 170 }
153 171
172 void BrowserRootView::OnMouseExited(const ui::MouseEvent& event) {
173 // Reset such that the tab switch always occurs halfway through a smooth
174 // scroll
175 scroll_amount_x_ = 0;
176 scroll_amount_y_ = 0;
177 }
178
154 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) { 179 void BrowserRootView::OnEventProcessingStarted(ui::Event* event) {
155 if (event->IsGestureEvent()) { 180 if (event->IsGestureEvent()) {
156 ui::GestureEvent* gesture_event = event->AsGestureEvent(); 181 ui::GestureEvent* gesture_event = event->AsGestureEvent();
157 if (gesture_event->type() == ui::ET_GESTURE_TAP && 182 if (gesture_event->type() == ui::ET_GESTURE_TAP &&
158 gesture_event->location().y() <= 0 && 183 gesture_event->location().y() <= 0 &&
159 gesture_event->location().x() <= browser_view_->GetBounds().width()) { 184 gesture_event->location().x() <= browser_view_->GetBounds().width()) {
160 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP); 185 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP);
161 } 186 }
162 } 187 }
163 188
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 browser_view_->browser()->profile())->Classify( 229 browser_view_->browser()->profile())->Classify(
205 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match, 230 text, false, false, metrics::OmniboxEventProto::INVALID_SPEC, &match,
206 nullptr); 231 nullptr);
207 if (!match.destination_url.is_valid()) 232 if (!match.destination_url.is_valid())
208 return false; 233 return false;
209 234
210 if (url) 235 if (url)
211 *url = match.destination_url; 236 *url = match.destination_url;
212 return true; 237 return true;
213 } 238 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698