| 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 // Used by FrameView to keep track of the number of layout objects created |
| 26 // in the frame. |
| 27 class LayoutObjectCounter { |
| 28 public: |
| 29 void reset() { m_count = 0; } |
| 30 void increment() { m_count++; } |
| 31 unsigned count() const { return m_count; } |
| 32 private: |
| 33 unsigned m_count = 0; |
| 34 }; |
| 35 |
| 36 static FirstMeaningfulPaintDetector& from(Document&); |
| 37 |
| 38 FirstMeaningfulPaintDetector(PaintTiming*); |
| 39 virtual ~FirstMeaningfulPaintDetector() { } |
| 40 |
| 41 void markNextPaintAsMeaningfulIfNeeded(const LayoutObjectCounter&, |
| 42 int contentsHeightBeforeLayout, int contentsHeightAfterLayout, int visib
leHeight); |
| 43 void notifyPaint(); |
| 44 void checkNetworkStable(); |
| 45 |
| 46 DECLARE_TRACE(); |
| 47 |
| 48 private: |
| 49 friend class FirstMeaningfulPaintDetectorTest; |
| 50 |
| 51 Document* document(); |
| 52 void networkStableTimerFired(TimerBase*); |
| 53 |
| 54 enum State { NextPaintIsNotMeaningful, NextPaintIsMeaningful, Reported }; |
| 55 State m_state = NextPaintIsNotMeaningful; |
| 56 |
| 57 Member<PaintTiming> m_paintTiming; |
| 58 double m_provisionalFirstMeaningfulPaint = 0.0; |
| 59 double m_maxSignificanceSoFar = 0.0; |
| 60 double m_accumulatedSignificanceWhileHavingBlankText = 0.0; |
| 61 unsigned m_prevLayoutObjectCount = 0; |
| 62 Timer<FirstMeaningfulPaintDetector> m_networkStableTimer; |
| 63 }; |
| 64 |
| 65 } // namespace blink |
| 66 |
| 67 #endif |
| OLD | NEW |