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 "ui/views/controls/menu/submenu_view.h" | 5 #include "ui/views/controls/menu/submenu_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "ui/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 bool SubmenuView::AreDropTypesRequired() { | 173 bool SubmenuView::AreDropTypesRequired() { |
174 DCHECK(GetMenuItem()->GetMenuController()); | 174 DCHECK(GetMenuItem()->GetMenuController()); |
175 return GetMenuItem()->GetMenuController()->AreDropTypesRequired(this); | 175 return GetMenuItem()->GetMenuController()->AreDropTypesRequired(this); |
176 } | 176 } |
177 | 177 |
178 bool SubmenuView::CanDrop(const OSExchangeData& data) { | 178 bool SubmenuView::CanDrop(const OSExchangeData& data) { |
179 DCHECK(GetMenuItem()->GetMenuController()); | 179 DCHECK(GetMenuItem()->GetMenuController()); |
180 return GetMenuItem()->GetMenuController()->CanDrop(this, data); | 180 return GetMenuItem()->GetMenuController()->CanDrop(this, data); |
181 } | 181 } |
182 | 182 |
183 void SubmenuView::OnDragEntered(const DropTargetEvent& event) { | 183 void SubmenuView::OnDragEntered(const ui::DropTargetEvent& event) { |
184 DCHECK(GetMenuItem()->GetMenuController()); | 184 DCHECK(GetMenuItem()->GetMenuController()); |
185 GetMenuItem()->GetMenuController()->OnDragEntered(this, event); | 185 GetMenuItem()->GetMenuController()->OnDragEntered(this, event); |
186 } | 186 } |
187 | 187 |
188 int SubmenuView::OnDragUpdated(const DropTargetEvent& event) { | 188 int SubmenuView::OnDragUpdated(const ui::DropTargetEvent& event) { |
189 DCHECK(GetMenuItem()->GetMenuController()); | 189 DCHECK(GetMenuItem()->GetMenuController()); |
190 return GetMenuItem()->GetMenuController()->OnDragUpdated(this, event); | 190 return GetMenuItem()->GetMenuController()->OnDragUpdated(this, event); |
191 } | 191 } |
192 | 192 |
193 void SubmenuView::OnDragExited() { | 193 void SubmenuView::OnDragExited() { |
194 DCHECK(GetMenuItem()->GetMenuController()); | 194 DCHECK(GetMenuItem()->GetMenuController()); |
195 GetMenuItem()->GetMenuController()->OnDragExited(this); | 195 GetMenuItem()->GetMenuController()->OnDragExited(this); |
196 } | 196 } |
197 | 197 |
198 int SubmenuView::OnPerformDrop(const DropTargetEvent& event) { | 198 int SubmenuView::OnPerformDrop(const ui::DropTargetEvent& event) { |
199 DCHECK(GetMenuItem()->GetMenuController()); | 199 DCHECK(GetMenuItem()->GetMenuController()); |
200 return GetMenuItem()->GetMenuController()->OnPerformDrop(this, event); | 200 return GetMenuItem()->GetMenuController()->OnPerformDrop(this, event); |
201 } | 201 } |
202 | 202 |
203 bool SubmenuView::OnMouseWheel(const MouseWheelEvent& e) { | 203 bool SubmenuView::OnMouseWheel(const ui::MouseWheelEvent& e) { |
204 gfx::Rect vis_bounds = GetVisibleBounds(); | 204 gfx::Rect vis_bounds = GetVisibleBounds(); |
205 int menu_item_count = GetMenuItemCount(); | 205 int menu_item_count = GetMenuItemCount(); |
206 if (vis_bounds.height() == height() || !menu_item_count) { | 206 if (vis_bounds.height() == height() || !menu_item_count) { |
207 // All menu items are visible, nothing to scroll. | 207 // All menu items are visible, nothing to scroll. |
208 return true; | 208 return true; |
209 } | 209 } |
210 | 210 |
211 // Find the index of the first menu item whose y-coordinate is >= visible | 211 // Find the index of the first menu item whose y-coordinate is >= visible |
212 // y-coordinate. | 212 // y-coordinate. |
213 int i = 0; | 213 int i = 0; |
214 while ((i < menu_item_count) && (GetMenuItemAt(i)->y() < vis_bounds.y())) | 214 while ((i < menu_item_count) && (GetMenuItemAt(i)->y() < vis_bounds.y())) |
215 ++i; | 215 ++i; |
216 if (i == menu_item_count) | 216 if (i == menu_item_count) |
217 return true; | 217 return true; |
218 int first_vis_index = std::max(0, | 218 int first_vis_index = std::max(0, |
219 (GetMenuItemAt(i)->y() == vis_bounds.y()) ? i : i - 1); | 219 (GetMenuItemAt(i)->y() == vis_bounds.y()) ? i : i - 1); |
220 | 220 |
221 // If the first item isn't entirely visible, make it visible, otherwise make | 221 // If the first item isn't entirely visible, make it visible, otherwise make |
222 // the next/previous one entirely visible. | 222 // the next/previous one entirely visible. |
223 int delta = abs(e.offset() / MouseWheelEvent::kWheelDelta); | 223 int delta = abs(e.offset() / ui::MouseWheelEvent::kWheelDelta); |
224 for (bool scroll_up = (e.offset() > 0); delta != 0; --delta) { | 224 for (bool scroll_up = (e.offset() > 0); delta != 0; --delta) { |
225 int scroll_target; | 225 int scroll_target; |
226 if (scroll_up) { | 226 if (scroll_up) { |
227 if (GetMenuItemAt(first_vis_index)->y() == vis_bounds.y()) { | 227 if (GetMenuItemAt(first_vis_index)->y() == vis_bounds.y()) { |
228 if (first_vis_index == 0) | 228 if (first_vis_index == 0) |
229 break; | 229 break; |
230 first_vis_index--; | 230 first_vis_index--; |
231 } | 231 } |
232 scroll_target = GetMenuItemAt(first_vis_index)->y(); | 232 scroll_target = GetMenuItemAt(first_vis_index)->y(); |
233 } else { | 233 } else { |
234 if (first_vis_index + 1 == menu_item_count) | 234 if (first_vis_index + 1 == menu_item_count) |
235 break; | 235 break; |
236 scroll_target = GetMenuItemAt(first_vis_index + 1)->y(); | 236 scroll_target = GetMenuItemAt(first_vis_index + 1)->y(); |
237 if (GetMenuItemAt(first_vis_index)->y() == vis_bounds.y()) | 237 if (GetMenuItemAt(first_vis_index)->y() == vis_bounds.y()) |
238 first_vis_index++; | 238 first_vis_index++; |
239 } | 239 } |
240 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target), | 240 ScrollRectToVisible(gfx::Rect(gfx::Point(0, scroll_target), |
241 vis_bounds.size())); | 241 vis_bounds.size())); |
242 vis_bounds = GetVisibleBounds(); | 242 vis_bounds = GetVisibleBounds(); |
243 } | 243 } |
244 | 244 |
245 return true; | 245 return true; |
246 } | 246 } |
247 | 247 |
248 ui::GestureStatus SubmenuView::OnGestureEvent(const GestureEvent& e) { | 248 ui::GestureStatus SubmenuView::OnGestureEvent(const ui::GestureEvent& e) { |
249 ui::GestureStatus to_return = ui::GESTURE_STATUS_CONSUMED; | 249 ui::GestureStatus to_return = ui::GESTURE_STATUS_CONSUMED; |
250 switch (e.type()) { | 250 switch (e.type()) { |
251 case ui::ET_GESTURE_SCROLL_BEGIN: | 251 case ui::ET_GESTURE_SCROLL_BEGIN: |
252 scroll_animator_->Stop(); | 252 scroll_animator_->Stop(); |
253 break; | 253 break; |
254 case ui::ET_GESTURE_SCROLL_UPDATE: | 254 case ui::ET_GESTURE_SCROLL_UPDATE: |
255 OnScroll(0, e.details().scroll_y()); | 255 OnScroll(0, e.details().scroll_y()); |
256 break; | 256 break; |
257 case ui::ET_GESTURE_SCROLL_END: | 257 case ui::ET_GESTURE_SCROLL_END: |
258 break; | 258 break; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 int y = vis_bounds.y() - static_cast<int>(dy); | 431 int y = vis_bounds.y() - static_cast<int>(dy); |
432 // clamp y to [0, full_height - vis_height) | 432 // clamp y to [0, full_height - vis_height) |
433 y = std::max(y, 0); | 433 y = std::max(y, 0); |
434 y = std::min(y, full_bounds.height() - vis_bounds.height() - 1); | 434 y = std::min(y, full_bounds.height() - vis_bounds.height() - 1); |
435 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); | 435 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); |
436 if (new_vis_bounds != vis_bounds) | 436 if (new_vis_bounds != vis_bounds) |
437 ScrollRectToVisible(new_vis_bounds); | 437 ScrollRectToVisible(new_vis_bounds); |
438 } | 438 } |
439 | 439 |
440 } // namespace views | 440 } // namespace views |
OLD | NEW |