Changeset 86739 in webkit
- Timestamp:
- May 18, 2011 12:19:48 AM (13 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r86737 r86739 1 2011-05-17 Nikolas Zimmermann <nzimmermann@rim.com> 2 3 Reviewed by Dirk Schulze. 4 5 Refactor TextRun creation 6 https://bugs.webkit.org/show_bug.cgi?id=60255 7 8 Add constructTextRun() methods to RenderBlock/InlineTextBox and use it in various places in rendering/. 9 The long-term goal is to remove the ugly eight parameters catch-it-all TextRun constructor, and 10 replace it with explicit setters/getters. To avoid expanding dozens of callsites, when removing 11 the catch-it-all constructor, these helper functions are introduced, which hide the details of 12 creating a TextRun. 13 14 Furthermore it will be used to remove the platform layering violation, that TextRun stores 15 RenderObject pointers for the sake of SVG Fonts support, see bug 60254. 16 17 No change in functionaliy, no new tests. 18 19 * rendering/EllipsisBox.cpp: 20 (WebCore::EllipsisBox::paint): 21 (WebCore::EllipsisBox::selectionRect): 22 (WebCore::EllipsisBox::paintSelection): 23 * rendering/InlineTextBox.cpp: 24 (WebCore::InlineTextBox::selectionRect): 25 (WebCore::InlineTextBox::paint): 26 (WebCore::InlineTextBox::paintSelection): 27 (WebCore::InlineTextBox::paintCompositionBackground): 28 (WebCore::InlineTextBox::paintSpellingOrGrammarMarker): 29 (WebCore::InlineTextBox::paintTextMatchMarker): 30 (WebCore::InlineTextBox::computeRectForReplacementMarker): 31 (WebCore::InlineTextBox::offsetForPosition): 32 (WebCore::InlineTextBox::positionForOffset): 33 (WebCore::InlineTextBox::constructTextRun): 34 * rendering/InlineTextBox.h: 35 * rendering/RenderBlock.cpp: 36 (WebCore::RenderBlock::constructTextRunAllowTrailingExpansion): 37 * rendering/RenderBlock.h: 38 * rendering/RenderEmbeddedObject.cpp: 39 (WebCore::RenderEmbeddedObject::getReplacementTextGeometry): 40 * rendering/RenderFileUploadControl.cpp: 41 (WebCore::RenderFileUploadControl::paintObject): 42 (WebCore::RenderFileUploadControl::computePreferredLogicalWidths): 43 * rendering/RenderImage.cpp: 44 (WebCore::RenderImage::setImageSizeForAltText): 45 (WebCore::RenderImage::paintReplaced): 46 * rendering/RenderListBox.cpp: 47 (WebCore::RenderListBox::updateFromElement): 48 * rendering/RenderTextControl.cpp: 49 (WebCore::RenderTextControl::getAvgCharWidth): 50 1 51 2011-05-17 Jeremy Noble <jer.noble@apple.com> 2 52 -
trunk/Source/WebCore/rendering/EllipsisBox.cpp
r86705 r86739 25 25 #include "HitTestResult.h" 26 26 #include "PaintInfo.h" 27 #include "RenderBlock.h" 27 28 #include "RootInlineBox.h" 28 29 #include "TextRun.h" … … 53 54 } 54 55 55 const String& str = m_str; 56 // FIXME: Why is this alwasy LTR? 57 context->drawText(style->font(), TextRun(str.characters(), str.length(), false, 0, 0, TextRun::AllowTrailingExpansion, LTR, style->visuallyOrdered()), IntPoint(m_x + tx, m_y + ty + style->fontMetrics().ascent())); 56 // FIXME: Why is this always LTR? Fix by passing correct text run flags below. 57 context->drawText(style->font(), RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + style->fontMetrics().ascent())); 58 58 59 59 // Restore the regular fill color. … … 76 76 RenderStyle* style = m_renderer->style(m_firstLine); 77 77 const Font& f = style->font(); 78 // FIXME: Why is this always LTR? 79 return enclosingIntRect(f.selectionRectForText(TextRun(m_str.characters(), m_str.length(), false, 0, 0, TextRun::AllowTrailingExpansion, LTR, style->visuallyOrdered()), 80 IntPoint(m_x + tx, m_y + ty + root()->selectionTop()), root()->selectionHeight())); 78 // FIXME: Why is this always LTR? Fix by passing correct text run flags below. 79 return enclosingIntRect(f.selectionRectForText(RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + root()->selectionTop()), root()->selectionHeight())); 81 80 } 82 81 … … 97 96 int h = root()->selectionHeight(); 98 97 context->clip(IntRect(m_x + tx, y + ty, m_logicalWidth, h)); 99 // FIXME: Why is this always LTR? 100 context->drawHighlightForText(font, TextRun(m_str.characters(), m_str.length(), false, 0, 0, TextRun::AllowTrailingExpansion, LTR, style->visuallyOrdered()), 101 IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace()); 98 // FIXME: Why is this always LTR? Fix by passing correct text run flags below. 99 context->drawHighlightForText(font, RenderBlock::constructTextRunAllowTrailingExpansion(m_str, style), IntPoint(m_x + tx, m_y + ty + y), h, c, style->colorSpace()); 102 100 } 103 101 -
trunk/Source/WebCore/rendering/InlineTextBox.cpp
r86705 r86739 43 43 #include "RenderTheme.h" 44 44 #include "Text.h" 45 #include "TextRun.h" 45 46 #include "break_lines.h" 46 47 #include <wtf/AlwaysInline.h> … … 160 161 } 161 162 162 typedef Vector<UChar, 256> BufferForAppendingHyphen;163 164 163 static void adjustCharactersAndLengthForHyphen(BufferForAppendingHyphen& charactersWithHyphen, RenderStyle* style, const UChar*& characters, int& length) 165 164 { … … 186 185 const Font& f = styleToUse->font(); 187 186 188 const UChar* characters = textObj->text()->characters() + m_start;189 int len = m_len;190 187 BufferForAppendingHyphen charactersWithHyphen; 191 if (ePos == len && hasHyphen()) { 192 adjustCharactersAndLengthForHyphen(charactersWithHyphen, styleToUse, characters, len); 193 ePos = len; 194 } 195 196 IntRect r = enclosingIntRect(f.selectionRectForText(TextRun(characters, len, textObj->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride), 197 FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos)); 188 bool respectHyphen = ePos == m_len && hasHyphen(); 189 TextRun textRun = constructTextRun(styleToUse, respectHyphen ? &charactersWithHyphen : 0); 190 if (respectHyphen) 191 endPos = textRun.length(); 192 193 IntRect r = enclosingIntRect(f.selectionRectForText(textRun, FloatPoint(logicalLeft(), selTop), selHeight, sPos, ePos)); 198 194 199 195 int logicalWidth = r.width(); … … 648 644 649 645 BufferForAppendingHyphen charactersWithHyphen; 646 TextRun textRun = constructTextRun(styleToUse, characters, length, hasHyphen() ? &charactersWithHyphen : 0); 650 647 if (hasHyphen()) 651 adjustCharactersAndLengthForHyphen(charactersWithHyphen, styleToUse, characters, length); 652 653 TextRun textRun(characters, length, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride || styleToUse->visuallyOrdered()); 648 length = textRun.length(); 654 649 655 650 int sPos = 0; … … 813 808 814 809 BufferForAppendingHyphen charactersWithHyphen; 815 if (ePos == length && hasHyphen()) {816 adjustCharactersAndLengthForHyphen(charactersWithHyphen, style, characters, length);817 ePos = length;818 }810 bool respectHyphen = ePos == length && hasHyphen(); 811 TextRun textRun = constructTextRun(style, characters, length, respectHyphen ? &charactersWithHyphen : 0); 812 if (respectHyphen) 813 ePos = textRun.length(); 819 814 820 815 int deltaY = renderer()->style()->isFlippedLinesWritingMode() ? selectionBottom() - logicalBottom() : logicalTop() - selectionTop(); … … 828 823 context->clip(clipRect); 829 824 830 context->drawHighlightForText(font, TextRun(characters, length, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), 831 direction(), m_dirOverride || style->visuallyOrdered()), 832 localOrigin, selHeight, c, style->colorSpace(), sPos, ePos); 825 context->drawHighlightForText(font, textRun, localOrigin, selHeight, c, style->colorSpace(), sPos, ePos); 833 826 } 834 827 … … 851 844 int selHeight = selectionHeight(); 852 845 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); 853 context->drawHighlightForText(font, TextRun(textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), 854 direction(), m_dirOverride || style->visuallyOrdered()), 855 localOrigin, selHeight, c, style->colorSpace(), sPos, ePos); 846 context->drawHighlightForText(font, constructTextRun(style), localOrigin, selHeight, c, style->colorSpace(), sPos, ePos); 856 847 } 857 848 … … 1011 1002 int selHeight = selectionHeight(); 1012 1003 FloatPoint startPoint(boxOrigin.x(), boxOrigin.y() - deltaY); 1013 TextRun run (textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered());1014 1004 TextRun run = constructTextRun(style); 1005 1015 1006 // FIXME: Convert the document markers to float rects. 1016 1007 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, startPoint, selHeight, startPosition, endPosition)); … … 1056 1047 int sPos = max(marker.startOffset - m_start, (unsigned)0); 1057 1048 int ePos = min(marker.endOffset - m_start, (unsigned)m_len); 1058 TextRun run (textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered());1059 1049 TextRun run = constructTextRun(style); 1050 1060 1051 // Always compute and store the rect associated with this marker. The computed rect is in absolute coordinates. 1061 1052 IntRect markerRect = enclosingIntRect(font.selectionRectForText(run, IntPoint(m_x, selectionTop()), selHeight, sPos, ePos)); … … 1083 1074 int sPos = max(marker.startOffset - m_start, (unsigned)0); 1084 1075 int ePos = min(marker.endOffset - m_start, (unsigned)m_len); 1085 TextRun run (textRenderer()->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered());1076 TextRun run = constructTextRun(style); 1086 1077 IntPoint startPoint = IntPoint(m_x, y); 1087 1078 … … 1243 1234 RenderStyle* style = text->style(m_firstLine); 1244 1235 const Font* f = &style->font(); 1245 int offset = f->offsetForPosition(TextRun(textRenderer()->text()->characters() + m_start, m_len, 1246 textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered()), 1247 lineOffset - logicalLeft(), includePartialGlyphs); 1236 int offset = f->offsetForPosition(constructTextRun(style), lineOffset - logicalLeft(), includePartialGlyphs); 1248 1237 if (blockIsInOppositeDirection && (!offset || offset == m_len)) 1249 1238 return !offset ? m_len : 0; … … 1260 1249 1261 1250 RenderText* text = toRenderText(renderer()); 1262 const Font& f = text->style(m_firstLine)->font(); 1251 RenderStyle* styleToUse = text->style(m_firstLine); 1252 ASSERT(styleToUse); 1253 const Font& f = styleToUse->font(); 1263 1254 int from = !isLeftToRightDirection() ? offset - m_start : 0; 1264 1255 int to = !isLeftToRightDirection() ? m_len : offset - m_start; 1265 1256 // FIXME: Do we need to add rightBearing here? 1266 return f.selectionRectForText(TextRun(text->text()->characters() + m_start, m_len, textRenderer()->allowTabs(), textPos(), m_expansion, expansionBehavior(), direction(), m_dirOverride), 1267 IntPoint(logicalLeft(), 0), 0, from, to).maxX(); 1257 return f.selectionRectForText(constructTextRun(styleToUse), IntPoint(logicalLeft(), 0), 0, from, to).maxX(); 1268 1258 } 1269 1259 … … 1290 1280 // Offsets at the end are "in" for normal boxes (but the caller has to check affinity). 1291 1281 return true; 1282 } 1283 1284 TextRun InlineTextBox::constructTextRun(RenderStyle* style, BufferForAppendingHyphen* charactersWithHyphen) const 1285 { 1286 ASSERT(style); 1287 1288 RenderText* textRenderer = this->textRenderer(); 1289 ASSERT(textRenderer); 1290 ASSERT(textRenderer->characters()); 1291 1292 return constructTextRun(style, textRenderer->characters() + start(), len(), charactersWithHyphen); 1293 } 1294 1295 TextRun InlineTextBox::constructTextRun(RenderStyle* style, const UChar* characters, int length, BufferForAppendingHyphen* charactersWithHyphen) const 1296 { 1297 ASSERT(style); 1298 1299 RenderText* textRenderer = this->textRenderer(); 1300 ASSERT(textRenderer); 1301 1302 if (charactersWithHyphen) 1303 adjustCharactersAndLengthForHyphen(*charactersWithHyphen, style, characters, length); 1304 1305 // FIXME: Remove TextRuns all-in-one-constructor and use explicit setters here. 1306 return TextRun(characters, length, textRenderer->allowTabs(), textPos(), expansion(), expansionBehavior(), direction(), m_dirOverride || style->visuallyOrdered()); 1292 1307 } 1293 1308 -
trunk/Source/WebCore/rendering/InlineTextBox.h
r86705 r86739 35 35 const unsigned short cNoTruncation = USHRT_MAX; 36 36 const unsigned short cFullTruncation = USHRT_MAX - 1; 37 typedef Vector<UChar, 256> BufferForAppendingHyphen; 37 38 38 39 // Helper functions shared by InlineTextBox / SVGRootInlineBox … … 98 99 int selectionBottom(); 99 100 int selectionHeight(); 101 102 TextRun constructTextRun(RenderStyle*, BufferForAppendingHyphen* = 0) const; 103 TextRun constructTextRun(RenderStyle*, const UChar*, int length, BufferForAppendingHyphen* = 0) const; 100 104 101 105 public: -
trunk/Source/WebCore/rendering/RenderBlock.cpp
r86705 r86739 6317 6317 } 6318 6318 6319 TextRun RenderBlock::constructTextRunAllowTrailingExpansion(const UChar* characters, int length, RenderStyle* style, TextRunFlags flags) 6320 { 6321 ASSERT(style); 6322 6323 TextDirection textDirection = LTR; 6324 bool directionalOverride = style->visuallyOrdered(); 6325 if (flags != DefaultTextRunFlags) { 6326 if (flags & RespectDirection) 6327 textDirection = style->direction(); 6328 if (flags & RespectDirectionOverride) 6329 directionalOverride |= style->unicodeBidi() == Override; 6330 } 6331 6332 // FIXME: Remove TextRuns all-in-one-constructor and use explicit setters here. 6333 return TextRun(characters, length, false, 0, 0, TextRun::AllowTrailingExpansion, textDirection, directionalOverride); 6334 } 6335 6336 TextRun RenderBlock::constructTextRunAllowTrailingExpansion(const String& string, RenderStyle* style, TextRunFlags flags) 6337 { 6338 return constructTextRunAllowTrailingExpansion(string.characters(), string.length(), style, flags); 6339 } 6319 6340 6320 6341 #ifndef NDEBUG -
trunk/Source/WebCore/rendering/RenderBlock.h
r86705 r86739 56 56 enum CaretType { CursorCaret, DragCaret }; 57 57 58 enum TextRunFlag { 59 DefaultTextRunFlags = 0, 60 RespectDirection = 1 << 0, 61 RespectDirectionOverride = 1 << 1 62 }; 63 64 typedef unsigned TextRunFlags; 65 58 66 class RenderBlock : public RenderBox { 59 67 public: … … 161 169 162 170 static void appendRunsForObject(BidiRunList<BidiRun>&, int start, int end, RenderObject*, InlineBidiResolver&); 171 172 static TextRun constructTextRunAllowTrailingExpansion(const String&, RenderStyle*, TextRunFlags = DefaultTextRunFlags); 173 static TextRun constructTextRunAllowTrailingExpansion(const UChar*, int length, RenderStyle*, TextRunFlags = DefaultTextRunFlags); 163 174 164 175 ColumnInfo* columnInfo() const; -
trunk/Source/WebCore/rendering/RenderEmbeddedObject.cpp
r84504 r86739 198 198 font.update(0); 199 199 200 run = TextRun(m_replacementText .characters(), m_replacementText.length());200 run = TextRun(m_replacementText); 201 201 textWidth = font.width(run); 202 202 -
trunk/Source/WebCore/rendering/RenderFileUploadControl.cpp
r85143 r86739 222 222 if (paintInfo.phase == PaintPhaseForeground) { 223 223 const String& displayedFilename = fileTextValue(); 224 unsigned length = displayedFilename.length(); 225 const UChar* string = displayedFilename.characters(); 226 TextRun textRun(string, length, false, 0, 0, TextRun::AllowTrailingExpansion, style()->direction(), style()->unicodeBidi() == Override); 227 224 TextRun textRun = constructTextRunAllowTrailingExpansion(displayedFilename, style(), RespectDirection | RespectDirectionOverride); 225 228 226 // Determine where the filename should be placed 229 227 int contentLeft = tx + borderLeft() + paddingLeft(); … … 271 269 m_maxPreferredLogicalWidth = 0; 272 270 273 if (style()->width().isFixed() && style()->width().value() > 0) 274 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style()->width().value()); 271 RenderStyle* style = this->style(); 272 ASSERT(style); 273 274 if (style->width().isFixed() && style->width().value() > 0) 275 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth = computeContentBoxLogicalWidth(style->width().value()); 275 276 else { 276 277 // Figure out how big the filename space needs to be for a given number of characters 277 278 // (using "0" as the nominal character). 278 279 const UChar ch = '0'; 279 float charWidth = style ()->font().width(TextRun(&ch, 1, false, 0, 0, TextRun::AllowTrailingExpansion));280 float charWidth = style->font().width(constructTextRunAllowTrailingExpansion(String(&ch, 1), style)); 280 281 m_maxPreferredLogicalWidth = (int)ceilf(charWidth * defaultWidthNumChars); 281 282 } 282 283 283 if (style ()->minWidth().isFixed() && style()->minWidth().value() > 0) {284 m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style ()->minWidth().value()));285 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style ()->minWidth().value()));286 } else if (style ()->width().isPercent() || (style()->width().isAuto() && style()->height().isPercent()))284 if (style->minWidth().isFixed() && style->minWidth().value() > 0) { 285 m_maxPreferredLogicalWidth = max(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style->minWidth().value())); 286 m_minPreferredLogicalWidth = max(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style->minWidth().value())); 287 } else if (style->width().isPercent() || (style->width().isAuto() && style->height().isPercent())) 287 288 m_minPreferredLogicalWidth = 0; 288 289 else 289 290 m_minPreferredLogicalWidth = m_maxPreferredLogicalWidth; 290 291 291 if (style ()->maxWidth().isFixed() && style()->maxWidth().value() != undefinedLength) {292 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style ()->maxWidth().value()));293 m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style ()->maxWidth().value()));292 if (style->maxWidth().isFixed() && style->maxWidth().value() != undefinedLength) { 293 m_maxPreferredLogicalWidth = min(m_maxPreferredLogicalWidth, computeContentBoxLogicalWidth(style->maxWidth().value())); 294 m_minPreferredLogicalWidth = min(m_minPreferredLogicalWidth, computeContentBoxLogicalWidth(style->maxWidth().value())); 294 295 } 295 296 -
trunk/Source/WebCore/rendering/RenderImage.cpp
r86705 r86739 105 105 if (!m_altText.isEmpty()) { 106 106 const Font& font = style()->font(); 107 IntSize textSize(min(font.width(TextRun(m_altText .characters(), m_altText.length())), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight));107 IntSize textSize(min(font.width(TextRun(m_altText)), maxAltTextWidth), min(font.fontMetrics().height(), maxAltTextHeight)); 108 108 imageSize = imageSize.expandedTo(textSize); 109 109 } … … 287 287 // Only draw the alt text if it'll fit within the content box, 288 288 // and only if it fits above the error image. 289 TextRun textRun(text .characters(), text.length());289 TextRun textRun(text); 290 290 int textWidth = font.width(textRun); 291 291 if (errorPictureDrawn) { -
trunk/Source/WebCore/rendering/RenderListBox.cpp
r86705 r86739 121 121 if (!text.isEmpty()) { 122 122 // FIXME: Why is this always LTR? Can't text direction affect the width? 123 float textWidth = itemFont.width( TextRun(text.impl(), false, 0, 0, TextRun::AllowTrailingExpansion, LTR));123 float textWidth = itemFont.width(constructTextRunAllowTrailingExpansion(text, style())); 124 124 width = max(width, textWidth); 125 125 } -
trunk/Source/WebCore/rendering/RenderTextControl.cpp
r85864 r86739 543 543 544 544 const UChar ch = '0'; 545 return style()->font().width( TextRun(&ch, 1, false, 0, 0, TextRun::AllowTrailingExpansion));545 return style()->font().width(constructTextRunAllowTrailingExpansion(String(&ch, 1), style())); 546 546 } 547 547
Note: See TracChangeset
for help on using the changeset viewer.