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

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

Issue 889563002: Make RenderObject::style() return a const object (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Blind fix for Mac. Created 5 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 | Annotate | Revision Log
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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
179 int sPos = std::max(startPos - m_start, 0); 179 int sPos = std::max(startPos - m_start, 0);
180 int ePos = std::min(endPos - m_start, (int)m_len); 180 int ePos = std::min(endPos - m_start, (int)m_len);
181 181
182 if (sPos > ePos) 182 if (sPos > ePos)
183 return LayoutRect(); 183 return LayoutRect();
184 184
185 FontCachePurgePreventer fontCachePurgePreventer; 185 FontCachePurgePreventer fontCachePurgePreventer;
186 186
187 LayoutUnit selTop = root().selectionTop(); 187 LayoutUnit selTop = root().selectionTop();
188 LayoutUnit selHeight = root().selectionHeight(); 188 LayoutUnit selHeight = root().selectionHeight();
189 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); 189 const RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
190 const Font& font = styleToUse->font(); 190 const Font& font = styleToUse->font();
191 191
192 StringBuilder charactersWithHyphen; 192 StringBuilder charactersWithHyphen;
193 bool respectHyphen = ePos == m_len && hasHyphen(); 193 bool respectHyphen = ePos == m_len && hasHyphen();
194 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac tersWithHyphen : 0); 194 TextRun textRun = constructTextRun(styleToUse, font, respectHyphen ? &charac tersWithHyphen : 0);
195 195
196 FloatPointWillBeLayoutPoint startingPoint = FloatPointWillBeLayoutPoint(logi calLeft(), selTop.toFloat()); 196 FloatPointWillBeLayoutPoint startingPoint = FloatPointWillBeLayoutPoint(logi calLeft(), selTop.toFloat());
197 LayoutRect r; 197 LayoutRect r;
198 if (sPos || ePos != static_cast<int>(m_len)) { 198 if (sPos || ePos != static_cast<int>(m_len)) {
199 r = enclosingIntRect(font.selectionRectForText(textRun, startingPoint.to FloatPoint(), selHeight, sPos, ePos)); 199 r = enclosingIntRect(font.selectionRectForText(textRun, startingPoint.to FloatPoint(), selHeight, sPos, ePos));
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset))); 325 renderer().updateHitTestResult(result, flipForWritingMode(locationInCont ainer.point() - toLayoutSize(accumulatedOffset)));
326 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect.rawValue())) 326 if (!result.addNodeToRectBasedTestResult(renderer().node(), request, loc ationInContainer, rect.rawValue()))
327 return true; 327 return true;
328 } 328 }
329 return false; 329 return false;
330 } 330 }
331 331
332 bool InlineTextBox::getEmphasisMarkPosition(RenderStyle* style, TextEmphasisPosi tion& emphasisPosition) const 332 bool InlineTextBox::getEmphasisMarkPosition(const RenderStyle* style, TextEmphas isPosition& 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 RenderBlock* containingBlock = renderer().containingBlock(); 342 RenderBlock* containingBlock = renderer().containingBlock();
(...skipping 25 matching lines...) Expand all
368 if (renderer().selectionState() == RenderObject::SelectionStart) 368 if (renderer().selectionState() == RenderObject::SelectionStart)
369 endPos = renderer().textLength(); 369 endPos = renderer().textLength();
370 else if (renderer().selectionState() == RenderObject::SelectionEnd) 370 else if (renderer().selectionState() == RenderObject::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, RenderStyle* style, const Fon t& font, bool grammar) 378 void InlineTextBox::paintDocumentMarker(GraphicsContext* pt, const FloatPointWil lBeLayoutPoint& boxOrigin, DocumentMarker* marker, const RenderStyle* style, con st 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, RenderStyle* style, const Fo nt& font) 383 void InlineTextBox::paintTextMatchMarker(GraphicsContext* pt, const FloatPointWi llBeLayoutPoint& boxOrigin, DocumentMarker* marker, const RenderStyle* style, co nst 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
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 RenderText& text = renderer(); 417 RenderText& text = renderer();
418 RenderStyle* style = text.style(isFirstLineStyle()); 418 const RenderStyle* style = text.style(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 RenderText& text = renderer(); 431 RenderText& text = renderer();
432 RenderStyle* styleToUse = text.style(isFirstLineStyle()); 432 const RenderStyle* styleToUse = text.style(isFirstLineStyle());
433 ASSERT(styleToUse); 433 ASSERT(styleToUse);
434 const Font& font = styleToUse->font(); 434 const Font& font = styleToUse->font();
435 int from = !isLeftToRightDirection() ? offset - m_start : 0; 435 int from = !isLeftToRightDirection() ? offset - m_start : 0;
436 int to = !isLeftToRightDirection() ? m_len : offset - m_start; 436 int to = !isLeftToRightDirection() ? m_len : offset - m_start;
437 // FIXME: Do we need to add rightBearing here? 437 // FIXME: Do we need to add rightBearing here?
438 return font.selectionRectForText(constructTextRun(styleToUse, font), IntPoin t(logicalLeft(), 0), 0, from, to).maxX(); 438 return font.selectionRectForText(constructTextRun(styleToUse, font), IntPoin t(logicalLeft(), 0), 0, from, to).maxX();
439 } 439 }
440 440
441 bool InlineTextBox::containsCaretOffset(int offset) const 441 bool InlineTextBox::containsCaretOffset(int offset) const
442 { 442 {
(...skipping 16 matching lines...) Expand all
459 return false; 459 return false;
460 460
461 // Offsets at the end are "in" for normal boxes (but the caller has to check affinity). 461 // Offsets at the end are "in" for normal boxes (but the caller has to check affinity).
462 return true; 462 return true;
463 } 463 }
464 464
465 void InlineTextBox::characterWidths(Vector<FloatWillBeLayoutUnit>& widths) const 465 void InlineTextBox::characterWidths(Vector<FloatWillBeLayoutUnit>& widths) const
466 { 466 {
467 FontCachePurgePreventer fontCachePurgePreventer; 467 FontCachePurgePreventer fontCachePurgePreventer;
468 468
469 RenderStyle* styleToUse = renderer().style(isFirstLineStyle()); 469 const RenderStyle* styleToUse = renderer().style(isFirstLineStyle());
470 const Font& font = styleToUse->font(); 470 const Font& font = styleToUse->font();
471 471
472 TextRun textRun = constructTextRun(styleToUse, font); 472 TextRun textRun = constructTextRun(styleToUse, font);
473 473
474 SimpleShaper shaper(&font, textRun); 474 SimpleShaper shaper(&font, textRun);
475 FloatWillBeLayoutUnit lastWidth; 475 FloatWillBeLayoutUnit lastWidth;
476 widths.resize(m_len); 476 widths.resize(m_len);
477 for (unsigned i = 0; i < m_len; i++) { 477 for (unsigned i = 0; i < m_len; i++) {
478 shaper.advance(i + 1); 478 shaper.advance(i + 1);
479 widths[i] = shaper.runWidthSoFar() - lastWidth; 479 widths[i] = shaper.runWidthSoFar() - lastWidth;
480 lastWidth = shaper.runWidthSoFar(); 480 lastWidth = shaper.runWidthSoFar();
481 } 481 }
482 } 482 }
483 483
484 TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, St ringBuilder* charactersWithHyphen) const 484 TextRun InlineTextBox::constructTextRun(const RenderStyle* style, const Font& fo nt, StringBuilder* charactersWithHyphen) const
485 { 485 {
486 ASSERT(style); 486 ASSERT(style);
487 ASSERT(renderer().text()); 487 ASSERT(renderer().text());
488 488
489 StringView string = renderer().text().createView(); 489 StringView string = renderer().text().createView();
490 unsigned startPos = start(); 490 unsigned startPos = start();
491 unsigned length = len(); 491 unsigned length = len();
492 492
493 if (string.length() != length || startPos) 493 if (string.length() != length || startPos)
494 string.narrow(startPos, length); 494 string.narrow(startPos, length);
495 495
496 return constructTextRun(style, font, string, renderer().textLength() - start Pos, charactersWithHyphen); 496 return constructTextRun(style, font, string, renderer().textLength() - start Pos, charactersWithHyphen);
497 } 497 }
498 498
499 TextRun InlineTextBox::constructTextRun(RenderStyle* style, const Font& font, St ringView string, int maximumLength, StringBuilder* charactersWithHyphen) const 499 TextRun InlineTextBox::constructTextRun(const RenderStyle* style, const Font& fo nt, StringView string, int maximumLength, StringBuilder* charactersWithHyphen) c onst
500 { 500 {
501 ASSERT(style); 501 ASSERT(style);
502 502
503 if (charactersWithHyphen) { 503 if (charactersWithHyphen) {
504 const AtomicString& hyphenString = style->hyphenString(); 504 const AtomicString& hyphenString = style->hyphenString();
505 charactersWithHyphen->reserveCapacity(string.length() + hyphenString.len gth()); 505 charactersWithHyphen->reserveCapacity(string.length() + hyphenString.len gth());
506 charactersWithHyphen->append(string); 506 charactersWithHyphen->append(string);
507 charactersWithHyphen->append(hyphenString); 507 charactersWithHyphen->append(hyphenString);
508 string = charactersWithHyphen->toString().createView(); 508 string = charactersWithHyphen->toString().createView();
509 maximumLength = string.length(); 509 maximumLength = string.length();
510 } 510 }
511 511
512 ASSERT(maximumLength >= static_cast<int>(string.length())); 512 ASSERT(maximumLength >= static_cast<int>(string.length()));
513 513
514 TextRun run(string, textPos(), expansion(), expansionBehavior(), direction() , dirOverride() || style->rtlOrdering() == VisualOrder, !renderer().canUseSimple FontCodePath()); 514 TextRun run(string, textPos(), expansion(), expansionBehavior(), direction() , dirOverride() || style->rtlOrdering() == VisualOrder, !renderer().canUseSimple FontCodePath());
515 run.setTabSize(!style->collapseWhiteSpace(), style->tabSize()); 515 run.setTabSize(!style->collapseWhiteSpace(), style->tabSize());
516 run.setCodePath(renderer().canUseSimpleFontCodePath() ? TextRun::ForceSimple : TextRun::ForceComplex); 516 run.setCodePath(renderer().canUseSimpleFontCodePath() ? TextRun::ForceSimple : TextRun::ForceComplex);
517 run.setTextJustify(style->textJustify()); 517 run.setTextJustify(style->textJustify());
518 518
519 // Propagate the maximum length of the characters buffer to the TextRun, eve n when we're only processing a substring. 519 // Propagate the maximum length of the characters buffer to the TextRun, eve n when we're only processing a substring.
520 run.setCharactersLength(maximumLength); 520 run.setCharactersLength(maximumLength);
521 ASSERT(run.charactersLength() >= run.length()); 521 ASSERT(run.charactersLength() >= run.length());
522 return run; 522 return run;
523 } 523 }
524 524
525 TextRun InlineTextBox::constructTextRunForInspector(RenderStyle* style, const Fo nt& font) const 525 TextRun InlineTextBox::constructTextRunForInspector(const RenderStyle* style, co nst Font& font) const
526 { 526 {
527 return InlineTextBox::constructTextRun(style, font); 527 return InlineTextBox::constructTextRun(style, font);
528 } 528 }
529 529
530 #ifndef NDEBUG 530 #ifndef NDEBUG
531 531
532 const char* InlineTextBox::boxName() const 532 const char* InlineTextBox::boxName() const
533 { 533 {
534 return "InlineTextBox"; 534 return "InlineTextBox";
535 } 535 }
(...skipping 11 matching lines...) Expand all
547 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); 547 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj);
548 const int rendererCharacterOffset = 75; 548 const int rendererCharacterOffset = 75;
549 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) 549 for (; printedCharacters < rendererCharacterOffset; printedCharacters++)
550 fputc(' ', stderr); 550 fputc(' ', stderr);
551 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata()); 551 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d ata());
552 } 552 }
553 553
554 #endif 554 #endif
555 555
556 } // namespace blink 556 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698