OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Many of these functions are based on those found in | 5 // Many of these functions are based on those found in |
6 // webkit/port/platform/PasteboardWin.cpp | 6 // webkit/port/platform/PasteboardWin.cpp |
7 | 7 |
8 #include "ui/base/clipboard/clipboard.h" | 8 #include "ui/base/clipboard/clipboard.h" |
9 | 9 |
10 #include <shlobj.h> | 10 #include <shlobj.h> |
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 break; | 557 break; |
558 case 24: | 558 case 24: |
559 break; | 559 break; |
560 default: | 560 default: |
561 NOTREACHED(); | 561 NOTREACHED(); |
562 } | 562 } |
563 const void* bitmap_bits = reinterpret_cast<const char*>(bitmap) | 563 const void* bitmap_bits = reinterpret_cast<const char*>(bitmap) |
564 + bitmap->bmiHeader.biSize + color_table_length * sizeof(RGBQUAD); | 564 + bitmap->bmiHeader.biSize + color_table_length * sizeof(RGBQUAD); |
565 | 565 |
566 gfx::Canvas canvas(gfx::Size(bitmap->bmiHeader.biWidth, | 566 gfx::Canvas canvas(gfx::Size(bitmap->bmiHeader.biWidth, |
567 bitmap->bmiHeader.biHeight), false); | 567 bitmap->bmiHeader.biHeight), |
| 568 ui::SCALE_FACTOR_100P, |
| 569 false); |
568 { | 570 { |
569 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); | 571 skia::ScopedPlatformPaint scoped_platform_paint(canvas.sk_canvas()); |
570 HDC dc = scoped_platform_paint.GetPlatformSurface(); | 572 HDC dc = scoped_platform_paint.GetPlatformSurface(); |
571 ::SetDIBitsToDevice(dc, 0, 0, bitmap->bmiHeader.biWidth, | 573 ::SetDIBitsToDevice(dc, 0, 0, bitmap->bmiHeader.biWidth, |
572 bitmap->bmiHeader.biHeight, 0, 0, 0, | 574 bitmap->bmiHeader.biHeight, 0, 0, 0, |
573 bitmap->bmiHeader.biHeight, bitmap_bits, bitmap, | 575 bitmap->bmiHeader.biHeight, bitmap_bits, bitmap, |
574 DIB_RGB_COLORS); | 576 DIB_RGB_COLORS); |
575 } | 577 } |
576 // Windows doesn't really handle alpha channels well in many situations. When | 578 // Windows doesn't really handle alpha channels well in many situations. When |
577 // the source image is < 32 bpp, we force the bitmap to be opaque. When the | 579 // the source image is < 32 bpp, we force the bitmap to be opaque. When the |
578 // source image is 32 bpp, the alpha channel might still contain garbage data. | 580 // source image is 32 bpp, the alpha channel might still contain garbage data. |
579 // Since Windows uses premultiplied alpha, we scan for instances where | 581 // Since Windows uses premultiplied alpha, we scan for instances where |
580 // (R, G, B) > A. If there are any invalid premultiplied colors in the image, | 582 // (R, G, B) > A. If there are any invalid premultiplied colors in the image, |
581 // we assume the alpha channel contains garbage and force the bitmap to be | 583 // we assume the alpha channel contains garbage and force the bitmap to be |
582 // opaque as well. Note that this heuristic will fail on a transparent bitmap | 584 // opaque as well. Note that this heuristic will fail on a transparent bitmap |
583 // containing only black pixels... | 585 // containing only black pixels... |
584 const SkBitmap& device_bitmap = | 586 const SkBitmap& device_bitmap = |
585 canvas.sk_canvas()->getDevice()->accessBitmap(true); | 587 canvas.sk_canvas()->getDevice()->accessBitmap(true); |
586 { | 588 { |
587 SkAutoLockPixels lock(device_bitmap); | 589 SkAutoLockPixels lock(device_bitmap); |
588 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || | 590 bool has_invalid_alpha_channel = bitmap->bmiHeader.biBitCount < 32 || |
589 BitmapHasInvalidPremultipliedColors(device_bitmap); | 591 BitmapHasInvalidPremultipliedColors(device_bitmap); |
590 if (has_invalid_alpha_channel) { | 592 if (has_invalid_alpha_channel) { |
591 MakeBitmapOpaque(device_bitmap); | 593 MakeBitmapOpaque(device_bitmap); |
592 } | 594 } |
593 } | 595 } |
594 | 596 |
595 return canvas.ExtractBitmap(); | 597 return canvas.ExtractImageRep().sk_bitmap(); |
596 } | 598 } |
597 | 599 |
598 void Clipboard::ReadCustomData(Buffer buffer, | 600 void Clipboard::ReadCustomData(Buffer buffer, |
599 const string16& type, | 601 const string16& type, |
600 string16* result) const { | 602 string16* result) const { |
601 DCHECK_EQ(buffer, BUFFER_STANDARD); | 603 DCHECK_EQ(buffer, BUFFER_STANDARD); |
602 | 604 |
603 // Acquire the clipboard. | 605 // Acquire the clipboard. |
604 ScopedClipboard clipboard; | 606 ScopedClipboard clipboard; |
605 if (!clipboard.Acquire(GetClipboardWindow())) | 607 if (!clipboard.Acquire(GetClipboardWindow())) |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
837 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", | 839 clipboard_owner_ = ::CreateWindow(L"ClipboardOwnerWindowClass", |
838 L"ClipboardOwnerWindow", | 840 L"ClipboardOwnerWindow", |
839 0, 0, 0, 0, 0, | 841 0, 0, 0, 0, 0, |
840 HWND_MESSAGE, | 842 HWND_MESSAGE, |
841 0, 0, 0); | 843 0, 0, 0); |
842 } | 844 } |
843 return clipboard_owner_; | 845 return clipboard_owner_; |
844 } | 846 } |
845 | 847 |
846 } // namespace ui | 848 } // namespace ui |
OLD | NEW |