Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2362 } | 2362 } |
| 2363 | 2363 |
| 2364 // 5.1 Text inputs - step 3 (placeholder attribute) | 2364 // 5.1 Text inputs - step 3 (placeholder attribute) |
| 2365 if (htmlElement && htmlElement->isTextFormControl()) { | 2365 if (htmlElement && htmlElement->isTextFormControl()) { |
| 2366 nameFrom = AXNameFromPlaceholder; | 2366 nameFrom = AXNameFromPlaceholder; |
| 2367 if (nameSources) { | 2367 if (nameSources) { |
| 2368 nameSources->append(NameSource(*foundTextAlternative, placeholderAttr)); | 2368 nameSources->append(NameSource(*foundTextAlternative, placeholderAttr)); |
| 2369 NameSource& source = nameSources->last(); | 2369 NameSource& source = nameSources->last(); |
| 2370 source.type = nameFrom; | 2370 source.type = nameFrom; |
| 2371 } | 2371 } |
| 2372 HTMLElement* element = toHTMLElement(getNode()); | 2372 const String placeholder = placeholderFromAttribute(); |
| 2373 const AtomicString& placeholder = | |
| 2374 element->fastGetAttribute(placeholderAttr); | |
| 2375 if (!placeholder.isEmpty()) { | 2373 if (!placeholder.isEmpty()) { |
| 2376 textAlternative = placeholder; | 2374 textAlternative = placeholder; |
| 2377 if (nameSources) { | 2375 if (nameSources) { |
| 2378 NameSource& source = nameSources->last(); | 2376 NameSource& source = nameSources->last(); |
| 2379 source.text = textAlternative; | 2377 source.text = textAlternative; |
| 2380 source.attributeValue = placeholder; | 2378 source.attributeValue = htmlElement->fastGetAttribute(placeholderAttr); |
| 2379 *foundTextAlternative = true; | |
| 2381 } else { | 2380 } else { |
| 2382 return textAlternative; | 2381 return textAlternative; |
| 2383 } | 2382 } |
| 2384 } | 2383 } |
| 2384 | |
| 2385 // Also check for aria-placeholder. | |
| 2386 nameFrom = AXNameFromPlaceholder; | |
| 2387 if (nameSources) { | |
| 2388 nameSources->append( | |
| 2389 NameSource(*foundTextAlternative, aria_placeholderAttr)); | |
| 2390 NameSource& source = nameSources->last(); | |
| 2391 source.type = nameFrom; | |
| 2392 } | |
| 2393 const AtomicString& ariaPlaceholder = | |
| 2394 htmlElement->fastGetAttribute(aria_placeholderAttr); | |
| 2395 if (!ariaPlaceholder.isEmpty()) { | |
| 2396 textAlternative = ariaPlaceholder; | |
| 2397 if (nameSources) { | |
| 2398 NameSource& source = nameSources->last(); | |
| 2399 source.text = textAlternative; | |
| 2400 source.attributeValue = ariaPlaceholder; | |
| 2401 *foundTextAlternative = true; | |
| 2402 } else { | |
| 2403 return textAlternative; | |
| 2404 } | |
| 2405 } | |
| 2406 | |
| 2385 return textAlternative; | 2407 return textAlternative; |
| 2386 } | 2408 } |
| 2387 | 2409 |
| 2388 // 5.7 figure and figcaption Elements | 2410 // 5.7 figure and figcaption Elements |
| 2389 if (getNode()->hasTagName(figureTag)) { | 2411 if (getNode()->hasTagName(figureTag)) { |
| 2390 // figcaption | 2412 // figcaption |
| 2391 nameFrom = AXNameFromRelatedElement; | 2413 nameFrom = AXNameFromRelatedElement; |
| 2392 if (nameSources) { | 2414 if (nameSources) { |
| 2393 nameSources->append(NameSource(*foundTextAlternative)); | 2415 nameSources->append(NameSource(*foundTextAlternative)); |
| 2394 nameSources->last().type = nameFrom; | 2416 nameSources->last().type = nameFrom; |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2709 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html | 2731 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html |
| 2710 if (nameFrom != AXNameFromPlaceholder && htmlElement && | 2732 if (nameFrom != AXNameFromPlaceholder && htmlElement && |
| 2711 htmlElement->isTextFormControl()) { | 2733 htmlElement->isTextFormControl()) { |
| 2712 descriptionFrom = AXDescriptionFromPlaceholder; | 2734 descriptionFrom = AXDescriptionFromPlaceholder; |
| 2713 if (descriptionSources) { | 2735 if (descriptionSources) { |
| 2714 descriptionSources->append( | 2736 descriptionSources->append( |
| 2715 DescriptionSource(foundDescription, placeholderAttr)); | 2737 DescriptionSource(foundDescription, placeholderAttr)); |
| 2716 DescriptionSource& source = descriptionSources->last(); | 2738 DescriptionSource& source = descriptionSources->last(); |
| 2717 source.type = descriptionFrom; | 2739 source.type = descriptionFrom; |
| 2718 } | 2740 } |
| 2719 HTMLElement* element = toHTMLElement(getNode()); | 2741 const String placeholder = placeholderFromAttribute(); |
| 2720 const AtomicString& placeholder = | |
| 2721 element->fastGetAttribute(placeholderAttr); | |
| 2722 if (!placeholder.isEmpty()) { | 2742 if (!placeholder.isEmpty()) { |
| 2723 description = placeholder; | 2743 description = AtomicString(placeholder); |
| 2724 if (descriptionSources) { | 2744 if (descriptionSources) { |
| 2725 DescriptionSource& source = descriptionSources->last(); | 2745 DescriptionSource& source = descriptionSources->last(); |
| 2726 source.text = description; | 2746 source.text = description; |
| 2727 source.attributeValue = placeholder; | 2747 source.attributeValue = htmlElement->fastGetAttribute(placeholderAttr); |
| 2728 foundDescription = true; | 2748 foundDescription = true; |
| 2729 } else { | 2749 } else { |
| 2730 return description; | 2750 return description; |
| 2751 } | |
| 2752 } | |
| 2753 | |
| 2754 // Also check for aria-placeholder. | |
| 2755 descriptionFrom = AXDescriptionFromPlaceholder; | |
| 2756 if (descriptionSources) { | |
| 2757 descriptionSources->append( | |
| 2758 DescriptionSource(foundDescription, aria_placeholderAttr)); | |
| 2759 DescriptionSource& source = descriptionSources->last(); | |
| 2760 source.type = descriptionFrom; | |
| 2761 } | |
| 2762 const AtomicString& ariaPlaceholder = | |
| 2763 htmlElement->fastGetAttribute(aria_placeholderAttr); | |
| 2764 if (!ariaPlaceholder.isEmpty()) { | |
| 2765 description = ariaPlaceholder; | |
| 2766 if (descriptionSources) { | |
| 2767 DescriptionSource& source = descriptionSources->last(); | |
| 2768 source.text = description; | |
| 2769 source.attributeValue = ariaPlaceholder; | |
| 2770 foundDescription = true; | |
| 2771 } else { | |
| 2772 return description; | |
| 2731 } | 2773 } |
| 2732 } | 2774 } |
| 2733 } | 2775 } |
| 2734 | 2776 |
| 2735 const HTMLInputElement* inputElement = nullptr; | 2777 const HTMLInputElement* inputElement = nullptr; |
| 2736 if (isHTMLInputElement(getNode())) | 2778 if (isHTMLInputElement(getNode())) |
| 2737 inputElement = toHTMLInputElement(getNode()); | 2779 inputElement = toHTMLInputElement(getNode()); |
| 2738 | 2780 |
| 2739 // value, 5.2.2 from: http://rawgit.com/w3c/aria/master/html-aam/html-aam.html | 2781 // value, 5.2.2 from: http://rawgit.com/w3c/aria/master/html-aam/html-aam.html |
| 2740 if (nameFrom != AXNameFromValue && inputElement && | 2782 if (nameFrom != AXNameFromValue && inputElement && |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2878 AXDescriptionFrom descriptionFrom) const { | 2920 AXDescriptionFrom descriptionFrom) const { |
| 2879 if (nameFrom == AXNameFromPlaceholder) | 2921 if (nameFrom == AXNameFromPlaceholder) |
| 2880 return String(); | 2922 return String(); |
| 2881 | 2923 |
| 2882 if (descriptionFrom == AXDescriptionFromPlaceholder) | 2924 if (descriptionFrom == AXDescriptionFromPlaceholder) |
| 2883 return String(); | 2925 return String(); |
| 2884 | 2926 |
| 2885 if (!getNode()) | 2927 if (!getNode()) |
| 2886 return String(); | 2928 return String(); |
| 2887 | 2929 |
| 2888 String placeholder; | 2930 return placeholderFromAttribute(); |
| 2931 } | |
| 2932 | |
| 2933 String AXNodeObject::placeholderFromAttribute() const { | |
| 2889 if (isHTMLInputElement(*getNode())) { | 2934 if (isHTMLInputElement(*getNode())) { |
|
dmazzoni
2016/11/15 18:11:15
You can clean up this code slightly, use isHTMLTex
| |
| 2890 HTMLInputElement* inputElement = toHTMLInputElement(getNode()); | 2935 HTMLInputElement* inputElement = toHTMLInputElement(getNode()); |
| 2891 placeholder = inputElement->strippedPlaceholder(); | 2936 return inputElement->strippedPlaceholder(); |
| 2892 } else if (isHTMLTextAreaElement(*getNode())) { | 2937 } else if (isHTMLTextAreaElement(*getNode())) { |
| 2893 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(getNode()); | 2938 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(getNode()); |
| 2894 placeholder = textAreaElement->strippedPlaceholder(); | 2939 return textAreaElement->strippedPlaceholder(); |
| 2895 } | 2940 } |
| 2896 return placeholder; | 2941 return String(); |
| 2897 } | 2942 } |
| 2898 | 2943 |
| 2899 DEFINE_TRACE(AXNodeObject) { | 2944 DEFINE_TRACE(AXNodeObject) { |
| 2900 visitor->trace(m_node); | 2945 visitor->trace(m_node); |
| 2901 AXObject::trace(visitor); | 2946 AXObject::trace(visitor); |
| 2902 } | 2947 } |
| 2903 | 2948 |
| 2904 } // namespace blink | 2949 } // namespace blink |
| OLD | NEW |