summaryrefslogtreecommitdiff
path: root/chromium/ui/views/accessibility/view_accessibility.h
blob: 6a366b4cb6fbba1217623e8ecb72ba6a1db85cbf (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
// Copyright 2017 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.

#ifndef UI_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H_
#define UI_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H_

#include <memory>

#include "base/macros.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_unique_id.h"
#include "ui/gfx/native_widget_types.h"
#include "ui/views/views_export.h"

namespace views {

class View;

// An object that manages the accessibility interface for a View.
//
// The default accessibility properties of a View is determined by
// calling View::GetAccessibleNodeData(), which is overridden by many
// View subclasses. ViewAccessibility lets you override these for a
// particular view.
//
// On some platforms, subclasses of ViewAccessibility own the
// AXPlatformNode that implements the native accessibility APIs on that
// platform.
class VIEWS_EXPORT ViewAccessibility {
 public:
  static std::unique_ptr<ViewAccessibility> Create(View* view);

  virtual ~ViewAccessibility();

  // Modifies |node_data| to reflect the current accessible state of the
  // associated View, taking any custom overrides into account
  // (see OverrideRole, etc. below).
  virtual void GetAccessibleNodeData(ui::AXNodeData* node_data) const;

  //
  // These override accessibility information, including properties returned
  // from View::GetAccessibleNodeData().
  // Note that string attributes are only used if non-empty, so you can't
  // override a string with the empty string.
  //
  void OverrideRole(ax::mojom::Role role);
  void OverrideName(const std::string& name);
  void OverrideName(const base::string16& name);
  void OverrideDescription(const std::string& description);
  void OverrideIsLeaf();  // Force this node to be treated as a leaf node.

  virtual void OnAutofillShown(){};
  virtual void OnAutofillHidden(){};

  virtual gfx::NativeViewAccessible GetNativeObject();
  virtual void NotifyAccessibilityEvent(ax::mojom::Event event_type) {}

  virtual const ui::AXUniqueId& GetUniqueId() const;

  bool IsLeaf() const;

 protected:
  explicit ViewAccessibility(View* view);

  View* view() const { return owner_view_; }

 private:
  // Weak. Owns this.
  View* const owner_view_;

  const ui::AXUniqueId unique_id_;

  // Contains data set explicitly via SetRole, SetName, etc. that overrides
  // anything provided by GetAccessibleNodeData().
  ui::AXNodeData custom_data_;

  bool is_leaf_;

  DISALLOW_COPY_AND_ASSIGN(ViewAccessibility);
};

}  // namespace views

#endif  // UI_VIEWS_ACCESSIBILITY_VIEW_ACCESSIBILITY_H_