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

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

Issue 899163003: Move rendering/RenderObject to layout/LayoutObject. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 10 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/VisibleUnits.cpp ('k') | Source/core/editing/iterators/BitStack.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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #include "core/editing/iterators/TextIterator.h" 45 #include "core/editing/iterators/TextIterator.h"
46 #include "core/frame/LocalFrame.h" 46 #include "core/frame/LocalFrame.h"
47 #include "core/frame/UseCounter.h" 47 #include "core/frame/UseCounter.h"
48 #include "core/html/HTMLBRElement.h" 48 #include "core/html/HTMLBRElement.h"
49 #include "core/html/HTMLDivElement.h" 49 #include "core/html/HTMLDivElement.h"
50 #include "core/html/HTMLLIElement.h" 50 #include "core/html/HTMLLIElement.h"
51 #include "core/html/HTMLParagraphElement.h" 51 #include "core/html/HTMLParagraphElement.h"
52 #include "core/html/HTMLSpanElement.h" 52 #include "core/html/HTMLSpanElement.h"
53 #include "core/html/HTMLTableCellElement.h" 53 #include "core/html/HTMLTableCellElement.h"
54 #include "core/html/HTMLUListElement.h" 54 #include "core/html/HTMLUListElement.h"
55 #include "core/layout/LayoutObject.h"
55 #include "core/layout/LayoutTableCell.h" 56 #include "core/layout/LayoutTableCell.h"
56 #include "core/rendering/RenderObject.h"
57 #include "wtf/Assertions.h" 57 #include "wtf/Assertions.h"
58 #include "wtf/StdLibExtras.h" 58 #include "wtf/StdLibExtras.h"
59 #include "wtf/text/StringBuilder.h" 59 #include "wtf/text/StringBuilder.h"
60 60
61 namespace blink { 61 namespace blink {
62 62
63 using namespace HTMLNames; 63 using namespace HTMLNames;
64 64
65 // Atomic means that the node has no children, or has children which are ignored for the 65 // Atomic means that the node has no children, or has children which are ignored for the
66 // purposes of editing. 66 // purposes of editing.
(...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 bool inSameContainingBlockFlowElement(Node* a, Node* b) 348 bool inSameContainingBlockFlowElement(Node* a, Node* b)
349 { 349 {
350 return a && b && enclosingBlockFlowElement(*a) == enclosingBlockFlowElement( *b); 350 return a && b && enclosingBlockFlowElement(*a) == enclosingBlockFlowElement( *b);
351 } 351 }
352 352
353 TextDirection directionOfEnclosingBlock(const Position& position) 353 TextDirection directionOfEnclosingBlock(const Position& position)
354 { 354 {
355 Element* enclosingBlockElement = enclosingBlock(position.containerNode()); 355 Element* enclosingBlockElement = enclosingBlock(position.containerNode());
356 if (!enclosingBlockElement) 356 if (!enclosingBlockElement)
357 return LTR; 357 return LTR;
358 RenderObject* renderer = enclosingBlockElement->renderer(); 358 LayoutObject* renderer = enclosingBlockElement->renderer();
359 return renderer ? renderer->style()->direction() : LTR; 359 return renderer ? renderer->style()->direction() : LTR;
360 } 360 }
361 361
362 // This method is used to create positions in the DOM. It returns the maximum va lid offset 362 // This method is used to create positions in the DOM. It returns the maximum va lid offset
363 // in a node. It returns 1 for some elements even though they do not have childr en, which 363 // in a node. It returns 1 for some elements even though they do not have childr en, which
364 // creates technically invalid DOM Positions. Be sure to call parentAnchoredEqui valent 364 // creates technically invalid DOM Positions. Be sure to call parentAnchoredEqui valent
365 // on a Position before using it to create a DOM Range, or an exception will be thrown. 365 // on a Position before using it to create a DOM Range, or an exception will be thrown.
366 int lastOffsetForEditing(const Node* node) 366 int lastOffsetForEditing(const Node* node)
367 { 367 {
368 ASSERT(node); 368 ASSERT(node);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 } 406 }
407 } 407 }
408 408
409 ASSERT(rebalancedString.length() == length); 409 ASSERT(rebalancedString.length() == length);
410 410
411 return rebalancedString.toString(); 411 return rebalancedString.toString();
412 } 412 }
413 413
414 bool isTableStructureNode(const Node *node) 414 bool isTableStructureNode(const Node *node)
415 { 415 {
416 RenderObject* renderer = node->renderer(); 416 LayoutObject* renderer = node->renderer();
417 return (renderer && (renderer->isTableCell() || renderer->isTableRow() || re nderer->isTableSection() || renderer->isLayoutTableCol())); 417 return (renderer && (renderer->isTableCell() || renderer->isTableRow() || re nderer->isTableSection() || renderer->isLayoutTableCol()));
418 } 418 }
419 419
420 const String& nonBreakingSpaceString() 420 const String& nonBreakingSpaceString()
421 { 421 {
422 DEFINE_STATIC_LOCAL(String, nonBreakingSpaceString, (&noBreakSpace, 1)); 422 DEFINE_STATIC_LOCAL(String, nonBreakingSpaceString, (&noBreakSpace, 1));
423 return nonBreakingSpaceString; 423 return nonBreakingSpaceString;
424 } 424 }
425 425
426 // FIXME: need to dump this 426 // FIXME: need to dump this
427 static bool isSpecialHTMLElement(const Node& n) 427 static bool isSpecialHTMLElement(const Node& n)
428 { 428 {
429 if (!n.isHTMLElement()) 429 if (!n.isHTMLElement())
430 return false; 430 return false;
431 431
432 if (n.isLink()) 432 if (n.isLink())
433 return true; 433 return true;
434 434
435 RenderObject* renderer = n.renderer(); 435 LayoutObject* renderer = n.renderer();
436 if (!renderer) 436 if (!renderer)
437 return false; 437 return false;
438 438
439 if (renderer->style()->display() == TABLE || renderer->style()->display() == INLINE_TABLE) 439 if (renderer->style()->display() == TABLE || renderer->style()->display() == INLINE_TABLE)
440 return true; 440 return true;
441 441
442 if (renderer->style()->isFloating()) 442 if (renderer->style()->isFloating())
443 return true; 443 return true;
444 444
445 return false; 445 return false;
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 n = NodeTraversal::next(*n, node); 622 n = NodeTraversal::next(*n, node);
623 } 623 }
624 return false; 624 return false;
625 } 625 }
626 626
627 Node* highestNodeToRemoveInPruning(Node* node, Node* excludeNode) 627 Node* highestNodeToRemoveInPruning(Node* node, Node* excludeNode)
628 { 628 {
629 Node* previousNode = nullptr; 629 Node* previousNode = nullptr;
630 Element* rootEditableElement = node ? node->rootEditableElement() : nullptr; 630 Element* rootEditableElement = node ? node->rootEditableElement() : nullptr;
631 for (; node; node = node->parentNode()) { 631 for (; node; node = node->parentNode()) {
632 if (RenderObject* renderer = node->renderer()) { 632 if (LayoutObject* renderer = node->renderer()) {
633 if (!renderer->canHaveChildren() || hasARenderedDescendant(node, pre viousNode) || rootEditableElement == node || excludeNode == node) 633 if (!renderer->canHaveChildren() || hasARenderedDescendant(node, pre viousNode) || rootEditableElement == node || excludeNode == node)
634 return previousNode; 634 return previousNode;
635 } 635 }
636 previousNode = node; 636 previousNode = node;
637 } 637 }
638 return 0; 638 return 0;
639 } 639 }
640 640
641 Element* enclosingTableCell(const Position& p) 641 Element* enclosingTableCell(const Position& p)
642 { 642 {
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 bool isRenderedHTMLTableElement(const Node* node) 745 bool isRenderedHTMLTableElement(const Node* node)
746 { 746 {
747 return isHTMLTableElement(*node) && node->renderer(); 747 return isHTMLTableElement(*node) && node->renderer();
748 } 748 }
749 749
750 bool isRenderedTableElement(const Node* node) 750 bool isRenderedTableElement(const Node* node)
751 { 751 {
752 if (!node || !node->isElementNode()) 752 if (!node || !node->isElementNode())
753 return false; 753 return false;
754 754
755 RenderObject* renderer = node->renderer(); 755 LayoutObject* renderer = node->renderer();
756 return (renderer && renderer->isTable()); 756 return (renderer && renderer->isTable());
757 } 757 }
758 758
759 bool isTableCell(const Node* node) 759 bool isTableCell(const Node* node)
760 { 760 {
761 ASSERT(node); 761 ASSERT(node);
762 RenderObject* r = node->renderer(); 762 LayoutObject* r = node->renderer();
763 return r ? r->isTableCell() : isHTMLTableCellElement(*node); 763 return r ? r->isTableCell() : isHTMLTableCellElement(*node);
764 } 764 }
765 765
766 bool isEmptyTableCell(const Node* node) 766 bool isEmptyTableCell(const Node* node)
767 { 767 {
768 // Returns true IFF the passed in node is one of: 768 // Returns true IFF the passed in node is one of:
769 // .) a table cell with no children, 769 // .) a table cell with no children,
770 // .) a table cell with a single BR child, and which has no other child re nderers, including :before and :after renderers 770 // .) a table cell with a single BR child, and which has no other child re nderers, including :before and :after renderers
771 // .) the BR child of such a table cell 771 // .) the BR child of such a table cell
772 772
773 // Find rendered node 773 // Find rendered node
774 while (node && !node->renderer()) 774 while (node && !node->renderer())
775 node = node->parentNode(); 775 node = node->parentNode();
776 if (!node) 776 if (!node)
777 return false; 777 return false;
778 778
779 // Make sure the rendered node is a table cell or <br>. 779 // Make sure the rendered node is a table cell or <br>.
780 // If it's a <br>, then the parent node has to be a table cell. 780 // If it's a <br>, then the parent node has to be a table cell.
781 RenderObject* renderer = node->renderer(); 781 LayoutObject* renderer = node->renderer();
782 if (renderer->isBR()) { 782 if (renderer->isBR()) {
783 renderer = renderer->parent(); 783 renderer = renderer->parent();
784 if (!renderer) 784 if (!renderer)
785 return false; 785 return false;
786 } 786 }
787 if (!renderer->isTableCell()) 787 if (!renderer->isTableCell())
788 return false; 788 return false;
789 789
790 // Check that the table cell contains no child renderers except for perhaps a single <br>. 790 // Check that the table cell contains no child renderers except for perhaps a single <br>.
791 RenderObject* childRenderer = toLayoutTableCell(renderer)->firstChild(); 791 LayoutObject* childRenderer = toLayoutTableCell(renderer)->firstChild();
792 if (!childRenderer) 792 if (!childRenderer)
793 return true; 793 return true;
794 if (!childRenderer->isBR()) 794 if (!childRenderer->isBR())
795 return false; 795 return false;
796 return !childRenderer->nextSibling(); 796 return !childRenderer->nextSibling();
797 } 797 }
798 798
799 PassRefPtrWillBeRawPtr<HTMLElement> createDefaultParagraphElement(Document& docu ment) 799 PassRefPtrWillBeRawPtr<HTMLElement> createDefaultParagraphElement(Document& docu ment)
800 { 800 {
801 switch (document.frame()->editor().defaultParagraphSeparator()) { 801 switch (document.frame()->editor().defaultParagraphSeparator()) {
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 return createTabSpanElement(document, PassRefPtrWillBeRawPtr<Text>(nullptr)) ; 875 return createTabSpanElement(document, PassRefPtrWillBeRawPtr<Text>(nullptr)) ;
876 } 876 }
877 877
878 PassRefPtrWillBeRawPtr<HTMLBRElement> createBlockPlaceholderElement(Document& do cument) 878 PassRefPtrWillBeRawPtr<HTMLBRElement> createBlockPlaceholderElement(Document& do cument)
879 { 879 {
880 return toHTMLBRElement(document.createElement(brTag, false).get()); 880 return toHTMLBRElement(document.createElement(brTag, false).get());
881 } 881 }
882 882
883 bool isNodeRendered(const Node& node) 883 bool isNodeRendered(const Node& node)
884 { 884 {
885 RenderObject* renderer = node.renderer(); 885 LayoutObject* renderer = node.renderer();
886 if (!renderer) 886 if (!renderer)
887 return false; 887 return false;
888 888
889 return renderer->style()->visibility() == VISIBLE; 889 return renderer->style()->visibility() == VISIBLE;
890 } 890 }
891 891
892 // return first preceding DOM position rendered at a different location, or "thi s" 892 // return first preceding DOM position rendered at a different location, or "thi s"
893 static Position previousCharacterPosition(const Position& position, EAffinity af finity) 893 static Position previousCharacterPosition(const Position& position, EAffinity af finity)
894 { 894 {
895 if (position.isNull()) 895 if (position.isNull())
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
1000 { 1000 {
1001 if (!node || !node->isHTMLElement()) 1001 if (!node || !node->isHTMLElement())
1002 return false; 1002 return false;
1003 1003
1004 const HTMLElement& element = toHTMLElement(*node); 1004 const HTMLElement& element = toHTMLElement(*node);
1005 return element.hasTagName(blockquoteTag) && element.getAttribute("type") == "cite"; 1005 return element.hasTagName(blockquoteTag) && element.getAttribute("type") == "cite";
1006 } 1006 }
1007 1007
1008 int caretMinOffset(const Node* n) 1008 int caretMinOffset(const Node* n)
1009 { 1009 {
1010 RenderObject* r = n->renderer(); 1010 LayoutObject* r = n->renderer();
1011 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now. 1011 ASSERT(!n->isCharacterDataNode() || !r || r->isText()); // FIXME: This was a runtime check that seemingly couldn't fail; changed it to an assertion for now.
1012 return r ? r->caretMinOffset() : 0; 1012 return r ? r->caretMinOffset() : 0;
1013 } 1013 }
1014 1014
1015 // If a node can contain candidates for VisiblePositions, return the offset of t he last candidate, otherwise 1015 // If a node can contain candidates for VisiblePositions, return the offset of t he last candidate, otherwise
1016 // return the number of children for container nodes and the length for unrender ed text nodes. 1016 // return the number of children for container nodes and the length for unrender ed text nodes.
1017 int caretMaxOffset(const Node* n) 1017 int caretMaxOffset(const Node* n)
1018 { 1018 {
1019 // For rendered text nodes, return the last position that a caret could occu py. 1019 // For rendered text nodes, return the last position that a caret could occu py.
1020 if (n->isTextNode() && n->renderer()) 1020 if (n->isTextNode() && n->renderer())
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after
1128 if (endIsVisuallySame && comparePositions(selectedRange.startPosition(), pos itionInParentBeforeNode(node)) < 0) 1128 if (endIsVisuallySame && comparePositions(selectedRange.startPosition(), pos itionInParentBeforeNode(node)) < 0)
1129 return true; 1129 return true;
1130 1130
1131 return startIsVisuallySame && endIsVisuallySame; 1131 return startIsVisuallySame && endIsVisuallySame;
1132 } 1132 }
1133 1133
1134 bool isRenderedAsNonInlineTableImageOrHR(const Node* node) 1134 bool isRenderedAsNonInlineTableImageOrHR(const Node* node)
1135 { 1135 {
1136 if (!node) 1136 if (!node)
1137 return false; 1137 return false;
1138 RenderObject* renderer = node->renderer(); 1138 LayoutObject* renderer = node->renderer();
1139 return renderer && ((renderer->isTable() && !renderer->isInline()) || (rende rer->isImage() && !renderer->isInline()) || renderer->isHR()); 1139 return renderer && ((renderer->isTable() && !renderer->isInline()) || (rende rer->isImage() && !renderer->isInline()) || renderer->isHR());
1140 } 1140 }
1141 1141
1142 bool areIdenticalElements(const Node* first, const Node* second) 1142 bool areIdenticalElements(const Node* first, const Node* second)
1143 { 1143 {
1144 if (!first->isElementNode() || !second->isElementNode()) 1144 if (!first->isElementNode() || !second->isElementNode())
1145 return false; 1145 return false;
1146 1146
1147 const Element* firstElement = toElement(first); 1147 const Element* firstElement = toElement(first);
1148 const Element* secondElement = toElement(second); 1148 const Element* secondElement = toElement(second);
(...skipping 17 matching lines...) Expand all
1166 || element.hasTagName(xmpTag) 1166 || element.hasTagName(xmpTag)
1167 || element.hasTagName(h1Tag) 1167 || element.hasTagName(h1Tag)
1168 || element.hasTagName(h2Tag) 1168 || element.hasTagName(h2Tag)
1169 || element.hasTagName(h3Tag) 1169 || element.hasTagName(h3Tag)
1170 || element.hasTagName(h4Tag) 1170 || element.hasTagName(h4Tag)
1171 || element.hasTagName(h5Tag); 1171 || element.hasTagName(h5Tag);
1172 } 1172 }
1173 1173
1174 bool isBlockFlowElement(const Node& node) 1174 bool isBlockFlowElement(const Node& node)
1175 { 1175 {
1176 RenderObject* renderer = node.renderer(); 1176 LayoutObject* renderer = node.renderer();
1177 return node.isElementNode() && renderer && renderer->isRenderBlockFlow(); 1177 return node.isElementNode() && renderer && renderer->isRenderBlockFlow();
1178 } 1178 }
1179 1179
1180 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selec tion) 1180 Position adjustedSelectionStartForStyleComputation(const VisibleSelection& selec tion)
1181 { 1181 {
1182 // This function is used by range style computations to avoid bugs like: 1182 // This function is used by range style computations to avoid bugs like:
1183 // <rdar://problem/4017641> REGRESSION (Mail): you can only bold/unbold a se lection starting from end of line once 1183 // <rdar://problem/4017641> REGRESSION (Mail): you can only bold/unbold a se lection starting from end of line once
1184 // It is important to skip certain irrelevant content at the start of the se lection, so we do not wind up 1184 // It is important to skip certain irrelevant content at the start of the se lection, so we do not wind up
1185 // with a spurious "mixed" style. 1185 // with a spurious "mixed" style.
1186 1186
1187 VisiblePosition visiblePosition(selection.start()); 1187 VisiblePosition visiblePosition(selection.start());
1188 if (visiblePosition.isNull()) 1188 if (visiblePosition.isNull())
1189 return Position(); 1189 return Position();
1190 1190
1191 // if the selection is a caret, just return the position, since the style 1191 // if the selection is a caret, just return the position, since the style
1192 // behind us is relevant 1192 // behind us is relevant
1193 if (selection.isCaret()) 1193 if (selection.isCaret())
1194 return visiblePosition.deepEquivalent(); 1194 return visiblePosition.deepEquivalent();
1195 1195
1196 // if the selection starts just before a paragraph break, skip over it 1196 // if the selection starts just before a paragraph break, skip over it
1197 if (isEndOfParagraph(visiblePosition)) 1197 if (isEndOfParagraph(visiblePosition))
1198 return visiblePosition.next().deepEquivalent().downstream(); 1198 return visiblePosition.next().deepEquivalent().downstream();
1199 1199
1200 // otherwise, make sure to be at the start of the first selected node, 1200 // otherwise, make sure to be at the start of the first selected node,
1201 // instead of possibly at the end of the last node before the selection 1201 // instead of possibly at the end of the last node before the selection
1202 return visiblePosition.deepEquivalent().downstream(); 1202 return visiblePosition.deepEquivalent().downstream();
1203 } 1203 }
1204 1204
1205 } // namespace blink 1205 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.cpp ('k') | Source/core/editing/iterators/BitStack.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698