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

Side by Side Diff: third_party/WebKit/Source/modules/accessibility/AXNodeObject.cpp

Issue 2492083002: Implement aria-placeholder (Closed)
Patch Set: Implement code cleanup suggestion Created 4 years, 1 month 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
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 2351 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 = placeholderFromNativeAttribute();
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 303 matching lines...) Expand 10 before | Expand all | Expand 10 after
2698 } 2720 }
2699 } else if (descriptionSources) { 2721 } else if (descriptionSources) {
2700 descriptionSources->last().invalid = true; 2722 descriptionSources->last().invalid = true;
2701 } 2723 }
2702 } 2724 }
2703 2725
2704 HTMLElement* htmlElement = nullptr; 2726 HTMLElement* htmlElement = nullptr;
2705 if (getNode()->isHTMLElement()) 2727 if (getNode()->isHTMLElement())
2706 htmlElement = toHTMLElement(getNode()); 2728 htmlElement = toHTMLElement(getNode());
2707 2729
2708 // placeholder, 5.1.2 from:
2709 // http://rawgit.com/w3c/aria/master/html-aam/html-aam.html
2710 if (nameFrom != AXNameFromPlaceholder && htmlElement &&
2711 htmlElement->isTextFormControl()) {
2712 descriptionFrom = AXDescriptionFromPlaceholder;
2713 if (descriptionSources) {
2714 descriptionSources->append(
2715 DescriptionSource(foundDescription, placeholderAttr));
2716 DescriptionSource& source = descriptionSources->last();
2717 source.type = descriptionFrom;
2718 }
2719 HTMLElement* element = toHTMLElement(getNode());
2720 const AtomicString& placeholder =
2721 element->fastGetAttribute(placeholderAttr);
2722 if (!placeholder.isEmpty()) {
2723 description = placeholder;
2724 if (descriptionSources) {
2725 DescriptionSource& source = descriptionSources->last();
2726 source.text = description;
2727 source.attributeValue = placeholder;
2728 foundDescription = true;
2729 } else {
2730 return description;
2731 }
2732 }
2733 }
2734
2735 const HTMLInputElement* inputElement = nullptr; 2730 const HTMLInputElement* inputElement = nullptr;
2736 if (isHTMLInputElement(getNode())) 2731 if (isHTMLInputElement(getNode()))
2737 inputElement = toHTMLInputElement(getNode()); 2732 inputElement = toHTMLInputElement(getNode());
2738 2733
2739 // value, 5.2.2 from: http://rawgit.com/w3c/aria/master/html-aam/html-aam.html 2734 // value, 5.2.2 from: http://rawgit.com/w3c/aria/master/html-aam/html-aam.html
2740 if (nameFrom != AXNameFromValue && inputElement && 2735 if (nameFrom != AXNameFromValue && inputElement &&
2741 inputElement->isTextButton()) { 2736 inputElement->isTextButton()) {
2742 descriptionFrom = AXDescriptionFromAttribute; 2737 descriptionFrom = AXDescriptionFromAttribute;
2743 if (descriptionSources) { 2738 if (descriptionSources) {
2744 descriptionSources->append( 2739 descriptionSources->append(
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
2875 } 2870 }
2876 2871
2877 String AXNodeObject::placeholder(AXNameFrom nameFrom, 2872 String AXNodeObject::placeholder(AXNameFrom nameFrom,
2878 AXDescriptionFrom descriptionFrom) const { 2873 AXDescriptionFrom descriptionFrom) const {
2879 if (nameFrom == AXNameFromPlaceholder) 2874 if (nameFrom == AXNameFromPlaceholder)
2880 return String(); 2875 return String();
2881 2876
2882 if (descriptionFrom == AXDescriptionFromPlaceholder) 2877 if (descriptionFrom == AXDescriptionFromPlaceholder)
2883 return String(); 2878 return String();
2884 2879
2885 if (!getNode()) 2880 Node* node = getNode();
2881 if (!node || !node->isHTMLElement())
2886 return String(); 2882 return String();
2887 2883
2888 String placeholder; 2884 String nativePlaceholder = placeholderFromNativeAttribute();
2889 if (isHTMLInputElement(*getNode())) { 2885 if (!nativePlaceholder.isEmpty())
2890 HTMLInputElement* inputElement = toHTMLInputElement(getNode()); 2886 return nativePlaceholder;
2891 placeholder = inputElement->strippedPlaceholder(); 2887
2892 } else if (isHTMLTextAreaElement(*getNode())) { 2888 const AtomicString& ariaPlaceholder =
2893 HTMLTextAreaElement* textAreaElement = toHTMLTextAreaElement(getNode()); 2889 toHTMLElement(node)->fastGetAttribute(aria_placeholderAttr);
2894 placeholder = textAreaElement->strippedPlaceholder(); 2890 if (!ariaPlaceholder.isEmpty())
2895 } 2891 return ariaPlaceholder;
2896 return placeholder; 2892
2893 return String();
2894 }
2895
2896 String AXNodeObject::placeholderFromNativeAttribute() const {
2897 Node* node = getNode();
2898 if (!node || !isHTMLTextFormControlElement(node))
2899 return String();
2900 return toHTMLTextFormControlElement(node)->strippedPlaceholder();
2897 } 2901 }
2898 2902
2899 DEFINE_TRACE(AXNodeObject) { 2903 DEFINE_TRACE(AXNodeObject) {
2900 visitor->trace(m_node); 2904 visitor->trace(m_node);
2901 AXObject::trace(visitor); 2905 AXObject::trace(visitor);
2902 } 2906 }
2903 2907
2904 } // namespace blink 2908 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698