Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org> | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde .org> |
| 3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> | 3 * Copyright (C) 2004, 2005, 2006, 2008 Rob Buis <buis@kde.org> |
| 4 * Copyright (C) 2008 Apple Inc. All rights reserved. | 4 * Copyright (C) 2008 Apple Inc. All rights reserved. |
| 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> | 5 * Copyright (C) 2008 Alp Toker <alp@atoker.com> |
| 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> | 6 * Copyright (C) 2009 Cameron McCormack <cam@mcc.id.au> |
| 7 * | 7 * |
| 8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
| 9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
| 10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 #include "SVGNames.h" | 29 #include "SVGNames.h" |
| 30 #include "XLinkNames.h" | 30 #include "XLinkNames.h" |
| 31 #include "XMLNames.h" | 31 #include "XMLNames.h" |
| 32 #include "bindings/v8/ScriptEventListener.h" | 32 #include "bindings/v8/ScriptEventListener.h" |
| 33 #include "core/css/CSSCursorImageValue.h" | 33 #include "core/css/CSSCursorImageValue.h" |
| 34 #include "core/css/parser/BisonCSSParser.h" | 34 #include "core/css/parser/BisonCSSParser.h" |
| 35 #include "core/dom/Document.h" | 35 #include "core/dom/Document.h" |
| 36 #include "core/dom/ElementTraversal.h" | 36 #include "core/dom/ElementTraversal.h" |
| 37 #include "core/dom/shadow/ShadowRoot.h" | 37 #include "core/dom/shadow/ShadowRoot.h" |
| 38 #include "core/events/Event.h" | 38 #include "core/events/Event.h" |
| 39 #include "core/frame/Settings.h" | |
| 39 #include "core/html/HTMLElement.h" | 40 #include "core/html/HTMLElement.h" |
| 41 #include "core/html/parser/HTMLParserIdioms.h" | |
| 40 #include "core/rendering/RenderObject.h" | 42 #include "core/rendering/RenderObject.h" |
| 41 #include "core/rendering/svg/RenderSVGResourceContainer.h" | 43 #include "core/rendering/svg/RenderSVGResourceContainer.h" |
| 42 #include "core/svg/SVGCursorElement.h" | 44 #include "core/svg/SVGCursorElement.h" |
| 43 #include "core/svg/SVGDocumentExtensions.h" | 45 #include "core/svg/SVGDocumentExtensions.h" |
| 44 #include "core/svg/SVGElementInstance.h" | 46 #include "core/svg/SVGElementInstance.h" |
| 45 #include "core/svg/SVGElementRareData.h" | 47 #include "core/svg/SVGElementRareData.h" |
| 46 #include "core/svg/SVGGraphicsElement.h" | 48 #include "core/svg/SVGGraphicsElement.h" |
| 47 #include "core/svg/SVGSVGElement.h" | 49 #include "core/svg/SVGSVGElement.h" |
| 48 #include "core/svg/SVGTitleElement.h" | 50 #include "core/svg/SVGTitleElement.h" |
| 49 #include "core/svg/SVGUseElement.h" | 51 #include "core/svg/SVGUseElement.h" |
| (...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 { | 625 { |
| 624 ASSERT(!hasSVGRareData() || !svgRareData()->correspondingElement() || contai ningShadowRoot()); | 626 ASSERT(!hasSVGRareData() || !svgRareData()->correspondingElement() || contai ningShadowRoot()); |
| 625 return hasSVGRareData() ? svgRareData()->correspondingElement() : 0; | 627 return hasSVGRareData() ? svgRareData()->correspondingElement() : 0; |
| 626 } | 628 } |
| 627 | 629 |
| 628 void SVGElement::setCorrespondingElement(SVGElement* correspondingElement) | 630 void SVGElement::setCorrespondingElement(SVGElement* correspondingElement) |
| 629 { | 631 { |
| 630 ensureSVGRareData()->setCorrespondingElement(correspondingElement); | 632 ensureSVGRareData()->setCorrespondingElement(correspondingElement); |
| 631 } | 633 } |
| 632 | 634 |
| 635 short SVGElement::tabIndex() const | |
| 636 { | |
| 637 if (supportsFocus()) | |
| 638 return Element::tabIndex(); | |
| 639 return -1; | |
| 640 } | |
| 641 | |
| 642 void SVGElement::setTabIndex(int value) | |
| 643 { | |
| 644 setIntegralAttribute(tabindexAttr, value); | |
| 645 } | |
| 646 | |
| 647 bool SVGElement::rendererIsFocusable() const | |
| 648 { | |
| 649 return inDocument() && supportsFocus() && !isInert() && Element::tabIndex() >= 0; | |
|
fs
2014/03/14 16:05:12
IIUC, they way this is called the the first three
Erik Dahlström (inactive)
2014/03/17 14:45:29
Hmm, true. I'll remove this.
visibility:hidden on
| |
| 650 } | |
| 651 | |
| 652 bool SVGElement::supportsFocus() const | |
| 653 { | |
| 654 // FIXME: supportsFocus() can be called when layout is not up to date. | |
| 655 // Logic that deals with the renderer should be moved to rendererIsFocusable (). | |
| 656 // But supportsFocus must return true when the element is editable, or else | |
| 657 // it won't be focusable. Furthermore, supportsFocus cannot just return true | |
| 658 // always or else tabIndex() will change for all HTML elements. | |
| 659 return Element::supportsFocus() || (rendererIsEditable() && parentNode() && !parentNode()->rendererIsEditable()) | |
| 660 || supportsSpatialNavigationFocus(); | |
| 661 } | |
| 662 | |
| 663 bool SVGElement::supportsSpatialNavigationFocus() const | |
| 664 { | |
| 665 // This function checks whether the element satisfies the extended criteria | |
| 666 // for the element to be focusable, introduced by spatial navigation feature , | |
| 667 // i.e. checks if click or keyboard event handler is specified. | |
| 668 // This is the way to make it possible to navigate to (focus) elements | |
| 669 // which web designer meant for being active (made them respond to click eve nts). | |
| 670 | |
| 671 if (!document().settings() || !document().settings()->spatialNavigationEnabl ed()) | |
| 672 return false; | |
| 673 return hasEventListeners(EventTypeNames::click) | |
| 674 || hasEventListeners(EventTypeNames::keydown) | |
| 675 || hasEventListeners(EventTypeNames::keypress) | |
| 676 || hasEventListeners(EventTypeNames::keyup) | |
| 677 || hasEventListeners(EventTypeNames::focus) | |
| 678 || hasEventListeners(EventTypeNames::blur) | |
| 679 || hasEventListeners(EventTypeNames::focusin) | |
| 680 || hasEventListeners(EventTypeNames::focusout); | |
| 681 } | |
| 682 | |
| 633 void SVGElement::parseAttribute(const QualifiedName& name, const AtomicString& v alue) | 683 void SVGElement::parseAttribute(const QualifiedName& name, const AtomicString& v alue) |
| 634 { | 684 { |
| 635 if (name == HTMLNames::classAttr) { | 685 if (name == HTMLNames::classAttr) { |
| 636 // SVG animation has currently requires special storage of values so we set | 686 // SVG animation has currently requires special storage of values so we set |
| 637 // the className here. svgAttributeChanged actually causes the resulting | 687 // the className here. svgAttributeChanged actually causes the resulting |
| 638 // style updates (instead of Element::parseAttribute). We don't | 688 // style updates (instead of Element::parseAttribute). We don't |
| 639 // tell Element about the change to avoid parsing the class list twice | 689 // tell Element about the change to avoid parsing the class list twice |
| 640 SVGParsingError parseError = NoError; | 690 SVGParsingError parseError = NoError; |
| 641 m_className->setBaseValueAsString(value, parseError); | 691 m_className->setBaseValueAsString(value, parseError); |
| 642 reportAttributeParsingError(parseError, name, value); | 692 reportAttributeParsingError(parseError, name, value); |
| 643 } else if (name.matches(XMLNames::langAttr) || name.matches(XMLNames::spaceA ttr)) { | 693 } else if (name.matches(XMLNames::langAttr) || name.matches(XMLNames::spaceA ttr)) { |
| 694 } else if (name == tabindexAttr) { | |
| 695 int tabindex = 0; | |
| 696 if (value.isEmpty()) { | |
| 697 clearTabIndexExplicitlyIfNeeded(); | |
| 698 if (treeScope().adjustedFocusedElement() == this) { | |
| 699 // We might want to call blur(), but it's dangerous to dispatch | |
| 700 // events here. | |
| 701 document().setNeedsFocusedElementCheck(); | |
| 702 } | |
| 703 } else if (parseHTMLInteger(value, tabindex)) { | |
| 704 // Clamp tabindex to the range of 'short' to match Firefox's behavio r. | |
| 705 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short >::min()), std::min(tabindex, static_cast<int>(std::numeric_limits<short>::max() )))); | |
| 706 } | |
| 644 } else { | 707 } else { |
| 645 // standard events | 708 // standard events |
| 646 const AtomicString& eventName = HTMLElement::eventNameForAttributeName(n ame); | 709 const AtomicString& eventName = HTMLElement::eventNameForAttributeName(n ame); |
| 647 if (!eventName.isNull()) | 710 if (!eventName.isNull()) |
| 648 setAttributeEventListener(eventName, createAttributeEventListener(th is, name, value)); | 711 setAttributeEventListener(eventName, createAttributeEventListener(th is, name, value)); |
| 649 else | 712 else |
| 650 Element::parseAttribute(name, value); | 713 Element::parseAttribute(name, value); |
| 651 } | 714 } |
| 652 } | 715 } |
| 653 | 716 |
| (...skipping 364 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 if (Element* parent = parentOrShadowHostElement()) { | 1081 if (Element* parent = parentOrShadowHostElement()) { |
| 1019 if (RenderObject* renderer = parent->renderer()) | 1082 if (RenderObject* renderer = parent->renderer()) |
| 1020 parentStyle = renderer->style(); | 1083 parentStyle = renderer->style(); |
| 1021 } | 1084 } |
| 1022 | 1085 |
| 1023 return svgRareData()->overrideComputedStyle(this, parentStyle); | 1086 return svgRareData()->overrideComputedStyle(this, parentStyle); |
| 1024 } | 1087 } |
| 1025 | 1088 |
| 1026 bool SVGElement::hasFocusEventListeners() const | 1089 bool SVGElement::hasFocusEventListeners() const |
| 1027 { | 1090 { |
| 1028 return hasEventListeners(EventTypeNames::focusin) || hasEventListeners(Event TypeNames::focusout); | 1091 return hasEventListeners(EventTypeNames::focusin) || hasEventListeners(Event TypeNames::focusout) |
| 1029 } | 1092 || hasEventListeners(EventTypeNames::focus) || hasEventListeners(EventTy peNames::blur); |
| 1030 | |
| 1031 bool SVGElement::isKeyboardFocusable() const | |
| 1032 { | |
| 1033 return isFocusable(); | |
| 1034 } | 1093 } |
| 1035 | 1094 |
| 1036 #ifndef NDEBUG | 1095 #ifndef NDEBUG |
| 1037 bool SVGElement::isAnimatableAttribute(const QualifiedName& name) const | 1096 bool SVGElement::isAnimatableAttribute(const QualifiedName& name) const |
| 1038 { | 1097 { |
| 1039 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, animatableAttributes, ()); | 1098 DEFINE_STATIC_LOCAL(HashSet<QualifiedName>, animatableAttributes, ()); |
| 1040 | 1099 |
| 1041 if (animatableAttributes.isEmpty()) { | 1100 if (animatableAttributes.isEmpty()) { |
| 1042 animatableAttributes.add(XLinkNames::hrefAttr); | 1101 animatableAttributes.add(XLinkNames::hrefAttr); |
| 1043 animatableAttributes.add(SVGNames::amplitudeAttr); | 1102 animatableAttributes.add(SVGNames::amplitudeAttr); |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1133 animatableAttributes.add(SVGNames::zAttr); | 1192 animatableAttributes.add(SVGNames::zAttr); |
| 1134 } | 1193 } |
| 1135 | 1194 |
| 1136 if (name == classAttr) | 1195 if (name == classAttr) |
| 1137 return true; | 1196 return true; |
| 1138 | 1197 |
| 1139 return animatableAttributes.contains(name); | 1198 return animatableAttributes.contains(name); |
| 1140 } | 1199 } |
| 1141 #endif | 1200 #endif |
| 1142 } | 1201 } |
| OLD | NEW |