| 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/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/ime/input_method.h" |
| 11 #include "ui/compositor/paint_recorder.h" | 12 #include "ui/compositor/paint_recorder.h" |
| 12 #include "ui/events/event.h" | 13 #include "ui/events/event.h" |
| 13 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 14 #include "ui/gfx/geometry/safe_integer_conversions.h" | 15 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 15 #include "ui/views/controls/menu/menu_config.h" | 16 #include "ui/views/controls/menu/menu_config.h" |
| 16 #include "ui/views/controls/menu/menu_controller.h" | 17 #include "ui/views/controls/menu/menu_controller.h" |
| 17 #include "ui/views/controls/menu/menu_host.h" | 18 #include "ui/views/controls/menu/menu_host.h" |
| 18 #include "ui/views/controls/menu/menu_item_view.h" | 19 #include "ui/views/controls/menu/menu_item_view.h" |
| 19 #include "ui/views/controls/menu/menu_scroll_view_container.h" | 20 #include "ui/views/controls/menu/menu_scroll_view_container.h" |
| 20 #include "ui/views/widget/root_view.h" | 21 #include "ui/views/widget/root_view.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 50 DCHECK(parent); | 51 DCHECK(parent); |
| 51 // We'll delete ourselves, otherwise the ScrollView would delete us on close. | 52 // We'll delete ourselves, otherwise the ScrollView would delete us on close. |
| 52 set_owned_by_client(); | 53 set_owned_by_client(); |
| 53 } | 54 } |
| 54 | 55 |
| 55 SubmenuView::~SubmenuView() { | 56 SubmenuView::~SubmenuView() { |
| 56 // The menu may not have been closed yet (it will be hidden, but not | 57 // The menu may not have been closed yet (it will be hidden, but not |
| 57 // necessarily closed). | 58 // necessarily closed). |
| 58 Close(); | 59 Close(); |
| 59 | 60 |
| 61 if (GetInputMethod()) |
| 62 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); |
| 63 |
| 60 delete scroll_view_container_; | 64 delete scroll_view_container_; |
| 61 } | 65 } |
| 62 | 66 |
| 63 int SubmenuView::GetMenuItemCount() { | 67 int SubmenuView::GetMenuItemCount() { |
| 64 int count = 0; | 68 int count = 0; |
| 65 for (int i = 0; i < child_count(); ++i) { | 69 for (int i = 0; i < child_count(); ++i) { |
| 66 if (child_at(i)->id() == MenuItemView::kMenuItemViewID) | 70 if (child_at(i)->id() == MenuItemView::kMenuItemViewID) |
| 67 count++; | 71 count++; |
| 68 } | 72 } |
| 69 return count; | 73 return count; |
| 70 } | 74 } |
| 71 | 75 |
| 72 MenuItemView* SubmenuView::GetMenuItemAt(int index) { | 76 MenuItemView* SubmenuView::GetMenuItemAt(int index) { |
| 73 for (int i = 0, count = 0; i < child_count(); ++i) { | 77 for (int i = 0, count = 0; i < child_count(); ++i) { |
| 74 if (child_at(i)->id() == MenuItemView::kMenuItemViewID && | 78 if (child_at(i)->id() == MenuItemView::kMenuItemViewID && |
| 75 count++ == index) { | 79 count++ == index) { |
| 76 return static_cast<MenuItemView*>(child_at(i)); | 80 return static_cast<MenuItemView*>(child_at(i)); |
| 77 } | 81 } |
| 78 } | 82 } |
| 79 NOTREACHED(); | 83 NOTREACHED(); |
| 80 return NULL; | 84 return NULL; |
| 81 } | 85 } |
| 82 | 86 |
| 87 PrefixSelector* SubmenuView::GetPrefixSelector() { |
| 88 return &prefix_selector_; |
| 89 } |
| 90 |
| 83 void SubmenuView::ChildPreferredSizeChanged(View* child) { | 91 void SubmenuView::ChildPreferredSizeChanged(View* child) { |
| 84 if (!resize_open_menu_) | 92 if (!resize_open_menu_) |
| 85 return; | 93 return; |
| 86 | 94 |
| 87 MenuItemView *item = GetMenuItem(); | 95 MenuItemView *item = GetMenuItem(); |
| 88 MenuController* controller = item->GetMenuController(); | 96 MenuController* controller = item->GetMenuController(); |
| 89 | 97 |
| 90 if (controller) { | 98 if (controller) { |
| 91 bool dir; | 99 bool dir; |
| 92 gfx::Rect bounds = controller->CalculateMenuBounds(item, false, &dir); | 100 gfx::Rect bounds = controller->CalculateMenuBounds(item, false, &dir); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 return gfx::Size(width, height + insets.height()); | 185 return gfx::Size(width, height + insets.height()); |
| 178 } | 186 } |
| 179 | 187 |
| 180 void SubmenuView::GetAccessibleState(ui::AXViewState* state) { | 188 void SubmenuView::GetAccessibleState(ui::AXViewState* state) { |
| 181 // Inherit most of the state from the parent menu item, except the role. | 189 // Inherit most of the state from the parent menu item, except the role. |
| 182 if (GetMenuItem()) | 190 if (GetMenuItem()) |
| 183 GetMenuItem()->GetAccessibleState(state); | 191 GetMenuItem()->GetAccessibleState(state); |
| 184 state->role = ui::AX_ROLE_MENU_LIST_POPUP; | 192 state->role = ui::AX_ROLE_MENU_LIST_POPUP; |
| 185 } | 193 } |
| 186 | 194 |
| 187 ui::TextInputClient* SubmenuView::GetTextInputClient() { | |
| 188 return &prefix_selector_; | |
| 189 } | |
| 190 | |
| 191 void SubmenuView::PaintChildren(const ui::PaintContext& context) { | 195 void SubmenuView::PaintChildren(const ui::PaintContext& context) { |
| 192 View::PaintChildren(context); | 196 View::PaintChildren(context); |
| 193 | 197 |
| 194 bool paint_drop_indicator = false; | 198 bool paint_drop_indicator = false; |
| 195 if (drop_item_) { | 199 if (drop_item_) { |
| 196 switch (drop_position_) { | 200 switch (drop_position_) { |
| 197 case MenuDelegate::DROP_NONE: | 201 case MenuDelegate::DROP_NONE: |
| 198 case MenuDelegate::DROP_ON: | 202 case MenuDelegate::DROP_ON: |
| 199 break; | 203 break; |
| 200 case MenuDelegate::DROP_UNKNOWN: | 204 case MenuDelegate::DROP_UNKNOWN: |
| (...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 y = std::max(y, 0); | 513 y = std::max(y, 0); |
| 510 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); | 514 gfx::Rect new_vis_bounds(x, y, vis_bounds.width(), vis_bounds.height()); |
| 511 if (new_vis_bounds != vis_bounds) { | 515 if (new_vis_bounds != vis_bounds) { |
| 512 ScrollRectToVisible(new_vis_bounds); | 516 ScrollRectToVisible(new_vis_bounds); |
| 513 return true; | 517 return true; |
| 514 } | 518 } |
| 515 return false; | 519 return false; |
| 516 } | 520 } |
| 517 | 521 |
| 518 } // namespace views | 522 } // namespace views |
| OLD | NEW |