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

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

Issue 2578493002: Add a skeleton of idle time spell checker (Closed)
Patch Set: Fix usage of Timer::startOneShot Created 4 years 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
new file mode 100644
index 0000000000000000000000000000000000000000..1d86d02e81d370bd6b0009d9ca38a01381a20938
--- /dev/null
+++ b/third_party/WebKit/Source/core/editing/spellcheck/IdleSpellCheckCallback.h
@@ -0,0 +1,76 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef IdleSpellCheckCallback_h
+#define IdleSpellCheckCallback_h
+
+#include "core/dom/IdleRequestCallback.h"
+#include "core/frame/LocalFrame.h"
+#include "platform/Timer.h"
+
+namespace blink {
+
+// Main class for the implementation of idle time spell checker.
+class IdleSpellCheckCallback final : public IdleRequestCallback {
+ public:
+ // TODO(xiaochengh): Make each LocalFrame own an IdleSpellCheckCallback.
+ static IdleSpellCheckCallback* create(LocalFrame&);
+ ~IdleSpellCheckCallback() override;
+
+ // 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();
+
+ // 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();
+
+ DECLARE_VIRTUAL_TRACE();
+
+ private:
+ explicit IdleSpellCheckCallback(LocalFrame&);
+ void handleEvent(IdleDeadline*) override;
+
+ LocalFrame& frame() const { return *m_frame; }
+
+ enum class State {
+ Inactive,
tkent 2016/12/14 08:45:50 Please prepend 'k' to each items. Reference: [nam
Xiaocheng 2016/12/14 09:08:12 Done.
+ HotModeRequested,
+ InHotModeInvocation,
+ ColdModeTimerStarted,
+ ColdModeRequested,
+ InColdModeInvocation
+ };
+
+ // Returns whether spell checking is globally enabled.
+ bool isSpellCheckingEnabled() const;
+
+ // Calls requestIdleCallback with this IdleSpellCheckCallback.
+ void requestInvocation();
+
+ // Functions for hot mode.
+ void hotModeInvocation(IdleDeadline*);
+
+ // Functions for cold mode.
+ void coldModeTimerFired(TimerBase*);
+ void coldModeInvocation(IdleDeadline*);
+ bool coldModeFinishesFullDocument() const;
+
+ State m_state;
+ const Member<LocalFrame> m_frame;
+
+ // TODO(xiaochengh): assign the timer to some proper task runner.
+ Timer<IdleSpellCheckCallback> m_coldModeTimer;
+};
+
+} // namespace blink
+
+#endif // IdleSpellCheckCallback_h

Powered by Google App Engine
This is Rietveld 408576698