From 2d6f8350cb5ac89f7527449e823196084256f761 Mon Sep 17 00:00:00 2001 From: Cheng Zhao Date: Thu, 6 Aug 2015 12:54:00 +0800 Subject: [PATCH] Move SetProgressBar to TaskbarHost --- atom/browser/native_window_views.cc | 19 +------------------ atom/browser/ui/win/taskbar_host.cc | 19 +++++++++++++++++++ atom/browser/ui/win/taskbar_host.h | 5 ++++- 3 files changed, 24 insertions(+), 19 deletions(-) diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 759249e5..868ca5da 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -621,24 +621,7 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() { void NativeWindowViews::SetProgressBar(double progress) { #if defined(OS_WIN) - if (base::win::GetVersion() < base::win::VERSION_WIN7) - return; - base::win::ScopedComPtr taskbar; - if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, NULL, - CLSCTX_INPROC_SERVER) || - FAILED(taskbar->HrInit()))) { - return; - } - HWND frame = views::HWNDForNativeWindow(GetNativeWindow()); - if (progress > 1.0) { - taskbar->SetProgressState(frame, TBPF_INDETERMINATE); - } else if (progress < 0) { - taskbar->SetProgressState(frame, TBPF_NOPROGRESS); - } else if (progress >= 0) { - taskbar->SetProgressValue(frame, - static_cast(progress * 100), - 100); - } + taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress); #elif defined(USE_X11) if (unity::IsRunning()) { unity::SetProgressFraction(progress); diff --git a/atom/browser/ui/win/taskbar_host.cc b/atom/browser/ui/win/taskbar_host.cc index a6ab44d0..e3ee3fcd 100644 --- a/atom/browser/ui/win/taskbar_host.cc +++ b/atom/browser/ui/win/taskbar_host.cc @@ -123,6 +123,25 @@ bool TaskbarHost::SetThumbarButtons( return SUCCEEDED(r); } +bool TaskbarHost::SetProgressBar(HWND window, double value) { + base::win::ScopedComPtr taskbar; + if (FAILED(taskbar.CreateInstance(CLSID_TaskbarList, + nullptr, + CLSCTX_INPROC_SERVER)) || + FAILED(taskbar->HrInit())) { + return false; + } + + HRESULT r; + if (value > 1.0) + r = taskbar->SetProgressState(window, TBPF_INDETERMINATE); + else if (value < 0) + r = taskbar->SetProgressState(window, TBPF_NOPROGRESS); + else + r= taskbar->SetProgressValue(window, static_cast(value * 100), 100); + return SUCCEEDED(r); +} + 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 f3172902..22ea4cbb 100644 --- a/atom/browser/ui/win/taskbar_host.h +++ b/atom/browser/ui/win/taskbar_host.h @@ -28,10 +28,13 @@ class TaskbarHost { TaskbarHost(); virtual ~TaskbarHost(); - // Add or update the buttons in thumbar + // Add or update the buttons in thumbar. bool SetThumbarButtons( HWND window, const std::vector& buttons); + // Sets the progress state in taskbar. + bool SetProgressBar(HWND window, double value); + // Called by the window that there is a button in thumbar clicked. bool HandleThumbarButtonEvent(int button_id); -- 2.43.0