OLD | NEW |
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 |
(...skipping 22 matching lines...) Expand all Loading... |
33 #include "core/frame/Settings.h" | 33 #include "core/frame/Settings.h" |
34 #include "core/html/HTMLTextFormControlElement.h" | 34 #include "core/html/HTMLTextFormControlElement.h" |
35 #include "core/rendering/RenderBlock.h" | 35 #include "core/rendering/RenderBlock.h" |
36 #include "core/rendering/RenderLayer.h" | 36 #include "core/rendering/RenderLayer.h" |
37 #include "core/rendering/RenderView.h" | 37 #include "core/rendering/RenderView.h" |
38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 CaretBase::CaretBase(CaretVisibility visibility) | 42 CaretBase::CaretBase(CaretVisibility visibility) |
43 : m_caretRectNeedsUpdate(true) | 43 : m_caretVisibility(visibility) |
44 , m_caretVisibility(visibility) | |
45 { | 44 { |
46 } | 45 } |
47 | 46 |
48 DragCaretController::DragCaretController() | 47 DragCaretController::DragCaretController() |
49 : CaretBase(Visible) | 48 : CaretBase(Visible) |
50 { | 49 { |
51 } | 50 } |
52 | 51 |
53 PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create() | 52 PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create() |
54 { | 53 { |
55 return adoptPtrWillBeNoop(new DragCaretController); | 54 return adoptPtrWillBeNoop(new DragCaretController); |
56 } | 55 } |
57 | 56 |
58 bool DragCaretController::isContentRichlyEditable() const | 57 bool DragCaretController::isContentRichlyEditable() const |
59 { | 58 { |
60 return isRichlyEditablePosition(m_position.deepEquivalent()); | 59 return isRichlyEditablePosition(m_position.deepEquivalent()); |
61 } | 60 } |
62 | 61 |
63 void DragCaretController::setCaretPosition(const VisiblePosition& position) | 62 void DragCaretController::setCaretPosition(const VisiblePosition& position) |
64 { | 63 { |
65 // for querying RenderLayer::compositingState() | 64 // for querying RenderLayer::compositingState() |
66 // This code is probably correct, since it doesn't occur in a stack that inv
olves updating compositing state. | 65 // This code is probably correct, since it doesn't occur in a stack that inv
olves updating compositing state. |
67 DisableCompositingQueryAsserts disabler; | 66 DisableCompositingQueryAsserts disabler; |
68 | 67 |
69 if (Node* node = m_position.deepEquivalent().deprecatedNode()) | 68 if (Node* node = m_position.deepEquivalent().deprecatedNode()) |
70 invalidateCaretRect(node); | 69 invalidateCaretRect(node); |
71 m_position = position; | 70 m_position = position; |
72 setCaretRectNeedsUpdate(); | |
73 Document* document = nullptr; | 71 Document* document = nullptr; |
74 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { | 72 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { |
75 invalidateCaretRect(node); | 73 invalidateCaretRect(node); |
76 document = &node->document(); | 74 document = &node->document(); |
77 } | 75 } |
78 if (m_position.isNull() || m_position.isOrphan()) { | 76 if (m_position.isNull() || m_position.isOrphan()) { |
79 clearCaretRect(); | 77 clearCaretRect(); |
80 } else { | 78 } else { |
81 document->updateRenderTreeIfNeeded(); | 79 document->updateRenderTreeIfNeeded(); |
82 updateCaretRect(document, m_position); | 80 updateCaretRect(document, m_position); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 } | 157 } |
160 | 158 |
161 if (unrooted) | 159 if (unrooted) |
162 caretRect = LayoutRect(); | 160 caretRect = LayoutRect(); |
163 } | 161 } |
164 | 162 |
165 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) | 163 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) |
166 { | 164 { |
167 m_caretLocalRect = LayoutRect(); | 165 m_caretLocalRect = LayoutRect(); |
168 | 166 |
169 m_caretRectNeedsUpdate = false; | |
170 | |
171 if (caretPosition.position().isNull()) | 167 if (caretPosition.position().isNull()) |
172 return false; | 168 return false; |
173 | 169 |
174 ASSERT(caretPosition.position().deprecatedNode()->renderer()); | 170 ASSERT(caretPosition.position().deprecatedNode()->renderer()); |
175 | 171 |
176 // First compute a rect local to the renderer at the selection start. | 172 // First compute a rect local to the renderer at the selection start. |
177 RenderObject* renderer; | 173 RenderObject* renderer; |
178 m_caretLocalRect = localCaretRectOfPosition(caretPosition, renderer); | 174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, renderer); |
179 | 175 |
180 // Get the renderer that will be responsible for painting the caret | 176 // Get the renderer that will be responsible for painting the caret |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 bool caretBrowsing = false; | 226 bool caretBrowsing = false; |
231 if (FrameView* frameView = view->frameView()) { | 227 if (FrameView* frameView = view->frameView()) { |
232 LocalFrame& frame = frameView->frame(); // The frame where the selection
started | 228 LocalFrame& frame = frameView->frame(); // The frame where the selection
started |
233 caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabl
ed(); | 229 caretBrowsing = frame.settings() && frame.settings()->caretBrowsingEnabl
ed(); |
234 } | 230 } |
235 return (caretBrowsing || isContentEditable); | 231 return (caretBrowsing || isContentEditable); |
236 } | 232 } |
237 | 233 |
238 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) | 234 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) |
239 { | 235 { |
240 // EDIT FIXME: This is an unfortunate hack. | |
241 // Basically, we can't trust this layout position since we | |
242 // can't guarantee that the check to see if we are in unrendered | |
243 // content will work at this point. We may have to wait for | |
244 // a layout and re-render of the document to happen. So, resetting this | |
245 // flag will cause another caret layout to happen the first time | |
246 // that we try to paint the caret after this call. That one will work since | |
247 // it happens after the document has accounted for any editing | |
248 // changes which may have been done. | |
249 // And, we need to leave this layout here so the caret moves right | |
250 // away after clicking. | |
251 m_caretRectNeedsUpdate = true; | |
252 | |
253 if (caretRectChanged) | 236 if (caretRectChanged) |
254 return; | 237 return; |
255 | 238 |
256 if (RenderView* view = node->document().renderView()) { | 239 if (RenderView* view = node->document().renderView()) { |
257 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll
IsAlwaysNonEditable))) | 240 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll
IsAlwaysNonEditable))) |
258 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); | 241 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); |
259 } | 242 } |
260 } | 243 } |
261 | 244 |
262 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const | 245 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const |
(...skipping 23 matching lines...) Expand all Loading... |
286 context->fillRect(caret, caretColor); | 269 context->fillRect(caret, caretColor); |
287 } | 270 } |
288 | 271 |
289 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 272 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
290 { | 273 { |
291 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 274 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
292 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 275 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
293 } | 276 } |
294 | 277 |
295 } | 278 } |
OLD | NEW |