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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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 | Annotate | Revision Log
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
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 63
64 void DragCaretController::setCaretPosition(const VisiblePosition& position) 64 void DragCaretController::setCaretPosition(const VisiblePosition& position)
65 { 65 {
66 if (Node* node = m_position.deepEquivalent().deprecatedNode()) 66 if (Node* node = m_position.deepEquivalent().deprecatedNode())
67 invalidateCaretRect(node); 67 invalidateCaretRect(node);
68 m_position = position; 68 m_position = position;
69 setCaretRectNeedsUpdate(); 69 setCaretRectNeedsUpdate();
70 Document* document = 0; 70 Document* document = 0;
71 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { 71 if (Node* node = m_position.deepEquivalent().deprecatedNode()) {
72 invalidateCaretRect(node); 72 invalidateCaretRect(node);
73 document = node->document(); 73 document = &node->document();
74 } 74 }
75 if (m_position.isNull() || m_position.isOrphan()) 75 if (m_position.isNull() || m_position.isOrphan())
76 clearCaretRect(); 76 clearCaretRect();
77 else 77 else
78 updateCaretRect(document, m_position); 78 updateCaretRect(document, m_position);
79 } 79 }
80 80
81 static bool removingNodeRemovesPosition(Node* node, const Position& position) 81 static bool removingNodeRemovesPosition(Node* node, const Position& position)
82 { 82 {
83 if (!position.anchorNode()) 83 if (!position.anchorNode())
84 return false; 84 return false;
85 85
86 if (position.anchorNode() == node) 86 if (position.anchorNode() == node)
87 return true; 87 return true;
88 88
89 if (!node->isElementNode()) 89 if (!node->isElementNode())
90 return false; 90 return false;
91 91
92 Element* element = toElement(node); 92 Element* element = toElement(node);
93 return element->containsIncludingShadowDOM(position.anchorNode()); 93 return element->containsIncludingShadowDOM(position.anchorNode());
94 } 94 }
95 95
96 static void clearRenderViewSelection(const Position& position) 96 static void clearRenderViewSelection(const Position& position)
97 { 97 {
98 RefPtr<Document> document = position.anchorNode()->document(); 98 RefPtr<Document> document = &position.anchorNode()->document();
99 document->updateStyleIfNeeded(); 99 document->updateStyleIfNeeded();
100 if (RenderView* view = document->renderView()) 100 if (RenderView* view = document->renderView())
101 view->clearSelection(); 101 view->clearSelection();
102 } 102 }
103 103
104 void DragCaretController::nodeWillBeRemoved(Node* node) 104 void DragCaretController::nodeWillBeRemoved(Node* node)
105 { 105 {
106 if (!hasCaret() || (node && !node->inDocument())) 106 if (!hasCaret() || (node && !node->inDocument()))
107 return; 107 return;
108 108
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
225 // that we try to paint the caret after this call. That one will work since 225 // that we try to paint the caret after this call. That one will work since
226 // it happens after the document has accounted for any editing 226 // it happens after the document has accounted for any editing
227 // changes which may have been done. 227 // changes which may have been done.
228 // And, we need to leave this layout here so the caret moves right 228 // And, we need to leave this layout here so the caret moves right
229 // away after clicking. 229 // away after clicking.
230 m_caretRectNeedsUpdate = true; 230 m_caretRectNeedsUpdate = true;
231 231
232 if (caretRectChanged) 232 if (caretRectChanged)
233 return; 233 return;
234 234
235 if (RenderView* view = node->document()->renderView()) { 235 if (RenderView* view = node->document().renderView()) {
236 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll IsAlwaysNonEditable))) 236 if (shouldRepaintCaret(view, node->isContentEditable(Node::UserSelectAll IsAlwaysNonEditable)))
237 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); 237 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate());
238 } 238 }
239 } 239 }
240 240
241 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi nt& paintOffset, const LayoutRect& clipRect) const 241 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi nt& paintOffset, const LayoutRect& clipRect) const
242 { 242 {
243 if (m_caretVisibility == Hidden) 243 if (m_caretVisibility == Hidden)
244 return; 244 return;
245 245
(...skipping 15 matching lines...) Expand all
261 element = node->parentElement(); 261 element = node->parentElement();
262 262
263 if (element && element->renderer()) 263 if (element && element->renderer())
264 caretColor = element->renderer()->resolveColor(CSSPropertyColor); 264 caretColor = element->renderer()->resolveColor(CSSPropertyColor);
265 265
266 context->fillRect(caret, caretColor); 266 context->fillRect(caret, caretColor);
267 } 267 }
268 268
269 void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const 269 void DragCaretController::paintDragCaret(Frame* frame, GraphicsContext* p, const LayoutPoint& paintOffset, const LayoutRect& clipRect) const
270 { 270 {
271 if (m_position.deepEquivalent().deprecatedNode()->document()->frame() == fra me) 271 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram e)
272 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect); 272 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset, clipRect);
273 } 273 }
274 274
275 } 275 }
OLDNEW
« no previous file with comments | « Source/core/editing/ApplyStyleCommand.cpp ('k') | Source/core/editing/DeleteFromTextNodeCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698