summaryrefslogtreecommitdiffstats
path: root/content/renderer/renderer_accessibility.cc
blob: 63729cc0a1f084ddc5dd4f43b21a99d041f1e037 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "content/renderer/renderer_accessibility.h"

#include "base/command_line.h"
#include "content/public/common/content_switches.h"
#include "content/renderer/render_view_impl.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"

using WebKit::WebAccessibilityNotification;
using WebKit::WebAccessibilityObject;
using WebKit::WebDocument;
using WebKit::WebFrame;
using WebKit::WebView;

namespace content {

RendererAccessibility::RendererAccessibility(
    RenderViewImpl* render_view)
    : RenderViewObserver(render_view),
      render_view_(render_view),
      logging_(false) {
  const CommandLine& command_line = *CommandLine::ForCurrentProcess();
  if (command_line.HasSwitch(switches::kEnableAccessibilityLogging))
    logging_ = true;
}

RendererAccessibility::~RendererAccessibility() {
}

WebDocument RendererAccessibility::GetMainDocument() {
  WebView* view = render_view()->GetWebView();
  WebFrame* main_frame = view ? view->mainFrame() : NULL;

  if (main_frame)
    return main_frame->document();

  return WebDocument();
}

#ifndef NDEBUG
const std::string RendererAccessibility::AccessibilityNotificationToString(
    AccessibilityNotification notification) {
  switch (notification) {
    case AccessibilityNotificationActiveDescendantChanged:
      return "active descendant changed";
    case AccessibilityNotificationBlur:
      return "blur";
    case AccessibilityNotificationAlert:
      return "alert";
    case AccessibilityNotificationCheckStateChanged:
      return "check state changed";
    case AccessibilityNotificationChildrenChanged:
      return "children changed";
    case AccessibilityNotificationFocusChanged:
      return "focus changed";
    case AccessibilityNotificationLayoutComplete:
      return "layout complete";
    case AccessibilityNotificationLiveRegionChanged:
      return "live region changed";
    case AccessibilityNotificationLoadComplete:
      return "load complete";
    case AccessibilityNotificationMenuListValueChanged:
      return "menu list changed";
    case AccessibilityNotificationObjectShow:
      return "object show";
    case AccessibilityNotificationObjectHide:
      return "object hide";
    case AccessibilityNotificationRowCountChanged:
      return "row count changed";
    case AccessibilityNotificationRowCollapsed:
      return "row collapsed";
    case AccessibilityNotificationRowExpanded:
      return "row expanded";
    case AccessibilityNotificationScrolledToAnchor:
      return "scrolled to anchor";
    case AccessibilityNotificationSelectedChildrenChanged:
      return "selected children changed";
    case AccessibilityNotificationSelectedTextChanged:
      return "selected text changed";
    case AccessibilityNotificationTextInserted:
      return "text inserted";
    case AccessibilityNotificationTextRemoved:
      return "text removed";
    case AccessibilityNotificationValueChanged:
      return "value changed";
    default:
      NOTREACHED();
  }
  return "";
}
#endif

}  // namespace content