summaryrefslogtreecommitdiffstats
path: root/accessible/html/HTMLSelectAccessible.h
blob: e2498a52f886dd1dee076978653da9809680472d (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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_a11y_HTMLSelectAccessible_h__
#define mozilla_a11y_HTMLSelectAccessible_h__

#include "HTMLFormControlAccessible.h"

namespace mozilla {
namespace a11y {

/**
 *  Selects, Listboxes and Comboboxes, are made up of a number of different
 *  widgets, some of which are shared between the two. This file contains
 *  all of the widgets for both of the Selects, for HTML only.
 *
 *  Listbox:
 *     - HTMLSelectListAccessible
 *        - HTMLSelectOptionAccessible
 *
 *  Comboboxes:
 *     - HTMLComboboxAccessible
 *        - HTMLComboboxListAccessible  [ inserted in accessible tree ]
 *           - HTMLSelectOptionAccessible(s)
 */

/*
 * The list that contains all the options in the select.
 */
class HTMLSelectListAccessible : public AccessibleWrap {
 public:
  HTMLSelectListAccessible(nsIContent* aContent, DocAccessible* aDoc);
  virtual ~HTMLSelectListAccessible() {}

  // LocalAccessible
  virtual a11y::role NativeRole() const override;
  virtual uint64_t NativeState() const override;
  virtual bool IsAcceptableChild(nsIContent* aEl) const override;
  virtual bool AttributeChangesState(nsAtom* aAttribute) override;

  // SelectAccessible
  virtual bool SelectAll() override;
  virtual bool UnselectAll() override;

  // Widgets
  virtual bool IsWidget() const override;
  virtual bool IsActiveWidget() const override;
  virtual bool AreItemsOperable() const override;
  virtual LocalAccessible* CurrentItem() const override;
  virtual void SetCurrentItem(const LocalAccessible* aItem) override;
};

/*
 * Options inside the select, contained within the list
 */
class HTMLSelectOptionAccessible : public HyperTextAccessibleWrap {
 public:
  enum { eAction_Select = 0 };

  HTMLSelectOptionAccessible(nsIContent* aContent, DocAccessible* aDoc);
  virtual ~HTMLSelectOptionAccessible() {}

  // LocalAccessible
  virtual a11y::role NativeRole() const override;
  virtual uint64_t NativeState() const override;
  virtual uint64_t NativeInteractiveState() const override;

  virtual nsRect RelativeBounds(nsIFrame** aBoundingFrame) const override;
  virtual void SetSelected(bool aSelect) override;

  // ActionAccessible
  virtual bool HasPrimaryAction() const override;
  virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;

  // Widgets
  virtual LocalAccessible* ContainerWidget() const override;

 protected:
  // LocalAccessible
  virtual ENameValueFlag NativeName(nsString& aName) const override;
  virtual void DOMAttributeChanged(int32_t aNameSpaceID, nsAtom* aAttribute,
                                   int32_t aModType,
                                   const nsAttrValue* aOldValue,
                                   uint64_t aOldState) override;

 private:
  /**
   * Return a select accessible the option belongs to if any.
   */
  LocalAccessible* GetSelect() const {
    LocalAccessible* parent = mParent;
    if (parent && parent->IsHTMLOptGroup()) {
      parent = parent->LocalParent();
    }

    if (parent && parent->IsListControl()) {
      LocalAccessible* combobox = parent->LocalParent();
      return combobox && combobox->IsCombobox() ? combobox : mParent;
    }

    return nullptr;
  }

  /**
   * Return a combobox accessible the option belongs to if any.
   */
  LocalAccessible* GetCombobox() const {
    LocalAccessible* parent = mParent;
    if (parent && parent->IsHTMLOptGroup()) {
      parent = parent->LocalParent();
    }

    if (parent && parent->IsListControl()) {
      LocalAccessible* combobox = parent->LocalParent();
      return combobox && combobox->IsCombobox() ? combobox : nullptr;
    }

    return nullptr;
  }
};

/*
 * Opt Groups inside the select, contained within the list
 */
class HTMLSelectOptGroupAccessible : public HTMLSelectOptionAccessible {
 public:
  HTMLSelectOptGroupAccessible(nsIContent* aContent, DocAccessible* aDoc)
      : HTMLSelectOptionAccessible(aContent, aDoc) {
    mType = eHTMLOptGroupType;
  }
  virtual ~HTMLSelectOptGroupAccessible() {}

  // LocalAccessible
  virtual a11y::role NativeRole() const override;
  virtual uint64_t NativeInteractiveState() const override;
  virtual bool IsAcceptableChild(nsIContent* aEl) const override;

  // ActionAccessible
  virtual bool HasPrimaryAction() const override;
};

/** ------------------------------------------------------ */
/**  Finally, the Combobox widgets                         */
/** ------------------------------------------------------ */

class HTMLComboboxListAccessible;

/*
 * A class the represents the HTML Combobox widget.
 */
class HTMLComboboxAccessible final : public AccessibleWrap {
 public:
  enum { eAction_Click = 0 };

  HTMLComboboxAccessible(nsIContent* aContent, DocAccessible* aDoc);
  virtual ~HTMLComboboxAccessible() {}

  // LocalAccessible
  virtual void Shutdown() override;
  virtual void Description(nsString& aDescription) const override;
  virtual void Value(nsString& aValue) const override;
  virtual a11y::role NativeRole() const override;
  virtual uint64_t NativeState() const override;
  virtual bool RemoveChild(LocalAccessible* aChild) override;
  virtual bool IsAcceptableChild(nsIContent* aEl) const override;

  // ActionAccessible
  virtual bool HasPrimaryAction() const override;
  virtual void ActionNameAt(uint8_t aIndex, nsAString& aName) override;

  // Widgets
  virtual bool IsWidget() const override;
  virtual bool IsActiveWidget() const override;
  virtual bool AreItemsOperable() const override;
  virtual LocalAccessible* CurrentItem() const override;
  virtual void SetCurrentItem(const LocalAccessible* aItem) override;

  HTMLComboboxListAccessible* List() const { return mListAccessible; }

  /**
   * Return selected option.
   */
  LocalAccessible* SelectedOption() const;

 private:
  RefPtr<HTMLComboboxListAccessible> mListAccessible;
};

/*
 * A class that represents the window that lives to the right
 * of the drop down button inside the Select. This is the window
 * that is made visible when the button is pressed.
 */
class HTMLComboboxListAccessible : public HTMLSelectListAccessible {
 public:
  HTMLComboboxListAccessible(LocalAccessible* aParent, nsIContent* aContent,
                             DocAccessible* aDoc);
  virtual ~HTMLComboboxListAccessible() {}

  // LocalAccessible
  virtual a11y::role NativeRole() const override;
  virtual uint64_t NativeState() const override;
  virtual nsRect RelativeBounds(nsIFrame** aBoundingFrame) const override;
  virtual bool IsAcceptableChild(nsIContent* aEl) const override;

  // Widgets
  virtual bool IsActiveWidget() const override;
  virtual bool AreItemsOperable() const override;
};

}  // namespace a11y
}  // namespace mozilla

#endif