Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(588)

Side by Side Diff: views/controls/menu/menu_controller.cc

Issue 6452011: Rework tree APIs to reflect Google style and more const-correctness.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « views/controls/button/radio_button.cc ('k') | views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 (int 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 (int 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 (int i = start == -1 ? view->child_count() - 1 : start; i >= 0; --i) {
107 i >= 0; --i) {
108 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, 107 View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1,
109 forward); 108 forward);
110 if (deepest) 109 if (deepest)
111 return deepest; 110 return deepest;
112 } 111 }
113 } 112 }
114 return view->IsFocusableInRootView() ? view : NULL; 113 return view->IsFocusableInRootView() ? view : NULL;
115 } 114 }
116 115
117 // Returns the first child of |start| that is focusable. 116 // Returns the first child of |start| that is focusable.
118 static View* GetInitialFocusableView(View* start, bool forward) { 117 static View* GetInitialFocusableView(View* start, bool forward) {
119 return GetFirstFocusableView(start, -1, forward); 118 return GetFirstFocusableView(start, -1, forward);
120 } 119 }
121 120
122 // Returns the next view after |start_at| that is focusable. Returns NULL if 121 // Returns the next view after |start_at| that is focusable. Returns NULL if
123 // there are no focusable children of |ancestor| after |start_at|. 122 // there are no focusable children of |ancestor| after |start_at|.
124 static View* GetNextFocusableView(View* ancestor, 123 static View* GetNextFocusableView(View* ancestor,
125 View* start_at, 124 View* start_at,
126 bool forward) { 125 bool forward) {
127 DCHECK(ancestor->IsParentOf(start_at)); 126 DCHECK(ancestor->Contains(start_at));
128 View* parent = start_at; 127 View* parent = start_at;
129 do { 128 do {
130 View* new_parent = parent->GetParent(); 129 View* new_parent = parent->parent();
131 int index = new_parent->GetChildIndex(parent); 130 int index = new_parent->GetIndexOf(parent);
132 index += forward ? 1 : -1; 131 index += forward ? 1 : -1;
133 if (forward || index != -1) { 132 if (forward || index != -1) {
134 View* next = GetFirstFocusableView(new_parent, index, forward); 133 View* next = GetFirstFocusableView(new_parent, index, forward);
135 if (next) 134 if (next)
136 return next; 135 return next;
137 } 136 }
138 parent = new_parent; 137 parent = new_parent;
139 } while (parent != ancestor); 138 } while (parent != ancestor);
140 return NULL; 139 return NULL;
141 } 140 }
(...skipping 949 matching lines...) Expand 10 before | Expand all | Expand 10 after
1091 i->submenu_open = false; 1090 i->submenu_open = false;
1092 i->item = last_item; 1091 i->item = last_item;
1093 } 1092 }
1094 } 1093 }
1095 1094
1096 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { 1095 MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) {
1097 // Walk the view hierarchy until we find a menu item (or the root). 1096 // Walk the view hierarchy until we find a menu item (or the root).
1098 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); 1097 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y));
1099 while (child_under_mouse && 1098 while (child_under_mouse &&
1100 child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) { 1099 child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) {
1101 child_under_mouse = child_under_mouse->GetParent(); 1100 child_under_mouse = child_under_mouse->parent();
1102 } 1101 }
1103 if (child_under_mouse && child_under_mouse->IsEnabled() && 1102 if (child_under_mouse && child_under_mouse->IsEnabled() &&
1104 child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) { 1103 child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) {
1105 return static_cast<MenuItemView*>(child_under_mouse); 1104 return static_cast<MenuItemView*>(child_under_mouse);
1106 } 1105 }
1107 return NULL; 1106 return NULL;
1108 } 1107 }
1109 1108
1110 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) { 1109 MenuItemView* MenuController::GetEmptyMenuItemAt(View* source, int x, int y) {
1111 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); 1110 View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y));
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 item->GetSubmenu()->IsShowing()) { 1485 item->GetSubmenu()->IsShowing()) {
1487 // A menu is selected and open, but none of its children are selected, 1486 // A menu is selected and open, but none of its children are selected,
1488 // select the first menu item. 1487 // select the first menu item.
1489 if (item->GetSubmenu()->GetMenuItemCount()) { 1488 if (item->GetSubmenu()->GetMenuItemCount()) {
1490 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT); 1489 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT);
1491 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0)); 1490 ScrollToVisible(item->GetSubmenu()->GetMenuItemAt(0));
1492 return; 1491 return;
1493 } 1492 }
1494 } 1493 }
1495 1494
1496 if (item->GetChildViewCount()) { 1495 if (item->has_children()) {
1497 View* hot_view = GetFirstHotTrackedView(item); 1496 View* hot_view = GetFirstHotTrackedView(item);
1498 if (hot_view) { 1497 if (hot_view) {
1499 hot_view->SetHotTracked(false); 1498 hot_view->SetHotTracked(false);
1500 View* to_make_hot = GetNextFocusableView(item, hot_view, delta == 1); 1499 View* to_make_hot = GetNextFocusableView(item, hot_view, delta == 1);
1501 if (to_make_hot) { 1500 if (to_make_hot) {
1502 to_make_hot->SetHotTracked(true); 1501 to_make_hot->SetHotTracked(true);
1503 return; 1502 return;
1504 } 1503 }
1505 } else { 1504 } else {
1506 View* to_make_hot = GetInitialFocusableView(item, delta == 1); 1505 View* to_make_hot = GetInitialFocusableView(item, delta == 1);
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1759 1758
1760 void MenuController::StopScrolling() { 1759 void MenuController::StopScrolling() {
1761 scroll_task_.reset(NULL); 1760 scroll_task_.reset(NULL);
1762 } 1761 }
1763 1762
1764 void MenuController::UpdateActiveMouseView(SubmenuView* event_source, 1763 void MenuController::UpdateActiveMouseView(SubmenuView* event_source,
1765 const MouseEvent& event, 1764 const MouseEvent& event,
1766 View* target_menu) { 1765 View* target_menu) {
1767 View* target = NULL; 1766 View* target = NULL;
1768 gfx::Point target_menu_loc(event.location()); 1767 gfx::Point target_menu_loc(event.location());
1769 if (target_menu && target_menu->GetChildViewCount()) { 1768 if (target_menu && target_menu->has_children()) {
1770 // Locate the deepest child view to send events to. This code assumes we 1769 // 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 1770 // 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 1771 // is currently true for the cases we are embedding views, but if we embed
1773 // more complex hierarchies it'll need to change. 1772 // more complex hierarchies it'll need to change.
1774 View::ConvertPointToScreen(event_source->GetScrollViewContainer(), 1773 View::ConvertPointToScreen(event_source->GetScrollViewContainer(),
1775 &target_menu_loc); 1774 &target_menu_loc);
1776 View::ConvertPointToView(NULL, target_menu, &target_menu_loc); 1775 View::ConvertPointToView(NULL, target_menu, &target_menu_loc);
1777 target = target_menu->GetViewForPoint(target_menu_loc); 1776 target = target_menu->GetViewForPoint(target_menu_loc);
1778 if (target == target_menu || !target->IsEnabled()) 1777 if (target == target_menu || !target->IsEnabled())
1779 target = NULL; 1778 target = NULL;
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
1836 1835
1837 MouseEvent release_event(Event::ET_MOUSE_RELEASED, -1, -1, 0); 1836 MouseEvent release_event(Event::ET_MOUSE_RELEASED, -1, -1, 0);
1838 // Reset the active_mouse_view_ before sending mouse released. That way if if 1837 // 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. 1838 // calls back to use we aren't in a weird state.
1840 View* active_view = active_mouse_view_; 1839 View* active_view = active_mouse_view_;
1841 active_mouse_view_ = NULL; 1840 active_mouse_view_ = NULL;
1842 active_view->OnMouseReleased(release_event, true); 1841 active_view->OnMouseReleased(release_event, true);
1843 } 1842 }
1844 1843
1845 } // namespace views 1844 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/button/radio_button.cc ('k') | views/controls/menu/menu_item_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698