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

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

Issue 268833003: Refactor avoidsFloats() to reflect CSS2.1 spec more clearly (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Updated Created 6 years, 1 month 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/RenderBlockFlow.h ('k') | Source/core/rendering/RenderBox.h » ('j') | 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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after
892 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 892 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
893 FloatingObjectSetIterator end = floatingObjectSet.end(); 893 FloatingObjectSetIterator end = floatingObjectSet.end();
894 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 894 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
895 FloatingObject* floatingObject = it->get(); 895 FloatingObject* floatingObject = it->get();
896 if (!floatingObject->isDescendant()) 896 if (!floatingObject->isDescendant())
897 oldIntrudingFloatSet.add(floatingObject->renderer()); 897 oldIntrudingFloatSet.add(floatingObject->renderer());
898 } 898 }
899 } 899 }
900 900
901 // Inline blocks are covered by the isReplaced() check in the avoidFloats me thod. 901 // Inline blocks are covered by the isReplaced() check in the avoidFloats me thod.
902 if (avoidsFloats() || isDocumentElement() || isRenderView() || isFloatingOrO utOfFlowPositioned() || isTableCell()) { 902 if (avoidsOrIgnoresFloats() || isRenderView()) {
903 if (m_floatingObjects) { 903 if (m_floatingObjects) {
904 m_floatingObjects->clear(); 904 m_floatingObjects->clear();
905 } 905 }
906 if (!oldIntrudingFloatSet.isEmpty()) 906 if (!oldIntrudingFloatSet.isEmpty())
907 markAllDescendantsWithFloatsForLayout(); 907 markAllDescendantsWithFloatsForLayout();
908 return; 908 return;
909 } 909 }
910 910
911 RendererToFloatInfoMap floatMap; 911 RendererToFloatInfoMap floatMap;
912 912
913 if (m_floatingObjects) { 913 if (m_floatingObjects) {
914 if (childrenInline()) 914 if (childrenInline())
915 m_floatingObjects->moveAllToFloatInfoMap(floatMap); 915 m_floatingObjects->moveAllToFloatInfoMap(floatMap);
916 else 916 else
917 m_floatingObjects->clear(); 917 m_floatingObjects->clear();
918 } 918 }
919 919
920 // We should not process floats if the parent node is not a RenderBlockFlow. Otherwise, we will add 920 // We should not process floats if the parent node is not a RenderBlockFlow. Otherwise, we will add
921 // floats in an invalid context. This will cause a crash arising from a bad cast on the parent. 921 // floats in an invalid context. This will cause a crash arising from a bad cast on the parent.
922 // See <rdar://problem/8049753>, where float property is applied on a text n ode in a SVG. 922 // See <rdar://problem/8049753>, where float property is applied on a text n ode in a SVG.
923 if (!parent() || !parent()->isRenderBlockFlow()) 923 if (!parent() || !parent()->isRenderBlockFlow())
924 return; 924 return;
925 925
926 // Attempt to locate a previous sibling with overhanging floats. We skip any elements that 926 // Attempt to locate a previous sibling with overhanging floats. We skip any elements that
927 // may have shifted to avoid floats, and any objects whose floats cannot int eract with objects 927 // may have shifted to avoid floats, and any objects whose floats cannot int eract with objects
928 // outside it (i.e. objects that create a new block formatting context). 928 // outside it (i.e. objects that create a new block formatting context).
929 RenderBlockFlow* parentBlockFlow = toRenderBlockFlow(parent()); 929 RenderBlockFlow* parentBlockFlow = toRenderBlockFlow(parent());
930 bool parentHasFloats = false; 930 bool parentHasFloats = false;
931 RenderObject* prev = previousSibling(); 931 RenderObject* prev = previousSibling();
932 while (prev && (!prev->isBox() || !prev->isRenderBlock() || toRenderBlock(pr ev)->avoidsFloats() || toRenderBlock(prev)->createsBlockFormattingContext())) { 932 while (prev && (!prev->isBox() || !prev->isRenderBlock() || toRenderBlock(pr ev)->avoidsOrIgnoresFloats())) {
933 if (prev->isFloating()) 933 if (prev->isFloating())
934 parentHasFloats = true; 934 parentHasFloats = true;
935 prev = prev->previousSibling(); 935 prev = prev->previousSibling();
936 } 936 }
937 937
938 // First add in floats from the parent. Self-collapsing blocks let their par ent track any floats that intrude into 938 // First add in floats from the parent. Self-collapsing blocks let their par ent track any floats that intrude into
939 // them (as opposed to floats they contain themselves) so check for those he re too. 939 // them (as opposed to floats they contain themselves) so check for those he re too.
940 LayoutUnit logicalTopOffset = logicalTop(); 940 LayoutUnit logicalTopOffset = logicalTop();
941 bool parentHasIntrudingFloats = !parentHasFloats && (!prev || toRenderBlockF low(prev)->isSelfCollapsingBlock()) && parentBlockFlow->lowestFloatLogicalBottom () > logicalTopOffset; 941 bool parentHasIntrudingFloats = !parentHasFloats && (!prev || toRenderBlockF low(prev)->isSelfCollapsingBlock()) && parentBlockFlow->lowestFloatLogicalBottom () > logicalTopOffset;
942 if (parentHasFloats || parentHasIntrudingFloats) 942 if (parentHasFloats || parentHasIntrudingFloats)
(...skipping 888 matching lines...) Expand 10 before | Expand all | Expand 10 after
1831 1831
1832 void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove) 1832 void RenderBlockFlow::markSiblingsWithFloatsForLayout(RenderBox* floatToRemove)
1833 { 1833 {
1834 if (!m_floatingObjects) 1834 if (!m_floatingObjects)
1835 return; 1835 return;
1836 1836
1837 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1837 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1838 FloatingObjectSetIterator end = floatingObjectSet.end(); 1838 FloatingObjectSetIterator end = floatingObjectSet.end();
1839 1839
1840 for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) { 1840 for (RenderObject* next = nextSibling(); next; next = next->nextSibling()) {
1841 if (!next->isRenderBlockFlow() || next->isFloatingOrOutOfFlowPositioned( ) || toRenderBlockFlow(next)->avoidsFloats()) 1841 if (!next->isRenderBlockFlow() || avoidsOrIgnoresFloats())
1842 continue; 1842 continue;
1843 1843
1844 RenderBlockFlow* nextBlock = toRenderBlockFlow(next); 1844 RenderBlockFlow* nextBlock = toRenderBlockFlow(next);
1845 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) { 1845 for (FloatingObjectSetIterator it = floatingObjectSet.begin(); it != end ; ++it) {
1846 RenderBox* floatingBox = (*it)->renderer(); 1846 RenderBox* floatingBox = (*it)->renderer();
1847 if (floatToRemove && floatingBox != floatToRemove) 1847 if (floatToRemove && floatingBox != floatToRemove)
1848 continue; 1848 continue;
1849 if (nextBlock->containsFloat(floatingBox)) 1849 if (nextBlock->containsFloat(floatingBox))
1850 nextBlock->markAllDescendantsWithFloatsForLayout(floatingBox); 1850 nextBlock->markAllDescendantsWithFloatsForLayout(floatingBox);
1851 } 1851 }
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1910 } 1910 }
1911 1911
1912 void RenderBlockFlow::createFloatingObjects() 1912 void RenderBlockFlow::createFloatingObjects()
1913 { 1913 {
1914 m_floatingObjects = adoptPtr(new FloatingObjects(this, isHorizontalWritingMo de())); 1914 m_floatingObjects = adoptPtr(new FloatingObjects(this, isHorizontalWritingMo de()));
1915 } 1915 }
1916 1916
1917 void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& n ewStyle) 1917 void RenderBlockFlow::styleWillChange(StyleDifference diff, const RenderStyle& n ewStyle)
1918 { 1918 {
1919 RenderStyle* oldStyle = style(); 1919 RenderStyle* oldStyle = style();
1920 s_canPropagateFloatIntoSibling = oldStyle ? !isFloatingOrOutOfFlowPositioned () && !avoidsFloats() : false; 1920 s_canPropagateFloatIntoSibling = oldStyle ? !avoidsOrIgnoresFloats() : false ;
rhogan 2014/11/11 19:17:13 I had !createsBlockFormattingContext() here; which
1921 if (oldStyle && parent() && diff.needsFullLayout() && oldStyle->position() ! = newStyle.position() 1921 if (oldStyle && parent() && diff.needsFullLayout() && oldStyle->position() ! = newStyle.position()
1922 && containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newS tyle.hasOutOfFlowPosition()) 1922 && containsFloats() && !isFloating() && !isOutOfFlowPositioned() && newS tyle.hasOutOfFlowPosition())
1923 markAllDescendantsWithFloatsForLayout(); 1923 markAllDescendantsWithFloatsForLayout();
1924 1924
1925 RenderBlock::styleWillChange(diff, newStyle); 1925 RenderBlock::styleWillChange(diff, newStyle);
1926 } 1926 }
1927 1927
1928 void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* ol dStyle) 1928 void RenderBlockFlow::styleDidChange(StyleDifference diff, const RenderStyle* ol dStyle)
1929 { 1929 {
1930 RenderBlock::styleDidChange(diff, oldStyle); 1930 RenderBlock::styleDidChange(diff, oldStyle);
1931 1931
1932 // After our style changed, if we lose our ability to propagate floats into next sibling 1932 // After our style changed, if we lose our ability to propagate floats into next sibling
1933 // blocks, then we need to find the top most parent containing that overhang ing float and 1933 // blocks, then we need to find the top most parent containing that overhang ing float and
1934 // then mark its descendants with floats for layout and clear all floats fro m its next 1934 // then mark its descendants with floats for layout and clear all floats fro m its next
1935 // sibling blocks that exist in our floating objects list. See bug 56299 and 62875. 1935 // sibling blocks that exist in our floating objects list. See bug 56299 and 62875.
1936 bool canPropagateFloatIntoSibling = !isFloatingOrOutOfFlowPositioned() && !a voidsFloats(); 1936 bool canPropagateFloatIntoSibling = !avoidsOrIgnoresFloats();
1937 if (diff.needsFullLayout() && s_canPropagateFloatIntoSibling && !canPropagat eFloatIntoSibling && hasOverhangingFloats()) { 1937 if (diff.needsFullLayout() && s_canPropagateFloatIntoSibling && !canPropagat eFloatIntoSibling && hasOverhangingFloats()) {
1938 RenderBlockFlow* parentBlockFlow = this; 1938 RenderBlockFlow* parentBlockFlow = this;
1939 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set(); 1939 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1940 FloatingObjectSetIterator end = floatingObjectSet.end(); 1940 FloatingObjectSetIterator end = floatingObjectSet.end();
1941 1941
1942 for (RenderObject* curr = parent(); curr && !curr->isRenderView(); curr = curr->parent()) { 1942 for (RenderObject* curr = parent(); curr && !curr->isRenderView(); curr = curr->parent()) {
1943 if (curr->isRenderBlockFlow()) { 1943 if (curr->isRenderBlockFlow()) {
1944 RenderBlockFlow* currBlock = toRenderBlockFlow(curr); 1944 RenderBlockFlow* currBlock = toRenderBlockFlow(curr);
1945 1945
1946 if (currBlock->hasOverhangingFloats()) { 1946 if (currBlock->hasOverhangingFloats()) {
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
2703 void RenderBlockFlow::setPaginationStrut(LayoutUnit strut) 2703 void RenderBlockFlow::setPaginationStrut(LayoutUnit strut)
2704 { 2704 {
2705 if (!m_rareData) { 2705 if (!m_rareData) {
2706 if (!strut) 2706 if (!strut)
2707 return; 2707 return;
2708 m_rareData = adoptPtrWillBeNoop(new RenderBlockFlowRareData(this)); 2708 m_rareData = adoptPtrWillBeNoop(new RenderBlockFlowRareData(this));
2709 } 2709 }
2710 m_rareData->m_paginationStrut = strut; 2710 m_rareData->m_paginationStrut = strut;
2711 } 2711 }
2712 2712
2713 bool RenderBlockFlow::avoidsFloats() const
2714 {
2715 // Floats can't intrude into our box if we have a non-auto column count or w idth.
2716 // Note: we need to use RenderBox::avoidsFloats here since RenderBlock::avoi dsFloats is always true.
2717 return RenderBox::avoidsFloats() || !style()->hasAutoColumnCount() || !style ()->hasAutoColumnWidth();
2718 }
2719
2720 LayoutUnit RenderBlockFlow::logicalLeftSelectionOffset(const RenderBlock* rootBl ock, LayoutUnit position) const 2713 LayoutUnit RenderBlockFlow::logicalLeftSelectionOffset(const RenderBlock* rootBl ock, LayoutUnit position) const
2721 { 2714 {
2722 LayoutUnit logicalLeft = logicalLeftOffsetForLine(position, false); 2715 LayoutUnit logicalLeft = logicalLeftOffsetForLine(position, false);
2723 if (logicalLeft == logicalLeftOffsetForContent()) 2716 if (logicalLeft == logicalLeftOffsetForContent())
2724 return RenderBlock::logicalLeftSelectionOffset(rootBlock, position); 2717 return RenderBlock::logicalLeftSelectionOffset(rootBlock, position);
2725 2718
2726 const RenderBlock* cb = this; 2719 const RenderBlock* cb = this;
2727 while (cb != rootBlock) { 2720 while (cb != rootBlock) {
2728 logicalLeft += cb->logicalLeft(); 2721 logicalLeft += cb->logicalLeft();
2729 cb = cb->containingBlock(); 2722 cb = cb->containingBlock();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
2844 FrameView* frameView = document().view(); 2837 FrameView* frameView = document().view();
2845 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr ollOffset().height(); 2838 LayoutUnit top = (style()->position() == FixedPosition) ? 0 : frameView->scr ollOffset().height();
2846 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height( ); 2839 int visibleHeight = frameView->visibleContentRect(IncludeScrollbars).height( );
2847 if (height() < visibleHeight) 2840 if (height() < visibleHeight)
2848 top += (visibleHeight - height()) / 2; 2841 top += (visibleHeight - height()) / 2;
2849 setY(top); 2842 setY(top);
2850 dialog->setCentered(top); 2843 dialog->setCentered(top);
2851 } 2844 }
2852 2845
2853 } // namespace blink 2846 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderBlockFlow.h ('k') | Source/core/rendering/RenderBox.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698