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

Side by Side Diff: third_party/WebKit/Source/core/editing/Position.cpp

Issue 2229703002: Improve canBeAnchorNode() for PositionInFlatTree constructor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-08-09T13:48:05 Created 4 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 | « no previous file | 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, 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 17 matching lines...) Expand all
28 #include "core/dom/shadow/ElementShadow.h" 28 #include "core/dom/shadow/ElementShadow.h"
29 #include "core/editing/EditingUtilities.h" 29 #include "core/editing/EditingUtilities.h"
30 #include "core/editing/TextAffinity.h" 30 #include "core/editing/TextAffinity.h"
31 #include "wtf/text/CString.h" 31 #include "wtf/text/CString.h"
32 #include <stdio.h> 32 #include <stdio.h>
33 #include <ostream> // NOLINT 33 #include <ostream> // NOLINT
34 34
35 namespace blink { 35 namespace blink {
36 36
37 #if DCHECK_IS_ON() 37 #if DCHECK_IS_ON()
38 static bool canBeAnchorNode(Node* node) 38 template <typename Strategy>
39 static bool canBeAnchorNode(Node*);
40
41 template <>
42 bool canBeAnchorNode<EditingStrategy>(Node* node)
39 { 43 {
40 return !node || !node->isPseudoElement(); 44 return !node || !node->isPseudoElement();
41 } 45 }
46
47 template <>
48 bool canBeAnchorNode<EditingInFlatTreeStrategy>(Node* node)
49 {
50 return canBeAnchorNode<EditingStrategy>(node) && node->canParticipateInFlatT ree();
51 }
42 #endif 52 #endif
43 53
44 template <typename Strategy> 54 template <typename Strategy>
45 const TreeScope* PositionTemplate<Strategy>::commonAncestorTreeScope(const Posit ionTemplate<Strategy>& a, const PositionTemplate<Strategy>& b) 55 const TreeScope* PositionTemplate<Strategy>::commonAncestorTreeScope(const Posit ionTemplate<Strategy>& a, const PositionTemplate<Strategy>& b)
46 { 56 {
47 if (!a.computeContainerNode() || !b.computeContainerNode()) 57 if (!a.computeContainerNode() || !b.computeContainerNode())
48 return nullptr; 58 return nullptr;
49 return a.computeContainerNode()->treeScope().commonAncestorTreeScope(b.compu teContainerNode()->treeScope()); 59 return a.computeContainerNode()->treeScope().commonAncestorTreeScope(b.compu teContainerNode()->treeScope());
50 } 60 }
51 61
(...skipping 30 matching lines...) Expand all
82 DCHECK(m_anchorType == PositionAnchorType::BeforeAnchor || m_anchorType == PositionAnchorType::AfterAnchor); 92 DCHECK(m_anchorType == PositionAnchorType::BeforeAnchor || m_anchorType == PositionAnchorType::AfterAnchor);
83 return; 93 return;
84 } 94 }
85 if (m_anchorNode->isDocumentNode()) { 95 if (m_anchorNode->isDocumentNode()) {
86 // Since |RangeBoundaryPoint| can't represent before/after Document, we 96 // Since |RangeBoundaryPoint| can't represent before/after Document, we
87 // should not use them. 97 // should not use them.
88 DCHECK(isBeforeChildren() || isAfterChildren()) << m_anchorType; 98 DCHECK(isBeforeChildren() || isAfterChildren()) << m_anchorType;
89 return; 99 return;
90 } 100 }
91 #if DCHECK_IS_ON() 101 #if DCHECK_IS_ON()
92 DCHECK(canBeAnchorNode(m_anchorNode.get())); 102 DCHECK(canBeAnchorNode<Strategy>(m_anchorNode.get())) << m_anchorNode;
93 #endif 103 #endif
94 DCHECK_NE(m_anchorType, PositionAnchorType::OffsetInAnchor); 104 DCHECK_NE(m_anchorType, PositionAnchorType::OffsetInAnchor);
95 } 105 }
96 106
97 template <typename Strategy> 107 template <typename Strategy>
98 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, int offset) 108 PositionTemplate<Strategy>::PositionTemplate(Node* anchorNode, int offset)
99 : m_anchorNode(anchorNode) 109 : m_anchorNode(anchorNode)
100 , m_offset(offset) 110 , m_offset(offset)
101 , m_anchorType(PositionAnchorType::OffsetInAnchor) 111 , m_anchorType(PositionAnchorType::OffsetInAnchor)
102 { 112 {
103 if (m_anchorNode) 113 if (m_anchorNode)
104 DCHECK_GE(offset, 0); 114 DCHECK_GE(offset, 0);
105 else 115 else
106 DCHECK_EQ(offset, 0); 116 DCHECK_EQ(offset, 0);
107 #if DCHECK_IS_ON() 117 #if DCHECK_IS_ON()
108 DCHECK(canBeAnchorNode(m_anchorNode.get())); 118 DCHECK(canBeAnchorNode<Strategy>(m_anchorNode.get())) << m_anchorNode;
109 #endif 119 #endif
110 } 120 }
111 121
112 template <typename Strategy> 122 template <typename Strategy>
113 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other) 123 PositionTemplate<Strategy>::PositionTemplate(const PositionTemplate& other)
114 : m_anchorNode(other.m_anchorNode) 124 : m_anchorNode(other.m_anchorNode)
115 , m_offset(other.m_offset) 125 , m_offset(other.m_offset)
116 , m_anchorType(other.m_anchorType) 126 , m_anchorType(other.m_anchorType)
117 { 127 {
118 } 128 }
(...skipping 584 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 713
704 void showTree(const blink::Position* pos) 714 void showTree(const blink::Position* pos)
705 { 715 {
706 if (pos) 716 if (pos)
707 pos->showTreeForThis(); 717 pos->showTreeForThis();
708 else 718 else
709 fprintf(stderr, "Cannot showTree for (nil)\n"); 719 fprintf(stderr, "Cannot showTree for (nil)\n");
710 } 720 }
711 721
712 #endif 722 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698