| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. | 2 * Copyright (C) 2003, 2004, 2005, 2006, 2009 Apple Inc. All rights reserved. |
| 3 * Copyright (C) 2013 Google Inc. All rights reserved. | 3 * Copyright (C) 2013 Google Inc. All rights reserved. |
| 4 * | 4 * |
| 5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
| 6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
| 7 * are met: | 7 * are met: |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 drawRect(r1, fillPaint); | 504 drawRect(r1, fillPaint); |
| 505 drawRect(r2, fillPaint); | 505 drawRect(r2, fillPaint); |
| 506 } | 506 } |
| 507 | 507 |
| 508 adjustLineToPixelBoundaries(p1, p2, width, penStyle); | 508 adjustLineToPixelBoundaries(p1, p2, width, penStyle); |
| 509 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint); | 509 m_canvas->drawLine(p1.x(), p1.y(), p2.x(), p2.y(), paint); |
| 510 } | 510 } |
| 511 | 511 |
| 512 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, | 512 void GraphicsContext::drawLineForDocumentMarker(const FloatPoint& pt, |
| 513 float width, | 513 float width, |
| 514 DocumentMarkerLineStyle style) { | 514 DocumentMarkerLineStyle style, |
| 515 float zoom) { |
| 515 if (contextDisabled()) | 516 if (contextDisabled()) |
| 516 return; | 517 return; |
| 517 | 518 |
| 518 // Use 2x resources for a device scale factor of 1.5 or above. | 519 // Use 2x resources for a device scale factor of 1.5 or above. |
| 519 int deviceScaleFactor = m_deviceScaleFactor > 1.5f ? 2 : 1; | 520 // This modifes the bitmaps used for the marker, not the overall |
| 521 // scaling of the marker. |
| 522 int deviceScaleFactor = m_deviceScaleFactor * zoom > 1.5f ? 2 : 1; |
| 520 | 523 |
| 521 // Create the pattern we'll use to draw the underline. | 524 // Create the pattern we'll use to draw the underline. |
| 522 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; | 525 int index = style == DocumentMarkerGrammarLineStyle ? 1 : 0; |
| 523 static SkBitmap* misspellBitmap1x[2] = {0, 0}; | 526 static SkBitmap* misspellBitmap1x[2] = {0, 0}; |
| 524 static SkBitmap* misspellBitmap2x[2] = {0, 0}; | 527 static SkBitmap* misspellBitmap2x[2] = {0, 0}; |
| 525 SkBitmap** misspellBitmap = | 528 SkBitmap** misspellBitmap = |
| 526 deviceScaleFactor == 2 ? misspellBitmap2x : misspellBitmap1x; | 529 deviceScaleFactor == 2 ? misspellBitmap2x : misspellBitmap1x; |
| 527 if (!misspellBitmap[index]) { | 530 if (!misspellBitmap[index]) { |
| 528 #if OS(MACOSX) | 531 #if OS(MACOSX) |
| 529 // Match the artwork used by the Mac. | 532 // Match the artwork used by the Mac. |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 row[5] = colors[index][x * 3]; | 582 row[5] = colors[index][x * 3]; |
| 580 row[6] = transparentColor; | 583 row[6] = transparentColor; |
| 581 row[7] = transparentColor; | 584 row[7] = transparentColor; |
| 582 } | 585 } |
| 583 } else | 586 } else |
| 584 ASSERT_NOT_REACHED(); | 587 ASSERT_NOT_REACHED(); |
| 585 | 588 |
| 586 misspellBitmap[index] = new SkBitmap(bitmap); | 589 misspellBitmap[index] = new SkBitmap(bitmap); |
| 587 #else | 590 #else |
| 588 // We use a 2-pixel-high misspelling indicator because that seems to be | 591 // We use a 2-pixel-high misspelling indicator because that seems to be |
| 589 // what WebKit is designed for, and how much room there is in a typical | 592 // what Blink is designed for, and how much room there is in a typical |
| 590 // page for it. | 593 // page for it. |
| 591 const int rowPixels = | 594 const int rowPixels = |
| 592 32 * deviceScaleFactor; // Must be multiple of 4 for pattern below. | 595 32 * deviceScaleFactor; // Must be multiple of 4 for pattern below. |
| 593 const int colPixels = 2 * deviceScaleFactor; | 596 const int colPixels = 2 * deviceScaleFactor; |
| 594 SkBitmap bitmap; | 597 SkBitmap bitmap; |
| 595 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels)) | 598 if (!bitmap.tryAllocN32Pixels(rowPixels, colPixels)) |
| 596 return; | 599 return; |
| 597 | 600 |
| 598 bitmap.eraseARGB(0, 0, 0, 0); | 601 bitmap.eraseARGB(0, 0, 0, 0); |
| 599 if (deviceScaleFactor == 1) | 602 if (deviceScaleFactor == 1) |
| 600 draw1xMarker(&bitmap, index); | 603 draw1xMarker(&bitmap, index); |
| 601 else if (deviceScaleFactor == 2) | 604 else if (deviceScaleFactor == 2) |
| 602 draw2xMarker(&bitmap, index); | 605 draw2xMarker(&bitmap, index); |
| 603 else | 606 else |
| 604 ASSERT_NOT_REACHED(); | 607 ASSERT_NOT_REACHED(); |
| 605 | 608 |
| 606 misspellBitmap[index] = new SkBitmap(bitmap); | 609 misspellBitmap[index] = new SkBitmap(bitmap); |
| 607 #endif | 610 #endif |
| 608 } | 611 } |
| 609 | 612 |
| 610 #if OS(MACOSX) | 613 #if OS(MACOSX) |
| 611 SkScalar originX = WebCoreFloatToSkScalar(pt.x()) * deviceScaleFactor; | 614 // Position already includes zoom and device scale factor. |
| 612 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) * deviceScaleFactor; | 615 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); |
| 616 SkScalar originY = WebCoreFloatToSkScalar(pt.y()); |
| 613 | 617 |
| 614 // Make sure to draw only complete dots. | 618 // Make sure to draw only complete dots, and finish inside the marked text. |
| 615 int rowPixels = misspellBitmap[index]->width(); | 619 float rowPixels = misspellBitmap[index]->width() * zoom / deviceScaleFactor; |
| 616 float widthMod = fmodf(width * deviceScaleFactor, rowPixels); | 620 float dotCount = floorf(width / rowPixels); |
| 617 if (rowPixels - widthMod > deviceScaleFactor) | 621 width = dotCount * rowPixels; |
| 618 width -= widthMod / deviceScaleFactor; | |
| 619 #else | 622 #else |
| 620 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); | 623 SkScalar originX = WebCoreFloatToSkScalar(pt.x()); |
| 621 | 624 |
| 622 // Offset it vertically by 1 so that there's some space under the text. | 625 // Offset it vertically by 1 so that there's some space under the text. |
| 623 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1; | 626 SkScalar originY = WebCoreFloatToSkScalar(pt.y()) + 1; |
| 624 originX *= deviceScaleFactor; | |
| 625 originY *= deviceScaleFactor; | |
| 626 #endif | 627 #endif |
| 627 | 628 |
| 628 SkMatrix localMatrix; | 629 SkMatrix localMatrix; |
| 629 localMatrix.setTranslate(originX, originY); | 630 localMatrix.setScale(zoom / deviceScaleFactor, zoom / deviceScaleFactor); |
| 631 localMatrix.postTranslate(originX, originY); |
| 630 | 632 |
| 631 PaintFlags paint; | 633 PaintFlags paint; |
| 632 paint.setShader(WrapSkShader(SkShader::MakeBitmapShader( | 634 paint.setShader(WrapSkShader(SkShader::MakeBitmapShader( |
| 633 *misspellBitmap[index], SkShader::kRepeat_TileMode, | 635 *misspellBitmap[index], SkShader::kRepeat_TileMode, |
| 634 SkShader::kRepeat_TileMode, &localMatrix))); | 636 SkShader::kRepeat_TileMode, &localMatrix))); |
| 635 | 637 |
| 636 SkRect rect; | 638 SkRect rect; |
| 637 rect.set(originX, originY, | 639 rect.set( |
| 638 originX + WebCoreFloatToSkScalar(width) * deviceScaleFactor, | 640 originX, originY, originX + WebCoreFloatToSkScalar(width), |
| 639 originY + SkIntToScalar(misspellBitmap[index]->height())); | 641 originY + |
| 642 SkIntToScalar(misspellBitmap[index]->height() / deviceScaleFactor) * |
| 643 zoom); |
| 640 | 644 |
| 641 if (deviceScaleFactor == 2) { | |
| 642 save(); | |
| 643 scale(0.5, 0.5); | |
| 644 } | |
| 645 drawRect(rect, paint); | 645 drawRect(rect, paint); |
| 646 if (deviceScaleFactor == 2) | |
| 647 restore(); | |
| 648 } | 646 } |
| 649 | 647 |
| 650 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { | 648 void GraphicsContext::drawLineForText(const FloatPoint& pt, float width) { |
| 651 if (contextDisabled()) | 649 if (contextDisabled()) |
| 652 return; | 650 return; |
| 653 | 651 |
| 654 if (width <= 0) | 652 if (width <= 0) |
| 655 return; | 653 return; |
| 656 | 654 |
| 657 PaintFlags paint; | 655 PaintFlags paint; |
| (...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1417 static const SkPMColor colors[] = { | 1415 static const SkPMColor colors[] = { |
| 1418 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red | 1416 SkPreMultiplyARGB(0x60, 0xFF, 0x00, 0x00), // More transparent red |
| 1419 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray | 1417 SkPreMultiplyARGB(0x60, 0xC0, 0xC0, 0xC0) // More transparent gray |
| 1420 }; | 1418 }; |
| 1421 | 1419 |
| 1422 return colors[index]; | 1420 return colors[index]; |
| 1423 } | 1421 } |
| 1424 #endif | 1422 #endif |
| 1425 | 1423 |
| 1426 } // namespace blink | 1424 } // namespace blink |
| OLD | NEW |