| OLD | NEW | 
|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "views/controls/menu/submenu_view.h" | 5 #include "views/controls/menu/submenu_view.h" | 
| 6 | 6 | 
| 7 #include "ui/gfx/canvas.h" | 7 #include "ui/gfx/canvas.h" | 
| 8 #include "views/controls/menu/menu_config.h" | 8 #include "views/controls/menu/menu_config.h" | 
| 9 #include "views/controls/menu/menu_controller.h" | 9 #include "views/controls/menu/menu_controller.h" | 
| 10 #include "views/controls/menu/menu_host.h" | 10 #include "views/controls/menu/menu_host.h" | 
| (...skipping 29 matching lines...) Expand all  Loading... | 
| 40 SubmenuView::~SubmenuView() { | 40 SubmenuView::~SubmenuView() { | 
| 41   // The menu may not have been closed yet (it will be hidden, but not | 41   // The menu may not have been closed yet (it will be hidden, but not | 
| 42   // necessarily closed). | 42   // necessarily closed). | 
| 43   Close(); | 43   Close(); | 
| 44 | 44 | 
| 45   delete scroll_view_container_; | 45   delete scroll_view_container_; | 
| 46 } | 46 } | 
| 47 | 47 | 
| 48 int SubmenuView::GetMenuItemCount() { | 48 int SubmenuView::GetMenuItemCount() { | 
| 49   int count = 0; | 49   int count = 0; | 
| 50   for (int i = 0; i < GetChildViewCount(); ++i) { | 50   for (int i = 0; i < child_count(); ++i) { | 
| 51     if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID) | 51     if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID) | 
| 52       count++; | 52       count++; | 
| 53   } | 53   } | 
| 54   return count; | 54   return count; | 
| 55 } | 55 } | 
| 56 | 56 | 
| 57 MenuItemView* SubmenuView::GetMenuItemAt(int index) { | 57 MenuItemView* SubmenuView::GetMenuItemAt(int index) { | 
| 58   for (int i = 0, count = 0; i < GetChildViewCount(); ++i) { | 58   for (int i = 0; i < child_count(); ++i) { | 
| 59     if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID && | 59     if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID && | 
| 60         count++ == index) { | 60         i == index) { | 
| 61       return static_cast<MenuItemView*>(GetChildViewAt(i)); | 61       return static_cast<MenuItemView*>(GetChildViewAt(i)); | 
| 62     } | 62     } | 
| 63   } | 63   } | 
| 64   NOTREACHED(); | 64   NOTREACHED(); | 
| 65   return NULL; | 65   return NULL; | 
| 66 } | 66 } | 
| 67 | 67 | 
| 68 void SubmenuView::Layout() { | 68 void SubmenuView::Layout() { | 
| 69   // We're in a ScrollView, and need to set our width/height ourselves. | 69   // We're in a ScrollView, and need to set our width/height ourselves. | 
| 70   View* parent = GetParent(); | 70   if (!parent()) | 
| 71   if (!parent) |  | 
| 72     return; | 71     return; | 
| 73 | 72 | 
| 74   // Use our current y, unless it means part of the menu isn't visible anymore. | 73   // Use our current y, unless it means part of the menu isn't visible anymore. | 
| 75   int pref_height = GetPreferredSize().height(); | 74   int pref_height = GetPreferredSize().height(); | 
| 76   int new_y; | 75   int new_y; | 
| 77   if (pref_height > parent->height()) | 76   if (pref_height > parent()->height()) | 
| 78     new_y = std::max(parent->height() - pref_height, y()); | 77     new_y = std::max(parent()->height() - pref_height, y()); | 
| 79   else | 78   else | 
| 80     new_y = 0; | 79     new_y = 0; | 
| 81   SetBounds(x(), new_y, parent->width(), pref_height); | 80   SetBounds(x(), new_y, parent()->width(), pref_height); | 
| 82 | 81 | 
| 83   gfx::Insets insets = GetInsets(); | 82   gfx::Insets insets = GetInsets(); | 
| 84   int x = insets.left(); | 83   int x = insets.left(); | 
| 85   int y = insets.top(); | 84   int y = insets.top(); | 
| 86   int menu_item_width = width() - insets.width(); | 85   int menu_item_width = width() - insets.width(); | 
| 87   for (int i = 0; i < GetChildViewCount(); ++i) { | 86   for (int i = 0; i < child_count(); ++i) { | 
| 88     View* child = GetChildViewAt(i); | 87     View* child = GetChildViewAt(i); | 
| 89     if (child->IsVisible()) { | 88     if (child->IsVisible()) { | 
| 90       gfx::Size child_pref_size = child->GetPreferredSize(); | 89       gfx::Size child_pref_size = child->GetPreferredSize(); | 
| 91       child->SetBounds(x, y, menu_item_width, child_pref_size.height()); | 90       child->SetBounds(x, y, menu_item_width, child_pref_size.height()); | 
| 92       y += child_pref_size.height(); | 91       y += child_pref_size.height(); | 
| 93     } | 92     } | 
| 94   } | 93   } | 
| 95 } | 94 } | 
| 96 | 95 | 
| 97 gfx::Size SubmenuView::GetPreferredSize() { | 96 gfx::Size SubmenuView::GetPreferredSize() { | 
| 98   if (GetChildViewCount() == 0) | 97   if (!has_children()) | 
| 99     return gfx::Size(); | 98     return gfx::Size(); | 
| 100 | 99 | 
| 101   max_accelerator_width_ = 0; | 100   max_accelerator_width_ = 0; | 
| 102   int max_width = 0; | 101   int max_width = 0; | 
| 103   int height = 0; | 102   int height = 0; | 
| 104   for (int i = 0; i < GetChildViewCount(); ++i) { | 103   for (int i = 0; i < child_count(); ++i) { | 
| 105     View* child = GetChildViewAt(i); | 104     View* child = GetChildViewAt(i); | 
| 106     gfx::Size child_pref_size = child->IsVisible() ? | 105     gfx::Size child_pref_size = child->IsVisible() ? | 
| 107         child->GetPreferredSize() : gfx::Size(); | 106         child->GetPreferredSize() : gfx::Size(); | 
| 108     max_width = std::max(max_width, child_pref_size.width()); | 107     max_width = std::max(max_width, child_pref_size.width()); | 
| 109     height += child_pref_size.height(); | 108     height += child_pref_size.height(); | 
| 110     if (child->GetID() == MenuItemView::kMenuItemViewID) { | 109     if (child->GetID() == MenuItemView::kMenuItemViewID) { | 
| 111       MenuItemView* menu = static_cast<MenuItemView*>(child); | 110       MenuItemView* menu = static_cast<MenuItemView*>(child); | 
| 112       max_accelerator_width_ = | 111       max_accelerator_width_ = | 
| 113           std::max(max_accelerator_width_, menu->GetAcceleratorTextWidth()); | 112           std::max(max_accelerator_width_, menu->GetAcceleratorTextWidth()); | 
| 114     } | 113     } | 
| (...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 372       item_bounds.set_height(kDropIndicatorHeight); | 371       item_bounds.set_height(kDropIndicatorHeight); | 
| 373       return item_bounds; | 372       return item_bounds; | 
| 374 | 373 | 
| 375     default: | 374     default: | 
| 376       // Don't render anything for on. | 375       // Don't render anything for on. | 
| 377       return gfx::Rect(); | 376       return gfx::Rect(); | 
| 378   } | 377   } | 
| 379 } | 378 } | 
| 380 | 379 | 
| 381 }  // namespace views | 380 }  // namespace views | 
| OLD | NEW | 
|---|