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

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

Issue 429453004: Let FrameSelection::localCaretRect on a text input field avoid synchronous layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Nits Created 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 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
11 * documentation and/or other materials provided with the distribution. 11 * documentation and/or other materials provided with the distribution.
12 * 12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */ 24 */
25 25
26 #include "config.h" 26 #include "config.h"
27 #include "core/editing/Caret.h" 27 #include "core/editing/Caret.h"
28 28
29 #include "core/dom/Document.h" 29 #include "core/dom/Document.h"
30 #include "core/editing/VisibleUnits.h"
30 #include "core/editing/htmlediting.h" 31 #include "core/editing/htmlediting.h"
31 #include "core/frame/LocalFrame.h" 32 #include "core/frame/LocalFrame.h"
32 #include "core/frame/Settings.h" 33 #include "core/frame/Settings.h"
34 #include "core/html/HTMLTextFormControlElement.h"
33 #include "core/rendering/RenderBlock.h" 35 #include "core/rendering/RenderBlock.h"
34 #include "core/rendering/RenderView.h" 36 #include "core/rendering/RenderView.h"
35 #include "platform/graphics/GraphicsContext.h" 37 #include "platform/graphics/GraphicsContext.h"
36 38
37 namespace blink { 39 namespace blink {
38 40
39 CaretBase::CaretBase(CaretVisibility visibility) 41 CaretBase::CaretBase(CaretVisibility visibility)
40 : m_caretRectNeedsUpdate(true) 42 : m_caretRectNeedsUpdate(true)
41 , m_caretVisibility(visibility) 43 , m_caretVisibility(visibility)
42 { 44 {
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 125
124 RenderObject* renderer = node->renderer(); 126 RenderObject* renderer = node->renderer();
125 if (!renderer) 127 if (!renderer)
126 return 0; 128 return 0;
127 129
128 // if caretNode is a block and caret is inside it then caret should be paint ed by that block 130 // if caretNode is a block and caret is inside it then caret should be paint ed by that block
129 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no de); 131 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no de);
130 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock( ); 132 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock( );
131 } 133 }
132 134
133 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret Position) 135 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity& caretPosition)
134 { 136 {
135 document->updateRenderTreeIfNeeded(); 137 document->updateRenderTreeIfNeeded();
136 m_caretLocalRect = LayoutRect(); 138 m_caretLocalRect = LayoutRect();
137 139
138 m_caretRectNeedsUpdate = false; 140 m_caretRectNeedsUpdate = false;
139 141
140 if (caretPosition.isNull()) 142 if (caretPosition.position().isNull())
141 return false; 143 return false;
142 144
143 ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer()); 145 ASSERT(caretPosition.position().deprecatedNode()->renderer());
144 146
145 // First compute a rect local to the renderer at the selection start. 147 // First compute a rect local to the renderer at the selection start.
146 RenderObject* renderer; 148 RenderObject* renderer;
147 LayoutRect localRect = caretPosition.localCaretRect(renderer); 149 LayoutRect localRect = localCaretRectOfPosition(caretPosition, renderer);
148 150
149 // Get the renderer that will be responsible for painting the caret 151 // Get the renderer that will be responsible for painting the caret
150 // (which is either the renderer we just found, or one of its containers). 152 // (which is either the renderer we just found, or one of its containers).
151 RenderBlock* caretPainter = caretRenderer(caretPosition.deepEquivalent().dep recatedNode()); 153 RenderBlock* caretPainter = caretRenderer(caretPosition.position().deprecate dNode());
152 154
153 // Compute an offset between the renderer and the caretPainter. 155 // Compute an offset between the renderer and the caretPainter.
154 bool unrooted = false; 156 bool unrooted = false;
155 while (renderer != caretPainter) { 157 while (renderer != caretPainter) {
156 RenderObject* containerObject = renderer->container(); 158 RenderObject* containerObject = renderer->container();
157 if (!containerObject) { 159 if (!containerObject) {
158 unrooted = true; 160 unrooted = true;
159 break; 161 break;
160 } 162 }
161 localRect.move(renderer->offsetFromContainer(containerObject, localRect. location())); 163 localRect.move(renderer->offsetFromContainer(containerObject, localRect. location()));
162 renderer = containerObject; 164 renderer = containerObject;
163 } 165 }
164 166
165 if (!unrooted) 167 if (!unrooted)
166 m_caretLocalRect = localRect; 168 m_caretLocalRect = localRect;
167 169
168 return true; 170 return true;
169 } 171 }
170 172
173 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret Position)
174 {
175 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui valent(), caretPosition.affinity()));
176 }
177
171 RenderBlock* DragCaretController::caretRenderer() const 178 RenderBlock* DragCaretController::caretRenderer() const
172 { 179 {
173 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode() ); 180 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode() );
174 } 181 }
175 182
176 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect ) const 183 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect ) const
177 { 184 {
178 RenderBlock* caretPainter = caretRenderer(node); 185 RenderBlock* caretPainter = caretRenderer(node);
179 if (!caretPainter) 186 if (!caretPainter)
180 return IntRect(); 187 return IntRect();
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 context->fillRect(caret, caretColor); 267 context->fillRect(caret, caretColor);
261 } 268 }
262 269
263 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const 270 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
264 { 271 {
265 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram e) 272 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram e)
266 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); 273 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect);
267 } 274 }
268 275
269 } 276 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698