|
43 | 43 | #include "ui/gfx/native_widget_types.h"
|
44 | 44 | #include "ui/gfx/win/hwnd_util.h"
|
45 | 45 | #include "ui/gfx/path.h"
|
| 46 | +#include "ui/gfx/canvas.h" |
| 47 | +#include "ui/gfx/icon_util.h" |
| 48 | +#include "ui/gfx/font_list.h" |
| 49 | +#include "ui/gfx/platform_font.h" |
46 | 50 | #include "ui/gfx/image/image_skia_operations.h"
|
47 | 51 | #include "ui/views/controls/webview/webview.h"
|
48 | 52 | #include "ui/views/layout/box_layout.h"
|
@@ -470,8 +474,51 @@ void NativeWindowWin::FlashFrame(bool flash) {
|
470 | 474 | window_->FlashFrame(flash);
|
471 | 475 | }
|
472 | 476 |
|
| 477 | +HICON createBadgeIcon(const HWND hWnd, const TCHAR *value, const int sizeX, const int sizeY) { |
| 478 | + // canvas for the overlay icon |
| 479 | + gfx::Canvas canvas(gfx::Size(sizeX, sizeY), 1, false); |
| 480 | + |
| 481 | + // drawing red circle |
| 482 | + SkPaint paint; |
| 483 | + paint.setColor(SK_ColorRED); |
| 484 | + canvas.DrawCircle(gfx::Point(sizeX / 2, sizeY / 2), sizeX / 2, paint); |
| 485 | + |
| 486 | + // drawing the text |
| 487 | + gfx::PlatformFont *platform_font = gfx::PlatformFont::CreateDefault(); |
| 488 | + const int fontSize = sizeY*0.65f; |
| 489 | + gfx::Font font(platform_font->GetFontName(), fontSize); |
| 490 | + platform_font->Release(); |
| 491 | + platform_font = NULL; |
| 492 | + const int yMargin = (sizeY - fontSize) / 2; |
| 493 | + canvas.DrawStringRectWithFlags(value, gfx::FontList(font), SK_ColorWHITE, gfx::Rect(sizeX, fontSize + yMargin + 1), gfx::Canvas::TEXT_ALIGN_CENTER); |
| 494 | + |
| 495 | + // return the canvas as windows native icon handle |
| 496 | + return IconUtil::CreateHICONFromSkBitmap(canvas.ExtractImageRep().sk_bitmap()); |
| 497 | +} |
| 498 | + |
473 | 499 | void NativeWindowWin::SetBadgeLabel(const std::string& badge) {
|
474 |
| - // TODO |
| 500 | + base::win::ScopedComPtr<ITaskbarList3> taskbar; |
| 501 | + HRESULT result = taskbar.CreateInstance(CLSID_TaskbarList, NULL, |
| 502 | + CLSCTX_INPROC_SERVER); |
| 503 | + |
| 504 | + if (FAILED(result)) { |
| 505 | + VLOG(1) << "Failed creating a TaskbarList3 object: " << result; |
| 506 | + return; |
| 507 | + } |
| 508 | + |
| 509 | + result = taskbar->HrInit(); |
| 510 | + if (FAILED(result)) { |
| 511 | + LOG(ERROR) << "Failed initializing an ITaskbarList3 interface."; |
| 512 | + return; |
| 513 | + } |
| 514 | + |
| 515 | + HICON icon = NULL; |
| 516 | + HWND hWnd = window_->GetNativeWindow(); |
| 517 | + if (badge.size()) |
| 518 | + icon = createBadgeIcon(hWnd, UTF8ToUTF16(badge).c_str(), 32, 32); |
| 519 | + |
| 520 | + taskbar->SetOverlayIcon(hWnd, icon, _T("Status")); |
| 521 | + DestroyIcon(icon); |
475 | 522 | }
|
476 | 523 |
|
477 | 524 | void NativeWindowWin::SetKiosk(bool kiosk) {
|
|
0 commit comments