Chromium Code Reviews| 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 29 matching lines...) Expand all Loading... | |
| 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 Loading... | |
| 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 an additional multiplier based on device and accessibility settin gs. | |
| 138 m_additionalMultiplier = m_document->settings()->accessibilityFontScaleFacto r(); | |
| 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_additionalMultiplier *= m_document->settings()->deviceScaleAdjustment( ); | |
| 143 | |
| 144 #ifndef NDEBUG | |
| 145 m_renderViewInfoPrepared = true; | |
| 146 #endif | |
| 133 } | 147 } |
| 134 | 148 |
| 135 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block) | 149 bool FastTextAutosizer::shouldBeClusterRoot(RenderBlock* block) |
| 136 { | 150 { |
| 137 // FIXME: move the logic out of TextAutosizer.cpp into this class. | 151 // FIXME: move the logic out of TextAutosizer.cpp into this class. |
| 138 return block->isRenderView() | 152 return block->isRenderView() |
| 139 || (TextAutosizer::isAutosizingContainer(block) | 153 || (TextAutosizer::isAutosizingContainer(block) |
| 140 && TextAutosizer::isIndependentDescendant(block)); | 154 && TextAutosizer::isIndependentDescendant(block)); |
| 141 } | 155 } |
| 142 | 156 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 206 if (ancestors.count(block) == blocks.size()) | 220 if (ancestors.count(block) == blocks.size()) |
| 207 return block; | 221 return block; |
| 208 } | 222 } |
| 209 } | 223 } |
| 210 ASSERT_NOT_REACHED(); | 224 ASSERT_NOT_REACHED(); |
| 211 return 0; | 225 return 0; |
| 212 } | 226 } |
| 213 | 227 |
| 214 float FastTextAutosizer::computeMultiplier(RenderBlock* block) | 228 float FastTextAutosizer::computeMultiplier(RenderBlock* block) |
| 215 { | 229 { |
| 230 #ifndef NDEBUG | |
| 231 ASSERT(m_renderViewInfoPrepared); | |
| 232 #endif | |
| 233 | |
| 216 // Block width, in CSS pixels. | 234 // Block width, in CSS pixels. |
| 217 float blockWidth = block->contentLogicalWidth(); | 235 float blockWidth = block->contentLogicalWidth(); |
| 218 | 236 |
| 219 // FIXME(crbug.com/333124): incorporate font scale factor. | 237 float multiplier = min(blockWidth, (float) m_layoutWidth) / m_windowWidth; |
|
skobes
2014/01/13 19:10:13
I should have used static_cast<float> here, do you
pdr.
2014/01/13 19:49:12
Done.
| |
| 220 // FIXME(crbug.com/333124): incorporate device scale adjustment. | 238 return max(m_additionalMultiplier * multiplier, 1.0f); |
| 221 return max(min(blockWidth, (float) m_layoutWidth) / m_windowWidth, 1.0f); | |
| 222 } | 239 } |
| 223 | 240 |
| 224 void FastTextAutosizer::applyMultiplier(RenderObject* renderer, float multiplier ) | 241 void FastTextAutosizer::applyMultiplier(RenderObject* renderer, float multiplier ) |
| 225 { | 242 { |
| 226 RenderStyle* currentStyle = renderer->style(); | 243 RenderStyle* currentStyle = renderer->style(); |
| 227 if (currentStyle->textAutosizingMultiplier() == multiplier) | 244 if (currentStyle->textAutosizingMultiplier() == multiplier) |
| 228 return; | 245 return; |
| 229 | 246 |
| 230 // We need to clone the render style to avoid breaking style sharing. | 247 // We need to clone the render style to avoid breaking style sharing. |
| 231 RefPtr<RenderStyle> style = RenderStyle::clone(currentStyle); | 248 RefPtr<RenderStyle> style = RenderStyle::clone(currentStyle); |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 261 { | 278 { |
| 262 return m_fingerprints.get(block); | 279 return m_fingerprints.get(block); |
| 263 } | 280 } |
| 264 | 281 |
| 265 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint) | 282 FastTextAutosizer::BlockSet& FastTextAutosizer::FingerprintMapper::getBlocks(Ato micString fingerprint) |
| 266 { | 283 { |
| 267 return *m_blocksForFingerprint.get(fingerprint); | 284 return *m_blocksForFingerprint.get(fingerprint); |
| 268 } | 285 } |
| 269 | 286 |
| 270 } // namespace WebCore | 287 } // namespace WebCore |
| OLD | NEW |