← All changes
|
vendor/symfony/css-selector/XPath/Extension/HtmlExtension.php
+11
-4
4.4.2
→
4.4.9
View file →
| @@ -27,8 +27,15 @@ | ||
| 27 | 27 | * @internal |
| 28 | 28 | */ |
| 29 | 29 | class HtmlExtension extends AbstractExtension |
| 30 | 30 | { |
| 31 | + // Each disabled fieldset ancestor disables the element, except the one whose first legend | |
| 32 | + // child the element sits in. Those excepted fieldsets are exactly the parents of the | |
| 33 | + // ancestors-or-self that are a first legend child of a disabled fieldset, one for one, so | |
| 34 | + // the element is disabled as soon as the first count exceeds the second one. Counting keeps | |
| 35 | + // this to two cheap ancestor walks instead of a predicate run on every ancestor. | |
| 36 | + private const DISABLING_FIELDSET = 'count(ancestor::fieldset[@disabled]) > count(ancestor-or-self::legend[not(preceding-sibling::legend)][parent::fieldset[@disabled]])'; | |
| 37 | + | |
| 31 | 38 | public function __construct(Translator $translator) |
| 32 | 39 | { |
| 33 | 40 | $translator |
| 34 | 41 | ->getExtension('node') |
| @@ -90,12 +97,12 @@ | ||
| 90 | 97 | ."(name(.) = 'input' and @type != 'hidden')" |
| 91 | 98 | ." or name(.) = 'button'" |
| 92 | 99 | ." or name(.) = 'select'" |
| 93 | 100 | ." or name(.) = 'textarea'" |
| 101 | + ." or name(.) = 'fieldset'" | |
| 94 | 102 | .')' |
| 95 | - .' and ancestor::fieldset[@disabled]' | |
| 103 | + .' and '.self::DISABLING_FIELDSET | |
| 96 | 104 | ); |
| 97 | - // todo: in the second half, add "and is not a descendant of that fieldset element's first legend element child, if any." | |
| 98 | 105 | } |
| 99 | 106 | |
| 100 | 107 | public function translateEnabled(XPathExpr $xpath): XPathExpr |
| 101 | 108 | { |
| @@ -108,9 +115,8 @@ | ||
| 108 | 115 | .')' |
| 109 | 116 | .') or (' |
| 110 | 117 | .'(' |
| 111 | 118 | ."name(.) = 'command'" |
| 112 | - ." or name(.) = 'fieldset'" | |
| 113 | 119 | ." or name(.) = 'optgroup'" |
| 114 | 120 | .')' |
| 115 | 121 | .' and not(@disabled)' |
| 116 | 122 | .') or (' |
| @@ -119,10 +125,11 @@ | ||
| 119 | 125 | ." or name(.) = 'button'" |
| 120 | 126 | ." or name(.) = 'select'" |
| 121 | 127 | ." or name(.) = 'textarea'" |
| 122 | 128 | ." or name(.) = 'keygen'" |
| 129 | + ." or name(.) = 'fieldset'" | |
| 123 | 130 | .')' |
| 124 | - .' and not (@disabled or ancestor::fieldset[@disabled])' | |
| 131 | + .' and not(@disabled or '.self::DISABLING_FIELDSET.')' | |
| 125 | 132 | .') or (' |
| 126 | 133 | ."name(.) = 'option' and not(" |
| 127 | 134 | .'@disabled or ancestor::optgroup[@disabled]' |
| 128 | 135 | .')' |