]> khamidou — GitHub mirrors - electron.git/commitdiff
Move SetProgressBar to TaskbarHost
authorCheng Zhao <zcbenz@gmail.com>
Thu, 6 Aug 2015 04:54:00 +0000 (12:54 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 6 Aug 2015 04:54:00 +0000 (12:54 +0800)
atom/browser/native_window_views.cc
atom/browser/ui/win/taskbar_host.cc
atom/browser/ui/win/taskbar_host.h

index 759249e5aa4ef039de29f4286c27ab3f8896ad93..868ca5da19291e081dd6c24eeb5c9b5795a69224 100644 (file)
@@ -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<ITaskbarList3> 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<int>(progress * 100),
-                              100);
-  }
+  taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress);
 #elif defined(USE_X11)
   if (unity::IsRunning()) {
     unity::SetProgressFraction(progress);
index a6ab44d0723d6ed466a3bed99552425928304406..e3ee3fcd47c6f6ff1be1e5efcaf6770d3680fecb 100644 (file)
@@ -123,6 +123,25 @@ bool TaskbarHost::SetThumbarButtons(
   return SUCCEEDED(r);
 }
 
+bool TaskbarHost::SetProgressBar(HWND window, double value) {
+  base::win::ScopedComPtr<ITaskbarList3> 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<int>(value * 100), 100);
+  return SUCCEEDED(r);
+}
+
 bool TaskbarHost::HandleThumbarButtonEvent(int button_id) {
   if (ContainsKey(callback_map_, button_id)) {
     auto callback = callback_map_[button_id];
index f3172902af112827ed07016fda1222bfe7e5e65c..22ea4cbb31a2de05617207d1fcf72efaab7156b8 100644 (file)
@@ -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<ThumbarButton>& 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);