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 3 // found in the LICENSE file. 4 5 #include "content/renderer/accessibility/renderer_accessibility.h" 6 7 #include "base/command_line.h" 8 #include "content/public/common/content_switches.h" 9 #include "content/renderer/render_view_impl.h" 10 #include "third_party/WebKit/public/web/WebAccessibilityObject.h" 11 #include "third_party/WebKit/public/web/WebDocument.h" 12 #include "third_party/WebKit/public/web/WebFrame.h" 13 #include "third_party/WebKit/public/web/WebView.h" 14 15 using WebKit::WebAccessibilityNotification; 16 using WebKit::WebAccessibilityObject; 17 using WebKit::WebDocument; 18 using WebKit::WebFrame; 19 using WebKit::WebView; 20 21 namespace content { 22 23 RendererAccessibility::RendererAccessibility( 24 RenderViewImpl* render_view) 25 : RenderViewObserver(render_view), 26 render_view_(render_view), 27 logging_(false) { 28 const CommandLine& command_line = *CommandLine::ForCurrentProcess(); 29 if (command_line.HasSwitch(switches::kEnableAccessibilityLogging)) 30 logging_ = true; 31 } 32 33 RendererAccessibility::~RendererAccessibility() { 34 } 35 36 WebDocument RendererAccessibility::GetMainDocument() { 37 WebView* view = render_view()->GetWebView(); 38 WebFrame* main_frame = view ? view->mainFrame() : NULL; 39 40 if (main_frame) 41 return main_frame->document(); 42 43 return WebDocument(); 44 } 45 46 #ifndef NDEBUG 47 const std::string RendererAccessibility::AccessibilityNotificationToString( 48 AccessibilityNotification notification) { 49 switch (notification) { 50 case AccessibilityNotificationActiveDescendantChanged: 51 return "active descendant changed"; 52 case AccessibilityNotificationAriaAttributeChanged: 53 return "aria attribute changed"; 54 case AccessibilityNotificationAutocorrectionOccurred: 55 return "autocorrection occurred"; 56 case AccessibilityNotificationBlur: 57 return "blur"; 58 case AccessibilityNotificationAlert: 59 return "alert"; 60 case AccessibilityNotificationCheckStateChanged: 61 return "check state changed"; 62 case AccessibilityNotificationChildrenChanged: 63 return "children changed"; 64 case AccessibilityNotificationFocusChanged: 65 return "focus changed"; 66 case AccessibilityNotificationInvalidStatusChanged: 67 return "invalid status changed"; 68 case AccessibilityNotificationLayoutComplete: 69 return "layout complete"; 70 case AccessibilityNotificationLiveRegionChanged: 71 return "live region changed"; 72 case AccessibilityNotificationLoadComplete: 73 return "load complete"; 74 case AccessibilityNotificationMenuListItemSelected: 75 return "menu list item selected"; 76 case AccessibilityNotificationMenuListValueChanged: 77 return "menu list changed"; 78 case AccessibilityNotificationObjectShow: 79 return "object show"; 80 case AccessibilityNotificationObjectHide: 81 return "object hide"; 82 case AccessibilityNotificationRowCountChanged: 83 return "row count changed"; 84 case AccessibilityNotificationRowCollapsed: 85 return "row collapsed"; 86 case AccessibilityNotificationRowExpanded: 87 return "row expanded"; 88 case AccessibilityNotificationScrolledToAnchor: 89 return "scrolled to anchor"; 90 case AccessibilityNotificationSelectedChildrenChanged: 91 return "selected children changed"; 92 case AccessibilityNotificationSelectedTextChanged: 93 return "selected text changed"; 94 case AccessibilityNotificationTextChanged: 95 return "text changed"; 96 case AccessibilityNotificationTextInserted: 97 return "text inserted"; 98 case AccessibilityNotificationTextRemoved: 99 return "text removed"; 100 case AccessibilityNotificationValueChanged: 101 return "value changed"; 102 default: 103 NOTREACHED(); 104 } 105 return ""; 106 } 107 #endif 108 109 } // namespace content 110