Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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) | |
|
esprehn
2014/06/26 09:32:55
You don't need the &
oystein (OOO til 10th of July)
2014/06/26 23:13:43
I do, m_highestNodeToBeSerialized is a RawPtrWillB
| |
| 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(CSSPropertyBackground); | |
|
esprehn
2014/06/26 09:32:55
This doesn't work, background is a shorthand so yo
oystein (OOO til 10th of July)
2014/06/26 23:13:43
Done.
| |
| 353 } | |
| 354 | |
| 348 | 355 |
| 349 return traverseNodesForSerialization(startNode, pastEnd, EmitString); | 356 return traverseNodesForSerialization(startNode, pastEnd, EmitString); |
| 350 } | 357 } |
| 351 | 358 |
| 352 Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No de* pastEnd, NodeTraversalMode traversalMode) | 359 Node* StyledMarkupAccumulator::traverseNodesForSerialization(Node* startNode, No de* pastEnd, NodeTraversalMode traversalMode) |
| 353 { | 360 { |
| 354 const bool shouldEmit = traversalMode == EmitString; | 361 const bool shouldEmit = traversalMode == EmitString; |
| 355 WillBeHeapVector<RawPtrWillBeMember<Node> > ancestorsToClose; | 362 WillBeHeapVector<RawPtrWillBeMember<Node> > ancestorsToClose; |
| 356 Node* next; | 363 Node* next; |
| 357 Node* lastClosed = 0; | 364 Node* lastClosed = 0; |
| 358 for (Node* n = startNode; n != pastEnd; n = next) { | 365 for (Node* n = startNode; n != pastEnd; n = next) { |
| 359 // According to <rdar://problem/5730668>, it is possible for n to blow | 366 // According to <rdar://problem/5730668>, it is possible for n to blow |
| 360 // past pastEnd and become null here. This shouldn't be possible. | 367 // past pastEnd and become null here. This shouldn't be possible. |
| 361 // This null check will prevent crashes (but create too much markup) | 368 // This null check will prevent crashes (but create too much markup) |
| 362 // and the ASSERT will hopefully lead us to understanding the problem. | 369 // and the ASSERT will hopefully lead us to understanding the problem. |
| 363 ASSERT(n); | 370 ASSERT(n); |
| 364 if (!n) | 371 if (!n) |
| 365 break; | 372 break; |
| 366 | 373 |
| 367 next = NodeTraversal::next(*n); | 374 next = NodeTraversal::next(*n); |
| 368 bool openedTag = false; | 375 bool openedTag = false; |
| 369 | 376 |
| 370 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) | 377 if (isBlock(n) && canHaveChildrenForEditing(n) && next == pastEnd) |
| 371 // Don't write out empty block containers that aren't fully selected . | 378 // Don't write out empty block containers that aren't fully selected . |
| 372 continue; | 379 continue; |
| 373 | 380 |
| 374 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag)) { | 381 if (!n->renderer() && !enclosingNodeWithTag(firstPositionInOrBeforeNode( n), selectTag) && m_shouldAnnotate != AnnotateForNavigationTransition) { |
| 375 next = NodeTraversal::nextSkippingChildren(*n); | 382 next = NodeTraversal::nextSkippingChildren(*n); |
| 376 // Don't skip over pastEnd. | 383 // Don't skip over pastEnd. |
| 377 if (pastEnd && pastEnd->isDescendantOf(n)) | 384 if (pastEnd && pastEnd->isDescendantOf(n)) |
| 378 next = pastEnd; | 385 next = pastEnd; |
| 379 } else { | 386 } else { |
| 380 // Add the node to the markup if we're not skipping the descendants | 387 // Add the node to the markup if we're not skipping the descendants |
| 381 if (shouldEmit) | 388 if (shouldEmit) |
| 382 appendStartTag(*n); | 389 appendStartTag(*n); |
| 383 | 390 |
| 384 // If node has no children, close the tag now. | 391 // If node has no children, close the tag now. |
| (...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 if (!next || !next->isTextNode()) | 1083 if (!next || !next->isTextNode()) |
| 1077 return; | 1084 return; |
| 1078 | 1085 |
| 1079 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); | 1086 RefPtrWillBeRawPtr<Text> textNode = toText(node.get()); |
| 1080 RefPtrWillBeRawPtr<Text> textNext = toText(next); | 1087 RefPtrWillBeRawPtr<Text> textNext = toText(next); |
| 1081 textNode->appendData(textNext->data()); | 1088 textNode->appendData(textNext->data()); |
| 1082 if (textNext->parentNode()) // Might have been removed by mutation event. | 1089 if (textNext->parentNode()) // Might have been removed by mutation event. |
| 1083 textNext->remove(exceptionState); | 1090 textNext->remove(exceptionState); |
| 1084 } | 1091 } |
| 1085 | 1092 |
| 1093 String createStyledMarkupForNavigationTransition(Node* node) | |
| 1094 { | |
| 1095 StyledMarkupAccumulator accumulator(0, ResolveAllURLs, AnnotateForNavigation Transition, nullptr, 0); | |
| 1096 accumulator.serializeNodes(node, NodeTraversal::nextSkippingChildren(*node)) ; | |
| 1097 | |
| 1098 static const char* documentMarkup = "<!DOCTYPE html><meta name=\"viewport\" content=\"width=device-width, user-scalable=0\">"; | |
|
esprehn
2014/06/26 09:32:55
Why not use the meta viewport from the original do
oystein (OOO til 10th of July)
2014/06/26 23:13:43
The idea is that we'll enforce the whole navigatio
| |
| 1099 return documentMarkup + accumulator.takeResults(); | |
| 1086 } | 1100 } |
| 1101 | |
| 1102 } | |
| OLD | NEW |