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

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

Issue 420603002: Use tighter typing in editing/ (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase Created 6 years, 5 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.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) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed. 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserv ed.
3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2008, 2009, 2010, 2011 Google Inc. All rights reserved.
4 * Copyright (C) 2011 Igalia S.L. 4 * Copyright (C) 2011 Igalia S.L.
5 * Copyright (C) 2011 Motorola Mobility. All rights reserved. 5 * Copyright (C) 2011 Motorola Mobility. All rights reserved.
6 * 6 *
7 * Redistribution and use in source and binary forms, with or without 7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions 8 * modification, are permitted provided that the following conditions
9 * are met: 9 * are met:
10 * 1. Redistributions of source code must retain the above copyright 10 * 1. Redistributions of source code must retain the above copyright
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
46 #include "core/dom/Range.h" 46 #include "core/dom/Range.h"
47 #include "core/editing/Editor.h" 47 #include "core/editing/Editor.h"
48 #include "core/editing/MarkupAccumulator.h" 48 #include "core/editing/MarkupAccumulator.h"
49 #include "core/editing/TextIterator.h" 49 #include "core/editing/TextIterator.h"
50 #include "core/editing/VisibleSelection.h" 50 #include "core/editing/VisibleSelection.h"
51 #include "core/editing/VisibleUnits.h" 51 #include "core/editing/VisibleUnits.h"
52 #include "core/editing/htmlediting.h" 52 #include "core/editing/htmlediting.h"
53 #include "core/frame/LocalFrame.h" 53 #include "core/frame/LocalFrame.h"
54 #include "core/html/HTMLBodyElement.h" 54 #include "core/html/HTMLBodyElement.h"
55 #include "core/html/HTMLElement.h" 55 #include "core/html/HTMLElement.h"
56 #include "core/html/HTMLSpanElement.h"
56 #include "core/html/HTMLTableCellElement.h" 57 #include "core/html/HTMLTableCellElement.h"
57 #include "core/html/HTMLTextFormControlElement.h" 58 #include "core/html/HTMLTextFormControlElement.h"
58 #include "core/rendering/RenderObject.h" 59 #include "core/rendering/RenderObject.h"
59 #include "platform/weborigin/KURL.h" 60 #include "platform/weborigin/KURL.h"
60 #include "wtf/StdLibExtras.h" 61 #include "wtf/StdLibExtras.h"
61 #include "wtf/text/StringBuilder.h" 62 #include "wtf/text/StringBuilder.h"
62 63
63 namespace blink { 64 namespace blink {
64 65
65 using namespace HTMLNames; 66 using namespace HTMLNames;
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 wrappingStyle->forceInline(); 232 wrappingStyle->forceInline();
232 // FIXME: Should this be included in forceInline? 233 // FIXME: Should this be included in forceInline?
233 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone); 234 wrappingStyle->style()->setProperty(CSSPropertyFloat, CSSValueNone);
234 235
235 appendStyleNodeOpenTag(out, wrappingStyle->style(), text.document()); 236 appendStyleNodeOpenTag(out, wrappingStyle->style(), text.document());
236 } 237 }
237 238
238 if (!shouldAnnotate() || parentIsTextarea) 239 if (!shouldAnnotate() || parentIsTextarea)
239 MarkupAccumulator::appendText(out, text); 240 MarkupAccumulator::appendText(out, text);
240 else { 241 else {
241 const bool useRenderedText = !enclosingNodeWithTag(firstPositionInNode(& text), selectTag); 242 const bool useRenderedText = !enclosingElementWithTag(firstPositionInNod e(&text), selectTag);
242 String content = useRenderedText ? renderedText(text, m_range) : stringV alueForRange(text, m_range); 243 String content = useRenderedText ? renderedText(text, m_range) : stringV alueForRange(text, m_range);
243 StringBuilder buffer; 244 StringBuilder buffer;
244 appendCharactersReplacingEntities(buffer, content, 0, content.length(), EntityMaskInPCDATA); 245 appendCharactersReplacingEntities(buffer, content, 0, content.length(), EntityMaskInPCDATA);
245 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text)); 246 out.append(convertHTMLTextToInterchangeFormat(buffer.toString(), text));
246 } 247 }
247 248
248 if (wrappingSpan) 249 if (wrappingSpan)
249 out.append(styleNodeCloseTag()); 250 out.append(styleNodeCloseTag());
250 } 251 }
251 252
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 if (!n) 374 if (!n)
374 break; 375 break;
375 376
376 next = NodeTraversal::next(*n); 377 next = NodeTraversal::next(*n);
377 bool openedTag = false; 378 bool openedTag = false;
378 379
379 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) 380 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
380 // Don't write out empty block containers that aren't fully selected . 381 // Don't write out empty block containers that aren't fully selected .
381 continue; 382 continue;
382 383
383 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag) && m_shouldAnnotate != AnnotateForNavigationTransition) { 384 if (!n->renderer() && !enclosingElementWithTag(firstPositionInOrBeforeNo de(n), selectTag) && m_shouldAnnotate != AnnotateForNavigationTransition) {
384 next = NodeTraversal::nextSkippingChildren(*n); 385 next = NodeTraversal::nextSkippingChildren(*n);
385 // Don't skip over pastEnd. 386 // Don't skip over pastEnd.
386 if (pastEnd && pastEnd->isDescendantOf(n)) 387 if (pastEnd && pastEnd->isDescendantOf(n))
387 next = pastEnd; 388 next = pastEnd;
388 } else { 389 } else {
389 // Add the node to the markup if we're not skipping the descendants 390 // Add the node to the markup if we're not skipping the descendants
390 if (shouldEmit) 391 if (shouldEmit)
391 appendStartTag(*n); 392 appendStartTag(*n);
392 393
393 // If node has no children, close the tag now. 394 // If node has no children, close the tag now.
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (newSpecialCommonAncestor) 545 if (newSpecialCommonAncestor)
545 specialCommonAncestor = newSpecialCommonAncestor; 546 specialCommonAncestor = newSpecialCommonAncestor;
546 } 547 }
547 548
548 // If a single tab is selected, commonAncestor will be a text node inside a tab span. 549 // If a single tab is selected, commonAncestor will be a text node inside a tab span.
549 // If two or more tabs are selected, commonAncestor will be the tab span. 550 // If two or more tabs are selected, commonAncestor will be the tab span.
550 // In either case, if there is a specialCommonAncestor already, it will nece ssarily be above 551 // In either case, if there is a specialCommonAncestor already, it will nece ssarily be above
551 // any tab span that needs to be included. 552 // any tab span that needs to be included.
552 if (!specialCommonAncestor && isTabSpanTextNode(commonAncestor)) 553 if (!specialCommonAncestor && isTabSpanTextNode(commonAncestor))
553 specialCommonAncestor = commonAncestor->parentNode(); 554 specialCommonAncestor = commonAncestor->parentNode();
554 if (!specialCommonAncestor && isTabSpanNode(commonAncestor)) 555 if (!specialCommonAncestor && isTabSpanElement(commonAncestor))
555 specialCommonAncestor = commonAncestor; 556 specialCommonAncestor = commonAncestor;
556 557
557 if (Node *enclosingAnchor = enclosingNodeWithTag(firstPositionInNode(special CommonAncestor ? specialCommonAncestor : commonAncestor), aTag)) 558 if (Element* enclosingAnchor = enclosingElementWithTag(firstPositionInNode(s pecialCommonAncestor ? specialCommonAncestor : commonAncestor), aTag))
558 specialCommonAncestor = enclosingAnchor; 559 specialCommonAncestor = enclosingAnchor;
559 560
560 return specialCommonAncestor; 561 return specialCommonAncestor;
561 } 562 }
562 563
563 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha nge? 564 // FIXME: Shouldn't we omit style info when annotate == DoNotAnnotateForIntercha nge?
564 // FIXME: At least, annotation and style info should probably not be included in range.markupString() 565 // FIXME: At least, annotation and style info should probably not be included in range.markupString()
565 static String createMarkupInternal(Document& document, const Range* range, const Range* updatedRange, WillBeHeapVector<RawPtrWillBeMember<Node> >* nodes, 566 static String createMarkupInternal(Document& document, const Range* range, const Range* updatedRange, WillBeHeapVector<RawPtrWillBeMember<Node> >* nodes,
566 EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsolu teURLs shouldResolveURLs, Node* constrainingAncestor) 567 EAnnotateForInterchange shouldAnnotate, bool convertBlocksToInlines, EAbsolu teURLs shouldResolveURLs, Node* constrainingAncestor)
567 { 568 {
568 ASSERT(range); 569 ASSERT(range);
569 ASSERT(updatedRange); 570 ASSERT(updatedRange);
570 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">")); 571 DEFINE_STATIC_LOCAL(const String, interchangeNewlineString, ("<br class=\"" AppleInterchangeNewline "\">"));
571 572
572 bool collapsed = updatedRange->collapsed(); 573 bool collapsed = updatedRange->collapsed();
573 if (collapsed) 574 if (collapsed)
574 return emptyString(); 575 return emptyString();
575 Node* commonAncestor = updatedRange->commonAncestorContainer(); 576 Node* commonAncestor = updatedRange->commonAncestorContainer();
576 if (!commonAncestor) 577 if (!commonAncestor)
577 return emptyString(); 578 return emptyString();
578 579
579 document.updateLayoutIgnorePendingStylesheets(); 580 document.updateLayoutIgnorePendingStylesheets();
580 581
581 Node* body = enclosingNodeWithTag(firstPositionInNode(commonAncestor), bodyT ag); 582 Element* body = enclosingElementWithTag(firstPositionInNode(commonAncestor), bodyTag);
582 Node* fullySelectedRoot = 0; 583 Node* fullySelectedRoot = 0;
583 // FIXME: Do this for all fully selected blocks, not just the body. 584 // FIXME: Do this for all fully selected blocks, not just the body.
584 if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(bod y).toNormalizedRange().get(), range)) 585 if (body && areRangesEqual(VisibleSelection::selectionFromContentsOfNode(bod y).toNormalizedRange().get(), range))
585 fullySelectedRoot = body; 586 fullySelectedRoot = body;
586 Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shou ldAnnotate, constrainingAncestor); 587 Node* specialCommonAncestor = highestAncestorToWrapMarkup(updatedRange, shou ldAnnotate, constrainingAncestor);
587 StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate , updatedRange, specialCommonAncestor); 588 StyledMarkupAccumulator accumulator(nodes, shouldResolveURLs, shouldAnnotate , updatedRange, specialCommonAncestor);
588 Node* pastEnd = updatedRange->pastLastNode(); 589 Node* pastEnd = updatedRange->pastLastNode();
589 590
590 Node* startNode = updatedRange->firstNode(); 591 Node* startNode = updatedRange->firstNode();
591 VisiblePosition visibleStart(updatedRange->startPosition(), VP_DEFAULT_AFFIN ITY); 592 VisiblePosition visibleStart(updatedRange->startPosition(), VP_DEFAULT_AFFIN ITY);
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1110 node->document().updateLayoutIgnorePendingStylesheets(); 1111 node->document().updateLayoutIgnorePendingStylesheets();
1111 1112
1112 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0); 1113 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0);
1113 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ; 1114 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ;
1114 1115
1115 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">"; 1116 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">";
1116 return documentMarkup + accumulator.takeResults(); 1117 return documentMarkup + accumulator.takeResults();
1117 } 1118 }
1118 1119
1119 } 1120 }
OLDNEW
« no previous file with comments | « Source/core/editing/htmlediting.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698