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

Side by Side Diff: third_party/WebKit/Source/core/editing/Position.cpp

Issue 1362283003: Make toPositionInComposedTree() with non-distributed node to return non-null position (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2015-09-24T18:07:50 Created 5 years, 2 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/PositionTest.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, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006, 2009 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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 } 378 }
379 379
380 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset); 380 fprintf(stderr, "Position [%s]: %s [%p] %s at %d\n", msg, anchorNode()->node Name().utf8().data(), anchorNode(), anchorType, m_offset);
381 } 381 }
382 382
383 PositionInComposedTree toPositionInComposedTree(const Position& pos) 383 PositionInComposedTree toPositionInComposedTree(const Position& pos)
384 { 384 {
385 if (pos.isNull()) 385 if (pos.isNull())
386 return PositionInComposedTree(); 386 return PositionInComposedTree();
387 387
388 PositionInComposedTree position;
389 if (pos.isOffsetInAnchor()) { 388 if (pos.isOffsetInAnchor()) {
390 Node* anchor = pos.anchorNode(); 389 Node* anchor = pos.anchorNode();
391 if (anchor->offsetInCharacters()) 390 if (anchor->offsetInCharacters())
392 return PositionInComposedTree(anchor, pos.computeOffsetInContainerNo de()); 391 return PositionInComposedTree(anchor, pos.computeOffsetInContainerNo de());
393 ASSERT(!isActiveInsertionPoint(*anchor)); 392 ASSERT(!isActiveInsertionPoint(*anchor));
394 int offset = pos.computeOffsetInContainerNode(); 393 int offset = pos.computeOffsetInContainerNode();
395 Node* child = NodeTraversal::childAt(*anchor, offset); 394 Node* child = NodeTraversal::childAt(*anchor, offset);
396 if (!child) { 395 if (!child) {
397 if (anchor->isShadowRoot()) 396 if (anchor->isShadowRoot())
398 return PositionInComposedTree(anchor->shadowHost(), PositionAnch orType::AfterChildren); 397 return PositionInComposedTree(anchor->shadowHost(), PositionAnch orType::AfterChildren);
399 return PositionInComposedTree(anchor, PositionAnchorType::AfterChild ren); 398 return PositionInComposedTree(anchor, PositionAnchorType::AfterChild ren);
400 } 399 }
401 child->updateDistribution(); 400 child->updateDistribution();
402 if (isActiveInsertionPoint(*child)) { 401 if (isActiveInsertionPoint(*child)) {
403 if (anchor->isShadowRoot()) 402 if (anchor->isShadowRoot())
404 return PositionInComposedTree(anchor->shadowHost(), offset); 403 return PositionInComposedTree(anchor->shadowHost(), offset);
405 return PositionInComposedTree(anchor, offset); 404 return PositionInComposedTree(anchor, offset);
406 } 405 }
407 return PositionInComposedTree(ComposedTreeTraversal::parent(*child), Com posedTreeTraversal::index(*child)); 406 if (Node* parent = ComposedTreeTraversal::parent(*child))
407 return PositionInComposedTree(parent, ComposedTreeTraversal::index(* child));
408 // When |pos| isn't appeared in composed tree, we map |pos| to after
409 // children of shadow host.
410 // e.g. "foo",0 in <progress>foo</progress>
411 if (anchor->isShadowRoot())
412 return PositionInComposedTree(anchor->shadowHost(), PositionAnchorTy pe::AfterChildren);
413 return PositionInComposedTree(anchor, PositionAnchorType::AfterChildren) ;
408 } 414 }
409 415
410 return PositionInComposedTree(pos.anchorNode(), pos.anchorType()); 416 return PositionInComposedTree(pos.anchorNode(), pos.anchorType());
411 } 417 }
412 418
413 Position toPositionInDOMTree(const Position& position) 419 Position toPositionInDOMTree(const Position& position)
414 { 420 {
415 return position; 421 return position;
416 } 422 }
417 423
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
530 536
531 void showTree(const blink::Position* pos) 537 void showTree(const blink::Position* pos)
532 { 538 {
533 if (pos) 539 if (pos)
534 pos->showTreeForThis(); 540 pos->showTreeForThis();
535 else 541 else
536 fprintf(stderr, "Cannot showTree for (nil)\n"); 542 fprintf(stderr, "Cannot showTree for (nil)\n");
537 } 543 }
538 544
539 #endif 545 #endif
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/PositionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698