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

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

Issue 184023003: Make InlineBox::renderer() and related subclass methods return reference. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Move m_renderer on its old place to avoid InlineBox object size increase. Created 6 years, 9 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 : m_renderer(0) 67 : m_renderer(0)
68 , m_inlineBox(0) 68 , m_inlineBox(0)
69 , m_offset(0) 69 , m_offset(0)
70 , m_prevLeafChild(uncachedInlineBox()) 70 , m_prevLeafChild(uncachedInlineBox())
71 , m_nextLeafChild(uncachedInlineBox()) 71 , m_nextLeafChild(uncachedInlineBox())
72 { 72 {
73 if (position.isNull()) 73 if (position.isNull())
74 return; 74 return;
75 position.getInlineBoxAndOffset(m_inlineBox, m_offset); 75 position.getInlineBoxAndOffset(m_inlineBox, m_offset);
76 if (m_inlineBox) 76 if (m_inlineBox)
77 m_renderer = m_inlineBox->renderer(); 77 m_renderer = &m_inlineBox->renderer();
78 else 78 else
79 m_renderer = rendererFromPosition(position.deepEquivalent()); 79 m_renderer = rendererFromPosition(position.deepEquivalent());
80 } 80 }
81 81
82 RenderedPosition::RenderedPosition(const Position& position, EAffinity affinity) 82 RenderedPosition::RenderedPosition(const Position& position, EAffinity affinity)
83 : m_renderer(0) 83 : m_renderer(0)
84 , m_inlineBox(0) 84 , m_inlineBox(0)
85 , m_offset(0) 85 , m_offset(0)
86 , m_prevLeafChild(uncachedInlineBox()) 86 , m_prevLeafChild(uncachedInlineBox())
87 , m_nextLeafChild(uncachedInlineBox()) 87 , m_nextLeafChild(uncachedInlineBox())
88 { 88 {
89 if (position.isNull()) 89 if (position.isNull())
90 return; 90 return;
91 position.getInlineBoxAndOffset(affinity, m_inlineBox, m_offset); 91 position.getInlineBoxAndOffset(affinity, m_inlineBox, m_offset);
92 if (m_inlineBox) 92 if (m_inlineBox)
93 m_renderer = m_inlineBox->renderer(); 93 m_renderer = &m_inlineBox->renderer();
94 else 94 else
95 m_renderer = rendererFromPosition(position); 95 m_renderer = rendererFromPosition(position);
96 } 96 }
97 97
98 InlineBox* RenderedPosition::prevLeafChild() const 98 InlineBox* RenderedPosition::prevLeafChild() const
99 { 99 {
100 if (m_prevLeafChild == uncachedInlineBox()) 100 if (m_prevLeafChild == uncachedInlineBox())
101 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak(); 101 m_prevLeafChild = m_inlineBox->prevLeafChildIgnoringLineBreak();
102 return m_prevLeafChild; 102 return m_prevLeafChild;
103 } 103 }
(...skipping 26 matching lines...) Expand all
130 130
131 RenderedPosition RenderedPosition::leftBoundaryOfBidiRun(unsigned char bidiLevel OfRun) 131 RenderedPosition RenderedPosition::leftBoundaryOfBidiRun(unsigned char bidiLevel OfRun)
132 { 132 {
133 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) 133 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel())
134 return RenderedPosition(); 134 return RenderedPosition();
135 135
136 InlineBox* box = m_inlineBox; 136 InlineBox* box = m_inlineBox;
137 do { 137 do {
138 InlineBox* prev = box->prevLeafChildIgnoringLineBreak(); 138 InlineBox* prev = box->prevLeafChildIgnoringLineBreak();
139 if (!prev || prev->bidiLevel() < bidiLevelOfRun) 139 if (!prev || prev->bidiLevel() < bidiLevelOfRun)
140 return RenderedPosition(box->renderer(), box, box->caretLeftmostOffs et()); 140 return RenderedPosition(&box->renderer(), box, box->caretLeftmostOff set());
141 box = prev; 141 box = prev;
142 } while (box); 142 } while (box);
143 143
144 ASSERT_NOT_REACHED(); 144 ASSERT_NOT_REACHED();
145 return RenderedPosition(); 145 return RenderedPosition();
146 } 146 }
147 147
148 RenderedPosition RenderedPosition::rightBoundaryOfBidiRun(unsigned char bidiLeve lOfRun) 148 RenderedPosition RenderedPosition::rightBoundaryOfBidiRun(unsigned char bidiLeve lOfRun)
149 { 149 {
150 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel()) 150 if (!m_inlineBox || bidiLevelOfRun > m_inlineBox->bidiLevel())
151 return RenderedPosition(); 151 return RenderedPosition();
152 152
153 InlineBox* box = m_inlineBox; 153 InlineBox* box = m_inlineBox;
154 do { 154 do {
155 InlineBox* next = box->nextLeafChildIgnoringLineBreak(); 155 InlineBox* next = box->nextLeafChildIgnoringLineBreak();
156 if (!next || next->bidiLevel() < bidiLevelOfRun) 156 if (!next || next->bidiLevel() < bidiLevelOfRun)
157 return RenderedPosition(box->renderer(), box, box->caretRightmostOff set()); 157 return RenderedPosition(&box->renderer(), box, box->caretRightmostOf fset());
158 box = next; 158 box = next;
159 } while (box); 159 } while (box);
160 160
161 ASSERT_NOT_REACHED(); 161 ASSERT_NOT_REACHED();
162 return RenderedPosition(); 162 return RenderedPosition();
163 } 163 }
164 164
165 bool RenderedPosition::atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel shouldMatchB idiLevel, unsigned char bidiLevelOfRun) const 165 bool RenderedPosition::atLeftBoundaryOfBidiRun(ShouldMatchBidiLevel shouldMatchB idiLevel, unsigned char bidiLevelOfRun) const
166 { 166 {
167 if (!m_inlineBox) 167 if (!m_inlineBox)
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
202 return false; 202 return false;
203 } 203 }
204 204
205 Position RenderedPosition::positionAtLeftBoundaryOfBiDiRun() const 205 Position RenderedPosition::positionAtLeftBoundaryOfBiDiRun() const
206 { 206 {
207 ASSERT(atLeftBoundaryOfBidiRun()); 207 ASSERT(atLeftBoundaryOfBidiRun());
208 208
209 if (atLeftmostOffsetInBox()) 209 if (atLeftmostOffsetInBox())
210 return createLegacyEditingPosition(m_renderer->node(), m_offset); 210 return createLegacyEditingPosition(m_renderer->node(), m_offset);
211 211
212 return createLegacyEditingPosition(nextLeafChild()->renderer()->node(), next LeafChild()->caretLeftmostOffset()); 212 return createLegacyEditingPosition(nextLeafChild()->renderer().node(), nextL eafChild()->caretLeftmostOffset());
213 } 213 }
214 214
215 Position RenderedPosition::positionAtRightBoundaryOfBiDiRun() const 215 Position RenderedPosition::positionAtRightBoundaryOfBiDiRun() const
216 { 216 {
217 ASSERT(atRightBoundaryOfBidiRun()); 217 ASSERT(atRightBoundaryOfBidiRun());
218 218
219 if (atRightmostOffsetInBox()) 219 if (atRightmostOffsetInBox())
220 return createLegacyEditingPosition(m_renderer->node(), m_offset); 220 return createLegacyEditingPosition(m_renderer->node(), m_offset);
221 221
222 return createLegacyEditingPosition(prevLeafChild()->renderer()->node(), prev LeafChild()->caretRightmostOffset()); 222 return createLegacyEditingPosition(prevLeafChild()->renderer().node(), prevL eafChild()->caretRightmostOffset());
223 } 223 }
224 224
225 IntRect RenderedPosition::absoluteRect(LayoutUnit* extraWidthToEndOfLine) const 225 IntRect RenderedPosition::absoluteRect(LayoutUnit* extraWidthToEndOfLine) const
226 { 226 {
227 if (isNull()) 227 if (isNull())
228 return IntRect(); 228 return IntRect();
229 229
230 IntRect localRect = pixelSnappedIntRect(m_renderer->localCaretRect(m_inlineB ox, m_offset, extraWidthToEndOfLine)); 230 IntRect localRect = pixelSnappedIntRect(m_renderer->localCaretRect(m_inlineB ox, m_offset, extraWidthToEndOfLine));
231 return localRect == IntRect() ? IntRect() : m_renderer->localToAbsoluteQuad( FloatRect(localRect)).enclosingBoundingBox(); 231 return localRect == IntRect() ? IntRect() : m_renderer->localToAbsoluteQuad( FloatRect(localRect)).enclosingBoundingBox();
232 } 232 }
233 233
234 bool renderObjectContainsPosition(RenderObject* target, const Position& position ) 234 bool renderObjectContainsPosition(RenderObject* target, const Position& position )
235 { 235 {
236 for (RenderObject* renderer = rendererFromPosition(position); renderer && re nderer->node(); renderer = renderer->parent()) { 236 for (RenderObject* renderer = rendererFromPosition(position); renderer && re nderer->node(); renderer = renderer->parent()) {
237 if (renderer == target) 237 if (renderer == target)
238 return true; 238 return true;
239 } 239 }
240 return false; 240 return false;
241 } 241 }
242 242
243 }; 243 };
OLDNEW
« no previous file with comments | « no previous file | Source/core/editing/VisiblePosition.cpp » ('j') | Source/core/editing/VisiblePosition.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698