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

Side by Side Diff: third_party/WebKit/Source/core/dom/DocumentLifecycle.h

Issue 2528113002: [PAUSED] Add a scope for disallowing style update when calling hasEditableStyle (Closed)
Patch Set: Add DocumentLifecycle::DisallowStyleRecalcScope 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 : m_documentLifecycle(documentLifecycle) { 143 : m_documentLifecycle(documentLifecycle) {
144 m_documentLifecycle.incrementDetachCount(); 144 m_documentLifecycle.incrementDetachCount();
145 } 145 }
146 146
147 ~DetachScope() { m_documentLifecycle.decrementDetachCount(); } 147 ~DetachScope() { m_documentLifecycle.decrementDetachCount(); }
148 148
149 private: 149 private:
150 DocumentLifecycle& m_documentLifecycle; 150 DocumentLifecycle& m_documentLifecycle;
151 }; 151 };
152 152
153 // This scope should only be used when we need to call hasEditableStyle(), but
154 // the document's style may be dirty and cannot be updated due to some other
155 // blockers. In the long term, we should fix those blockers and remove this
156 // scope. See crbug.com/667575 for details.
157 class DisallowStyleRecalcScope {
158 STACK_ALLOCATED();
159 WTF_MAKE_NONCOPYABLE(DisallowStyleRecalcScope);
yosin_UTC9 2016/11/25 09:52:37 Use |DISALLOW_COPY_AND_ASSIGN(DisallowStyleRecalcS
Xiaocheng 2016/11/25 10:05:32 Done.
160
161 public:
162 explicit DisallowStyleRecalcScope(DocumentLifecycle& documentLifecycle)
163 : m_documentLifecycle(documentLifecycle) {
164 m_documentLifecycle.incrementNoStyleRecalcCount();
165 }
166
167 ~DisallowStyleRecalcScope() {
168 m_documentLifecycle.decrementNoStyleRecalcCount();
169 }
170
171 private:
172 DocumentLifecycle& m_documentLifecycle;
173 };
174
153 // Throttling is disabled by default. Instantiating this class allows 175 // Throttling is disabled by default. Instantiating this class allows
154 // throttling (e.g., during BeginMainFrame). If a script needs to run inside 176 // throttling (e.g., during BeginMainFrame). If a script needs to run inside
155 // this scope, DisallowThrottlingScope should be used to let the script 177 // this scope, DisallowThrottlingScope should be used to let the script
156 // perform a synchronous layout if necessary. 178 // perform a synchronous layout if necessary.
157 class CORE_EXPORT AllowThrottlingScope { 179 class CORE_EXPORT AllowThrottlingScope {
158 STACK_ALLOCATED(); 180 STACK_ALLOCATED();
159 WTF_MAKE_NONCOPYABLE(AllowThrottlingScope); 181 WTF_MAKE_NONCOPYABLE(AllowThrottlingScope);
160 182
161 public: 183 public:
162 AllowThrottlingScope(DocumentLifecycle&); 184 AllowThrottlingScope(DocumentLifecycle&);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 m_disallowTransitionCount--; 219 m_disallowTransitionCount--;
198 } 220 }
199 221
200 bool inDetach() const { return m_detachCount; } 222 bool inDetach() const { return m_detachCount; }
201 void incrementDetachCount() { m_detachCount++; } 223 void incrementDetachCount() { m_detachCount++; }
202 void decrementDetachCount() { 224 void decrementDetachCount() {
203 DCHECK_GT(m_detachCount, 0); 225 DCHECK_GT(m_detachCount, 0);
204 m_detachCount--; 226 m_detachCount--;
205 } 227 }
206 228
229 bool styleRecalcDisallowed() const { return m_disallowStyleRecalcCount; }
230 void incrementNoStyleRecalcCount() { ++m_disallowStyleRecalcCount; }
231 void decrementNoStyleRecalcCount() { --m_disallowStyleRecalcCount; }
232
207 bool throttlingAllowed() const; 233 bool throttlingAllowed() const;
208 234
209 private: 235 private:
210 #if DCHECK_IS_ON() 236 #if DCHECK_IS_ON()
211 static const char* stateAsDebugString(const LifecycleState); 237 static const char* stateAsDebugString(const LifecycleState);
212 bool canAdvanceTo(LifecycleState) const; 238 bool canAdvanceTo(LifecycleState) const;
213 bool canRewindTo(LifecycleState) const; 239 bool canRewindTo(LifecycleState) const;
214 #endif 240 #endif
215 241
216 LifecycleState m_state; 242 LifecycleState m_state;
217 int m_detachCount; 243 int m_detachCount;
218 int m_disallowTransitionCount; 244 int m_disallowTransitionCount;
245 int m_disallowStyleRecalcCount;
219 }; 246 };
220 247
221 inline bool DocumentLifecycle::stateAllowsTreeMutations() const { 248 inline bool DocumentLifecycle::stateAllowsTreeMutations() const {
222 // FIXME: We should not allow mutations in InPreLayout or AfterPerformLayout 249 // FIXME: We should not allow mutations in InPreLayout or AfterPerformLayout
223 // either, but we need to fix MediaList listeners and plugins first. 250 // either, but we need to fix MediaList listeners and plugins first.
224 return m_state != InStyleRecalc && m_state != InPerformLayout && 251 return m_state != InStyleRecalc && m_state != InPerformLayout &&
225 m_state != InCompositingUpdate && m_state != InPrePaint && 252 m_state != InCompositingUpdate && m_state != InPrePaint &&
226 m_state != InPaint; 253 m_state != InPaint;
227 } 254 }
228 255
(...skipping 17 matching lines...) Expand all
246 273
247 inline bool DocumentLifecycle::stateAllowsLayoutInvalidation() const { 274 inline bool DocumentLifecycle::stateAllowsLayoutInvalidation() const {
248 return m_state != InPerformLayout && m_state != InCompositingUpdate && 275 return m_state != InPerformLayout && m_state != InCompositingUpdate &&
249 m_state != InPaintInvalidation && m_state != InPrePaint && 276 m_state != InPaintInvalidation && m_state != InPrePaint &&
250 m_state != InPaint; 277 m_state != InPaint;
251 } 278 }
252 279
253 } // namespace blink 280 } // namespace blink
254 281
255 #endif 282 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698