| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "core/editing/spellcheck/IdleSpellCheckCallback.h" | 5 #include "core/editing/spellcheck/IdleSpellCheckCallback.h" |
| 6 | 6 |
| 7 #include "core/dom/IdleRequestOptions.h" | 7 #include "core/dom/IdleRequestOptions.h" |
| 8 #include "core/dom/TaskRunnerHelper.h" | 8 #include "core/dom/TaskRunnerHelper.h" |
| 9 #include "core/editing/EditingUtilities.h" | 9 #include "core/editing/EditingUtilities.h" |
| 10 #include "core/editing/FrameSelection.h" | 10 #include "core/editing/FrameSelection.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 } | 46 } |
| 47 | 47 |
| 48 IdleSpellCheckCallback::IdleSpellCheckCallback(LocalFrame& frame) | 48 IdleSpellCheckCallback::IdleSpellCheckCallback(LocalFrame& frame) |
| 49 : m_state(State::kInactive), | 49 : m_state(State::kInactive), |
| 50 m_frame(frame), | 50 m_frame(frame), |
| 51 m_coldModeTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame), | 51 m_coldModeTimer(TaskRunnerHelper::get(TaskType::UnspecedTimer, &frame), |
| 52 this, | 52 this, |
| 53 &IdleSpellCheckCallback::coldModeTimerFired) {} | 53 &IdleSpellCheckCallback::coldModeTimerFired) {} |
| 54 | 54 |
| 55 SpellCheckRequester& IdleSpellCheckCallback::spellCheckRequester() const { | 55 SpellCheckRequester& IdleSpellCheckCallback::spellCheckRequester() const { |
| 56 // TODO(xiaochengh): decouple with SpellChecker after SpellCheckRequester is | |
| 57 // moved to IdleSpellCheckCallback. | |
| 58 return frame().spellChecker().spellCheckRequester(); | 56 return frame().spellChecker().spellCheckRequester(); |
| 59 } | 57 } |
| 60 | 58 |
| 61 bool IdleSpellCheckCallback::isSpellCheckingEnabled() const { | 59 bool IdleSpellCheckCallback::isSpellCheckingEnabled() const { |
| 62 // TODO(xiaochengh): decouple with SpellChecker. | |
| 63 return frame().spellChecker().isSpellCheckingEnabled(); | 60 return frame().spellChecker().isSpellCheckingEnabled(); |
| 64 } | 61 } |
| 65 | 62 |
| 66 void IdleSpellCheckCallback::prepareForLeakDetection() { | |
| 67 if (RuntimeEnabledFeatures::idleTimeSpellCheckingEnabled()) | |
| 68 spellCheckRequester().prepareForLeakDetection(); | |
| 69 } | |
| 70 | |
| 71 void IdleSpellCheckCallback::requestInvocation() { | 63 void IdleSpellCheckCallback::requestInvocation() { |
| 72 IdleRequestOptions options; | 64 IdleRequestOptions options; |
| 73 options.setTimeout(kRequestTimeoutMS); | 65 options.setTimeout(kRequestTimeoutMS); |
| 74 frame().document()->requestIdleCallback(this, options); | 66 frame().document()->requestIdleCallback(this, options); |
| 75 } | 67 } |
| 76 | 68 |
| 77 void IdleSpellCheckCallback::deactivate() { | 69 void IdleSpellCheckCallback::deactivate() { |
| 78 m_state = State::kInactive; | 70 m_state = State::kInactive; |
| 79 if (m_coldModeTimer.isActive()) | 71 if (m_coldModeTimer.isActive()) |
| 80 m_coldModeTimer.stop(); | 72 m_coldModeTimer.stop(); |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 if (coldModeFinishesFullDocument()) | 156 if (coldModeFinishesFullDocument()) |
| 165 m_state = State::kInactive; | 157 m_state = State::kInactive; |
| 166 else | 158 else |
| 167 setNeedsColdModeInvocation(); | 159 setNeedsColdModeInvocation(); |
| 168 } else { | 160 } else { |
| 169 NOTREACHED(); | 161 NOTREACHED(); |
| 170 } | 162 } |
| 171 } | 163 } |
| 172 | 164 |
| 173 } // namespace blink | 165 } // namespace blink |
| OLD | NEW |