 Chromium Code Reviews
 Chromium Code Reviews Issue 6452011:
  Rework tree APIs to reflect Google style and more const-correctness....  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/
    
  
    Issue 6452011:
  Rework tree APIs to reflect Google style and more const-correctness....  (Closed) 
  Base URL: svn://svn.chromium.org/chrome/trunk/src/| 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/menu_controller.h" | 5 #include "views/controls/menu/menu_controller.h" | 
| 6 | 6 | 
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" | 
| 8 #include "base/time.h" | 8 #include "base/time.h" | 
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" | 
| 10 #include "ui/base/dragdrop/os_exchange_data.h" | 10 #include "ui/base/dragdrop/os_exchange_data.h" | 
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 74 } | 74 } | 
| 75 | 75 | 
| 76 // Returns the first descendant of |view| that is hot tracked. | 76 // Returns the first descendant of |view| that is hot tracked. | 
| 77 static View* GetFirstHotTrackedView(View* view) { | 77 static View* GetFirstHotTrackedView(View* view) { | 
| 78 if (!view) | 78 if (!view) | 
| 79 return NULL; | 79 return NULL; | 
| 80 | 80 | 
| 81 if (view->IsHotTracked()) | 81 if (view->IsHotTracked()) | 
| 82 return view; | 82 return view; | 
| 83 | 83 | 
| 84 for (int i = 0; i < view->GetChildViewCount(); ++i) { | 84 for (size_t i = 0; i < view->child_count(); ++i) { | 
| 85 View* hot_view = GetFirstHotTrackedView(view->GetChildViewAt(i)); | 85 View* hot_view = GetFirstHotTrackedView(view->GetChildViewAt(i)); | 
| 86 if (hot_view) | 86 if (hot_view) | 
| 87 return hot_view; | 87 return hot_view; | 
| 88 } | 88 } | 
| 89 return NULL; | 89 return NULL; | 
| 90 } | 90 } | 
| 91 | 91 | 
| 92 // Recurses through the child views of |view| returning the first view starting | 92 // Recurses through the child views of |view| returning the first view starting | 
| 93 // at |start| that is focusable. A value of -1 for |start| indicates to start at | 93 // at |start| that is focusable. A value of -1 for |start| indicates to start at | 
| 94 // the first view (if |forward| is false, iterating starts at the last view). If | 94 // the first view (if |forward| is false, iterating starts at the last view). If | 
| 95 // |forward| is true the children are considered first to last, otherwise last | 95 // |forward| is true the children are considered first to last, otherwise last | 
| 96 // to first. | 96 // to first. | 
| 97 static View* GetFirstFocusableView(View* view, int start, bool forward) { | 97 static View* GetFirstFocusableView(View* view, int start, bool forward) { | 
| 98 if (forward) { | 98 if (forward) { | 
| 99 for (int i = start == -1 ? 0 : start; i < view->GetChildViewCount(); ++i) { | 99 for (size_t i = start == -1 ? 0 : start; i < view->child_count(); ++i) { | 
| 100 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, | 100 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, | 
| 101 forward); | 101 forward); | 
| 102 if (deepest) | 102 if (deepest) | 
| 103 return deepest; | 103 return deepest; | 
| 104 } | 104 } | 
| 105 } else { | 105 } else { | 
| 106 for (int i = start == -1 ? view->GetChildViewCount() - 1 : start; | 106 for (size_t i = start == -1 ? view->child_count() - 1 : start; | 
| 107 i >= 0; --i) { | 107 i >= 0; --i) { | 
| 
sky
2011/02/08 19:11:54
This never stops if we never find deepest.
PS I d
 | |
| 108 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, | 108 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, | 
| 109 forward); | 109 forward); | 
| 110 if (deepest) | 110 if (deepest) | 
| 111 return deepest; | 111 return deepest; | 
| 112 } | 112 } | 
| 113 } | 113 } | 
| 114 return view->IsFocusableInRootView() ? view : NULL; | 114 return view->IsFocusableInRootView() ? view : NULL; | 
| 115 } | 115 } | 
| 116 | 116 | 
| 117 // Returns the first child of |start| that is focusable. | 117 // Returns the first child of |start| that is focusable. | 
| 118 static View* GetInitialFocusableView(View* start, bool forward) { | 118 static View* GetInitialFocusableView(View* start, bool forward) { | 
| 119 return GetFirstFocusableView(start, -1, forward); | 119 return GetFirstFocusableView(start, -1, forward); | 
| 120 } | 120 } | 
| 121 | 121 | 
| 122 // Returns the next view after |start_at| that is focusable. Returns NULL if | 122 // Returns the next view after |start_at| that is focusable. Returns NULL if | 
| 123 // there are no focusable children of |ancestor| after |start_at|. | 123 // there are no focusable children of |ancestor| after |start_at|. | 
| 124 static View* GetNextFocusableView(View* ancestor, | 124 static View* GetNextFocusableView(View* ancestor, | 
| 125 View* start_at, | 125 View* start_at, | 
| 126 bool forward) { | 126 bool forward) { | 
| 127 DCHECK(ancestor->IsParentOf(start_at)); | 127 DCHECK(ancestor->Contains(start_at)); | 
| 128 View* parent = start_at; | 128 View* parent = start_at; | 
| 129 do { | 129 do { | 
| 130 View* new_parent = parent->GetParent(); | 130 View* new_parent = parent->parent(); | 
| 131 int index = new_parent->GetChildIndex(parent); | 131 int index = new_parent->GetIndexOf(parent); | 
| 132 index += forward ? 1 : -1; | 132 index += forward ? 1 : -1; | 
| 133 if (forward || index != -1) { | 133 if (forward || index != -1) { | 
| 134 View* next = GetFirstFocusableView(new_parent, index, forward); | 134 View* next = GetFirstFocusableView(new_parent, index, forward); | 
| 135 if (next) | 135 if (next) | 
| 136 return next; | 136 return next; | 
| 137 } | 137 } | 
| 138 parent = new_parent; | 138 parent = new_parent; | 
| 139 } while (parent != ancestor); | 139 } while (parent != ancestor); | 
| 140 return NULL; | 140 return NULL; | 
| 141 } | 141 } | 
| (...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1091 i->submenu_open = false; | 1091 i->submenu_open = false; | 
| 1092 i->item = last_item; | 1092 i->item = last_item; | 
| 1093 } | 1093 } | 
| 1094 } | 1094 } | 
| 1095 | 1095 | 
| 1096 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { | 1096 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { | 
| 1097 // Walk the view hierarchy until we find a menu item (or the root). | 1097 // Walk the view hierarchy until we find a menu item (or the root). | 
| 1098 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); | 1098 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); | 
| 1099 while (child_under_mouse && | 1099 while (child_under_mouse && | 
| 1100 child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) { | 1100 child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) { | 
| 1101 child_under_mouse = child_under_mouse->GetParent(); | 1101 child_under_mouse = child_under_mouse->parent(); | 
| 1102 } | 1102 } | 
| 1103 if (child_under_mouse && child_under_mouse->IsEnabled() && | 1103 if (child_under_mouse && child_under_mouse->IsEnabled() && | 
| 1104 child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) { | 1104 child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) { | 
| 1105 return static_cast<MenuItemView*>(child_under_mouse); | 1105 return static_cast<MenuItemView*>(child_under_mouse); | 
| 1106 } | 1106 } | 
| 1107 return NULL; | 1107 return NULL; | 
| 1108 } | 1108 } | 
| 1109 | 1109 | 
| 1110 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { | 1110 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { | 
| 1111 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); | 1111 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); | 
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1486 item->GetSubmenu()->IsShowing()) { | 1486 item->GetSubmenu()->IsShowing()) { | 
| 1487 // A menu is selected and open, but none of its children are selected, | 1487 // A menu is selected and open, but none of its children are selected, | 
| 1488 // select the first menu item. | 1488 // select the first menu item. | 
| 1489 if (item->GetSubmenu()->GetMenuItemCount()) { | 1489 if (item->GetSubmenu()->GetMenuItemCount()) { | 
| 1490 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT); | 1490 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT); | 
| 1491 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0)); | 1491 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0)); | 
| 1492 return; | 1492 return; | 
| 1493 } | 1493 } | 
| 1494 } | 1494 } | 
| 1495 | 1495 | 
| 1496 if (item->GetChildViewCount()) { | 1496 if (item->has_children()) { | 
| 1497 View* hot_view = GetFirstHotTrackedView(item); | 1497 View* hot_view = GetFirstHotTrackedView(item); | 
| 1498 if (hot_view) { | 1498 if (hot_view) { | 
| 1499 hot_view->SetHotTracked(false); | 1499 hot_view->SetHotTracked(false); | 
| 1500 View* to_make_hot = GetNextFocusableView(item, hot_view, delta == 1); | 1500 View* to_make_hot = GetNextFocusableView(item, hot_view, delta == 1); | 
| 1501 if (to_make_hot) { | 1501 if (to_make_hot) { | 
| 1502 to_make_hot->SetHotTracked(true); | 1502 to_make_hot->SetHotTracked(true); | 
| 1503 return; | 1503 return; | 
| 1504 } | 1504 } | 
| 1505 } else { | 1505 } else { | 
| 1506 View* to_make_hot = GetInitialFocusableView(item, delta == 1); | 1506 View* to_make_hot = GetInitialFocusableView(item, delta == 1); | 
| (...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1759 | 1759 | 
| 1760 void MenuController::StopScrolling() { | 1760 void MenuController::StopScrolling() { | 
| 1761 scroll_task_.reset(NULL); | 1761 scroll_task_.reset(NULL); | 
| 1762 } | 1762 } | 
| 1763 | 1763 | 
| 1764 void MenuController::UpdateActiveMouseView(SubmenuView* event_source, | 1764 void MenuController::UpdateActiveMouseView(SubmenuView* event_source, | 
| 1765 const MouseEvent& event, | 1765 const MouseEvent& event, | 
| 1766 View* target_menu) { | 1766 View* target_menu) { | 
| 1767 View* target = NULL; | 1767 View* target = NULL; | 
| 1768 gfx::Point target_menu_loc(event.location()); | 1768 gfx::Point target_menu_loc(event.location()); | 
| 1769 if (target_menu && target_menu->GetChildViewCount()) { | 1769 if (target_menu && target_menu->has_children()) { | 
| 1770 // Locate the deepest child view to send events to. This code assumes we | 1770 // Locate the deepest child view to send events to. This code assumes we | 
| 1771 // don't have to walk up the tree to find a view interested in events. This | 1771 // don't have to walk up the tree to find a view interested in events. This | 
| 1772 // is currently true for the cases we are embedding views, but if we embed | 1772 // is currently true for the cases we are embedding views, but if we embed | 
| 1773 // more complex hierarchies it'll need to change. | 1773 // more complex hierarchies it'll need to change. | 
| 1774 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), | 1774 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), | 
| 1775 &target_menu_loc); | 1775 &target_menu_loc); | 
| 1776 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); | 1776 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); | 
| 1777 target = target_menu->GetViewForPoint(target_menu_loc); | 1777 target = target_menu->GetViewForPoint(target_menu_loc); | 
| 1778 if (target == target_menu || !target->IsEnabled()) | 1778 if (target == target_menu || !target->IsEnabled()) | 
| 1779 target = NULL; | 1779 target = NULL; | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1836 | 1836 | 
| 1837 MouseEvent release_event(Event::ET_MOUSE_RELEASED, -1, -1, 0); | 1837 MouseEvent release_event(Event::ET_MOUSE_RELEASED, -1, -1, 0); | 
| 1838 // Reset the active_mouse_view_ before sending mouse released. That way if if | 1838 // Reset the active_mouse_view_ before sending mouse released. That way if if | 
| 1839 // calls back to use we aren't in a weird state. | 1839 // calls back to use we aren't in a weird state. | 
| 1840 View* active_view = active_mouse_view_; | 1840 View* active_view = active_mouse_view_; | 
| 1841 active_mouse_view_ = NULL; | 1841 active_mouse_view_ = NULL; | 
| 1842 active_view->OnMouseReleased(release_event, true); | 1842 active_view->OnMouseReleased(release_event, true); | 
| 1843 } | 1843 } | 
| 1844 | 1844 | 
| 1845 } // namespace views | 1845 } // namespace views | 
| OLD | NEW |