| 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 "chrome/browser/autocomplete/autocomplete_classifier.h" | 7 #include "chrome/browser/autocomplete/autocomplete_classifier.h" |
| 8 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" | 8 #include "chrome/browser/autocomplete/autocomplete_classifier_factory.h" |
| 9 #include "chrome/browser/autocomplete/autocomplete_input.h" | 9 #include "chrome/browser/autocomplete/autocomplete_input.h" |
| 10 #include "chrome/browser/autocomplete/autocomplete_match.h" | 10 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 116 } | 116 } |
| 117 | 117 |
| 118 const char* BrowserRootView::GetClassName() const { | 118 const char* BrowserRootView::GetClassName() const { |
| 119 return kViewClassName; | 119 return kViewClassName; |
| 120 } | 120 } |
| 121 | 121 |
| 122 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { | 122 bool BrowserRootView::OnMouseWheel(const ui::MouseWheelEvent& event) { |
| 123 if (browser_defaults::kScrollEventChangesTab) { | 123 if (browser_defaults::kScrollEventChangesTab) { |
| 124 // Switch to the left/right tab if the wheel-scroll happens over the | 124 // Switch to the left/right tab if the wheel-scroll happens over the |
| 125 // tabstrip, or the empty space beside the tabstrip. | 125 // tabstrip, or the empty space beside the tabstrip. |
| 126 views::View* hit_view = GetEventHandlerForPoint(event.location()); | 126 views::View* hit_view = |
| 127 GetEventHandlerForPoint(gfx::ToFlooredPoint(event.location())); |
| 127 views::NonClientView* non_client = GetWidget()->non_client_view(); | 128 views::NonClientView* non_client = GetWidget()->non_client_view(); |
| 128 if (tabstrip()->Contains(hit_view) || | 129 if (tabstrip()->Contains(hit_view) || |
| 129 hit_view == non_client->frame_view()) { | 130 hit_view == non_client->frame_view()) { |
| 130 int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ? | 131 int scroll_offset = abs(event.y_offset()) > abs(event.x_offset()) ? |
| 131 event.y_offset() : -event.x_offset(); | 132 event.y_offset() : -event.x_offset(); |
| 132 Browser* browser = browser_view_->browser(); | 133 Browser* browser = browser_view_->browser(); |
| 133 TabStripModel* model = browser->tab_strip_model(); | 134 TabStripModel* model = browser->tab_strip_model(); |
| 134 // Switch to the next tab only if not at the end of the tab-strip. | 135 // Switch to the next tab only if not at the end of the tab-strip. |
| 135 if (scroll_offset < 0 && model->active_index() + 1 < model->count()) { | 136 if (scroll_offset < 0 && model->active_index() + 1 < model->count()) { |
| 136 chrome::SelectNextTab(browser); | 137 chrome::SelectNextTab(browser); |
| 137 return true; | 138 return true; |
| 138 } | 139 } |
| 139 | 140 |
| 140 // Switch to the previous tab only if not at the beginning of the | 141 // Switch to the previous tab only if not at the beginning of the |
| 141 // tab-strip. | 142 // tab-strip. |
| 142 if (scroll_offset > 0 && model->active_index() > 0) { | 143 if (scroll_offset > 0 && model->active_index() > 0) { |
| 143 chrome::SelectPreviousTab(browser); | 144 chrome::SelectPreviousTab(browser); |
| 144 return true; | 145 return true; |
| 145 } | 146 } |
| 146 } | 147 } |
| 147 } | 148 } |
| 148 return RootView::OnMouseWheel(event); | 149 return RootView::OnMouseWheel(event); |
| 149 } | 150 } |
| 150 | 151 |
| 151 void BrowserRootView::DispatchGestureEvent(ui::GestureEvent* event) { | 152 void BrowserRootView::DispatchGestureEvent(ui::GestureEvent* event) { |
| 152 if (event->type() == ui::ET_GESTURE_TAP && | 153 if (event->type() == ui::ET_GESTURE_TAP && |
| 153 event->location().y() <= 0 && | 154 gfx::ToFlooredPoint(event->location()).y() <= 0 && |
| 154 event->location().x() <= browser_view_->GetBounds().width()) { | 155 gfx::ToFlooredPoint(event->location()).x() <= |
| 156 browser_view_->GetBounds().width()) { |
| 155 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP); | 157 TouchUMA::RecordGestureAction(TouchUMA::GESTURE_ROOTVIEWTOP_TAP); |
| 156 } | 158 } |
| 157 | 159 |
| 158 RootView::DispatchGestureEvent(event); | 160 RootView::DispatchGestureEvent(event); |
| 159 } | 161 } |
| 160 | 162 |
| 161 bool BrowserRootView::ShouldForwardToTabStrip( | 163 bool BrowserRootView::ShouldForwardToTabStrip( |
| 162 const ui::DropTargetEvent& event) { | 164 const ui::DropTargetEvent& event) { |
| 163 if (!tabstrip()->visible()) | 165 if (!tabstrip()->visible()) |
| 164 return false; | 166 return false; |
| 165 | 167 |
| 166 // Allow the drop as long as the mouse is over the tabstrip or vertically | 168 // Allow the drop as long as the mouse is over the tabstrip or vertically |
| 167 // before it. | 169 // before it. |
| 168 gfx::Point tab_loc_in_host; | 170 gfx::Point tab_loc_in_host; |
| 169 ConvertPointToTarget(tabstrip(), this, &tab_loc_in_host); | 171 ConvertPointToTarget(tabstrip(), this, &tab_loc_in_host); |
| 170 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); | 172 return event.y() < tab_loc_in_host.y() + tabstrip()->height(); |
| 171 } | 173 } |
| 172 | 174 |
| 173 ui::DropTargetEvent* BrowserRootView::MapEventToTabStrip( | 175 ui::DropTargetEvent* BrowserRootView::MapEventToTabStrip( |
| 174 const ui::DropTargetEvent& event, | 176 const ui::DropTargetEvent& event, |
| 175 const ui::OSExchangeData& data) { | 177 const ui::OSExchangeData& data) { |
| 176 gfx::Point tab_strip_loc(event.location()); | 178 gfx::Point tab_strip_loc(gfx::ToFlooredPoint(event.location())); |
| 177 ConvertPointToTarget(this, tabstrip(), &tab_strip_loc); | 179 ConvertPointToTarget(this, tabstrip(), &tab_strip_loc); |
| 178 return new ui::DropTargetEvent(data, tab_strip_loc, tab_strip_loc, | 180 return new ui::DropTargetEvent(data, tab_strip_loc, tab_strip_loc, |
| 179 event.source_operations()); | 181 event.source_operations()); |
| 180 } | 182 } |
| 181 | 183 |
| 182 TabStrip* BrowserRootView::tabstrip() const { | 184 TabStrip* BrowserRootView::tabstrip() const { |
| 183 return browser_view_->tabstrip(); | 185 return browser_view_->tabstrip(); |
| 184 } | 186 } |
| 185 | 187 |
| 186 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, | 188 bool BrowserRootView::GetPasteAndGoURL(const ui::OSExchangeData& data, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 197 AutocompleteClassifierFactory::GetForProfile( | 199 AutocompleteClassifierFactory::GetForProfile( |
| 198 browser_view_->browser()->profile())->Classify( | 200 browser_view_->browser()->profile())->Classify( |
| 199 text, false, false, AutocompleteInput::INVALID_SPEC, &match, NULL); | 201 text, false, false, AutocompleteInput::INVALID_SPEC, &match, NULL); |
| 200 if (!match.destination_url.is_valid()) | 202 if (!match.destination_url.is_valid()) |
| 201 return false; | 203 return false; |
| 202 | 204 |
| 203 if (url) | 205 if (url) |
| 204 *url = match.destination_url; | 206 *url = match.destination_url; |
| 205 return true; | 207 return true; |
| 206 } | 208 } |
| OLD | NEW |