| OLD | NEW | 
|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/ui/views/accessibility_event_router_views.h" | 5 #include "chrome/browser/ui/views/accessibility_event_router_views.h" | 
| 6 | 6 | 
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" | 
| 8 #include "base/callback.h" | 8 #include "base/callback.h" | 
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" | 
| 10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" | 
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 155     views::View* view, NotificationType type, Profile* profile) { | 155     views::View* view, NotificationType type, Profile* profile) { | 
| 156   std::string name = GetViewName(view); | 156   std::string name = GetViewName(view); | 
| 157 | 157 | 
| 158   bool has_submenu = false; | 158   bool has_submenu = false; | 
| 159   int index = -1; | 159   int index = -1; | 
| 160   int count = -1; | 160   int count = -1; | 
| 161 | 161 | 
| 162   if (view->GetClassName() == views::MenuItemView::kViewClassName) | 162   if (view->GetClassName() == views::MenuItemView::kViewClassName) | 
| 163     has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); | 163     has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); | 
| 164 | 164 | 
| 165   views::View* parent_menu = view->GetParent(); | 165   views::View* parent_menu = view->parent(); | 
| 166   while (parent_menu != NULL && parent_menu->GetClassName() != | 166   while (parent_menu != NULL && parent_menu->GetClassName() != | 
| 167          views::SubmenuView::kViewClassName) { | 167          views::SubmenuView::kViewClassName) { | 
| 168     parent_menu = parent_menu->GetParent(); | 168     parent_menu = parent_menu->parent(); | 
| 169   } | 169   } | 
| 170   if (parent_menu) { | 170   if (parent_menu) { | 
| 171     count = 0; | 171     count = 0; | 
| 172     RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 172     RecursiveGetMenuItemIndexAndCount(parent_menu, view, &index, &count); | 
| 173   } | 173   } | 
| 174 | 174 | 
| 175   AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); | 175   AccessibilityMenuItemInfo info(profile, name, has_submenu, index, count); | 
| 176   SendAccessibilityNotification(type, &info); | 176   SendAccessibilityNotification(type, &info); | 
| 177 } | 177 } | 
| 178 | 178 | 
| 179 void AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 179 void AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( | 
| 180     views::View* menu, views::View* item, int* index, int* count) { | 180     views::View* menu, views::View* item, int* index, int* count) { | 
| 181   for (int i = 0; i < menu->GetChildViewCount(); ++i) { | 181   for (int i = 0; i < menu->child_count(); ++i) { | 
| 182     views::View* child = menu->GetChildViewAt(i); | 182     views::View* child = menu->GetChildViewAt(i); | 
| 183     int previous_count = *count; | 183     int previous_count = *count; | 
| 184     RecursiveGetMenuItemIndexAndCount(child, item, index, count); | 184     RecursiveGetMenuItemIndexAndCount(child, item, index, count); | 
| 185     if (child->GetClassName() == views::MenuItemView::kViewClassName && | 185     if (child->GetClassName() == views::MenuItemView::kViewClassName && | 
| 186         *count == previous_count) { | 186         *count == previous_count) { | 
| 187       if (item == child) | 187       if (item == child) | 
| 188         *index = *count; | 188         *index = *count; | 
| 189       (*count)++; | 189       (*count)++; | 
| 190     } else if (child->GetClassName() == views::TextButton::kViewClassName) { | 190     } else if (child->GetClassName() == views::TextButton::kViewClassName) { | 
| 191       if (item == child) | 191       if (item == child) | 
| 192         *index = *count; | 192         *index = *count; | 
| 193       (*count)++; | 193       (*count)++; | 
| 194     } | 194     } | 
| 195   } | 195   } | 
| 196 } | 196 } | 
| 197 | 197 | 
| 198 bool AccessibilityEventRouterViews::IsMenuEvent( | 198 bool AccessibilityEventRouterViews::IsMenuEvent( | 
| 199     views::View* view, NotificationType type) { | 199     views::View* view, NotificationType type) { | 
| 200   if (type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 200   if (type == NotificationType::ACCESSIBILITY_MENU_OPENED || | 
| 201       type == NotificationType::ACCESSIBILITY_MENU_CLOSED) | 201       type == NotificationType::ACCESSIBILITY_MENU_CLOSED) | 
| 202     return true; | 202     return true; | 
| 203 | 203 | 
| 204   while (view) { | 204   while (view) { | 
| 205     AccessibilityTypes::Role role = view->GetAccessibleRole(); | 205     AccessibilityTypes::Role role = view->GetAccessibleRole(); | 
| 206     if (role == AccessibilityTypes::ROLE_MENUITEM || | 206     if (role == AccessibilityTypes::ROLE_MENUITEM || | 
| 207         role == AccessibilityTypes::ROLE_MENUPOPUP) { | 207         role == AccessibilityTypes::ROLE_MENUPOPUP) { | 
| 208       return true; | 208       return true; | 
| 209     } | 209     } | 
| 210     view = view->GetParent(); | 210     view = view->parent(); | 
| 211   } | 211   } | 
| 212 | 212 | 
| 213   return false; | 213   return false; | 
| 214 } | 214 } | 
| 215 | 215 | 
| 216 void AccessibilityEventRouterViews::SendLocationBarNotification( | 216 void AccessibilityEventRouterViews::SendLocationBarNotification( | 
| 217     views::View* view, NotificationType type, Profile* profile) { | 217     views::View* view, NotificationType type, Profile* profile) { | 
| 218 #if defined(OS_WIN) | 218 #if defined(OS_WIN) | 
| 219   // This particular method isn't needed on Linux/Views, we get text | 219   // This particular method isn't needed on Linux/Views, we get text | 
| 220   // notifications directly from GTK. | 220   // notifications directly from GTK. | 
| 221   std::string name = GetViewName(view); | 221   std::string name = GetViewName(view); | 
| 222   LocationBarView* location_bar = static_cast<LocationBarView*>(view); | 222   LocationBarView* location_bar = static_cast<LocationBarView*>(view); | 
| 223   AutocompleteEditViewWin* location_entry = | 223   AutocompleteEditViewWin* location_entry = | 
| 224       static_cast<AutocompleteEditViewWin*>(location_bar->location_entry()); | 224       static_cast<AutocompleteEditViewWin*>(location_bar->location_entry()); | 
| 225 | 225 | 
| 226   std::string value = WideToUTF8(location_entry->GetText()); | 226   std::string value = WideToUTF8(location_entry->GetText()); | 
| 227   std::wstring::size_type selection_start; | 227   std::wstring::size_type selection_start; | 
| 228   std::wstring::size_type selection_end; | 228   std::wstring::size_type selection_end; | 
| 229   location_entry->GetSelectionBounds(&selection_start, &selection_end); | 229   location_entry->GetSelectionBounds(&selection_start, &selection_end); | 
| 230 | 230 | 
| 231   AccessibilityTextBoxInfo info(profile, name, false); | 231   AccessibilityTextBoxInfo info(profile, name, false); | 
| 232   info.SetValue(value, selection_start, selection_end); | 232   info.SetValue(value, selection_start, selection_end); | 
| 233   SendAccessibilityNotification(type, &info); | 233   SendAccessibilityNotification(type, &info); | 
| 234 #endif | 234 #endif | 
| 235 } | 235 } | 
| OLD | NEW | 
|---|