| 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 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(ResetCaretBlink); |
| 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); |
| 287 m_frame->editor().respondToChangedSelection(oldSelection, options); | 285 m_frame->editor().respondToChangedSelection(oldSelection, options); |
| 288 if (userTriggered == UserTriggered) { | 286 if (userTriggered == UserTriggered) { |
| 289 ScrollAlignment alignment; | 287 ScrollAlignment alignment; |
| (...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1223 static bool isNonOrphanedCaret(const VisibleSelection& selection) | 1221 static bool isNonOrphanedCaret(const VisibleSelection& selection) |
| 1224 { | 1222 { |
| 1225 return selection.isCaret() && !selection.start().isOrphan() && !selection.en
d().isOrphan(); | 1223 return selection.isCaret() && !selection.start().isOrphan() && !selection.en
d().isOrphan(); |
| 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 void FrameSelection::updateLocalCaretRect() |
| 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 | |
| 1244 return localCaretRectWithoutUpdate(); | |
| 1245 } | 1243 } |
| 1246 | 1244 |
| 1247 IntRect FrameSelection::absoluteCaretBounds() | 1245 IntRect FrameSelection::absoluteCaretBounds() |
| 1248 { | 1246 { |
| 1249 recomputeCaretRect(); | 1247 recomputeCaretRect(); |
| 1250 return m_absCaretBounds; | 1248 return m_absCaretBounds; |
| 1251 } | 1249 } |
| 1252 | 1250 |
| 1253 bool FrameSelection::recomputeCaretRect() | 1251 bool FrameSelection::recomputeCaretRect() |
| 1254 { | 1252 { |
| 1255 if (!shouldUpdateCaretRect()) | 1253 if (!shouldUpdateCaretRect()) |
| 1256 return false; | 1254 return false; |
| 1257 | 1255 |
| 1258 if (!m_frame || !m_frame->document()->view()) | 1256 if (!m_frame || !m_frame->document()->view()) |
| 1259 return false; | 1257 return false; |
| 1260 | 1258 |
| 1261 LayoutRect oldRect = localCaretRectWithoutUpdate(); | 1259 LayoutRect oldRect = localCaretRectWithoutUpdate(); |
| 1262 LayoutRect newRect = localCaretRect(); | 1260 updateLocalCaretRect(); |
| 1261 LayoutRect newRect = localCaretRectWithoutUpdate(); |
| 1263 if (oldRect == newRect && !m_absCaretBoundsDirty) | 1262 if (oldRect == newRect && !m_absCaretBoundsDirty) |
| 1264 return false; | 1263 return false; |
| 1265 | 1264 |
| 1266 IntRect oldAbsCaretBounds = m_absCaretBounds; | 1265 IntRect oldAbsCaretBounds = m_absCaretBounds; |
| 1267 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecated
Node(), localCaretRectWithoutUpdate()); | 1266 m_absCaretBounds = absoluteBoundsForLocalRect(m_selection.start().deprecated
Node(), localCaretRectWithoutUpdate()); |
| 1268 m_absCaretBoundsDirty = false; | 1267 m_absCaretBoundsDirty = false; |
| 1269 | 1268 |
| 1270 if (oldAbsCaretBounds == m_absCaretBounds) | 1269 if (oldAbsCaretBounds == m_absCaretBounds) |
| 1271 return false; | 1270 return false; |
| 1272 | 1271 |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1533 bool FrameSelection::isFocusedAndActive() const | 1532 bool FrameSelection::isFocusedAndActive() const |
| 1534 { | 1533 { |
| 1535 return m_focused && m_frame->page() && m_frame->page()->focusController().is
Active(); | 1534 return m_focused && m_frame->page() && m_frame->page()->focusController().is
Active(); |
| 1536 } | 1535 } |
| 1537 | 1536 |
| 1538 inline static bool shouldStopBlinkingDueToTypingCommand(LocalFrame* frame) | 1537 inline static bool shouldStopBlinkingDueToTypingCommand(LocalFrame* frame) |
| 1539 { | 1538 { |
| 1540 return frame->editor().lastEditCommand() && frame->editor().lastEditCommand(
)->shouldStopCaretBlinking(); | 1539 return frame->editor().lastEditCommand() && frame->editor().lastEditCommand(
)->shouldStopCaretBlinking(); |
| 1541 } | 1540 } |
| 1542 | 1541 |
| 1543 void FrameSelection::updateAppearance() | 1542 void FrameSelection::updateAppearance(UpdateAppearanceOption option) |
| 1544 { | 1543 { |
| 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 | 1544 // 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). | 1545 // the FrameSelection will paint a blinking caret as usual). |
| 1547 VisiblePosition forwardPosition; | 1546 VisiblePosition forwardPosition; |
| 1548 if (m_shouldShowBlockCursor && m_selection.isCaret()) { | 1547 if (m_shouldShowBlockCursor && m_selection.isCaret()) { |
| 1549 forwardPosition = modifyExtendingForward(CharacterGranularity); | 1548 forwardPosition = modifyExtendingForward(CharacterGranularity); |
| 1550 m_caretPaint = forwardPosition.isNull(); | 1549 m_caretPaint = forwardPosition.isNull(); |
| 1551 } | 1550 } |
| 1552 | 1551 |
| 1553 bool caretRectChangedOrCleared = recomputeCaretRect(); | |
| 1554 bool shouldBlink = shouldBlinkCaret() && forwardPosition.isNull(); | 1552 bool shouldBlink = shouldBlinkCaret() && forwardPosition.isNull(); |
| 1555 | 1553 |
| 1556 // If the caret moved, stop the blink timer so we can restart with a | 1554 // If the caret moved, stop the blink timer so we can restart with a |
| 1557 // black caret in the new location. | 1555 // black caret in the new location. |
| 1558 if (caretRectChangedOrCleared || !shouldBlink || shouldStopBlinkingDueToTypi
ngCommand(m_frame)) { | 1556 if (option == ResetCaretBlink || !shouldBlink || shouldStopBlinkingDueToTypi
ngCommand(m_frame)) { |
| 1559 m_caretBlinkTimer.stop(); | 1557 m_caretBlinkTimer.stop(); |
| 1560 if (!shouldBlink && m_caretPaint) { | 1558 if (!shouldBlink && m_caretPaint) { |
| 1561 m_caretPaint = false; | 1559 m_caretPaint = false; |
| 1562 invalidateCaretRect(); | 1560 invalidateCaretRect(); |
| 1563 } | 1561 } |
| 1564 } | 1562 } |
| 1565 | 1563 |
| 1566 // Start blinking with a black caret. Be sure not to restart if we're | 1564 // Start blinking with a black caret. Be sure not to restart if we're |
| 1567 // already blinking in the right location. | 1565 // already blinking in the right location. |
| 1568 if (shouldBlink && !m_caretBlinkTimer.isActive()) { | 1566 if (shouldBlink && !m_caretBlinkTimer.isActive()) { |
| 1569 if (double blinkInterval = RenderTheme::theme().caretBlinkInterval()) | 1567 if (double blinkInterval = RenderTheme::theme().caretBlinkInterval()) |
| 1570 m_caretBlinkTimer.startRepeating(blinkInterval, FROM_HERE); | 1568 m_caretBlinkTimer.startRepeating(blinkInterval, FROM_HERE); |
| 1571 | 1569 |
| 1572 if (!m_caretPaint) { | 1570 if (!m_caretPaint) { |
| 1573 m_caretPaint = true; | 1571 m_caretPaint = true; |
| 1574 invalidateCaretRect(); | 1572 invalidateCaretRect(); |
| 1575 } | 1573 } |
| 1576 } | 1574 } |
| 1577 | 1575 |
| 1578 RenderView* view = m_frame->contentRenderer(); | 1576 RenderView* view = m_frame->contentRenderer(); |
| 1579 if (!view) | 1577 if (!view) |
| 1580 return; | 1578 return; |
| 1581 | 1579 |
| 1582 // Construct a new VisibleSolution, since m_selection is not necessarily val
id, and the following steps | 1580 // 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>. | 1581 // 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()); | 1582 VisibleSelection selection; |
| 1583 if (isTextFormControl(m_selection)) |
| 1584 selection.setWithoutValidation(m_selection.start(), forwardPosition.isNo
tNull() ? forwardPosition.deepEquivalent() : m_selection.end()); |
| 1585 else |
| 1586 selection = VisibleSelection(m_selection.visibleStart(), forwardPosition
.isNotNull() ? forwardPosition : m_selection.visibleEnd()); |
| 1585 | 1587 |
| 1586 if (!selection.isRange()) { | 1588 if (!selection.isRange()) { |
| 1587 view->clearSelection(); | 1589 view->clearSelection(); |
| 1588 return; | 1590 return; |
| 1589 } | 1591 } |
| 1590 | 1592 |
| 1591 // Use the rightmost candidate for the start of the selection, and the leftm
ost candidate for the end of the selection. | 1593 // 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] | 1594 // 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 | 1595 // 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'. | 1596 // and will fill the gap before 'bar'. |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1650 ASSERT(caretIsVisible()); | 1652 ASSERT(caretIsVisible()); |
| 1651 ASSERT(isCaret()); | 1653 ASSERT(isCaret()); |
| 1652 if (isCaretBlinkingSuspended() && m_caretPaint) | 1654 if (isCaretBlinkingSuspended() && m_caretPaint) |
| 1653 return; | 1655 return; |
| 1654 m_caretPaint = !m_caretPaint; | 1656 m_caretPaint = !m_caretPaint; |
| 1655 invalidateCaretRect(); | 1657 invalidateCaretRect(); |
| 1656 } | 1658 } |
| 1657 | 1659 |
| 1658 void FrameSelection::notifyRendererOfSelectionChange(EUserTriggered userTriggere
d) | 1660 void FrameSelection::notifyRendererOfSelectionChange(EUserTriggered userTriggere
d) |
| 1659 { | 1661 { |
| 1660 m_frame->document()->updateRenderTreeIfNeeded(); | |
| 1661 | |
| 1662 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start
())) | 1662 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start
())) |
| 1663 textControl->selectionChanged(userTriggered == UserTriggered); | 1663 textControl->selectionChanged(userTriggered == UserTriggered); |
| 1664 } | 1664 } |
| 1665 | 1665 |
| 1666 // Helper function that tells whether a particular node is an element that has a
n entire | 1666 // 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>. | 1667 // LocalFrame and FrameView, a <frame>, <iframe>, or <object>. |
| 1668 static bool isFrameElement(const Node* n) | 1668 static bool isFrameElement(const Node* n) |
| 1669 { | 1669 { |
| 1670 if (!n) | 1670 if (!n) |
| 1671 return false; | 1671 return false; |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1927 sel.showTreeForThis(); | 1927 sel.showTreeForThis(); |
| 1928 } | 1928 } |
| 1929 | 1929 |
| 1930 void showTree(const blink::FrameSelection* sel) | 1930 void showTree(const blink::FrameSelection* sel) |
| 1931 { | 1931 { |
| 1932 if (sel) | 1932 if (sel) |
| 1933 sel->showTreeForThis(); | 1933 sel->showTreeForThis(); |
| 1934 } | 1934 } |
| 1935 | 1935 |
| 1936 #endif | 1936 #endif |
| OLD | NEW |