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

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

Issue 1299873002: ALL-IN-ONE Introduce enum class TextAffinity (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-08-19T18:08:52 Created 5 years, 4 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/VisibleSelection.h ('k') | Source/core/editing/VisibleUnits.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 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 24 matching lines...) Expand all
35 #include "core/layout/LayoutObject.h" 35 #include "core/layout/LayoutObject.h"
36 #include "platform/geometry/LayoutPoint.h" 36 #include "platform/geometry/LayoutPoint.h"
37 #include "wtf/Assertions.h" 37 #include "wtf/Assertions.h"
38 #include "wtf/text/CString.h" 38 #include "wtf/text/CString.h"
39 #include "wtf/text/CharacterNames.h" 39 #include "wtf/text/CharacterNames.h"
40 #include "wtf/text/StringBuilder.h" 40 #include "wtf/text/StringBuilder.h"
41 41
42 namespace blink { 42 namespace blink {
43 43
44 VisibleSelection::VisibleSelection() 44 VisibleSelection::VisibleSelection()
45 : m_affinity(DOWNSTREAM) 45 : m_affinity(TextAffinity::Downstream)
46 , m_changeObserver(nullptr) 46 , m_changeObserver(nullptr)
47 , m_selectionType(NoSelection) 47 , m_selectionType(NoSelection)
48 , m_baseIsFirst(true) 48 , m_baseIsFirst(true)
49 , m_isDirectional(false) 49 , m_isDirectional(false)
50 { 50 {
51 } 51 }
52 52
53 VisibleSelection::VisibleSelection(const Position& pos, EAffinity affinity, bool isDirectional) 53 VisibleSelection::VisibleSelection(const Position& pos, TextAffinity affinity, b ool isDirectional)
54 : VisibleSelection(pos, pos, affinity, isDirectional) 54 : VisibleSelection(pos, pos, affinity, isDirectional)
55 { 55 {
56 } 56 }
57 57
58 VisibleSelection::VisibleSelection(const Position& base, const Position& extent, EAffinity affinity, bool isDirectional) 58 VisibleSelection::VisibleSelection(const Position& base, const Position& extent, TextAffinity affinity, bool isDirectional)
59 : m_base(base) 59 : m_base(base)
60 , m_extent(extent) 60 , m_extent(extent)
61 , m_affinity(affinity) 61 , m_affinity(affinity)
62 , m_changeObserver(nullptr) 62 , m_changeObserver(nullptr)
63 , m_isDirectional(isDirectional) 63 , m_isDirectional(isDirectional)
64 { 64 {
65 validate(); 65 validate();
66 } 66 }
67 67
68 VisibleSelection::VisibleSelection(const PositionInComposedTree& base, const Pos itionInComposedTree& extent, EAffinity affinity, bool isDirectional) 68 VisibleSelection::VisibleSelection(const PositionInComposedTree& base, const Pos itionInComposedTree& extent, TextAffinity affinity, bool isDirectional)
69 : VisibleSelection(toPositionInDOMTree(base), toPositionInDOMTree(extent), a ffinity, isDirectional) 69 : VisibleSelection(toPositionInDOMTree(base), toPositionInDOMTree(extent), a ffinity, isDirectional)
70 { 70 {
71 } 71 }
72 72
73 VisibleSelection::VisibleSelection(const VisiblePosition& pos, bool isDirectiona l) 73 VisibleSelection::VisibleSelection(const VisiblePosition& pos, bool isDirectiona l)
74 : VisibleSelection(pos, pos, isDirectional) 74 : VisibleSelection(pos, pos, isDirectional)
75 { 75 {
76 } 76 }
77 77
78 VisibleSelection::VisibleSelection(const VisiblePosition& base, const VisiblePos ition& extent, bool isDirectional) 78 VisibleSelection::VisibleSelection(const VisiblePosition& base, const VisiblePos ition& extent, bool isDirectional)
79 : VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affi nity(), isDirectional) 79 : VisibleSelection(base.deepEquivalent(), extent.deepEquivalent(), base.affi nity(), isDirectional)
80 { 80 {
81 } 81 }
82 82
83 VisibleSelection::VisibleSelection(const EphemeralRange& range, EAffinity affini ty, bool isDirectional) 83 VisibleSelection::VisibleSelection(const EphemeralRange& range, TextAffinity aff inity, bool isDirectional)
84 : VisibleSelection(range.startPosition(), range.endPosition(), affinity, isD irectional) 84 : VisibleSelection(range.startPosition(), range.endPosition(), affinity, isD irectional)
85 { 85 {
86 } 86 }
87 87
88 VisibleSelection::VisibleSelection(const Range* range, EAffinity affinity, bool isDirectional) 88 VisibleSelection::VisibleSelection(const Range* range, TextAffinity affinity, bo ol isDirectional)
89 : VisibleSelection(range->startPosition(), range->endPosition(), affinity, i sDirectional) 89 : VisibleSelection(range->startPosition(), range->endPosition(), affinity, i sDirectional)
90 { 90 {
91 } 91 }
92 92
93 VisibleSelection::VisibleSelection(const VisibleSelection& other) 93 VisibleSelection::VisibleSelection(const VisibleSelection& other)
94 : m_base(other.m_base) 94 : m_base(other.m_base)
95 , m_extent(other.m_extent) 95 , m_extent(other.m_extent)
96 , m_start(other.m_start) 96 , m_start(other.m_start)
97 , m_end(other.m_end) 97 , m_end(other.m_end)
98 , m_baseInComposedTree(other.m_baseInComposedTree) 98 , m_baseInComposedTree(other.m_baseInComposedTree)
(...skipping 497 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 return CaretSelection; 596 return CaretSelection;
597 return RangeSelection; 597 return RangeSelection;
598 } 598 }
599 599
600 void VisibleSelection::updateSelectionType() 600 void VisibleSelection::updateSelectionType()
601 { 601 {
602 m_selectionType = selectionType(m_start, m_end); 602 m_selectionType = selectionType(m_start, m_end);
603 603
604 // Affinity only makes sense for a caret 604 // Affinity only makes sense for a caret
605 if (m_selectionType != CaretSelection) 605 if (m_selectionType != CaretSelection)
606 m_affinity = DOWNSTREAM; 606 m_affinity = TextAffinity::Downstream;
607 } 607 }
608 608
609 static Node* enclosingShadowHost(Node* node) 609 static Node* enclosingShadowHost(Node* node)
610 { 610 {
611 for (Node* runner = node; runner; runner = ComposedTreeTraversal::parent(*ru nner)) { 611 for (Node* runner = node; runner; runner = ComposedTreeTraversal::parent(*ru nner)) {
612 if (isShadowHost(runner)) 612 if (isShadowHost(runner))
613 return runner; 613 return runner;
614 } 614 }
615 return nullptr; 615 return nullptr;
616 } 616 }
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
756 // invalid, will be valid once the changes are undone. This is a design problem. 756 // invalid, will be valid once the changes are undone. This is a design problem.
757 // To fix it we either need to change the invariants of VisibleSelection or crea te a new 757 // To fix it we either need to change the invariants of VisibleSelection or crea te a new
758 // class for editing to use that can manipulate selections that are not currentl y valid. 758 // class for editing to use that can manipulate selections that are not currentl y valid.
759 void VisibleSelection::setWithoutValidation(const Position& base, const Position & extent) 759 void VisibleSelection::setWithoutValidation(const Position& base, const Position & extent)
760 { 760 {
761 ASSERT(!base.isNull()); 761 ASSERT(!base.isNull());
762 ASSERT(!extent.isNull()); 762 ASSERT(!extent.isNull());
763 763
764 // TODO(hajimehoshi): We doubt this assertion is needed. This was introduced 764 // TODO(hajimehoshi): We doubt this assertion is needed. This was introduced
765 // by http://trac.webkit.org/browser/trunk/WebCore/editing/Selection.cpp?ann otate=blame&rev=21071 765 // by http://trac.webkit.org/browser/trunk/WebCore/editing/Selection.cpp?ann otate=blame&rev=21071
766 ASSERT(m_affinity == DOWNSTREAM); 766 ASSERT(m_affinity == TextAffinity::Downstream);
767 767
768 m_base = base; 768 m_base = base;
769 m_extent = extent; 769 m_extent = extent;
770 m_baseInComposedTree = toPositionInComposedTree(base); 770 m_baseInComposedTree = toPositionInComposedTree(base);
771 m_extentInComposedTree = toPositionInComposedTree(extent); 771 m_extentInComposedTree = toPositionInComposedTree(extent);
772 m_baseIsFirst = comparePositions(base, extent) <= 0; 772 m_baseIsFirst = comparePositions(base, extent) <= 0;
773 if (m_baseIsFirst) { 773 if (m_baseIsFirst) {
774 m_start = base; 774 m_start = base;
775 m_end = extent; 775 m_end = extent;
776 } else { 776 } else {
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
1198 endInComposedTree().debugPosition("endInComposedTree: "); 1198 endInComposedTree().debugPosition("endInComposedTree: ");
1199 extentInComposedTree().debugPosition("extentInComposedTree: "); 1199 extentInComposedTree().debugPosition("extentInComposedTree: ");
1200 } else { 1200 } else {
1201 startInComposedTree().debugPosition("startInComposedTree: "); 1201 startInComposedTree().debugPosition("startInComposedTree: ");
1202 extentInComposedTree().debugPosition("extentInComposedTree: "); 1202 extentInComposedTree().debugPosition("extentInComposedTree: ");
1203 endInComposedTree().debugPosition("endInComposedTree: "); 1203 endInComposedTree().debugPosition("endInComposedTree: ");
1204 baseInComposedTree().debugPosition("baseInComposedTree: "); 1204 baseInComposedTree().debugPosition("baseInComposedTree: ");
1205 } 1205 }
1206 1206
1207 fprintf(stderr, "isDirectional=%s\n", isDirectional() ? "true" : "false"); 1207 fprintf(stderr, "isDirectional=%s\n", isDirectional() ? "true" : "false");
1208 fprintf(stderr, "affinity=%s\n", affinity() == DOWNSTREAM ? "DOWNSTREaM" : a ffinity() == UPSTREAM ? "UPSTREAM" : "UNKNOWN"); 1208 fprintf(stderr, "affinity=%s\n", affinity() == TextAffinity::Downstream ? "D OWNSTREaM" : affinity() == TextAffinity::Upstream ? "UPSTREAM" : "UNKNOWN");
1209 fprintf(stderr, "================================\n"); 1209 fprintf(stderr, "================================\n");
1210 } 1210 }
1211 1211
1212 void VisibleSelection::formatForDebugger(char* buffer, unsigned length) const 1212 void VisibleSelection::formatForDebugger(char* buffer, unsigned length) const
1213 { 1213 {
1214 StringBuilder result; 1214 StringBuilder result;
1215 String s; 1215 String s;
1216 1216
1217 if (isNone()) { 1217 if (isNone()) {
1218 result.appendLiteral("<none>"); 1218 result.appendLiteral("<none>");
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1252 sel.showTreeForThis(); 1252 sel.showTreeForThis();
1253 } 1253 }
1254 1254
1255 void showTree(const blink::VisibleSelection* sel) 1255 void showTree(const blink::VisibleSelection* sel)
1256 { 1256 {
1257 if (sel) 1257 if (sel)
1258 sel->showTreeForThis(); 1258 sel->showTreeForThis();
1259 } 1259 }
1260 1260
1261 #endif 1261 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | Source/core/editing/VisibleUnits.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698