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 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
302 truncatedWidth += widthOfVisibleText + ellipsisWidth; | 302 truncatedWidth += widthOfVisibleText + ellipsisWidth; |
303 if (flowIsLTR) | 303 if (flowIsLTR) |
304 return logicalLeft() + widthOfVisibleText; | 304 return logicalLeft() + widthOfVisibleText; |
305 else | 305 else |
306 return logicalRight() - widthOfVisibleText - ellipsisWidth; | 306 return logicalRight() - widthOfVisibleText - ellipsisWidth; |
307 } | 307 } |
308 truncatedWidth += logicalWidth(); | 308 truncatedWidth += logicalWidth(); |
309 return -1; | 309 return -1; |
310 } | 310 } |
311 | 311 |
312 static Color textColorForWhiteBackground(Color textColor) | |
313 { | |
314 int distanceFromWhite = differenceSquared(textColor, Color::white); | |
315 // semi-arbitrarily chose 65025 (255^2) value here after a few tests; | |
316 return distanceFromWhite > 65025 ? textColor : textColor.dark(); | |
317 } | |
318 | |
319 bool InlineTextBox::isLineBreak() const | 312 bool InlineTextBox::isLineBreak() const |
320 { | 313 { |
321 return renderer().style()->preserveNewline() && len() == 1 && (*renderer().t
ext().impl())[start()] == '\n'; | 314 return renderer().style()->preserveNewline() && len() == 1 && (*renderer().t
ext().impl())[start()] == '\n'; |
322 } | 315 } |
323 | 316 |
324 bool InlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re
sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated
Offset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) | 317 bool InlineTextBox::nodeAtPoint(const HitTestRequest& request, HitTestResult& re
sult, const HitTestLocation& locationInContainer, const LayoutPoint& accumulated
Offset, LayoutUnit /* lineTop */, LayoutUnit /*lineBottom*/) |
325 { | 318 { |
326 if (isLineBreak()) | 319 if (isLineBreak()) |
327 return false; | 320 return false; |
328 | 321 |
(...skipping 30 matching lines...) Expand all Loading... |
359 { | 352 { |
360 return fillColor == other.fillColor | 353 return fillColor == other.fillColor |
361 && strokeColor == other.strokeColor | 354 && strokeColor == other.strokeColor |
362 && emphasisMarkColor == other.emphasisMarkColor | 355 && emphasisMarkColor == other.emphasisMarkColor |
363 && strokeWidth == other.strokeWidth | 356 && strokeWidth == other.strokeWidth |
364 && shadow == other.shadow; | 357 && shadow == other.shadow; |
365 } | 358 } |
366 bool operator!=(const TextPaintingStyle& other) { return !(*this == other);
} | 359 bool operator!=(const TextPaintingStyle& other) { return !(*this == other);
} |
367 }; | 360 }; |
368 | 361 |
369 TextPaintingStyle textPaintingStyle(RenderText& renderer, RenderStyle* style, bo
ol forceBlackText) | 362 TextPaintingStyle textPaintingStyle(RenderText& renderer, RenderStyle* style) |
370 { | 363 { |
371 TextPaintingStyle textStyle; | 364 TextPaintingStyle textStyle; |
372 | 365 textStyle.fillColor = renderer.resolveColor(style, CSSPropertyWebkitTextFill
Color); |
373 if (forceBlackText) { | 366 textStyle.strokeColor = renderer.resolveColor(style, CSSPropertyWebkitTextSt
rokeColor); |
374 textStyle.fillColor = Color::black; | 367 textStyle.emphasisMarkColor = renderer.resolveColor(style, CSSPropertyWebkit
TextEmphasisColor); |
375 textStyle.strokeColor = Color::black; | 368 textStyle.strokeWidth = style->textStrokeWidth(); |
376 textStyle.emphasisMarkColor = Color::black; | 369 textStyle.shadow = style->textShadow(); |
377 textStyle.strokeWidth = style->textStrokeWidth(); | |
378 textStyle.shadow = 0; | |
379 } else { | |
380 textStyle.fillColor = renderer.resolveColor(style, CSSPropertyWebkitText
FillColor); | |
381 textStyle.strokeColor = renderer.resolveColor(style, CSSPropertyWebkitTe
xtStrokeColor); | |
382 textStyle.emphasisMarkColor = renderer.resolveColor(style, CSSPropertyWe
bkitTextEmphasisColor); | |
383 textStyle.strokeWidth = style->textStrokeWidth(); | |
384 textStyle.shadow = style->textShadow(); | |
385 | |
386 // Adjust text color when printing with a white background. | |
387 bool forceBackgroundToWhite = false; | |
388 if (forceBackgroundToWhite) { | |
389 textStyle.fillColor = textColorForWhiteBackground(textStyle.fillColo
r); | |
390 textStyle.strokeColor = textColorForWhiteBackground(textStyle.stroke
Color); | |
391 textStyle.emphasisMarkColor = textColorForWhiteBackground(textStyle.
emphasisMarkColor); | |
392 } | |
393 } | |
394 | |
395 return textStyle; | 370 return textStyle; |
396 } | 371 } |
397 | 372 |
398 TextPaintingStyle selectionPaintingStyle(RenderText& renderer, bool haveSelectio
n, bool forceBlackText, const TextPaintingStyle& textStyle) | 373 TextPaintingStyle selectionPaintingStyle(RenderText& renderer, bool haveSelectio
n, const TextPaintingStyle& textStyle) |
399 { | 374 { |
400 TextPaintingStyle selectionStyle = textStyle; | 375 TextPaintingStyle selectionStyle = textStyle; |
401 | 376 |
402 if (haveSelection) { | 377 if (haveSelection) { |
403 if (!forceBlackText) { | 378 selectionStyle.fillColor = renderer.selectionForegroundColor(); |
404 selectionStyle.fillColor = renderer.selectionForegroundColor(); | 379 selectionStyle.emphasisMarkColor = renderer.selectionEmphasisMarkColor()
; |
405 selectionStyle.emphasisMarkColor = renderer.selectionEmphasisMarkCol
or(); | |
406 } | |
407 } | 380 } |
408 | 381 |
409 return selectionStyle; | 382 return selectionStyle; |
410 } | 383 } |
411 | 384 |
412 void updateGraphicsContext(GraphicsContext* context, const TextPaintingStyle& te
xtStyle, GraphicsContextStateSaver& stateSaver) | 385 void updateGraphicsContext(GraphicsContext* context, const TextPaintingStyle& te
xtStyle, GraphicsContextStateSaver& stateSaver) |
413 { | 386 { |
414 TextDrawingModeFlags mode = context->textDrawingMode(); | 387 TextDrawingModeFlags mode = context->textDrawingMode(); |
415 if (textStyle.strokeWidth > 0) { | 388 if (textStyle.strokeWidth > 0) { |
416 TextDrawingModeFlags newMode = mode | TextModeStroke; | 389 TextDrawingModeFlags newMode = mode | TextModeStroke; |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 | 530 |
558 FloatPoint boxOrigin = locationIncludingFlipping(); | 531 FloatPoint boxOrigin = locationIncludingFlipping(); |
559 boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().to
Float()); | 532 boxOrigin.move(adjustedPaintOffset.x().toFloat(), adjustedPaintOffset.y().to
Float()); |
560 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight())); | 533 FloatRect boxRect(boxOrigin, LayoutSize(logicalWidth(), logicalHeight())); |
561 | 534 |
562 // Determine whether or not we have composition underlines to draw. | 535 // Determine whether or not we have composition underlines to draw. |
563 bool containsComposition = renderer().node() && renderer().frame()->inputMet
hodController().compositionNode() == renderer().node(); | 536 bool containsComposition = renderer().node() && renderer().frame()->inputMet
hodController().compositionNode() == renderer().node(); |
564 bool useCustomUnderlines = containsComposition && renderer().frame()->inputM
ethodController().compositionUsesCustomUnderlines(); | 537 bool useCustomUnderlines = containsComposition && renderer().frame()->inputM
ethodController().compositionUsesCustomUnderlines(); |
565 | 538 |
566 // Determine text colors. | 539 // Determine text colors. |
567 TextPaintingStyle textStyle = textPaintingStyle(renderer(), styleToUse, pain
tInfo.forceBlackText()); | 540 TextPaintingStyle textStyle = textPaintingStyle(renderer(), styleToUse); |
568 TextPaintingStyle selectionStyle = selectionPaintingStyle(renderer(), haveSe
lection, paintInfo.forceBlackText(), textStyle); | 541 TextPaintingStyle selectionStyle = selectionPaintingStyle(renderer(), haveSe
lection, textStyle); |
569 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); | 542 bool paintSelectedTextOnly = (paintInfo.phase == PaintPhaseSelection); |
570 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se
lectionStyle; | 543 bool paintSelectedTextSeparately = !paintSelectedTextOnly && textStyle != se
lectionStyle; |
571 | 544 |
572 // Set our font. | 545 // Set our font. |
573 const Font& font = styleToUse->font(); | 546 const Font& font = styleToUse->font(); |
574 | 547 |
575 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM
etrics().ascent()); | 548 FloatPoint textOrigin = FloatPoint(boxOrigin.x(), boxOrigin.y() + font.fontM
etrics().ascent()); |
576 | 549 |
577 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds
include selection | 550 // 1. Paint backgrounds behind text if needed. Examples of such backgrounds
include selection |
578 // and composition highlights. | 551 // and composition highlights. |
(...skipping 805 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1384 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); | 1357 printedCharacters = fprintf(stderr, "\t%s %p", obj.renderName(), &obj); |
1385 const int rendererCharacterOffset = 24; | 1358 const int rendererCharacterOffset = 24; |
1386 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) | 1359 for (; printedCharacters < rendererCharacterOffset; printedCharacters++) |
1387 fputc(' ', stderr); | 1360 fputc(' ', stderr); |
1388 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); | 1361 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), value.utf8().d
ata()); |
1389 } | 1362 } |
1390 | 1363 |
1391 #endif | 1364 #endif |
1392 | 1365 |
1393 } // namespace blink | 1366 } // namespace blink |
OLD | NEW |