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/menu_controller.h" | 5 #include "ui/views/controls/menu/menu_controller.h" |
6 | 6 |
7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
8 #include <windowsx.h> | 8 #include <windowsx.h> |
9 #endif | 9 #endif |
10 | 10 |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 if (menu->GetMnemonic()) | 96 if (menu->GetMnemonic()) |
97 return false; | 97 return false; |
98 | 98 |
99 string16 lower_title = base::i18n::ToLower(menu->title()); | 99 string16 lower_title = base::i18n::ToLower(menu->title()); |
100 return !lower_title.empty() && lower_title[0] == key; | 100 return !lower_title.empty() && lower_title[0] == key; |
101 } | 101 } |
102 | 102 |
103 } // namespace | 103 } // namespace |
104 | 104 |
105 // Returns the first descendant of |view| that is hot tracked. | 105 // Returns the first descendant of |view| that is hot tracked. |
106 static View* GetFirstHotTrackedView(View* view) { | 106 static CustomButton* GetFirstHotTrackedView(View* view) { |
107 if (!view) | 107 if (!view) |
108 return NULL; | 108 return NULL; |
109 | 109 CustomButton* button = CustomButton::AsCustomButton(view); |
110 if (!strcmp(view->GetClassName(), CustomButton::kViewClassName)) { | 110 if (button) { |
111 CustomButton* button = static_cast<CustomButton*>(view); | |
112 if (button->IsHotTracked()) | 111 if (button->IsHotTracked()) |
113 return button; | 112 return button; |
114 } | 113 } |
115 | 114 |
116 for (int i = 0; i < view->child_count(); ++i) { | 115 for (int i = 0; i < view->child_count(); ++i) { |
117 View* hot_view = GetFirstHotTrackedView(view->child_at(i)); | 116 CustomButton* hot_view = GetFirstHotTrackedView(view->child_at(i)); |
118 if (hot_view) | 117 if (hot_view) |
119 return hot_view; | 118 return hot_view; |
120 } | 119 } |
121 return NULL; | 120 return NULL; |
122 } | 121 } |
123 | 122 |
124 // Recurses through the child views of |view| returning the first view starting | 123 // Recurses through the child views of |view| returning the first view starting |
125 // at |start| that is focusable. A value of -1 for |start| indicates to start at | 124 // at |start| that is focusable. A value of -1 for |start| indicates to start at |
126 // the first view (if |forward| is false, iterating starts at the last view). If | 125 // the first view (if |forward| is false, iterating starts at the last view). If |
127 // |forward| is true the children are considered first to last, otherwise last | 126 // |forward| is true the children are considered first to last, otherwise last |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
801 std::vector<MenuItemView*> current_path; | 800 std::vector<MenuItemView*> current_path; |
802 std::vector<MenuItemView*> new_path; | 801 std::vector<MenuItemView*> new_path; |
803 BuildPathsAndCalculateDiff(pending_state_.item, menu_item, ¤t_path, | 802 BuildPathsAndCalculateDiff(pending_state_.item, menu_item, ¤t_path, |
804 &new_path, &paths_differ_at); | 803 &new_path, &paths_differ_at); |
805 | 804 |
806 size_t current_size = current_path.size(); | 805 size_t current_size = current_path.size(); |
807 size_t new_size = new_path.size(); | 806 size_t new_size = new_path.size(); |
808 | 807 |
809 bool pending_item_changed = pending_state_.item != menu_item; | 808 bool pending_item_changed = pending_state_.item != menu_item; |
810 if (pending_item_changed && pending_state_.item) { | 809 if (pending_item_changed && pending_state_.item) { |
811 View* current_hot_view = GetFirstHotTrackedView(pending_state_.item); | 810 CustomButton* button = GetFirstHotTrackedView(pending_state_.item); |
812 if (current_hot_view && !strcmp(current_hot_view->GetClassName(), | 811 if (button) |
813 CustomButton::kViewClassName)) { | |
814 CustomButton* button = static_cast<CustomButton*>(current_hot_view); | |
815 button->SetHotTracked(false); | 812 button->SetHotTracked(false); |
816 } | |
817 } | 813 } |
818 | 814 |
819 // Notify the old path it isn't selected. | 815 // Notify the old path it isn't selected. |
820 MenuDelegate* current_delegate = | 816 MenuDelegate* current_delegate = |
821 current_path.empty() ? NULL : current_path.front()->GetDelegate(); | 817 current_path.empty() ? NULL : current_path.front()->GetDelegate(); |
822 for (size_t i = paths_differ_at; i < current_size; ++i) { | 818 for (size_t i = paths_differ_at; i < current_size; ++i) { |
823 if (current_delegate && | 819 if (current_delegate && |
824 current_path[i]->GetType() == MenuItemView::SUBMENU) { | 820 current_path[i]->GetType() == MenuItemView::SUBMENU) { |
825 current_delegate->WillHideMenu(current_path[i]); | 821 current_delegate->WillHideMenu(current_path[i]); |
826 } | 822 } |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1182 if (owner_) | 1178 if (owner_) |
1183 owner_->RemoveObserver(this); | 1179 owner_->RemoveObserver(this); |
1184 if (active_instance_ == this) | 1180 if (active_instance_ == this) |
1185 active_instance_ = NULL; | 1181 active_instance_ = NULL; |
1186 StopShowTimer(); | 1182 StopShowTimer(); |
1187 StopCancelAllTimer(); | 1183 StopCancelAllTimer(); |
1188 } | 1184 } |
1189 | 1185 |
1190 MenuController::SendAcceleratorResultType | 1186 MenuController::SendAcceleratorResultType |
1191 MenuController::SendAcceleratorToHotTrackedView() { | 1187 MenuController::SendAcceleratorToHotTrackedView() { |
1192 View* hot_view = GetFirstHotTrackedView(pending_state_.item); | 1188 CustomButton* hot_view = GetFirstHotTrackedView(pending_state_.item); |
1193 if (!hot_view) | 1189 if (!hot_view) |
1194 return ACCELERATOR_NOT_PROCESSED; | 1190 return ACCELERATOR_NOT_PROCESSED; |
1195 | 1191 |
1196 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); | 1192 ui::Accelerator accelerator(ui::VKEY_RETURN, ui::EF_NONE); |
1197 hot_view->AcceleratorPressed(accelerator); | 1193 hot_view->AcceleratorPressed(accelerator); |
1198 if (!strcmp(hot_view->GetClassName(), CustomButton::kViewClassName)) { | 1194 CustomButton* button = static_cast<CustomButton*>(hot_view); |
1199 CustomButton* button = static_cast<CustomButton*>(hot_view); | 1195 button->SetHotTracked(true); |
1200 button->SetHotTracked(true); | |
1201 } | |
1202 return (exit_type_ == EXIT_NONE) ? | 1196 return (exit_type_ == EXIT_NONE) ? |
1203 ACCELERATOR_PROCESSED : ACCELERATOR_PROCESSED_EXIT; | 1197 ACCELERATOR_PROCESSED : ACCELERATOR_PROCESSED_EXIT; |
1204 } | 1198 } |
1205 | 1199 |
1206 void MenuController::UpdateInitialLocation( | 1200 void MenuController::UpdateInitialLocation( |
1207 const gfx::Rect& bounds, | 1201 const gfx::Rect& bounds, |
1208 MenuItemView::AnchorPosition position, | 1202 MenuItemView::AnchorPosition position, |
1209 bool context_menu) { | 1203 bool context_menu) { |
1210 pending_state_.context_menu = context_menu; | 1204 pending_state_.context_menu = context_menu; |
1211 pending_state_.initial_bounds = bounds; | 1205 pending_state_.initial_bounds = bounds; |
(...skipping 725 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1937 item->GetSubmenu()->IsShowing()) { | 1931 item->GetSubmenu()->IsShowing()) { |
1938 // A menu is selected and open, but none of its children are selected, | 1932 // A menu is selected and open, but none of its children are selected, |
1939 // select the first menu item. | 1933 // select the first menu item. |
1940 if (item->GetSubmenu()->GetMenuItemCount()) { | 1934 if (item->GetSubmenu()->GetMenuItemCount()) { |
1941 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT); | 1935 SetSelection(item->GetSubmenu()->GetMenuItemAt(0), SELECTION_DEFAULT); |
1942 return; | 1936 return; |
1943 } | 1937 } |
1944 } | 1938 } |
1945 | 1939 |
1946 if (item->has_children()) { | 1940 if (item->has_children()) { |
1947 View* hot_view = GetFirstHotTrackedView(item); | 1941 CustomButton* button = GetFirstHotTrackedView(item); |
1948 if (hot_view && | 1942 if (button) { |
1949 !strcmp(hot_view->GetClassName(), CustomButton::kViewClassName)) { | |
1950 CustomButton* button = static_cast<CustomButton*>(hot_view); | |
1951 button->SetHotTracked(false); | 1943 button->SetHotTracked(false); |
1952 View* to_make_hot = GetNextFocusableView(item, button, delta == 1); | 1944 View* to_make_hot = GetNextFocusableView(item, button, delta == 1); |
1953 if (to_make_hot && | 1945 CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot); |
1954 !strcmp(to_make_hot->GetClassName(), CustomButton::kViewClassName)) { | 1946 if (button_hot) { |
1955 CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot); | |
1956 button_hot->SetHotTracked(true); | 1947 button_hot->SetHotTracked(true); |
1957 return; | 1948 return; |
1958 } | 1949 } |
1959 } else { | 1950 } else { |
1960 View* to_make_hot = GetInitialFocusableView(item, delta == 1); | 1951 View* to_make_hot = GetInitialFocusableView(item, delta == 1); |
1961 if (to_make_hot && | 1952 CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot); |
1962 !strcmp(to_make_hot->GetClassName(), CustomButton::kViewClassName)) { | 1953 if (button_hot) { |
1963 CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot); | |
1964 button_hot->SetHotTracked(true); | 1954 button_hot->SetHotTracked(true); |
1965 return; | 1955 return; |
1966 } | 1956 } |
1967 } | 1957 } |
1968 } | 1958 } |
1969 | 1959 |
1970 MenuItemView* parent = item->GetParentMenuItem(); | 1960 MenuItemView* parent = item->GetParentMenuItem(); |
1971 if (parent) { | 1961 if (parent) { |
1972 int parent_count = parent->GetSubmenu()->GetMenuItemCount(); | 1962 int parent_count = parent->GetSubmenu()->GetMenuItemCount(); |
1973 if (parent_count > 1) { | 1963 if (parent_count > 1) { |
1974 for (int i = 0; i < parent_count; ++i) { | 1964 for (int i = 0; i < parent_count; ++i) { |
1975 if (parent->GetSubmenu()->GetMenuItemAt(i) == item) { | 1965 if (parent->GetSubmenu()->GetMenuItemAt(i) == item) { |
1976 MenuItemView* to_select = | 1966 MenuItemView* to_select = |
1977 FindNextSelectableMenuItem(parent, i, delta); | 1967 FindNextSelectableMenuItem(parent, i, delta); |
1978 if (!to_select) | 1968 if (!to_select) |
1979 break; | 1969 break; |
1980 SetSelection(to_select, SELECTION_DEFAULT); | 1970 SetSelection(to_select, SELECTION_DEFAULT); |
1981 View* to_make_hot = GetInitialFocusableView(to_select, delta == 1); | 1971 View* to_make_hot = GetInitialFocusableView(to_select, delta == 1); |
1982 if (to_make_hot && !strcmp(to_make_hot->GetClassName(), | 1972 CustomButton* button_hot = CustomButton::AsCustomButton(to_make_hot); |
1983 CustomButton::kViewClassName)) { | 1973 if (button_hot) |
1984 CustomButton* button_hot = static_cast<CustomButton*>(to_make_hot); | |
1985 button_hot->SetHotTracked(true); | 1974 button_hot->SetHotTracked(true); |
1986 } | |
1987 break; | 1975 break; |
1988 } | 1976 } |
1989 } | 1977 } |
1990 } | 1978 } |
1991 } | 1979 } |
1992 } | 1980 } |
1993 | 1981 |
1994 MenuItemView* MenuController::FindNextSelectableMenuItem(MenuItemView* parent, | 1982 MenuItemView* MenuController::FindNextSelectableMenuItem(MenuItemView* parent, |
1995 int index, | 1983 int index, |
1996 int delta) { | 1984 int delta) { |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2324 (!pending_state_.item->HasSubmenu() || | 2312 (!pending_state_.item->HasSubmenu() || |
2325 !pending_state_.item->GetSubmenu()->IsShowing())) { | 2313 !pending_state_.item->GetSubmenu()->IsShowing())) { |
2326 // On exit if the user hasn't selected an item with a submenu, move the | 2314 // On exit if the user hasn't selected an item with a submenu, move the |
2327 // selection back to the parent menu item. | 2315 // selection back to the parent menu item. |
2328 SetSelection(pending_state_.item->GetParentMenuItem(), | 2316 SetSelection(pending_state_.item->GetParentMenuItem(), |
2329 SELECTION_OPEN_SUBMENU); | 2317 SELECTION_OPEN_SUBMENU); |
2330 } | 2318 } |
2331 } | 2319 } |
2332 | 2320 |
2333 } // namespace views | 2321 } // namespace views |
OLD | NEW |