forked from qt/qtwebkit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRenderBlockLineLayout.cpp
More file actions
2271 lines (1984 loc) · 109 KB
/
Copy pathRenderBlockLineLayout.cpp
File metadata and controls
2271 lines (1984 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) 2000 Lars Knoll (knoll@kde.org)
* Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All right reserved.
* Copyright (C) 2010 Google Inc. All rights reserved.
* Copyright (C) 2013 ChangSeok Oh <shivamidow@gmail.com>
* Copyright (C) 2013 Adobe Systems Inc. All right reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
*/
#include "config.h"
#include "AXObjectCache.h"
#include "BidiResolver.h"
#include "BreakingContext.h"
#include "FloatingObjects.h"
#include "InlineElementBox.h"
#include "InlineIterator.h"
#include "InlineTextBox.h"
#include "InlineTextBoxStyle.h"
#include "LineLayoutState.h"
#include "Logging.h"
#include "RenderBlockFlow.h"
#include "RenderFlowThread.h"
#include "RenderLineBreak.h"
#include "RenderRegion.h"
#include "RenderRubyBase.h"
#include "RenderRubyText.h"
#include "RenderView.h"
#include "SVGRootInlineBox.h"
#include "Settings.h"
#include "SimpleLineLayoutFunctions.h"
#include "TrailingFloatsRootInlineBox.h"
#include "VerticalPositionCache.h"
#include <wtf/RefCountedLeakCounter.h>
#include <wtf/StdLibExtras.h>
namespace WebCore {
static void determineDirectionality(TextDirection& dir, InlineIterator iter)
{
while (!iter.atEnd()) {
if (iter.atParagraphSeparator())
return;
if (UChar current = iter.current()) {
UCharDirection charDirection = u_charDirection(current);
if (charDirection == U_LEFT_TO_RIGHT) {
dir = LTR;
return;
}
if (charDirection == U_RIGHT_TO_LEFT || charDirection == U_RIGHT_TO_LEFT_ARABIC) {
dir = RTL;
return;
}
}
iter.increment();
}
}
inline BidiRun* createRun(int start, int end, RenderObject& obj, InlineBidiResolver& resolver)
{
return new BidiRun(start, end, obj, resolver.context(), resolver.dir());
}
void RenderBlockFlow::appendRunsForObject(BidiRunList<BidiRun>* runs, int start, int end, RenderObject& obj, InlineBidiResolver& resolver)
{
if (start > end || shouldSkipCreatingRunsForObject(obj))
return;
LineMidpointState& lineMidpointState = resolver.midpointState();
bool haveNextMidpoint = (lineMidpointState.currentMidpoint() < lineMidpointState.numMidpoints());
InlineIterator nextMidpoint;
if (haveNextMidpoint)
nextMidpoint = lineMidpointState.midpoints()[lineMidpointState.currentMidpoint()];
if (lineMidpointState.betweenMidpoints()) {
if (!haveNextMidpoint || (&obj != nextMidpoint.renderer()))
return;
// This is a new start point. Stop ignoring objects and
// adjust our start.
start = nextMidpoint.offset();
lineMidpointState.incrementCurrentMidpoint();
if (start < end) {
appendRunsForObject(runs, start, end, obj, resolver);
return;
}
} else {
if (!haveNextMidpoint || (&obj != nextMidpoint.renderer())) {
if (runs)
runs->addRun(createRun(start, end, obj, resolver));
return;
}
// An end midpoint has been encountered within our object. We need to append a run with our endpoint.
if (static_cast<int>(nextMidpoint.offset() + 1) <= end) {
lineMidpointState.incrementCurrentMidpoint();
// The end of the line is before the object we're inspecting. Skip everything and return
if (nextMidpoint.refersToEndOfPreviousNode())
return;
if (static_cast<int>(nextMidpoint.offset() + 1) > start && runs)
runs->addRun(createRun(start, nextMidpoint.offset() + 1, obj, resolver));
appendRunsForObject(runs, nextMidpoint.offset() + 1, end, obj, resolver);
} else if (runs)
runs->addRun(createRun(start, end, obj, resolver));
}
}
std::unique_ptr<RootInlineBox> RenderBlockFlow::createRootInlineBox()
{
return std::make_unique<RootInlineBox>(*this);
}
RootInlineBox* RenderBlockFlow::createAndAppendRootInlineBox()
{
auto newRootBox = createRootInlineBox();
RootInlineBox* rootBox = newRootBox.get();
m_lineBoxes.appendLineBox(WTFMove(newRootBox));
if (UNLIKELY(AXObjectCache::accessibilityEnabled()) && firstRootBox() == rootBox) {
if (AXObjectCache* cache = document().existingAXObjectCache())
cache->recomputeIsIgnored(this);
}
return rootBox;
}
static inline InlineBox* createInlineBoxForRenderer(RenderObject* renderer, bool isRootLineBox, bool isOnlyRun = false)
{
if (isRootLineBox)
return downcast<RenderBlockFlow>(*renderer).createAndAppendRootInlineBox();
if (is<RenderText>(*renderer))
return downcast<RenderText>(*renderer).createInlineTextBox();
if (is<RenderBox>(*renderer)) {
// FIXME: This is terrible. This branch returns an *owned* pointer!
return downcast<RenderBox>(*renderer).createInlineBox().release();
}
if (is<RenderLineBreak>(*renderer)) {
// FIXME: This is terrible. This branch returns an *owned* pointer!
auto inlineBox = downcast<RenderLineBreak>(*renderer).createInlineBox().release();
// We only treat a box as text for a <br> if we are on a line by ourself or in strict mode
// (Note the use of strict mode. In "almost strict" mode, we don't treat the box for <br> as text.)
inlineBox->setBehavesLikeText(isOnlyRun || renderer->document().inNoQuirksMode() || renderer->isLineBreakOpportunity());
return inlineBox;
}
return downcast<RenderInline>(*renderer).createAndAppendInlineFlowBox();
}
static inline void dirtyLineBoxesForRenderer(RenderObject& renderer, bool fullLayout)
{
if (is<RenderText>(renderer)) {
RenderText& renderText = downcast<RenderText>(renderer);
updateCounterIfNeeded(renderText);
renderText.dirtyLineBoxes(fullLayout);
} else if (is<RenderLineBreak>(renderer))
downcast<RenderLineBreak>(renderer).dirtyLineBoxes(fullLayout);
else
downcast<RenderInline>(renderer).dirtyLineBoxes(fullLayout);
}
static bool parentIsConstructedOrHaveNext(InlineFlowBox* parentBox)
{
do {
if (parentBox->isConstructed() || parentBox->nextOnLine())
return true;
parentBox = parentBox->parent();
} while (parentBox);
return false;
}
InlineFlowBox* RenderBlockFlow::createLineBoxes(RenderObject* obj, const LineInfo& lineInfo, InlineBox* childBox)
{
// See if we have an unconstructed line box for this object that is also
// the last item on the line.
unsigned lineDepth = 1;
InlineFlowBox* parentBox = nullptr;
InlineFlowBox* result = nullptr;
bool hasDefaultLineBoxContain = style().lineBoxContain() == RenderStyle::initialLineBoxContain();
do {
ASSERT_WITH_SECURITY_IMPLICATION(is<RenderInline>(*obj) || obj == this);
RenderInline* inlineFlow = obj != this ? downcast<RenderInline>(obj) : nullptr;
// Get the last box we made for this render object.
parentBox = inlineFlow ? inlineFlow->lastLineBox() : downcast<RenderBlockFlow>(*obj).lastRootBox();
// If this box or its ancestor is constructed then it is from a previous line, and we need
// to make a new box for our line. If this box or its ancestor is unconstructed but it has
// something following it on the line, then we know we have to make a new box
// as well. In this situation our inline has actually been split in two on
// the same line (this can happen with very fancy language mixtures).
bool constructedNewBox = false;
bool allowedToConstructNewBox = !hasDefaultLineBoxContain || !inlineFlow || inlineFlow->alwaysCreateLineBoxes();
bool canUseExistingParentBox = parentBox && !parentIsConstructedOrHaveNext(parentBox);
if (allowedToConstructNewBox && !canUseExistingParentBox) {
// We need to make a new box for this render object. Once
// made, we need to place it at the end of the current line.
InlineBox* newBox = createInlineBoxForRenderer(obj, obj == this);
parentBox = downcast<InlineFlowBox>(newBox);
parentBox->setIsFirstLine(lineInfo.isFirstLine());
parentBox->setIsHorizontal(isHorizontalWritingMode());
if (!hasDefaultLineBoxContain)
parentBox->clearDescendantsHaveSameLineHeightAndBaseline();
constructedNewBox = true;
}
if (constructedNewBox || canUseExistingParentBox) {
if (!result)
result = parentBox;
// If we have hit the block itself, then |box| represents the root
// inline box for the line, and it doesn't have to be appended to any parent
// inline.
if (childBox)
parentBox->addToLine(childBox);
if (!constructedNewBox || obj == this)
break;
childBox = parentBox;
}
// If we've exceeded our line depth, then jump straight to the root and skip all the remaining
// intermediate inline flows.
obj = (++lineDepth >= cMaxLineDepth) ? this : obj->parent();
} while (true);
return result;
}
template <typename CharacterType>
static inline bool endsWithASCIISpaces(const CharacterType* characters, unsigned pos, unsigned end)
{
while (isASCIISpace(characters[pos])) {
pos++;
if (pos >= end)
return true;
}
return false;
}
static bool reachedEndOfTextRenderer(const BidiRunList<BidiRun>& bidiRuns)
{
BidiRun* run = bidiRuns.logicallyLastRun();
if (!run)
return true;
unsigned pos = run->stop();
const RenderObject& renderer = run->renderer();
if (!is<RenderText>(renderer))
return false;
const RenderText& renderText = downcast<RenderText>(renderer);
unsigned length = renderText.textLength();
if (pos >= length)
return true;
if (renderText.is8Bit())
return endsWithASCIISpaces(renderText.characters8(), pos, length);
return endsWithASCIISpaces(renderText.characters16(), pos, length);
}
RootInlineBox* RenderBlockFlow::constructLine(BidiRunList<BidiRun>& bidiRuns, const LineInfo& lineInfo)
{
ASSERT(bidiRuns.firstRun());
bool rootHasSelectedChildren = false;
InlineFlowBox* parentBox = 0;
int runCount = bidiRuns.runCount() - lineInfo.runsFromLeadingWhitespace();
for (BidiRun* r = bidiRuns.firstRun(); r; r = r->next()) {
// Create a box for our object.
bool isOnlyRun = (runCount == 1);
if (runCount == 2 && !r->renderer().isListMarker())
isOnlyRun = (!style().isLeftToRightDirection() ? bidiRuns.lastRun() : bidiRuns.firstRun())->renderer().isListMarker();
if (lineInfo.isEmpty())
continue;
InlineBox* box = createInlineBoxForRenderer(&r->renderer(), false, isOnlyRun);
r->setBox(box);
if (!rootHasSelectedChildren && box->renderer().selectionState() != RenderObject::SelectionNone)
rootHasSelectedChildren = true;
// If we have no parent box yet, or if the run is not simply a sibling,
// then we need to construct inline boxes as necessary to properly enclose the
// run's inline box. Segments can only be siblings at the root level, as
// they are positioned separately.
if (!parentBox || &parentBox->renderer() != r->renderer().parent()) {
// Create new inline boxes all the way back to the appropriate insertion point.
RenderObject* parentToUse = r->renderer().parent();
parentBox = createLineBoxes(parentToUse, lineInfo, box);
} else {
// Append the inline box to this line.
parentBox->addToLine(box);
}
bool visuallyOrdered = r->renderer().style().rtlOrdering() == VisualOrder;
box->setBidiLevel(r->level());
if (is<InlineTextBox>(*box)) {
auto& textBox = downcast<InlineTextBox>(*box);
textBox.setStart(r->m_start);
textBox.setLen(r->m_stop - r->m_start);
textBox.setDirOverride(r->dirOverride(visuallyOrdered));
if (r->m_hasHyphen)
textBox.setHasHyphen(true);
}
}
// We should have a root inline box. It should be unconstructed and
// be the last continuation of our line list.
ASSERT(lastRootBox() && !lastRootBox()->isConstructed());
// Set the m_selectedChildren flag on the root inline box if one of the leaf inline box
// from the bidi runs walk above has a selection state.
if (rootHasSelectedChildren)
lastRootBox()->root().setHasSelectedChildren(true);
// Set bits on our inline flow boxes that indicate which sides should
// paint borders/margins/padding. This knowledge will ultimately be used when
// we determine the horizontal positions and widths of all the inline boxes on
// the line.
bool isLogicallyLastRunWrapped = bidiRuns.logicallyLastRun()->renderer().isText() ? !reachedEndOfTextRenderer(bidiRuns) : true;
lastRootBox()->determineSpacingForFlowBoxes(lineInfo.isLastLine(), isLogicallyLastRunWrapped, &bidiRuns.logicallyLastRun()->renderer());
// Now mark the line boxes as being constructed.
lastRootBox()->setConstructed();
// Return the last line.
return lastRootBox();
}
ETextAlign RenderBlockFlow::textAlignmentForLine(bool endsWithSoftBreak) const
{
ETextAlign alignment = style().textAlign();
#if ENABLE(CSS3_TEXT)
TextJustify textJustify = style().textJustify();
if (alignment == JUSTIFY && textJustify == TextJustifyNone)
return style().direction() == LTR ? LEFT : RIGHT;
#endif
if (endsWithSoftBreak)
return alignment;
#if !ENABLE(CSS3_TEXT)
return (alignment == JUSTIFY) ? TASTART : alignment;
#else
if (alignment != JUSTIFY)
return alignment;
TextAlignLast alignmentLast = style().textAlignLast();
switch (alignmentLast) {
case TextAlignLastStart:
return TASTART;
case TextAlignLastEnd:
return TAEND;
case TextAlignLastLeft:
return LEFT;
case TextAlignLastRight:
return RIGHT;
case TextAlignLastCenter:
return CENTER;
case TextAlignLastJustify:
return JUSTIFY;
case TextAlignLastAuto:
if (textJustify == TextJustifyDistribute)
return JUSTIFY;
return TASTART;
}
return alignment;
#endif
}
static void updateLogicalWidthForLeftAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
// The direction of the block should determine what happens with wide lines.
// In particular with RTL blocks, wide lines should still spill out to the left.
if (isLeftToRightDirection) {
if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun)
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
return;
}
if (trailingSpaceRun)
trailingSpaceRun->box()->setLogicalWidth(0);
else if (totalLogicalWidth > availableLogicalWidth)
logicalLeft -= (totalLogicalWidth - availableLogicalWidth);
}
static void updateLogicalWidthForRightAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
// Wide lines spill out of the block based off direction.
// So even if text-align is right, if direction is LTR, wide lines should overflow out of the right
// side of the block.
if (isLeftToRightDirection) {
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceRun->box()->setLogicalWidth(0);
}
logicalLeft += std::max(0.f, availableLogicalWidth - totalLogicalWidth);
return;
}
if (totalLogicalWidth > availableLogicalWidth && trailingSpaceRun) {
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceRun->box()->logicalWidth() - totalLogicalWidth + availableLogicalWidth));
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
} else
logicalLeft += availableLogicalWidth - totalLogicalWidth;
}
static void updateLogicalWidthForCenterAlignedBlock(bool isLeftToRightDirection, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float availableLogicalWidth)
{
float trailingSpaceWidth = 0;
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceWidth = std::min(trailingSpaceRun->box()->logicalWidth(), (availableLogicalWidth - totalLogicalWidth + 1) / 2);
trailingSpaceRun->box()->setLogicalWidth(std::max<float>(0, trailingSpaceWidth));
}
if (isLeftToRightDirection)
logicalLeft += std::max<float>((availableLogicalWidth - totalLogicalWidth) / 2, 0);
else
logicalLeft += totalLogicalWidth > availableLogicalWidth ? (availableLogicalWidth - totalLogicalWidth) : (availableLogicalWidth - totalLogicalWidth) / 2 - trailingSpaceWidth;
}
void RenderBlockFlow::setMarginsForRubyRun(BidiRun* run, RenderRubyRun& renderer, RenderObject* previousObject, const LineInfo& lineInfo)
{
float startOverhang;
float endOverhang;
RenderObject* nextObject = 0;
for (BidiRun* runWithNextObject = run->next(); runWithNextObject; runWithNextObject = runWithNextObject->next()) {
if (!runWithNextObject->renderer().isOutOfFlowPositioned() && !runWithNextObject->box()->isLineBreak()) {
nextObject = &runWithNextObject->renderer();
break;
}
}
renderer.getOverhang(lineInfo.isFirstLine(), renderer.style().isLeftToRightDirection() ? previousObject : nextObject, renderer.style().isLeftToRightDirection() ? nextObject : previousObject, startOverhang, endOverhang);
setMarginStartForChild(renderer, -startOverhang);
setMarginEndForChild(renderer, -endOverhang);
}
static inline void setLogicalWidthForTextRun(RootInlineBox* lineBox, BidiRun* run, RenderText& renderer, float xPos, const LineInfo& lineInfo,
GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
{
HashSet<const Font*> fallbackFonts;
GlyphOverflow glyphOverflow;
const FontCascade& font = lineStyle(*renderer.parent(), lineInfo).fontCascade();
// Always compute glyph overflow if the block's line-box-contain value is "glyphs".
if (lineBox->fitsToGlyphs()) {
// If we don't stick out of the root line's font box, then don't bother computing our glyph overflow. This optimization
// will keep us from computing glyph bounds in nearly all cases.
bool includeRootLine = lineBox->includesRootLineBoxFontOrLeading();
int baselineShift = lineBox->verticalPositionForBox(run->box(), verticalPositionCache);
int rootDescent = includeRootLine ? font.fontMetrics().descent() : 0;
int rootAscent = includeRootLine ? font.fontMetrics().ascent() : 0;
int boxAscent = font.fontMetrics().ascent() - baselineShift;
int boxDescent = font.fontMetrics().descent() + baselineShift;
if (boxAscent > rootDescent || boxDescent > rootAscent)
glyphOverflow.computeBounds = true;
}
LayoutUnit hyphenWidth = 0;
if (downcast<InlineTextBox>(*run->box()).hasHyphen())
hyphenWidth = measureHyphenWidth(renderer, font, &fallbackFonts);
float measuredWidth = 0;
bool kerningIsEnabled = font.enableKerning();
bool canUseSimpleFontCodePath = renderer.canUseSimpleFontCodePath();
// Since we don't cache glyph overflows, we need to re-measure the run if
// the style is linebox-contain: glyph.
if (!lineBox->fitsToGlyphs() && canUseSimpleFontCodePath) {
int lastEndOffset = run->m_start;
for (size_t i = 0, size = wordMeasurements.size(); i < size && lastEndOffset < run->m_stop; ++i) {
WordMeasurement& wordMeasurement = wordMeasurements[i];
if (wordMeasurement.width <= 0 || wordMeasurement.startOffset == wordMeasurement.endOffset)
continue;
if (wordMeasurement.renderer != &renderer || wordMeasurement.startOffset != lastEndOffset || wordMeasurement.endOffset > run->m_stop)
continue;
lastEndOffset = wordMeasurement.endOffset;
if (kerningIsEnabled && lastEndOffset == run->m_stop) {
int wordLength = lastEndOffset - wordMeasurement.startOffset;
GlyphOverflow overflow;
measuredWidth += renderer.width(wordMeasurement.startOffset, wordLength, xPos + measuredWidth, lineInfo.isFirstLine(),
&wordMeasurement.fallbackFonts, &overflow);
UChar c = renderer.characterAt(wordMeasurement.startOffset);
if (i > 0 && wordLength == 1 && (c == ' ' || c == '\t'))
measuredWidth += renderer.style().fontCascade().wordSpacing();
} else
measuredWidth += wordMeasurement.width;
if (!wordMeasurement.fallbackFonts.isEmpty()) {
HashSet<const Font*>::const_iterator end = wordMeasurement.fallbackFonts.end();
for (HashSet<const Font*>::const_iterator it = wordMeasurement.fallbackFonts.begin(); it != end; ++it)
fallbackFonts.add(*it);
}
}
if (measuredWidth && lastEndOffset != run->m_stop) {
// If we don't have enough cached data, we'll measure the run again.
measuredWidth = 0;
fallbackFonts.clear();
}
}
if (!measuredWidth)
measuredWidth = renderer.width(run->m_start, run->m_stop - run->m_start, xPos, lineInfo.isFirstLine(), &fallbackFonts, &glyphOverflow);
run->box()->setLogicalWidth(measuredWidth + hyphenWidth);
if (!fallbackFonts.isEmpty()) {
ASSERT(run->box()->behavesLikeText());
GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator;
ASSERT(it->value.first.isEmpty());
copyToVector(fallbackFonts, it->value.first);
run->box()->parent()->clearDescendantsHaveSameLineHeightAndBaseline();
}
// Include text decoration visual overflow as part of the glyph overflow.
if (renderer.style().textDecorationsInEffect() != TextDecorationNone)
glyphOverflow.extendTo(visualOverflowForDecorations(run->box()->lineStyle(), downcast<InlineTextBox>(run->box())));
if (!glyphOverflow.isEmpty()) {
ASSERT(run->box()->behavesLikeText());
GlyphOverflowAndFallbackFontsMap::iterator it = textBoxDataMap.add(downcast<InlineTextBox>(run->box()), std::make_pair(Vector<const Font*>(), GlyphOverflow())).iterator;
it->value.second = glyphOverflow;
run->box()->clearKnownToHaveNoOverflow();
}
}
void RenderBlockFlow::updateRubyForJustifiedText(RenderRubyRun& rubyRun, BidiRun& r, const Vector<unsigned, 16>& expansionOpportunities, unsigned& expansionOpportunityCount, float& totalLogicalWidth, float availableLogicalWidth, size_t& i)
{
if (!rubyRun.rubyBase() || !rubyRun.rubyBase()->firstRootBox() || rubyRun.rubyBase()->firstRootBox()->nextRootBox() || !r.renderer().style().collapseWhiteSpace())
return;
auto& rubyBase = *rubyRun.rubyBase();
auto& rootBox = *rubyBase.firstRootBox();
float totalExpansion = 0;
unsigned totalOpportunitiesInRun = 0;
for (auto* leafChild = rootBox.firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
if (!leafChild->isInlineTextBox())
continue;
unsigned opportunitiesInRun = expansionOpportunities[i++];
ASSERT(opportunitiesInRun <= expansionOpportunityCount);
auto expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
totalExpansion += expansion;
totalOpportunitiesInRun += opportunitiesInRun;
}
ASSERT(!rubyRun.hasOverrideLogicalContentWidth());
float newBaseWidth = rubyRun.logicalWidth() + totalExpansion + marginStartForChild(rubyRun) + marginEndForChild(rubyRun);
float newRubyRunWidth = rubyRun.logicalWidth() + totalExpansion;
rubyBase.setInitialOffset((newRubyRunWidth - newBaseWidth) / 2);
rubyRun.setOverrideLogicalContentWidth(newRubyRunWidth);
rubyRun.setNeedsLayout(MarkOnlyThis);
rootBox.markDirty();
if (RenderRubyText* rubyText = rubyRun.rubyText()) {
if (RootInlineBox* textRootBox = rubyText->firstRootBox())
textRootBox->markDirty();
}
rubyRun.layoutBlock(true);
rubyRun.clearOverrideLogicalContentWidth();
r.box()->setExpansion(newRubyRunWidth - r.box()->logicalWidth());
// This relayout caused the size of the RenderRubyText and the RenderRubyBase to change, dependent on the line's current expansion. Next time we relayout the
// RenderRubyRun, make sure that we relayout the RenderRubyBase and RenderRubyText as well.
rubyBase.setNeedsLayout(MarkOnlyThis);
if (RenderRubyText* rubyText = rubyRun.rubyText())
rubyText->setNeedsLayout(MarkOnlyThis);
totalLogicalWidth += totalExpansion;
expansionOpportunityCount -= totalOpportunitiesInRun;
}
void RenderBlockFlow::computeExpansionForJustifiedText(BidiRun* firstRun, BidiRun* trailingSpaceRun, const Vector<unsigned, 16>& expansionOpportunities, unsigned expansionOpportunityCount, float totalLogicalWidth, float availableLogicalWidth)
{
if (!expansionOpportunityCount || availableLogicalWidth <= totalLogicalWidth)
return;
size_t i = 0;
for (BidiRun* run = firstRun; run; run = run->next()) {
if (!run->box() || run == trailingSpaceRun)
continue;
if (is<RenderText>(run->renderer())) {
unsigned opportunitiesInRun = expansionOpportunities[i++];
ASSERT(opportunitiesInRun <= expansionOpportunityCount);
// Only justify text if whitespace is collapsed.
if (run->renderer().style().collapseWhiteSpace()) {
InlineTextBox& textBox = downcast<InlineTextBox>(*run->box());
float expansion = (availableLogicalWidth - totalLogicalWidth) * opportunitiesInRun / expansionOpportunityCount;
textBox.setExpansion(expansion);
totalLogicalWidth += expansion;
}
expansionOpportunityCount -= opportunitiesInRun;
} else if (is<RenderRubyRun>(run->renderer()))
updateRubyForJustifiedText(downcast<RenderRubyRun>(run->renderer()), *run, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth, i);
if (!expansionOpportunityCount)
break;
}
}
void RenderBlockFlow::updateLogicalWidthForAlignment(const ETextAlign& textAlign, const RootInlineBox* rootInlineBox, BidiRun* trailingSpaceRun, float& logicalLeft, float& totalLogicalWidth, float& availableLogicalWidth, int expansionOpportunityCount)
{
TextDirection direction;
if (rootInlineBox && style().unicodeBidi() == Plaintext)
direction = rootInlineBox->direction();
else
direction = style().direction();
// Armed with the total width of the line (without justification),
// we now examine our text-align property in order to determine where to position the
// objects horizontally. The total width of the line can be increased if we end up
// justifying text.
switch (textAlign) {
case LEFT:
case WEBKIT_LEFT:
updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case RIGHT:
case WEBKIT_RIGHT:
updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case CENTER:
case WEBKIT_CENTER:
updateLogicalWidthForCenterAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case JUSTIFY:
adjustInlineDirectionLineBounds(expansionOpportunityCount, logicalLeft, availableLogicalWidth);
if (expansionOpportunityCount) {
if (trailingSpaceRun) {
totalLogicalWidth -= trailingSpaceRun->box()->logicalWidth();
trailingSpaceRun->box()->setLogicalWidth(0);
}
break;
}
FALLTHROUGH;
case TASTART:
if (direction == LTR)
updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
else
updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
case TAEND:
if (direction == LTR)
updateLogicalWidthForRightAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
else
updateLogicalWidthForLeftAlignedBlock(style().isLeftToRightDirection(), trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth);
break;
}
}
static void updateLogicalInlinePositions(RenderBlockFlow& block, float& lineLogicalLeft, float& lineLogicalRight, float& availableLogicalWidth, bool firstLine,
IndentTextOrNot shouldIndentText, LayoutUnit boxLogicalHeight, RootInlineBox* rootBox)
{
LayoutUnit lineLogicalHeight = block.minLineHeightForReplacedRenderer(firstLine, boxLogicalHeight);
if (rootBox->hasAnonymousInlineBlock()) {
lineLogicalLeft = block.logicalLeftOffsetForContent(block.logicalHeight());
lineLogicalRight = block.logicalRightOffsetForContent(block.logicalHeight());
} else {
lineLogicalLeft = block.logicalLeftOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight);
lineLogicalRight = block.logicalRightOffsetForLine(block.logicalHeight(), shouldIndentText, lineLogicalHeight);
}
availableLogicalWidth = lineLogicalRight - lineLogicalLeft;
}
void RenderBlockFlow::computeInlineDirectionPositionsForLine(RootInlineBox* lineBox, const LineInfo& lineInfo, BidiRun* firstRun, BidiRun* trailingSpaceRun, bool reachedEnd, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache, WordMeasurements& wordMeasurements)
{
ETextAlign textAlign = textAlignmentForLine(!reachedEnd && !lineBox->endsWithBreak());
// CSS 2.1: "'Text-indent' only affects a line if it is the first formatted line of an element. For example, the first line of an anonymous block
// box is only affected if it is the first child of its parent element."
// CSS3 "text-indent", "-webkit-each-line" affects the first line of the block container as well as each line after a forced line break,
// but does not affect lines after a soft wrap break.
bool isFirstLine = lineInfo.isFirstLine() && !(isAnonymousBlock() && parent()->firstChild() != this);
bool isAfterHardLineBreak = lineBox->prevRootBox() && lineBox->prevRootBox()->endsWithBreak();
IndentTextOrNot shouldIndentText = requiresIndent(isFirstLine, isAfterHardLineBreak, style());
float lineLogicalLeft;
float lineLogicalRight;
float availableLogicalWidth;
updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, 0, lineBox);
bool needsWordSpacing;
if (firstRun && firstRun->renderer().isReplaced()) {
RenderBox& renderBox = downcast<RenderBox>(firstRun->renderer());
updateLogicalInlinePositions(*this, lineLogicalLeft, lineLogicalRight, availableLogicalWidth, isFirstLine, shouldIndentText, renderBox.logicalHeight(), lineBox);
}
computeInlineDirectionPositionsForSegment(lineBox, lineInfo, textAlign, lineLogicalLeft, availableLogicalWidth, firstRun, trailingSpaceRun, textBoxDataMap, verticalPositionCache, wordMeasurements);
// The widths of all runs are now known. We can now place every inline box (and
// compute accurate widths for the inline flow boxes).
needsWordSpacing = false;
lineBox->placeBoxesInInlineDirection(lineLogicalLeft, needsWordSpacing);
}
static inline ExpansionBehavior expansionBehaviorForInlineTextBox(RenderBlockFlow& block, InlineTextBox& textBox, BidiRun* previousRun, BidiRun* nextRun, ETextAlign textAlign, bool isAfterExpansion)
{
// Tatechuyoko is modeled as the Object Replacement Character (U+FFFC), which can never have expansion opportunities inside nor intrinsically adjacent to it.
if (textBox.renderer().style().textCombine() == TextCombineHorizontal)
return ForbidLeadingExpansion | ForbidTrailingExpansion;
ExpansionBehavior result = 0;
bool setLeadingExpansion = false;
bool setTrailingExpansion = false;
if (textAlign == JUSTIFY) {
// If the next box is ruby, and we're justifying, and the first box in the ruby base has a leading expansion, and we are a text box, then force a trailing expansion.
if (nextRun && is<RenderRubyRun>(nextRun->renderer()) && downcast<RenderRubyRun>(nextRun->renderer()).rubyBase() && nextRun->renderer().style().collapseWhiteSpace()) {
auto& rubyBase = *downcast<RenderRubyRun>(nextRun->renderer()).rubyBase();
if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) {
if (auto* leafChild = rubyBase.firstRootBox()->firstLeafChild()) {
if (is<InlineTextBox>(*leafChild)) {
// FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA
if (FontCascade::leadingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) {
setTrailingExpansion = true;
result |= ForceTrailingExpansion;
}
}
}
}
}
// Same thing, except if we're following a ruby
if (previousRun && is<RenderRubyRun>(previousRun->renderer()) && downcast<RenderRubyRun>(previousRun->renderer()).rubyBase() && previousRun->renderer().style().collapseWhiteSpace()) {
auto& rubyBase = *downcast<RenderRubyRun>(previousRun->renderer()).rubyBase();
if (rubyBase.firstRootBox() && !rubyBase.firstRootBox()->nextRootBox()) {
if (auto* leafChild = rubyBase.firstRootBox()->lastLeafChild()) {
if (is<InlineTextBox>(*leafChild)) {
// FIXME: This leadingExpansionOpportunity doesn't actually work because it doesn't perform the UBA
if (FontCascade::trailingExpansionOpportunity(downcast<RenderText>(leafChild->renderer()).stringView(), leafChild->direction())) {
setLeadingExpansion = true;
result |= ForceLeadingExpansion;
}
}
}
}
}
// If we're the first box inside a ruby base, forbid a leading expansion, and vice-versa
if (is<RenderRubyBase>(block)) {
RenderRubyBase& rubyBase = downcast<RenderRubyBase>(block);
if (&textBox == rubyBase.firstRootBox()->firstLeafChild()) {
setLeadingExpansion = true;
result |= ForbidLeadingExpansion;
} if (&textBox == rubyBase.firstRootBox()->lastLeafChild()) {
setTrailingExpansion = true;
result |= ForbidTrailingExpansion;
}
}
}
if (!setLeadingExpansion)
result |= isAfterExpansion ? ForbidLeadingExpansion : AllowLeadingExpansion;
if (!setTrailingExpansion)
result |= AllowTrailingExpansion;
return result;
}
static inline void applyExpansionBehavior(InlineTextBox& textBox, ExpansionBehavior expansionBehavior)
{
switch (expansionBehavior & LeadingExpansionMask) {
case ForceLeadingExpansion:
textBox.setForceLeadingExpansion();
break;
case ForbidLeadingExpansion:
textBox.setCanHaveLeadingExpansion(false);
break;
case AllowLeadingExpansion:
textBox.setCanHaveLeadingExpansion(true);
break;
default:
ASSERT_NOT_REACHED();
break;
}
switch (expansionBehavior & TrailingExpansionMask) {
case ForceTrailingExpansion:
textBox.setForceTrailingExpansion();
break;
case ForbidTrailingExpansion:
textBox.setCanHaveTrailingExpansion(false);
break;
case AllowTrailingExpansion:
textBox.setCanHaveTrailingExpansion(true);
break;
default:
ASSERT_NOT_REACHED();
break;
}
}
BidiRun* RenderBlockFlow::computeInlineDirectionPositionsForSegment(RootInlineBox* lineBox, const LineInfo& lineInfo, ETextAlign textAlign, float& logicalLeft,
float& availableLogicalWidth, BidiRun* firstRun, BidiRun* trailingSpaceRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap, VerticalPositionCache& verticalPositionCache,
WordMeasurements& wordMeasurements)
{
bool needsWordSpacing = false;
float totalLogicalWidth = lineBox->getFlowSpacingLogicalWidth();
unsigned expansionOpportunityCount = 0;
bool isAfterExpansion = is<RenderRubyBase>(*this) ? downcast<RenderRubyBase>(*this).isAfterExpansion() : true;
Vector<unsigned, 16> expansionOpportunities;
BidiRun* run = firstRun;
BidiRun* previousRun = nullptr;
for (; run; run = run->next()) {
if (!run->box() || run->renderer().isOutOfFlowPositioned() || run->box()->isLineBreak()) {
continue; // Positioned objects are only participating to figure out their
// correct static x position. They have no effect on the width.
// Similarly, line break boxes have no effect on the width.
}
if (is<RenderText>(run->renderer())) {
auto& renderText = downcast<RenderText>(run->renderer());
auto& textBox = downcast<InlineTextBox>(*run->box());
if (textAlign == JUSTIFY && run != trailingSpaceRun) {
ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*this, textBox, previousRun, run->next(), textAlign, isAfterExpansion);
applyExpansionBehavior(textBox, expansionBehavior);
unsigned opportunitiesInRun;
std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(run->m_start, run->m_stop), run->box()->direction(), expansionBehavior);
expansionOpportunities.append(opportunitiesInRun);
expansionOpportunityCount += opportunitiesInRun;
}
if (int length = renderText.textLength()) {
if (!run->m_start && needsWordSpacing && isSpaceOrNewline(renderText.characterAt(run->m_start)))
totalLogicalWidth += lineStyle(*renderText.parent(), lineInfo).fontCascade().wordSpacing();
needsWordSpacing = !isSpaceOrNewline(renderText.characterAt(run->m_stop - 1)) && run->m_stop == length;
}
setLogicalWidthForTextRun(lineBox, run, renderText, totalLogicalWidth, lineInfo, textBoxDataMap, verticalPositionCache, wordMeasurements);
} else {
bool encounteredJustifiedRuby = false;
if (is<RenderRubyRun>(run->renderer()) && textAlign == JUSTIFY && run != trailingSpaceRun && downcast<RenderRubyRun>(run->renderer()).rubyBase()) {
auto* rubyBase = downcast<RenderRubyRun>(run->renderer()).rubyBase();
if (rubyBase->firstRootBox() && !rubyBase->firstRootBox()->nextRootBox() && run->renderer().style().collapseWhiteSpace()) {
rubyBase->setIsAfterExpansion(isAfterExpansion);
for (auto* leafChild = rubyBase->firstRootBox()->firstLeafChild(); leafChild; leafChild = leafChild->nextLeafChild()) {
if (!is<InlineTextBox>(*leafChild))
continue;
auto& textBox = downcast<InlineTextBox>(*leafChild);
encounteredJustifiedRuby = true;
auto& renderText = downcast<RenderText>(leafChild->renderer());
ExpansionBehavior expansionBehavior = expansionBehaviorForInlineTextBox(*rubyBase, textBox, nullptr, nullptr, textAlign, isAfterExpansion);
applyExpansionBehavior(textBox, expansionBehavior);
unsigned opportunitiesInRun;
std::tie(opportunitiesInRun, isAfterExpansion) = FontCascade::expansionOpportunityCount(renderText.stringView(), leafChild->direction(), expansionBehavior);
expansionOpportunities.append(opportunitiesInRun);
expansionOpportunityCount += opportunitiesInRun;
}
}
}
if (!encounteredJustifiedRuby)
isAfterExpansion = false;
if (!is<RenderInline>(run->renderer())) {
auto& renderBox = downcast<RenderBox>(run->renderer());
if (is<RenderRubyRun>(renderBox))
setMarginsForRubyRun(run, downcast<RenderRubyRun>(renderBox), previousRun ? &previousRun->renderer() : nullptr, lineInfo);
run->box()->setLogicalWidth(logicalWidthForChild(renderBox));
totalLogicalWidth += marginStartForChild(renderBox) + marginEndForChild(renderBox);
}
}
totalLogicalWidth += run->box()->logicalWidth();
previousRun = run;
}
if (isAfterExpansion && !expansionOpportunities.isEmpty()) {
expansionOpportunities.last()--;
expansionOpportunityCount--;
}
if (is<RenderRubyBase>(*this) && !expansionOpportunityCount)
textAlign = CENTER;
updateLogicalWidthForAlignment(textAlign, lineBox, trailingSpaceRun, logicalLeft, totalLogicalWidth, availableLogicalWidth, expansionOpportunityCount);
computeExpansionForJustifiedText(firstRun, trailingSpaceRun, expansionOpportunities, expansionOpportunityCount, totalLogicalWidth, availableLogicalWidth);
return run;
}
void RenderBlockFlow::removeInlineBox(BidiRun& run, const RootInlineBox& rootLineBox) const
{
auto* inlineBox = run.box();
#if !ASSERT_DISABLED
auto* inlineParent = inlineBox->parent();
while (inlineParent && inlineParent != &rootLineBox) {
ASSERT(!inlineParent->isDirty());
inlineParent = inlineParent->parent();
}
ASSERT(!rootLineBox.isDirty());
#endif
auto* parent = inlineBox->parent();
inlineBox->removeFromParent();
auto& renderer = run.renderer();
if (is<RenderText>(renderer))
downcast<RenderText>(renderer).removeTextBox(downcast<InlineTextBox>(*inlineBox));
delete inlineBox;
run.setBox(nullptr);
// removeFromParent() unnecessarily dirties the ancestor subtree.
auto* ancestor = parent;
while (ancestor) {
ancestor->markDirty(false);
if (ancestor == &rootLineBox)
break;
ancestor = ancestor->parent();
}
}
void RenderBlockFlow::computeBlockDirectionPositionsForLine(RootInlineBox* lineBox, BidiRun* firstRun, GlyphOverflowAndFallbackFontsMap& textBoxDataMap,
VerticalPositionCache& verticalPositionCache)
{
setLogicalHeight(lineBox->alignBoxesInBlockDirection(logicalHeight(), textBoxDataMap, verticalPositionCache));
// Now make sure we place replaced render objects correctly.
for (auto* run = firstRun; run; run = run->next()) {
ASSERT(run->box());
if (!run->box())
continue; // Skip runs with no line boxes.
// Align positioned boxes with the top of the line box. This is
// a reasonable approximation of an appropriate y position.
auto& renderer = run->renderer();
if (renderer.isOutOfFlowPositioned())
run->box()->setLogicalTop(logicalHeight());
// Position is used to properly position both replaced elements and
// to update the static normal flow x/y of positioned elements.
bool inlineBoxIsRedundant = false;
if (is<RenderText>(renderer)) {
auto& inlineTextBox = downcast<InlineTextBox>(*run->box());
downcast<RenderText>(renderer).positionLineBox(inlineTextBox);
inlineBoxIsRedundant = !inlineTextBox.len();
} else if (is<RenderBox>(renderer)) {
downcast<RenderBox>(renderer).positionLineBox(downcast<InlineElementBox>(*run->box()));
inlineBoxIsRedundant = renderer.isOutOfFlowPositioned();
} else if (is<RenderLineBreak>(renderer))
downcast<RenderLineBreak>(renderer).replaceInlineBoxWrapper(downcast<InlineElementBox>(*run->box()));
// Check if we need to keep this box on the line at all.
if (inlineBoxIsRedundant)
removeInlineBox(*run, *lineBox);
}
}
static inline bool isCollapsibleSpace(UChar character, const RenderText& renderer)
{
if (character == ' ' || character == '\t' || character == softHyphen)
return true;
if (character == '\n')
return !renderer.style().preserveNewline();
if (character == noBreakSpace)
return renderer.style().nbspMode() == SPACE;
return false;
}
template <typename CharacterType>
static inline int findFirstTrailingSpace(const RenderText& lastText, const CharacterType* characters, int start, int stop)
{
int firstSpace = stop;
while (firstSpace > start) {
UChar current = characters[firstSpace - 1];
if (!isCollapsibleSpace(current, lastText))
break;
firstSpace--;
}
return firstSpace;
}
inline BidiRun* RenderBlockFlow::handleTrailingSpaces(BidiRunList<BidiRun>& bidiRuns, BidiContext* currentContext)
{
if (!bidiRuns.runCount()
|| !bidiRuns.logicallyLastRun()->renderer().style().breakOnlyAfterWhiteSpace()
|| !bidiRuns.logicallyLastRun()->renderer().style().autoWrap())
return nullptr;
BidiRun* trailingSpaceRun = bidiRuns.logicallyLastRun();
const RenderObject& lastObject = trailingSpaceRun->renderer();
if (!is<RenderText>(lastObject))
return nullptr;
const RenderText& lastText = downcast<RenderText>(lastObject);