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

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

Issue 1325443002: Introduce localCaretRectOf() for VisiblePosition (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-28T23:08:19 Rebase after absoluteCaretRectBoundsOf() Created 5 years, 3 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/VisiblePosition.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 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved. 3 * Portions Copyright (c) 2011 Motorola Mobility, Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 669 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 return 0; 680 return 0;
681 681
682 return textNode->data().characterStartingAt(offset); 682 return textNode->data().characterStartingAt(offset);
683 } 683 }
684 684
685 UChar32 characterBefore(const VisiblePosition& visiblePosition) 685 UChar32 characterBefore(const VisiblePosition& visiblePosition)
686 { 686 {
687 return characterAfter(previousPositionOf(visiblePosition)); 687 return characterAfter(previousPositionOf(visiblePosition));
688 } 688 }
689 689
690 LayoutRect VisiblePosition::localCaretRect(LayoutObject*& layoutObject) const 690 // TODO(yosin) We should move |localCaretRect()| to "VisibleUnits.cpp".
691 static LayoutRect localCaretRectOf(const VisiblePosition& visiblePosition, Layou tObject*& layoutObject)
691 { 692 {
692 PositionWithAffinity positionWithAffinity(m_deepPosition, m_affinity); 693 PositionWithAffinity positionWithAffinity(visiblePosition.deepEquivalent(), visiblePosition.affinity());
693 return localCaretRectOfPosition(positionWithAffinity, layoutObject); 694 return localCaretRectOfPosition(positionWithAffinity, layoutObject);
694 } 695 }
695 696
696 IntRect absoluteCaretBoundsOf(const VisiblePosition& visiblePosition) 697 IntRect absoluteCaretBoundsOf(const VisiblePosition& visiblePosition)
697 { 698 {
698 LayoutObject* layoutObject; 699 LayoutObject* layoutObject;
699 LayoutRect localRect = visiblePosition.localCaretRect(layoutObject); 700 LayoutRect localRect = localCaretRectOf(visiblePosition, layoutObject);
700 if (localRect.isEmpty() || !layoutObject) 701 if (localRect.isEmpty() || !layoutObject)
701 return IntRect(); 702 return IntRect();
702 703
703 return layoutObject->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox(); 704 return layoutObject->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox();
704 } 705 }
705 706
706 // TODO(yosin) We should move a global function 707 // TODO(yosin) We should move a global function
707 // |lineDirectionPointForBlockDirectionNavigationOf()| to "FrameSelection.h" 708 // |lineDirectionPointForBlockDirectionNavigationOf()| to "FrameSelection.h"
708 // as static function. 709 // as static function.
709 int lineDirectionPointForBlockDirectionNavigationOf(const VisiblePosition& visib lePosition) 710 int lineDirectionPointForBlockDirectionNavigationOf(const VisiblePosition& visib lePosition)
710 { 711 {
711 if (visiblePosition.isNull()) 712 if (visiblePosition.isNull())
712 return 0; 713 return 0;
713 714
714 LayoutObject* layoutObject; 715 LayoutObject* layoutObject;
715 LayoutRect localRect = visiblePosition.localCaretRect(layoutObject); 716 LayoutRect localRect = localCaretRectOf(visiblePosition, layoutObject);
716 if (localRect.isEmpty() || !layoutObject) 717 if (localRect.isEmpty() || !layoutObject)
717 return 0; 718 return 0;
718 719
719 // This ignores transforms on purpose, for now. Vertical navigation is done 720 // This ignores transforms on purpose, for now. Vertical navigation is done
720 // without consulting transforms, so that 'up' in transformed text is 'up' 721 // without consulting transforms, so that 'up' in transformed text is 'up'
721 // relative to the text, not absolute 'up'. 722 // relative to the text, not absolute 'up'.
722 FloatPoint caretPoint = layoutObject->localToAbsolute(FloatPoint(localRect.l ocation())); 723 FloatPoint caretPoint = layoutObject->localToAbsolute(FloatPoint(localRect.l ocation()));
723 LayoutObject* containingBlock = layoutObject->containingBlock(); 724 LayoutObject* containingBlock = layoutObject->containingBlock();
724 if (!containingBlock) 725 if (!containingBlock)
725 containingBlock = layoutObject; // Just use ourselves to determine the w riting mode if we have no containing block. 726 containingBlock = layoutObject; // Just use ourselves to determine the w riting mode if we have no containing block.
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
778 else 779 else
779 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n"); 780 fprintf(stderr, "Cannot showTree for (nil) VisiblePosition.\n");
780 } 781 }
781 782
782 void showTree(const blink::VisiblePosition& vpos) 783 void showTree(const blink::VisiblePosition& vpos)
783 { 784 {
784 vpos.showTreeForThis(); 785 vpos.showTreeForThis();
785 } 786 }
786 787
787 #endif 788 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisiblePosition.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698