| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2013 Apple Inc. All rights reserv
ed. | 4 * Copyright (C) 2004-2008, 2013, 2014 Apple Inc. All rights reserved. |
| 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) | 5 * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmo
bile.com/) |
| 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. | 6 * Copyright (C) 2011 Motorola Mobility. All rights reserved. |
| 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 |
| 11 * version 2 of the License, or (at your option) any later version. | 11 * version 2 of the License, or (at your option) any later version. |
| 12 * | 12 * |
| 13 * This library is distributed in the hope that it will be useful, | 13 * This library is distributed in the hope that it will be useful, |
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 | 83 |
| 84 bool HTMLElement::ieForbidsInsertHTML() const | 84 bool HTMLElement::ieForbidsInsertHTML() const |
| 85 { | 85 { |
| 86 // FIXME: Supposedly IE disallows settting innerHTML, outerHTML | 86 // FIXME: Supposedly IE disallows settting innerHTML, outerHTML |
| 87 // and createContextualFragment on these tags. We have no tests to | 87 // and createContextualFragment on these tags. We have no tests to |
| 88 // verify this however, so this list could be totally wrong. | 88 // verify this however, so this list could be totally wrong. |
| 89 // This list was moved from the previous endTagRequirement() implementation. | 89 // This list was moved from the previous endTagRequirement() implementation. |
| 90 // This is also called from editing and assumed to be the list of tags | 90 // This is also called from editing and assumed to be the list of tags |
| 91 // for which no end tag should be serialized. It's unclear if the list for | 91 // for which no end tag should be serialized. It's unclear if the list for |
| 92 // IE compat and the list for serialization sanity are the same. | 92 // IE compat and the list for serialization sanity are the same. |
| 93 if (hasLocalName(areaTag) | 93 if (hasTagName(areaTag) |
| 94 || hasLocalName(baseTag) | 94 || hasTagName(baseTag) |
| 95 || hasLocalName(basefontTag) | 95 || hasTagName(basefontTag) |
| 96 || hasLocalName(brTag) | 96 || hasTagName(brTag) |
| 97 || hasLocalName(colTag) | 97 || hasTagName(colTag) |
| 98 || hasLocalName(embedTag) | 98 || hasTagName(embedTag) |
| 99 || hasLocalName(frameTag) | 99 || hasTagName(frameTag) |
| 100 || hasLocalName(hrTag) | 100 || hasTagName(hrTag) |
| 101 || hasLocalName(imageTag) | 101 || hasTagName(imageTag) |
| 102 || hasLocalName(imgTag) | 102 || hasTagName(imgTag) |
| 103 || hasLocalName(inputTag) | 103 || hasTagName(inputTag) |
| 104 || hasLocalName(linkTag) | 104 || hasTagName(linkTag) |
| 105 || hasLocalName(metaTag) | 105 || hasTagName(metaTag) |
| 106 || hasLocalName(paramTag) | 106 || hasTagName(paramTag) |
| 107 || hasLocalName(sourceTag) | 107 || hasTagName(sourceTag) |
| 108 || hasLocalName(wbrTag)) | 108 || hasTagName(wbrTag)) |
| 109 return true; | 109 return true; |
| 110 return false; | 110 return false; |
| 111 } | 111 } |
| 112 | 112 |
| 113 static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement* element) | 113 static inline CSSValueID unicodeBidiAttributeForDirAuto(HTMLElement* element) |
| 114 { | 114 { |
| 115 if (element->hasLocalName(preTag) || element->hasLocalName(textareaTag)) | 115 if (element->hasTagName(preTag) || element->hasTagName(textareaTag)) |
| 116 return CSSValueWebkitPlaintext; | 116 return CSSValueWebkitPlaintext; |
| 117 // FIXME: For bdo element, dir="auto" should result in "bidi-override isolat
e" but we don't support having multiple values in unicode-bidi yet. | 117 // FIXME: For bdo element, dir="auto" should result in "bidi-override isolat
e" but we don't support having multiple values in unicode-bidi yet. |
| 118 // See https://bugs.webkit.org/show_bug.cgi?id=73164. | 118 // See https://bugs.webkit.org/show_bug.cgi?id=73164. |
| 119 return CSSValueWebkitIsolate; | 119 return CSSValueWebkitIsolate; |
| 120 } | 120 } |
| 121 | 121 |
| 122 unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const | 122 unsigned HTMLElement::parseBorderWidthAttribute(const AtomicString& value) const |
| 123 { | 123 { |
| 124 unsigned borderWidth = 0; | 124 unsigned borderWidth = 0; |
| 125 if (value.isEmpty() || !parseHTMLNonNegativeInteger(value, borderWidth)) | 125 if (value.isEmpty() || !parseHTMLNonNegativeInteger(value, borderWidth)) |
| 126 return hasLocalName(tableTag) ? 1 : borderWidth; | 126 return hasTagName(tableTag) ? 1 : borderWidth; |
| 127 return borderWidth; | 127 return borderWidth; |
| 128 } | 128 } |
| 129 | 129 |
| 130 void HTMLElement::applyBorderAttributeToStyle(const AtomicString& value, Mutable
StylePropertySet* style) | 130 void HTMLElement::applyBorderAttributeToStyle(const AtomicString& value, Mutable
StylePropertySet* style) |
| 131 { | 131 { |
| 132 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, parse
BorderWidthAttribute(value), CSSPrimitiveValue::CSS_PX); | 132 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderWidth, parse
BorderWidthAttribute(value), CSSPrimitiveValue::CSS_PX); |
| 133 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSVa
lueSolid); | 133 addPropertyToPresentationAttributeStyle(style, CSSPropertyBorderStyle, CSSVa
lueSolid); |
| 134 } | 134 } |
| 135 | 135 |
| 136 void HTMLElement::mapLanguageAttributeToLocale(const AtomicString& value, Mutabl
eStylePropertySet* style) | 136 void HTMLElement::mapLanguageAttributeToLocale(const AtomicString& value, Mutabl
eStylePropertySet* style) |
| (...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 if (c == '\r' && i + 1 < length && text[i + 1] == '\n') | 344 if (c == '\r' && i + 1 < length && text[i + 1] == '\n') |
| 345 i++; | 345 i++; |
| 346 } | 346 } |
| 347 | 347 |
| 348 start = i + 1; // Character after line break. | 348 start = i + 1; // Character after line break. |
| 349 } | 349 } |
| 350 | 350 |
| 351 return fragment; | 351 return fragment; |
| 352 } | 352 } |
| 353 | 353 |
| 354 static inline bool shouldProhibitSetInnerOuterText(const HTMLElement& element) |
| 355 { |
| 356 return element.hasTagName(colTag) |
| 357 || element.hasTagName(colgroupTag) |
| 358 || element.hasTagName(framesetTag) |
| 359 || element.hasTagName(headTag) |
| 360 || element.hasTagName(htmlTag) |
| 361 || element.hasTagName(tableTag) |
| 362 || element.hasTagName(tbodyTag) |
| 363 || element.hasTagName(tfootTag) |
| 364 || element.hasTagName(theadTag) |
| 365 || element.hasTagName(trTag); |
| 366 } |
| 367 |
| 354 void HTMLElement::setInnerText(const String& text, ExceptionState& exceptionStat
e) | 368 void HTMLElement::setInnerText(const String& text, ExceptionState& exceptionStat
e) |
| 355 { | 369 { |
| 356 if (ieForbidsInsertHTML()) { | 370 if (ieForbidsInsertHTML()) { |
| 357 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 371 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 358 return; | 372 return; |
| 359 } | 373 } |
| 360 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames
etTag) || | 374 if (shouldProhibitSetInnerOuterText(*this)) { |
| 361 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag)
|| | |
| 362 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa
g) || | |
| 363 hasLocalName(trTag)) { | |
| 364 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 375 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 365 return; | 376 return; |
| 366 } | 377 } |
| 367 | 378 |
| 368 // FIXME: This doesn't take whitespace collapsing into account at all. | 379 // FIXME: This doesn't take whitespace collapsing into account at all. |
| 369 | 380 |
| 370 if (!text.contains('\n') && !text.contains('\r')) { | 381 if (!text.contains('\n') && !text.contains('\r')) { |
| 371 if (text.isEmpty()) { | 382 if (text.isEmpty()) { |
| 372 removeChildren(); | 383 removeChildren(); |
| 373 return; | 384 return; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 391 replaceChildrenWithText(this, textWithConsistentLineBreaks, exceptionSta
te); | 402 replaceChildrenWithText(this, textWithConsistentLineBreaks, exceptionSta
te); |
| 392 return; | 403 return; |
| 393 } | 404 } |
| 394 | 405 |
| 395 // Add text nodes and <br> elements. | 406 // Add text nodes and <br> elements. |
| 396 RefPtrWillBeRawPtr<DocumentFragment> fragment = textToFragment(text, excepti
onState); | 407 RefPtrWillBeRawPtr<DocumentFragment> fragment = textToFragment(text, excepti
onState); |
| 397 if (!exceptionState.hadException()) | 408 if (!exceptionState.hadException()) |
| 398 replaceChildrenWithFragment(this, fragment.release(), exceptionState); | 409 replaceChildrenWithFragment(this, fragment.release(), exceptionState); |
| 399 } | 410 } |
| 400 | 411 |
| 401 void HTMLElement::setOuterText(const String &text, ExceptionState& exceptionStat
e) | 412 void HTMLElement::setOuterText(const String& text, ExceptionState& exceptionStat
e) |
| 402 { | 413 { |
| 403 if (ieForbidsInsertHTML()) { | 414 if (ieForbidsInsertHTML()) { |
| 404 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 415 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 405 return; | 416 return; |
| 406 } | 417 } |
| 407 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames
etTag) || | 418 if (shouldProhibitSetInnerOuterText(*this)) { |
| 408 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag)
|| | |
| 409 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa
g) || | |
| 410 hasLocalName(trTag)) { | |
| 411 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); | 419 exceptionState.throwDOMException(NoModificationAllowedError, "The '" + l
ocalName() + "' element does not support text insertion."); |
| 412 return; | 420 return; |
| 413 } | 421 } |
| 414 | 422 |
| 415 ContainerNode* parent = parentNode(); | 423 ContainerNode* parent = parentNode(); |
| 416 if (!parent) { | 424 if (!parent) { |
| 417 exceptionState.throwDOMException(NoModificationAllowedError, "The elemen
t has no parent."); | 425 exceptionState.throwDOMException(NoModificationAllowedError, "The elemen
t has no parent."); |
| 418 return; | 426 return; |
| 419 } | 427 } |
| 420 | 428 |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 620 setAttribute(dirAttr, value); | 628 setAttribute(dirAttr, value); |
| 621 } | 629 } |
| 622 | 630 |
| 623 HTMLFormElement* HTMLElement::findFormAncestor() const | 631 HTMLFormElement* HTMLElement::findFormAncestor() const |
| 624 { | 632 { |
| 625 return Traversal<HTMLFormElement>::firstAncestor(*this); | 633 return Traversal<HTMLFormElement>::firstAncestor(*this); |
| 626 } | 634 } |
| 627 | 635 |
| 628 static inline bool elementAffectsDirectionality(const Node* node) | 636 static inline bool elementAffectsDirectionality(const Node* node) |
| 629 { | 637 { |
| 630 return node->isHTMLElement() && (isHTMLBDIElement(*node) || toHTMLElement(no
de)->hasAttribute(dirAttr)); | 638 return node->isHTMLElement() && (isHTMLBDIElement(toHTMLElement(*node)) || t
oHTMLElement(*node).hasAttribute(dirAttr)); |
| 631 } | 639 } |
| 632 | 640 |
| 633 static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN
ode = 0) | 641 static void setHasDirAutoFlagRecursively(Node* firstNode, bool flag, Node* lastN
ode = 0) |
| 634 { | 642 { |
| 635 firstNode->setSelfOrAncestorHasDirAutoAttribute(flag); | 643 firstNode->setSelfOrAncestorHasDirAutoAttribute(flag); |
| 636 | 644 |
| 637 Node* node = firstNode->firstChild(); | 645 Node* node = firstNode->firstChild(); |
| 638 | 646 |
| 639 while (node) { | 647 while (node) { |
| 640 if (elementAffectsDirectionality(node)) { | 648 if (elementAffectsDirectionality(node)) { |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 950 #ifndef NDEBUG | 958 #ifndef NDEBUG |
| 951 | 959 |
| 952 // For use in the debugger | 960 // For use in the debugger |
| 953 void dumpInnerHTML(blink::HTMLElement*); | 961 void dumpInnerHTML(blink::HTMLElement*); |
| 954 | 962 |
| 955 void dumpInnerHTML(blink::HTMLElement* element) | 963 void dumpInnerHTML(blink::HTMLElement* element) |
| 956 { | 964 { |
| 957 printf("%s\n", element->innerHTML().ascii().data()); | 965 printf("%s\n", element->innerHTML().ascii().data()); |
| 958 } | 966 } |
| 959 #endif | 967 #endif |
| OLD | NEW |