• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/WebAXObject.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 blink::WebAXObject;
16 using blink::WebDocument;
17 using blink::WebFrame;
18 using blink::WebView;
19 
20 namespace content {
21 
RendererAccessibility(RenderViewImpl * render_view)22 RendererAccessibility::RendererAccessibility(
23     RenderViewImpl* render_view)
24     : RenderViewObserver(render_view),
25       render_view_(render_view),
26       logging_(false) {
27   const CommandLine& command_line = *CommandLine::ForCurrentProcess();
28   if (command_line.HasSwitch(switches::kEnableAccessibilityLogging))
29     logging_ = true;
30 }
31 
~RendererAccessibility()32 RendererAccessibility::~RendererAccessibility() {
33 }
34 
GetMainDocument()35 WebDocument RendererAccessibility::GetMainDocument() {
36   WebView* view = render_view()->GetWebView();
37   WebFrame* main_frame = view ? view->mainFrame() : NULL;
38 
39   if (main_frame)
40     return main_frame->document();
41 
42   return WebDocument();
43 }
44 
45 #ifndef NDEBUG
AccessibilityEventToString(blink::WebAXEvent event)46 const std::string RendererAccessibility::AccessibilityEventToString(
47     blink::WebAXEvent event) {
48   switch (event) {
49     case blink::WebAXEventActiveDescendantChanged:
50       return "active descendant changed";
51     case blink::WebAXEventAriaAttributeChanged:
52       return "aria attribute changed";
53     case blink::WebAXEventAutocorrectionOccured:
54       return "autocorrection occurred";
55     case blink::WebAXEventBlur:
56       return "blur";
57     case blink::WebAXEventAlert:
58       return "alert";
59     case blink::WebAXEventCheckedStateChanged:
60       return "check state changed";
61     case blink::WebAXEventChildrenChanged:
62       return "children changed";
63     case blink::WebAXEventFocus:
64       return "focus changed";
65     case blink::WebAXEventInvalidStatusChanged:
66       return "invalid status changed";
67     case blink::WebAXEventLayoutComplete:
68       return "layout complete";
69     case blink::WebAXEventLiveRegionChanged:
70       return "live region changed";
71     case blink::WebAXEventLoadComplete:
72       return "load complete";
73     case blink::WebAXEventMenuListItemSelected:
74       return "menu list item selected";
75     case blink::WebAXEventMenuListValueChanged:
76       return "menu list changed";
77     case blink::WebAXEventShow:
78       return "object show";
79     case blink::WebAXEventHide:
80       return "object hide";
81     case blink::WebAXEventRowCountChanged:
82       return "row count changed";
83     case blink::WebAXEventRowCollapsed:
84       return "row collapsed";
85     case blink::WebAXEventRowExpanded:
86       return "row expanded";
87     case blink::WebAXEventScrolledToAnchor:
88       return "scrolled to anchor";
89     case blink::WebAXEventSelectedChildrenChanged:
90       return "selected children changed";
91     case blink::WebAXEventSelectedTextChanged:
92       return "selected text changed";
93     case blink::WebAXEventTextChanged:
94       return "text changed";
95     case blink::WebAXEventTextInserted:
96       return "text inserted";
97     case blink::WebAXEventTextRemoved:
98       return "text removed";
99     case blink::WebAXEventValueChanged:
100       return "value changed";
101     default:
102       NOTREACHED();
103   }
104   return "";
105 }
106 #endif
107 
108 }  // namespace content
109