From 86218fe7736b1b89516936faf04b3764fe8f0604 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Thu, 14 Jul 2016 13:27:16 -0700 Subject: [PATCH] win: Add setThumbnailClip window API --- atom/browser/api/atom_api_window.cc | 7 +++++++ atom/browser/api/atom_api_window.h | 1 + atom/browser/ui/win/taskbar_host.cc | 16 ++++++++++++++++ atom/browser/ui/win/taskbar_host.h | 4 ++++ 4 files changed, 28 insertions(+) diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index afa04c31a46e..848294045428 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -649,6 +649,12 @@ bool Window::IsWindowMessageHooked(UINT message) { void Window::UnhookAllWindowMessages() { messages_callback_map_.clear(); } + +bool Window::SetThumbnailClip(const gfx::Rect& region) { + auto window = static_cast(window_.get()); + return window->taskbar_host().SetThumbnailClip( + window_->GetAcceleratedWidget(), region); +} #endif #if defined(TOOLKIT_VIEWS) @@ -836,6 +842,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("isWindowMessageHooked", &Window::IsWindowMessageHooked) .SetMethod("unhookWindowMessage", &Window::UnhookWindowMessage) .SetMethod("unhookAllWindowMessages", &Window::UnhookAllWindowMessages) + .SetMethod("setThumbnailClip", &Window::SetThumbnailClip) #endif #if defined(TOOLKIT_VIEWS) .SetMethod("setIcon", &Window::SetIcon) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index f4b481a5cef8..f681e1c036ff 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -179,6 +179,7 @@ class Window : public mate::TrackableObject, bool IsWindowMessageHooked(UINT message); void UnhookWindowMessage(UINT message); void UnhookAllWindowMessages(); + bool SetThumbnailClip(const gfx::Rect& window_region); #endif #if defined(TOOLKIT_VIEWS) diff --git a/atom/browser/ui/win/taskbar_host.cc b/atom/browser/ui/win/taskbar_host.cc index 78bcc578c19f..8fef5e08a3fb 100644 --- a/atom/browser/ui/win/taskbar_host.cc +++ b/atom/browser/ui/win/taskbar_host.cc @@ -142,6 +142,22 @@ bool TaskbarHost::SetOverlayIcon( window, icon.get(), base::UTF8ToUTF16(text).c_str())); } +bool TaskbarHost::SetThumbnailClip(HWND window, const gfx::Rect& region) { + if (!InitializeTaskbar()) + return false; + + if (region.IsEmpty()) { + return SUCCEEDED(taskbar_->SetThumbnailClip(window, NULL)); + } else { + RECT rect; + rect.left = region.x(); + rect.right = region.right(); + rect.top = region.y(); + rect.bottom = region.bottom(); + return SUCCEEDED(taskbar_->SetThumbnailClip(window, &rect)); + } +} + bool TaskbarHost::HandleThumbarButtonEvent(int button_id) { if (ContainsKey(callback_map_, button_id)) { auto callback = callback_map_[button_id]; diff --git a/atom/browser/ui/win/taskbar_host.h b/atom/browser/ui/win/taskbar_host.h index 0cd5aa714fc2..c10e05f764dd 100644 --- a/atom/browser/ui/win/taskbar_host.h +++ b/atom/browser/ui/win/taskbar_host.h @@ -13,6 +13,7 @@ #include "base/callback.h" #include "base/win/scoped_comptr.h" +#include "ui/gfx/geometry/rect.h" #include "ui/gfx/image/image.h" namespace atom { @@ -40,6 +41,9 @@ class TaskbarHost { bool SetOverlayIcon( HWND window, const gfx::Image& overlay, const std::string& text); + // Set the region of the window to show as a thumbnail in taskbar. + bool TaskbarHost::SetThumbnailClip(HWND window, const gfx::Rect& region); + // Called by the window that there is a button in thumbar clicked. bool HandleThumbarButtonEvent(int button_id);