OLD | NEW |
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 474 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
485 { | 485 { |
486 return mostForwardCaretPosition(*this, rule); | 486 return mostForwardCaretPosition(*this, rule); |
487 } | 487 } |
488 | 488 |
489 template <typename Strategy> | 489 template <typename Strategy> |
490 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::downstream(EditingBound
aryCrossingRule rule) const | 490 PositionAlgorithm<Strategy> PositionAlgorithm<Strategy>::downstream(EditingBound
aryCrossingRule rule) const |
491 { | 491 { |
492 return mostBackwardCaretPosition(*this, rule); | 492 return mostBackwardCaretPosition(*this, rule); |
493 } | 493 } |
494 | 494 |
| 495 // TODO(yosin) We should move |isVisuallyEquivalentCandidate()| to |
| 496 // "VisibleUnits.cpp" to reduce |LayoutObject| dependency in "Position.cpp". |
495 template <typename Strategy> | 497 template <typename Strategy> |
496 bool PositionAlgorithm<Strategy>::isCandidate() const | 498 static bool isVisuallyEquivalentCandidateAlgorithm(const PositionAlgorithm<Strat
egy>& position) |
497 { | 499 { |
498 if (isNull()) | 500 Node* const anchorNode = position.anchorNode(); |
| 501 if (!anchorNode) |
499 return false; | 502 return false; |
500 | 503 |
501 LayoutObject* layoutObject = anchorNode()->layoutObject(); | 504 LayoutObject* layoutObject = anchorNode->layoutObject(); |
502 if (!layoutObject) | 505 if (!layoutObject) |
503 return false; | 506 return false; |
504 | 507 |
505 if (layoutObject->style()->visibility() != VISIBLE) | 508 if (layoutObject->style()->visibility() != VISIBLE) |
506 return false; | 509 return false; |
507 | 510 |
508 if (layoutObject->isBR()) { | 511 if (layoutObject->isBR()) { |
509 // TODO(leviw) The condition should be | 512 // TODO(leviw) The condition should be |
510 // m_anchorType == PositionAnchorType::BeforeAnchor, but for now we | 513 // m_anchorType == PositionAnchorType::BeforeAnchor, but for now we |
511 // still need to support legacy positions. | 514 // still need to support legacy positions. |
512 return !m_offset && !isAfterAnchor() && !nodeIsUserSelectNone(Strategy::
parent(*anchorNode())); | 515 if (position.isAfterAnchor()) |
| 516 return false; |
| 517 return !position.computeEditingOffset() && !nodeIsUserSelectNone(Strateg
y::parent(*anchorNode)); |
513 } | 518 } |
514 | 519 |
515 if (layoutObject->isText()) | 520 if (layoutObject->isText()) |
516 return !nodeIsUserSelectNone(anchorNode()) && inRenderedText(*this); | 521 return !nodeIsUserSelectNone(anchorNode) && inRenderedText(position); |
517 | 522 |
518 if (layoutObject->isSVG()) { | 523 if (layoutObject->isSVG()) { |
519 // We don't consider SVG elements are contenteditable except for | 524 // We don't consider SVG elements are contenteditable except for |
520 // associated layoutObject returns isText() true, e.g. LayoutSVGInlineTe
xt. | 525 // associated |layoutObject| returns |isText()| true, |
| 526 // e.g. |LayoutSVGInlineText|. |
521 return false; | 527 return false; |
522 } | 528 } |
523 | 529 |
524 if (isRenderedHTMLTableElement(anchorNode()) || Strategy::editingIgnoresCont
ent(anchorNode())) | 530 if (isRenderedHTMLTableElement(anchorNode) || Strategy::editingIgnoresConten
t(anchorNode)) |
525 return (atFirstEditingPositionForNode() || atLastEditingPositionForNode(
)) && !nodeIsUserSelectNone(Strategy::parent(*anchorNode())); | 531 return (position.atFirstEditingPositionForNode() || position.atLastEditi
ngPositionForNode()) && !nodeIsUserSelectNone(Strategy::parent(*anchorNode)); |
526 | 532 |
527 if (isHTMLHtmlElement(*m_anchorNode)) | 533 if (isHTMLHtmlElement(*anchorNode)) |
528 return false; | 534 return false; |
529 | 535 |
530 if (layoutObject->isLayoutBlockFlow() || layoutObject->isFlexibleBox() || la
youtObject->isLayoutGrid()) { | 536 if (layoutObject->isLayoutBlockFlow() || layoutObject->isFlexibleBox() || la
youtObject->isLayoutGrid()) { |
531 if (toLayoutBlock(layoutObject)->logicalHeight() || isHTMLBodyElement(*m
_anchorNode)) { | 537 if (toLayoutBlock(layoutObject)->logicalHeight() || isHTMLBodyElement(*a
nchorNode)) { |
532 if (!hasRenderedNonAnonymousDescendantsWithHeight(layoutObject)) | 538 if (!hasRenderedNonAnonymousDescendantsWithHeight(layoutObject)) |
533 return atFirstEditingPositionForNode() && !nodeIsUserSelectNone(
anchorNode()); | 539 return position.atFirstEditingPositionForNode() && !nodeIsUserSe
lectNone(anchorNode); |
534 return m_anchorNode->hasEditableStyle() && !nodeIsUserSelectNone(anc
horNode()) && atEditingBoundary(*this); | 540 return anchorNode->hasEditableStyle() && !nodeIsUserSelectNone(ancho
rNode) && atEditingBoundary(position); |
535 } | 541 } |
536 } else { | 542 } else { |
537 LocalFrame* frame = m_anchorNode->document().frame(); | 543 LocalFrame* frame = anchorNode->document().frame(); |
538 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsi
ngEnabled(); | 544 bool caretBrowsing = frame->settings() && frame->settings()->caretBrowsi
ngEnabled(); |
539 return (caretBrowsing || m_anchorNode->hasEditableStyle()) && !nodeIsUse
rSelectNone(anchorNode()) && atEditingBoundary(*this); | 545 return (caretBrowsing || anchorNode->hasEditableStyle()) && !nodeIsUserS
electNone(anchorNode) && atEditingBoundary(position); |
540 } | 546 } |
541 | 547 |
542 return false; | 548 return false; |
543 } | 549 } |
544 | 550 |
545 // TODO(yosin) We should move |inRenderedText()| to "VisibleUnits.h" for | 551 // TODO(yosin) We should move |inRenderedText()| to "VisibleUnits.h" for |
546 // reduce dependency of |LayoutObject| in |Position| class. | 552 // reduce dependency of |LayoutObject| in |Position| class. |
| 553 bool isVisuallyEquivalentCandidate(const Position& position) |
| 554 { |
| 555 return isVisuallyEquivalentCandidateAlgorithm<EditingStrategy>(position); |
| 556 } |
| 557 |
| 558 bool isVisuallyEquivalentCandidate(const PositionInComposedTree& position) |
| 559 { |
| 560 return isVisuallyEquivalentCandidateAlgorithm<EditingInComposedTreeStrategy>
(position); |
| 561 } |
| 562 |
547 template <typename Strategy> | 563 template <typename Strategy> |
548 static bool inRenderedTextAlgorithm(const PositionAlgorithm<Strategy>& position) | 564 static bool inRenderedTextAlgorithm(const PositionAlgorithm<Strategy>& position) |
549 { | 565 { |
550 Node* const anchorNode = position.anchorNode(); | 566 Node* const anchorNode = position.anchorNode(); |
551 if (!anchorNode || !anchorNode->isTextNode()) | 567 if (!anchorNode || !anchorNode->isTextNode()) |
552 return false; | 568 return false; |
553 | 569 |
554 LayoutObject* layoutObject = anchorNode->layoutObject(); | 570 LayoutObject* layoutObject = anchorNode->layoutObject(); |
555 if (!layoutObject) | 571 if (!layoutObject) |
556 return false; | 572 return false; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 1025 |
1010 void showTree(const blink::Position* pos) | 1026 void showTree(const blink::Position* pos) |
1011 { | 1027 { |
1012 if (pos) | 1028 if (pos) |
1013 pos->showTreeForThis(); | 1029 pos->showTreeForThis(); |
1014 else | 1030 else |
1015 fprintf(stderr, "Cannot showTree for (nil)\n"); | 1031 fprintf(stderr, "Cannot showTree for (nil)\n"); |
1016 } | 1032 } |
1017 | 1033 |
1018 #endif | 1034 #endif |
OLD | NEW |