| OLD | NEW |
| 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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 int sPos = std::max(startPos - m_start, 0); | 180 int sPos = std::max(startPos - m_start, 0); |
| 181 int ePos = std::min(endPos - m_start, (int)m_len); | 181 int ePos = std::min(endPos - m_start, (int)m_len); |
| 182 | 182 |
| 183 if (sPos > ePos) | 183 if (sPos > ePos) |
| 184 return LayoutRect(); | 184 return LayoutRect(); |
| 185 | 185 |
| 186 FontCachePurgePreventer fontCachePurgePreventer; | 186 FontCachePurgePreventer fontCachePurgePreventer; |
| 187 | 187 |
| 188 LayoutUnit selTop = root().selectionTop(); | 188 LayoutUnit selTop = root().selectionTop(); |
| 189 LayoutUnit selHeight = root().selectionHeight(); | 189 LayoutUnit selHeight = root().selectionHeight(); |
| 190 const LayoutStyle& styleToUse = layoutObject().styleRef(isFirstLineStyle()); | 190 const ComputedStyle& styleToUse = layoutObject().styleRef(isFirstLineStyle()
); |
| 191 const Font& font = styleToUse.font(); | 191 const Font& font = styleToUse.font(); |
| 192 | 192 |
| 193 StringBuilder charactersWithHyphen; | 193 StringBuilder charactersWithHyphen; |
| 194 bool respectHyphen = ePos == m_len && hasHyphen(); | 194 bool respectHyphen = ePos == m_len && hasHyphen(); |
| 195 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac
tersWithHyphen : 0); | 195 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac
tersWithHyphen : 0); |
| 196 | 196 |
| 197 FloatPointWillBeLayoutPoint startingPoint = FloatPointWillBeLayoutPoint(logi
calLeft(), selTop.toFloat()); | 197 FloatPointWillBeLayoutPoint startingPoint = FloatPointWillBeLayoutPoint(logi
calLeft(), selTop.toFloat()); |
| 198 LayoutRect r; | 198 LayoutRect r; |
| 199 if (sPos || ePos != static_cast<int>(m_len)) { | 199 if (sPos || ePos != static_cast<int>(m_len)) { |
| 200 r = LayoutRect(enclosingIntRect(font.selectionRectForText(textRun, start
ingPoint.toFloatPoint(), selHeight, sPos, ePos))); | 200 r = LayoutRect(enclosingIntRect(font.selectionRectForText(textRun, start
ingPoint.toFloatPoint(), selHeight, sPos, ePos))); |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 322 // FIXME: both calls to rawValue() below is temporary and should be removed
once the transition | 322 // FIXME: both calls to rawValue() below is temporary and should be removed
once the transition |
| 323 // to LayoutUnit-based types is complete (crbug.com/321237) | 323 // to LayoutUnit-based types is complete (crbug.com/321237) |
| 324 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l
ocationInContainer.intersects(rect.rawValue())) { | 324 if (m_truncation != cFullTruncation && visibleToHitTestRequest(request) && l
ocationInContainer.intersects(rect.rawValue())) { |
| 325 layoutObject().updateHitTestResult(result, flipForWritingMode(locationIn
Container.point() - toLayoutSize(accumulatedOffset))); | 325 layoutObject().updateHitTestResult(result, flipForWritingMode(locationIn
Container.point() - toLayoutSize(accumulatedOffset))); |
| 326 if (!result.addNodeToListBasedTestResult(layoutObject().node(), request,
locationInContainer, rect.rawValue())) | 326 if (!result.addNodeToListBasedTestResult(layoutObject().node(), request,
locationInContainer, rect.rawValue())) |
| 327 return true; | 327 return true; |
| 328 } | 328 } |
| 329 return false; | 329 return false; |
| 330 } | 330 } |
| 331 | 331 |
| 332 bool InlineTextBox::getEmphasisMarkPosition(const LayoutStyle& style, TextEmphas
isPosition& emphasisPosition) const | 332 bool InlineTextBox::getEmphasisMarkPosition(const ComputedStyle& style, TextEmph
asisPosition& emphasisPosition) const |
| 333 { | 333 { |
| 334 // This function returns true if there are text emphasis marks and they are
suppressed by ruby text. | 334 // This function returns true if there are text emphasis marks and they are
suppressed by ruby text. |
| 335 if (style.textEmphasisMark() == TextEmphasisMarkNone) | 335 if (style.textEmphasisMark() == TextEmphasisMarkNone) |
| 336 return false; | 336 return false; |
| 337 | 337 |
| 338 emphasisPosition = style.textEmphasisPosition(); | 338 emphasisPosition = style.textEmphasisPosition(); |
| 339 if (emphasisPosition == TextEmphasisPositionUnder) | 339 if (emphasisPosition == TextEmphasisPositionUnder) |
| 340 return true; // Ruby text is always over, so it cannot suppress emphasis
marks under. | 340 return true; // Ruby text is always over, so it cannot suppress emphasis
marks under. |
| 341 | 341 |
| 342 LayoutBlock* containingBlock = layoutObject().containingBlock(); | 342 LayoutBlock* containingBlock = layoutObject().containingBlock(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 368 if (layoutObject().selectionState() == LayoutObject::SelectionStart) | 368 if (layoutObject().selectionState() == LayoutObject::SelectionStart) |
| 369 endPos = layoutObject().textLength(); | 369 endPos = layoutObject().textLength(); |
| 370 else if (layoutObject().selectionState() == LayoutObject::SelectionEnd) | 370 else if (layoutObject().selectionState() == LayoutObject::SelectionEnd) |
| 371 startPos = 0; | 371 startPos = 0; |
| 372 } | 372 } |
| 373 | 373 |
| 374 sPos = std::max(startPos - m_start, 0); | 374 sPos = std::max(startPos - m_start, 0); |
| 375 ePos = std::min(endPos - m_start, (int)m_len); | 375 ePos = std::min(endPos - m_start, (int)m_len); |
| 376 } | 376 } |
| 377 | 377 |
| 378 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPointWil
lBeLayoutPoint& boxOrigin, DocumentMarker* marker, const LayoutStyle& style, con
st Font& font, bool grammar) | 378 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPointWil
lBeLayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style, c
onst Font& font, bool grammar) |
| 379 { | 379 { |
| 380 InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin.toFloatPoint()
, marker, style, font, grammar); | 380 InlineTextBoxPainter(*this).paintDocumentMarker(pt, boxOrigin.toFloatPoint()
, marker, style, font, grammar); |
| 381 } | 381 } |
| 382 | 382 |
| 383 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPointWi
llBeLayoutPoint& boxOrigin, DocumentMarker* marker, const LayoutStyle& style, co
nst Font& font) | 383 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPointWi
llBeLayoutPoint& boxOrigin, DocumentMarker* marker, const ComputedStyle& style,
const Font& font) |
| 384 { | 384 { |
| 385 InlineTextBoxPainter(*this).paintTextMatchMarker(pt, boxOrigin.toFloatPoint(
), marker, style, font); | 385 InlineTextBoxPainter(*this).paintTextMatchMarker(pt, boxOrigin.toFloatPoint(
), marker, style, font); |
| 386 } | 386 } |
| 387 | 387 |
| 388 int InlineTextBox::caretMinOffset() const | 388 int InlineTextBox::caretMinOffset() const |
| 389 { | 389 { |
| 390 return m_start; | 390 return m_start; |
| 391 } | 391 } |
| 392 | 392 |
| 393 int InlineTextBox::caretMaxOffset() const | 393 int InlineTextBox::caretMaxOffset() const |
| (...skipping 14 matching lines...) Expand all Loading... |
| 408 { | 408 { |
| 409 if (isLineBreak()) | 409 if (isLineBreak()) |
| 410 return 0; | 410 return 0; |
| 411 | 411 |
| 412 if (lineOffset - logicalLeft() > logicalWidth()) | 412 if (lineOffset - logicalLeft() > logicalWidth()) |
| 413 return isLeftToRightDirection() ? len() : 0; | 413 return isLeftToRightDirection() ? len() : 0; |
| 414 if (lineOffset - logicalLeft() < 0) | 414 if (lineOffset - logicalLeft() < 0) |
| 415 return isLeftToRightDirection() ? 0 : len(); | 415 return isLeftToRightDirection() ? 0 : len(); |
| 416 | 416 |
| 417 LayoutText& text = layoutObject(); | 417 LayoutText& text = layoutObject(); |
| 418 const LayoutStyle& style = text.styleRef(isFirstLineStyle()); | 418 const ComputedStyle& style = text.styleRef(isFirstLineStyle()); |
| 419 const Font& font = style.font(); | 419 const Font& font = style.font(); |
| 420 return font.offsetForPosition(constructTextRun(style, font), lineOffset - lo
gicalLeft(), includePartialGlyphs); | 420 return font.offsetForPosition(constructTextRun(style, font), lineOffset - lo
gicalLeft(), includePartialGlyphs); |
| 421 } | 421 } |
| 422 | 422 |
| 423 FloatWillBeLayoutUnit InlineTextBox::positionForOffset(int offset) const | 423 FloatWillBeLayoutUnit InlineTextBox::positionForOffset(int offset) const |
| 424 { | 424 { |
| 425 ASSERT(offset >= m_start); | 425 ASSERT(offset >= m_start); |
| 426 ASSERT(offset <= m_start + m_len); | 426 ASSERT(offset <= m_start + m_len); |
| 427 | 427 |
| 428 if (isLineBreak()) | 428 if (isLineBreak()) |
| 429 return logicalLeft(); | 429 return logicalLeft(); |
| 430 | 430 |
| 431 LayoutText& text = layoutObject(); | 431 LayoutText& text = layoutObject(); |
| 432 const LayoutStyle& styleToUse = text.styleRef(isFirstLineStyle()); | 432 const ComputedStyle& styleToUse = text.styleRef(isFirstLineStyle()); |
| 433 const Font& font = styleToUse.font(); | 433 const Font& font = styleToUse.font(); |
| 434 int from = !isLeftToRightDirection() ? offset - m_start : 0; | 434 int from = !isLeftToRightDirection() ? offset - m_start : 0; |
| 435 int to = !isLeftToRightDirection() ? m_len : offset - m_start; | 435 int to = !isLeftToRightDirection() ? m_len : offset - m_start; |
| 436 // FIXME: Do we need to add rightBearing here? | 436 // FIXME: Do we need to add rightBearing here? |
| 437 return font.selectionRectForText(constructTextRun(styleToUse, font), IntPoin
t(logicalLeft(), 0), 0, from, to).maxX(); | 437 return font.selectionRectForText(constructTextRun(styleToUse, font), IntPoin
t(logicalLeft(), 0), 0, from, to).maxX(); |
| 438 } | 438 } |
| 439 | 439 |
| 440 bool InlineTextBox::containsCaretOffset(int offset) const | 440 bool InlineTextBox::containsCaretOffset(int offset) const |
| 441 { | 441 { |
| 442 // Offsets before the box are never "in". | 442 // Offsets before the box are never "in". |
| (...skipping 15 matching lines...) Expand all Loading... |
| 458 return false; | 458 return false; |
| 459 | 459 |
| 460 // Offsets at the end are "in" for normal boxes (but the caller has to check
affinity). | 460 // Offsets at the end are "in" for normal boxes (but the caller has to check
affinity). |
| 461 return true; | 461 return true; |
| 462 } | 462 } |
| 463 | 463 |
| 464 void InlineTextBox::characterWidths(Vector<FloatWillBeLayoutUnit>& widths) const | 464 void InlineTextBox::characterWidths(Vector<FloatWillBeLayoutUnit>& widths) const |
| 465 { | 465 { |
| 466 FontCachePurgePreventer fontCachePurgePreventer; | 466 FontCachePurgePreventer fontCachePurgePreventer; |
| 467 | 467 |
| 468 const LayoutStyle& styleToUse = layoutObject().styleRef(isFirstLineStyle()); | 468 const ComputedStyle& styleToUse = layoutObject().styleRef(isFirstLineStyle()
); |
| 469 const Font& font = styleToUse.font(); | 469 const Font& font = styleToUse.font(); |
| 470 | 470 |
| 471 TextRun textRun = constructTextRun(styleToUse, font); | 471 TextRun textRun = constructTextRun(styleToUse, font); |
| 472 | 472 |
| 473 SimpleShaper shaper(&font, textRun); | 473 SimpleShaper shaper(&font, textRun); |
| 474 FloatWillBeLayoutUnit lastWidth; | 474 FloatWillBeLayoutUnit lastWidth; |
| 475 widths.resize(m_len); | 475 widths.resize(m_len); |
| 476 for (unsigned i = 0; i < m_len; i++) { | 476 for (unsigned i = 0; i < m_len; i++) { |
| 477 shaper.advance(i + 1); | 477 shaper.advance(i + 1); |
| 478 widths[i] = shaper.runWidthSoFar() - lastWidth; | 478 widths[i] = shaper.runWidthSoFar() - lastWidth; |
| 479 lastWidth = shaper.runWidthSoFar(); | 479 lastWidth = shaper.runWidthSoFar(); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 TextRun InlineTextBox::constructTextRun(const LayoutStyle& style, const Font& fo
nt, StringBuilder* charactersWithHyphen) const | 483 TextRun InlineTextBox::constructTextRun(const ComputedStyle& style, const Font&
font, StringBuilder* charactersWithHyphen) const |
| 484 { | 484 { |
| 485 ASSERT(layoutObject().text()); | 485 ASSERT(layoutObject().text()); |
| 486 | 486 |
| 487 StringView string = layoutObject().text().createView(); | 487 StringView string = layoutObject().text().createView(); |
| 488 unsigned startPos = start(); | 488 unsigned startPos = start(); |
| 489 unsigned length = len(); | 489 unsigned length = len(); |
| 490 | 490 |
| 491 if (string.length() != length || startPos) | 491 if (string.length() != length || startPos) |
| 492 string.narrow(startPos, length); | 492 string.narrow(startPos, length); |
| 493 | 493 |
| 494 return constructTextRun(style, font, string, layoutObject().textLength() - s
tartPos, charactersWithHyphen); | 494 return constructTextRun(style, font, string, layoutObject().textLength() - s
tartPos, charactersWithHyphen); |
| 495 } | 495 } |
| 496 | 496 |
| 497 TextRun InlineTextBox::constructTextRun(const LayoutStyle& style, const Font& fo
nt, StringView string, int maximumLength, StringBuilder* charactersWithHyphen) c
onst | 497 TextRun InlineTextBox::constructTextRun(const ComputedStyle& style, const Font&
font, StringView string, int maximumLength, StringBuilder* charactersWithHyphen)
const |
| 498 { | 498 { |
| 499 if (charactersWithHyphen) { | 499 if (charactersWithHyphen) { |
| 500 const AtomicString& hyphenString = style.hyphenString(); | 500 const AtomicString& hyphenString = style.hyphenString(); |
| 501 charactersWithHyphen->reserveCapacity(string.length() + hyphenString.len
gth()); | 501 charactersWithHyphen->reserveCapacity(string.length() + hyphenString.len
gth()); |
| 502 charactersWithHyphen->append(string); | 502 charactersWithHyphen->append(string); |
| 503 charactersWithHyphen->append(hyphenString); | 503 charactersWithHyphen->append(hyphenString); |
| 504 string = charactersWithHyphen->toString().createView(); | 504 string = charactersWithHyphen->toString().createView(); |
| 505 maximumLength = string.length(); | 505 maximumLength = string.length(); |
| 506 } | 506 } |
| 507 | 507 |
| 508 ASSERT(maximumLength >= static_cast<int>(string.length())); | 508 ASSERT(maximumLength >= static_cast<int>(string.length())); |
| 509 | 509 |
| 510 TextRun run(string, textPos(), expansion(), expansionBehavior(), direction()
, dirOverride() || style.rtlOrdering() == VisualOrder, !layoutObject().canUseSim
pleFontCodePath()); | 510 TextRun run(string, textPos(), expansion(), expansionBehavior(), direction()
, dirOverride() || style.rtlOrdering() == VisualOrder, !layoutObject().canUseSim
pleFontCodePath()); |
| 511 run.setTabSize(!style.collapseWhiteSpace(), style.tabSize()); | 511 run.setTabSize(!style.collapseWhiteSpace(), style.tabSize()); |
| 512 run.setCodePath(layoutObject().canUseSimpleFontCodePath() ? TextRun::ForceSi
mple : TextRun::ForceComplex); | 512 run.setCodePath(layoutObject().canUseSimpleFontCodePath() ? TextRun::ForceSi
mple : TextRun::ForceComplex); |
| 513 run.setTextJustify(style.textJustify()); | 513 run.setTextJustify(style.textJustify()); |
| 514 | 514 |
| 515 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. | 515 // Propagate the maximum length of the characters buffer to the TextRun, eve
n when we're only processing a substring. |
| 516 run.setCharactersLength(maximumLength); | 516 run.setCharactersLength(maximumLength); |
| 517 ASSERT(run.charactersLength() >= run.length()); | 517 ASSERT(run.charactersLength() >= run.length()); |
| 518 return run; | 518 return run; |
| 519 } | 519 } |
| 520 | 520 |
| 521 TextRun InlineTextBox::constructTextRunForInspector(const LayoutStyle& style, co
nst Font& font) const | 521 TextRun InlineTextBox::constructTextRunForInspector(const ComputedStyle& style,
const Font& font) const |
| 522 { | 522 { |
| 523 return InlineTextBox::constructTextRun(style, font); | 523 return InlineTextBox::constructTextRun(style, font); |
| 524 } | 524 } |
| 525 | 525 |
| 526 const char* InlineTextBox::boxName() const | 526 const char* InlineTextBox::boxName() const |
| 527 { | 527 { |
| 528 return "InlineTextBox"; | 528 return "InlineTextBox"; |
| 529 } | 529 } |
| 530 | 530 |
| 531 String InlineTextBox::debugName() const | 531 String InlineTextBox::debugName() const |
| (...skipping 20 matching lines...) Expand all Loading... |
| 552 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), &obj); | 552 printedCharacters = fprintf(stderr, "\t%s %p", obj.name(), &obj); |
| 553 const int layoutObjectCharacterOffset = 75; | 553 const int layoutObjectCharacterOffset = 75; |
| 554 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) | 554 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) |
| 555 fputc(' ', stderr); | 555 fputc(' ', stderr); |
| 556 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); | 556 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); |
| 557 } | 557 } |
| 558 | 558 |
| 559 #endif | 559 #endif |
| 560 | 560 |
| 561 } // namespace blink | 561 } // namespace blink |
| OLD | NEW |