| 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/scrollbar/base_scroll_bar.h" | 5 #include "ui/views/controls/scrollbar/base_scroll_bar.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 enum ScrollBarContextMenuCommands { | 266 enum ScrollBarContextMenuCommands { |
| 267 ScrollBarContextMenuCommand_ScrollHere = 1, | 267 ScrollBarContextMenuCommand_ScrollHere = 1, |
| 268 ScrollBarContextMenuCommand_ScrollStart, | 268 ScrollBarContextMenuCommand_ScrollStart, |
| 269 ScrollBarContextMenuCommand_ScrollEnd, | 269 ScrollBarContextMenuCommand_ScrollEnd, |
| 270 ScrollBarContextMenuCommand_ScrollPageUp, | 270 ScrollBarContextMenuCommand_ScrollPageUp, |
| 271 ScrollBarContextMenuCommand_ScrollPageDown, | 271 ScrollBarContextMenuCommand_ScrollPageDown, |
| 272 ScrollBarContextMenuCommand_ScrollPrev, | 272 ScrollBarContextMenuCommand_ScrollPrev, |
| 273 ScrollBarContextMenuCommand_ScrollNext | 273 ScrollBarContextMenuCommand_ScrollNext |
| 274 }; | 274 }; |
| 275 | 275 |
| 276 void BaseScrollBar::ShowContextMenuForView(View* source, const gfx::Point& p) { | 276 void BaseScrollBar::ShowContextMenuForView( |
| 277 View* source, |
| 278 const gfx::Point& p, |
| 279 ui::ContextMenuSourceType source_type) { |
| 277 Widget* widget = GetWidget(); | 280 Widget* widget = GetWidget(); |
| 278 gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen(); | 281 gfx::Rect widget_bounds = widget->GetWindowBoundsInScreen(); |
| 279 gfx::Point temp_pt(p.x() - widget_bounds.x(), p.y() - widget_bounds.y()); | 282 gfx::Point temp_pt(p.x() - widget_bounds.x(), p.y() - widget_bounds.y()); |
| 280 View::ConvertPointFromWidget(this, &temp_pt); | 283 View::ConvertPointFromWidget(this, &temp_pt); |
| 281 context_menu_mouse_position_ = IsHorizontal() ? temp_pt.x() : temp_pt.y(); | 284 context_menu_mouse_position_ = IsHorizontal() ? temp_pt.x() : temp_pt.y(); |
| 282 | 285 |
| 283 views::MenuItemView* menu = new views::MenuItemView(this); | 286 views::MenuItemView* menu = new views::MenuItemView(this); |
| 284 // MenuRunner takes ownership of |menu|. | 287 // MenuRunner takes ownership of |menu|. |
| 285 menu_runner_.reset(new MenuRunner(menu)); | 288 menu_runner_.reset(new MenuRunner(menu)); |
| 286 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollHere); | 289 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollHere); |
| 287 menu->AppendSeparator(); | 290 menu->AppendSeparator(); |
| 288 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollStart); | 291 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollStart); |
| 289 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollEnd); | 292 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollEnd); |
| 290 menu->AppendSeparator(); | 293 menu->AppendSeparator(); |
| 291 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPageUp); | 294 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPageUp); |
| 292 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPageDown); | 295 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPageDown); |
| 293 menu->AppendSeparator(); | 296 menu->AppendSeparator(); |
| 294 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPrev); | 297 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollPrev); |
| 295 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollNext); | 298 menu->AppendDelegateMenuItem(ScrollBarContextMenuCommand_ScrollNext); |
| 296 if (menu_runner_->RunMenuAt(GetWidget(), NULL, gfx::Rect(p, gfx::Size()), | 299 if (menu_runner_->RunContextMenuAt(GetWidget(), NULL, |
| 297 MenuItemView::TOPLEFT, MenuRunner::HAS_MNEMONICS | | 300 gfx::Rect(p, gfx::Size()), |
| 301 source_type, MenuRunner::HAS_MNEMONICS | |
| 298 views::MenuRunner::CONTEXT_MENU) == | 302 views::MenuRunner::CONTEXT_MENU) == |
| 299 MenuRunner::MENU_DELETED) | 303 MenuRunner::MENU_DELETED) |
| 300 return; | 304 return; |
| 301 } | 305 } |
| 302 | 306 |
| 303 /////////////////////////////////////////////////////////////////////////////// | 307 /////////////////////////////////////////////////////////////////////////////// |
| 304 // BaseScrollBar, Menu::Delegate implementation: | 308 // BaseScrollBar, Menu::Delegate implementation: |
| 305 | 309 |
| 306 string16 BaseScrollBar::GetLabel(int id) const { | 310 string16 BaseScrollBar::GetLabel(int id) const { |
| 307 int ids_value = 0; | 311 int ids_value = 0; |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 491 thumb_position = thumb_position - (thumb_->GetSize() / 2); | 495 thumb_position = thumb_position - (thumb_->GetSize() / 2); |
| 492 return (thumb_position * contents_size_) / GetTrackSize(); | 496 return (thumb_position * contents_size_) / GetTrackSize(); |
| 493 } | 497 } |
| 494 | 498 |
| 495 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { | 499 void BaseScrollBar::SetThumbTrackState(CustomButton::ButtonState state) { |
| 496 thumb_track_state_ = state; | 500 thumb_track_state_ = state; |
| 497 SchedulePaint(); | 501 SchedulePaint(); |
| 498 } | 502 } |
| 499 | 503 |
| 500 } // namespace views | 504 } // namespace views |
| OLD | NEW |