void FrameCaret::updateAppearance() { // Paint a block cursor instead of a caret in overtype mode unless the caret // is at the end of a line (in this case the FrameSelection will paint a // blinking caret as usual). bool paintBlockCursor = m_shouldShowBlockCursor && isActive(); if (paintBlockCursor) { // TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets // needs to be audited. see http://crbug.com/590369 for more details. // In the long term, we should defer the update of the caret's appearance // to prevent synchronous layout. m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); if (isLogicalEndOfLine(createVisiblePosition(caretPosition()))) paintBlockCursor = false; } bool shouldBlink = !paintBlockCursor && shouldBlinkCaret(); // If the caret moved, stop the blink timer so we can restart with a // black caret in the new location. if (!shouldBlink || shouldStopBlinkingDueToTypingCommand(m_frame)) stopCaretBlinkTimer(); // Start blinking with a black caret. Be sure not to restart if we're // already blinking in the right location. if (shouldBlink) startBlinkCaret(); }
VisibleSelectionTemplate<Strategy> PendingSelection::calcVisibleSelectionAlgorithm(const VisibleSelectionTemplate<Strategy>& originalSelection) const { const PositionTemplate<Strategy> start = originalSelection.start(); const PositionTemplate<Strategy> end = originalSelection.end(); SelectionType selectionType = originalSelection.selectionType(); const TextAffinity affinity = originalSelection.affinity(); bool paintBlockCursor = m_frameSelection->shouldShowBlockCursor() && selectionType == SelectionType::CaretSelection && !isLogicalEndOfLine(createVisiblePosition(end, affinity)); VisibleSelectionTemplate<Strategy> selection; if (enclosingTextFormControl(start.computeContainerNode())) { // TODO(yosin) We should use |PositionMoveType::Character| to avoid // ending paint at middle of character. PositionTemplate<Strategy> endPosition = paintBlockCursor ? nextPositionOf(originalSelection.extent(), PositionMoveType::CodePoint) : end; selection.setWithoutValidation(start, endPosition); return selection; } const VisiblePositionTemplate<Strategy> visibleStart = createVisiblePosition(start, selectionType == SelectionType::RangeSelection ? TextAffinity::Downstream : affinity); if (paintBlockCursor) { VisiblePositionTemplate<Strategy> visibleExtent = createVisiblePosition(end, affinity); visibleExtent = nextPositionOf(visibleExtent, CanSkipOverEditingBoundary); return VisibleSelectionTemplate<Strategy>(visibleStart, visibleExtent); } const VisiblePositionTemplate<Strategy> visibleEnd = createVisiblePosition(end, selectionType == SelectionType::RangeSelection ? TextAffinity::Upstream : affinity); return VisibleSelectionTemplate<Strategy>(visibleStart, visibleEnd); }
VisibleSelection PendingSelection::calcVisibleSelectionAlgorithm() const { using PositionType = typename Strategy::PositionType; PositionType start = Strategy::selectionStart(m_selection); PositionType end = Strategy::selectionEnd(m_selection); SelectionType selectionType = VisibleSelection::selectionType(start, end); TextAffinity affinity = m_selection.affinity(); bool paintBlockCursor = m_shouldShowBlockCursor && selectionType == SelectionType::CaretSelection && !isLogicalEndOfLine(VisiblePosition(end, affinity)); VisibleSelection selection; if (enclosingTextFormControl(start.computeContainerNode())) { // TODO(yosin) We should use |PositionMoveType::Character| to avoid // ending paint at middle of character. PositionType endPosition = paintBlockCursor ? nextPositionOf(Strategy::selectionExtent(m_selection), PositionMoveType::CodePoint) : end; selection.setWithoutValidation(start, endPosition); return selection; } VisiblePosition visibleStart = VisiblePosition(start, selectionType == SelectionType::RangeSelection ? TextAffinity::Downstream : affinity); if (paintBlockCursor) { VisiblePosition visibleExtent(end, affinity); visibleExtent = visibleExtent.next(CanSkipOverEditingBoundary); return VisibleSelection(visibleStart, visibleExtent); } VisiblePosition visibleEnd(end, selectionType == SelectionType::RangeSelection ? TextAffinity::Upstream : affinity); return VisibleSelection(visibleStart, visibleEnd); }