OLD | NEW |
---|---|
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_amount_x_(0), | |
35 scroll_amount_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 Loading... | |
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_amount_x_ += event.x_offset(); |
134 event.y_offset() : event.x_offset(); | 138 scroll_amount_y_ += event.y_offset(); |
139 | |
140 // 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.
| |
141 int whole_scroll_amount_x = | |
142 std::lround(static_cast<double>(scroll_amount_x_) / | |
143 ui::MouseWheelEvent::kWheelDelta); | |
144 int whole_scroll_amount_y = | |
145 std::lround(static_cast<double>(scroll_amount_y_) / | |
146 ui::MouseWheelEvent::kWheelDelta); | |
147 | |
148 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
| |
149 whole_scroll_amount_x * ui::MouseWheelEvent::kWheelDelta; | |
150 scroll_amount_y_ -= | |
151 whole_scroll_amount_y * ui::MouseWheelEvent::kWheelDelta; | |
152 | |
153 // Count a scroll in either axis - summing the axes works for this. | |
154 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
| |
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 | |
msw
2016/01/09 05:23:57
nit: trailing period
Will Shackleton
2016/01/10 14:18:42
Done.
| |
179 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
| |
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 Loading... | |
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 } |
OLD | NEW |