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

Side by Side Diff: Source/core/editing/FrameSelection.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
« no previous file with comments | « Source/core/editing/EditorCommand.cpp ('k') | Source/core/editing/InputMethodController.cpp » ('j') | 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, 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 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 s.setIsDirectional(true); 234 s.setIsDirectional(true);
235 235
236 if (!m_frame) { 236 if (!m_frame) {
237 m_selection = s; 237 m_selection = s;
238 return; 238 return;
239 } 239 }
240 240
241 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra meSelection::setSelection 241 // <http://bugs.webkit.org/show_bug.cgi?id=23464>: Infinite recursion at Fra meSelection::setSelection
242 // if document->frame() == m_frame we can get into an infinite loop 242 // if document->frame() == m_frame we can get into an infinite loop
243 if (s.base().anchorNode()) { 243 if (s.base().anchorNode()) {
244 Document* document = s.base().anchorNode()->document(); 244 Document& document = s.base().anchorNode()->document();
245 if (document->frame() && document->frame() != m_frame && document != m_f rame->document()) { 245 if (document.frame() && document.frame() != m_frame && &document != m_fr ame->document()) {
246 RefPtr<Frame> guard = document->frame(); 246 RefPtr<Frame> guard = document.frame();
247 document->frame()->selection()->setSelection(s, options, align, gran ularity); 247 document.frame()->selection()->setSelection(s, options, align, granu larity);
248 // It's possible that during the above set selection, this FrameSele ction has been modified by 248 // It's possible that during the above set selection, this FrameSele ction has been modified by
249 // selectFrameElementInParentIfFullySelected, but that the selection is no longer valid since 249 // selectFrameElementInParentIfFullySelected, but that the selection is no longer valid since
250 // the frame is about to be destroyed. If this is the case, clear ou r selection. 250 // the frame is about to be destroyed. If this is the case, clear ou r selection.
251 if (guard->hasOneRef() && !m_selection.isNonOrphanedCaretOrRange()) 251 if (guard->hasOneRef() && !m_selection.isNonOrphanedCaretOrRange())
252 clear(); 252 clear();
253 return; 253 return;
254 } 254 }
255 } 255 }
256 256
257 m_granularity = granularity; 257 m_granularity = granularity;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 313
314 if (!node->isElementNode()) 314 if (!node->isElementNode())
315 return false; 315 return false;
316 316
317 Element* element = toElement(node); 317 Element* element = toElement(node);
318 return element->containsIncludingShadowDOM(position.anchorNode()); 318 return element->containsIncludingShadowDOM(position.anchorNode());
319 } 319 }
320 320
321 static void clearRenderViewSelection(const Position& position) 321 static void clearRenderViewSelection(const Position& position)
322 { 322 {
323 RefPtr<Document> document = position.anchorNode()->document(); 323 RefPtr<Document> document = &position.anchorNode()->document();
324 document->updateStyleIfNeeded(); 324 document->updateStyleIfNeeded();
325 if (RenderView* view = document->renderView()) 325 if (RenderView* view = document->renderView())
326 view->clearSelection(); 326 view->clearSelection();
327 } 327 }
328 328
329 void FrameSelection::nodeWillBeRemoved(Node* node) 329 void FrameSelection::nodeWillBeRemoved(Node* node)
330 { 330 {
331 // There can't be a selection inside a fragment, so if a fragment's node is being removed, 331 // There can't be a selection inside a fragment, so if a fragment's node is being removed,
332 // the selection in the document that created the fragment needs no adjustme nt. 332 // the selection in the document that created the fragment needs no adjustme nt.
333 if (isNone() || (node && !node->inDocument())) 333 if (isNone() || (node && !node->inDocument()))
(...skipping 774 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 pos = m_selection.end(); 1108 pos = m_selection.end();
1109 break; 1109 break;
1110 case BASE: 1110 case BASE:
1111 pos = m_selection.base(); 1111 pos = m_selection.base();
1112 break; 1112 break;
1113 case EXTENT: 1113 case EXTENT:
1114 pos = m_selection.extent(); 1114 pos = m_selection.extent();
1115 break; 1115 break;
1116 } 1116 }
1117 1117
1118 Frame* frame = pos.anchorNode()->document()->frame(); 1118 Frame* frame = pos.anchorNode()->document().frame();
1119 if (!frame) 1119 if (!frame)
1120 return x; 1120 return x;
1121 1121
1122 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation()) { 1122 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation()) {
1123 VisiblePosition visiblePosition(pos, m_selection.affinity()); 1123 VisiblePosition visiblePosition(pos, m_selection.affinity());
1124 // VisiblePosition creation can fail here if a node containing the selec tion becomes visibility:hidden 1124 // VisiblePosition creation can fail here if a node containing the selec tion becomes visibility:hidden
1125 // after the selection is created and before this function is called. 1125 // after the selection is created and before this function is called.
1126 x = visiblePosition.isNotNull() ? visiblePosition.lineDirectionPointForB lockDirectionNavigation() : 0; 1126 x = visiblePosition.isNotNull() ? visiblePosition.lineDirectionPointForB lockDirectionNavigation() : 0;
1127 m_xPosForVerticalArrowNavigation = x; 1127 m_xPosForVerticalArrowNavigation = x;
1128 } else 1128 } else
(...skipping 325 matching lines...) Expand 10 before | Expand all | Expand 10 after
1454 setSelection(newSelection); 1454 setSelection(newSelection);
1455 1455
1456 selectFrameElementInParentIfFullySelected(); 1456 selectFrameElementInParentIfFullySelected();
1457 notifyRendererOfSelectionChange(UserTriggered); 1457 notifyRendererOfSelectionChange(UserTriggered);
1458 } 1458 }
1459 1459
1460 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool clo seTyping) 1460 bool FrameSelection::setSelectedRange(Range* range, EAffinity affinity, bool clo seTyping)
1461 { 1461 {
1462 if (!range || !range->startContainer() || !range->endContainer()) 1462 if (!range || !range->startContainer() || !range->endContainer())
1463 return false; 1463 return false;
1464 ASSERT(range->startContainer()->document() == range->endContainer()->documen t()); 1464 ASSERT(&range->startContainer()->document() == &range->endContainer()->docum ent());
1465 1465
1466 m_frame->document()->updateLayoutIgnorePendingStylesheets(); 1466 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1467 1467
1468 // Non-collapsed ranges are not allowed to start at the end of a line that i s wrapped, 1468 // Non-collapsed ranges are not allowed to start at the end of a line that i s wrapped,
1469 // they start at the beginning of the next line instead 1469 // they start at the beginning of the next line instead
1470 TrackExceptionState es; 1470 TrackExceptionState es;
1471 bool collapsed = range->collapsed(es); 1471 bool collapsed = range->collapsed(es);
1472 if (es.hadException()) 1472 if (es.hadException())
1473 return false; 1473 return false;
1474 1474
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
1657 if (!caretIsVisible() || !isCaret()) 1657 if (!caretIsVisible() || !isCaret())
1658 return false; 1658 return false;
1659 1659
1660 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled()) 1660 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled())
1661 return false; 1661 return false;
1662 1662
1663 Node* root = rootEditableElement(); 1663 Node* root = rootEditableElement();
1664 if (!root) 1664 if (!root)
1665 return false; 1665 return false;
1666 1666
1667 Element* focusedElement = root->document()->focusedElement(); 1667 Element* focusedElement = root->document().focusedElement();
1668 if (!focusedElement) 1668 if (!focusedElement)
1669 return false; 1669 return false;
1670 1670
1671 return focusedElement->containsIncludingShadowDOM(m_selection.start().anchor Node()); 1671 return focusedElement->containsIncludingShadowDOM(m_selection.start().anchor Node());
1672 } 1672 }
1673 1673
1674 void FrameSelection::caretBlinkTimerFired(Timer<FrameSelection>*) 1674 void FrameSelection::caretBlinkTimerFired(Timer<FrameSelection>*)
1675 { 1675 {
1676 ASSERT(caretIsVisible()); 1676 ASSERT(caretIsVisible());
1677 ASSERT(isCaret()); 1677 ASSERT(isCaret());
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
1931 sel.showTreeForThis(); 1931 sel.showTreeForThis();
1932 } 1932 }
1933 1933
1934 void showTree(const WebCore::FrameSelection* sel) 1934 void showTree(const WebCore::FrameSelection* sel)
1935 { 1935 {
1936 if (sel) 1936 if (sel)
1937 sel->showTreeForThis(); 1937 sel->showTreeForThis();
1938 } 1938 }
1939 1939
1940 #endif 1940 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/EditorCommand.cpp ('k') | Source/core/editing/InputMethodController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698