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

Unified Diff: third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h

Issue 2701983002: Implement complete lifecycle transition for IdleSpellCheckCallback (Closed)
Patch Set: Fix compiler error Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h
diff --git a/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h b/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h
index 7ddc2c4e392948fb656d778e54921844368ef91e..db1e34d49f2b9e952e397da3c15dcdcc17755b47 100644
--- a/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h
+++ b/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h
@@ -6,6 +6,7 @@
#define IdleSpellCheckCallback_h
#include "core/dom/IdleRequestCallback.h"
+#include "core/dom/SynchronousMutationObserver.h"
#include "platform/Timer.h"
namespace blink {
@@ -14,28 +15,45 @@ class LocalFrame;
class SpellCheckRequester;
// Main class for the implementation of idle time spell checker.
-class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback {
+class CORE_EXPORT IdleSpellCheckCallback final
+ : public IdleRequestCallback,
+ public SynchronousMutationObserver {
+ DISALLOW_COPY_AND_ASSIGN(IdleSpellCheckCallback);
+ USING_GARBAGE_COLLECTED_MIXIN(IdleSpellCheckCallback);
+
public:
static IdleSpellCheckCallback* create(LocalFrame&);
~IdleSpellCheckCallback() override;
+ enum class State {
+ kInactive,
+ kHotModeRequested,
+ kInHotModeInvocation,
+ kColdModeTimerStarted,
+ kColdModeRequested,
+ kInColdModeInvocation
+ };
+
+ State state() const { return m_state; }
+
// Transit to HotModeRequested, if possible. Called by operations that need
// spell checker to follow up.
- // TODO(xiaochengh): Add proper call sites.
- void setNeedsHotModeInvocation();
-
- // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
- // cold mode invocation if no critical operation occurs before timer firing.
- // TODO(xiaochengh): Add proper call sites.
- void setNeedsColdModeInvocation();
+ void setNeedsInvocation();
// Cleans everything up and makes the callback inactive. Should be called when
// document is detached or spellchecking is globally disabled.
- // TODO(xiaochengh): Add proper call sites.
void deactivate();
+ void documentAttached(Document*);
+
// Exposed for testing only.
SpellCheckRequester& spellCheckRequester() const;
+ void forceInvocationForTesting();
+ void setNeedsMoreColdModeInvocationForTesting() {
+ m_needsMoreColdModeInvocationForTesting = true;
+ }
+ void skipColdModeTimerForTesting();
+ int idleCallbackHandle() const { return m_idleCallbackHandle; }
DECLARE_VIRTUAL_TRACE();
@@ -45,15 +63,6 @@ class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback {
LocalFrame& frame() const { return *m_frame; }
- enum class State {
- kInactive,
- kHotModeRequested,
- kInHotModeInvocation,
- kColdModeTimerStarted,
- kColdModeRequested,
- kInColdModeInvocation
- };
-
// Returns whether spell checking is globally enabled.
bool isSpellCheckingEnabled() const;
@@ -63,12 +72,21 @@ class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback {
// Functions for hot mode.
void hotModeInvocation(IdleDeadline*);
+ // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
+ // cold mode invocation if no critical operation occurs before timer firing.
+ void setNeedsColdModeInvocation();
+
// Functions for cold mode.
void coldModeTimerFired(TimerBase*);
void coldModeInvocation(IdleDeadline*);
bool coldModeFinishesFullDocument() const;
+ // Implements |SynchronousMutationObserver|.
+ void contextDestroyed(Document*) final;
+
State m_state;
+ int m_idleCallbackHandle;
+ mutable bool m_needsMoreColdModeInvocationForTesting;
const Member<LocalFrame> m_frame;
TaskRunnerTimer<IdleSpellCheckCallback> m_coldModeTimer;

Powered by Google App Engine
This is Rietveld 408576698