OLD | NEW |
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 Loading... |
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 AXObject* next_a_xobject = AxObjectCache().Get(next_element); | 42 AXObject* next_a_xobject = AxObjectCache().Get(next_element); |
43 if (!next_a_xobject || !next_a_xobject->IsAXRadioInput()) | 43 if (!next_a_xobject || !next_a_xobject->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. |
(...skipping 24 matching lines...) Expand all Loading... |
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 AXObject* object = AxObjectCache().Get(prev_element); | 88 AXObject* object = AxObjectCache().Get(prev_element); |
89 // If the previous element doesn't have AXObject yet, caculate position from | 89 // If the previous element doesn't have AXObject yet, caculate position from |
90 // the first element. Otherwise, get position from the previous AXObject. | 90 // the first element. Otherwise, get position from the previous AXObject. |
91 if (!object || !object->IsAXRadioInput()) { | 91 if (!object || !object->IsAXRadioInput()) { |
92 position = CountFromFirstElement(); | 92 position = CountFromFirstElement(); |
93 } else { | 93 } else { |
94 position = object->PosInSet() + 1; | 94 position = object->PosInSet() + 1; |
95 // It returns true if previous objects need to be updated. | 95 // It returns true if previous objects need to be updated. |
96 // When AX tree exists already and a new node is inserted, | 96 // When AX tree exists already and a new node is inserted, |
97 // as updating is started from the inserted node, | 97 // as updating is started from the inserted node, |
98 // we need to update setSize for previous nodes. | 98 // we need to update setSize for previous nodes. |
99 if (SetSize() != object->SetSize()) | 99 if (SetSize() != object->SetSize()) |
100 need_to_update_prev = true; | 100 need_to_update_prev = true; |
101 } | 101 } |
102 } | 102 } |
103 UpdatePosAndSetSize(position); | 103 UpdatePosAndSetSize(position); |
104 | 104 |
105 // If it is not the last element, request update to the next node. | 105 // If it is not the last element, request update to the next node. |
106 if (position != SetSize()) | 106 if (position != SetSize()) |
107 RequestUpdateToNextNode(true); | 107 RequestUpdateToNextNode(true); |
108 return need_to_update_prev; | 108 return need_to_update_prev; |
109 } | 109 } |
110 | 110 |
111 int AXRadioInput::CountFromFirstElement() const { | 111 int AXRadioInput::CountFromFirstElement() const { |
112 int count = 1; | 112 int count = 1; |
113 HTMLInputElement* current = GetElement(); | 113 HTMLInputElement* current = GetInputElement(); |
114 while (HTMLInputElement* prev_element = | 114 while (HTMLInputElement* prev_element = |
115 RadioInputType::NextRadioButtonInGroup(current, false)) { | 115 RadioInputType::NextRadioButtonInGroup(current, false)) { |
116 current = prev_element; | 116 current = prev_element; |
117 count++; | 117 count++; |
118 } | 118 } |
119 return count; | 119 return count; |
120 } | 120 } |
121 | 121 |
122 HTMLInputElement* AXRadioInput::GetElement() const { | 122 HTMLInputElement* AXRadioInput::GetInputElement() const { |
123 return toHTMLInputElement(layout_object_->GetNode()); | 123 return toHTMLInputElement(layout_object_->GetNode()); |
124 } | 124 } |
125 | 125 |
126 int AXRadioInput::SizeOfRadioGroup() const { | 126 int AXRadioInput::SizeOfRadioGroup() const { |
127 int size = GetElement()->SizeOfRadioGroup(); | 127 int size = GetInputElement()->SizeOfRadioGroup(); |
128 // If it has no size in Group, it means that there is only itself. | 128 // If it has no size in Group, it means that there is only itself. |
129 if (!size) | 129 if (!size) |
130 return 1; | 130 return 1; |
131 return size; | 131 return size; |
132 } | 132 } |
133 | 133 |
134 } // namespace blink | 134 } // namespace blink |
OLD | NEW |