OLD | NEW |
---|---|
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 Loading... | |
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 | 75 RenderBlock* m_root; |
76 AtomicString m_fingerprint; | |
77 WTF::HashSet<RenderBlock*> m_blocks; | |
78 float m_multiplier; | 76 float m_multiplier; |
79 const RenderObject* m_clusterRoot; | |
80 | |
81 void addBlock(RenderBlock* block) | |
82 { | |
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 }; | 77 }; |
90 | 78 |
91 explicit FastTextAutosizer(Document*); | 79 explicit FastTextAutosizer(Document*); |
92 | 80 |
93 bool updateWindowWidth(); | 81 bool enabled(); |
82 void prepareWindowInfo(RenderView*); | |
83 bool shouldBeClusterRoot(RenderBlock*); | |
84 bool clusterWantsAutosizing(RenderBlock*); | |
85 AtomicString computeFingerprint(RenderBlock*); | |
86 Cluster* getCluster(RenderBlock*); | |
87 Cluster* createCluster(RenderBlock*); | |
88 Cluster* addSupercluster(WTF::HashSet<RenderBlock*>&, RenderBlock*); | |
pdr.
2013/12/21 01:46:57
Nit: addSuperCluster (camel case)
skobes
2014/01/07 03:12:37
I'm not a fan of this capitalization unless it som
| |
89 RenderBlock* deepestCommonAncestor(WTF::HashSet<RenderBlock*>&); | |
90 float computeMultiplier(RenderBlock*); | |
91 void applyMultiplier(RenderObject*, float); | |
94 | 92 |
95 AtomicString fingerprint(const RenderBlock*); | 93 typedef WTF::HashSet<RenderBlock*> BlockSet; |
96 void recalcClusterIfNeeded(Cluster*); | 94 typedef WTF::HashMap<RenderBlock*, AtomicString> FingerprintMap; |
97 | 95 typedef WTF::HashMap<AtomicString, OwnPtr<BlockSet> > ReverseFingerprintMap; |
98 int m_windowWidth; | 96 typedef WTF::HashMap<RenderBlock*, OwnPtr<Cluster> > ClusterMap; |
97 typedef WTF::Vector<Cluster*> ClusterStack; | |
99 | 98 |
100 Document* m_document; | 99 Document* m_document; |
100 int m_windowWidth; // Frame width in density-independent pixels (DIPs). | |
101 int m_layoutWidth; // Layout width in CSS pixels. | |
101 | 102 |
102 typedef WTF::HashMap<const RenderBlock*, Cluster*> BlockToClusterMap; | 103 // Fingerprints are computed during style recalc, for (some subset of) |
103 typedef WTF::HashMap<AtomicString, OwnPtr<Cluster> > FingerprintToClusterMap ; | 104 // blocks that will become cluster roots. |
104 BlockToClusterMap m_clusterForBlock; | 105 FingerprintMap m_fingerprints; |
105 FingerprintToClusterMap m_clusterForFingerprint; | 106 ReverseFingerprintMap m_blocksForFingerprint; |
107 | |
108 // Clusters are created and destroyed during layout. The map key is the | |
109 // cluster root. Clusters whose roots share the same fingerprint use the | |
110 // same multiplier. | |
111 ClusterMap m_clusters; | |
pdr.
2013/12/21 01:46:57
Is this needed?
skobes
2014/01/07 03:12:37
Yes, this actually owns the Cluster objects.
| |
112 ClusterStack m_clusterStack; | |
106 }; | 113 }; |
107 | 114 |
108 } // namespace WebCore | 115 } // namespace WebCore |
109 | 116 |
110 #endif // FastTextAutosizer_h | 117 #endif // FastTextAutosizer_h |
OLD | NEW |