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

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

Issue 1191283002: Make VisiblePosition::init to not use being constructed object (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-06-22T16:23:26 Add a comment to PositionWIthAffinity::operator==() Created 5 years, 6 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 | « Source/core/editing/VisibleUnits.h ('k') | no next file » | 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, 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 * 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 693 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 704
705 VisiblePosition nextWordPosition(const VisiblePosition &c) 705 VisiblePosition nextWordPosition(const VisiblePosition &c)
706 { 706 {
707 VisiblePosition next = nextBoundary(c, nextWordPositionBoundary); 707 VisiblePosition next = nextBoundary(c, nextWordPositionBoundary);
708 return c.honorEditingBoundaryAtOrAfter(next); 708 return c.honorEditingBoundaryAtOrAfter(next);
709 } 709 }
710 710
711 // --------- 711 // ---------
712 712
713 enum LineEndpointComputationMode { UseLogicalOrdering, UseInlineBoxOrdering }; 713 enum LineEndpointComputationMode { UseLogicalOrdering, UseInlineBoxOrdering };
714 static VisiblePosition startPositionForLine(const VisiblePosition& c, LineEndpoi ntComputationMode mode) 714 static PositionWithAffinity startPositionForLine(const PositionWithAffinity& c, LineEndpointComputationMode mode)
715 { 715 {
716 if (c.isNull()) 716 if (c.isNull())
717 return VisiblePosition(); 717 return PositionWithAffinity();
718 718
719 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 719 RootInlineBox* rootBox = RenderedPosition(c.position(), c.affinity()).rootBo x();
720 if (!rootBox) { 720 if (!rootBox) {
721 // There are VisiblePositions at offset 0 in blocks without 721 // There are VisiblePositions at offset 0 in blocks without
722 // RootInlineBoxes, like empty editable blocks and bordered blocks. 722 // RootInlineBoxes, like empty editable blocks and bordered blocks.
723 Position p = c.deepEquivalent(); 723 Position p = c.position();
724 if (p.deprecatedNode()->layoutObject() && p.deprecatedNode()->layoutObje ct()->isLayoutBlock() && !p.deprecatedEditingOffset()) 724 if (p.deprecatedNode()->layoutObject() && p.deprecatedNode()->layoutObje ct()->isLayoutBlock() && !p.deprecatedEditingOffset())
725 return c; 725 return c;
726 726
727 return VisiblePosition(); 727 return PositionWithAffinity();
728 } 728 }
729 729
730 Node* startNode; 730 Node* startNode;
731 InlineBox* startBox; 731 InlineBox* startBox;
732 if (mode == UseLogicalOrdering) { 732 if (mode == UseLogicalOrdering) {
733 startNode = rootBox->getLogicalStartBoxWithNode(startBox); 733 startNode = rootBox->getLogicalStartBoxWithNode(startBox);
734 if (!startNode) 734 if (!startNode)
735 return VisiblePosition(); 735 return PositionWithAffinity();
736 } else { 736 } else {
737 // Generated content (e.g. list markers and CSS :before and :after pseud oelements) have no corresponding DOM element, 737 // Generated content (e.g. list markers and CSS :before and :after pseud oelements) have no corresponding DOM element,
738 // and so cannot be represented by a VisiblePosition. Use whatever follo ws instead. 738 // and so cannot be represented by a VisiblePosition. Use whatever follo ws instead.
739 startBox = rootBox->firstLeafChild(); 739 startBox = rootBox->firstLeafChild();
740 while (true) { 740 while (true) {
741 if (!startBox) 741 if (!startBox)
742 return VisiblePosition(); 742 return PositionWithAffinity();
743 743
744 startNode = startBox->layoutObject().nonPseudoNode(); 744 startNode = startBox->layoutObject().nonPseudoNode();
745 if (startNode) 745 if (startNode)
746 break; 746 break;
747 747
748 startBox = startBox->nextLeafChild(); 748 startBox = startBox->nextLeafChild();
749 } 749 }
750 } 750 }
751 751
752 return VisiblePosition(startNode->isTextNode() ? Position(toText(startNode), toInlineTextBox(startBox)->start()) : positionBeforeNode(startNode)); 752 return PositionWithAffinity(startNode->isTextNode() ? Position(toText(startN ode), toInlineTextBox(startBox)->start()) : positionBeforeNode(startNode));
753 } 753 }
754 754
755 static VisiblePosition startOfLine(const VisiblePosition& c, LineEndpointComputa tionMode mode) 755 static PositionWithAffinity startOfLine(const PositionWithAffinity& c, LineEndpo intComputationMode mode)
756 { 756 {
757 // TODO: this is the current behavior that might need to be fixed. 757 // TODO: this is the current behavior that might need to be fixed.
758 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail. 758 // Please refer to https://bugs.webkit.org/show_bug.cgi?id=49107 for detail.
759 VisiblePosition visPos = startPositionForLine(c, mode); 759 PositionWithAffinity visPos = startPositionForLine(c, mode);
760 760
761 if (mode == UseLogicalOrdering) { 761 if (mode == UseLogicalOrdering) {
762 if (ContainerNode* editableRoot = highestEditableRoot(c.deepEquivalent() )) { 762 if (ContainerNode* editableRoot = highestEditableRoot(c.position())) {
763 if (!editableRoot->contains(visPos.deepEquivalent().containerNode()) ) 763 if (!editableRoot->contains(visPos.position().containerNode()))
764 return VisiblePosition(firstPositionInNode(editableRoot)); 764 return PositionWithAffinity(firstPositionInNode(editableRoot));
765 } 765 }
766 } 766 }
767 767
768 return c.honorEditingBoundaryAtOrBefore(visPos); 768 return honorEditingBoundaryAtOrBeforeOf(visPos, c.position());
769 }
770
771 static PositionWithAffinity startOfLine(const PositionWithAffinity& currentPosit ion)
772 {
773 return startOfLine(currentPosition, UseInlineBoxOrdering);
769 } 774 }
770 775
771 // FIXME: Rename this function to reflect the fact it ignores bidi levels. 776 // FIXME: Rename this function to reflect the fact it ignores bidi levels.
772 VisiblePosition startOfLine(const VisiblePosition& currentPosition) 777 VisiblePosition startOfLine(const VisiblePosition& currentPosition)
773 { 778 {
774 return startOfLine(currentPosition, UseInlineBoxOrdering); 779 return VisiblePosition(startOfLine(PositionWithAffinity(currentPosition.deep Equivalent(), currentPosition.affinity()), UseInlineBoxOrdering));
775 } 780 }
776 781
777 VisiblePosition logicalStartOfLine(const VisiblePosition& currentPosition) 782 VisiblePosition logicalStartOfLine(const VisiblePosition& currentPosition)
778 { 783 {
779 return startOfLine(currentPosition, UseLogicalOrdering); 784 return VisiblePosition(startOfLine(PositionWithAffinity(currentPosition.deep Equivalent(), currentPosition.affinity()), UseLogicalOrdering));
780 } 785 }
781 786
782 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode) 787 static VisiblePosition endPositionForLine(const VisiblePosition& c, LineEndpoint ComputationMode mode)
783 { 788 {
784 if (c.isNull()) 789 if (c.isNull())
785 return VisiblePosition(); 790 return VisiblePosition();
786 791
787 RootInlineBox* rootBox = RenderedPosition(c).rootBox(); 792 RootInlineBox* rootBox = RenderedPosition(c).rootBox();
788 if (!rootBox) { 793 if (!rootBox) {
789 // There are VisiblePositions at offset 0 in blocks without 794 // There are VisiblePositions at offset 0 in blocks without
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
878 VisiblePosition endOfLine(const VisiblePosition& currentPosition) 883 VisiblePosition endOfLine(const VisiblePosition& currentPosition)
879 { 884 {
880 return endOfLine(currentPosition, UseInlineBoxOrdering); 885 return endOfLine(currentPosition, UseInlineBoxOrdering);
881 } 886 }
882 887
883 VisiblePosition logicalEndOfLine(const VisiblePosition& currentPosition) 888 VisiblePosition logicalEndOfLine(const VisiblePosition& currentPosition)
884 { 889 {
885 return endOfLine(currentPosition, UseLogicalOrdering); 890 return endOfLine(currentPosition, UseLogicalOrdering);
886 } 891 }
887 892
893 bool inSameLine(const PositionWithAffinity& position1, const PositionWithAffinit y& position2)
894 {
895 if (position1.isNull() || position2.isNull())
896 return false;
897 PositionWithAffinity startOfLine1 = startOfLine(position1);
898 PositionWithAffinity startOfLine2 = startOfLine(position2);
899 if (startOfLine1 == startOfLine2)
900 return true;
901 Position canonicalized1 = canonicalPositionOf(startOfLine1.position());
902 if (canonicalized1 == startOfLine2.position())
903 return true;
904 return canonicalized1 == canonicalPositionOf(startOfLine2.position());
905 }
906
888 bool inSameLine(const VisiblePosition &a, const VisiblePosition &b) 907 bool inSameLine(const VisiblePosition &a, const VisiblePosition &b)
889 { 908 {
890 return a.isNotNull() && startOfLine(a) == startOfLine(b); 909 return inSameLine(PositionWithAffinity(a.deepEquivalent(), a.affinity()), Po sitionWithAffinity(b.deepEquivalent(), b.affinity()));
891 } 910 }
892 911
893 bool isStartOfLine(const VisiblePosition &p) 912 bool isStartOfLine(const VisiblePosition &p)
894 { 913 {
895 return p.isNotNull() && p == startOfLine(p); 914 return p.isNotNull() && p == startOfLine(p);
896 } 915 }
897 916
898 bool isEndOfLine(const VisiblePosition &p) 917 bool isEndOfLine(const VisiblePosition &p)
899 { 918 {
900 return p.isNotNull() && p == endOfLine(p); 919 return p.isNotNull() && p == endOfLine(p);
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
1422 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping; 1441 HitTestRequest request = HitTestRequest::Move | HitTestRequest::ReadOnly | H itTestRequest::Active | HitTestRequest::IgnoreClipping;
1423 HitTestResult result(request, contentsPoint); 1442 HitTestResult result(request, contentsPoint);
1424 frame->document()->layoutView()->hitTest(result); 1443 frame->document()->layoutView()->hitTest(result);
1425 1444
1426 if (Node* node = result.innerNode()) 1445 if (Node* node = result.innerNode())
1427 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node); 1446 return frame->selection().selection().visiblePositionRespectingEditingBo undary(result.localPoint(), node);
1428 return VisiblePosition(); 1447 return VisiblePosition();
1429 } 1448 }
1430 1449
1431 } 1450 }
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleUnits.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698