Chromium Code Reviews| Index: third_party/WebKit/Source/core/editing/FrameCaret.cpp |
| diff --git a/third_party/WebKit/Source/core/editing/FrameCaret.cpp b/third_party/WebKit/Source/core/editing/FrameCaret.cpp |
| index f45bead89376b6cec0fd112fff8c2285135a8d5b..3e4424967ddef7ebf6460db486a2a37cb0d9c7e0 100644 |
| --- a/third_party/WebKit/Source/core/editing/FrameCaret.cpp |
| +++ b/third_party/WebKit/Source/core/editing/FrameCaret.cpp |
| @@ -28,9 +28,7 @@ |
| #include "core/dom/TaskRunnerHelper.h" |
| #include "core/editing/CaretDisplayItemClient.h" |
| #include "core/editing/EditingUtilities.h" |
| -#include "core/editing/Editor.h" |
| #include "core/editing/SelectionEditor.h" |
| -#include "core/editing/commands/CompositeEditCommand.h" |
| #include "core/frame/FrameView.h" |
| #include "core/frame/LocalFrame.h" |
| #include "core/frame/Settings.h" |
| @@ -49,9 +47,10 @@ FrameCaret::FrameCaret(LocalFrame& frame, |
| m_frame(frame), |
| m_displayItemClient(new CaretDisplayItemClient()), |
| m_caretVisibility(CaretVisibility::Hidden), |
| - m_caretBlinkTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame), |
| - this, |
| - &FrameCaret::caretBlinkTimerFired), |
| + m_caretBlinkTimer(new TaskRunnerTimer<FrameCaret>( |
| + TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame), |
| + this, |
| + &FrameCaret::caretBlinkTimerFired)), |
| m_shouldPaintCaret(true), |
| m_isCaretBlinkingSuspended(false), |
| m_shouldShowBlockCursor(false) {} |
| @@ -75,11 +74,6 @@ const PositionWithAffinity FrameCaret::caretPosition() const { |
| return PositionWithAffinity(selection.start(), selection.affinity()); |
| } |
| -inline static bool shouldStopBlinkingDueToTypingCommand(LocalFrame* frame) { |
| - return frame->editor().lastEditCommand() && |
| - frame->editor().lastEditCommand()->shouldStopCaretBlinking(); |
| -} |
| - |
| void FrameCaret::updateAppearance() { |
| DCHECK_GE(m_frame->document()->lifecycle().state(), |
| DocumentLifecycle::LayoutClean); |
| @@ -91,33 +85,30 @@ void FrameCaret::updateAppearance() { |
| !isLogicalEndOfLine(createVisiblePosition(caretPosition())); |
| 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)) |
| + if (!shouldBlink) { |
|
yosin_UTC9
2017/03/01 03:21:07
nit: I prefer early-return style to reduce indenta
tkent
2017/03/01 05:50:40
Done.
|
| stopCaretBlinkTimer(); |
| - |
| - // Start blinking with a black caret. Be sure not to restart if we're |
| - // already blinking in the right location. |
| - if (shouldBlink) |
| + } else { |
| + // Start blinking with a black caret. Be sure not to restart if we're |
| + // already blinking in the right location. |
| startBlinkCaret(); |
| + } |
| } |
| void FrameCaret::stopCaretBlinkTimer() { |
| - if (m_caretBlinkTimer.isActive() || m_shouldPaintCaret) |
| + if (m_caretBlinkTimer->isActive() || m_shouldPaintCaret) |
| scheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| m_shouldPaintCaret = false; |
| - m_caretBlinkTimer.stop(); |
| + m_caretBlinkTimer->stop(); |
| } |
| void FrameCaret::startBlinkCaret() { |
| // Start blinking with a black caret. Be sure not to restart if we're |
| // already blinking in the right location. |
| - if (m_caretBlinkTimer.isActive()) |
| + if (m_caretBlinkTimer->isActive()) |
| return; |
| if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval()) |
| - m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE); |
| + m_caretBlinkTimer->startRepeating(blinkInterval, BLINK_FROM_HERE); |
| m_shouldPaintCaret = true; |
| scheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| @@ -238,4 +229,10 @@ void FrameCaret::scheduleVisualUpdateForPaintInvalidationIfNeeded() { |
| frameView->scheduleVisualUpdateForPaintInvalidationIfNeeded(); |
| } |
| +void FrameCaret::recreateCaretBlinkTimerForTesting( |
| + RefPtr<WebTaskRunner> taskRunner) { |
| + m_caretBlinkTimer.reset(new TaskRunnerTimer<FrameCaret>( |
| + std::move(taskRunner), this, &FrameCaret::caretBlinkTimerFired)); |
| +} |
| + |
| } // namespace blink |