| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef FirstMeaningfulPaintDetector_h |
| 6 #define FirstMeaningfulPaintDetector_h |
| 7 |
| 8 #include "core/CoreExport.h" |
| 9 #include "platform/Timer.h" |
| 10 #include "platform/heap/Handle.h" |
| 11 #include "wtf/Noncopyable.h" |
| 12 |
| 13 namespace blink { |
| 14 |
| 15 class Document; |
| 16 class PaintTiming; |
| 17 |
| 18 // FirstMeaningfulPaintDetector observes layout operations during page load |
| 19 // until network stable (2 seconds of no network activity), and computes the |
| 20 // layout-based First Meaningful Paint. |
| 21 // See https://goo.gl/vpaxv6 and http://goo.gl/TEiMi4 for more details. |
| 22 class CORE_EXPORT FirstMeaningfulPaintDetector : public GarbageCollectedFinalize
d<FirstMeaningfulPaintDetector> { |
| 23 WTF_MAKE_NONCOPYABLE(FirstMeaningfulPaintDetector); |
| 24 public: |
| 25 class LayoutObjectCounter { |
| 26 public: |
| 27 void reset() { m_count = 0; } |
| 28 void increment() { m_count++; } |
| 29 unsigned count() const { return m_count; } |
| 30 private: |
| 31 unsigned m_count = 0; |
| 32 }; |
| 33 |
| 34 static FirstMeaningfulPaintDetector& from(Document&); |
| 35 |
| 36 FirstMeaningfulPaintDetector(PaintTiming*); |
| 37 virtual ~FirstMeaningfulPaintDetector() { } |
| 38 |
| 39 void computeLayoutSignificance(const LayoutObjectCounter&, |
| 40 int contentsHeightBeforeLayout, int contentsHeightAfterLayout, int visib
leHeight); |
| 41 void notifyPaint(); |
| 42 void checkNetworkStable(); |
| 43 |
| 44 DECLARE_TRACE(); |
| 45 |
| 46 private: |
| 47 friend class FirstMeaningfulPaintDetectorTest; |
| 48 |
| 49 Document* document(); |
| 50 void networkStableTimerFired(TimerBase*); |
| 51 |
| 52 enum State { NextPaintIsNotMeaningful, NextPaintIsMeaningful, Reported }; |
| 53 State m_state = NextPaintIsNotMeaningful; |
| 54 |
| 55 Member<PaintTiming> m_paintTiming; |
| 56 double m_provisionalFirstMeaningfulPaint = 0.0; |
| 57 double m_maxSignificanceSoFar = 0.0; |
| 58 double m_accumulatedSignificanceWhileHavingBlankText = 0.0; |
| 59 unsigned m_prevLayoutObjectCount = 0; |
| 60 Timer<FirstMeaningfulPaintDetector> m_networkStableTimer; |
| 61 }; |
| 62 |
| 63 } // namespace blink |
| 64 |
| 65 #endif |
| OLD | NEW |