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

Side by Side Diff: Source/core/accessibility/AccessibilityNodeObject.cpp

Issue 16081007: Introduce toHTMLInputElement(Node*), and use it. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 6 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 | Annotate | Revision Log
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012, Google Inc. All rights reserved. 2 * Copyright (C) 2012, Google 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 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 } 71 }
72 72
73 // This function implements the ARIA accessible name as described by the Mozilla 73 // This function implements the ARIA accessible name as described by the Mozilla
74 // ARIA Implementer's Guide. 74 // ARIA Implementer's Guide.
75 static String accessibleNameForNode(Node* node) 75 static String accessibleNameForNode(Node* node)
76 { 76 {
77 if (node->isTextNode()) 77 if (node->isTextNode())
78 return toText(node)->data(); 78 return toText(node)->data();
79 79
80 if (node->hasTagName(inputTag)) 80 if (node->hasTagName(inputTag))
81 return static_cast<HTMLInputElement*>(node)->value(); 81 return toHTMLInputElement(node)->value();
82 82
83 if (node->isHTMLElement()) { 83 if (node->isHTMLElement()) {
84 const AtomicString& alt = toHTMLElement(node)->getAttribute(altAttr); 84 const AtomicString& alt = toHTMLElement(node)->getAttribute(altAttr);
85 if (!alt.isEmpty()) 85 if (!alt.isEmpty())
86 return alt; 86 return alt;
87 } 87 }
88 88
89 return String(); 89 return String();
90 } 90 }
91 91
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 if (ariaRole != UnknownRole) 176 if (ariaRole != UnknownRole)
177 return ariaRole; 177 return ariaRole;
178 178
179 if (node()->isLink()) 179 if (node()->isLink())
180 return WebCoreLinkRole; 180 return WebCoreLinkRole;
181 if (node()->isTextNode()) 181 if (node()->isTextNode())
182 return StaticTextRole; 182 return StaticTextRole;
183 if (node()->hasTagName(buttonTag)) 183 if (node()->hasTagName(buttonTag))
184 return buttonRoleType(); 184 return buttonRoleType();
185 if (node()->hasTagName(inputTag)) { 185 if (node()->hasTagName(inputTag)) {
186 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 186 HTMLInputElement* input = toHTMLInputElement(node());
187 if (input->isCheckbox()) 187 if (input->isCheckbox())
188 return CheckBoxRole; 188 return CheckBoxRole;
189 if (input->isRadioButton()) 189 if (input->isRadioButton())
190 return RadioButtonRole; 190 return RadioButtonRole;
191 if (input->isTextButton()) 191 if (input->isTextButton())
192 return buttonRoleType(); 192 return buttonRoleType();
193 if (input->isRangeControl()) 193 if (input->isRangeControl())
194 return SliderRole; 194 return SliderRole;
195 195
196 #if ENABLE(INPUT_TYPE_COLOR) 196 #if ENABLE(INPUT_TYPE_COLOR)
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 { 526 {
527 return isNativeImage() && isButton(); 527 return isNativeImage() && isButton();
528 } 528 }
529 529
530 bool AccessibilityNodeObject::isInputImage() const 530 bool AccessibilityNodeObject::isInputImage() const
531 { 531 {
532 Node* node = this->node(); 532 Node* node = this->node();
533 if (!node) 533 if (!node)
534 return false; 534 return false;
535 535
536 if (roleValue() == ButtonRole && node->hasTagName(inputTag)) { 536 if (roleValue() == ButtonRole && node->hasTagName(inputTag))
537 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 537 return toHTMLInputElement(node)->isImageButton();
538 return input->isImageButton();
539 }
540 538
541 return false; 539 return false;
542 } 540 }
543 541
544 bool AccessibilityNodeObject::isLink() const 542 bool AccessibilityNodeObject::isLink() const
545 { 543 {
546 return roleValue() == WebCoreLinkRole; 544 return roleValue() == WebCoreLinkRole;
547 } 545 }
548 546
549 bool AccessibilityNodeObject::isMenu() const 547 bool AccessibilityNodeObject::isMenu() const
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
608 Node* node = this->node(); 606 Node* node = this->node();
609 if (!node) 607 if (!node)
610 return false; 608 return false;
611 609
612 if (node->hasTagName(imgTag)) 610 if (node->hasTagName(imgTag))
613 return true; 611 return true;
614 612
615 if (node->hasTagName(appletTag) || node->hasTagName(embedTag) || node->hasTa gName(objectTag)) 613 if (node->hasTagName(appletTag) || node->hasTagName(embedTag) || node->hasTa gName(objectTag))
616 return true; 614 return true;
617 615
618 if (node->hasTagName(inputTag)) { 616 if (node->hasTagName(inputTag))
619 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 617 return toHTMLInputElement(node)->isImageButton();
620 return input->isImageButton();
621 }
622 618
623 return false; 619 return false;
624 } 620 }
625 621
626 bool AccessibilityNodeObject::isNativeTextControl() const 622 bool AccessibilityNodeObject::isNativeTextControl() const
627 { 623 {
628 Node* node = this->node(); 624 Node* node = this->node();
629 if (!node) 625 if (!node)
630 return false; 626 return false;
631 627
632 if (node->hasTagName(textareaTag)) 628 if (node->hasTagName(textareaTag))
633 return true; 629 return true;
634 630
635 if (node->hasTagName(inputTag)) { 631 if (node->hasTagName(inputTag)) {
636 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 632 HTMLInputElement* input = toHTMLInputElement(node);
637 return input->isText() || input->isNumberField(); 633 return input->isText() || input->isNumberField();
638 } 634 }
639 635
640 return false; 636 return false;
641 } 637 }
642 638
643 bool AccessibilityNodeObject::isPasswordField() const 639 bool AccessibilityNodeObject::isPasswordField() const
644 { 640 {
645 Node* node = this->node(); 641 Node* node = this->node();
646 if (!node || !node->isHTMLElement()) 642 if (!node || !node->isHTMLElement())
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 bool AccessibilityNodeObject::isReadOnly() const 762 bool AccessibilityNodeObject::isReadOnly() const
767 { 763 {
768 Node* node = this->node(); 764 Node* node = this->node();
769 if (!node) 765 if (!node)
770 return true; 766 return true;
771 767
772 if (node->hasTagName(textareaTag)) 768 if (node->hasTagName(textareaTag))
773 return static_cast<HTMLTextAreaElement*>(node)->isReadOnly(); 769 return static_cast<HTMLTextAreaElement*>(node)->isReadOnly();
774 770
775 if (node->hasTagName(inputTag)) { 771 if (node->hasTagName(inputTag)) {
776 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 772 HTMLInputElement* input = toHTMLInputElement(node);
777 if (input->isTextField()) 773 if (input->isTextField())
778 return input->isReadOnly(); 774 return input->isReadOnly();
779 } 775 }
780 776
781 return !node->rendererIsEditable(); 777 return !node->rendererIsEditable();
782 } 778 }
783 779
784 bool AccessibilityNodeObject::isRequired() const 780 bool AccessibilityNodeObject::isRequired() const
785 { 781 {
786 if (equalIgnoringCase(getAttribute(aria_requiredAttr), "true")) 782 if (equalIgnoringCase(getAttribute(aria_requiredAttr), "true"))
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 r = 0; 925 r = 0;
930 g = 0; 926 g = 0;
931 b = 0; 927 b = 0;
932 928
933 if (!isColorWell()) 929 if (!isColorWell())
934 return; 930 return;
935 931
936 if (!node() || !node()->hasTagName(inputTag)) 932 if (!node() || !node()->hasTagName(inputTag))
937 return; 933 return;
938 934
939 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 935 HTMLInputElement* input = toHTMLInputElement(node());
940 const AtomicString& type = input->getAttribute(typeAttr); 936 const AtomicString& type = input->getAttribute(typeAttr);
941 if (!equalIgnoringCase(type, "color")) 937 if (!equalIgnoringCase(type, "color"))
942 return; 938 return;
943 939
944 // HTMLInputElement::value always returns a string parseable by Color(). 940 // HTMLInputElement::value always returns a string parseable by Color().
945 Color color(input->value()); 941 Color color(input->value());
946 r = color.red(); 942 r = color.red();
947 g = color.green(); 943 g = color.green();
948 b = color.blue(); 944 b = color.blue();
949 } 945 }
950 946
951 String AccessibilityNodeObject::valueDescription() const 947 String AccessibilityNodeObject::valueDescription() const
952 { 948 {
953 if (!isARIARange()) 949 if (!isARIARange())
954 return String(); 950 return String();
955 951
956 return getAttribute(aria_valuetextAttr).string(); 952 return getAttribute(aria_valuetextAttr).string();
957 } 953 }
958 954
959 float AccessibilityNodeObject::valueForRange() const 955 float AccessibilityNodeObject::valueForRange() const
960 { 956 {
961 if (node() && node()->hasTagName(inputTag)) { 957 if (node() && node()->hasTagName(inputTag)) {
962 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 958 HTMLInputElement* input = toHTMLInputElement(node());
963 if (input->isRangeControl()) 959 if (input->isRangeControl())
964 return input->valueAsNumber(); 960 return input->valueAsNumber();
965 } 961 }
966 962
967 if (!isARIARange()) 963 if (!isARIARange())
968 return 0.0f; 964 return 0.0f;
969 965
970 return getAttribute(aria_valuenowAttr).toFloat(); 966 return getAttribute(aria_valuenowAttr).toFloat();
971 } 967 }
972 968
973 float AccessibilityNodeObject::maxValueForRange() const 969 float AccessibilityNodeObject::maxValueForRange() const
974 { 970 {
975 if (node() && node()->hasTagName(inputTag)) { 971 if (node() && node()->hasTagName(inputTag)) {
976 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 972 HTMLInputElement* input = toHTMLInputElement(node());
977 if (input->isRangeControl()) 973 if (input->isRangeControl())
978 return input->maximum(); 974 return input->maximum();
979 } 975 }
980 976
981 if (!isARIARange()) 977 if (!isARIARange())
982 return 0.0f; 978 return 0.0f;
983 979
984 return getAttribute(aria_valuemaxAttr).toFloat(); 980 return getAttribute(aria_valuemaxAttr).toFloat();
985 } 981 }
986 982
987 float AccessibilityNodeObject::minValueForRange() const 983 float AccessibilityNodeObject::minValueForRange() const
988 { 984 {
989 if (node() && node()->hasTagName(inputTag)) { 985 if (node() && node()->hasTagName(inputTag)) {
990 HTMLInputElement* input = static_cast<HTMLInputElement*>(node()); 986 HTMLInputElement* input = toHTMLInputElement(node());
991 if (input->isRangeControl()) 987 if (input->isRangeControl())
992 return input->minimum(); 988 return input->minimum();
993 } 989 }
994 990
995 if (!isARIARange()) 991 if (!isARIARange())
996 return 0.0f; 992 return 0.0f;
997 993
998 return getAttribute(aria_valueminAttr).toFloat(); 994 return getAttribute(aria_valueminAttr).toFloat();
999 } 995 }
1000 996
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1200 } 1196 }
1201 1197
1202 String AccessibilityNodeObject::title() const 1198 String AccessibilityNodeObject::title() const
1203 { 1199 {
1204 Node* node = this->node(); 1200 Node* node = this->node();
1205 if (!node) 1201 if (!node)
1206 return String(); 1202 return String();
1207 1203
1208 bool isInputTag = node->hasTagName(inputTag); 1204 bool isInputTag = node->hasTagName(inputTag);
1209 if (isInputTag) { 1205 if (isInputTag) {
1210 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 1206 HTMLInputElement* input = toHTMLInputElement(node);
1211 if (input->isTextButton()) 1207 if (input->isTextButton())
1212 return input->valueWithDefault(); 1208 return input->valueWithDefault();
1213 } 1209 }
1214 1210
1215 if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || i sControl()) { 1211 if (isInputTag || AccessibilityObject::isARIAInput(ariaRoleAttribute()) || i sControl()) {
1216 HTMLLabelElement* label = labelForElement(toElement(node)); 1212 HTMLLabelElement* label = labelForElement(toElement(node));
1217 if (label && !exposesTitleUIElement()) 1213 if (label && !exposesTitleUIElement())
1218 return label->innerText(); 1214 return label->innerText();
1219 } 1215 }
1220 1216
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after
1451 } 1447 }
1452 } 1448 }
1453 1449
1454 Element* AccessibilityNodeObject::actionElement() const 1450 Element* AccessibilityNodeObject::actionElement() const
1455 { 1451 {
1456 Node* node = this->node(); 1452 Node* node = this->node();
1457 if (!node) 1453 if (!node)
1458 return 0; 1454 return 0;
1459 1455
1460 if (node->hasTagName(inputTag)) { 1456 if (node->hasTagName(inputTag)) {
1461 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 1457 HTMLInputElement* input = toHTMLInputElement(node);
1462 if (!input->isDisabledFormControl() && (isCheckboxOrRadio() || input->is TextButton())) 1458 if (!input->isDisabledFormControl() && (isCheckboxOrRadio() || input->is TextButton()))
1463 return input; 1459 return input;
1464 } else if (node->hasTagName(buttonTag)) 1460 } else if (node->hasTagName(buttonTag))
1465 return toElement(node); 1461 return toElement(node);
1466 1462
1467 if (isFileUploadButton()) 1463 if (isFileUploadButton())
1468 return toElement(node); 1464 return toElement(node);
1469 1465
1470 if (AccessibilityObject::isARIAInput(ariaRoleAttribute())) 1466 if (AccessibilityObject::isARIAInput(ariaRoleAttribute()))
1471 return toElement(node); 1467 return toElement(node);
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1728 } 1724 }
1729 1725
1730 void AccessibilityNodeObject::visibleText(Vector<AccessibilityText>& textOrder) const 1726 void AccessibilityNodeObject::visibleText(Vector<AccessibilityText>& textOrder) const
1731 { 1727 {
1732 Node* node = this->node(); 1728 Node* node = this->node();
1733 if (!node) 1729 if (!node)
1734 return; 1730 return;
1735 1731
1736 bool isInputTag = node->hasTagName(inputTag); 1732 bool isInputTag = node->hasTagName(inputTag);
1737 if (isInputTag) { 1733 if (isInputTag) {
1738 HTMLInputElement* input = static_cast<HTMLInputElement*>(node); 1734 HTMLInputElement* input = toHTMLInputElement(node);
1739 if (input->isTextButton()) { 1735 if (input->isTextButton()) {
1740 textOrder.append(AccessibilityText(input->valueWithDefault(), Visibl eText)); 1736 textOrder.append(AccessibilityText(input->valueWithDefault(), Visibl eText));
1741 return; 1737 return;
1742 } 1738 }
1743 } 1739 }
1744 1740
1745 // If this node isn't rendered, there's no inner text we can extract from a select element. 1741 // If this node isn't rendered, there's no inner text we can extract from a select element.
1746 if (!isAccessibilityRenderObject() && node->hasTagName(selectTag)) 1742 if (!isAccessibilityRenderObject() && node->hasTagName(selectTag))
1747 return; 1743 return;
1748 1744
(...skipping 24 matching lines...) Expand all
1773 useTextUnderElement = true; 1769 useTextUnderElement = true;
1774 1770
1775 if (useTextUnderElement) { 1771 if (useTextUnderElement) {
1776 String text = textUnderElement(); 1772 String text = textUnderElement();
1777 if (!text.isEmpty()) 1773 if (!text.isEmpty())
1778 textOrder.append(AccessibilityText(text, ChildrenText)); 1774 textOrder.append(AccessibilityText(text, ChildrenText));
1779 } 1775 }
1780 } 1776 }
1781 1777
1782 } // namespace WebCore 1778 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/accessibility/AccessibilityMediaControls.cpp ('k') | Source/core/accessibility/AccessibilityRenderObject.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698