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

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

Issue 2701983002: Implement complete lifecycle transition for IdleSpellCheckCallback (Closed)
Patch Set: Fix compile 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 unified diff | Download patch
OLDNEW
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 #ifndef IdleSpellCheckCallback_h 5 #ifndef IdleSpellCheckCallback_h
6 #define IdleSpellCheckCallback_h 6 #define IdleSpellCheckCallback_h
7 7
8 #include "core/dom/IdleRequestCallback.h" 8 #include "core/dom/IdleRequestCallback.h"
9 #include "core/dom/SynchronousMutationObserver.h"
9 #include "platform/Timer.h" 10 #include "platform/Timer.h"
10 11
11 namespace blink { 12 namespace blink {
12 13
13 class LocalFrame; 14 class LocalFrame;
14 class SpellCheckRequester; 15 class SpellCheckRequester;
15 16
16 // Main class for the implementation of idle time spell checker. 17 // Main class for the implementation of idle time spell checker.
17 class CORE_EXPORT IdleSpellCheckCallback final : public IdleRequestCallback { 18 class CORE_EXPORT IdleSpellCheckCallback final
19 : public IdleRequestCallback,
20 public SynchronousMutationObserver {
yosin_UTC9 2017/02/25 02:22:57 FYI: We may want to introduce |DocumentShutdownObs
21 DISALLOW_COPY_AND_ASSIGN(IdleSpellCheckCallback);
22 USING_GARBAGE_COLLECTED_MIXIN(IdleSpellCheckCallback);
23
18 public: 24 public:
19 static IdleSpellCheckCallback* create(LocalFrame&); 25 static IdleSpellCheckCallback* create(LocalFrame&);
20 ~IdleSpellCheckCallback() override; 26 ~IdleSpellCheckCallback() override;
21 27
28 enum class State {
29 kInactive,
30 kHotModeRequested,
31 kInHotModeInvocation,
32 kColdModeTimerStarted,
33 kColdModeRequested,
34 kInColdModeInvocation
35 };
36
37 State state() const { return m_state; }
38
22 // Transit to HotModeRequested, if possible. Called by operations that need 39 // Transit to HotModeRequested, if possible. Called by operations that need
23 // spell checker to follow up. 40 // spell checker to follow up.
24 // TODO(xiaochengh): Add proper call sites. 41 void setNeedsInvocation();
25 void setNeedsHotModeInvocation();
26
27 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
28 // cold mode invocation if no critical operation occurs before timer firing.
29 // TODO(xiaochengh): Add proper call sites.
30 void setNeedsColdModeInvocation();
31 42
32 // Cleans everything up and makes the callback inactive. Should be called when 43 // Cleans everything up and makes the callback inactive. Should be called when
33 // document is detached or spellchecking is globally disabled. 44 // document is detached or spellchecking is globally disabled.
34 // TODO(xiaochengh): Add proper call sites.
35 void deactivate(); 45 void deactivate();
36 46
47 void documentAttached(Document*);
48
37 // Exposed for testing only. 49 // Exposed for testing only.
38 SpellCheckRequester& spellCheckRequester() const; 50 SpellCheckRequester& spellCheckRequester() const;
51 void forceInvocationForTesting();
52 void setNeedsMoreColdModeInvocationForTesting() {
53 m_needsMoreColdModeInvocationForTesting = true;
54 }
55 void skipColdModeTimerForTesting();
56 int idleCallbackHandle() const { return m_idleCallbackHandle; }
39 57
40 DECLARE_VIRTUAL_TRACE(); 58 DECLARE_VIRTUAL_TRACE();
41 59
42 private: 60 private:
43 explicit IdleSpellCheckCallback(LocalFrame&); 61 explicit IdleSpellCheckCallback(LocalFrame&);
44 void handleEvent(IdleDeadline*) override; 62 void handleEvent(IdleDeadline*) override;
45 63
46 LocalFrame& frame() const { return *m_frame; } 64 LocalFrame& frame() const { return *m_frame; }
47 65
48 enum class State {
49 kInactive,
50 kHotModeRequested,
51 kInHotModeInvocation,
52 kColdModeTimerStarted,
53 kColdModeRequested,
54 kInColdModeInvocation
55 };
56
57 // Returns whether spell checking is globally enabled. 66 // Returns whether spell checking is globally enabled.
58 bool isSpellCheckingEnabled() const; 67 bool isSpellCheckingEnabled() const;
59 68
60 // Calls requestIdleCallback with this IdleSpellCheckCallback. 69 // Calls requestIdleCallback with this IdleSpellCheckCallback.
61 void requestInvocation(); 70 void requestInvocation();
62 71
63 // Functions for hot mode. 72 // Functions for hot mode.
64 void hotModeInvocation(IdleDeadline*); 73 void hotModeInvocation(IdleDeadline*);
65 74
75 // Transit to ColdModeTimerStarted, if possible. Sets up a timer, and requests
76 // cold mode invocation if no critical operation occurs before timer firing.
77 void setNeedsColdModeInvocation();
78
66 // Functions for cold mode. 79 // Functions for cold mode.
67 void coldModeTimerFired(TimerBase*); 80 void coldModeTimerFired(TimerBase*);
68 void coldModeInvocation(IdleDeadline*); 81 void coldModeInvocation(IdleDeadline*);
69 bool coldModeFinishesFullDocument() const; 82 bool coldModeFinishesFullDocument() const;
70 83
84 // Implements |SynchronousMutationObserver|.
85 void contextDestroyed(Document*) final;
86
71 State m_state; 87 State m_state;
88 int m_idleCallbackHandle;
89 mutable bool m_needsMoreColdModeInvocationForTesting;
72 const Member<LocalFrame> m_frame; 90 const Member<LocalFrame> m_frame;
73 91
74 TaskRunnerTimer<IdleSpellCheckCallback> m_coldModeTimer; 92 TaskRunnerTimer<IdleSpellCheckCallback> m_coldModeTimer;
75 }; 93 };
76 94
77 } // namespace blink 95 } // namespace blink
78 96
79 #endif // IdleSpellCheckCallback_h 97 #endif // IdleSpellCheckCallback_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698