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

Side by Side Diff: Source/core/editing/htmlediting.cpp

Issue 23548010: Have htmlediting create functions take a Document reference in argument (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 3 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/editing/htmlediting.h ('k') | Source/core/editing/markup.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) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 if (node->childNodeCount()) 522 if (node->childNodeCount())
523 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM); 523 return VisiblePosition(lastPositionInOrAfterNode(node), DOWNSTREAM);
524 ASSERT(node->parentNode()); 524 ASSERT(node->parentNode());
525 ASSERT(!node->parentNode()->isShadowRoot()); 525 ASSERT(!node->parentNode()->isShadowRoot());
526 return positionInParentAfterNode(node); 526 return positionInParentAfterNode(node);
527 } 527 }
528 528
529 // Create a range object with two visible positions, start and end. 529 // Create a range object with two visible positions, start and end.
530 // create(Document*, const Position&, const Position&); will use deprecatedEditi ngOffset 530 // create(Document*, const Position&, const Position&); will use deprecatedEditi ngOffset
531 // Use this function instead of create a regular range object (avoiding editing offset). 531 // Use this function instead of create a regular range object (avoiding editing offset).
532 PassRefPtr<Range> createRange(Document* document, const VisiblePosition& start, const VisiblePosition& end, ExceptionState& es) 532 PassRefPtr<Range> createRange(Document& document, const VisiblePosition& start, const VisiblePosition& end, ExceptionState& es)
533 { 533 {
534 RefPtr<Range> selectedRange = Range::create(document); 534 RefPtr<Range> selectedRange = Range::create(&document);
535 selectedRange->setStart(start.deepEquivalent().containerNode(), start.deepEq uivalent().computeOffsetInContainerNode(), es); 535 selectedRange->setStart(start.deepEquivalent().containerNode(), start.deepEq uivalent().computeOffsetInContainerNode(), es);
536 if (!es.hadException()) 536 if (!es.hadException())
537 selectedRange->setEnd(end.deepEquivalent().containerNode(), end.deepEqui valent().computeOffsetInContainerNode(), es); 537 selectedRange->setEnd(end.deepEquivalent().containerNode(), end.deepEqui valent().computeOffsetInContainerNode(), es);
538 return selectedRange.release(); 538 return selectedRange.release();
539 } 539 }
540 540
541 bool isListElement(Node *n) 541 bool isListElement(Node *n)
542 { 542 {
543 return (n && (n->hasTagName(ulTag) || n->hasTagName(olTag) || n->hasTagName( dlTag))); 543 return (n && (n->hasTagName(ulTag) || n->hasTagName(olTag) || n->hasTagName( dlTag)));
544 } 544 }
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 809
810 // Check that the table cell contains no child renderers except for perhaps a single <br>. 810 // Check that the table cell contains no child renderers except for perhaps a single <br>.
811 RenderObject* childRenderer = renderer->firstChild(); 811 RenderObject* childRenderer = renderer->firstChild();
812 if (!childRenderer) 812 if (!childRenderer)
813 return true; 813 return true;
814 if (!childRenderer->isBR()) 814 if (!childRenderer->isBR())
815 return false; 815 return false;
816 return !childRenderer->nextSibling(); 816 return !childRenderer->nextSibling();
817 } 817 }
818 818
819 PassRefPtr<HTMLElement> createDefaultParagraphElement(Document* document) 819 PassRefPtr<HTMLElement> createDefaultParagraphElement(Document& document)
820 { 820 {
821 switch (document->frame()->editor().defaultParagraphSeparator()) { 821 switch (document.frame()->editor().defaultParagraphSeparator()) {
822 case EditorParagraphSeparatorIsDiv: 822 case EditorParagraphSeparatorIsDiv:
823 return HTMLDivElement::create(document); 823 return HTMLDivElement::create(&document);
824 case EditorParagraphSeparatorIsP: 824 case EditorParagraphSeparatorIsP:
825 return HTMLParagraphElement::create(document); 825 return HTMLParagraphElement::create(&document);
826 } 826 }
827 827
828 ASSERT_NOT_REACHED(); 828 ASSERT_NOT_REACHED();
829 return 0; 829 return 0;
830 } 830 }
831 831
832 PassRefPtr<HTMLElement> createBreakElement(Document* document) 832 PassRefPtr<HTMLElement> createBreakElement(Document& document)
833 { 833 {
834 return HTMLBRElement::create(document); 834 return HTMLBRElement::create(&document);
835 } 835 }
836 836
837 PassRefPtr<HTMLElement> createOrderedListElement(Document* document) 837 PassRefPtr<HTMLElement> createOrderedListElement(Document& document)
838 { 838 {
839 return HTMLOListElement::create(document); 839 return HTMLOListElement::create(&document);
840 } 840 }
841 841
842 PassRefPtr<HTMLElement> createUnorderedListElement(Document* document) 842 PassRefPtr<HTMLElement> createUnorderedListElement(Document& document)
843 { 843 {
844 return HTMLUListElement::create(document); 844 return HTMLUListElement::create(&document);
845 } 845 }
846 846
847 PassRefPtr<HTMLElement> createListItemElement(Document* document) 847 PassRefPtr<HTMLElement> createListItemElement(Document& document)
848 { 848 {
849 return HTMLLIElement::create(document); 849 return HTMLLIElement::create(&document);
850 } 850 }
851 851
852 PassRefPtr<HTMLElement> createHTMLElement(Document* document, const QualifiedNam e& name) 852 PassRefPtr<HTMLElement> createHTMLElement(Document& document, const QualifiedNam e& name)
853 { 853 {
854 return HTMLElementFactory::createHTMLElement(name, document, 0, false); 854 return HTMLElementFactory::createHTMLElement(name, &document, 0, false);
855 } 855 }
856 856
857 PassRefPtr<HTMLElement> createHTMLElement(Document* document, const AtomicString & tagName) 857 PassRefPtr<HTMLElement> createHTMLElement(Document& document, const AtomicString & tagName)
858 { 858 {
859 return createHTMLElement(document, QualifiedName(nullAtom, tagName, xhtmlNam espaceURI)); 859 return createHTMLElement(document, QualifiedName(nullAtom, tagName, xhtmlNam espaceURI));
860 } 860 }
861 861
862 bool isTabSpanNode(const Node *node) 862 bool isTabSpanNode(const Node *node)
863 { 863 {
864 return node && node->hasTagName(spanTag) && node->isElementNode() && toEleme nt(node)->getAttribute(classAttr) == AppleTabSpanClass; 864 return node && node->hasTagName(spanTag) && node->isElementNode() && toEleme nt(node)->getAttribute(classAttr) == AppleTabSpanClass;
865 } 865 }
866 866
867 bool isTabSpanTextNode(const Node *node) 867 bool isTabSpanTextNode(const Node *node)
(...skipping 13 matching lines...) Expand all
881 node = tabSpanNode(node); 881 node = tabSpanNode(node);
882 else if (!isTabSpanNode(node)) 882 else if (!isTabSpanNode(node))
883 return pos; 883 return pos;
884 884
885 if (node && VisiblePosition(pos) == lastPositionInNode(node)) 885 if (node && VisiblePosition(pos) == lastPositionInNode(node))
886 return positionInParentAfterNode(node); 886 return positionInParentAfterNode(node);
887 887
888 return positionInParentBeforeNode(node); 888 return positionInParentBeforeNode(node);
889 } 889 }
890 890
891 PassRefPtr<Element> createTabSpanElement(Document* document, PassRefPtr<Node> pr pTabTextNode) 891 PassRefPtr<Element> createTabSpanElement(Document& document, PassRefPtr<Node> pr pTabTextNode)
892 { 892 {
893 RefPtr<Node> tabTextNode = prpTabTextNode; 893 RefPtr<Node> tabTextNode = prpTabTextNode;
894 894
895 // Make the span to hold the tab. 895 // Make the span to hold the tab.
896 RefPtr<Element> spanElement = document->createElement(spanTag, false); 896 RefPtr<Element> spanElement = document.createElement(spanTag, false);
897 spanElement->setAttribute(classAttr, AppleTabSpanClass); 897 spanElement->setAttribute(classAttr, AppleTabSpanClass);
898 spanElement->setAttribute(styleAttr, "white-space:pre"); 898 spanElement->setAttribute(styleAttr, "white-space:pre");
899 899
900 // Add tab text to that span. 900 // Add tab text to that span.
901 if (!tabTextNode) 901 if (!tabTextNode)
902 tabTextNode = document->createEditingTextNode("\t"); 902 tabTextNode = document.createEditingTextNode("\t");
903 903
904 spanElement->appendChild(tabTextNode.release()); 904 spanElement->appendChild(tabTextNode.release());
905 905
906 return spanElement.release(); 906 return spanElement.release();
907 } 907 }
908 908
909 PassRefPtr<Element> createTabSpanElement(Document* document, const String& tabTe xt) 909 PassRefPtr<Element> createTabSpanElement(Document& document, const String& tabTe xt)
910 { 910 {
911 return createTabSpanElement(document, document->createTextNode(tabText)); 911 return createTabSpanElement(document, document.createTextNode(tabText));
912 } 912 }
913 913
914 PassRefPtr<Element> createTabSpanElement(Document* document) 914 PassRefPtr<Element> createTabSpanElement(Document& document)
915 { 915 {
916 return createTabSpanElement(document, PassRefPtr<Node>()); 916 return createTabSpanElement(document, PassRefPtr<Node>());
917 } 917 }
918 918
919 bool isNodeRendered(const Node *node) 919 bool isNodeRendered(const Node *node)
920 { 920 {
921 if (!node) 921 if (!node)
922 return false; 922 return false;
923 923
924 RenderObject* renderer = node->renderer(); 924 RenderObject* renderer = node->renderer();
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1164 // if the selection starts just before a paragraph break, skip over it 1164 // if the selection starts just before a paragraph break, skip over it
1165 if (isEndOfParagraph(visiblePosition)) 1165 if (isEndOfParagraph(visiblePosition))
1166 return visiblePosition.next().deepEquivalent().downstream(); 1166 return visiblePosition.next().deepEquivalent().downstream();
1167 1167
1168 // otherwise, make sure to be at the start of the first selected node, 1168 // otherwise, make sure to be at the start of the first selected node,
1169 // instead of possibly at the end of the last node before the selection 1169 // instead of possibly at the end of the last node before the selection
1170 return visiblePosition.deepEquivalent().downstream(); 1170 return visiblePosition.deepEquivalent().downstream();
1171 } 1171 }
1172 1172
1173 } // namespace WebCore 1173 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/htmlediting.h ('k') | Source/core/editing/markup.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698