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

Side by Side Diff: Source/core/rendering/FastTextAutosizer.h

Issue 101543009: Make cluster creation independent of fingerprinting. Keep track of current (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@pdr-multiplier
Patch Set: Address review comments. Created 6 years, 11 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 /* 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 class FastTextAutosizer FINAL { 52 class FastTextAutosizer FINAL {
53 WTF_MAKE_NONCOPYABLE(FastTextAutosizer); 53 WTF_MAKE_NONCOPYABLE(FastTextAutosizer);
54 54
55 public: 55 public:
56 static PassOwnPtr<FastTextAutosizer> create(Document* document) 56 static PassOwnPtr<FastTextAutosizer> create(Document* document)
57 { 57 {
58 return adoptPtr(new FastTextAutosizer(document)); 58 return adoptPtr(new FastTextAutosizer(document));
59 } 59 }
60 60
61 void prepareForLayout();
62
63 void record(RenderBlock*); 61 void record(RenderBlock*);
64 void destroy(RenderBlock*); 62 void destroy(RenderBlock*);
63
64 void beginLayout(RenderBlock*);
65 void inflate(RenderBlock*); 65 void inflate(RenderBlock*);
66 void endLayout(RenderBlock*);
66 67
67 private: 68 private:
68 // FIXME(crbug.com/327811): make a proper API for this class.
69 struct Cluster { 69 struct Cluster {
70 explicit Cluster(AtomicString fingerprint) 70 explicit Cluster(RenderBlock* root, float multiplier)
71 : m_fingerprint(fingerprint) 71 : m_root(root)
72 , m_multiplier(0) 72 , m_multiplier(multiplier)
73 { 73 {
74 } 74 }
75 RenderBlock* m_root;
76 float m_multiplier;
77 };
75 78
76 AtomicString m_fingerprint; 79 // Fingerprints are computed during style recalc, for (some subset of)
77 WTF::HashSet<RenderBlock*> m_blocks; 80 // blocks that will become cluster roots.
78 float m_multiplier; 81 class FingerprintMapper {
79 const RenderObject* m_clusterRoot; 82 public:
83 void add(RenderBlock*, AtomicString);
84 void remove(RenderBlock*);
85 AtomicString get(RenderBlock*);
86 WTF::HashSet<RenderBlock*>& getBlocks(AtomicString);
87 private:
88 typedef WTF::HashSet<RenderBlock*> BlockSet;
89 typedef WTF::HashMap<RenderBlock*, AtomicString> FingerprintMap;
90 typedef WTF::HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprint Map;
80 91
81 void addBlock(RenderBlock* block) 92 FingerprintMap m_fingerprints;
82 { 93 ReverseFingerprintMap m_blocksForFingerprint;
83 m_blocks.add(block);
84 setNeedsClusterRecalc();
85 }
86
87 void setNeedsClusterRecalc() { m_multiplier = 0; m_clusterRoot = 0; }
88 bool needsClusterRecalc() const { return !m_clusterRoot || m_multiplier <= 0; }
89 }; 94 };
90 95
91 explicit FastTextAutosizer(Document*); 96 explicit FastTextAutosizer(Document*);
92 97
93 bool updateWindowWidth(); 98 bool enabled();
99 void prepareWindowInfo(RenderView*);
100 bool shouldBeClusterRoot(RenderBlock*);
101 bool clusterWantsAutosizing(RenderBlock*);
102 AtomicString computeFingerprint(RenderBlock*);
103 Cluster* getOrCreateCluster(RenderBlock*);
104 Cluster* createCluster(RenderBlock*);
105 Cluster* addSupercluster(WTF::HashSet<RenderBlock*>&, RenderBlock*);
106 RenderBlock* deepestCommonAncestor(WTF::HashSet<RenderBlock*>&);
107 float computeMultiplier(RenderBlock*);
108 void applyMultiplier(RenderObject*, float);
94 109
95 AtomicString fingerprint(const RenderBlock*); 110 typedef WTF::HashMap<RenderBlock*, OwnPtr<Cluster> > ClusterMap;
96 void recalcClusterIfNeeded(Cluster*); 111 typedef WTF::Vector<Cluster*> ClusterStack;
97
98 int m_windowWidth;
99 112
100 Document* m_document; 113 Document* m_document;
114 int m_windowWidth; // Frame width in density-independent pixels (DIPs).
115 int m_layoutWidth; // Layout width in CSS pixels.
101 116
102 typedef WTF::HashMap<const RenderBlock*, Cluster*> BlockToClusterMap; 117 // Clusters are created and destroyed during layout. The map key is the
103 typedef WTF::HashMap<AtomicString, OwnPtr<Cluster> > FingerprintToClusterMap ; 118 // cluster root. Clusters whose roots share the same fingerprint use the
104 BlockToClusterMap m_clusterForBlock; 119 // same multiplier.
105 FingerprintToClusterMap m_clusterForFingerprint; 120 ClusterMap m_clusters;
121 ClusterStack m_clusterStack;
122 FingerprintMapper m_fingerprintMapper;
106 }; 123 };
107 124
108 } // namespace WebCore 125 } // namespace WebCore
109 126
110 #endif // FastTextAutosizer_h 127 #endif // FastTextAutosizer_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698