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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 | 145 |
| 146 template <typename Strategy> | 146 template <typename Strategy> |
| 147 static bool needInterchangeNewlineAt(const VisiblePositionTemplate<Strategy>& v) | 147 static bool needInterchangeNewlineAt(const VisiblePositionTemplate<Strategy>& v) |
| 148 { | 148 { |
| 149 return needInterchangeNewlineAfter(previousPositionOf(v)); | 149 return needInterchangeNewlineAfter(previousPositionOf(v)); |
| 150 } | 150 } |
| 151 | 151 |
| 152 template<typename Strategy> | 152 template<typename Strategy> |
| 153 static bool areSameRanges(Node* node, const PositionTemplate<Strategy>& startPos ition, const PositionTemplate<Strategy>& endPosition) | 153 static bool areSameRanges(Node* node, const PositionTemplate<Strategy>& startPos ition, const PositionTemplate<Strategy>& endPosition) |
| 154 { | 154 { |
| 155 ASSERT(node); | 155 DCHECK(node); |
| 156 const EphemeralRange range = VisibleSelection::selectionFromContentsOfNode(n ode).toNormalizedEphemeralRange(); | 156 const EphemeralRange range = VisibleSelection::selectionFromContentsOfNode(n ode).toNormalizedEphemeralRange(); |
| 157 return toPositionInDOMTree(startPosition) == range.startPosition() && toPosi tionInDOMTree(endPosition) == range.endPosition(); | 157 return toPositionInDOMTree(startPosition) == range.startPosition() && toPosi tionInDOMTree(endPosition) == range.endPosition(); |
| 158 } | 158 } |
| 159 | 159 |
| 160 static EditingStyle* styleFromMatchedRulesAndInlineDecl(const HTMLElement* eleme nt) | 160 static EditingStyle* styleFromMatchedRulesAndInlineDecl(const HTMLElement* eleme nt) |
| 161 { | 161 { |
| 162 EditingStyle* style = EditingStyle::create(element->inlineStyle()); | 162 EditingStyle* style = EditingStyle::create(element->inlineStyle()); |
| 163 // FIXME: Having to const_cast here is ugly, but it is quite a bit of work t o untangle | 163 // FIXME: Having to const_cast here is ugly, but it is quite a bit of work t o untangle |
| 164 // the non-const-ness of styleFromMatchedRulesForElement. | 164 // the non-const-ness of styleFromMatchedRulesForElement. |
| 165 style->mergeStyleFromRules(const_cast<HTMLElement*>(element)); | 165 style->mergeStyleFromRules(const_cast<HTMLElement*>(element)); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 190 } | 190 } |
| 191 | 191 |
| 192 if (!m_lastClosed) | 192 if (!m_lastClosed) |
| 193 m_lastClosed = StyledMarkupTraverser<Strategy>().traverse(firstNode, pas tEnd); | 193 m_lastClosed = StyledMarkupTraverser<Strategy>().traverse(firstNode, pas tEnd); |
| 194 StyledMarkupTraverser<Strategy> traverser(&markupAccumulator, m_lastClosed); | 194 StyledMarkupTraverser<Strategy> traverser(&markupAccumulator, m_lastClosed); |
| 195 Node* lastClosed = traverser.traverse(firstNode, pastEnd); | 195 Node* lastClosed = traverser.traverse(firstNode, pastEnd); |
| 196 | 196 |
| 197 if (m_highestNodeToBeSerialized && lastClosed) { | 197 if (m_highestNodeToBeSerialized && lastClosed) { |
| 198 // TODO(hajimehoshi): This is calculated at createMarkupInternal too. | 198 // TODO(hajimehoshi): This is calculated at createMarkupInternal too. |
| 199 Node* commonAncestor = Strategy::commonAncestor(*m_start.computeContaine rNode(), *m_end.computeContainerNode()); | 199 Node* commonAncestor = Strategy::commonAncestor(*m_start.computeContaine rNode(), *m_end.computeContainerNode()); |
| 200 ASSERT(commonAncestor); | 200 DCHECK(commonAncestor); |
| 201 HTMLBodyElement* body = toHTMLBodyElement(enclosingElementWithTag(firstP ositionInNode(commonAncestor), bodyTag)); | 201 HTMLBodyElement* body = toHTMLBodyElement(enclosingElementWithTag(firstP ositionInNode(commonAncestor), bodyTag)); |
| 202 HTMLBodyElement* fullySelectedRoot = nullptr; | 202 HTMLBodyElement* fullySelectedRoot = nullptr; |
| 203 // FIXME: Do this for all fully selected blocks, not just the body. | 203 // FIXME: Do this for all fully selected blocks, not just the body. |
| 204 if (body && areSameRanges(body, m_start, m_end)) | 204 if (body && areSameRanges(body, m_start, m_end)) |
| 205 fullySelectedRoot = body; | 205 fullySelectedRoot = body; |
| 206 | 206 |
| 207 // Also include all of the ancestors of lastClosed up to this special an cestor. | 207 // Also include all of the ancestors of lastClosed up to this special an cestor. |
| 208 // FIXME: What is ancestor? | 208 // FIXME: What is ancestor? |
| 209 for (ContainerNode* ancestor = Strategy::parent(*lastClosed); ancestor; ancestor = Strategy::parent(*ancestor)) { | 209 for (ContainerNode* ancestor = Strategy::parent(*lastClosed); ancestor; ancestor = Strategy::parent(*ancestor)) { |
| 210 if (ancestor == fullySelectedRoot && !markupAccumulator.convertBlock sToInlines()) { | 210 if (ancestor == fullySelectedRoot && !markupAccumulator.convertBlock sToInlines()) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 255 { | 255 { |
| 256 } | 256 } |
| 257 | 257 |
| 258 template<typename Strategy> | 258 template<typename Strategy> |
| 259 StyledMarkupTraverser<Strategy>::StyledMarkupTraverser(StyledMarkupAccumulator* accumulator, Node* lastClosed) | 259 StyledMarkupTraverser<Strategy>::StyledMarkupTraverser(StyledMarkupAccumulator* accumulator, Node* lastClosed) |
| 260 : m_accumulator(accumulator) | 260 : m_accumulator(accumulator) |
| 261 , m_lastClosed(lastClosed) | 261 , m_lastClosed(lastClosed) |
| 262 , m_wrappingStyle(nullptr) | 262 , m_wrappingStyle(nullptr) |
| 263 { | 263 { |
| 264 if (!m_accumulator) { | 264 if (!m_accumulator) { |
| 265 ASSERT(!m_lastClosed); | 265 DCHECK(!m_lastClosed); |
|
yosin_UTC9
2016/04/14 04:35:04
|DCHECK_EQ(m_lastClosed, nullptr)|
| |
| 266 return; | 266 return; |
| 267 } | 267 } |
| 268 if (!m_lastClosed) | 268 if (!m_lastClosed) |
| 269 return; | 269 return; |
| 270 ContainerNode* parent = Strategy::parent(*m_lastClosed); | 270 ContainerNode* parent = Strategy::parent(*m_lastClosed); |
| 271 if (!parent) | 271 if (!parent) |
| 272 return; | 272 return; |
| 273 if (shouldAnnotate()) { | 273 if (shouldAnnotate()) { |
| 274 m_wrappingStyle = EditingStyle::wrappingStyleForAnnotatedSerialization(p arent); | 274 m_wrappingStyle = EditingStyle::wrappingStyleForAnnotatedSerialization(p arent); |
| 275 return; | 275 return; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 316 } | 316 } |
| 317 | 317 |
| 318 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors. | 318 // If we didn't insert open tag and there's no more siblings or we're at the end of the traversal, take care of ancestors. |
| 319 // FIXME: What happens if we just inserted open tag and reached the end? | 319 // FIXME: What happens if we just inserted open tag and reached the end? |
| 320 if (Strategy::nextSibling(*n) && next != pastEnd) | 320 if (Strategy::nextSibling(*n) && next != pastEnd) |
| 321 continue; | 321 continue; |
| 322 | 322 |
| 323 // Close up the ancestors. | 323 // Close up the ancestors. |
| 324 while (!ancestorsToClose.isEmpty()) { | 324 while (!ancestorsToClose.isEmpty()) { |
| 325 ContainerNode* ancestor = ancestorsToClose.last(); | 325 ContainerNode* ancestor = ancestorsToClose.last(); |
| 326 ASSERT(ancestor); | 326 DCHECK(ancestor); |
| 327 if (next && next != pastEnd && Strategy::isDescendantOf(*next, *ance stor)) | 327 if (next && next != pastEnd && Strategy::isDescendantOf(*next, *ance stor)) |
| 328 break; | 328 break; |
| 329 // Not at the end of the range, close ancestors up to sibling of nex t node. | 329 // Not at the end of the range, close ancestors up to sibling of nex t node. |
| 330 appendEndMarkup(*ancestor); | 330 appendEndMarkup(*ancestor); |
| 331 lastClosed = ancestor; | 331 lastClosed = ancestor; |
| 332 ancestorsToClose.removeLast(); | 332 ancestorsToClose.removeLast(); |
| 333 } | 333 } |
| 334 | 334 |
| 335 // Surround the currently accumulated markup with markup for ancestors w e never opened as we leave the subtree(s) rooted at those ancestors. | 335 // Surround the currently accumulated markup with markup for ancestors w e never opened as we leave the subtree(s) rooted at those ancestors. |
| 336 ContainerNode* nextParent = next ? Strategy::parent(*next) : nullptr; | 336 ContainerNode* nextParent = next ? Strategy::parent(*next) : nullptr; |
| 337 if (next == pastEnd || n == nextParent) | 337 if (next == pastEnd || n == nextParent) |
| 338 continue; | 338 continue; |
| 339 | 339 |
| 340 ASSERT(n); | 340 DCHECK(n); |
| 341 Node* lastAncestorClosedOrSelf = (lastClosed && Strategy::isDescendantOf (*n, *lastClosed)) ? lastClosed : n; | 341 Node* lastAncestorClosedOrSelf = (lastClosed && Strategy::isDescendantOf (*n, *lastClosed)) ? lastClosed : n; |
| 342 for (ContainerNode* parent = Strategy::parent(*lastAncestorClosedOrSelf) ; parent && parent != nextParent; parent = Strategy::parent(*parent)) { | 342 for (ContainerNode* parent = Strategy::parent(*lastAncestorClosedOrSelf) ; parent && parent != nextParent; parent = Strategy::parent(*parent)) { |
| 343 // All ancestors that aren't in the ancestorsToClose list should eit her be a) unrendered: | 343 // All ancestors that aren't in the ancestorsToClose list should eit her be a) unrendered: |
| 344 if (!parent->layoutObject()) | 344 if (!parent->layoutObject()) |
| 345 continue; | 345 continue; |
| 346 // or b) ancestors that we never encountered during a pre-order trav ersal starting at startNode: | 346 // or b) ancestors that we never encountered during a pre-order trav ersal starting at startNode: |
| 347 ASSERT(startNode); | 347 DCHECK(startNode); |
| 348 ASSERT(Strategy::isDescendantOf(*startNode, *parent)); | 348 DCHECK(Strategy::isDescendantOf(*startNode, *parent)); |
|
yosin_UTC9
2016/04/14 04:35:04
How about adding |<< startNode << ' ' << parent|?
| |
| 349 EditingStyle* style = createInlineStyleIfNeeded(*parent); | 349 EditingStyle* style = createInlineStyleIfNeeded(*parent); |
| 350 wrapWithNode(*parent, style); | 350 wrapWithNode(*parent, style); |
| 351 lastClosed = parent; | 351 lastClosed = parent; |
| 352 } | 352 } |
| 353 } | 353 } |
| 354 | 354 |
| 355 return lastClosed; | 355 return lastClosed; |
| 356 } | 356 } |
| 357 | 357 |
| 358 template<typename Strategy> | 358 template<typename Strategy> |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 474 if (element.isHTMLElement() && shouldAnnotate()) | 474 if (element.isHTMLElement() && shouldAnnotate()) |
| 475 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element) ); | 475 inlineStyle->mergeStyleFromRulesForSerialization(&toHTMLElement(element) ); |
| 476 | 476 |
| 477 return inlineStyle; | 477 return inlineStyle; |
| 478 } | 478 } |
| 479 | 479 |
| 480 template class StyledMarkupSerializer<EditingStrategy>; | 480 template class StyledMarkupSerializer<EditingStrategy>; |
| 481 template class StyledMarkupSerializer<EditingInFlatTreeStrategy>; | 481 template class StyledMarkupSerializer<EditingInFlatTreeStrategy>; |
| 482 | 482 |
| 483 } // namespace blink | 483 } // namespace blink |
| OLD | NEW |