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

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

Issue 135733002: [FastTextAutosizer] Incorporate accessibility and device scale factors (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update after reviewer 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 29 matching lines...) Expand all
40 #include "core/rendering/RenderBlock.h" 40 #include "core/rendering/RenderBlock.h"
41 #include "core/rendering/RenderView.h" 41 #include "core/rendering/RenderView.h"
42 #include "core/rendering/TextAutosizer.h" 42 #include "core/rendering/TextAutosizer.h"
43 43
44 using namespace std; 44 using namespace std;
45 45
46 namespace WebCore { 46 namespace WebCore {
47 47
48 FastTextAutosizer::FastTextAutosizer(Document* document) 48 FastTextAutosizer::FastTextAutosizer(Document* document)
49 : m_document(document) 49 : m_document(document)
50 #ifndef NDEBUG
51 , m_renderViewInfoPrepared(false)
52 #endif
50 { 53 {
51 } 54 }
52 55
53 void FastTextAutosizer::record(RenderBlock* block) 56 void FastTextAutosizer::record(RenderBlock* block)
54 { 57 {
55 if (!enabled()) 58 if (!enabled())
56 return; 59 return;
57 60
58 if (!shouldBeClusterRoot(block)) 61 if (!shouldBeClusterRoot(block))
59 return; 62 return;
60 63
61 AtomicString fingerprint = computeFingerprint(block); 64 AtomicString fingerprint = computeFingerprint(block);
62 if (fingerprint.isNull()) 65 if (fingerprint.isNull())
63 return; 66 return;
64 67
65 m_fingerprintMapper.add(block, fingerprint); 68 m_fingerprintMapper.add(block, fingerprint);
66 } 69 }
67 70
68 void FastTextAutosizer::destroy(RenderBlock* block) 71 void FastTextAutosizer::destroy(RenderBlock* block)
69 { 72 {
70 m_fingerprintMapper.remove(block); 73 m_fingerprintMapper.remove(block);
71 } 74 }
72 75
73 void FastTextAutosizer::beginLayout(RenderBlock* block) 76 void FastTextAutosizer::beginLayout(RenderBlock* block)
74 { 77 {
75 if (!enabled()) 78 if (!enabled())
76 return; 79 return;
77 80
78 if (block->isRenderView()) 81 if (block->isRenderView())
79 prepareWindowInfo(toRenderView(block)); 82 prepareRenderViewInfo(toRenderView(block));
80 83
81 if (shouldBeClusterRoot(block)) 84 if (shouldBeClusterRoot(block))
82 m_clusterStack.append(getOrCreateCluster(block)); 85 m_clusterStack.append(getOrCreateCluster(block));
83 } 86 }
84 87
85 void FastTextAutosizer::inflate(RenderBlock* block) 88 void FastTextAutosizer::inflate(RenderBlock* block)
86 { 89 {
87 if (m_clusterStack.isEmpty()) 90 if (m_clusterStack.isEmpty())
88 return; 91 return;
89 Cluster* cluster = m_clusterStack.last(); 92 Cluster* cluster = m_clusterStack.last();
(...skipping 21 matching lines...) Expand all
111 } 114 }
112 115
113 bool FastTextAutosizer::enabled() 116 bool FastTextAutosizer::enabled()
114 { 117 {
115 return m_document->settings() 118 return m_document->settings()
116 && m_document->settings()->textAutosizingEnabled() 119 && m_document->settings()->textAutosizingEnabled()
117 && !m_document->printing() 120 && !m_document->printing()
118 && m_document->page(); 121 && m_document->page();
119 } 122 }
120 123
121 void FastTextAutosizer::prepareWindowInfo(RenderView* renderView) 124 void FastTextAutosizer::prepareRenderViewInfo(RenderView* renderView)
122 { 125 {
123 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr itingMode()); 126 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr itingMode());
124 127
125 Frame* mainFrame = m_document->page()->mainFrame(); 128 Frame* mainFrame = m_document->page()->mainFrame();
126 IntSize windowSize = m_document->settings()->textAutosizingWindowSizeOverrid e(); 129 IntSize windowSize = m_document->settings()->textAutosizingWindowSizeOverrid e();
127 if (windowSize.isEmpty()) 130 if (windowSize.isEmpty())
128 windowSize = mainFrame->view()->unscaledVisibleContentSize(ScrollableAre a::IncludeScrollbars); 131 windowSize = mainFrame->view()->unscaledVisibleContentSize(ScrollableAre a::IncludeScrollbars);
129 m_windowWidth = horizontalWritingMode ? windowSize.width() : windowSize.heig ht(); 132 m_windowWidth = horizontalWritingMode ? windowSize.width() : windowSize.heig ht();
130 133
131 IntSize layoutSize = m_document->page()->mainFrame()->view()->layoutSize(); 134 IntSize layoutSize = m_document->page()->mainFrame()->view()->layoutSize();
132 m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.heig ht(); 135 m_layoutWidth = horizontalWritingMode ? layoutSize.width() : layoutSize.heig ht();
136
137 // Compute the base font scale multiplier based on device and accessibility settings.
138 m_baseMultiplier = m_document->settings()->accessibilityFontScaleFactor();
139 // If the page has a meta viewport or @viewport, don't apply the device scal e adjustment.
140 const ViewportDescription& viewportDescription = m_document->page()->mainFra me()->document()->viewportDescription();
141 if (!viewportDescription.isSpecifiedByAuthor())
142 m_baseMultiplier *= m_document->settings()->deviceScaleAdjustment();
143 #ifndef NDEBUG
144 m_renderViewInfoPrepared = true;
145 #endif
133 } 146 }
134 147
135 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block) 148 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block)
136 { 149 {
137 // FIXME: move the logic out of TextAutosizer.cpp into this class. 150 // FIXME: move the logic out of TextAutosizer.cpp into this class.
138 return block->isRenderView() 151 return block->isRenderView()
139 || (TextAutosizer::isAutosizingContainer(block) 152 || (TextAutosizer::isAutosizingContainer(block)
140 && TextAutosizer::isIndependentDescendant(block)); 153 && TextAutosizer::isIndependentDescendant(block));
141 } 154 }
142 155
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (ancestors.count(block) == blocks.size()) 219 if (ancestors.count(block) == blocks.size())
207 return block; 220 return block;
208 } 221 }
209 } 222 }
210 ASSERT_NOT_REACHED(); 223 ASSERT_NOT_REACHED();
211 return 0; 224 return 0;
212 } 225 }
213 226
214 float FastTextAutosizer::computeMultiplier(RenderBlock* block) 227 float FastTextAutosizer::computeMultiplier(RenderBlock* block)
215 { 228 {
229 #ifndef NDEBUG
230 ASSERT(m_renderViewInfoPrepared);
231 #endif
216 // Block width, in CSS pixels. 232 // Block width, in CSS pixels.
217 float blockWidth = block->contentLogicalWidth(); 233 float blockWidth = block->contentLogicalWidth();
218 234
219 // FIXME(crbug.com/333124): incorporate font scale factor. 235 float multiplier = min(blockWidth, static_cast<float>(m_layoutWidth)) / m_wi ndowWidth;
220 // FIXME(crbug.com/333124): incorporate device scale adjustment. 236 return max(m_baseMultiplier * multiplier, 1.0f);
221 return max(min(blockWidth, (float) m_layoutWidth) / m_windowWidth, 1.0f);
222 } 237 }
223 238
224 void FastTextAutosizer::applyMultiplier(RenderObject* renderer, float multiplier ) 239 void FastTextAutosizer::applyMultiplier(RenderObject* renderer, float multiplier )
225 { 240 {
226 RenderStyle* currentStyle = renderer->style(); 241 RenderStyle* currentStyle = renderer->style();
227 if (currentStyle->textAutosizingMultiplier() == multiplier) 242 if (currentStyle->textAutosizingMultiplier() == multiplier)
228 return; 243 return;
229 244
230 // We need to clone the render style to avoid breaking style sharing. 245 // We need to clone the render style to avoid breaking style sharing.
231 RefPtr<RenderStyle> style = RenderStyle::clone(currentStyle); 246 RefPtr<RenderStyle> style = RenderStyle::clone(currentStyle);
(...skipping 29 matching lines...) Expand all
261 { 276 {
262 return m_fingerprints.get(block); 277 return m_fingerprints.get(block);
263 } 278 }
264 279
265 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint) 280 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint)
266 { 281 {
267 return *m_blocksForFingerprint.get(fingerprint); 282 return *m_blocksForFingerprint.get(fingerprint);
268 } 283 }
269 284
270 } // namespace WebCore 285 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/FastTextAutosizer.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698