| 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" |
| 11 #include "modules/accessibility/AXObjectCacheImpl.h" | 11 #include "modules/accessibility/AXObjectCacheImpl.h" |
| 12 | 12 |
| 13 namespace blink { | 13 namespace blink { |
| 14 | 14 |
| 15 using namespace HTMLNames; | 15 using namespace HTMLNames; |
| 16 | 16 |
| 17 AXRadioInput::AXRadioInput(LayoutObject* layoutObject, | 17 AXRadioInput::AXRadioInput(LayoutObject* layoutObject, |
| 18 AXObjectCacheImpl& axObjectCache) | 18 AXObjectCacheImpl& axObjectCache) |
| 19 : AXLayoutObject(layoutObject, axObjectCache) { | 19 : AXLayoutObject(layoutObject, axObjectCache) { |
| 20 // Updates posInSet and setSize for the current object and the next objects. | 20 // Updates posInSet and setSize for the current object and the next objects. |
| 21 if (!calculatePosInSet()) | 21 if (!calculatePosInSet()) |
| 22 return; | 22 return; |
| 23 // When a new object is inserted, it needs to update setSize for the previous
objects. | 23 // When a new object is inserted, it needs to update setSize for the previous |
| 24 // objects. |
| 24 requestUpdateToNextNode(false); | 25 requestUpdateToNextNode(false); |
| 25 } | 26 } |
| 26 | 27 |
| 27 AXRadioInput* AXRadioInput::create(LayoutObject* layoutObject, | 28 AXRadioInput* AXRadioInput::create(LayoutObject* layoutObject, |
| 28 AXObjectCacheImpl& axObjectCache) { | 29 AXObjectCacheImpl& axObjectCache) { |
| 29 return new AXRadioInput(layoutObject, axObjectCache); | 30 return new AXRadioInput(layoutObject, axObjectCache); |
| 30 } | 31 } |
| 31 | 32 |
| 32 void AXRadioInput::updatePosAndSetSize(int position) { | 33 void AXRadioInput::updatePosAndSetSize(int position) { |
| 33 if (position) | 34 if (position) |
| 34 m_posInSet = position; | 35 m_posInSet = position; |
| 35 m_setSize = sizeOfRadioGroup(); | 36 m_setSize = sizeOfRadioGroup(); |
| 36 } | 37 } |
| 37 | 38 |
| 38 void AXRadioInput::requestUpdateToNextNode(bool forward) { | 39 void AXRadioInput::requestUpdateToNextNode(bool forward) { |
| 39 HTMLInputElement* nextElement = | 40 HTMLInputElement* nextElement = |
| 40 RadioInputType::nextRadioButtonInGroup(element(), forward); | 41 RadioInputType::nextRadioButtonInGroup(element(), forward); |
| 41 AXObject* nextAXobject = axObjectCache().get(nextElement); | 42 AXObject* nextAXobject = axObjectCache().get(nextElement); |
| 42 if (!nextAXobject || !nextAXobject->isAXRadioInput()) | 43 if (!nextAXobject || !nextAXobject->isAXRadioInput()) |
| 43 return; | 44 return; |
| 44 | 45 |
| 45 int position = 0; | 46 int position = 0; |
| 46 if (forward) | 47 if (forward) |
| 47 position = posInSet() + 1; | 48 position = posInSet() + 1; |
| 48 // If it is backward, it keeps position as positions are already assigned for
previous objects. | 49 // If it is backward, it keeps position as positions are already assigned for |
| 49 // updatePosAndSetSize() is called with '0' and it doesn't modify m_posInSet a
nd updates m_setSize as size is increased. | 50 // previous objects. updatePosAndSetSize() is called with '0' and it doesn't |
| 51 // modify m_posInSet and updates m_setSize as size is increased. |
| 50 | 52 |
| 51 toAXRadioInput(nextAXobject)->updatePosAndSetSize(position); | 53 toAXRadioInput(nextAXobject)->updatePosAndSetSize(position); |
| 52 axObjectCache().postNotification(nextAXobject, | 54 axObjectCache().postNotification(nextAXobject, |
| 53 AXObjectCacheImpl::AXAriaAttributeChanged); | 55 AXObjectCacheImpl::AXAriaAttributeChanged); |
| 54 toAXRadioInput(nextAXobject)->requestUpdateToNextNode(forward); | 56 toAXRadioInput(nextAXobject)->requestUpdateToNextNode(forward); |
| 55 } | 57 } |
| 56 | 58 |
| 57 HTMLInputElement* AXRadioInput::findFirstRadioButtonInGroup( | 59 HTMLInputElement* AXRadioInput::findFirstRadioButtonInGroup( |
| 58 HTMLInputElement* current) const { | 60 HTMLInputElement* current) const { |
| 59 while (HTMLInputElement* prevElement = | 61 while (HTMLInputElement* prevElement = |
| 60 RadioInputType::nextRadioButtonInGroup(current, false)) | 62 RadioInputType::nextRadioButtonInGroup(current, false)) |
| 61 current = prevElement; | 63 current = prevElement; |
| 62 return current; | 64 return current; |
| 63 } | 65 } |
| 64 | 66 |
| 65 int AXRadioInput::posInSet() const { | 67 int AXRadioInput::posInSet() const { |
| 66 if (hasAttribute(aria_posinsetAttr)) | 68 if (hasAttribute(aria_posinsetAttr)) |
| 67 return getAttribute(aria_posinsetAttr).toInt(); | 69 return getAttribute(aria_posinsetAttr).toInt(); |
| 68 return m_posInSet; | 70 return m_posInSet; |
| 69 } | 71 } |
| 70 | 72 |
| 71 int AXRadioInput::setSize() const { | 73 int AXRadioInput::setSize() const { |
| 72 if (hasAttribute(aria_setsizeAttr)) | 74 if (hasAttribute(aria_setsizeAttr)) |
| 73 return getAttribute(aria_setsizeAttr).toInt(); | 75 return getAttribute(aria_setsizeAttr).toInt(); |
| 74 return m_setSize; | 76 return m_setSize; |
| 75 } | 77 } |
| 76 | 78 |
| 77 bool AXRadioInput::calculatePosInSet() { | 79 bool AXRadioInput::calculatePosInSet() { |
| 78 // Calculate 'posInSet' attribute when AXRadioInputs need to be updated | 80 // Calculate 'posInSet' attribute when AXRadioInputs need to be updated |
| 79 // as a new AXRadioInput Object is added or one of objects from RadioGroup is
removed. | 81 // as a new AXRadioInput Object is added or one of objects from RadioGroup is |
| 82 // removed. |
| 80 bool needToUpdatePrev = false; | 83 bool needToUpdatePrev = false; |
| 81 int position = 1; | 84 int position = 1; |
| 82 HTMLInputElement* prevElement = | 85 HTMLInputElement* prevElement = |
| 83 RadioInputType::nextRadioButtonInGroup(element(), false); | 86 RadioInputType::nextRadioButtonInGroup(element(), false); |
| 84 if (prevElement) { | 87 if (prevElement) { |
| 85 AXObject* object = axObjectCache().get(prevElement); | 88 AXObject* object = axObjectCache().get(prevElement); |
| 86 // If the previous element doesn't have AXObject yet, caculate position from
the first element. | 89 // If the previous element doesn't have AXObject yet, caculate position from |
| 87 // Otherwise, get position from the previous AXObject. | 90 // the first element. Otherwise, get position from the previous AXObject. |
| 88 if (!object || !object->isAXRadioInput()) { | 91 if (!object || !object->isAXRadioInput()) { |
| 89 position = countFromFirstElement(); | 92 position = countFromFirstElement(); |
| 90 } else { | 93 } else { |
| 91 position = object->posInSet() + 1; | 94 position = object->posInSet() + 1; |
| 92 // It returns true if previous objects need to be updated. | 95 // It returns true if previous objects need to be updated. |
| 93 // When AX tree exists already and a new node is inserted, | 96 // When AX tree exists already and a new node is inserted, |
| 94 // as updating is started from the inserted node, | 97 // as updating is started from the inserted node, |
| 95 // we need to update setSize for previous nodes. | 98 // we need to update setSize for previous nodes. |
| 96 if (setSize() != object->setSize()) | 99 if (setSize() != object->setSize()) |
| 97 needToUpdatePrev = true; | 100 needToUpdatePrev = true; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 122 | 125 |
| 123 int AXRadioInput::sizeOfRadioGroup() const { | 126 int AXRadioInput::sizeOfRadioGroup() const { |
| 124 int size = element()->sizeOfRadioGroup(); | 127 int size = element()->sizeOfRadioGroup(); |
| 125 // 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. |
| 126 if (!size) | 129 if (!size) |
| 127 return 1; | 130 return 1; |
| 128 return size; | 131 return size; |
| 129 } | 132 } |
| 130 | 133 |
| 131 } // namespace blink | 134 } // namespace blink |
| OLD | NEW |