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

Side by Side Diff: third_party/WebKit/Source/core/layout/line/InlineTextBox.cpp

Issue 1656743002: Removing more implicit LayoutUnit construction (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix additional test Created 4 years, 10 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 if (!isText() || !parent()) 113 if (!isText() || !parent())
114 return 0; 114 return 0;
115 if (parent()->lineLayoutItem() == lineLayoutItem().parent()) 115 if (parent()->lineLayoutItem() == lineLayoutItem().parent())
116 return parent()->baselinePosition(baselineType); 116 return parent()->baselinePosition(baselineType);
117 return LineLayoutBoxModel(lineLayoutItem().parent()).baselinePosition(baseli neType, isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, Posi tionOnContainingLine); 117 return LineLayoutBoxModel(lineLayoutItem().parent()).baselinePosition(baseli neType, isFirstLineStyle(), isHorizontal() ? HorizontalLine : VerticalLine, Posi tionOnContainingLine);
118 } 118 }
119 119
120 LayoutUnit InlineTextBox::lineHeight() const 120 LayoutUnit InlineTextBox::lineHeight() const
121 { 121 {
122 if (!isText() || !lineLayoutItem().parent()) 122 if (!isText() || !lineLayoutItem().parent())
123 return 0; 123 return LayoutUnit();
124 if (lineLayoutItem().isBR()) 124 if (lineLayoutItem().isBR())
125 return toLayoutBR(lineLayoutItem())->lineHeight(isFirstLineStyle()); 125 return LayoutUnit(toLayoutBR(lineLayoutItem())->lineHeight(isFirstLineSt yle()));
126 if (parent()->lineLayoutItem() == lineLayoutItem().parent()) 126 if (parent()->lineLayoutItem() == lineLayoutItem().parent())
127 return parent()->lineHeight(); 127 return parent()->lineHeight();
128 return LineLayoutBoxModel(lineLayoutItem().parent()).lineHeight(isFirstLineS tyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine ); 128 return LineLayoutBoxModel(lineLayoutItem().parent()).lineHeight(isFirstLineS tyle(), isHorizontal() ? HorizontalLine : VerticalLine, PositionOnContainingLine );
129 } 129 }
130 130
131 bool InlineTextBox::isSelected(int startPos, int endPos) const 131 bool InlineTextBox::isSelected(int startPos, int endPos) const
132 { 132 {
133 int sPos = std::max(startPos - m_start, 0); 133 int sPos = std::max(startPos - m_start, 0);
134 // The position after a hard line break is considered to be past its end. 134 // The position after a hard line break is considered to be past its end.
135 // See the corresponding code in InlineTextBox::selectionState. 135 // See the corresponding code in InlineTextBox::selectionState.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 if (sPos || ePos != static_cast<int>(m_len)) { 236 if (sPos || ePos != static_cast<int>(m_len)) {
237 r = LayoutRect(enclosingIntRect(font.selectionRectForText(textRun, Float Point(startingPoint), selHeight, sPos, ePos))); 237 r = LayoutRect(enclosingIntRect(font.selectionRectForText(textRun, Float Point(startingPoint), selHeight, sPos, ePos)));
238 } else { // Avoid computing the font width when the entire line box is selec ted as an optimization. 238 } else { // Avoid computing the font width when the entire line box is selec ted as an optimization.
239 // FIXME: the call to rawValue() below is temporary and should be remove d once the transition 239 // FIXME: the call to rawValue() below is temporary and should be remove d once the transition
240 // to LayoutUnit-based types is complete (crbug.com/321237) 240 // to LayoutUnit-based types is complete (crbug.com/321237)
241 r = LayoutRect(enclosingIntRect(LayoutRect(startingPoint, LayoutSize(m_l ogicalWidth, selHeight)))); 241 r = LayoutRect(enclosingIntRect(LayoutRect(startingPoint, LayoutSize(m_l ogicalWidth, selHeight))));
242 } 242 }
243 243
244 LayoutUnit logicalWidth = r.width(); 244 LayoutUnit logicalWidth = r.width();
245 if (r.x() > logicalRight()) 245 if (r.x() > logicalRight())
246 logicalWidth = 0; 246 logicalWidth = LayoutUnit();
247 else if (r.maxX() > logicalRight()) 247 else if (r.maxX() > logicalRight())
248 logicalWidth = logicalRight() - r.x(); 248 logicalWidth = logicalRight() - r.x();
249 249
250 LayoutPoint topPoint; 250 LayoutPoint topPoint;
251 LayoutUnit width; 251 LayoutUnit width;
252 LayoutUnit height; 252 LayoutUnit height;
253 if (isHorizontal()) { 253 if (isHorizontal()) {
254 topPoint = LayoutPoint(r.x(), selTop); 254 topPoint = LayoutPoint(r.x(), selTop);
255 width = logicalWidth; 255 width = logicalWidth;
256 height = selHeight; 256 height = selHeight;
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 305
306 void InlineTextBox::clearTruncation() 306 void InlineTextBox::clearTruncation()
307 { 307 {
308 setTruncation(cNoTruncation); 308 setTruncation(cNoTruncation);
309 } 309 }
310 310
311 LayoutUnit InlineTextBox::placeEllipsisBox(bool flowIsLTR, LayoutUnit visibleLef tEdge, LayoutUnit visibleRightEdge, LayoutUnit ellipsisWidth, LayoutUnit &trunca tedWidth, bool& foundBox) 311 LayoutUnit InlineTextBox::placeEllipsisBox(bool flowIsLTR, LayoutUnit visibleLef tEdge, LayoutUnit visibleRightEdge, LayoutUnit ellipsisWidth, LayoutUnit &trunca tedWidth, bool& foundBox)
312 { 312 {
313 if (foundBox) { 313 if (foundBox) {
314 setTruncation(cFullTruncation); 314 setTruncation(cFullTruncation);
315 return -1; 315 return LayoutUnit(-1);
316 } 316 }
317 317
318 // For LTR this is the left edge of the box, for RTL, the right edge in pare nt coordinates. 318 // For LTR this is the left edge of the box, for RTL, the right edge in pare nt coordinates.
319 LayoutUnit ellipsisX = flowIsLTR ? visibleRightEdge - ellipsisWidth : visibl eLeftEdge + ellipsisWidth; 319 LayoutUnit ellipsisX = flowIsLTR ? visibleRightEdge - ellipsisWidth : visibl eLeftEdge + ellipsisWidth;
320 320
321 // Criteria for full truncation: 321 // Criteria for full truncation:
322 // LTR: the left edge of the ellipsis is to the left of our text run. 322 // LTR: the left edge of the ellipsis is to the left of our text run.
323 // RTL: the right edge of the ellipsis is to the right of our text run. 323 // RTL: the right edge of the ellipsis is to the right of our text run.
324 bool ltrFullTruncation = flowIsLTR && ellipsisX <= logicalLeft(); 324 bool ltrFullTruncation = flowIsLTR && ellipsisX <= logicalLeft();
325 bool rtlFullTruncation = !flowIsLTR && ellipsisX >= logicalLeft() + logicalW idth(); 325 bool rtlFullTruncation = !flowIsLTR && ellipsisX >= logicalLeft() + logicalW idth();
326 if (ltrFullTruncation || rtlFullTruncation) { 326 if (ltrFullTruncation || rtlFullTruncation) {
327 // Too far. Just set full truncation, but return -1 and let the ellipsi s just be placed at the edge of the box. 327 // Too far. Just set full truncation, but return -1 and let the ellipsi s just be placed at the edge of the box.
328 setTruncation(cFullTruncation); 328 setTruncation(cFullTruncation);
329 foundBox = true; 329 foundBox = true;
330 return -1; 330 return LayoutUnit(-1);
331 } 331 }
332 332
333 bool ltrEllipsisWithinBox = flowIsLTR && (ellipsisX < logicalRight()); 333 bool ltrEllipsisWithinBox = flowIsLTR && (ellipsisX < logicalRight());
334 bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > logicalLeft()); 334 bool rtlEllipsisWithinBox = !flowIsLTR && (ellipsisX > logicalLeft());
335 if (ltrEllipsisWithinBox || rtlEllipsisWithinBox) { 335 if (ltrEllipsisWithinBox || rtlEllipsisWithinBox) {
336 foundBox = true; 336 foundBox = true;
337 337
338 // The inline box may have different directionality than it's parent. S ince truncation 338 // The inline box may have different directionality than it's parent. S ince truncation
339 // behavior depends both on both the parent and the inline block's direc tionality, we 339 // behavior depends both on both the parent and the inline block's direc tionality, we
340 // must keep track of these separately. 340 // must keep track of these separately.
(...skipping 24 matching lines...) Expand all
365 // Where "after" is defined by the flow directionality, not the inline 365 // Where "after" is defined by the flow directionality, not the inline
366 // box directionality. 366 // box directionality.
367 // e.g. In the case of an LTR inline box truncated in an RTL flow then w e can 367 // e.g. In the case of an LTR inline box truncated in an RTL flow then w e can
368 // have a situation such as |Hello| -> |...He| 368 // have a situation such as |Hello| -> |...He|
369 truncatedWidth += widthOfVisibleText + ellipsisWidth; 369 truncatedWidth += widthOfVisibleText + ellipsisWidth;
370 if (flowIsLTR) 370 if (flowIsLTR)
371 return logicalLeft() + widthOfVisibleText; 371 return logicalLeft() + widthOfVisibleText;
372 return logicalRight() - widthOfVisibleText - ellipsisWidth; 372 return logicalRight() - widthOfVisibleText - ellipsisWidth;
373 } 373 }
374 truncatedWidth += logicalWidth(); 374 truncatedWidth += logicalWidth();
375 return -1; 375 return LayoutUnit(-1);
376 } 376 }
377 377
378 bool InlineTextBox::isLineBreak() const 378 bool InlineTextBox::isLineBreak() const
379 { 379 {
380 return lineLayoutItem().isBR() || (lineLayoutItem().style()->preserveNewline () && len() == 1 && (*lineLayoutItem().text().impl())[start()] == '\n'); 380 return lineLayoutItem().isBR() || (lineLayoutItem().style()->preserveNewline () && len() == 1 && (*lineLayoutItem().text().impl())[start()] == '\n');
381 } 381 }
382 382
383 bool InlineTextBox::nodeAtPoint(HitTestResult& result, const HitTestLocation& lo cationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit /* lineTop * /, LayoutUnit /*lineBottom*/) 383 bool InlineTextBox::nodeAtPoint(HitTestResult& result, const HitTestLocation& lo cationInContainer, const LayoutPoint& accumulatedOffset, LayoutUnit /* lineTop * /, LayoutUnit /*lineBottom*/)
384 { 384 {
385 if (isLineBreak() || m_truncation == cFullTruncation) 385 if (isLineBreak() || m_truncation == cFullTruncation)
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 int InlineTextBox::caretMaxOffset() const 465 int InlineTextBox::caretMaxOffset() const
466 { 466 {
467 return m_start + m_len; 467 return m_start + m_len;
468 } 468 }
469 469
470 LayoutUnit InlineTextBox::textPos() const 470 LayoutUnit InlineTextBox::textPos() const
471 { 471 {
472 // When computing the width of a text run, LayoutBlock::computeInlineDirecti onPositionsForLine() doesn't include the actual offset 472 // When computing the width of a text run, LayoutBlock::computeInlineDirecti onPositionsForLine() doesn't include the actual offset
473 // from the containing block edge in its measurement. textPos() should be co nsistent so the text are laid out in the same width. 473 // from the containing block edge in its measurement. textPos() should be co nsistent so the text are laid out in the same width.
474 if (logicalLeft() == 0) 474 if (logicalLeft() == 0)
475 return 0; 475 return LayoutUnit();
476 return logicalLeft() - root().logicalLeft(); 476 return logicalLeft() - root().logicalLeft();
477 } 477 }
478 478
479 int InlineTextBox::offsetForPosition(LayoutUnit lineOffset, bool includePartialG lyphs) const 479 int InlineTextBox::offsetForPosition(LayoutUnit lineOffset, bool includePartialG lyphs) const
480 { 480 {
481 if (isLineBreak()) 481 if (isLineBreak())
482 return 0; 482 return 0;
483 483
484 if (lineOffset - logicalLeft() > logicalWidth()) 484 if (lineOffset - logicalLeft() > logicalWidth())
485 return isLeftToRightDirection() ? len() : 0; 485 return isLeftToRightDirection() ? len() : 0;
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer( )); 626 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), obj.debugPointer( ));
627 const int layoutObjectCharacterOffset = 75; 627 const int layoutObjectCharacterOffset = 75;
628 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) 628 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++)
629 fputc(' ', stderr); 629 fputc(' ', stderr);
630 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 630 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
631 } 631 }
632 632
633 #endif 633 #endif
634 634
635 } // namespace blink 635 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698