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

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

Issue 15017002: WebFrame::selectRange and moveCaret should behave like mouse selection (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
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 14 matching lines...) Expand all
25 */ 25 */
26 26
27 #include "config.h" 27 #include "config.h"
28 #include "core/editing/VisiblePosition.h" 28 #include "core/editing/VisiblePosition.h"
29 29
30 #include <stdio.h> 30 #include <stdio.h>
31 #include "HTMLNames.h" 31 #include "HTMLNames.h"
32 #include "core/dom/Document.h" 32 #include "core/dom/Document.h"
33 #include "core/dom/Range.h" 33 #include "core/dom/Range.h"
34 #include "core/dom/Text.h" 34 #include "core/dom/Text.h"
35 #include "core/editing/VisibleSelection.h"
35 #include "core/editing/VisibleUnits.h" 36 #include "core/editing/VisibleUnits.h"
36 #include "core/editing/htmlediting.h" 37 #include "core/editing/htmlediting.h"
37 #include "core/html/HTMLElement.h" 38 #include "core/html/HTMLElement.h"
38 #include "core/platform/Logging.h" 39 #include "core/platform/Logging.h"
39 #include "core/platform/graphics/FloatQuad.h" 40 #include "core/platform/graphics/FloatQuad.h"
41 #include "core/platform/graphics/LayoutPoint.h"
40 #include "core/rendering/InlineTextBox.h" 42 #include "core/rendering/InlineTextBox.h"
41 #include "core/rendering/RenderBlock.h" 43 #include "core/rendering/RenderBlock.h"
42 #include "core/rendering/RootInlineBox.h" 44 #include "core/rendering/RootInlineBox.h"
43 #include <wtf/text/CString.h> 45 #include <wtf/text/CString.h>
44 46
45 namespace WebCore { 47 namespace WebCore {
46 48
47 using namespace HTMLNames; 49 using namespace HTMLNames;
48 50
49 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity) 51 VisiblePosition::VisiblePosition(const Position &pos, EAffinity affinity)
(...skipping 686 matching lines...) Expand 10 before | Expand all | Expand 10 after
736 if (visiblePosition.isNull()) 738 if (visiblePosition.isNull())
737 return false; 739 return false;
738 740
739 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node)) 741 if (!visiblePosition.deepEquivalent().containerNode()->isDescendantOf(node))
740 return false; 742 return false;
741 743
742 VisiblePosition next = visiblePosition.next(); 744 VisiblePosition next = visiblePosition.next();
743 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan tOf(node); 745 return next.isNull() || !next.deepEquivalent().deprecatedNode()->isDescendan tOf(node);
744 } 746 }
745 747
748 VisiblePosition visiblePositionRespectingEditingBoundary(const VisibleSelection& currentSelection, const LayoutPoint& localPoint, Node* targetNode)
749 {
750 LayoutPoint selectionEndPoint = localPoint;
751 Element* editableElement = currentSelection.rootEditableElement();
752
753 if (!targetNode->renderer())
754 return VisiblePosition();
755
756 if (editableElement && !editableElement->contains(targetNode)) {
757 if (!editableElement->renderer())
758 return VisiblePosition();
759
760 FloatPoint absolutePoint = targetNode->renderer()->localToAbsolute(Float Point(selectionEndPoint));
761 selectionEndPoint = roundedLayoutPoint(editableElement->renderer()->abso luteToLocal(absolutePoint));
762 targetNode = editableElement;
763 }
764
765 return targetNode->renderer()->positionForPoint(selectionEndPoint);
766 }
767
746 } // namespace WebCore 768 } // namespace WebCore
747 769
748 #ifndef NDEBUG 770 #ifndef NDEBUG
749 771
750 void showTree(const WebCore::VisiblePosition* vpos) 772 void showTree(const WebCore::VisiblePosition* vpos)
751 { 773 {
752 if (vpos) 774 if (vpos)
753 vpos->showTreeForThis(); 775 vpos->showTreeForThis();
754 } 776 }
755 777
756 void showTree(const WebCore::VisiblePosition& vpos) 778 void showTree(const WebCore::VisiblePosition& vpos)
757 { 779 {
758 vpos.showTreeForThis(); 780 vpos.showTreeForThis();
759 } 781 }
760 782
761 #endif 783 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698