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

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

Issue 281383006: Navigation transitions: Added createStyledMarkupForNavigationTransition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Review fixes 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
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const String& styleNodeCloseTag(bool isBlock = false); 139 const String& styleNodeCloseTag(bool isBlock = false);
140 virtual void appendText(StringBuilder& out, Text&) OVERRIDE; 140 virtual void appendText(StringBuilder& out, Text&) OVERRIDE;
141 String renderedText(Node&, const Range*); 141 String renderedText(Node&, const Range*);
142 String stringValueForRange(const Node&, const Range*); 142 String stringValueForRange(const Node&, const Range*);
143 void appendElement(StringBuilder& out, Element&, bool addDisplayInline, Rang eFullySelectsNode); 143 void appendElement(StringBuilder& out, Element&, bool addDisplayInline, Rang eFullySelectsNode);
144 virtual void appendElement(StringBuilder& out, Element& element, Namespaces* ) OVERRIDE { appendElement(out, element, false, DoesFullySelectNode); } 144 virtual void appendElement(StringBuilder& out, Element& element, Namespaces* ) OVERRIDE { appendElement(out, element, false, DoesFullySelectNode); }
145 145
146 enum NodeTraversalMode { EmitString, DoNotEmitString }; 146 enum NodeTraversalMode { EmitString, DoNotEmitString };
147 Node* traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTrav ersalMode); 147 Node* traverseNodesForSerialization(Node* startNode, Node* pastEnd, NodeTrav ersalMode);
148 148
149 bool shouldAnnotate() { return m_shouldAnnotate == AnnotateForInterchange; } 149 bool shouldAnnotate() const { return m_shouldAnnotate == AnnotateForIntercha nge || m_shouldAnnotate == AnnotateForNavigationTransition; }
150 bool shouldApplyWrappingStyle(const Node& node) const 150 bool shouldApplyWrappingStyle(const Node& node) const
151 { 151 {
152 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->paren tNode() == node.parentNode() 152 return m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->paren tNode() == node.parentNode()
153 && m_wrappingStyle && m_wrappingStyle->style(); 153 && m_wrappingStyle && m_wrappingStyle->style();
154 } 154 }
155 155
156 Vector<String> m_reversedPrecedingMarkup; 156 Vector<String> m_reversedPrecedingMarkup;
157 const EAnnotateForInterchange m_shouldAnnotate; 157 const EAnnotateForInterchange m_shouldAnnotate;
158 RawPtrWillBeMember<Node> m_highestNodeToBeSerialized; 158 RawPtrWillBeMember<Node> m_highestNodeToBeSerialized;
159 RefPtrWillBeMember<EditingStyle> m_wrappingStyle; 159 RefPtrWillBeMember<EditingStyle> m_wrappingStyle;
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 } else 310 } else
311 newInlineStyle = EditingStyle::create(); 311 newInlineStyle = EditingStyle::create();
312 312
313 if (element.isStyledElement() && element.inlineStyle()) 313 if (element.isStyledElement() && element.inlineStyle())
314 newInlineStyle->overrideWithStyle(element.inlineStyle()); 314 newInlineStyle->overrideWithStyle(element.inlineStyle());
315 315
316 if (shouldAnnotateOrForceInline) { 316 if (shouldAnnotateOrForceInline) {
317 if (shouldAnnotate()) 317 if (shouldAnnotate())
318 newInlineStyle->mergeStyleFromRulesForSerialization(&toHTMLEleme nt(element)); 318 newInlineStyle->mergeStyleFromRulesForSerialization(&toHTMLEleme nt(element));
319 319
320 if (&element == m_highestNodeToBeSerialized && m_shouldAnnotate == A nnotateForNavigationTransition)
321 newInlineStyle->addAbsolutePositioningFromElement(element);
322
320 if (addDisplayInline) 323 if (addDisplayInline)
321 newInlineStyle->forceInline(); 324 newInlineStyle->forceInline();
322 325
323 // If the node is not fully selected by the range, then we don't wan t to keep styles that affect its relationship to the nodes around it 326 // If the node is not fully selected by the range, then we don't wan t to keep styles that affect its relationship to the nodes around it
324 // only the ones that affect it and the nodes within it. 327 // only the ones that affect it and the nodes within it.
325 if (rangeFullySelectsNode == DoesNotFullySelectNode && newInlineStyl e->style()) 328 if (rangeFullySelectsNode == DoesNotFullySelectNode && newInlineStyl e->style())
326 newInlineStyle->style()->removeProperty(CSSPropertyFloat); 329 newInlineStyle->style()->removeProperty(CSSPropertyFloat);
327 } 330 }
328 331
329 if (!newInlineStyle->isEmpty()) { 332 if (!newInlineStyle->isEmpty()) {
330 out.appendLiteral(" style=\""); 333 out.appendLiteral(" style=\"");
331 appendAttributeValue(out, newInlineStyle->style()->asText(), documen tIsHTML); 334 appendAttributeValue(out, newInlineStyle->style()->asText(), documen tIsHTML);
332 out.append('\"'); 335 out.append('\"');
333 } 336 }
334 } 337 }
335 338
336 appendCloseTag(out, element); 339 appendCloseTag(out, element);
337 } 340 }
338 341
339 Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd) 342 Node* StyledMarkupAccumulator::serializeNodes(Node* startNode, Node* pastEnd)
340 { 343 {
341 if (!m_highestNodeToBeSerialized) { 344 if (!m_highestNodeToBeSerialized) {
342 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, DoN otEmitString); 345 Node* lastClosed = traverseNodesForSerialization(startNode, pastEnd, DoN otEmitString);
343 m_highestNodeToBeSerialized = lastClosed; 346 m_highestNodeToBeSerialized = lastClosed;
344 } 347 }
345 348
346 if (m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNode() ) 349 if (m_highestNodeToBeSerialized && m_highestNodeToBeSerialized->parentNode() ) {
347 m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(m_highestN odeToBeSerialized->parentNode(), shouldAnnotate()); 350 m_wrappingStyle = EditingStyle::wrappingStyleForSerialization(m_highestN odeToBeSerialized->parentNode(), shouldAnnotate());
351 if (m_shouldAnnotate == AnnotateForNavigationTransition) {
352 m_wrappingStyle->style()->removeProperty(CSSPropertyBackgroundColor) ;
353 m_wrappingStyle->style()->removeProperty(CSSPropertyBackgroundImage) ;
354 }
355 }
356
348 357
349 return traverseNodesForSerialization(startNode, pastEnd, EmitString); 358 return traverseNodesForSerialization(startNode, pastEnd, EmitString);
350 } 359 }
351 360
352 Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No de* pastEnd, NodeTraversalMode traversalMode) 361 Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No de* pastEnd, NodeTraversalMode traversalMode)
353 { 362 {
354 const bool shouldEmit = traversalMode == EmitString; 363 const bool shouldEmit = traversalMode == EmitString;
355 WillBeHeapVector<RawPtrWillBeMember<Node> > ancestorsToClose; 364 WillBeHeapVector<RawPtrWillBeMember<Node> > ancestorsToClose;
356 Node* next; 365 Node* next;
357 Node* lastClosed = 0; 366 Node* lastClosed = 0;
358 for (Node* n = startNode; n != pastEnd; n = next) { 367 for (Node* n = startNode; n != pastEnd; n = next) {
359 // According to <rdar://problem/5730668>, it is possible for n to blow 368 // According to <rdar://problem/5730668>, it is possible for n to blow
360 // past pastEnd and become null here. This shouldn't be possible. 369 // past pastEnd and become null here. This shouldn't be possible.
361 // This null check will prevent crashes (but create too much markup) 370 // This null check will prevent crashes (but create too much markup)
362 // and the ASSERT will hopefully lead us to understanding the problem. 371 // and the ASSERT will hopefully lead us to understanding the problem.
363 ASSERT(n); 372 ASSERT(n);
364 if (!n) 373 if (!n)
365 break; 374 break;
366 375
367 next = NodeTraversal::next(*n); 376 next = NodeTraversal::next(*n);
368 bool openedTag = false; 377 bool openedTag = false;
369 378
370 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) 379 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd)
371 // Don't write out empty block containers that aren't fully selected . 380 // Don't write out empty block containers that aren't fully selected .
372 continue; 381 continue;
373 382
374 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag)) { 383 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag) && m_shouldAnnotate != AnnotateForNavigationTransition) {
375 next = NodeTraversal::nextSkippingChildren(*n); 384 next = NodeTraversal::nextSkippingChildren(*n);
376 // Don't skip over pastEnd. 385 // Don't skip over pastEnd.
377 if (pastEnd && pastEnd->isDescendantOf(n)) 386 if (pastEnd && pastEnd->isDescendantOf(n))
378 next = pastEnd; 387 next = pastEnd;
379 } else { 388 } else {
380 // Add the node to the markup if we're not skipping the descendants 389 // Add the node to the markup if we're not skipping the descendants
381 if (shouldEmit) 390 if (shouldEmit)
382 appendStartTag(*n); 391 appendStartTag(*n);
383 392
384 // If node has no children, close the tag now. 393 // If node has no children, close the tag now.
(...skipping 703 matching lines...) Expand 10 before | Expand all | Expand 10 after
1088 if (!next || !next->isTextNode()) 1097 if (!next || !next->isTextNode())
1089 return; 1098 return;
1090 1099
1091 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); 1100 RefPtrWillBeRawPtr<Text> textNode = toText(node.get());
1092 RefPtrWillBeRawPtr<Text> textNext = toText(next); 1101 RefPtrWillBeRawPtr<Text> textNext = toText(next);
1093 textNode->appendData(textNext->data()); 1102 textNode->appendData(textNext->data());
1094 if (textNext->parentNode()) // Might have been removed by mutation event. 1103 if (textNext->parentNode()) // Might have been removed by mutation event.
1095 textNext->remove(exceptionState); 1104 textNext->remove(exceptionState);
1096 } 1105 }
1097 1106
1107 String createStyledMarkupForNavigationTransition(Node* node)
1108 {
1109 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0);
esprehn 2014/07/14 22:04:31 What updates the style of the page before you get
oystein (OOO til 10th of July) 2014/07/14 22:44:57 Not sure what you're asking here, exactly. If ther
1110 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ;
1111
1112 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">";
1113 return documentMarkup + accumulator.takeResults();
1098 } 1114 }
1115
1116 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698