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

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

Issue 72363002: Rename es => exceptionState in other than bindings/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Retry Created 7 years, 1 month 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/HTMLDialogElement.cpp ('k') | Source/core/html/HTMLFrameOwnerElement.cpp » ('j') | 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, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008 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 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 // Clamp tabindex to the range of 'short' to match Firefox's behavio r. 318 // Clamp tabindex to the range of 'short' to match Firefox's behavio r.
319 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short >::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max())))); 319 setTabIndexExplicitly(max(static_cast<int>(std::numeric_limits<short >::min()), min(tabindex, static_cast<int>(std::numeric_limits<short>::max()))));
320 } 320 }
321 } else { 321 } else {
322 AtomicString eventName = eventNameForAttributeName(name); 322 AtomicString eventName = eventNameForAttributeName(name);
323 if (!eventName.isNull()) 323 if (!eventName.isNull())
324 setAttributeEventListener(eventName, createAttributeEventListener(th is, name, value)); 324 setAttributeEventListener(eventName, createAttributeEventListener(th is, name, value));
325 } 325 }
326 } 326 }
327 327
328 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc eptionState& es) 328 PassRefPtr<DocumentFragment> HTMLElement::textToFragment(const String& text, Exc eptionState& exceptionState)
329 { 329 {
330 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document()); 330 RefPtr<DocumentFragment> fragment = DocumentFragment::create(document());
331 unsigned int i, length = text.length(); 331 unsigned int i, length = text.length();
332 UChar c = 0; 332 UChar c = 0;
333 for (unsigned int start = 0; start < length; ) { 333 for (unsigned int start = 0; start < length; ) {
334 334
335 // Find next line break. 335 // Find next line break.
336 for (i = start; i < length; i++) { 336 for (i = start; i < length; i++) {
337 c = text[i]; 337 c = text[i];
338 if (c == '\r' || c == '\n') 338 if (c == '\r' || c == '\n')
339 break; 339 break;
340 } 340 }
341 341
342 fragment->appendChild(Text::create(document(), text.substring(start, i - start)), es); 342 fragment->appendChild(Text::create(document(), text.substring(start, i - start)), exceptionState);
343 if (es.hadException()) 343 if (exceptionState.hadException())
344 return 0; 344 return 0;
345 345
346 if (c == '\r' || c == '\n') { 346 if (c == '\r' || c == '\n') {
347 fragment->appendChild(HTMLBRElement::create(document()), es); 347 fragment->appendChild(HTMLBRElement::create(document()), exceptionSt ate);
348 if (es.hadException()) 348 if (exceptionState.hadException())
349 return 0; 349 return 0;
350 // Make sure \r\n doesn't result in two line breaks. 350 // Make sure \r\n doesn't result in two line breaks.
351 if (c == '\r' && i + 1 < length && text[i + 1] == '\n') 351 if (c == '\r' && i + 1 < length && text[i + 1] == '\n')
352 i++; 352 i++;
353 } 353 }
354 354
355 start = i + 1; // Character after line break. 355 start = i + 1; // Character after line break.
356 } 356 }
357 357
358 return fragment; 358 return fragment;
359 } 359 }
360 360
361 void HTMLElement::setInnerText(const String& text, ExceptionState& es) 361 void HTMLElement::setInnerText(const String& text, ExceptionState& exceptionStat e)
362 { 362 {
363 if (ieForbidsInsertHTML()) { 363 if (ieForbidsInsertHTML()) {
364 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); 364 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAl lowedError);
365 return; 365 return;
366 } 366 }
367 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) || 367 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) ||
368 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) || 368 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) ||
369 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) || 369 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) ||
370 hasLocalName(trTag)) { 370 hasLocalName(trTag)) {
371 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); 371 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAl lowedError);
372 return; 372 return;
373 } 373 }
374 374
375 // FIXME: This doesn't take whitespace collapsing into account at all. 375 // FIXME: This doesn't take whitespace collapsing into account at all.
376 376
377 if (!text.contains('\n') && !text.contains('\r')) { 377 if (!text.contains('\n') && !text.contains('\r')) {
378 if (text.isEmpty()) { 378 if (text.isEmpty()) {
379 removeChildren(); 379 removeChildren();
380 return; 380 return;
381 } 381 }
382 replaceChildrenWithText(this, text, es); 382 replaceChildrenWithText(this, text, exceptionState);
383 return; 383 return;
384 } 384 }
385 385
386 // FIXME: Do we need to be able to detect preserveNewline style even when th ere's no renderer? 386 // FIXME: Do we need to be able to detect preserveNewline style even when th ere's no renderer?
387 // FIXME: Can the renderer be out of date here? Do we need to call updateSty leIfNeeded? 387 // FIXME: Can the renderer be out of date here? Do we need to call updateSty leIfNeeded?
388 // For example, for the contents of textarea elements that are display:none? 388 // For example, for the contents of textarea elements that are display:none?
389 RenderObject* r = renderer(); 389 RenderObject* r = renderer();
390 if (r && r->style()->preserveNewline()) { 390 if (r && r->style()->preserveNewline()) {
391 if (!text.contains('\r')) { 391 if (!text.contains('\r')) {
392 replaceChildrenWithText(this, text, es); 392 replaceChildrenWithText(this, text, exceptionState);
393 return; 393 return;
394 } 394 }
395 String textWithConsistentLineBreaks = text; 395 String textWithConsistentLineBreaks = text;
396 textWithConsistentLineBreaks.replace("\r\n", "\n"); 396 textWithConsistentLineBreaks.replace("\r\n", "\n");
397 textWithConsistentLineBreaks.replace('\r', '\n'); 397 textWithConsistentLineBreaks.replace('\r', '\n');
398 replaceChildrenWithText(this, textWithConsistentLineBreaks, es); 398 replaceChildrenWithText(this, textWithConsistentLineBreaks, exceptionSta te);
399 return; 399 return;
400 } 400 }
401 401
402 // Add text nodes and <br> elements. 402 // Add text nodes and <br> elements.
403 RefPtr<DocumentFragment> fragment = textToFragment(text, es); 403 RefPtr<DocumentFragment> fragment = textToFragment(text, exceptionState);
404 if (!es.hadException()) 404 if (!exceptionState.hadException())
405 replaceChildrenWithFragment(this, fragment.release(), es); 405 replaceChildrenWithFragment(this, fragment.release(), exceptionState);
406 } 406 }
407 407
408 void HTMLElement::setOuterText(const String &text, ExceptionState& es) 408 void HTMLElement::setOuterText(const String &text, ExceptionState& exceptionStat e)
409 { 409 {
410 if (ieForbidsInsertHTML()) { 410 if (ieForbidsInsertHTML()) {
411 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); 411 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAl lowedError);
412 return; 412 return;
413 } 413 }
414 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) || 414 if (hasLocalName(colTag) || hasLocalName(colgroupTag) || hasLocalName(frames etTag) ||
415 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) || 415 hasLocalName(headTag) || hasLocalName(htmlTag) || hasLocalName(tableTag) ||
416 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) || 416 hasLocalName(tbodyTag) || hasLocalName(tfootTag) || hasLocalName(theadTa g) ||
417 hasLocalName(trTag)) { 417 hasLocalName(trTag)) {
418 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); 418 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAl lowedError);
419 return; 419 return;
420 } 420 }
421 421
422 ContainerNode* parent = parentNode(); 422 ContainerNode* parent = parentNode();
423 if (!parent) { 423 if (!parent) {
424 es.throwUninformativeAndGenericDOMException(NoModificationAllowedError); 424 exceptionState.throwUninformativeAndGenericDOMException(NoModificationAl lowedError);
425 return; 425 return;
426 } 426 }
427 427
428 RefPtr<Node> prev = previousSibling(); 428 RefPtr<Node> prev = previousSibling();
429 RefPtr<Node> next = nextSibling(); 429 RefPtr<Node> next = nextSibling();
430 RefPtr<Node> newChild; 430 RefPtr<Node> newChild;
431 431
432 // Convert text to fragment with <br> tags instead of linebreaks if needed. 432 // Convert text to fragment with <br> tags instead of linebreaks if needed.
433 if (text.contains('\r') || text.contains('\n')) 433 if (text.contains('\r') || text.contains('\n'))
434 newChild = textToFragment(text, es); 434 newChild = textToFragment(text, exceptionState);
435 else 435 else
436 newChild = Text::create(document(), text); 436 newChild = Text::create(document(), text);
437 437
438 if (!this || !parentNode()) 438 if (!this || !parentNode())
439 es.throwUninformativeAndGenericDOMException(HierarchyRequestError); 439 exceptionState.throwUninformativeAndGenericDOMException(HierarchyRequest Error);
440 if (es.hadException()) 440 if (exceptionState.hadException())
441 return; 441 return;
442 parent->replaceChild(newChild.release(), this, es); 442 parent->replaceChild(newChild.release(), this, exceptionState);
443 443
444 RefPtr<Node> node = next ? next->previousSibling() : 0; 444 RefPtr<Node> node = next ? next->previousSibling() : 0;
445 if (!es.hadException() && node && node->isTextNode()) 445 if (!exceptionState.hadException() && node && node->isTextNode())
446 mergeWithNextTextNode(node.release(), es); 446 mergeWithNextTextNode(node.release(), exceptionState);
447 447
448 if (!es.hadException() && prev && prev->isTextNode()) 448 if (!exceptionState.hadException() && prev && prev->isTextNode())
449 mergeWithNextTextNode(prev.release(), es); 449 mergeWithNextTextNode(prev.release(), exceptionState);
450 } 450 }
451 451
452 Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, Exception State& es) 452 Node* HTMLElement::insertAdjacent(const String& where, Node* newChild, Exception State& exceptionState)
453 { 453 {
454 // In Internet Explorer if the element has no parent and where is "beforeBeg in" or "afterEnd", 454 // In Internet Explorer if the element has no parent and where is "beforeBeg in" or "afterEnd",
455 // a document fragment is created and the elements appended in the correct o rder. This document 455 // a document fragment is created and the elements appended in the correct o rder. This document
456 // fragment isn't returned anywhere. 456 // fragment isn't returned anywhere.
457 // 457 //
458 // This is impossible for us to implement as the DOM tree does not allow for such structures, 458 // This is impossible for us to implement as the DOM tree does not allow for such structures,
459 // Opera also appears to disallow such usage. 459 // Opera also appears to disallow such usage.
460 460
461 if (equalIgnoringCase(where, "beforeBegin")) { 461 if (equalIgnoringCase(where, "beforeBegin")) {
462 if (ContainerNode* parent = this->parentNode()) { 462 if (ContainerNode* parent = this->parentNode()) {
463 parent->insertBefore(newChild, this, es); 463 parent->insertBefore(newChild, this, exceptionState);
464 if (!es.hadException()) 464 if (!exceptionState.hadException())
465 return newChild; 465 return newChild;
466 } 466 }
467 return 0; 467 return 0;
468 } 468 }
469 469
470 if (equalIgnoringCase(where, "afterBegin")) { 470 if (equalIgnoringCase(where, "afterBegin")) {
471 insertBefore(newChild, firstChild(), es); 471 insertBefore(newChild, firstChild(), exceptionState);
472 return es.hadException() ? 0 : newChild; 472 return exceptionState.hadException() ? 0 : newChild;
473 } 473 }
474 474
475 if (equalIgnoringCase(where, "beforeEnd")) { 475 if (equalIgnoringCase(where, "beforeEnd")) {
476 appendChild(newChild, es); 476 appendChild(newChild, exceptionState);
477 return es.hadException() ? 0 : newChild; 477 return exceptionState.hadException() ? 0 : newChild;
478 } 478 }
479 479
480 if (equalIgnoringCase(where, "afterEnd")) { 480 if (equalIgnoringCase(where, "afterEnd")) {
481 if (ContainerNode* parent = this->parentNode()) { 481 if (ContainerNode* parent = this->parentNode()) {
482 parent->insertBefore(newChild, nextSibling(), es); 482 parent->insertBefore(newChild, nextSibling(), exceptionState);
483 if (!es.hadException()) 483 if (!exceptionState.hadException())
484 return newChild; 484 return newChild;
485 } 485 }
486 return 0; 486 return 0;
487 } 487 }
488 488
489 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative. 489 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alte rnative.
490 es.throwUninformativeAndGenericDOMException(NotSupportedError); 490 exceptionState.throwUninformativeAndGenericDOMException(NotSupportedError);
491 return 0; 491 return 0;
492 } 492 }
493 493
494 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionState& es) 494 Element* HTMLElement::insertAdjacentElement(const String& where, Element* newChi ld, ExceptionState& exceptionState)
495 { 495 {
496 if (!newChild) { 496 if (!newChild) {
497 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative. 497 // IE throws COM Exception E_INVALIDARG; this is the best DOM exception alternative.
498 es.throwUninformativeAndGenericDOMException(TypeMismatchError); 498 exceptionState.throwUninformativeAndGenericDOMException(TypeMismatchErro r);
499 return 0; 499 return 0;
500 } 500 }
501 501
502 Node* returnValue = insertAdjacent(where, newChild, es); 502 Node* returnValue = insertAdjacent(where, newChild, exceptionState);
503 return toElement(returnValue); 503 return toElement(returnValue);
504 } 504 }
505 505
506 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml() 506 // Step 3 of http://www.whatwg.org/specs/web-apps/current-work/multipage/apis-in -html-documents.html#insertadjacenthtml()
507 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionState& es) 507 static Element* contextElementForInsertion(const String& where, Element* element , ExceptionState& exceptionState)
508 { 508 {
509 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) { 509 if (equalIgnoringCase(where, "beforeBegin") || equalIgnoringCase(where, "aft erEnd")) {
510 ContainerNode* parent = element->parentNode(); 510 ContainerNode* parent = element->parentNode();
511 if (parent && !parent->isElementNode()) { 511 if (parent && !parent->isElementNode()) {
512 es.throwUninformativeAndGenericDOMException(NoModificationAllowedErr or); 512 exceptionState.throwUninformativeAndGenericDOMException(NoModificati onAllowedError);
513 return 0; 513 return 0;
514 } 514 }
515 return toElement(parent); 515 return toElement(parent);
516 } 516 }
517 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd")) 517 if (equalIgnoringCase(where, "afterBegin") || equalIgnoringCase(where, "befo reEnd"))
518 return element; 518 return element;
519 es.throwUninformativeAndGenericDOMException(SyntaxError); 519 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError);
520 return 0; 520 return 0;
521 } 521 }
522 522
523 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionState& es) 523 void HTMLElement::insertAdjacentHTML(const String& where, const String& markup, ExceptionState& exceptionState)
524 { 524 {
525 RefPtr<Element> contextElement = contextElementForInsertion(where, this, es) ; 525 RefPtr<Element> contextElement = contextElementForInsertion(where, this, exc eptionState);
526 if (!contextElement) 526 if (!contextElement)
527 return; 527 return;
528 528
529 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement.get(), AllowScriptingContent, "insertAdjacentHTML", es); 529 RefPtr<DocumentFragment> fragment = createFragmentForInnerOuterHTML(markup, contextElement.get(), AllowScriptingContent, "insertAdjacentHTML", exceptionStat e);
530 if (!fragment) 530 if (!fragment)
531 return; 531 return;
532 insertAdjacent(where, fragment.get(), es); 532 insertAdjacent(where, fragment.get(), exceptionState);
533 } 533 }
534 534
535 void HTMLElement::insertAdjacentText(const String& where, const String& text, Ex ceptionState& es) 535 void HTMLElement::insertAdjacentText(const String& where, const String& text, Ex ceptionState& exceptionState)
536 { 536 {
537 RefPtr<Text> textNode = document().createTextNode(text); 537 RefPtr<Text> textNode = document().createTextNode(text);
538 insertAdjacent(where, textNode.get(), es); 538 insertAdjacent(where, textNode.get(), exceptionState);
539 } 539 }
540 540
541 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style) 541 void HTMLElement::applyAlignmentAttributeToStyle(const AtomicString& alignment, MutableStylePropertySet* style)
542 { 542 {
543 // Vertical alignment with respect to the current baseline of the text 543 // Vertical alignment with respect to the current baseline of the text
544 // right or left means floating images. 544 // right or left means floating images.
545 CSSValueID floatValue = CSSValueInvalid; 545 CSSValueID floatValue = CSSValueInvalid;
546 CSSValueID verticalAlignValue = CSSValueInvalid; 546 CSSValueID verticalAlignValue = CSSValueInvalid;
547 547
548 if (equalIgnoringCase(alignment, "absmiddle")) 548 if (equalIgnoringCase(alignment, "absmiddle"))
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
614 if (value.isEmpty() || equalIgnoringCase(value, "true")) 614 if (value.isEmpty() || equalIgnoringCase(value, "true"))
615 return "true"; 615 return "true";
616 if (equalIgnoringCase(value, "false")) 616 if (equalIgnoringCase(value, "false"))
617 return "false"; 617 return "false";
618 if (equalIgnoringCase(value, "plaintext-only")) 618 if (equalIgnoringCase(value, "plaintext-only"))
619 return "plaintext-only"; 619 return "plaintext-only";
620 620
621 return "inherit"; 621 return "inherit";
622 } 622 }
623 623
624 void HTMLElement::setContentEditable(const String& enabled, ExceptionState& es) 624 void HTMLElement::setContentEditable(const String& enabled, ExceptionState& exce ptionState)
625 { 625 {
626 if (equalIgnoringCase(enabled, "true")) 626 if (equalIgnoringCase(enabled, "true"))
627 setAttribute(contenteditableAttr, "true"); 627 setAttribute(contenteditableAttr, "true");
628 else if (equalIgnoringCase(enabled, "false")) 628 else if (equalIgnoringCase(enabled, "false"))
629 setAttribute(contenteditableAttr, "false"); 629 setAttribute(contenteditableAttr, "false");
630 else if (equalIgnoringCase(enabled, "plaintext-only")) 630 else if (equalIgnoringCase(enabled, "plaintext-only"))
631 setAttribute(contenteditableAttr, "plaintext-only"); 631 setAttribute(contenteditableAttr, "plaintext-only");
632 else if (equalIgnoringCase(enabled, "inherit")) 632 else if (equalIgnoringCase(enabled, "inherit"))
633 removeAttribute(contenteditableAttr); 633 removeAttribute(contenteditableAttr);
634 else 634 else
635 es.throwUninformativeAndGenericDOMException(SyntaxError); 635 exceptionState.throwUninformativeAndGenericDOMException(SyntaxError);
636 } 636 }
637 637
638 bool HTMLElement::draggable() const 638 bool HTMLElement::draggable() const
639 { 639 {
640 return equalIgnoringCase(getAttribute(draggableAttr), "true"); 640 return equalIgnoringCase(getAttribute(draggableAttr), "true");
641 } 641 }
642 642
643 void HTMLElement::setDraggable(bool value) 643 void HTMLElement::setDraggable(bool value)
644 { 644 {
645 setAttribute(draggableAttr, value ? "true" : "false"); 645 setAttribute(draggableAttr, value ? "true" : "false");
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after
1072 #ifndef NDEBUG 1072 #ifndef NDEBUG
1073 1073
1074 // For use in the debugger 1074 // For use in the debugger
1075 void dumpInnerHTML(WebCore::HTMLElement*); 1075 void dumpInnerHTML(WebCore::HTMLElement*);
1076 1076
1077 void dumpInnerHTML(WebCore::HTMLElement* element) 1077 void dumpInnerHTML(WebCore::HTMLElement* element)
1078 { 1078 {
1079 printf("%s\n", element->innerHTML().ascii().data()); 1079 printf("%s\n", element->innerHTML().ascii().data());
1080 } 1080 }
1081 #endif 1081 #endif
OLDNEW
« no previous file with comments | « Source/core/html/HTMLDialogElement.cpp ('k') | Source/core/html/HTMLFrameOwnerElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698