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 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
284 #ifndef NDEBUG | 284 #ifndef NDEBUG |
285 m_blocksThatHaveBegunLayout.add(block); | 285 m_blocksThatHaveBegunLayout.add(block); |
286 #endif | 286 #endif |
287 if (Cluster* cluster = maybeCreateCluster(block)) | 287 if (Cluster* cluster = maybeCreateCluster(block)) |
288 m_clusterStack.append(adoptPtr(cluster)); | 288 m_clusterStack.append(adoptPtr(cluster)); |
289 } | 289 } |
290 } | 290 } |
291 | 291 |
292 void FastTextAutosizer::beginLayout(RenderBlock* block) | 292 void FastTextAutosizer::beginLayout(RenderBlock* block) |
293 { | 293 { |
294 ASSERT(enabled() && m_pageNeedsAutosizing && !m_updatePageInfoDeferred); | 294 ASSERT(enabled() && shouldHandleLayout()); |
295 #ifndef NDEBUG | 295 #ifndef NDEBUG |
296 m_blocksThatHaveBegunLayout.add(block); | 296 m_blocksThatHaveBegunLayout.add(block); |
297 #endif | 297 #endif |
298 | 298 |
299 if (!m_firstBlock) { | 299 if (!m_firstBlock) { |
300 m_firstBlock = block; | 300 m_firstBlock = block; |
301 prepareClusterStack(block->parent()); | 301 prepareClusterStack(block->parent()); |
302 } else if (block == currentCluster()->m_root) { | 302 } else if (block == currentCluster()->m_root) { |
303 // Ignore beginLayout on the same block twice. | 303 // Ignore beginLayout on the same block twice. |
304 // This can happen with paginated overflow. | 304 // This can happen with paginated overflow. |
305 return; | 305 return; |
306 } | 306 } |
307 | 307 |
308 if (Cluster* cluster = maybeCreateCluster(block)) { | 308 if (Cluster* cluster = maybeCreateCluster(block)) { |
309 m_clusterStack.append(adoptPtr(cluster)); | 309 m_clusterStack.append(adoptPtr(cluster)); |
310 if (block->isTable()) | 310 if (block->isTable()) |
311 inflateTable(toRenderTable(block)); | 311 inflateTable(toRenderTable(block)); |
312 } | 312 } |
313 | 313 |
314 if (block->childrenInline() && block->firstChild()) | 314 if (block->childrenInline() && block->firstChild()) |
315 inflate(block); | 315 inflate(block); |
316 } | 316 } |
317 | 317 |
318 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark
er* listItemMarker) | 318 void FastTextAutosizer::inflateListItem(RenderListItem* listItem, RenderListMark
er* listItemMarker) |
319 { | 319 { |
320 if (!enabled() || !m_pageNeedsAutosizing) | 320 if (!enabled() || !shouldHandleLayout()) |
321 return; | 321 return; |
322 ASSERT(listItem && listItemMarker); | 322 ASSERT(listItem && listItemMarker); |
323 #ifndef NDEBUG | 323 #ifndef NDEBUG |
324 m_blocksThatHaveBegunLayout.add(listItem); | 324 m_blocksThatHaveBegunLayout.add(listItem); |
325 #endif | 325 #endif |
326 // Force the LI to be inside the DBCAT when computing the multiplier. | 326 // Force the LI to be inside the DBCAT when computing the multiplier. |
327 // This guarantees that the DBCAT has entered layout, so we can ask for its
width. | 327 // This guarantees that the DBCAT has entered layout, so we can ask for its
width. |
328 // It also makes sense because the list marker is autosized like a text node
. | 328 // It also makes sense because the list marker is autosized like a text node
. |
329 float multiplier = clusterMultiplier(currentCluster()); | 329 float multiplier = clusterMultiplier(currentCluster()); |
330 | 330 |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 } | 373 } |
374 } | 374 } |
375 } | 375 } |
376 } | 376 } |
377 } | 377 } |
378 } | 378 } |
379 } | 379 } |
380 | 380 |
381 void FastTextAutosizer::endLayout(RenderBlock* block) | 381 void FastTextAutosizer::endLayout(RenderBlock* block) |
382 { | 382 { |
383 ASSERT(enabled() && m_pageNeedsAutosizing); | 383 ASSERT(enabled() && shouldHandleLayout()); |
384 | 384 |
385 if (block == m_firstBlock) { | 385 if (block == m_firstBlock) { |
386 m_firstBlock = 0; | 386 m_firstBlock = 0; |
387 m_clusterStack.clear(); | 387 m_clusterStack.clear(); |
388 m_superclusters.clear(); | 388 m_superclusters.clear(); |
389 #ifndef NDEBUG | 389 #ifndef NDEBUG |
390 m_blocksThatHaveBegunLayout.clear(); | 390 m_blocksThatHaveBegunLayout.clear(); |
391 #endif | 391 #endif |
392 } else if (currentCluster()->m_root == block) { | 392 } else if (currentCluster()->m_root == block) { |
393 m_clusterStack.removeLast(); | 393 m_clusterStack.removeLast(); |
(...skipping 16 matching lines...) Expand all Loading... |
410 // has entered layout. | 410 // has entered layout. |
411 if (!multiplier) | 411 if (!multiplier) |
412 multiplier = cluster->m_autosize ? clusterMultiplier(cluster) :
1.0f; | 412 multiplier = cluster->m_autosize ? clusterMultiplier(cluster) :
1.0f; |
413 applyMultiplier(descendant, multiplier); | 413 applyMultiplier(descendant, multiplier); |
414 applyMultiplier(descendant->parent(), multiplier); // Parent handles
line spacing. | 414 applyMultiplier(descendant->parent(), multiplier); // Parent handles
line spacing. |
415 } | 415 } |
416 descendant = descendant->nextInPreOrder(block); | 416 descendant = descendant->nextInPreOrder(block); |
417 } | 417 } |
418 } | 418 } |
419 | 419 |
420 bool FastTextAutosizer::enabled() | 420 bool FastTextAutosizer::enabled() const |
421 { | 421 { |
422 if (!m_document->settings() || !m_document->page() || m_document->printing()
) | 422 if (!m_document->settings() || !m_document->page() || m_document->printing()
) |
423 return false; | 423 return false; |
424 | 424 |
425 return m_document->settings()->textAutosizingEnabled(); | 425 return m_document->settings()->textAutosizingEnabled(); |
426 } | 426 } |
427 | 427 |
| 428 bool FastTextAutosizer::shouldHandleLayout() const |
| 429 { |
| 430 return m_pageNeedsAutosizing && !m_updatePageInfoDeferred; |
| 431 } |
| 432 |
428 void FastTextAutosizer::updatePageInfoInAllFrames() | 433 void FastTextAutosizer::updatePageInfoInAllFrames() |
429 { | 434 { |
430 if (!enabled()) | 435 ASSERT(!enabled() || m_document->frame()->isMainFrame()); |
431 return; | |
432 | |
433 ASSERT(m_document->frame()->isMainFrame()); | |
434 | 436 |
435 for (LocalFrame* frame = m_document->frame(); frame; frame = frame->tree().t
raverseNext()) { | 437 for (LocalFrame* frame = m_document->frame(); frame; frame = frame->tree().t
raverseNext()) { |
436 if (FastTextAutosizer* textAutosizer = frame->document()->fastTextAutosi
zer()) | 438 if (FastTextAutosizer* textAutosizer = frame->document()->fastTextAutosi
zer()) |
437 textAutosizer->updatePageInfo(); | 439 textAutosizer->updatePageInfo(); |
438 } | 440 } |
439 } | 441 } |
440 | 442 |
441 void FastTextAutosizer::updatePageInfo() | 443 void FastTextAutosizer::updatePageInfo() |
442 { | 444 { |
443 if (!enabled() || m_updatePageInfoDeferred) | 445 if (!enabled()) { |
| 446 if (m_previouslyAutosized) |
| 447 resetMultipliers(); |
| 448 return; |
| 449 } |
| 450 |
| 451 if (m_updatePageInfoDeferred) |
444 return; | 452 return; |
445 | 453 |
446 int previousFrameWidth = m_frameWidth; | 454 int previousFrameWidth = m_frameWidth; |
447 int previousLayoutWidth = m_layoutWidth; | 455 int previousLayoutWidth = m_layoutWidth; |
448 float previousBaseMultiplier = m_baseMultiplier; | 456 float previousBaseMultiplier = m_baseMultiplier; |
449 | 457 |
450 RenderView* renderView = toRenderView(m_document->renderer()); | 458 RenderView* renderView = toRenderView(m_document->renderer()); |
451 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr
itingMode()); | 459 bool horizontalWritingMode = isHorizontalWritingMode(renderView->style()->wr
itingMode()); |
452 | 460 |
453 LocalFrame* mainFrame = m_document->page()->mainFrame(); | 461 LocalFrame* mainFrame = m_document->page()->mainFrame(); |
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
969 return *m_blocksForFingerprint.get(fingerprint); | 977 return *m_blocksForFingerprint.get(fingerprint); |
970 } | 978 } |
971 | 979 |
972 FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block) | 980 FastTextAutosizer::LayoutScope::LayoutScope(RenderBlock* block) |
973 : m_textAutosizer(block->document().fastTextAutosizer()) | 981 : m_textAutosizer(block->document().fastTextAutosizer()) |
974 , m_block(block) | 982 , m_block(block) |
975 { | 983 { |
976 if (!m_textAutosizer) | 984 if (!m_textAutosizer) |
977 return; | 985 return; |
978 | 986 |
979 if (m_textAutosizer->enabled() && m_textAutosizer->m_pageNeedsAutosizing) | 987 if (m_textAutosizer->enabled() && m_textAutosizer->shouldHandleLayout()) |
980 m_textAutosizer->beginLayout(m_block); | 988 m_textAutosizer->beginLayout(m_block); |
981 else | 989 else |
982 m_textAutosizer = 0; | 990 m_textAutosizer = 0; |
983 } | 991 } |
984 | 992 |
985 FastTextAutosizer::LayoutScope::~LayoutScope() | 993 FastTextAutosizer::LayoutScope::~LayoutScope() |
986 { | 994 { |
987 if (m_textAutosizer) | 995 if (m_textAutosizer) |
988 m_textAutosizer->endLayout(m_block); | 996 m_textAutosizer->endLayout(m_block); |
989 } | 997 } |
(...skipping 10 matching lines...) Expand all Loading... |
1000 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() | 1008 FastTextAutosizer::DeferUpdatePageInfo::~DeferUpdatePageInfo() |
1001 { | 1009 { |
1002 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { | 1010 if (FastTextAutosizer* textAutosizer = m_mainFrame->document()->fastTextAuto
sizer()) { |
1003 ASSERT(textAutosizer->m_updatePageInfoDeferred); | 1011 ASSERT(textAutosizer->m_updatePageInfoDeferred); |
1004 textAutosizer->m_updatePageInfoDeferred = false; | 1012 textAutosizer->m_updatePageInfoDeferred = false; |
1005 textAutosizer->updatePageInfoInAllFrames(); | 1013 textAutosizer->updatePageInfoInAllFrames(); |
1006 } | 1014 } |
1007 } | 1015 } |
1008 | 1016 |
1009 } // namespace WebCore | 1017 } // namespace WebCore |
OLD | NEW |