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

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

Issue 198013006: Patch proposal (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Add a few more test cases to first-letter-punctuation.html and update expectations Created 6 years, 9 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
« no previous file with comments | « LayoutTests/platform/win/fast/css/first-letter-punctuation-expected.txt ('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) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2007 David Smith (catfish.man@gmail.com) 4 * (C) 2007 David Smith (catfish.man@gmail.com)
5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved. 5 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserved.
6 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 6 * Copyright (C) Research In Motion Limited 2010. All rights reserved.
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 4009 matching lines...) Expand 10 before | Expand all | Expand 10 after
4020 static inline bool isPunctuationForFirstLetter(UChar c) 4020 static inline bool isPunctuationForFirstLetter(UChar c)
4021 { 4021 {
4022 CharCategory charCategory = category(c); 4022 CharCategory charCategory = category(c);
4023 return charCategory == Punctuation_Open 4023 return charCategory == Punctuation_Open
4024 || charCategory == Punctuation_Close 4024 || charCategory == Punctuation_Close
4025 || charCategory == Punctuation_InitialQuote 4025 || charCategory == Punctuation_InitialQuote
4026 || charCategory == Punctuation_FinalQuote 4026 || charCategory == Punctuation_FinalQuote
4027 || charCategory == Punctuation_Other; 4027 || charCategory == Punctuation_Other;
4028 } 4028 }
4029 4029
4030 static inline bool shouldSkipForFirstLetter(UChar c) 4030 static inline bool isSpaceForFirstLetter(UChar c)
4031 { 4031 {
4032 return isSpaceOrNewline(c) || c == noBreakSpace || isPunctuationForFirstLett er(c); 4032 return isSpaceOrNewline(c) || c == noBreakSpace;
4033 } 4033 }
4034 4034
4035 static inline RenderObject* findFirstLetterBlock(RenderBlock* start) 4035 static inline RenderObject* findFirstLetterBlock(RenderBlock* start)
4036 { 4036 {
4037 RenderObject* firstLetterBlock = start; 4037 RenderObject* firstLetterBlock = start;
4038 while (true) { 4038 while (true) {
4039 // We include isRenderButton in these two checks because buttons are 4039 // We include isRenderButton in these two checks because buttons are
4040 // implemented using flex box but should still support first-letter. 4040 // implemented using flex box but should still support first-letter.
4041 // The flex box spec requires that flex box does not support 4041 // The flex box spec requires that flex box does not support
4042 // first-letter, though. 4042 // first-letter, though.
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
4101 4101
4102 for (RenderObject* genChild = firstLetter->firstChild(); genChild; genChild = genChild->nextSibling()) { 4102 for (RenderObject* genChild = firstLetter->firstChild(); genChild; genChild = genChild->nextSibling()) {
4103 if (genChild->isText()) 4103 if (genChild->isText())
4104 genChild->setStyle(pseudoStyle); 4104 genChild->setStyle(pseudoStyle);
4105 } 4105 }
4106 } 4106 }
4107 4107
4108 static inline unsigned firstLetterLength(const String& text) 4108 static inline unsigned firstLetterLength(const String& text)
4109 { 4109 {
4110 unsigned length = 0; 4110 unsigned length = 0;
4111 unsigned textLength = text.length();
4111 4112
4112 // Account for leading spaces and punctuation. 4113 // Account for leading spaces first.
4113 while (length < text.length() && shouldSkipForFirstLetter((text)[length])) 4114 while (length < textLength && isSpaceForFirstLetter(text[length]))
4114 length++; 4115 length++;
4115 4116
4116 // Bail if we didn't find a letter 4117 // Now account for leading punctuation.
4117 if (text.length() && length == text.length()) 4118 while (length < textLength && isPunctuationForFirstLetter(text[length]))
4119 length++;
4120
4121 // Bail if we didn't find a letter before the end of the text or before a sp ace.
4122 if (isSpaceForFirstLetter(text[length]) || (textLength && length == textLeng th))
4118 return 0; 4123 return 0;
4119 4124
4120 // Account for first letter. 4125 // Account the next character for first letter.
4121 length++; 4126 length++;
4122 4127
4123 // Keep looking for whitespace and allowed punctuation, but avoid 4128 // Keep looking allowed punctuation for the :first-letter.
4124 // accumulating just whitespace into the :first-letter. 4129 for (unsigned scanLength = length; scanLength < textLength; ++scanLength) {
4125 for (unsigned scanLength = length; scanLength < text.length(); ++scanLength) { 4130 UChar c = text[scanLength];
4126 UChar c = (text)[scanLength];
4127 4131
4128 if (!shouldSkipForFirstLetter(c)) 4132 if (!isPunctuationForFirstLetter(c))
4129 break; 4133 break;
4130 4134
4131 if (isPunctuationForFirstLetter(c)) 4135 length = scanLength + 1;
4132 length = scanLength + 1;
4133 } 4136 }
4134 4137
4135 // FIXME: If text.length() is 0, length may still be 1! 4138 // FIXME: If textLength is 0, length may still be 1!
4136 return length; 4139 return length;
4137 } 4140 }
4138 4141
4139 void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, Rend erObject* currentChild, unsigned length) 4142 void RenderBlock::createFirstLetterRenderer(RenderObject* firstLetterBlock, Rend erObject* currentChild, unsigned length)
4140 { 4143 {
4141 ASSERT(length && currentChild->isText()); 4144 ASSERT(length && currentChild->isText());
4142 4145
4143 RenderObject* firstLetterContainer = currentChild->parent(); 4146 RenderObject* firstLetterContainer = currentChild->parent();
4144 RenderStyle* pseudoStyle = styleForFirstLetter(firstLetterBlock, firstLetter Container); 4147 RenderStyle* pseudoStyle = styleForFirstLetter(firstLetterBlock, firstLetter Container);
4145 RenderObject* firstLetter = 0; 4148 RenderObject* firstLetter = 0;
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after
5021 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render Object* obj) const 5024 void RenderBlock::showLineTreeAndMark(const InlineBox* markedBox1, const char* m arkedLabel1, const InlineBox* markedBox2, const char* markedLabel2, const Render Object* obj) const
5022 { 5025 {
5023 showRenderObject(); 5026 showRenderObject();
5024 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box()) 5027 for (const RootInlineBox* root = firstRootBox(); root; root = root->nextRoot Box())
5025 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1); 5028 root->showLineTreeAndMark(markedBox1, markedLabel1, markedBox2, markedLa bel2, obj, 1);
5026 } 5029 }
5027 5030
5028 #endif 5031 #endif
5029 5032
5030 } // namespace WebCore 5033 } // namespace WebCore
OLDNEW
« no previous file with comments | « LayoutTests/platform/win/fast/css/first-letter-punctuation-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698