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 25 matching lines...) Expand all Loading... |
36 SubmenuView::SubmenuView(MenuItemView* parent) | 36 SubmenuView::SubmenuView(MenuItemView* parent) |
37 : parent_menu_item_(parent), | 37 : parent_menu_item_(parent), |
38 host_(NULL), | 38 host_(NULL), |
39 drop_item_(NULL), | 39 drop_item_(NULL), |
40 drop_position_(MenuDelegate::DROP_NONE), | 40 drop_position_(MenuDelegate::DROP_NONE), |
41 scroll_view_container_(NULL), | 41 scroll_view_container_(NULL), |
42 max_minor_text_width_(0), | 42 max_minor_text_width_(0), |
43 minimum_preferred_width_(0), | 43 minimum_preferred_width_(0), |
44 resize_open_menu_(false), | 44 resize_open_menu_(false), |
45 scroll_animator_(new ScrollAnimator(this)), | 45 scroll_animator_(new ScrollAnimator(this)), |
46 roundoff_error_(0) { | 46 roundoff_error_(0), |
| 47 prefix_selector_(this) { |
47 DCHECK(parent); | 48 DCHECK(parent); |
48 // We'll delete ourselves, otherwise the ScrollView would delete us on close. | 49 // We'll delete ourselves, otherwise the ScrollView would delete us on close. |
49 set_owned_by_client(); | 50 set_owned_by_client(); |
50 } | 51 } |
51 | 52 |
52 SubmenuView::~SubmenuView() { | 53 SubmenuView::~SubmenuView() { |
53 // The menu may not have been closed yet (it will be hidden, but not | 54 // The menu may not have been closed yet (it will be hidden, but not |
54 // necessarily closed). | 55 // necessarily closed). |
55 Close(); | 56 Close(); |
56 | 57 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 height + insets.height()); | 165 height + insets.height()); |
165 } | 166 } |
166 | 167 |
167 void SubmenuView::GetAccessibleState(ui::AccessibleViewState* state) { | 168 void SubmenuView::GetAccessibleState(ui::AccessibleViewState* state) { |
168 // Inherit most of the state from the parent menu item, except the role. | 169 // Inherit most of the state from the parent menu item, except the role. |
169 if (GetMenuItem()) | 170 if (GetMenuItem()) |
170 GetMenuItem()->GetAccessibleState(state); | 171 GetMenuItem()->GetAccessibleState(state); |
171 state->role = ui::AccessibilityTypes::ROLE_MENUPOPUP; | 172 state->role = ui::AccessibilityTypes::ROLE_MENUPOPUP; |
172 } | 173 } |
173 | 174 |
| 175 ui::TextInputClient* SubmenuView::GetTextInputClient() { |
| 176 return &prefix_selector_; |
| 177 } |
| 178 |
174 void SubmenuView::PaintChildren(gfx::Canvas* canvas) { | 179 void SubmenuView::PaintChildren(gfx::Canvas* canvas) { |
175 View::PaintChildren(canvas); | 180 View::PaintChildren(canvas); |
176 | 181 |
177 if (drop_item_ && drop_position_ != MenuDelegate::DROP_ON) | 182 if (drop_item_ && drop_position_ != MenuDelegate::DROP_ON) |
178 PaintDropIndicator(canvas, drop_item_, drop_position_); | 183 PaintDropIndicator(canvas, drop_item_, drop_position_); |
179 } | 184 } |
180 | 185 |
181 bool SubmenuView::GetDropFormats( | 186 bool SubmenuView::GetDropFormats( |
182 int* formats, | 187 int* formats, |
183 std::set<OSExchangeData::CustomFormat>* custom_formats) { | 188 std::set<OSExchangeData::CustomFormat>* custom_formats) { |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 handled = false; | 293 handled = false; |
289 break; | 294 break; |
290 default: | 295 default: |
291 handled = false; | 296 handled = false; |
292 break; | 297 break; |
293 } | 298 } |
294 if (handled) | 299 if (handled) |
295 event->SetHandled(); | 300 event->SetHandled(); |
296 } | 301 } |
297 | 302 |
| 303 int SubmenuView::GetRowCount() { |
| 304 return GetMenuItemCount(); |
| 305 } |
| 306 |
| 307 int SubmenuView::GetSelectedRow() { |
| 308 int row = 0; |
| 309 for (int i = 0; i < child_count(); ++i) { |
| 310 if (child_at(i)->id() != MenuItemView::kMenuItemViewID) |
| 311 continue; |
| 312 |
| 313 if (static_cast<MenuItemView*>(child_at(i))->IsSelected()) |
| 314 return row; |
| 315 |
| 316 row++; |
| 317 } |
| 318 |
| 319 return -1; |
| 320 } |
| 321 |
| 322 void SubmenuView::SetSelectedRow(int row) { |
| 323 GetMenuItem()->GetMenuController()->SetSelection( |
| 324 GetMenuItemAt(row), |
| 325 MenuController::SELECTION_DEFAULT); |
| 326 } |
| 327 |
| 328 base::string16 SubmenuView::GetTextForRow(int row) { |
| 329 return GetMenuItemAt(row)->title(); |
| 330 } |
| 331 |
298 bool SubmenuView::IsShowing() { | 332 bool SubmenuView::IsShowing() { |
299 return host_ && host_->IsMenuHostVisible(); | 333 return host_ && host_->IsMenuHostVisible(); |
300 } | 334 } |
301 | 335 |
302 void SubmenuView::ShowAt(Widget* parent, | 336 void SubmenuView::ShowAt(Widget* parent, |
303 const gfx::Rect& bounds, | 337 const gfx::Rect& bounds, |
304 bool do_capture) { | 338 bool do_capture) { |
305 if (host_) { | 339 if (host_) { |
306 host_->ShowMenuHost(do_capture); | 340 host_->ShowMenuHost(do_capture); |
307 } else { | 341 } else { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
456 y = std::max(y, 0); | 490 y = std::max(y, 0); |
457 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); | 491 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); |
458 if (new_vis_bounds != vis_bounds) { | 492 if (new_vis_bounds != vis_bounds) { |
459 ScrollRectToVisible(new_vis_bounds); | 493 ScrollRectToVisible(new_vis_bounds); |
460 return true; | 494 return true; |
461 } | 495 } |
462 return false; | 496 return false; |
463 } | 497 } |
464 | 498 |
465 } // namespace views | 499 } // namespace views |
OLD | NEW |