Index: Source/core/dom/WhitespaceChildList.h |
diff --git a/Source/core/platform/Task.h b/Source/core/dom/WhitespaceChildList.h |
similarity index 56% |
copy from Source/core/platform/Task.h |
copy to Source/core/dom/WhitespaceChildList.h |
index b9d2e46802aebf6391df4ec3dabb580d43b2483c..b5a4fb14f656e6ca69c20b1dbf92c26bc71b2b9b 100644 |
--- a/Source/core/platform/Task.h |
+++ b/Source/core/dom/WhitespaceChildList.h |
@@ -7,10 +7,6 @@ |
* |
* * Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
- * * Redistributions in binary form must reproduce the above |
- * copyright notice, this list of conditions and the following disclaimer |
- * in the documentation and/or other materials provided with the |
- * distribution. |
* * Neither the name of Google Inc. nor the names of its |
* contributors may be used to endorse or promote products derived from |
* this software without specific prior written permission. |
@@ -28,30 +24,48 @@ |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
-#ifndef Task_h |
-#define Task_h |
+#ifndef WhitespaceChildList_h |
+#define WhitespaceChildList_h |
-#include "wtf/Functional.h" |
-#include "public/platform/WebThread.h" |
+#include "core/dom/Text.h" |
+#include "core/rendering/style/RenderStyleConstants.h" |
namespace WebCore { |
-class Task : public WebKit::WebThread::Task { |
+class Text; |
+ |
+// Tracks a limited number of whitespace text children during style recalc |
+// to postpone their style recalc as part of optimization to avoid creating |
+// unnecessary whitespace text renderers. If we hit the limit, it recalcs |
+// the whitespace text's style and clears the list. |
+class WhitespaceChildList { |
public: |
- explicit Task(const Closure& closure) |
- : m_closure(closure) |
+ WhitespaceChildList(StyleRecalcChange change) |
+ : m_change(change) |
+ { } |
+ |
+ void append(Text* textChild) |
{ |
+ ASSERT(textChild->containsOnlyWhitespace()); |
+ if (m_list.size() == maxWhitespaceChildrenToDefer) { |
+ recalcStyle(); |
+ m_list.clear(); |
+ } |
+ m_list.append(textChild); |
} |
- virtual void run() OVERRIDE |
+ void recalcStyle() const |
{ |
- m_closure(); |
+ for (unsigned i = 0; i < m_list.size(); ++i) |
+ m_list[i]->recalcTextStyle(m_change); |
} |
- |
private: |
- Closure m_closure; |
+ StyleRecalcChange m_change; |
+ |
+ static const unsigned maxWhitespaceChildrenToDefer = 10; |
+ Vector<Text*, maxWhitespaceChildrenToDefer> m_list; |
}; |
} // namespace WebCore |
-#endif // Task_h |
+#endif // WhitespaceChildList_h |