Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(23)

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXRadioInput.cpp

Issue 2805493002: Boolean properties for Accessibility Object Model Phase 1 (Closed)
Patch Set: Back to previous patchset, ready to land Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "modules/accessibility/AXRadioInput.h" 5 #include "modules/accessibility/AXRadioInput.h"
6 6
7 #include "core/InputTypeNames.h" 7 #include "core/InputTypeNames.h"
8 #include "core/html/HTMLInputElement.h" 8 #include "core/html/HTMLInputElement.h"
9 #include "core/html/forms/RadioInputType.h" 9 #include "core/html/forms/RadioInputType.h"
10 #include "core/layout/LayoutObject.h" 10 #include "core/layout/LayoutObject.h"
(...skipping 20 matching lines...) Expand all
31 } 31 }
32 32
33 void AXRadioInput::UpdatePosAndSetSize(int position) { 33 void AXRadioInput::UpdatePosAndSetSize(int position) {
34 if (position) 34 if (position)
35 pos_in_set_ = position; 35 pos_in_set_ = position;
36 set_size_ = SizeOfRadioGroup(); 36 set_size_ = SizeOfRadioGroup();
37 } 37 }
38 38
39 void AXRadioInput::RequestUpdateToNextNode(bool forward) { 39 void AXRadioInput::RequestUpdateToNextNode(bool forward) {
40 HTMLInputElement* next_element = 40 HTMLInputElement* next_element =
41 RadioInputType::NextRadioButtonInGroup(GetElement(), forward); 41 RadioInputType::NextRadioButtonInGroup(GetInputElement(), forward);
42 AXObjectImpl* next_a_xobject = AxObjectCache().Get(next_element); 42 AXObjectImpl* next_axobject = AxObjectCache().Get(next_element);
43 if (!next_a_xobject || !next_a_xobject->IsAXRadioInput()) 43 if (!next_axobject || !next_axobject->IsAXRadioInput())
44 return; 44 return;
45 45
46 int position = 0; 46 int position = 0;
47 if (forward) 47 if (forward)
48 position = PosInSet() + 1; 48 position = PosInSet() + 1;
49 // If it is backward, it keeps position as positions are already assigned for 49 // If it is backward, it keeps position as positions are already assigned for
50 // previous objects. updatePosAndSetSize() is called with '0' and it doesn't 50 // previous objects. updatePosAndSetSize() is called with '0' and it doesn't
51 // modify m_posInSet and updates m_setSize as size is increased. 51 // modify m_posInSet and updates m_setSize as size is increased.
52 52
53 ToAXRadioInput(next_a_xobject)->UpdatePosAndSetSize(position); 53 ToAXRadioInput(next_axobject)->UpdatePosAndSetSize(position);
54 AxObjectCache().PostNotification(next_a_xobject, 54 AxObjectCache().PostNotification(next_axobject,
55 AXObjectCacheImpl::kAXAriaAttributeChanged); 55 AXObjectCacheImpl::kAXAriaAttributeChanged);
56 ToAXRadioInput(next_a_xobject)->RequestUpdateToNextNode(forward); 56 ToAXRadioInput(next_axobject)->RequestUpdateToNextNode(forward);
57 } 57 }
58 58
59 HTMLInputElement* AXRadioInput::FindFirstRadioButtonInGroup( 59 HTMLInputElement* AXRadioInput::FindFirstRadioButtonInGroup(
60 HTMLInputElement* current) const { 60 HTMLInputElement* current) const {
61 while (HTMLInputElement* prev_element = 61 while (HTMLInputElement* prev_element =
62 RadioInputType::NextRadioButtonInGroup(current, false)) 62 RadioInputType::NextRadioButtonInGroup(current, false))
63 current = prev_element; 63 current = prev_element;
64 return current; 64 return current;
65 } 65 }
66 66
67 int AXRadioInput::PosInSet() const { 67 int AXRadioInput::PosInSet() const {
68 if (HasAttribute(aria_posinsetAttr)) 68 if (HasAttribute(aria_posinsetAttr))
69 return GetAttribute(aria_posinsetAttr).ToInt(); 69 return GetAttribute(aria_posinsetAttr).ToInt();
70 return pos_in_set_; 70 return pos_in_set_;
71 } 71 }
72 72
73 int AXRadioInput::SetSize() const { 73 int AXRadioInput::SetSize() const {
74 if (HasAttribute(aria_setsizeAttr)) 74 if (HasAttribute(aria_setsizeAttr))
75 return GetAttribute(aria_setsizeAttr).ToInt(); 75 return GetAttribute(aria_setsizeAttr).ToInt();
76 return set_size_; 76 return set_size_;
77 } 77 }
78 78
79 bool AXRadioInput::CalculatePosInSet() { 79 bool AXRadioInput::CalculatePosInSet() {
80 // Calculate 'posInSet' attribute when AXRadioInputs need to be updated 80 // Calculate 'posInSet' attribute when AXRadioInputs need to be updated
81 // as a new AXRadioInput Object is added or one of objects from RadioGroup is 81 // as a new AXRadioInput Object is added or one of objects from RadioGroup is
82 // removed. 82 // removed.
83 bool need_to_update_prev = false; 83 bool need_to_update_prev = false;
84 int position = 1; 84 int position = 1;
85 HTMLInputElement* prev_element = 85 HTMLInputElement* prev_element =
86 RadioInputType::NextRadioButtonInGroup(GetElement(), false); 86 RadioInputType::NextRadioButtonInGroup(GetInputElement(), false);
87 if (prev_element) { 87 if (prev_element) {
88 AXObjectImpl* object = AxObjectCache().Get(prev_element); 88 AXObjectImpl* object = AxObjectCache().Get(prev_element);
89 // If the previous element doesn't have AXObjectImpl yet, caculate position 89 // If the previous element doesn't have AXObjectImpl yet, caculate position
90 // from the first element. Otherwise, get position from the previous 90 // from the first element. Otherwise, get position from the previous
91 // AXObjectImpl. 91 // AXObjectImpl.
92 if (!object || !object->IsAXRadioInput()) { 92 if (!object || !object->IsAXRadioInput()) {
93 position = CountFromFirstElement(); 93 position = CountFromFirstElement();
94 } else { 94 } else {
95 position = object->PosInSet() + 1; 95 position = object->PosInSet() + 1;
96 // It returns true if previous objects need to be updated. 96 // It returns true if previous objects need to be updated.
97 // When AX tree exists already and a new node is inserted, 97 // When AX tree exists already and a new node is inserted,
98 // as updating is started from the inserted node, 98 // as updating is started from the inserted node,
99 // we need to update setSize for previous nodes. 99 // we need to update setSize for previous nodes.
100 if (SetSize() != object->SetSize()) 100 if (SetSize() != object->SetSize())
101 need_to_update_prev = true; 101 need_to_update_prev = true;
102 } 102 }
103 } 103 }
104 UpdatePosAndSetSize(position); 104 UpdatePosAndSetSize(position);
105 105
106 // If it is not the last element, request update to the next node. 106 // If it is not the last element, request update to the next node.
107 if (position != SetSize()) 107 if (position != SetSize())
108 RequestUpdateToNextNode(true); 108 RequestUpdateToNextNode(true);
109 return need_to_update_prev; 109 return need_to_update_prev;
110 } 110 }
111 111
112 int AXRadioInput::CountFromFirstElement() const { 112 int AXRadioInput::CountFromFirstElement() const {
113 int count = 1; 113 int count = 1;
114 HTMLInputElement* current = GetElement(); 114 HTMLInputElement* current = GetInputElement();
115 while (HTMLInputElement* prev_element = 115 while (HTMLInputElement* prev_element =
116 RadioInputType::NextRadioButtonInGroup(current, false)) { 116 RadioInputType::NextRadioButtonInGroup(current, false)) {
117 current = prev_element; 117 current = prev_element;
118 count++; 118 count++;
119 } 119 }
120 return count; 120 return count;
121 } 121 }
122 122
123 HTMLInputElement* AXRadioInput::GetElement() const { 123 HTMLInputElement* AXRadioInput::GetInputElement() const {
124 return toHTMLInputElement(layout_object_->GetNode()); 124 return toHTMLInputElement(layout_object_->GetNode());
125 } 125 }
126 126
127 int AXRadioInput::SizeOfRadioGroup() const { 127 int AXRadioInput::SizeOfRadioGroup() const {
128 int size = GetElement()->SizeOfRadioGroup(); 128 int size = GetInputElement()->SizeOfRadioGroup();
129 // If it has no size in Group, it means that there is only itself. 129 // If it has no size in Group, it means that there is only itself.
130 if (!size) 130 if (!size)
131 return 1; 131 return 1;
132 return size; 132 return size;
133 } 133 }
134 134
135 } // namespace blink 135 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698