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 12 matching lines...) Expand all Loading... |
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "core/layout/TextAutosizer.h" | 31 #include "core/layout/TextAutosizer.h" |
32 | 32 |
| 33 #include <memory> |
33 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
34 #include "core/frame/FrameHost.h" | 35 #include "core/frame/FrameHost.h" |
35 #include "core/frame/FrameView.h" | 36 #include "core/frame/FrameView.h" |
36 #include "core/frame/LocalFrame.h" | 37 #include "core/frame/LocalFrame.h" |
37 #include "core/frame/Settings.h" | 38 #include "core/frame/Settings.h" |
38 #include "core/frame/VisualViewport.h" | 39 #include "core/frame/VisualViewport.h" |
39 #include "core/html/HTMLTextAreaElement.h" | 40 #include "core/html/HTMLTextAreaElement.h" |
40 #include "core/layout/LayoutBlock.h" | 41 #include "core/layout/LayoutBlock.h" |
41 #include "core/layout/LayoutInline.h" | 42 #include "core/layout/LayoutInline.h" |
42 #include "core/layout/LayoutListItem.h" | 43 #include "core/layout/LayoutListItem.h" |
43 #include "core/layout/LayoutListMarker.h" | 44 #include "core/layout/LayoutListMarker.h" |
| 45 #include "core/layout/LayoutRubyRun.h" |
44 #include "core/layout/LayoutTable.h" | 46 #include "core/layout/LayoutTable.h" |
45 #include "core/layout/LayoutTableCell.h" | 47 #include "core/layout/LayoutTableCell.h" |
46 #include "core/layout/LayoutView.h" | 48 #include "core/layout/LayoutView.h" |
47 #include "core/layout/api/LayoutAPIShim.h" | 49 #include "core/layout/api/LayoutAPIShim.h" |
48 #include "core/layout/api/LayoutViewItem.h" | 50 #include "core/layout/api/LayoutViewItem.h" |
49 #include "core/page/Page.h" | 51 #include "core/page/Page.h" |
50 #include "wtf/PtrUtil.h" | 52 #include "wtf/PtrUtil.h" |
51 #include <memory> | |
52 | 53 |
53 #ifdef AUTOSIZING_DOM_DEBUG_INFO | 54 #ifdef AUTOSIZING_DOM_DEBUG_INFO |
54 #include "core/dom/ExecutionContextTask.h" | 55 #include "core/dom/ExecutionContextTask.h" |
55 #endif | 56 #endif |
56 | 57 |
57 namespace blink { | 58 namespace blink { |
58 | 59 |
59 #ifdef AUTOSIZING_DOM_DEBUG_INFO | 60 #ifdef AUTOSIZING_DOM_DEBUG_INFO |
60 class WriteDebugInfoTask : public ExecutionContextTask { | 61 class WriteDebugInfoTask : public ExecutionContextTask { |
61 public: | 62 public: |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
393 } | 394 } |
394 } | 395 } |
395 | 396 |
396 void TextAutosizer::beginLayout(LayoutBlock* block, | 397 void TextAutosizer::beginLayout(LayoutBlock* block, |
397 SubtreeLayoutScope* layouter) { | 398 SubtreeLayoutScope* layouter) { |
398 ASSERT(shouldHandleLayout()); | 399 ASSERT(shouldHandleLayout()); |
399 | 400 |
400 if (prepareForLayout(block) == StopLayout) | 401 if (prepareForLayout(block) == StopLayout) |
401 return; | 402 return; |
402 | 403 |
| 404 // Skip ruby's inner blocks, because these blocks already are inflated. |
| 405 if (block->isRubyRun() || block->isRubyBase() || block->isRubyText()) |
| 406 return; |
| 407 |
403 ASSERT(!m_clusterStack.isEmpty() || block->isLayoutView()); | 408 ASSERT(!m_clusterStack.isEmpty() || block->isLayoutView()); |
404 | 409 |
405 if (Cluster* cluster = maybeCreateCluster(block)) | 410 if (Cluster* cluster = maybeCreateCluster(block)) |
406 m_clusterStack.push_back(WTF::wrapUnique(cluster)); | 411 m_clusterStack.push_back(WTF::wrapUnique(cluster)); |
407 | 412 |
408 ASSERT(!m_clusterStack.isEmpty()); | 413 ASSERT(!m_clusterStack.isEmpty()); |
409 | 414 |
410 // Cells in auto-layout tables are handled separately by inflateAutoTable. | 415 // Cells in auto-layout tables are handled separately by inflateAutoTable. |
411 bool isAutoTableCell = | 416 bool isAutoTableCell = |
412 block->isTableCell() && | 417 block->isTableCell() && |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 } | 468 } |
464 | 469 |
465 float TextAutosizer::inflate(LayoutObject* parent, | 470 float TextAutosizer::inflate(LayoutObject* parent, |
466 SubtreeLayoutScope* layouter, | 471 SubtreeLayoutScope* layouter, |
467 InflateBehavior behavior, | 472 InflateBehavior behavior, |
468 float multiplier) { | 473 float multiplier) { |
469 Cluster* cluster = currentCluster(); | 474 Cluster* cluster = currentCluster(); |
470 bool hasTextChild = false; | 475 bool hasTextChild = false; |
471 | 476 |
472 LayoutObject* child = nullptr; | 477 LayoutObject* child = nullptr; |
473 if (parent->isLayoutBlock() && | 478 if (parent->isRuby()) { |
474 (parent->childrenInline() || behavior == DescendToInnerBlocks)) | 479 // Skip layoutRubyRun which is inline-block. |
| 480 // Inflate rubyRun's inner blocks. |
| 481 LayoutObject* run = parent->slowFirstChild(); |
| 482 if (run && run->isRubyRun()) { |
| 483 child = toLayoutRubyRun(run)->firstChild(); |
| 484 behavior = DescendToInnerBlocks; |
| 485 } |
| 486 } else if (parent->isLayoutBlock() && |
| 487 (parent->childrenInline() || behavior == DescendToInnerBlocks)) { |
475 child = toLayoutBlock(parent)->firstChild(); | 488 child = toLayoutBlock(parent)->firstChild(); |
476 else if (parent->isLayoutInline()) | 489 } else if (parent->isLayoutInline()) { |
477 child = toLayoutInline(parent)->firstChild(); | 490 child = toLayoutInline(parent)->firstChild(); |
| 491 } |
478 | 492 |
479 while (child) { | 493 while (child) { |
480 if (child->isText()) { | 494 if (child->isText()) { |
481 hasTextChild = true; | 495 hasTextChild = true; |
482 // We only calculate this multiplier on-demand to ensure the parent block | 496 // We only calculate this multiplier on-demand to ensure the parent block |
483 // of this text has entered layout. | 497 // of this text has entered layout. |
484 if (!multiplier) | 498 if (!multiplier) |
485 multiplier = | 499 multiplier = |
486 cluster->m_flags & SUPPRESSING ? 1.0f : clusterMultiplier(cluster); | 500 cluster->m_flags & SUPPRESSING ? 1.0f : clusterMultiplier(cluster); |
487 applyMultiplier(child, multiplier, layouter); | 501 applyMultiplier(child, multiplier, layouter); |
488 | 502 |
489 // FIXME: Investigate why MarkOnlyThis is sufficient. | 503 if (behavior == DescendToInnerBlocks) { |
490 if (parent->isLayoutInline()) | 504 // The ancestor nodes might be inline-blocks. We should |
| 505 // setPreferredLogicalWidthsDirty for ancestor nodes here. |
| 506 child->setPreferredLogicalWidthsDirty(); |
| 507 } else if (parent->isLayoutInline()) { |
| 508 // FIXME: Investigate why MarkOnlyThis is sufficient. |
491 child->setPreferredLogicalWidthsDirty(MarkOnlyThis); | 509 child->setPreferredLogicalWidthsDirty(MarkOnlyThis); |
| 510 } |
492 } else if (child->isLayoutInline()) { | 511 } else if (child->isLayoutInline()) { |
493 multiplier = inflate(child, layouter, behavior, multiplier); | 512 multiplier = inflate(child, layouter, behavior, multiplier); |
494 } else if (child->isLayoutBlock() && behavior == DescendToInnerBlocks && | 513 } else if (child->isLayoutBlock() && behavior == DescendToInnerBlocks && |
495 !classifyBlock(child, | 514 !classifyBlock(child, |
496 INDEPENDENT | EXPLICIT_WIDTH | SUPPRESSING)) { | 515 INDEPENDENT | EXPLICIT_WIDTH | SUPPRESSING)) { |
497 multiplier = inflate(child, layouter, behavior, multiplier); | 516 multiplier = inflate(child, layouter, behavior, multiplier); |
498 } | 517 } |
499 child = child->nextSibling(); | 518 child = child->nextSibling(); |
500 } | 519 } |
501 | 520 |
(...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1166 style->setUnique(); | 1185 style->setUnique(); |
1167 | 1186 |
1168 switch (relayoutBehavior) { | 1187 switch (relayoutBehavior) { |
1169 case AlreadyInLayout: | 1188 case AlreadyInLayout: |
1170 // Don't free currentStyle until the end of the layout pass. This allows | 1189 // Don't free currentStyle until the end of the layout pass. This allows |
1171 // other parts of the system to safely hold raw ComputedStyle* pointers | 1190 // other parts of the system to safely hold raw ComputedStyle* pointers |
1172 // during layout, e.g. BreakingContext::m_currentStyle. | 1191 // during layout, e.g. BreakingContext::m_currentStyle. |
1173 m_stylesRetainedDuringLayout.push_back(¤tStyle); | 1192 m_stylesRetainedDuringLayout.push_back(¤tStyle); |
1174 | 1193 |
1175 layoutObject->setStyleInternal(std::move(style)); | 1194 layoutObject->setStyleInternal(std::move(style)); |
| 1195 if (layoutObject->isText()) |
| 1196 toLayoutText(layoutObject)->autosizingMultiplerChanged(); |
1176 DCHECK(!layouter || layoutObject->isDescendantOf(&layouter->root())); | 1197 DCHECK(!layouter || layoutObject->isDescendantOf(&layouter->root())); |
1177 layoutObject->setNeedsLayoutAndFullPaintInvalidation( | 1198 layoutObject->setNeedsLayoutAndFullPaintInvalidation( |
1178 LayoutInvalidationReason::TextAutosizing, MarkContainerChain, | 1199 LayoutInvalidationReason::TextAutosizing, MarkContainerChain, |
1179 layouter); | 1200 layouter); |
1180 break; | 1201 break; |
1181 | 1202 |
1182 case LayoutNeeded: | 1203 case LayoutNeeded: |
1183 DCHECK(!layouter); | 1204 DCHECK(!layouter); |
1184 layoutObject->setStyle(std::move(style)); | 1205 layoutObject->setStyle(std::move(style)); |
1185 break; | 1206 break; |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 } | 1452 } |
1432 } | 1453 } |
1433 potentiallyInconsistentSuperclusters.clear(); | 1454 potentiallyInconsistentSuperclusters.clear(); |
1434 } | 1455 } |
1435 | 1456 |
1436 DEFINE_TRACE(TextAutosizer) { | 1457 DEFINE_TRACE(TextAutosizer) { |
1437 visitor->trace(m_document); | 1458 visitor->trace(m_document); |
1438 } | 1459 } |
1439 | 1460 |
1440 } // namespace blink | 1461 } // namespace blink |
OLD | NEW |