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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2161373002: Make FrameCaret to retrieve caret position from SelectionEditor (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2016-07-21T11:26:04 Created 4 years, 5 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
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
92 return frame->editor().behavior().shouldConsiderSelectionAsDirectional(); 92 return frame->editor().behavior().shouldConsiderSelectionAsDirectional();
93 } 93 }
94 94
95 FrameSelection::FrameSelection(LocalFrame* frame) 95 FrameSelection::FrameSelection(LocalFrame* frame)
96 : m_frame(frame) 96 : m_frame(frame)
97 , m_pendingSelection(PendingSelection::create(*this)) 97 , m_pendingSelection(PendingSelection::create(*this))
98 , m_selectionEditor(SelectionEditor::create(*this)) 98 , m_selectionEditor(SelectionEditor::create(*this))
99 , m_granularity(CharacterGranularity) 99 , m_granularity(CharacterGranularity)
100 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) 100 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation())
101 , m_focused(frame->page() && frame->page()->focusController().focusedFrame() == frame) 101 , m_focused(frame->page() && frame->page()->focusController().focusedFrame() == frame)
102 , m_frameCaret(new FrameCaret(frame)) 102 , m_frameCaret(new FrameCaret(frame, *m_selectionEditor))
103 { 103 {
104 DCHECK(frame); 104 DCHECK(frame);
105 } 105 }
106 106
107 FrameSelection::~FrameSelection() 107 FrameSelection::~FrameSelection()
108 { 108 {
109 } 109 }
110 110
111 const Document& FrameSelection::document() const 111 const Document& FrameSelection::document() const
112 { 112 {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
313 // changed. 313 // changed.
314 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid() ; 314 m_frame->inputMethodController().cancelCompositionIfSelectionIsInvalid() ;
315 notifyLayoutObjectOfSelectionChange(userTriggered); 315 notifyLayoutObjectOfSelectionChange(userTriggered);
316 return; 316 return;
317 } 317 }
318 318
319 const VisibleSelectionTemplate<Strategy> oldSelection = visibleSelection<Str ategy>(); 319 const VisibleSelectionTemplate<Strategy> oldSelection = visibleSelection<Str ategy>();
320 const VisibleSelection oldSelectionInDOMTree = selection(); 320 const VisibleSelection oldSelectionInDOMTree = selection();
321 321
322 m_selectionEditor->setVisibleSelection(s, options); 322 m_selectionEditor->setVisibleSelection(s, options);
323 if (s.isCaret()) 323 m_frameCaret->setCaretRectNeedsUpdate();
324 m_frameCaret->setCaretPosition(PositionWithAffinity(toPositionInDOMTree( s.start()), s.affinity()));
325 else
326 m_frameCaret->clear();
327 324
328 if (!s.isNone() && !(options & DoNotSetFocus)) { 325 if (!s.isNone() && !(options & DoNotSetFocus)) {
329 setFocusedNodeIfNeeded(); 326 setFocusedNodeIfNeeded();
330 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and 327 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and
331 // "FocusIn", |m_frame| may associate to another document. 328 // "FocusIn", |m_frame| may associate to another document.
332 if (!isAvailable() || document() != currentDocument) { 329 if (!isAvailable() || document() != currentDocument) {
333 // Once we get test case to reach here, we should change this 330 // Once we get test case to reach here, we should change this
334 // if-statement to |DCHECK()|. 331 // if-statement to |DCHECK()|.
335 NOTREACHED(); 332 NOTREACHED();
336 return; 333 return;
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
470 // If we did nothing here, when this node's layoutObject was destroyed, the rect that it 467 // If we did nothing here, when this node's layoutObject was destroyed, the rect that it
471 // occupied would be invalidated, but, selection gaps that change as a r esult of 468 // occupied would be invalidated, but, selection gaps that change as a r esult of
472 // the removal wouldn't be invalidated. 469 // the removal wouldn't be invalidated.
473 // FIXME: Don't do so much unnecessary invalidation. 470 // FIXME: Don't do so much unnecessary invalidation.
474 clearLayoutTreeSelection = true; 471 clearLayoutTreeSelection = true;
475 } 472 }
476 473
477 if (clearLayoutTreeSelection) 474 if (clearLayoutTreeSelection)
478 selection().start().document()->layoutViewItem().clearSelection(); 475 selection().start().document()->layoutViewItem().clearSelection();
479 476
480 if (clearDOMTreeSelection) { 477 if (clearDOMTreeSelection)
481 setSelection(VisibleSelection(), DoNotSetFocus); 478 setSelection(VisibleSelection(), DoNotSetFocus);
482 } else { 479 m_frameCaret->setCaretRectNeedsUpdate();
483 const VisibleSelection& selection = m_selectionEditor->visibleSelection< EditingStrategy>();
484 if (selection.isCaret())
485 m_frameCaret->setCaretPosition(PositionWithAffinity(selection.start( ), selection.affinity()));
486 else
487 m_frameCaret->clear();
488 }
489 480
490 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to 481 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to
491 // |Editor| class. 482 // |Editor| class.
492 if (!document().isRunningExecCommand()) 483 if (!document().isRunningExecCommand())
493 TypingCommand::closeTyping(m_frame); 484 TypingCommand::closeTyping(m_frame);
494 } 485 }
495 486
496 static Position updatePositionAfterAdoptingTextReplacement(const Position& posit ion, CharacterData* node, unsigned offset, unsigned oldLength, unsigned newLengt h) 487 static Position updatePositionAfterAdoptingTextReplacement(const Position& posit ion, CharacterData* node, unsigned offset, unsigned oldLength, unsigned newLengt h)
497 { 488 {
498 if (!position.anchorNode() || position.anchorNode() != node || !position.isO ffsetInAnchor()) 489 if (!position.anchorNode() || position.anchorNode() != node || !position.isO ffsetInAnchor())
(...skipping 882 matching lines...) Expand 10 before | Expand all | Expand 10 after
1381 1372
1382 void showTree(const blink::FrameSelection* sel) 1373 void showTree(const blink::FrameSelection* sel)
1383 { 1374 {
1384 if (sel) 1375 if (sel)
1385 sel->showTreeForThis(); 1376 sel->showTreeForThis();
1386 else 1377 else
1387 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1378 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1388 } 1379 }
1389 1380
1390 #endif 1381 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.cpp ('k') | third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698