| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright (C) 2008 Apple Inc. All rights reserved. |    2  * Copyright (C) 2008 Apple Inc. All rights reserved. | 
|    3  * |    3  * | 
|    4  * Redistribution and use in source and binary forms, with or without |    4  * Redistribution and use in source and binary forms, with or without | 
|    5  * modification, are permitted provided that the following conditions |    5  * modification, are permitted provided that the following conditions | 
|    6  * are met: |    6  * are met: | 
|    7  * |    7  * | 
|    8  * 1.  Redistributions of source code must retain the above copyright |    8  * 1.  Redistributions of source code must retain the above copyright | 
|    9  *     notice, this list of conditions and the following disclaimer. |    9  *     notice, this list of conditions and the following disclaimer. | 
|   10  * 2.  Redistributions in binary form must reproduce the above copyright |   10  * 2.  Redistributions in binary form must reproduce the above copyright | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   46  |   46  | 
|   47 AXListBox::~AXListBox() |   47 AXListBox::~AXListBox() | 
|   48 { |   48 { | 
|   49 } |   49 } | 
|   50  |   50  | 
|   51 PassRefPtr<AXListBox> AXListBox::create(RenderObject* renderer) |   51 PassRefPtr<AXListBox> AXListBox::create(RenderObject* renderer) | 
|   52 { |   52 { | 
|   53     return adoptRef(new AXListBox(renderer)); |   53     return adoptRef(new AXListBox(renderer)); | 
|   54 } |   54 } | 
|   55  |   55  | 
|   56 bool AXListBox::canSetSelectedChildrenAttribute() const |  | 
|   57 { |  | 
|   58     Node* selectNode = m_renderer->node(); |  | 
|   59     if (!selectNode) |  | 
|   60         return false; |  | 
|   61  |  | 
|   62     return !toHTMLSelectElement(selectNode)->isDisabledFormControl(); |  | 
|   63 } |  | 
|   64  |  | 
|   65 void AXListBox::addChildren() |   56 void AXListBox::addChildren() | 
|   66 { |   57 { | 
|   67     Node* selectNode = m_renderer->node(); |   58     Node* selectNode = m_renderer->node(); | 
|   68     if (!selectNode) |   59     if (!selectNode) | 
|   69         return; |   60         return; | 
|   70  |   61  | 
|   71     m_haveChildren = true; |   62     m_haveChildren = true; | 
|   72  |   63  | 
|   73     const Vector<HTMLElement*>& listItems = toHTMLSelectElement(selectNode)->lis
     tItems(); |   64     const Vector<HTMLElement*>& listItems = toHTMLSelectElement(selectNode)->lis
     tItems(); | 
|   74     unsigned length = listItems.size(); |   65     unsigned length = listItems.size(); | 
|   75     for (unsigned i = 0; i < length; i++) { |   66     for (unsigned i = 0; i < length; i++) { | 
|   76         // The cast to HTMLElement below is safe because the only other possible
      listItem type |   67         // The cast to HTMLElement below is safe because the only other possible
      listItem type | 
|   77         // would be a WMLElement, but WML builds don't use accessibility feature
     s at all. |   68         // would be a WMLElement, but WML builds don't use accessibility feature
     s at all. | 
|   78         AXObject* listOption = listBoxOptionAXObject(listItems[i]); |   69         AXObject* listOption = listBoxOptionAXObject(listItems[i]); | 
|   79         if (listOption && !listOption->accessibilityIsIgnored()) |   70         if (listOption && !listOption->accessibilityIsIgnored()) | 
|   80             m_children.append(listOption); |   71             m_children.append(listOption); | 
|   81     } |   72     } | 
|   82 } |   73 } | 
|   83  |   74  | 
|   84 void AXListBox::setSelectedChildren(AccessibilityChildrenVector& children) |  | 
|   85 { |  | 
|   86     if (!canSetSelectedChildrenAttribute()) |  | 
|   87         return; |  | 
|   88  |  | 
|   89     Node* selectNode = m_renderer->node(); |  | 
|   90     if (!selectNode) |  | 
|   91         return; |  | 
|   92  |  | 
|   93     // disable any selected options |  | 
|   94     unsigned length = m_children.size(); |  | 
|   95     for (unsigned i = 0; i < length; i++) { |  | 
|   96         AXListBoxOption* listBoxOption = toAXListBoxOption(m_children[i].get()); |  | 
|   97         if (listBoxOption->isSelected()) |  | 
|   98             listBoxOption->setSelected(false); |  | 
|   99     } |  | 
|  100  |  | 
|  101     length = children.size(); |  | 
|  102     for (unsigned i = 0; i < length; i++) { |  | 
|  103         AXObject* obj = children[i].get(); |  | 
|  104         if (obj->roleValue() != ListBoxOptionRole) |  | 
|  105             continue; |  | 
|  106  |  | 
|  107         toAXListBoxOption(obj)->setSelected(true); |  | 
|  108     } |  | 
|  109 } |  | 
|  110  |  | 
|  111 void AXListBox::selectedChildren(AccessibilityChildrenVector& result) |  | 
|  112 { |  | 
|  113     ASSERT(result.isEmpty()); |  | 
|  114  |  | 
|  115     if (!hasChildren()) |  | 
|  116         addChildren(); |  | 
|  117  |  | 
|  118     unsigned length = m_children.size(); |  | 
|  119     for (unsigned i = 0; i < length; i++) { |  | 
|  120         if (toAXListBoxOption(m_children[i].get())->isSelected()) |  | 
|  121             result.append(m_children[i]); |  | 
|  122     } |  | 
|  123 } |  | 
|  124  |  | 
|  125 AXObject* AXListBox::listBoxOptionAXObject(HTMLElement* element) const |   75 AXObject* AXListBox::listBoxOptionAXObject(HTMLElement* element) const | 
|  126 { |   76 { | 
|  127     // skip hr elements |   77     // skip hr elements | 
|  128     if (!element || isHTMLHRElement(*element)) |   78     if (!element || isHTMLHRElement(*element)) | 
|  129         return 0; |   79         return 0; | 
|  130  |   80  | 
|  131     AXObject* listBoxObject = m_renderer->document().axObjectCache()->getOrCreat
     e(ListBoxOptionRole); |   81     AXObject* listBoxObject = m_renderer->document().axObjectCache()->getOrCreat
     e(ListBoxOptionRole); | 
|  132     toAXListBoxOption(listBoxObject)->setHTMLElement(element); |   82     toAXListBoxOption(listBoxObject)->setHTMLElement(element); | 
|  133  |   83  | 
|  134     return listBoxObject; |   84     return listBoxObject; | 
| (...skipping 24 matching lines...) Expand all  Loading... | 
|  159         } |  109         } | 
|  160     } |  110     } | 
|  161  |  111  | 
|  162     if (listBoxOption && !listBoxOption->accessibilityIsIgnored()) |  112     if (listBoxOption && !listBoxOption->accessibilityIsIgnored()) | 
|  163         return listBoxOption; |  113         return listBoxOption; | 
|  164  |  114  | 
|  165     return axObjectCache()->getOrCreate(m_renderer); |  115     return axObjectCache()->getOrCreate(m_renderer); | 
|  166 } |  116 } | 
|  167  |  117  | 
|  168 } // namespace WebCore |  118 } // namespace WebCore | 
| OLD | NEW |