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

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

Issue 182413005: Return refererence from InlineBox::root() (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: re-upload because previous patch didn't upload correctly. 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
OLDNEW
1 /* 1 /*
2 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All r ights 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 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 return 0; 117 return 0;
118 if (renderer().isBR()) 118 if (renderer().isBR())
119 return toRenderBR(renderer()).lineHeight(isFirstLineStyle()); 119 return toRenderBR(renderer()).lineHeight(isFirstLineStyle());
120 if (parent()->renderer() == renderer().parent()) 120 if (parent()->renderer() == renderer().parent())
121 return parent()->lineHeight(); 121 return parent()->lineHeight();
122 return toRenderBoxModelObject(renderer().parent())->lineHeight(isFirstLineSt yle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine) ; 122 return toRenderBoxModelObject(renderer().parent())->lineHeight(isFirstLineSt yle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine) ;
123 } 123 }
124 124
125 LayoutUnit InlineTextBox::selectionTop() 125 LayoutUnit InlineTextBox::selectionTop()
126 { 126 {
127 return root()->selectionTop(); 127 return root().selectionTop();
128 } 128 }
129 129
130 LayoutUnit InlineTextBox::selectionBottom() 130 LayoutUnit InlineTextBox::selectionBottom()
131 { 131 {
132 return root()->selectionBottom(); 132 return root().selectionBottom();
133 } 133 }
134 134
135 LayoutUnit InlineTextBox::selectionHeight() 135 LayoutUnit InlineTextBox::selectionHeight()
136 { 136 {
137 return root()->selectionHeight(); 137 return root().selectionHeight();
138 } 138 }
139 139
140 bool InlineTextBox::isSelected(int startPos, int endPos) const 140 bool InlineTextBox::isSelected(int startPos, int endPos) const
141 { 141 {
142 int sPos = max(startPos - m_start, 0); 142 int sPos = max(startPos - m_start, 0);
143 // The position after a hard line break is considered to be past its end. 143 // The position after a hard line break is considered to be past its end.
144 // See the corresponding code in InlineTextBox::selectionState. 144 // See the corresponding code in InlineTextBox::selectionState.
145 int ePos = min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1)); 145 int ePos = min(endPos - m_start, int(m_len) + (isLineBreak() ? 0 : 1));
146 return (sPos < ePos); 146 return (sPos < ePos);
147 } 147 }
(...skipping 19 matching lines...) Expand all
167 else if (end) 167 else if (end)
168 state = RenderObject::SelectionEnd; 168 state = RenderObject::SelectionEnd;
169 else if ((state == RenderObject::SelectionEnd || startPos < m_start) && 169 else if ((state == RenderObject::SelectionEnd || startPos < m_start) &&
170 (state == RenderObject::SelectionStart || endPos > lastSelectab le)) 170 (state == RenderObject::SelectionStart || endPos > lastSelectab le))
171 state = RenderObject::SelectionInside; 171 state = RenderObject::SelectionInside;
172 else if (state == RenderObject::SelectionBoth) 172 else if (state == RenderObject::SelectionBoth)
173 state = RenderObject::SelectionNone; 173 state = RenderObject::SelectionNone;
174 } 174 }
175 175
176 // If there are ellipsis following, make sure their selection is updated. 176 // If there are ellipsis following, make sure their selection is updated.
177 if (m_truncation != cNoTruncation && root()->ellipsisBox()) { 177 if (m_truncation != cNoTruncation && root().ellipsisBox()) {
178 EllipsisBox* ellipsis = root()->ellipsisBox(); 178 EllipsisBox* ellipsis = root().ellipsisBox();
179 if (state != RenderObject::SelectionNone) { 179 if (state != RenderObject::SelectionNone) {
180 int start, end; 180 int start, end;
181 selectionStartEnd(start, end); 181 selectionStartEnd(start, end);
182 // The ellipsis should be considered to be selected if the end of 182 // The ellipsis should be considered to be selected if the end of
183 // the selection is past the beginning of the truncation and the 183 // the selection is past the beginning of the truncation and the
184 // beginning of the selection is before or at the beginning of the 184 // beginning of the selection is before or at the beginning of the
185 // truncation. 185 // truncation.
186 ellipsis->setSelectionState(end >= m_truncation && start <= m_trunca tion ? 186 ellipsis->setSelectionState(end >= m_truncation && start <= m_trunca tion ?
187 RenderObject::SelectionInside : RenderObject::SelectionNone); 187 RenderObject::SelectionInside : RenderObject::SelectionNone);
188 } else 188 } else
(...skipping 649 matching lines...) Expand 10 before | Expand all | Expand 10 after
838 838
839 if (string.length() != static_cast<unsigned>(length) || m_start) 839 if (string.length() != static_cast<unsigned>(length) || m_start)
840 string.narrow(m_start, length); 840 string.narrow(m_start, length);
841 841
842 StringBuilder charactersWithHyphen; 842 StringBuilder charactersWithHyphen;
843 bool respectHyphen = ePos == length && hasHyphen(); 843 bool respectHyphen = ePos == length && hasHyphen();
844 TextRun textRun = constructTextRun(style, font, string, textRenderer().textL ength() - m_start, respectHyphen ? &charactersWithHyphen : 0); 844 TextRun textRun = constructTextRun(style, font, string, textRenderer().textL ength() - m_start, respectHyphen ? &charactersWithHyphen : 0);
845 if (respectHyphen) 845 if (respectHyphen)
846 ePos = textRun.length(); 846 ePos = textRun.length();
847 847
848 LayoutUnit selectionBottom = root()->selectionBottom(); 848 LayoutUnit selectionBottom = root().selectionBottom();
849 LayoutUnit selectionTop = root()->selectionTopAdjustedForPrecedingBlock(); 849 LayoutUnit selectionTop = root().selectionTopAdjustedForPrecedingBlock();
850 850
851 int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? se lectionBottom - logicalBottom() : logicalTop() - selectionTop); 851 int deltaY = roundToInt(renderer().style()->isFlippedLinesWritingMode() ? se lectionBottom - logicalBottom() : logicalTop() - selectionTop);
852 int selHeight = max(0, roundToInt(selectionBottom - selectionTop)); 852 int selHeight = max(0, roundToInt(selectionBottom - selectionTop));
853 853
854 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY); 854 FloatPoint localOrigin(boxOrigin.x(), boxOrigin.y() - deltaY);
855 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight)); 855 FloatRect clipRect(localOrigin, FloatSize(m_logicalWidth, selHeight));
856 alignSelectionRectToDevicePixels(clipRect); 856 alignSelectionRectToDevicePixels(clipRect);
857 857
858 context->clip(clipRect); 858 context->clip(clipRect);
859 859
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 // Compute the gap between the font and the underline. Use at least one 910 // Compute the gap between the font and the underline. Use at least one
911 // pixel gap, if underline is thick then use a bigger gap. 911 // pixel gap, if underline is thick then use a bigger gap.
912 const int gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f)); 912 const int gap = std::max<int>(1, ceilf(textDecorationThickness / 2.f));
913 913
914 // FIXME: We support only horizontal text for now. 914 // FIXME: We support only horizontal text for now.
915 switch (underlinePosition) { 915 switch (underlinePosition) {
916 case TextUnderlinePositionAuto: 916 case TextUnderlinePositionAuto:
917 return fontMetrics.ascent() + gap; // Position underline near the alphab etic baseline. 917 return fontMetrics.ascent() + gap; // Position underline near the alphab etic baseline.
918 case TextUnderlinePositionUnder: { 918 case TextUnderlinePositionUnder: {
919 // Position underline relative to the under edge of the lowest element's content box. 919 // Position underline relative to the under edge of the lowest element's content box.
920 const float offset = inlineTextBox->root()->maxLogicalTop() - inlineText Box->logicalTop(); 920 const float offset = inlineTextBox->root().maxLogicalTop() - inlineTextB ox->logicalTop();
921 if (offset > 0) 921 if (offset > 0)
922 return inlineTextBox->logicalHeight() + gap + offset; 922 return inlineTextBox->logicalHeight() + gap + offset;
923 return inlineTextBox->logicalHeight() + gap; 923 return inlineTextBox->logicalHeight() + gap;
924 } 924 }
925 } 925 }
926 926
927 ASSERT_NOT_REACHED(); 927 ASSERT_NOT_REACHED();
928 return fontMetrics.ascent() + gap; 928 return fontMetrics.ascent() + gap;
929 } 929 }
930 930
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
1395 { 1395 {
1396 return m_start + m_len; 1396 return m_start + m_len;
1397 } 1397 }
1398 1398
1399 float InlineTextBox::textPos() const 1399 float InlineTextBox::textPos() const
1400 { 1400 {
1401 // When computing the width of a text run, RenderBlock::computeInlineDirecti onPositionsForLine() doesn't include the actual offset 1401 // When computing the width of a text run, RenderBlock::computeInlineDirecti onPositionsForLine() doesn't include the actual offset
1402 // from the containing block edge in its measurement. textPos() should be co nsistent so the text are rendered in the same width. 1402 // from the containing block edge in its measurement. textPos() should be co nsistent so the text are rendered in the same width.
1403 if (logicalLeft() == 0) 1403 if (logicalLeft() == 0)
1404 return 0; 1404 return 0;
1405 return logicalLeft() - root()->logicalLeft(); 1405 return logicalLeft() - root().logicalLeft();
1406 } 1406 }
1407 1407
1408 int InlineTextBox::offsetForPosition(float lineOffset, bool includePartialGlyphs ) const 1408 int InlineTextBox::offsetForPosition(float lineOffset, bool includePartialGlyphs ) const
1409 { 1409 {
1410 if (isLineBreak()) 1410 if (isLineBreak())
1411 return 0; 1411 return 0;
1412 1412
1413 if (lineOffset - logicalLeft() > logicalWidth()) 1413 if (lineOffset - logicalLeft() > logicalWidth())
1414 return isLeftToRightDirection() ? len() : 0; 1414 return isLeftToRightDirection() ? len() : 0;
1415 if (lineOffset - logicalLeft() < 0) 1415 if (lineOffset - logicalLeft() < 0)
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
1554 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 1554 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
1555 const int rendererCharacterOffset = 24; 1555 const int rendererCharacterOffset = 24;
1556 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 1556 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
1557 fputc(' ', stderr); 1557 fputc(' ', stderr);
1558 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 1558 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
1559 } 1559 }
1560 1560
1561 #endif 1561 #endif
1562 1562
1563 } // namespace WebCore 1563 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698