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

Side by Side Diff: Source/core/layout/LayoutBlockFlowLine.cpp

Issue 1152953002: Remove some duplicated code when accounting for floats at line-end (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 7 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/layout/LayoutBlockFlow.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) 2000 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved. 3 * Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ight reserved.
4 * Copyright (C) 2010 Google Inc. All rights reserved. 4 * Copyright (C) 2010 Google Inc. All rights reserved.
5 * 5 *
6 * This library is free software; you can redistribute it and/or 6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public 7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either 8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version. 9 * version 2 of the License, or (at your option) any later version.
10 * 10 *
(...skipping 884 matching lines...) Expand 10 before | Expand all | Expand 10 after
895 895
896 if (!logicalWidthIsAvailable) { 896 if (!logicalWidthIsAvailable) {
897 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i) 897 for (size_t i = 0; i < lineBreaker.positionedObjects().size(); ++i)
898 setStaticPositions(this, lineBreaker.positionedObjects()[i]); 898 setStaticPositions(this, lineBreaker.positionedObjects()[i]);
899 899
900 if (!layoutState.lineInfo().isEmpty()) { 900 if (!layoutState.lineInfo().isEmpty()) {
901 layoutState.lineInfo().setFirstLine(false); 901 layoutState.lineInfo().setFirstLine(false);
902 clearFloats(lineBreaker.clear()); 902 clearFloats(lineBreaker.clear());
903 } 903 }
904 904
905 if (m_floatingObjects && lastRootBox()) { 905 if (appendFloatsToEndOfLine(layoutState, true))
906 const FloatingObjectSet& floatingObjectSet = m_floatingObjects-> set(); 906 checkForEndLineMatch = false;
907 FloatingObjectSetIterator it = floatingObjectSet.begin();
908 FloatingObjectSetIterator end = floatingObjectSet.end();
909 if (layoutState.lastFloat()) {
910 FloatingObjectSetIterator lastFloatIterator = floatingObject Set.find(layoutState.lastFloat());
911 ASSERT(lastFloatIterator != end);
912 ++lastFloatIterator;
913 it = lastFloatIterator;
914 }
915 for (; it != end; ++it) {
916 FloatingObject* f = it->get();
917 appendFloatingObjectToLastLine(f);
918 ASSERT(f->layoutObject() == layoutState.floats()[layoutState .floatIndex()].object);
919 // If a float's geometry has changed, give up on syncing wit h clean lines.
920 if (layoutState.floats()[layoutState.floatIndex()].rect != f ->frameRect())
921 checkForEndLineMatch = false;
922 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
923 }
924 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floating ObjectSet.last().get() : 0);
925 }
926 } 907 }
927 908
928 lineMidpointState.reset(); 909 lineMidpointState.reset();
929 resolver.setPosition(endOfLine, numberOfIsolateAncestors(endOfLine)); 910 resolver.setPosition(endOfLine, numberOfIsolateAncestors(endOfLine));
930 } 911 }
931 912
932 // In case we already adjusted the line positions during this layout to avoi d widows 913 // In case we already adjusted the line positions during this layout to avoi d widows
933 // then we need to ignore the possibility of having a new widows situation. 914 // then we need to ignore the possibility of having a new widows situation.
934 // Otherwise, we risk leaving empty containers which is against the block fr agmentation principles. 915 // Otherwise, we risk leaving empty containers which is against the block fr agmentation principles.
935 if (paginated && !style()->hasAutoWidows() && !didBreakAtLineToAvoidWidow()) { 916 if (paginated && !style()->hasAutoWidows() && !didBreakAtLineToAvoidWidow()) {
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
985 966
986 // We now want to break at this line. Remember for next layout and t rigger relayout. 967 // We now want to break at this line. Remember for next layout and t rigger relayout.
987 setBreakAtLineToAvoidWidow(lineCount(lineBox)); 968 setBreakAtLineToAvoidWidow(lineCount(lineBox));
988 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), l ineBox->lineBottomWithLeading(), lineBox); 969 markLinesDirtyInBlockRange(lastRootBox()->lineBottomWithLeading(), l ineBox->lineBottomWithLeading(), lineBox);
989 } 970 }
990 } 971 }
991 972
992 clearDidBreakAtLineToAvoidWidow(); 973 clearDidBreakAtLineToAvoidWidow();
993 } 974 }
994 975
976 bool LayoutBlockFlow::appendFloatsToEndOfLine(LineLayoutState& layoutState, bool updateFloatIndex)
977 {
978 if (!m_floatingObjects || !lastRootBox())
979 return false;
980
981 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
982 FloatingObjectSetIterator it = floatingObjectSet.begin();
983 FloatingObjectSetIterator end = floatingObjectSet.end();
984 if (layoutState.lastFloat()) {
985 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find(lay outState.lastFloat());
986 ASSERT(lastFloatIterator != end);
987 ++lastFloatIterator;
988 it = lastFloatIterator;
989 }
990
991 bool floatChangedSize = false;
992 for (; it != end; ++it) {
993 FloatingObject* f = it->get();
994 appendFloatingObjectToLastLine(f);
995 if (updateFloatIndex) {
996 ASSERT(f->layoutObject() == layoutState.floats()[layoutState.floatIn dex()].object);
997 // If a float's geometry has changed, give up on syncing with clean lines.
998 if (layoutState.floats()[layoutState.floatIndex()].rect != f->frameR ect())
999 floatChangedSize = true;
1000 layoutState.setFloatIndex(layoutState.floatIndex() + 1);
1001 }
1002 }
1003 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSet.la st().get() : 0);
1004 return floatChangedSize;
1005 }
1006
995 void LayoutBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState) 1007 void LayoutBlockFlow::linkToEndLineIfNeeded(LineLayoutState& layoutState)
996 { 1008 {
997 if (layoutState.endLine()) { 1009 if (layoutState.endLine()) {
998 if (layoutState.endLineMatched()) { 1010 if (layoutState.endLineMatched()) {
999 bool paginated = view()->layoutState() && view()->layoutState()->isP aginated(); 1011 bool paginated = view()->layoutState() && view()->layoutState()->isP aginated();
1000 // Attach all the remaining lines, and then adjust their y-positions as needed. 1012 // Attach all the remaining lines, and then adjust their y-positions as needed.
1001 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop() ; 1013 LayoutUnit delta = logicalHeight() - layoutState.endLineLogicalTop() ;
1002 for (RootInlineBox* line = layoutState.endLine(); line; line = line- >nextRootBox()) { 1014 for (RootInlineBox* line = layoutState.endLine(); line; line = line- >nextRootBox()) {
1003 line->attachLine(); 1015 line->attachLine();
1004 if (paginated) { 1016 if (paginated) {
(...skipping 14 matching lines...) Expand all
1019 } 1031 }
1020 } 1032 }
1021 } 1033 }
1022 setLogicalHeight(lastRootBox()->lineBottomWithLeading()); 1034 setLogicalHeight(lastRootBox()->lineBottomWithLeading());
1023 } else { 1035 } else {
1024 // Delete all the remaining lines. 1036 // Delete all the remaining lines.
1025 deleteLineRange(layoutState, layoutState.endLine()); 1037 deleteLineRange(layoutState, layoutState.endLine());
1026 } 1038 }
1027 } 1039 }
1028 1040
1029 if (positionNewFloats() && lastRootBox()) { 1041 if (positionNewFloats())
1030 // In case we have a float on the last line, it might not be positioned up to now. 1042 appendFloatsToEndOfLine(layoutState, false);
1031 // This has to be done before adding in the bottom border/padding, or th e float will
1032 // include the padding incorrectly. -dwh
leviw_travelin_and_unemployed 2015/05/27 18:26:19 Ahhh, from the good ol' days of "-dwh"
1033 const FloatingObjectSet& floatingObjectSet = m_floatingObjects->set();
1034 FloatingObjectSetIterator it = floatingObjectSet.begin();
1035 FloatingObjectSetIterator end = floatingObjectSet.end();
1036 if (layoutState.lastFloat()) {
1037 FloatingObjectSetIterator lastFloatIterator = floatingObjectSet.find (layoutState.lastFloat());
1038 ASSERT(lastFloatIterator != end);
1039 ++lastFloatIterator;
1040 it = lastFloatIterator;
1041 }
1042 layoutState.setLastFloat(!floatingObjectSet.isEmpty() ? floatingObjectSe t.last().get() : 0);
1043
1044 if (it == end)
1045 return;
1046
1047 for (; it != end; ++it)
1048 appendFloatingObjectToLastLine(it->get());
1049 }
1050 } 1043 }
1051 1044
1052 void LayoutBlockFlow::markDirtyFloatsForPaintInvalidation(Vector<FloatWithRect>& floats) 1045 void LayoutBlockFlow::markDirtyFloatsForPaintInvalidation(Vector<FloatWithRect>& floats)
1053 { 1046 {
1054 size_t floatCount = floats.size(); 1047 size_t floatCount = floats.size();
1055 // Floats that did not have layout did not paint invalidations when we laid them out. They would have 1048 // Floats that did not have layout did not paint invalidations when we laid them out. They would have
1056 // painted by now if they had moved, but if they stayed at (0, 0), they stil l need to be 1049 // painted by now if they had moved, but if they stayed at (0, 0), they stil l need to be
1057 // painted. 1050 // painted.
1058 for (size_t i = 0; i < floatCount; ++i) { 1051 for (size_t i = 0; i < floatCount; ++i) {
1059 if (!floats[i].everHadLayout) { 1052 if (!floats[i].everHadLayout) {
(...skipping 973 matching lines...) Expand 10 before | Expand all | Expand 10 after
2033 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false).toFloat (); 2026 float logicalLeft = logicalLeftOffsetForLine(logicalHeight(), false).toFloat ();
2034 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), fal se) - logicalLeft; 2027 float availableLogicalWidth = logicalRightOffsetForLine(logicalHeight(), fal se) - logicalLeft;
2035 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid th, availableLogicalWidth, 0); 2028 updateLogicalWidthForAlignment(textAlign, 0, 0, logicalLeft, totalLogicalWid th, availableLogicalWidth, 0);
2036 2029
2037 if (!style()->isLeftToRightDirection()) 2030 if (!style()->isLeftToRightDirection())
2038 return logicalWidth() - logicalLeft; 2031 return logicalWidth() - logicalLeft;
2039 return logicalLeft; 2032 return logicalLeft;
2040 } 2033 }
2041 2034
2042 } 2035 }
OLDNEW
« no previous file with comments | « Source/core/layout/LayoutBlockFlow.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698