darin | a51de91 | 2007-04-29 20:32:51 +0000 | [diff] [blame] | 1 | /* |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
weinig@apple.com | fa4b1a1 | 2008-06-15 02:03:24 +0000 | [diff] [blame] | 4 | * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
staikos@webkit.org | 159f11f | 2009-05-18 23:48:30 +0000 | [diff] [blame] | 5 | * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
rniwa@webkit.org | d10f670 | 2011-10-25 00:13:34 +0000 | [diff] [blame] | 6 | * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 7 | * |
| 8 | * This library is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU Library General Public |
| 10 | * License as published by the Free Software Foundation; either |
| 11 | * version 2 of the License, or (at your option) any later version. |
| 12 | * |
| 13 | * This library is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 16 | * Library General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU Library General Public License |
| 19 | * along with this library; see the file COPYING.LIB. If not, write to |
ddkilzer | c8eccec | 2007-09-26 02:29:57 +0000 | [diff] [blame] | 20 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 21 | * Boston, MA 02110-1301, USA. |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 22 | * |
| 23 | */ |
| 24 | |
| 25 | #include "config.h" |
| 26 | #include "HTMLElement.h" |
| 27 | |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 28 | #include "CSSParser.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 29 | #include "CSSPropertyNames.h" |
| 30 | #include "CSSValueKeywords.h" |
kling@webkit.org | c92997c | 2012-02-23 01:40:12 +0000 | [diff] [blame] | 31 | #include "CSSValuePool.h" |
cdumez@apple.com | 5863cc7 | 2016-02-04 16:57:44 +0000 | [diff] [blame] | 32 | #include "DOMTokenList.h" |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 33 | #include "DocumentFragment.h" |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 34 | #include "ElementAncestorIterator.h" |
darin | f1bb004 | 2006-12-01 22:46:21 +0000 | [diff] [blame] | 35 | #include "Event.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 36 | #include "EventListener.h" |
| 37 | #include "EventNames.h" |
| 38 | #include "ExceptionCode.h" |
| 39 | #include "Frame.h" |
abarth@webkit.org | 401a379 | 2013-03-03 10:12:59 +0000 | [diff] [blame] | 40 | #include "FrameLoader.h" |
antti@apple.com | 4942ea5 | 2013-12-20 14:44:23 +0000 | [diff] [blame] | 41 | #include "FrameView.h" |
cdumez@apple.com | cd13153 | 2014-09-27 01:32:34 +0000 | [diff] [blame] | 42 | #include "HTMLBDIElement.h" |
andersca | c1c14c9 | 2006-07-07 01:00:32 +0000 | [diff] [blame] | 43 | #include "HTMLBRElement.h" |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 44 | #include "HTMLButtonElement.h" |
darin@apple.com | 9a925fa | 2009-05-04 18:00:34 +0000 | [diff] [blame] | 45 | #include "HTMLCollection.h" |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 46 | #include "HTMLDocument.h" |
| 47 | #include "HTMLElementFactory.h" |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 48 | #include "HTMLFieldSetElement.h" |
darin | 9efc76e | 2007-05-29 17:41:17 +0000 | [diff] [blame] | 49 | #include "HTMLFormElement.h" |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 50 | #include "HTMLInputElement.h" |
darin | 98fa8b8 | 2006-03-20 08:03:57 +0000 | [diff] [blame] | 51 | #include "HTMLNames.h" |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 52 | #include "HTMLOptGroupElement.h" |
| 53 | #include "HTMLOptionElement.h" |
abarth@webkit.org | 9f272bb | 2010-09-14 22:53:02 +0000 | [diff] [blame] | 54 | #include "HTMLParserIdioms.h" |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 55 | #include "HTMLSelectElement.h" |
| 56 | #include "HTMLTextAreaElement.h" |
yael.aharon@nokia.com | 0a5d0e5 | 2011-08-05 14:36:33 +0000 | [diff] [blame] | 57 | #include "HTMLTextFormControlElement.h" |
antti@apple.com | 5d47b58 | 2012-12-11 00:13:29 +0000 | [diff] [blame] | 58 | #include "NodeTraversal.h" |
cdumez@apple.com | 43c01da | 2014-11-06 23:17:32 +0000 | [diff] [blame] | 59 | #include "RenderElement.h" |
weinig@apple.com | 123e4aa | 2013-04-14 00:54:27 +0000 | [diff] [blame] | 60 | #include "ScriptController.h" |
darin@apple.com | ab6c146e | 2016-09-06 03:33:50 +0000 | [diff] [blame] | 61 | #include "SimulatedClick.h" |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 62 | #include "StyleProperties.h" |
akling@apple.com | 7f81b1e | 2013-09-06 17:23:03 +0000 | [diff] [blame] | 63 | #include "SubframeLoader.h" |
darin | 42563ac5 | 2007-01-22 17:28:57 +0000 | [diff] [blame] | 64 | #include "Text.h" |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 65 | #include "XMLNames.h" |
weinig | 681a517 | 2006-06-19 22:58:36 +0000 | [diff] [blame] | 66 | #include "markup.h" |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 67 | #include <wtf/NeverDestroyed.h> |
bolsinga@apple.com | 97e42c4 | 2008-11-15 04:47:20 +0000 | [diff] [blame] | 68 | #include <wtf/StdLibExtras.h> |
andreas.kling@nokia.com | 5fac418 | 2010-09-16 15:17:46 +0000 | [diff] [blame] | 69 | #include <wtf/text/CString.h> |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 70 | |
| 71 | namespace WebCore { |
| 72 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 73 | using namespace HTMLNames; |
yael.aharon@nokia.com | 0a5d0e5 | 2011-08-05 14:36:33 +0000 | [diff] [blame] | 74 | using namespace WTF; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 75 | |
weinig@apple.com | 02f433a | 2015-01-06 22:32:48 +0000 | [diff] [blame] | 76 | Ref<HTMLElement> HTMLElement::create(const QualifiedName& tagName, Document& document) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 77 | { |
weinig@apple.com | 02f433a | 2015-01-06 22:32:48 +0000 | [diff] [blame] | 78 | return adoptRef(*new HTMLElement(tagName, document)); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | String HTMLElement::nodeName() const |
| 82 | { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 83 | // FIXME: Would be nice to have an AtomicString lookup based off uppercase |
| 84 | // ASCII characters that does not have to copy the string on a hit in the hash. |
cdumez@apple.com | 892c7c2 | 2015-09-11 14:51:32 +0000 | [diff] [blame] | 85 | if (document().isHTMLDocument()) { |
rniwa@webkit.org | cd6bdd4 | 2016-01-23 02:04:41 +0000 | [diff] [blame] | 86 | if (LIKELY(!tagQName().hasPrefix())) |
cdumez@apple.com | 892c7c2 | 2015-09-11 14:51:32 +0000 | [diff] [blame] | 87 | return tagQName().localNameUpper(); |
rniwa@webkit.org | cd6bdd4 | 2016-01-23 02:04:41 +0000 | [diff] [blame] | 88 | return Element::nodeName().convertToASCIIUppercase(); |
cdumez@apple.com | 892c7c2 | 2015-09-11 14:51:32 +0000 | [diff] [blame] | 89 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 90 | return Element::nodeName(); |
| 91 | } |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 92 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 93 | static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement& element) |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 94 | { |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 95 | if (element.hasTagName(preTag) || element.hasTagName(textareaTag)) |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 96 | return CSSValueWebkitPlaintext; |
rniwa@webkit.org | 01f7f67 | 2011-11-28 19:19:37 +0000 | [diff] [blame] | 97 | // FIXME: For bdo element, dir="auto" should result in "bidi-override isolate" but we don't support having multiple values in unicode-bidi yet. |
| 98 | // See https://bugs.webkit.org/show_bug.cgi?id=73164. |
| 99 | return CSSValueWebkitIsolate; |
leviw@chromium.org | 7781b6a | 2011-06-27 22:01:38 +0000 | [diff] [blame] | 100 | } |
| 101 | |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 102 | unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const |
commit-queue@webkit.org | 77f2f39 | 2011-08-01 11:18:15 +0000 | [diff] [blame] | 103 | { |
cdumez@apple.com | 2702e9c | 2016-09-08 21:31:54 +0000 | [diff] [blame] | 104 | if (Optional<unsigned> borderWidth = parseHTMLNonNegativeInteger(value)) |
cdumez@apple.com | 7a2e405 | 2016-03-02 17:12:37 +0000 | [diff] [blame] | 105 | return borderWidth.value(); |
| 106 | |
| 107 | return hasTagName(tableTag) ? 1 : 0; |
commit-queue@webkit.org | 77f2f39 | 2011-08-01 11:18:15 +0000 | [diff] [blame] | 108 | } |
| 109 | |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 110 | void HTMLElement::applyBorderAttributeToStyle(const AtomicString& value, MutableStyleProperties& style) |
commit-queue@webkit.org | 2c5d5c6 | 2011-09-02 17:01:42 +0000 | [diff] [blame] | 111 | { |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 112 | addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, parseBorderWidthAttribute(value), CSSPrimitiveValue::CSS_PX); |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 113 | addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSValueSolid); |
commit-queue@webkit.org | 2c5d5c6 | 2011-09-02 17:01:42 +0000 | [diff] [blame] | 114 | } |
| 115 | |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 116 | void HTMLElement::mapLanguageAttributeToLocale(const AtomicString& value, MutableStyleProperties& style) |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 117 | { |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 118 | if (!value.isEmpty()) { |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 119 | // Have to quote so the locale id is treated as a string instead of as a CSS keyword. |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 120 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLocale, quoteCSSString(value)); |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 121 | } else { |
| 122 | // The empty string means the language is explicitly unknown. |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 123 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLocale, CSSValueAuto); |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 124 | } |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 125 | } |
| 126 | |
kling@webkit.org | 44bc0dd | 2012-02-28 22:21:02 +0000 | [diff] [blame] | 127 | bool HTMLElement::isPresentationAttribute(const QualifiedName& name) const |
kling@webkit.org | 11f2556 | 2012-02-13 10:36:55 +0000 | [diff] [blame] | 128 | { |
kling@webkit.org | 44bc0dd | 2012-02-28 22:21:02 +0000 | [diff] [blame] | 129 | if (name == alignAttr || name == contenteditableAttr || name == hiddenAttr || name == langAttr || name.matches(XMLNames::langAttr) || name == draggableAttr || name == dirAttr) |
kling@webkit.org | 11f2556 | 2012-02-13 10:36:55 +0000 | [diff] [blame] | 130 | return true; |
kling@webkit.org | 44bc0dd | 2012-02-28 22:21:02 +0000 | [diff] [blame] | 131 | return StyledElement::isPresentationAttribute(name); |
kling@webkit.org | 11f2556 | 2012-02-13 10:36:55 +0000 | [diff] [blame] | 132 | } |
| 133 | |
rniwa@webkit.org | 8b638ce | 2013-12-17 20:10:12 +0000 | [diff] [blame] | 134 | static bool isLTROrRTLIgnoringCase(const AtomicString& dirAttributeValue) |
| 135 | { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 136 | return equalLettersIgnoringASCIICase(dirAttributeValue, "rtl") || equalLettersIgnoringASCIICase(dirAttributeValue, "ltr"); |
rniwa@webkit.org | 8b638ce | 2013-12-17 20:10:12 +0000 | [diff] [blame] | 137 | } |
| 138 | |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 139 | enum class ContentEditableType { |
| 140 | Inherit, |
| 141 | True, |
| 142 | False, |
| 143 | PlaintextOnly |
| 144 | }; |
| 145 | |
| 146 | static inline ContentEditableType contentEditableType(const AtomicString& value) |
| 147 | { |
| 148 | if (value.isNull()) |
| 149 | return ContentEditableType::Inherit; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 150 | if (value.isEmpty() || equalLettersIgnoringASCIICase(value, "true")) |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 151 | return ContentEditableType::True; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 152 | if (equalLettersIgnoringASCIICase(value, "false")) |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 153 | return ContentEditableType::False; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 154 | if (equalLettersIgnoringASCIICase(value, "plaintext-only")) |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 155 | return ContentEditableType::PlaintextOnly; |
| 156 | |
| 157 | return ContentEditableType::Inherit; |
| 158 | } |
| 159 | |
| 160 | static ContentEditableType contentEditableType(const HTMLElement& element) |
| 161 | { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 162 | return contentEditableType(element.attributeWithoutSynchronization(contenteditableAttr)); |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 163 | } |
| 164 | |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 165 | void HTMLElement::collectStyleForPresentationAttribute(const QualifiedName& name, const AtomicString& value, MutableStyleProperties& style) |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 166 | { |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 167 | if (name == alignAttr) { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 168 | if (equalLettersIgnoringASCIICase(value, "middle")) |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 169 | addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, CSSValueCenter); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 170 | else |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 171 | addPropertyToPresentationAttributeStyle(style, CSSPropertyTextAlign, value); |
| 172 | } else if (name == contenteditableAttr) { |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 173 | CSSValueID userModifyValue = CSSValueReadWrite; |
| 174 | switch (contentEditableType(value)) { |
| 175 | case ContentEditableType::Inherit: |
| 176 | return; |
| 177 | case ContentEditableType::False: |
| 178 | userModifyValue = CSSValueReadOnly; |
| 179 | break; |
| 180 | case ContentEditableType::PlaintextOnly: |
| 181 | userModifyValue = CSSValueReadWritePlaintextOnly; |
| 182 | FALLTHROUGH; |
| 183 | case ContentEditableType::True: |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 184 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWordWrap, CSSValueBreakWord); |
| 185 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitNbspMode, CSSValueSpace); |
| 186 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitLineBreak, CSSValueAfterWhiteSpace); |
dbates@webkit.org | 1edd81d | 2013-12-18 00:15:02 +0000 | [diff] [blame] | 187 | #if PLATFORM(IOS) |
| 188 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitTextSizeAdjust, CSSValueNone); |
| 189 | #endif |
rniwa@webkit.org | 095ae4e | 2015-02-25 18:42:04 +0000 | [diff] [blame] | 190 | break; |
| 191 | } |
| 192 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserModify, userModifyValue); |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 193 | } else if (name == hiddenAttr) { |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 194 | addPropertyToPresentationAttributeStyle(style, CSSPropertyDisplay, CSSValueNone); |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 195 | } else if (name == draggableAttr) { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 196 | if (equalLettersIgnoringASCIICase(value, "true")) { |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 197 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueElement); |
| 198 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserSelect, CSSValueNone); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 199 | } else if (equalLettersIgnoringASCIICase(value, "false")) |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 200 | addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUserDrag, CSSValueNone); |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 201 | } else if (name == dirAttr) { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 202 | if (equalLettersIgnoringASCIICase(value, "auto")) |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 203 | addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBidi, unicodeBidiAttributeForDirAuto(*this)); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 204 | else { |
rniwa@webkit.org | 8b638ce | 2013-12-17 20:10:12 +0000 | [diff] [blame] | 205 | if (isLTROrRTLIgnoringCase(value)) |
| 206 | addPropertyToPresentationAttributeStyle(style, CSSPropertyDirection, value); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 207 | if (!hasTagName(bdiTag) && !hasTagName(bdoTag) && !hasTagName(outputTag)) |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 208 | addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBidi, CSSValueEmbed); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 209 | } |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 210 | } else if (name.matches(XMLNames::langAttr)) |
| 211 | mapLanguageAttributeToLocale(value, style); |
| 212 | else if (name == langAttr) { |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 213 | // xml:lang has a higher priority than lang. |
rniwa@webkit.org | bda54a0 | 2016-07-18 00:39:37 +0000 | [diff] [blame] | 214 | if (!hasAttributeWithoutSynchronization(XMLNames::langAttr)) |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 215 | mapLanguageAttributeToLocale(value, style); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 216 | } else |
akling@apple.com | b75eeea | 2013-02-23 17:57:50 +0000 | [diff] [blame] | 217 | StyledElement::collectStyleForPresentationAttribute(name, value, style); |
commit-queue@webkit.org | 5d3b4a7 | 2011-12-23 07:29:32 +0000 | [diff] [blame] | 218 | } |
| 219 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 220 | HTMLElement::EventHandlerNameMap HTMLElement::createEventHandlerNameMap() |
keishi@webkit.org | b61c383 | 2013-03-29 09:59:09 +0000 | [diff] [blame] | 221 | { |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 222 | EventHandlerNameMap map; |
| 223 | |
| 224 | static const QualifiedName* const table[] = { |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 225 | &onabortAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 226 | &onanimationendAttr, |
| 227 | &onanimationiterationAttr, |
| 228 | &onanimationstartAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 229 | &onautocompleteAttr, |
| 230 | &onautocompleteerrorAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 231 | &onbeforecopyAttr, |
| 232 | &onbeforecutAttr, |
wenson_hsieh@apple.com | 2bebcde | 2016-10-07 23:47:18 +0000 | [diff] [blame] | 233 | &onbeforeinputAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 234 | &onbeforeloadAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 235 | &onbeforepasteAttr, |
| 236 | &onblurAttr, |
| 237 | &oncanplayAttr, |
| 238 | &oncanplaythroughAttr, |
| 239 | &onchangeAttr, |
| 240 | &onclickAttr, |
| 241 | &oncontextmenuAttr, |
| 242 | &oncopyAttr, |
| 243 | &oncutAttr, |
| 244 | &ondblclickAttr, |
| 245 | &ondragAttr, |
| 246 | &ondragendAttr, |
| 247 | &ondragenterAttr, |
| 248 | &ondragleaveAttr, |
| 249 | &ondragoverAttr, |
| 250 | &ondragstartAttr, |
| 251 | &ondropAttr, |
| 252 | &ondurationchangeAttr, |
| 253 | &onemptiedAttr, |
| 254 | &onendedAttr, |
| 255 | &onerrorAttr, |
| 256 | &onfocusAttr, |
| 257 | &onfocusinAttr, |
| 258 | &onfocusoutAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 259 | &ongesturechangeAttr, |
| 260 | &ongestureendAttr, |
| 261 | &ongesturestartAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 262 | &oninputAttr, |
| 263 | &oninvalidAttr, |
| 264 | &onkeydownAttr, |
| 265 | &onkeypressAttr, |
| 266 | &onkeyupAttr, |
| 267 | &onloadAttr, |
| 268 | &onloadeddataAttr, |
| 269 | &onloadedmetadataAttr, |
| 270 | &onloadstartAttr, |
| 271 | &onmousedownAttr, |
| 272 | &onmouseenterAttr, |
| 273 | &onmouseleaveAttr, |
| 274 | &onmousemoveAttr, |
| 275 | &onmouseoutAttr, |
| 276 | &onmouseoverAttr, |
| 277 | &onmouseupAttr, |
| 278 | &onmousewheelAttr, |
| 279 | &onpasteAttr, |
| 280 | &onpauseAttr, |
| 281 | &onplayAttr, |
| 282 | &onplayingAttr, |
| 283 | &onprogressAttr, |
| 284 | &onratechangeAttr, |
| 285 | &onresetAttr, |
commit-queue@webkit.org | aeaaa2d | 2016-02-01 06:34:07 +0000 | [diff] [blame] | 286 | &onresizeAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 287 | &onscrollAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 288 | &onsearchAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 289 | &onseekedAttr, |
| 290 | &onseekingAttr, |
| 291 | &onselectAttr, |
| 292 | &onselectstartAttr, |
| 293 | &onstalledAttr, |
| 294 | &onsubmitAttr, |
| 295 | &onsuspendAttr, |
| 296 | &ontimeupdateAttr, |
cdumez@apple.com | 4026111 | 2016-10-19 02:03:07 +0000 | [diff] [blame] | 297 | &ontoggleAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 298 | &ontouchcancelAttr, |
| 299 | &ontouchendAttr, |
bdakin@apple.com | 4e191ed | 2016-03-08 20:18:51 +0000 | [diff] [blame] | 300 | &ontouchforcechangeAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 301 | &ontouchmoveAttr, |
| 302 | &ontouchstartAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 303 | &ontransitionendAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 304 | &onvolumechangeAttr, |
| 305 | &onwaitingAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 306 | &onwebkitbeginfullscreenAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 307 | &onwebkitcurrentplaybacktargetiswirelesschangedAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 308 | &onwebkitendfullscreenAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 309 | &onwebkitfullscreenchangeAttr, |
| 310 | &onwebkitfullscreenerrorAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 311 | &onwebkitkeyaddedAttr, |
| 312 | &onwebkitkeyerrorAttr, |
| 313 | &onwebkitkeymessageAttr, |
bdakin@apple.com | fe24905 | 2015-03-24 21:31:28 +0000 | [diff] [blame] | 314 | &onwebkitmouseforcechangedAttr, |
bdakin@apple.com | fe24905 | 2015-03-24 21:31:28 +0000 | [diff] [blame] | 315 | &onwebkitmouseforcedownAttr, |
| 316 | &onwebkitmouseforcewillbeginAttr, |
| 317 | &onwebkitmouseforceupAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 318 | &onwebkitneedkeyAttr, |
| 319 | &onwebkitplaybacktargetavailabilitychangedAttr, |
darin@apple.com | 25da412 | 2015-03-11 02:21:20 +0000 | [diff] [blame] | 320 | &onwebkitpresentationmodechangedAttr, |
bdakin@apple.com | d7c6a1e | 2014-01-30 19:25:25 +0000 | [diff] [blame] | 321 | &onwebkitwillrevealbottomAttr, |
| 322 | &onwebkitwillrevealleftAttr, |
| 323 | &onwebkitwillrevealrightAttr, |
| 324 | &onwebkitwillrevealtopAttr, |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 325 | &onwheelAttr, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 326 | }; |
| 327 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 328 | populateEventHandlerNameMap(map, table); |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 329 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 330 | struct UnusualMapping { |
darin@apple.com | 5b7f307 | 2013-09-15 08:50:06 +0000 | [diff] [blame] | 331 | const QualifiedName& attributeName; |
| 332 | const AtomicString& eventName; |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 333 | }; |
| 334 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 335 | const UnusualMapping unusualPairsTable[] = { |
darin@apple.com | 5b7f307 | 2013-09-15 08:50:06 +0000 | [diff] [blame] | 336 | { onwebkitanimationendAttr, eventNames().webkitAnimationEndEvent }, |
| 337 | { onwebkitanimationiterationAttr, eventNames().webkitAnimationIterationEvent }, |
| 338 | { onwebkitanimationstartAttr, eventNames().webkitAnimationStartEvent }, |
| 339 | { onwebkittransitionendAttr, eventNames().webkitTransitionEndEvent }, |
darin@apple.com | 8ceb5ba | 2013-09-14 16:19:14 +0000 | [diff] [blame] | 340 | }; |
| 341 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 342 | for (auto& entry : unusualPairsTable) |
| 343 | map.add(entry.attributeName.localName().impl(), entry.eventName); |
| 344 | |
| 345 | return map; |
| 346 | } |
| 347 | |
| 348 | void HTMLElement::populateEventHandlerNameMap(EventHandlerNameMap& map, const QualifiedName* const table[], size_t tableSize) |
| 349 | { |
| 350 | for (size_t i = 0; i < tableSize; ++i) { |
| 351 | auto* entry = table[i]; |
| 352 | |
| 353 | // FIXME: Would be nice to check these against the actual event names in eventNames(). |
| 354 | // Not obvious how to do that simply, though. |
| 355 | auto& attributeName = entry->localName(); |
| 356 | |
| 357 | // Remove the "on" prefix. Requires some memory allocation and computing a hash, but by not |
| 358 | // using pointers from eventNames(), the passed-in table can be initialized at compile time. |
| 359 | AtomicString eventName = attributeName.string().substring(2); |
| 360 | |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 361 | map.add(attributeName.impl(), WTFMove(eventName)); |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 362 | } |
| 363 | } |
| 364 | |
| 365 | const AtomicString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName, const EventHandlerNameMap& map) |
| 366 | { |
| 367 | ASSERT(!attributeName.localName().isNull()); |
| 368 | |
| 369 | // Event handler attributes have no namespace. |
| 370 | if (!attributeName.namespaceURI().isNull()) |
| 371 | return nullAtom; |
| 372 | |
| 373 | // Fast early return for names that don't start with "on". |
| 374 | AtomicStringImpl& localName = *attributeName.localName().impl(); |
| 375 | if (localName.length() < 3 || localName[0] != 'o' || localName[1] != 'n') |
| 376 | return nullAtom; |
| 377 | |
| 378 | auto it = map.find(&localName); |
| 379 | return it == map.end() ? nullAtom : it->value; |
| 380 | } |
| 381 | |
| 382 | const AtomicString& HTMLElement::eventNameForEventHandlerAttribute(const QualifiedName& attributeName) |
| 383 | { |
| 384 | static NeverDestroyed<EventHandlerNameMap> map = createEventHandlerNameMap(); |
| 385 | return eventNameForEventHandlerAttribute(attributeName, map.get()); |
keishi@webkit.org | b61c383 | 2013-03-29 09:59:09 +0000 | [diff] [blame] | 386 | } |
| 387 | |
rniwa@webkit.org | dbb2a29 | 2015-03-01 19:52:21 +0000 | [diff] [blame] | 388 | Node::Editability HTMLElement::editabilityFromContentEditableAttr(const Node& node) |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 389 | { |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 390 | if (auto* startElement = is<Element>(node) ? &downcast<Element>(node) : node.parentElement()) { |
| 391 | for (auto& element : lineageOfType<HTMLElement>(*startElement)) { |
| 392 | switch (contentEditableType(element)) { |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 393 | case ContentEditableType::True: |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 394 | return Editability::CanEditRichly; |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 395 | case ContentEditableType::PlaintextOnly: |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 396 | return Editability::CanEditPlainText; |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 397 | case ContentEditableType::False: |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 398 | return Editability::ReadOnly; |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 399 | case ContentEditableType::Inherit: |
| 400 | break; |
| 401 | } |
| 402 | } |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 403 | } |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 404 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 405 | auto& document = node.document(); |
cdumez@apple.com | 21bd428 | 2014-09-29 16:58:42 +0000 | [diff] [blame] | 406 | if (is<HTMLDocument>(document)) |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 407 | return downcast<HTMLDocument>(document).inDesignMode() ? Editability::CanEditRichly : Editability::ReadOnly; |
rniwa@webkit.org | dbb2a29 | 2015-03-01 19:52:21 +0000 | [diff] [blame] | 408 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 409 | return Editability::ReadOnly; |
rniwa@webkit.org | dbb2a29 | 2015-03-01 19:52:21 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | bool HTMLElement::matchesReadWritePseudoClass() const |
| 413 | { |
| 414 | return editabilityFromContentEditableAttr(*this) != Editability::ReadOnly; |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 415 | } |
| 416 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 417 | void HTMLElement::parseAttribute(const QualifiedName& name, const AtomicString& value) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 418 | { |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 419 | if (name == dirAttr) { |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 420 | dirAttributeChanged(value); |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 421 | return; |
| 422 | } |
| 423 | |
| 424 | if (name == tabindexAttr) { |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 425 | if (value.isEmpty()) |
rniwa@webkit.org | 2015feb | 2013-01-14 23:57:39 +0000 | [diff] [blame] | 426 | clearTabIndexExplicitlyIfNeeded(); |
cdumez@apple.com | 825cfbb | 2016-03-08 06:38:10 +0000 | [diff] [blame] | 427 | else if (Optional<int> tabIndex = parseHTMLInteger(value)) |
| 428 | setTabIndexExplicitly(tabIndex.value()); |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 429 | return; |
ggaren | 59d1d76 | 2006-04-22 07:33:04 +0000 | [diff] [blame] | 430 | } |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 431 | |
| 432 | auto& eventName = eventNameForEventHandlerAttribute(name); |
| 433 | if (!eventName.isNull()) |
| 434 | setAttributeEventListener(eventName, name, value); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 435 | } |
| 436 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 437 | ExceptionOr<Ref<DocumentFragment>> HTMLElement::textToFragment(const String& text) |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 438 | { |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 439 | auto fragment = DocumentFragment::create(document()); |
| 440 | |
| 441 | for (unsigned start = 0, length = text.length(); start < length; ) { |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 442 | |
| 443 | // Find next line break. |
pvollan@apple.com | 6394551 | 2016-08-26 13:29:31 +0000 | [diff] [blame] | 444 | UChar c = 0; |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 445 | unsigned i; |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 446 | for (i = start; i < length; i++) { |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 447 | c = text[i]; |
| 448 | if (c == '\r' || c == '\n') |
| 449 | break; |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 450 | } |
| 451 | |
darin@apple.com | 4a588ff | 2016-11-11 20:16:03 +0000 | [diff] [blame] | 452 | auto appendResult = fragment->appendChild(Text::create(document(), text.substring(start, i - start))); |
| 453 | if (appendResult.hasException()) |
| 454 | return appendResult.releaseException(); |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 455 | |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 456 | if (i == length) |
| 457 | break; |
| 458 | |
darin@apple.com | 4a588ff | 2016-11-11 20:16:03 +0000 | [diff] [blame] | 459 | appendResult = fragment->appendChild(HTMLBRElement::create(document())); |
| 460 | if (appendResult.hasException()) |
| 461 | return appendResult.releaseException(); |
darin@apple.com | c52c9bf | 2015-03-15 17:00:33 +0000 | [diff] [blame] | 462 | |
| 463 | // Make sure \r\n doesn't result in two line breaks. |
| 464 | if (c == '\r' && i + 1 < length && text[i + 1] == '\n') |
| 465 | ++i; |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 466 | |
| 467 | start = i + 1; // Character after line break. |
| 468 | } |
| 469 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 470 | return WTFMove(fragment); |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 471 | } |
| 472 | |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 473 | static inline bool shouldProhibitSetInnerOuterText(const HTMLElement& element) |
| 474 | { |
| 475 | return element.hasTagName(colTag) |
| 476 | || element.hasTagName(colgroupTag) |
| 477 | || element.hasTagName(framesetTag) |
| 478 | || element.hasTagName(headTag) |
| 479 | || element.hasTagName(htmlTag) |
| 480 | || element.hasTagName(tableTag) |
| 481 | || element.hasTagName(tbodyTag) |
| 482 | || element.hasTagName(tfootTag) |
| 483 | || element.hasTagName(theadTag) |
| 484 | || element.hasTagName(trTag); |
| 485 | } |
| 486 | |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 487 | // Returns the conforming 'dir' value associated with the state the attribute is in (in its canonical case), if any, |
| 488 | // or the empty string if the attribute is in a state that has no associated keyword value or if the attribute is |
| 489 | // not in a defined state (e.g. the attribute is missing and there is no missing value default). |
| 490 | // http://www.whatwg.org/specs/web-apps/current-work/multipage/common-dom-interfaces.html#limited-to-only-known-values |
| 491 | static inline const AtomicString& toValidDirValue(const AtomicString& value) |
| 492 | { |
| 493 | static NeverDestroyed<AtomicString> ltrValue("ltr", AtomicString::ConstructFromLiteral); |
| 494 | static NeverDestroyed<AtomicString> rtlValue("rtl", AtomicString::ConstructFromLiteral); |
| 495 | static NeverDestroyed<AtomicString> autoValue("auto", AtomicString::ConstructFromLiteral); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 496 | if (equalLettersIgnoringASCIICase(value, "ltr")) |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 497 | return ltrValue; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 498 | if (equalLettersIgnoringASCIICase(value, "rtl")) |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 499 | return rtlValue; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 500 | if (equalLettersIgnoringASCIICase(value, "auto")) |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 501 | return autoValue; |
| 502 | return nullAtom; |
| 503 | } |
| 504 | |
| 505 | const AtomicString& HTMLElement::dir() const |
| 506 | { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 507 | return toValidDirValue(attributeWithoutSynchronization(dirAttr)); |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | void HTMLElement::setDir(const AtomicString& value) |
| 511 | { |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 512 | setAttributeWithoutSynchronization(dirAttr, value); |
cdumez@apple.com | e9e8f11 | 2015-01-27 15:59:58 +0000 | [diff] [blame] | 513 | } |
| 514 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 515 | ExceptionOr<void> HTMLElement::setInnerText(const String& text) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 516 | { |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 517 | if (ieForbidsInsertHTML()) |
| 518 | return Exception { NO_MODIFICATION_ALLOWED_ERR }; |
| 519 | if (shouldProhibitSetInnerOuterText(*this)) |
| 520 | return Exception { NO_MODIFICATION_ALLOWED_ERR }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 521 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 522 | // FIXME: This doesn't take whitespace collapsing into account at all. |
andersca | c1c14c9 | 2006-07-07 01:00:32 +0000 | [diff] [blame] | 523 | |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 524 | if (!text.contains('\n') && !text.contains('\r')) { |
darin | 48ef06c | 2007-05-29 19:39:14 +0000 | [diff] [blame] | 525 | if (text.isEmpty()) { |
| 526 | removeChildren(); |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 527 | return { }; |
darin | 48ef06c | 2007-05-29 19:39:14 +0000 | [diff] [blame] | 528 | } |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 529 | return replaceChildrenWithText(*this, text); |
andersca | c1c14c9 | 2006-07-07 01:00:32 +0000 | [diff] [blame] | 530 | } |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 531 | |
| 532 | // FIXME: Do we need to be able to detect preserveNewline style even when there's no renderer? |
hyatt@apple.com | f6d72f3 | 2009-04-10 00:05:02 +0000 | [diff] [blame] | 533 | // FIXME: Can the renderer be out of date here? Do we need to call updateStyleIfNeeded? |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 534 | // For example, for the contents of textarea elements that are display:none? |
darin@apple.com | 8cdf712 | 2013-09-30 02:40:50 +0000 | [diff] [blame] | 535 | auto r = renderer(); |
antti@apple.com | 4942ea5 | 2013-12-20 14:44:23 +0000 | [diff] [blame] | 536 | if ((r && r->style().preserveNewline()) || (inDocument() && isTextControlInnerTextElement())) { |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 537 | if (!text.contains('\r')) |
| 538 | return replaceChildrenWithText(*this, text); |
darin | 48ef06c | 2007-05-29 19:39:14 +0000 | [diff] [blame] | 539 | String textWithConsistentLineBreaks = text; |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 540 | textWithConsistentLineBreaks.replace("\r\n", "\n"); |
| 541 | textWithConsistentLineBreaks.replace('\r', '\n'); |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 542 | return replaceChildrenWithText(*this, textWithConsistentLineBreaks); |
darin | 38ae534 | 2006-07-25 04:39:25 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | // Add text nodes and <br> elements. |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 546 | auto fragment = textToFragment(text); |
| 547 | if (fragment.hasException()) |
| 548 | return fragment.releaseException(); |
| 549 | return replaceChildrenWithFragment(*this, fragment.releaseReturnValue()); |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 550 | } |
| 551 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 552 | ExceptionOr<void> HTMLElement::setOuterText(const String& text) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 553 | { |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 554 | if (ieForbidsInsertHTML()) |
| 555 | return Exception { NO_MODIFICATION_ALLOWED_ERR }; |
| 556 | if (shouldProhibitSetInnerOuterText(*this)) |
| 557 | return Exception { NO_MODIFICATION_ALLOWED_ERR }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 558 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 559 | RefPtr<ContainerNode> parent = parentNode(); |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 560 | if (!parent) |
| 561 | return Exception { NO_MODIFICATION_ALLOWED_ERR }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 562 | |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 563 | RefPtr<Node> prev = previousSibling(); |
| 564 | RefPtr<Node> next = nextSibling(); |
| 565 | RefPtr<Node> newChild; |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 566 | |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 567 | // Convert text to fragment with <br> tags instead of linebreaks if needed. |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 568 | if (text.contains('\r') || text.contains('\n')) { |
| 569 | auto result = textToFragment(text); |
| 570 | if (result.hasException()) |
| 571 | return result.releaseException(); |
| 572 | newChild = result.releaseReturnValue(); |
| 573 | } else |
weinig@apple.com | f2a10f3 | 2013-09-15 13:31:54 +0000 | [diff] [blame] | 574 | newChild = Text::create(document(), text); |
commit-queue@webkit.org | 129fb5f | 2011-01-13 22:49:44 +0000 | [diff] [blame] | 575 | |
ddkilzer@apple.com | 824b19e2 | 2014-09-06 15:02:58 +0000 | [diff] [blame] | 576 | if (!parentNode()) |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 577 | return Exception { HIERARCHY_REQUEST_ERR }; |
| 578 | |
darin@apple.com | 4a588ff | 2016-11-11 20:16:03 +0000 | [diff] [blame] | 579 | auto replaceResult = parent->replaceChild(*newChild, *this); |
| 580 | if (replaceResult.hasException()) |
| 581 | return replaceResult.releaseException(); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 582 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 583 | RefPtr<Node> node = next ? next->previousSibling() : nullptr; |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 584 | if (is<Text>(node.get())) { |
darin@apple.com | 5e46c858 | 2016-10-30 22:36:07 +0000 | [diff] [blame] | 585 | auto result = mergeWithNextTextNode(downcast<Text>(*node)); |
| 586 | if (result.hasException()) |
| 587 | return result.releaseException(); |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 588 | } |
| 589 | if (is<Text>(prev.get())) { |
darin@apple.com | 5e46c858 | 2016-10-30 22:36:07 +0000 | [diff] [blame] | 590 | auto result = mergeWithNextTextNode(downcast<Text>(*prev)); |
| 591 | if (result.hasException()) |
| 592 | return result.releaseException(); |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 593 | } |
| 594 | return { }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 595 | } |
| 596 | |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 597 | void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStyleProperties& style) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 598 | { |
enrica@apple.com | 46e6d6a | 2010-02-23 21:31:11 +0000 | [diff] [blame] | 599 | // Vertical alignment with respect to the current baseline of the text |
| 600 | // right or left means floating images. |
alexis@webkit.org | 71873a0 | 2013-06-19 22:07:23 +0000 | [diff] [blame] | 601 | CSSValueID floatValue = CSSValueInvalid; |
| 602 | CSSValueID verticalAlignValue = CSSValueInvalid; |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 603 | |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 604 | if (equalLettersIgnoringASCIICase(alignment, "absmiddle")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 605 | verticalAlignValue = CSSValueMiddle; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 606 | else if (equalLettersIgnoringASCIICase(alignment, "absbottom")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 607 | verticalAlignValue = CSSValueBottom; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 608 | else if (equalLettersIgnoringASCIICase(alignment, "left")) { |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 609 | floatValue = CSSValueLeft; |
| 610 | verticalAlignValue = CSSValueTop; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 611 | } else if (equalLettersIgnoringASCIICase(alignment, "right")) { |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 612 | floatValue = CSSValueRight; |
| 613 | verticalAlignValue = CSSValueTop; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 614 | } else if (equalLettersIgnoringASCIICase(alignment, "top")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 615 | verticalAlignValue = CSSValueTop; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 616 | else if (equalLettersIgnoringASCIICase(alignment, "middle")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 617 | verticalAlignValue = CSSValueWebkitBaselineMiddle; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 618 | else if (equalLettersIgnoringASCIICase(alignment, "center")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 619 | verticalAlignValue = CSSValueMiddle; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 620 | else if (equalLettersIgnoringASCIICase(alignment, "bottom")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 621 | verticalAlignValue = CSSValueBaseline; |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 622 | else if (equalLettersIgnoringASCIICase(alignment, "texttop")) |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 623 | verticalAlignValue = CSSValueTextTop; |
| 624 | |
| 625 | if (floatValue != CSSValueInvalid) |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 626 | addPropertyToPresentationAttributeStyle(style, CSSPropertyFloat, floatValue); |
zimmermann@webkit.org | fcd8b3c | 2008-12-11 23:42:12 +0000 | [diff] [blame] | 627 | |
| 628 | if (verticalAlignValue != CSSValueInvalid) |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 629 | addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, verticalAlignValue); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 630 | } |
| 631 | |
yosin@chromium.org | 77701e6 | 2012-08-28 05:41:50 +0000 | [diff] [blame] | 632 | bool HTMLElement::hasCustomFocusLogic() const |
| 633 | { |
| 634 | return false; |
| 635 | } |
| 636 | |
abarth@webkit.org | 4093379 | 2009-09-07 05:10:12 +0000 | [diff] [blame] | 637 | bool HTMLElement::supportsFocus() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 638 | { |
antti@apple.com | f02be1e | 2013-12-21 18:51:04 +0000 | [diff] [blame] | 639 | return Element::supportsFocus() || (hasEditableStyle() && parentNode() && !parentNode()->hasEditableStyle()); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 640 | } |
| 641 | |
commit-queue@webkit.org | 595681f | 2011-03-25 16:21:30 +0000 | [diff] [blame] | 642 | String HTMLElement::contentEditable() const |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 643 | { |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 644 | switch (contentEditableType(*this)) { |
| 645 | case ContentEditableType::Inherit: |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 646 | return ASCIILiteral("inherit"); |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 647 | case ContentEditableType::True: |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 648 | return ASCIILiteral("true"); |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 649 | case ContentEditableType::False: |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 650 | return ASCIILiteral("false"); |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 651 | case ContentEditableType::PlaintextOnly: |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 652 | return ASCIILiteral("plaintext-only"); |
benjamin@webkit.org | ec64455 | 2014-09-09 21:03:29 +0000 | [diff] [blame] | 653 | } |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 654 | return ASCIILiteral("inherit"); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 655 | } |
| 656 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 657 | ExceptionOr<void> HTMLElement::setContentEditable(const String& enabled) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 658 | { |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 659 | if (equalLettersIgnoringASCIICase(enabled, "true")) |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 660 | setAttributeWithoutSynchronization(contenteditableAttr, AtomicString("true", AtomicString::ConstructFromLiteral)); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 661 | else if (equalLettersIgnoringASCIICase(enabled, "false")) |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 662 | setAttributeWithoutSynchronization(contenteditableAttr, AtomicString("false", AtomicString::ConstructFromLiteral)); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 663 | else if (equalLettersIgnoringASCIICase(enabled, "plaintext-only")) |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 664 | setAttributeWithoutSynchronization(contenteditableAttr, AtomicString("plaintext-only", AtomicString::ConstructFromLiteral)); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 665 | else if (equalLettersIgnoringASCIICase(enabled, "inherit")) |
adamk@chromium.org | 05ffa33 | 2011-12-21 01:32:54 +0000 | [diff] [blame] | 666 | removeAttribute(contenteditableAttr); |
commit-queue@webkit.org | 290528b | 2012-08-22 01:42:43 +0000 | [diff] [blame] | 667 | else |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 668 | return Exception { SYNTAX_ERR }; |
| 669 | return { }; |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 670 | } |
| 671 | |
darin@apple.com | 2fbab98 | 2009-07-14 01:04:19 +0000 | [diff] [blame] | 672 | bool HTMLElement::draggable() const |
| 673 | { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 674 | return equalLettersIgnoringASCIICase(attributeWithoutSynchronization(draggableAttr), "true"); |
darin@apple.com | 2fbab98 | 2009-07-14 01:04:19 +0000 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | void HTMLElement::setDraggable(bool value) |
| 678 | { |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 679 | setAttributeWithoutSynchronization(draggableAttr, value |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 680 | ? AtomicString("true", AtomicString::ConstructFromLiteral) |
| 681 | : AtomicString("false", AtomicString::ConstructFromLiteral)); |
darin@apple.com | 2fbab98 | 2009-07-14 01:04:19 +0000 | [diff] [blame] | 682 | } |
| 683 | |
morrita@google.com | d165d1d | 2010-10-28 10:41:58 +0000 | [diff] [blame] | 684 | bool HTMLElement::spellcheck() const |
| 685 | { |
| 686 | return isSpellCheckingEnabled(); |
| 687 | } |
| 688 | |
| 689 | void HTMLElement::setSpellcheck(bool enable) |
| 690 | { |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 691 | setAttributeWithoutSynchronization(spellcheckAttr, enable |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 692 | ? AtomicString("true", AtomicString::ConstructFromLiteral) |
| 693 | : AtomicString("false", AtomicString::ConstructFromLiteral)); |
morrita@google.com | d165d1d | 2010-10-28 10:41:58 +0000 | [diff] [blame] | 694 | } |
| 695 | |
darin | f1bb004 | 2006-12-01 22:46:21 +0000 | [diff] [blame] | 696 | void HTMLElement::click() |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 697 | { |
cdumez@apple.com | 16b46d7 | 2016-10-19 17:46:42 +0000 | [diff] [blame] | 698 | simulateClick(*this, nullptr, SendNoEvents, DoNotShowPressedLook, SimulatedClickSource::Bindings); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 699 | } |
| 700 | |
commit-queue@webkit.org | 5bc308c | 2011-11-18 21:19:14 +0000 | [diff] [blame] | 701 | void HTMLElement::accessKeyAction(bool sendMouseEvents) |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 702 | { |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 703 | dispatchSimulatedClick(nullptr, sendMouseEvents ? SendMouseUpDownEvents : SendNoEvents); |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 704 | } |
| 705 | |
eseidel | 95944d2 | 2007-02-05 11:21:15 +0000 | [diff] [blame] | 706 | String HTMLElement::title() const |
| 707 | { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 708 | return attributeWithoutSynchronization(titleAttr); |
eseidel | 95944d2 | 2007-02-05 11:21:15 +0000 | [diff] [blame] | 709 | } |
| 710 | |
cdumez@apple.com | 825cfbb | 2016-03-08 06:38:10 +0000 | [diff] [blame] | 711 | int HTMLElement::tabIndex() const |
alice.liu@apple.com | 8648482 | 2008-04-29 01:18:52 +0000 | [diff] [blame] | 712 | { |
| 713 | if (supportsFocus()) |
| 714 | return Element::tabIndex(); |
| 715 | return -1; |
| 716 | } |
| 717 | |
commit-queue@webkit.org | 22bfed6 | 2012-02-16 05:42:02 +0000 | [diff] [blame] | 718 | bool HTMLElement::translate() const |
| 719 | { |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 720 | for (auto& element : lineageOfType<HTMLElement>(*this)) { |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 721 | const AtomicString& value = element.attributeWithoutSynchronization(translateAttr); |
| 722 | if (equalLettersIgnoringASCIICase(value, "yes") || (value.isEmpty() && !value.isNull())) |
| 723 | return true; |
| 724 | if (equalLettersIgnoringASCIICase(value, "no")) |
| 725 | return false; |
commit-queue@webkit.org | 22bfed6 | 2012-02-16 05:42:02 +0000 | [diff] [blame] | 726 | } |
commit-queue@webkit.org | 22bfed6 | 2012-02-16 05:42:02 +0000 | [diff] [blame] | 727 | // Default on the root element is translate=yes. |
| 728 | return true; |
| 729 | } |
| 730 | |
| 731 | void HTMLElement::setTranslate(bool enable) |
| 732 | { |
cdumez@apple.com | 3605922 | 2016-07-15 21:35:40 +0000 | [diff] [blame] | 733 | setAttributeWithoutSynchronization(translateAttr, enable ? "yes" : "no"); |
commit-queue@webkit.org | 22bfed6 | 2012-02-16 05:42:02 +0000 | [diff] [blame] | 734 | } |
| 735 | |
antti@apple.com | b74dfb6 | 2013-08-20 21:22:53 +0000 | [diff] [blame] | 736 | bool HTMLElement::rendererIsNeeded(const RenderStyle& style) |
antti | abbddd2 | 2007-09-19 09:45:13 +0000 | [diff] [blame] | 737 | { |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 738 | if (hasTagName(noscriptTag)) { |
akling@apple.com | 622b1a4 | 2013-08-30 14:30:12 +0000 | [diff] [blame] | 739 | Frame* frame = document().frame(); |
psolanki@apple.com | c5b5dad | 2013-08-16 17:55:32 +0000 | [diff] [blame] | 740 | if (frame && frame->script().canExecuteScripts(NotAboutToExecuteScript)) |
antti | abbddd2 | 2007-09-19 09:45:13 +0000 | [diff] [blame] | 741 | return false; |
darin@apple.com | 15708b1 | 2014-03-16 16:38:58 +0000 | [diff] [blame] | 742 | } else if (hasTagName(noembedTag)) { |
akling@apple.com | 622b1a4 | 2013-08-30 14:30:12 +0000 | [diff] [blame] | 743 | Frame* frame = document().frame(); |
andersca@apple.com | 0ea9a03 | 2015-08-04 21:41:02 +0000 | [diff] [blame] | 744 | if (frame && frame->loader().subframeLoader().allowPlugins()) |
abarth@webkit.org | bb9d1af | 2010-08-07 01:56:07 +0000 | [diff] [blame] | 745 | return false; |
| 746 | } |
antti@apple.com | b74dfb6 | 2013-08-20 21:22:53 +0000 | [diff] [blame] | 747 | return StyledElement::rendererIsNeeded(style); |
antti | abbddd2 | 2007-09-19 09:45:13 +0000 | [diff] [blame] | 748 | } |
abarth@webkit.org | bb9d1af | 2010-08-07 01:56:07 +0000 | [diff] [blame] | 749 | |
antti@apple.com | 454418f | 2016-04-25 19:49:23 +0000 | [diff] [blame] | 750 | RenderPtr<RenderElement> HTMLElement::createElementRenderer(RenderStyle&& style, const RenderTreePosition&) |
darin | 55ae73e | 2007-05-11 15:47:28 +0000 | [diff] [blame] | 751 | { |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 752 | return RenderElement::createFor(*this, WTFMove(style)); |
darin | 55ae73e | 2007-05-11 15:47:28 +0000 | [diff] [blame] | 753 | } |
| 754 | |
darin | 9efc76e | 2007-05-29 17:41:17 +0000 | [diff] [blame] | 755 | HTMLFormElement* HTMLElement::virtualForm() const |
| 756 | { |
rniwa@webkit.org | f7bf376 | 2013-08-29 01:35:21 +0000 | [diff] [blame] | 757 | return HTMLFormElement::findClosestFormAncestor(*this); |
darin | 9efc76e | 2007-05-29 17:41:17 +0000 | [diff] [blame] | 758 | } |
| 759 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 760 | static inline bool elementAffectsDirectionality(const Node& node) |
rniwa@webkit.org | 00fa4f3 | 2012-03-22 01:08:22 +0000 | [diff] [blame] | 761 | { |
cdumez@apple.com | cd13153 | 2014-09-27 01:32:34 +0000 | [diff] [blame] | 762 | if (!is<HTMLElement>(node)) |
| 763 | return false; |
| 764 | const HTMLElement& element = downcast<HTMLElement>(node); |
rniwa@webkit.org | bda54a0 | 2016-07-18 00:39:37 +0000 | [diff] [blame] | 765 | return is<HTMLBDIElement>(element) || element.hasAttributeWithoutSynchronization(dirAttr); |
rniwa@webkit.org | 00fa4f3 | 2012-03-22 01:08:22 +0000 | [diff] [blame] | 766 | } |
| 767 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 768 | static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastNode = nullptr) |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 769 | { |
| 770 | firstNode->setSelfOrAncestorHasDirAutoAttribute(flag); |
| 771 | |
| 772 | Node* node = firstNode->firstChild(); |
| 773 | |
| 774 | while (node) { |
| 775 | if (node->selfOrAncestorHasDirAutoAttribute() == flag) |
| 776 | return; |
| 777 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 778 | if (elementAffectsDirectionality(*node)) { |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 779 | if (node == lastNode) |
| 780 | return; |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 781 | node = NodeTraversal::nextSkippingChildren(*node, firstNode); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 782 | continue; |
| 783 | } |
| 784 | node->setSelfOrAncestorHasDirAutoAttribute(flag); |
| 785 | if (node == lastNode) |
| 786 | return; |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 787 | node = NodeTraversal::next(*node, firstNode); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 788 | } |
| 789 | } |
| 790 | |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 791 | void HTMLElement::childrenChanged(const ChildChange& change) |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 792 | { |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 793 | StyledElement::childrenChanged(change); |
| 794 | adjustDirectionalityIfNeededAfterChildrenChanged(change.previousSiblingElement, change.type); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 795 | } |
| 796 | |
rniwa@webkit.org | 00fa4f3 | 2012-03-22 01:08:22 +0000 | [diff] [blame] | 797 | bool HTMLElement::hasDirectionAuto() const |
| 798 | { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 799 | const AtomicString& direction = attributeWithoutSynchronization(dirAttr); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 800 | return (hasTagName(bdiTag) && direction.isNull()) || equalLettersIgnoringASCIICase(direction, "auto"); |
rniwa@webkit.org | 00fa4f3 | 2012-03-22 01:08:22 +0000 | [diff] [blame] | 801 | } |
| 802 | |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 803 | TextDirection HTMLElement::directionalityIfhasDirAutoAttribute(bool& isAuto) const |
| 804 | { |
rniwa@webkit.org | 00fa4f3 | 2012-03-22 01:08:22 +0000 | [diff] [blame] | 805 | if (!(selfOrAncestorHasDirAutoAttribute() && hasDirectionAuto())) { |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 806 | isAuto = false; |
| 807 | return LTR; |
| 808 | } |
| 809 | |
| 810 | isAuto = true; |
| 811 | return directionality(); |
| 812 | } |
| 813 | |
| 814 | TextDirection HTMLElement::directionality(Node** strongDirectionalityTextNode) const |
| 815 | { |
cdumez@apple.com | cd13153 | 2014-09-27 01:32:34 +0000 | [diff] [blame] | 816 | if (is<HTMLTextFormControlElement>(*this)) { |
| 817 | HTMLTextFormControlElement& textElement = downcast<HTMLTextFormControlElement>(const_cast<HTMLElement&>(*this)); |
yael.aharon@nokia.com | 0a5d0e5 | 2011-08-05 14:36:33 +0000 | [diff] [blame] | 818 | bool hasStrongDirectionality; |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 819 | UCharDirection textDirection = textElement.value().defaultWritingDirection(&hasStrongDirectionality); |
tkent@chromium.org | 400caab | 2011-10-22 10:53:41 +0000 | [diff] [blame] | 820 | if (strongDirectionalityTextNode) |
cdumez@apple.com | 72754ba | 2014-09-23 22:03:15 +0000 | [diff] [blame] | 821 | *strongDirectionalityTextNode = hasStrongDirectionality ? &textElement : nullptr; |
darin@apple.com | 2eb5f4d | 2013-10-12 04:16:42 +0000 | [diff] [blame] | 822 | return (textDirection == U_LEFT_TO_RIGHT) ? LTR : RTL; |
yael.aharon@nokia.com | 0a5d0e5 | 2011-08-05 14:36:33 +0000 | [diff] [blame] | 823 | } |
| 824 | |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 825 | Node* node = firstChild(); |
| 826 | while (node) { |
yael.aharon@nokia.com | 0a5d0e5 | 2011-08-05 14:36:33 +0000 | [diff] [blame] | 827 | // Skip bdi, script, style and text form controls. |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 828 | if (equalLettersIgnoringASCIICase(node->nodeName(), "bdi") || node->hasTagName(scriptTag) || node->hasTagName(styleTag) |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 829 | || (is<Element>(*node) && downcast<Element>(*node).isTextFormControl())) { |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 830 | node = NodeTraversal::nextSkippingChildren(*node, this); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 831 | continue; |
| 832 | } |
| 833 | |
| 834 | // Skip elements with valid dir attribute |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 835 | if (is<Element>(*node)) { |
rniwa@webkit.org | e999a05 | 2016-07-16 15:21:55 +0000 | [diff] [blame] | 836 | AtomicString dirAttributeValue = downcast<Element>(*node).attributeWithoutSynchronization(dirAttr); |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 837 | if (isLTROrRTLIgnoringCase(dirAttributeValue) || equalLettersIgnoringASCIICase(dirAttributeValue, "auto")) { |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 838 | node = NodeTraversal::nextSkippingChildren(*node, this); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 839 | continue; |
| 840 | } |
| 841 | } |
| 842 | |
| 843 | if (node->isTextNode()) { |
| 844 | bool hasStrongDirectionality; |
darin@apple.com | 2eb5f4d | 2013-10-12 04:16:42 +0000 | [diff] [blame] | 845 | UCharDirection textDirection = node->textContent(true).defaultWritingDirection(&hasStrongDirectionality); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 846 | if (hasStrongDirectionality) { |
| 847 | if (strongDirectionalityTextNode) |
| 848 | *strongDirectionalityTextNode = node; |
darin@apple.com | 2eb5f4d | 2013-10-12 04:16:42 +0000 | [diff] [blame] | 849 | return (textDirection == U_LEFT_TO_RIGHT) ? LTR : RTL; |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 850 | } |
| 851 | } |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 852 | node = NodeTraversal::next(*node, this); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 853 | } |
| 854 | if (strongDirectionalityTextNode) |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 855 | *strongDirectionalityTextNode = nullptr; |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 856 | return LTR; |
| 857 | } |
| 858 | |
akling@apple.com | 43e9d04 | 2012-11-18 16:55:06 +0000 | [diff] [blame] | 859 | void HTMLElement::dirAttributeChanged(const AtomicString& value) |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 860 | { |
| 861 | Element* parent = parentElement(); |
| 862 | |
cdumez@apple.com | a9c60c9 | 2014-10-02 19:39:41 +0000 | [diff] [blame] | 863 | if (is<HTMLElement>(parent) && parent->selfOrAncestorHasDirAutoAttribute()) |
cdumez@apple.com | cd13153 | 2014-09-27 01:32:34 +0000 | [diff] [blame] | 864 | downcast<HTMLElement>(*parent).adjustDirectionalityIfNeededAfterChildAttributeChanged(this); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 865 | |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 866 | if (equalLettersIgnoringASCIICase(value, "auto")) |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 867 | calculateAndAdjustDirectionality(); |
| 868 | } |
| 869 | |
| 870 | void HTMLElement::adjustDirectionalityIfNeededAfterChildAttributeChanged(Element* child) |
| 871 | { |
| 872 | ASSERT(selfOrAncestorHasDirAutoAttribute()); |
| 873 | Node* strongDirectionalityTextNode; |
| 874 | TextDirection textDirection = directionality(&strongDirectionalityTextNode); |
| 875 | setHasDirAutoFlagRecursively(child, false); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 876 | if (!renderer() || renderer()->style().direction() == textDirection) |
antti@apple.com | 08281fa | 2013-09-01 10:33:08 +0000 | [diff] [blame] | 877 | return; |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 878 | for (auto& elementToAdjust : elementLineage(this)) { |
| 879 | if (elementAffectsDirectionality(elementToAdjust)) { |
antti@apple.com | 1c45583 | 2016-10-18 12:28:55 +0000 | [diff] [blame] | 880 | elementToAdjust.invalidateStyleForSubtree(); |
antti@apple.com | 08281fa | 2013-09-01 10:33:08 +0000 | [diff] [blame] | 881 | return; |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
| 886 | void HTMLElement::calculateAndAdjustDirectionality() |
| 887 | { |
| 888 | Node* strongDirectionalityTextNode; |
| 889 | TextDirection textDirection = directionality(&strongDirectionalityTextNode); |
| 890 | setHasDirAutoFlagRecursively(this, true, strongDirectionalityTextNode); |
akling@apple.com | 827be9c | 2013-10-29 02:58:43 +0000 | [diff] [blame] | 891 | if (renderer() && renderer()->style().direction() != textDirection) |
antti@apple.com | 1c45583 | 2016-10-18 12:28:55 +0000 | [diff] [blame] | 892 | invalidateStyleForSubtree(); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 893 | } |
| 894 | |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 895 | void HTMLElement::adjustDirectionalityIfNeededAfterChildrenChanged(Element* beforeChange, ChildChangeType changeType) |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 896 | { |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 897 | // FIXME: This function looks suspicious. |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 898 | |
| 899 | if (!selfOrAncestorHasDirAutoAttribute()) |
| 900 | return; |
| 901 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 902 | Node* oldMarkedNode = nullptr; |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 903 | if (beforeChange) |
cdumez@apple.com | b7f4850 | 2015-01-26 22:36:36 +0000 | [diff] [blame] | 904 | oldMarkedNode = changeType == ElementInserted ? ElementTraversal::nextSibling(*beforeChange) : beforeChange->nextSibling(); |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 905 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 906 | while (oldMarkedNode && elementAffectsDirectionality(*oldMarkedNode)) |
antti@apple.com | 1acee92 | 2013-09-02 15:17:50 +0000 | [diff] [blame] | 907 | oldMarkedNode = oldMarkedNode->nextSibling(); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 908 | if (oldMarkedNode) |
| 909 | setHasDirAutoFlagRecursively(oldMarkedNode, false); |
| 910 | |
weinig@apple.com | c77041e | 2013-12-14 18:05:45 +0000 | [diff] [blame] | 911 | for (auto& elementToAdjust : lineageOfType<HTMLElement>(*this)) { |
| 912 | if (elementAffectsDirectionality(elementToAdjust)) { |
| 913 | elementToAdjust.calculateAndAdjustDirectionality(); |
yael.aharon@nokia.com | c542de5 | 2011-02-18 21:28:32 +0000 | [diff] [blame] | 914 | return; |
| 915 | } |
| 916 | } |
| 917 | } |
| 918 | |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 919 | void HTMLElement::addHTMLLengthToStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& value) |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 920 | { |
| 921 | // FIXME: This function should not spin up the CSS parser, but should instead just figure out the correct |
| 922 | // length unit and make the appropriate parsed value. |
| 923 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 924 | if (StringImpl* string = value.impl()) { |
| 925 | unsigned parsedLength = 0; |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 926 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 927 | while (parsedLength < string->length() && (*string)[parsedLength] <= ' ') |
| 928 | ++parsedLength; |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 929 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 930 | for (; parsedLength < string->length(); ++parsedLength) { |
| 931 | UChar cc = (*string)[parsedLength]; |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 932 | if (cc > '9') |
| 933 | break; |
| 934 | if (cc < '0') { |
| 935 | if (cc == '%' || cc == '*') |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 936 | ++parsedLength; |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 937 | if (cc != '.') |
| 938 | break; |
| 939 | } |
| 940 | } |
| 941 | |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 942 | if (parsedLength != string->length()) { |
| 943 | addPropertyToPresentationAttributeStyle(style, propertyID, string->substring(0, parsedLength)); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 944 | return; |
| 945 | } |
| 946 | } |
| 947 | |
kling@webkit.org | 569556d | 2012-11-12 23:52:12 +0000 | [diff] [blame] | 948 | addPropertyToPresentationAttributeStyle(style, propertyID, value); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 949 | } |
| 950 | |
kling@webkit.org | c92997c | 2012-02-23 01:40:12 +0000 | [diff] [blame] | 951 | static RGBA32 parseColorStringWithCrazyLegacyRules(const String& colorString) |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 952 | { |
| 953 | // Per spec, only look at the first 128 digits of the string. |
| 954 | const size_t maxColorLength = 128; |
| 955 | // We'll pad the buffer with two extra 0s later, so reserve two more than the max. |
| 956 | Vector<char, maxColorLength+2> digitBuffer; |
| 957 | |
| 958 | size_t i = 0; |
| 959 | // Skip a leading #. |
| 960 | if (colorString[0] == '#') |
| 961 | i = 1; |
| 962 | |
| 963 | // Grab the first 128 characters, replacing non-hex characters with 0. |
| 964 | // Non-BMP characters are replaced with "00" due to them appearing as two "characters" in the String. |
| 965 | for (; i < colorString.length() && digitBuffer.size() < maxColorLength; i++) { |
| 966 | if (!isASCIIHexDigit(colorString[i])) |
| 967 | digitBuffer.append('0'); |
| 968 | else |
| 969 | digitBuffer.append(colorString[i]); |
| 970 | } |
| 971 | |
| 972 | if (!digitBuffer.size()) |
kling@webkit.org | c92997c | 2012-02-23 01:40:12 +0000 | [diff] [blame] | 973 | return Color::black; |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 974 | |
| 975 | // Pad the buffer out to at least the next multiple of three in size. |
| 976 | digitBuffer.append('0'); |
| 977 | digitBuffer.append('0'); |
| 978 | |
| 979 | if (digitBuffer.size() < 6) |
kling@webkit.org | c92997c | 2012-02-23 01:40:12 +0000 | [diff] [blame] | 980 | return makeRGB(toASCIIHexValue(digitBuffer[0]), toASCIIHexValue(digitBuffer[1]), toASCIIHexValue(digitBuffer[2])); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 981 | |
| 982 | // Split the digits into three components, then search the last 8 digits of each component. |
| 983 | ASSERT(digitBuffer.size() >= 6); |
| 984 | size_t componentLength = digitBuffer.size() / 3; |
andersca@apple.com | ff9adb8 | 2013-10-25 01:15:36 +0000 | [diff] [blame] | 985 | size_t componentSearchWindowLength = std::min<size_t>(componentLength, 8); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 986 | size_t redIndex = componentLength - componentSearchWindowLength; |
| 987 | size_t greenIndex = componentLength * 2 - componentSearchWindowLength; |
| 988 | size_t blueIndex = componentLength * 3 - componentSearchWindowLength; |
| 989 | // Skip digits until one of them is non-zero, or we've only got two digits left in the component. |
| 990 | while (digitBuffer[redIndex] == '0' && digitBuffer[greenIndex] == '0' && digitBuffer[blueIndex] == '0' && (componentLength - redIndex) > 2) { |
| 991 | redIndex++; |
| 992 | greenIndex++; |
| 993 | blueIndex++; |
| 994 | } |
| 995 | ASSERT(redIndex + 1 < componentLength); |
| 996 | ASSERT(greenIndex >= componentLength); |
| 997 | ASSERT(greenIndex + 1 < componentLength * 2); |
| 998 | ASSERT(blueIndex >= componentLength * 2); |
inferno@chromium.org | a227be6 | 2013-02-11 08:06:45 +0000 | [diff] [blame] | 999 | ASSERT_WITH_SECURITY_IMPLICATION(blueIndex + 1 < digitBuffer.size()); |
kling@webkit.org | c92997c | 2012-02-23 01:40:12 +0000 | [diff] [blame] | 1000 | |
| 1001 | int redValue = toASCIIHexValue(digitBuffer[redIndex], digitBuffer[redIndex + 1]); |
| 1002 | int greenValue = toASCIIHexValue(digitBuffer[greenIndex], digitBuffer[greenIndex + 1]); |
| 1003 | int blueValue = toASCIIHexValue(digitBuffer[blueIndex], digitBuffer[blueIndex + 1]); |
| 1004 | return makeRGB(redValue, greenValue, blueValue); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 1005 | } |
| 1006 | |
| 1007 | // Color parsing that matches HTML's "rules for parsing a legacy color value" |
antti@apple.com | e5428c5 | 2013-11-28 20:53:22 +0000 | [diff] [blame] | 1008 | void HTMLElement::addHTMLColorToStyle(MutableStyleProperties& style, CSSPropertyID propertyID, const String& attributeValue) |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 1009 | { |
| 1010 | // An empty string doesn't apply a color. (One containing only whitespace does, which is why this check occurs before stripping.) |
| 1011 | if (attributeValue.isEmpty()) |
| 1012 | return; |
| 1013 | |
| 1014 | String colorString = attributeValue.stripWhiteSpace(); |
| 1015 | |
| 1016 | // "transparent" doesn't apply a color either. |
darin@apple.com | 048cc3a | 2016-01-22 17:17:04 +0000 | [diff] [blame] | 1017 | if (equalLettersIgnoringASCIICase(colorString, "transparent")) |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 1018 | return; |
| 1019 | |
dino@apple.com | 2e87e37 | 2016-05-06 01:26:26 +0000 | [diff] [blame] | 1020 | Color color; |
dino@apple.com | 5401765 | 2016-10-18 00:12:00 +0000 | [diff] [blame] | 1021 | // We can't always use the default Color constructor because it accepts |
| 1022 | // 4/8-digit hex, which conflict with some legacy HTML content using attributes. |
| 1023 | if ((colorString.length() != 5 && colorString.length() != 9) || colorString[0] != '#') |
dino@apple.com | 2e87e37 | 2016-05-06 01:26:26 +0000 | [diff] [blame] | 1024 | color = Color(colorString); |
| 1025 | if (!color.isValid()) |
dino@apple.com | 5401765 | 2016-10-18 00:12:00 +0000 | [diff] [blame] | 1026 | color = Color(parseColorStringWithCrazyLegacyRules(colorString)); |
dino@apple.com | 2e87e37 | 2016-05-06 01:26:26 +0000 | [diff] [blame] | 1027 | |
| 1028 | style.setProperty(propertyID, CSSValuePool::singleton().createColorValue(color.rgb())); |
kling@webkit.org | 8b0e843 | 2012-02-11 19:29:49 +0000 | [diff] [blame] | 1029 | } |
| 1030 | |
dbates@webkit.org | 1edd81d | 2013-12-18 00:15:02 +0000 | [diff] [blame] | 1031 | bool HTMLElement::willRespondToMouseMoveEvents() |
| 1032 | { |
| 1033 | return !isDisabledFormControl() && Element::willRespondToMouseMoveEvents(); |
| 1034 | } |
| 1035 | |
| 1036 | bool HTMLElement::willRespondToMouseWheelEvents() |
| 1037 | { |
| 1038 | return !isDisabledFormControl() && Element::willRespondToMouseWheelEvents(); |
| 1039 | } |
| 1040 | |
| 1041 | bool HTMLElement::willRespondToMouseClickEvents() |
| 1042 | { |
| 1043 | return !isDisabledFormControl() && Element::willRespondToMouseClickEvents(); |
| 1044 | } |
| 1045 | |
akling@apple.com | 4d48f41 | 2016-08-26 21:46:07 +0000 | [diff] [blame] | 1046 | bool HTMLElement::canBeActuallyDisabled() const |
| 1047 | { |
| 1048 | return is<HTMLButtonElement>(*this) |
| 1049 | || is<HTMLInputElement>(*this) |
| 1050 | || is<HTMLSelectElement>(*this) |
| 1051 | || is<HTMLTextAreaElement>(*this) |
| 1052 | || is<HTMLOptGroupElement>(*this) |
| 1053 | || is<HTMLOptionElement>(*this) |
| 1054 | || is<HTMLFieldSetElement>(*this); |
| 1055 | } |
| 1056 | |
| 1057 | bool HTMLElement::isActuallyDisabled() const |
| 1058 | { |
| 1059 | return canBeActuallyDisabled() && isDisabledFormControl(); |
| 1060 | } |
| 1061 | |
wenson_hsieh@apple.com | a8fbaa4 | 2016-11-12 00:20:00 +0000 | [diff] [blame] | 1062 | #if ENABLE(IOS_AUTOCORRECT_AND_AUTOCAPITALIZE) |
| 1063 | |
| 1064 | const AtomicString& HTMLElement::autocapitalize() const |
| 1065 | { |
| 1066 | return stringForAutocapitalizeType(autocapitalizeType()); |
| 1067 | } |
| 1068 | |
| 1069 | AutocapitalizeType HTMLElement::autocapitalizeType() const |
| 1070 | { |
| 1071 | return autocapitalizeTypeForAttributeValue(attributeWithoutSynchronization(HTMLNames::autocapitalizeAttr)); |
| 1072 | } |
| 1073 | |
| 1074 | void HTMLElement::setAutocapitalize(const AtomicString& value) |
| 1075 | { |
| 1076 | setAttributeWithoutSynchronization(autocapitalizeAttr, value); |
| 1077 | } |
| 1078 | |
| 1079 | bool HTMLElement::shouldAutocorrect() const |
| 1080 | { |
| 1081 | auto autocorrectValue = attributeWithoutSynchronization(HTMLNames::autocorrectAttr); |
| 1082 | // Unrecognized values fall back to "on". |
| 1083 | return !equalLettersIgnoringASCIICase(autocorrectValue, "off"); |
| 1084 | } |
| 1085 | |
| 1086 | void HTMLElement::setAutocorrect(bool autocorrect) |
| 1087 | { |
| 1088 | setAttributeWithoutSynchronization(autocorrectAttr, autocorrect ? AtomicString("on", AtomicString::ConstructFromLiteral) : AtomicString("off", AtomicString::ConstructFromLiteral)); |
| 1089 | } |
| 1090 | |
| 1091 | #endif |
| 1092 | |
weinig | 3975ff6 | 2007-05-28 19:38:29 +0000 | [diff] [blame] | 1093 | } // namespace WebCore |
ggaren | 007c656 | 2007-06-21 02:46:18 +0000 | [diff] [blame] | 1094 | |
| 1095 | #ifndef NDEBUG |
andersca@apple.com | 3c1e6d9 | 2009-01-23 20:50:59 +0000 | [diff] [blame] | 1096 | |
| 1097 | // For use in the debugger |
andersca@apple.com | d8dda09 | 2009-01-23 19:52:19 +0000 | [diff] [blame] | 1098 | void dumpInnerHTML(WebCore::HTMLElement*); |
| 1099 | |
ggaren | 007c656 | 2007-06-21 02:46:18 +0000 | [diff] [blame] | 1100 | void dumpInnerHTML(WebCore::HTMLElement* element) |
| 1101 | { |
| 1102 | printf("%s\n", element->innerHTML().ascii().data()); |
| 1103 | } |
darin@apple.com | d8db087 | 2013-10-11 15:07:12 +0000 | [diff] [blame] | 1104 | |
ggaren | 007c656 | 2007-06-21 02:46:18 +0000 | [diff] [blame] | 1105 | #endif |