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

Side by Side Diff: Source/core/html/HTMLElement.cpp

Issue 1186823007: Code cleanup in core/html/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/core/html/HTMLDocument.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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-2008, 2013, 2014 Apple Inc. All rights reserved. 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
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 #include "platform/text/BidiTextRun.h" 61 #include "platform/text/BidiTextRun.h"
62 #include "platform/text/TextRunIterator.h" 62 #include "platform/text/TextRunIterator.h"
63 #include "wtf/StdLibExtras.h" 63 #include "wtf/StdLibExtras.h"
64 #include "wtf/text/CString.h" 64 #include "wtf/text/CString.h"
65 65
66 namespace blink { 66 namespace blink {
67 67
68 using namespace HTMLNames; 68 using namespace HTMLNames;
69 using namespace WTF; 69 using namespace WTF;
70 70
71 using std::min; 71 using namespace std;
72 using std::max;
73 72
74 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement); 73 DEFINE_ELEMENT_FACTORY_WITH_TAGNAME(HTMLElement);
75 74
76 String HTMLElement::nodeName() const 75 String HTMLElement::nodeName() const
77 { 76 {
78 // FIXME: Would be nice to have an atomicstring lookup based off uppercase 77 // FIXME: Would be nice to have an atomicstring lookup based off uppercase
79 // chars that does not have to copy the string on a hit in the hash. 78 // chars that does not have to copy the string on a hit in the hash.
80 // FIXME: We should have a way to detect XHTML elements and replace the hasP refix() check with it. 79 // FIXME: We should have a way to detect XHTML elements and replace the hasP refix() check with it.
81 if (document().isHTMLDocument()) { 80 if (document().isHTMLDocument()) {
82 if (!tagQName().hasPrefix()) 81 if (!tagQName().hasPrefix())
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Modify, CSSValueReadOnly); 204 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Modify, CSSValueReadOnly);
206 } else if (name == hiddenAttr) { 205 } else if (name == hiddenAttr) {
207 addPropertyToPresentationAttributeStyle(style, CSSPropertyDisplay, CSSVa lueNone); 206 addPropertyToPresentationAttributeStyle(style, CSSPropertyDisplay, CSSVa lueNone);
208 } else if (name == draggableAttr) { 207 } else if (name == draggableAttr) {
209 if (equalIgnoringCase(value, "true")) { 208 if (equalIgnoringCase(value, "true")) {
210 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Drag, CSSValueElement); 209 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Drag, CSSValueElement);
211 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Select, CSSValueNone); 210 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Select, CSSValueNone);
212 } else if (equalIgnoringCase(value, "false")) 211 } else if (equalIgnoringCase(value, "false"))
213 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Drag, CSSValueNone); 212 addPropertyToPresentationAttributeStyle(style, CSSPropertyWebkitUser Drag, CSSValueNone);
214 } else if (name == dirAttr) { 213 } else if (name == dirAttr) {
215 if (equalIgnoringCase(value, "auto")) 214 if (equalIgnoringCase(value, "auto")) {
216 addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBid i, unicodeBidiAttributeForDirAuto(this)); 215 addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicodeBid i, unicodeBidiAttributeForDirAuto(this));
216 }
217 else { 217 else {
218 if (isValidDirAttribute(value)) 218 if (isValidDirAttribute(value))
219 addPropertyToPresentationAttributeStyle(style, CSSPropertyDirect ion, value); 219 addPropertyToPresentationAttributeStyle(style, CSSPropertyDirect ion, value);
220 else 220 else
221 addPropertyToPresentationAttributeStyle(style, CSSPropertyDirect ion, "ltr"); 221 addPropertyToPresentationAttributeStyle(style, CSSPropertyDirect ion, "ltr");
222 if (!hasTagName(bdiTag) && !hasTagName(bdoTag) && !hasTagName(output Tag)) 222 if (!hasTagName(bdiTag) && !hasTagName(bdoTag) && !hasTagName(output Tag))
223 addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicod eBidi, CSSValueEmbed); 223 addPropertyToPresentationAttributeStyle(style, CSSPropertyUnicod eBidi, CSSValueEmbed);
224 } 224 }
225 } else if (name.matches(XMLNames::langAttr)) 225 } else if (name.matches(XMLNames::langAttr)) {
226 mapLanguageAttributeToLocale(value, style); 226 mapLanguageAttributeToLocale(value, style);
227 else if (name == langAttr) { 227 } else if (name == langAttr) {
228 // xml:lang has a higher priority than lang. 228 // xml:lang has a higher priority than lang.
229 if (!fastHasAttribute(XMLNames::langAttr)) 229 if (!fastHasAttribute(XMLNames::langAttr))
230 mapLanguageAttributeToLocale(value, style); 230 mapLanguageAttributeToLocale(value, style);
231 } else 231 } else {
232 Element::collectStyleForPresentationAttribute(name, value, style); 232 Element::collectStyleForPresentationAttribute(name, value, style);
233 }
233 } 234 }
234 235
235 const AtomicString& HTMLElement::eventNameForAttributeName(const QualifiedName& attrName) 236 const AtomicString& HTMLElement::eventNameForAttributeName(const QualifiedName& attrName)
236 { 237 {
237 if (!attrName.namespaceURI().isNull()) 238 if (!attrName.namespaceURI().isNull())
238 return nullAtom; 239 return nullAtom;
239 240
240 if (!attrName.localName().startsWith("on", TextCaseInsensitive)) 241 if (!attrName.localName().startsWith("on", TextCaseInsensitive))
241 return nullAtom; 242 return nullAtom;
242 243
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 359
359 PassRefPtrWillBeRawPtr<DocumentFragment> HTMLElement::textToFragment(const Strin g& text, ExceptionState& exceptionState) 360 PassRefPtrWillBeRawPtr<DocumentFragment> HTMLElement::textToFragment(const Strin g& text, ExceptionState& exceptionState)
360 { 361 {
361 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(doc ument()); 362 RefPtrWillBeRawPtr<DocumentFragment> fragment = DocumentFragment::create(doc ument());
362 unsigned i, length = text.length(); 363 unsigned i, length = text.length();
363 UChar c = 0; 364 UChar c = 0;
364 for (unsigned start = 0; start < length; ) { 365 for (unsigned start = 0; start < length; ) {
365 366
366 // Find next line break. 367 // Find next line break.
367 for (i = start; i < length; i++) { 368 for (i = start; i < length; i++) {
368 c = text[i]; 369 c = text[i];
369 if (c == '\r' || c == '\n') 370 if (c == '\r' || c == '\n')
370 break; 371 break;
371 } 372 }
372 373
373 fragment->appendChild(Text::create(document(), text.substring(start, i - start)), exceptionState); 374 fragment->appendChild(Text::create(document(), text.substring(start, i - start)), exceptionState);
374 if (exceptionState.hadException()) 375 if (exceptionState.hadException())
375 return nullptr; 376 return nullptr;
376 377
377 if (c == '\r' || c == '\n') { 378 if (c == '\r' || c == '\n') {
378 fragment->appendChild(HTMLBRElement::create(document()), exceptionSt ate); 379 fragment->appendChild(HTMLBRElement::create(document()), exceptionSt ate);
379 if (exceptionState.hadException()) 380 if (exceptionState.hadException())
380 return nullptr; 381 return nullptr;
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 mergeWithNextTextNode(toText(prev.get()), exceptionState); 492 mergeWithNextTextNode(toText(prev.get()), exceptionState);
492 } 493 }
493 494
494 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style) 495 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style)
495 { 496 {
496 // Vertical alignment with respect to the current baseline of the text 497 // Vertical alignment with respect to the current baseline of the text
497 // right or left means floating images. 498 // right or left means floating images.
498 CSSValueID floatValue = CSSValueInvalid; 499 CSSValueID floatValue = CSSValueInvalid;
499 CSSValueID verticalAlignValue = CSSValueInvalid; 500 CSSValueID verticalAlignValue = CSSValueInvalid;
500 501
501 if (equalIgnoringCase(alignment, "absmiddle")) 502 if (equalIgnoringCase(alignment, "absmiddle")) {
502 verticalAlignValue = CSSValueMiddle; 503 verticalAlignValue = CSSValueMiddle;
503 else if (equalIgnoringCase(alignment, "absbottom")) 504 } else if (equalIgnoringCase(alignment, "absbottom")) {
504 verticalAlignValue = CSSValueBottom; 505 verticalAlignValue = CSSValueBottom;
505 else if (equalIgnoringCase(alignment, "left")) { 506 } else if (equalIgnoringCase(alignment, "left")) {
506 floatValue = CSSValueLeft; 507 floatValue = CSSValueLeft;
507 verticalAlignValue = CSSValueTop; 508 verticalAlignValue = CSSValueTop;
508 } else if (equalIgnoringCase(alignment, "right")) { 509 } else if (equalIgnoringCase(alignment, "right")) {
509 floatValue = CSSValueRight; 510 floatValue = CSSValueRight;
510 verticalAlignValue = CSSValueTop; 511 verticalAlignValue = CSSValueTop;
511 } else if (equalIgnoringCase(alignment, "top")) 512 } else if (equalIgnoringCase(alignment, "top")) {
512 verticalAlignValue = CSSValueTop; 513 verticalAlignValue = CSSValueTop;
513 else if (equalIgnoringCase(alignment, "middle")) 514 } else if (equalIgnoringCase(alignment, "middle")) {
514 verticalAlignValue = CSSValueWebkitBaselineMiddle; 515 verticalAlignValue = CSSValueWebkitBaselineMiddle;
515 else if (equalIgnoringCase(alignment, "center")) 516 } else if (equalIgnoringCase(alignment, "center")) {
516 verticalAlignValue = CSSValueMiddle; 517 verticalAlignValue = CSSValueMiddle;
517 else if (equalIgnoringCase(alignment, "bottom")) 518 } else if (equalIgnoringCase(alignment, "bottom")) {
518 verticalAlignValue = CSSValueBaseline; 519 verticalAlignValue = CSSValueBaseline;
519 else if (equalIgnoringCase(alignment, "texttop")) 520 } else if (equalIgnoringCase(alignment, "texttop")) {
520 verticalAlignValue = CSSValueTextTop; 521 verticalAlignValue = CSSValueTextTop;
522 }
521 523
522 if (floatValue != CSSValueInvalid) 524 if (floatValue != CSSValueInvalid)
523 addPropertyToPresentationAttributeStyle(style, CSSPropertyFloat, floatVa lue); 525 addPropertyToPresentationAttributeStyle(style, CSSPropertyFloat, floatVa lue);
524 526
525 if (verticalAlignValue != CSSValueInvalid) 527 if (verticalAlignValue != CSSValueInvalid)
526 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, verticalAlignValue); 528 addPropertyToPresentationAttributeStyle(style, CSSPropertyVerticalAlign, verticalAlignValue);
527 } 529 }
528 530
529 bool HTMLElement::hasCustomFocusLogic() const 531 bool HTMLElement::hasCustomFocusLogic() const
530 { 532 {
531 return false; 533 return false;
532 } 534 }
533 535
534 String HTMLElement::contentEditable() const 536 String HTMLElement::contentEditable() const
535 { 537 {
536 const AtomicString& value = fastGetAttribute(contenteditableAttr); 538 const AtomicString& value = fastGetAttribute(contenteditableAttr);
537 539
538 if (value.isNull()) 540 if (value.isNull())
539 return "inherit"; 541 return "inherit";
540 if (value.isEmpty() || equalIgnoringCase(value, "true")) 542 if (value.isEmpty() || equalIgnoringCase(value, "true"))
541 return "true"; 543 return "true";
542 if (equalIgnoringCase(value, "false")) 544 if (equalIgnoringCase(value, "false"))
543 return "false"; 545 return "false";
544 if (equalIgnoringCase(value, "plaintext-only")) 546 if (equalIgnoringCase(value, "plaintext-only"))
545 return "plaintext-only"; 547 return "plaintext-only";
546 548
547 return "inherit"; 549 return "inherit";
548 } 550 }
549 551
550 void HTMLElement::setContentEditable(const String& enabled, ExceptionState& exce ptionState) 552 void HTMLElement::setContentEditable(const String& enabled, ExceptionState& exce ptionState)
551 { 553 {
552 if (equalIgnoringCase(enabled, "true")) 554 if (equalIgnoringCase(enabled, "true"))
553 setAttribute(contenteditableAttr, "true"); 555 setAttribute(contenteditableAttr, "true");
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
1013 #ifndef NDEBUG 1015 #ifndef NDEBUG
1014 1016
1015 // For use in the debugger 1017 // For use in the debugger
1016 void dumpInnerHTML(blink::HTMLElement*); 1018 void dumpInnerHTML(blink::HTMLElement*);
1017 1019
1018 void dumpInnerHTML(blink::HTMLElement* element) 1020 void dumpInnerHTML(blink::HTMLElement* element)
1019 { 1021 {
1020 printf("%s\n", element->innerHTML().ascii().data()); 1022 printf("%s\n", element->innerHTML().ascii().data());
1021 } 1023 }
1022 #endif 1024 #endif
OLDNEW
« no previous file with comments | « Source/core/html/HTMLDocument.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698