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

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

Issue 431983005: FrameSelection::updateApperance for caret should not cause layout. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: wip 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
« no previous file with comments | « no previous file | Source/core/html/HTMLTextFormControlElementTest.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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
265 265
266 VisibleSelection oldSelection = m_selection; 266 VisibleSelection oldSelection = m_selection;
267 267
268 m_selection = s; 268 m_selection = s;
269 setCaretRectNeedsUpdate(); 269 setCaretRectNeedsUpdate();
270 270
271 if (!s.isNone() && !(options & DoNotSetFocus)) 271 if (!s.isNone() && !(options & DoNotSetFocus))
272 setFocusedNodeIfNeeded(); 272 setFocusedNodeIfNeeded();
273 273
274 if (!(options & DoNotUpdateAppearance)) { 274 if (!(options & DoNotUpdateAppearance)) {
275 m_frame->document()->updateLayoutIgnorePendingStylesheets();
276
277 // Hits in compositing/overflow/do-not-paint-outline-into-composited-scr olling-contents.html 275 // Hits in compositing/overflow/do-not-paint-outline-into-composited-scr olling-contents.html
278 DisableCompositingQueryAsserts disabler; 276 DisableCompositingQueryAsserts disabler;
279 updateAppearance(); 277 updateAppearance();
280 } 278 }
281 279
282 // Always clear the x position used for vertical arrow navigation. 280 // Always clear the x position used for vertical arrow navigation.
283 // It will be restored by the vertical arrow navigation code if necessary. 281 // It will be restored by the vertical arrow navigation code if necessary.
284 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); 282 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation();
285 selectFrameElementInParentIfFullySelected(); 283 selectFrameElementInParentIfFullySelected();
286 notifyRendererOfSelectionChange(userTriggered); 284 notifyRendererOfSelectionChange(userTriggered);
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 } 1224 }
1227 1225
1228 static bool isTextFormControl(const VisibleSelection& selection) 1226 static bool isTextFormControl(const VisibleSelection& selection)
1229 { 1227 {
1230 return enclosingTextFormControl(selection.start()); 1228 return enclosingTextFormControl(selection.start());
1231 } 1229 }
1232 1230
1233 LayoutRect FrameSelection::localCaretRect() 1231 LayoutRect FrameSelection::localCaretRect()
1234 { 1232 {
1235 if (shouldUpdateCaretRect()) { 1233 if (shouldUpdateCaretRect()) {
1236 if (!isNonOrphanedCaret(m_selection)) 1234 if (!isNonOrphanedCaret(m_selection)) {
1237 clearCaretRect(); 1235 clearCaretRect();
1238 else if (isTextFormControl(m_selection)) 1236 } else if (isTextFormControl(m_selection)) {
1237 m_frame->document()->updateLayoutIgnorePendingStylesheets();
1239 m_absCaretBoundsDirty |= updateCaretRect(m_frame->document(), Positi onWithAffinity(m_selection.start().isCandidate() ? m_selection.start() : Positio n(), m_selection.affinity())); 1238 m_absCaretBoundsDirty |= updateCaretRect(m_frame->document(), Positi onWithAffinity(m_selection.start().isCandidate() ? m_selection.start() : Positio n(), m_selection.affinity()));
1240 else 1239 } else {
1241 m_absCaretBoundsDirty |= updateCaretRect(m_frame->document(), Visibl ePosition(m_selection.start(), m_selection.affinity())); 1240 m_absCaretBoundsDirty |= updateCaretRect(m_frame->document(), Visibl ePosition(m_selection.start(), m_selection.affinity()));
1241 }
1242 } 1242 }
1243 1243
1244 return localCaretRectWithoutUpdate(); 1244 return localCaretRectWithoutUpdate();
1245 } 1245 }
1246 1246
1247 IntRect FrameSelection::absoluteCaretBounds() 1247 IntRect FrameSelection::absoluteCaretBounds()
1248 { 1248 {
1249 recomputeCaretRect(); 1249 recomputeCaretRect();
1250 return m_absCaretBounds; 1250 return m_absCaretBounds;
1251 } 1251 }
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
1285 void FrameSelection::invalidateCaretRect() 1285 void FrameSelection::invalidateCaretRect()
1286 { 1286 {
1287 if (!isCaret()) 1287 if (!isCaret())
1288 return; 1288 return;
1289 1289
1290 CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recompu teCaretRect()); 1290 CaretBase::invalidateCaretRect(m_selection.start().deprecatedNode(), recompu teCaretRect());
1291 } 1291 }
1292 1292
1293 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect) 1293 void FrameSelection::paintCaret(GraphicsContext* context, const LayoutPoint& pai ntOffset, const LayoutRect& clipRect)
1294 { 1294 {
1295 if (m_selection.isCaret() && m_caretPaint) 1295 if (m_selection.isCaret() && m_caretPaint) {
1296 localCaretRect();
yosin_UTC9 2014/08/04 01:44:23 The name of |localCaretRect()| make me to feel it
yoichio 2014/08/04 02:12:18 Done.
1296 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect); 1297 CaretBase::paintCaret(m_selection.start().deprecatedNode(), context, pai ntOffset, clipRect);
1298 }
1297 } 1299 }
1298 1300
1299 bool FrameSelection::contains(const LayoutPoint& point) 1301 bool FrameSelection::contains(const LayoutPoint& point)
1300 { 1302 {
1301 Document* document = m_frame->document(); 1303 Document* document = m_frame->document();
1302 1304
1303 // Treat a collapsed selection like no selection. 1305 // Treat a collapsed selection like no selection.
1304 if (!isRange()) 1306 if (!isRange())
1305 return false; 1307 return false;
1306 if (!document->renderView()) 1308 if (!document->renderView())
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
1535 return m_focused && m_frame->page() && m_frame->page()->focusController().is Active(); 1537 return m_focused && m_frame->page() && m_frame->page()->focusController().is Active();
1536 } 1538 }
1537 1539
1538 inline static bool shouldStopBlinkingDueToTypingCommand(LocalFrame* frame) 1540 inline static bool shouldStopBlinkingDueToTypingCommand(LocalFrame* frame)
1539 { 1541 {
1540 return frame->editor().lastEditCommand() && frame->editor().lastEditCommand( )->shouldStopCaretBlinking(); 1542 return frame->editor().lastEditCommand() && frame->editor().lastEditCommand( )->shouldStopCaretBlinking();
1541 } 1543 }
1542 1544
1543 void FrameSelection::updateAppearance() 1545 void FrameSelection::updateAppearance()
1544 { 1546 {
1547 bool isTextForm = isTextFormControl(m_selection);
1545 // Paint a block cursor instead of a caret in overtype mode unless the caret is at the end of a line (in this case 1548 // Paint a block cursor instead of a caret in overtype mode unless the caret is at the end of a line (in this case
1546 // the FrameSelection will paint a blinking caret as usual). 1549 // the FrameSelection will paint a blinking caret as usual).
1547 VisiblePosition forwardPosition; 1550 VisiblePosition forwardPosition;
1548 if (m_shouldShowBlockCursor && m_selection.isCaret()) { 1551 if (m_shouldShowBlockCursor && m_selection.isCaret()) {
1549 forwardPosition = modifyExtendingForward(CharacterGranularity); 1552 forwardPosition = modifyExtendingForward(CharacterGranularity);
1550 m_caretPaint = forwardPosition.isNull(); 1553 m_caretPaint = forwardPosition.isNull();
1551 } 1554 }
1552 1555
1553 bool caretRectChangedOrCleared = recomputeCaretRect(); 1556 bool caretRectChangedOrCleared = isTextForm || recomputeCaretRect();
1554 bool shouldBlink = shouldBlinkCaret() && forwardPosition.isNull(); 1557 bool shouldBlink = shouldBlinkCaret() && forwardPosition.isNull();
1555 1558
1556 // If the caret moved, stop the blink timer so we can restart with a 1559 // If the caret moved, stop the blink timer so we can restart with a
1557 // black caret in the new location. 1560 // black caret in the new location.
1558 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi ngCommand(m_frame)) { 1561 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi ngCommand(m_frame)) {
1559 m_caretBlinkTimer.stop(); 1562 m_caretBlinkTimer.stop();
1560 if (!shouldBlink && m_caretPaint) { 1563 if (!shouldBlink && m_caretPaint) {
1561 m_caretPaint = false; 1564 m_caretPaint = false;
1562 invalidateCaretRect(); 1565 invalidateCaretRect();
1563 } 1566 }
(...skipping 10 matching lines...) Expand all
1574 invalidateCaretRect(); 1577 invalidateCaretRect();
1575 } 1578 }
1576 } 1579 }
1577 1580
1578 RenderView* view = m_frame->contentRenderer(); 1581 RenderView* view = m_frame->contentRenderer();
1579 if (!view) 1582 if (!view)
1580 return; 1583 return;
1581 1584
1582 // Construct a new VisibleSolution, since m_selection is not necessarily val id, and the following steps 1585 // Construct a new VisibleSolution, since m_selection is not necessarily val id, and the following steps
1583 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69 563> and <rdar://problem/10232866>. 1586 // assume a valid selection. See <https://bugs.webkit.org/show_bug.cgi?id=69 563> and <rdar://problem/10232866>.
1584 VisibleSelection selection(m_selection.visibleStart(), forwardPosition.isNot Null() ? forwardPosition : m_selection.visibleEnd()); 1587 VisibleSelection selection;
1588 if (isTextForm)
1589 selection.setWithoutValidation(m_selection.start(), forwardPosition.isNo tNull() ? forwardPosition.deepEquivalent() : m_selection.end());
1590 else
1591 selection = VisibleSelection(m_selection.visibleStart(), forwardPosition .isNotNull() ? forwardPosition : m_selection.visibleEnd());
1585 1592
1586 if (!selection.isRange()) { 1593 if (!selection.isRange()) {
1587 view->clearSelection(); 1594 view->clearSelection();
1588 return; 1595 return;
1589 } 1596 }
1590 1597
1591 // Use the rightmost candidate for the start of the selection, and the leftm ost candidate for the end of the selection. 1598 // Use the rightmost candidate for the start of the selection, and the leftm ost candidate for the end of the selection.
1592 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an d that 'bar' is selected. If we pass [foo, 3] 1599 // Example: foo <a>bar</a>. Imagine that a line wrap occurs after 'foo', an d that 'bar' is selected. If we pass [foo, 3]
1593 // as the start of the selection, the selection painting code will think tha t content on the line containing 'foo' is selected 1600 // as the start of the selection, the selection painting code will think tha t content on the line containing 'foo' is selected
1594 // and will fill the gap before 'bar'. 1601 // and will fill the gap before 'bar'.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1650 ASSERT(caretIsVisible()); 1657 ASSERT(caretIsVisible());
1651 ASSERT(isCaret()); 1658 ASSERT(isCaret());
1652 if (isCaretBlinkingSuspended() && m_caretPaint) 1659 if (isCaretBlinkingSuspended() && m_caretPaint)
1653 return; 1660 return;
1654 m_caretPaint = !m_caretPaint; 1661 m_caretPaint = !m_caretPaint;
1655 invalidateCaretRect(); 1662 invalidateCaretRect();
1656 } 1663 }
1657 1664
1658 void FrameSelection::notifyRendererOfSelectionChange(EUserTriggered userTriggere d) 1665 void FrameSelection::notifyRendererOfSelectionChange(EUserTriggered userTriggere d)
1659 { 1666 {
1660 m_frame->document()->updateRenderTreeIfNeeded();
1661
1662 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start ())) 1667 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start ()))
1663 textControl->selectionChanged(userTriggered == UserTriggered); 1668 textControl->selectionChanged(userTriggered == UserTriggered);
1664 } 1669 }
1665 1670
1666 // Helper function that tells whether a particular node is an element that has a n entire 1671 // Helper function that tells whether a particular node is an element that has a n entire
1667 // LocalFrame and FrameView, a <frame>, <iframe>, or <object>. 1672 // LocalFrame and FrameView, a <frame>, <iframe>, or <object>.
1668 static bool isFrameElement(const Node* n) 1673 static bool isFrameElement(const Node* n)
1669 { 1674 {
1670 if (!n) 1675 if (!n)
1671 return false; 1676 return false;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
1927 sel.showTreeForThis(); 1932 sel.showTreeForThis();
1928 } 1933 }
1929 1934
1930 void showTree(const blink::FrameSelection* sel) 1935 void showTree(const blink::FrameSelection* sel)
1931 { 1936 {
1932 if (sel) 1937 if (sel)
1933 sel->showTreeForThis(); 1938 sel->showTreeForThis();
1934 } 1939 }
1935 1940
1936 #endif 1941 #endif
OLDNEW
« no previous file with comments | « no previous file | Source/core/html/HTMLTextFormControlElementTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698