]> khamidou — GitHub mirrors - electron.git/commitdiff
win: Implement SetProgressBar API.
authorHaojian Wu <hokein.wu@gmail.com>
Wed, 17 Sep 2014 01:42:47 +0000 (09:42 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Wed, 17 Sep 2014 01:42:47 +0000 (09:42 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.h
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index 9b7cb204df3baf969651e81078a77260261156ed..40498153c3fee3ec6fc07b6f550ccf9d74969fb3 100644 (file)
@@ -366,6 +366,10 @@ void Window::Print(mate::Arguments* args) {
   window_->Print(settings.silent, settings.print_backgournd);
 }
 
+void Window::SetProgressBar(double progress) {
+  window_->SetProgressBar(progress);
+}
+
 mate::Handle<WebContents> Window::GetWebContents(v8::Isolate* isolate) const {
   return WebContents::Create(isolate, window_->GetWebContents());
 }
@@ -428,6 +432,7 @@ void Window::BuildPrototype(v8::Isolate* isolate,
       .SetMethod("isWebViewFocused", &Window::IsWebViewFocused)
       .SetMethod("capturePage", &Window::CapturePage)
       .SetMethod("print", &Window::Print)
+      .SetMethod("setProgressBar", &Window::SetProgressBar)
       .SetMethod("_getWebContents", &Window::GetWebContents)
       .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents);
 }
index e558b5ce00d39f0d78c1590175139034e5aaf123..25ea3700cf814023599a5b481b31a768d8bac2e2 100644 (file)
@@ -103,6 +103,7 @@ class Window : public mate::EventEmitter,
   bool IsDocumentEdited();
   void CapturePage(mate::Arguments* args);
   void Print(mate::Arguments* args);
+  void SetProgressBar(double progress);
 
   // APIs for WebContents.
   mate::Handle<WebContents> GetWebContents(v8::Isolate* isolate) const;
index 1da62ce3f7bdedb5f217ce64579335490c3d6258..929c1aabc5bbb4b0a2193bc266e9a26614ab644f 100644 (file)
@@ -140,6 +140,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   virtual void SetMenu(ui::MenuModel* menu);
   virtual bool HasModalDialog();
   virtual gfx::NativeWindow GetNativeWindow() = 0;
+  virtual void SetProgressBar(double progress) = 0;
 
   virtual bool IsClosed() const { return is_closed_; }
   virtual void OpenDevTools();
index 3892b7181b945fbfaa094b04f16e8a914eda1c96..d3eec5c1c57fda00e67117a0d888daced460d507 100644 (file)
@@ -43,7 +43,9 @@
 #elif defined(OS_WIN)
 #include "atom/browser/ui/views/win_frame_view.h"
 #include "base/win/scoped_comptr.h"
+#include "base/win/windows_version.h"
 #include "ui/base/win/shell.h"
+#include "ui/views/win/hwnd_util.h"
 #endif
 
 namespace atom {
@@ -479,6 +481,27 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
   return window_->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), progress);
+  }
+#endif
+}
+
 gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
   return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
 }
index 3d81a68be2247404a97968752e268d4a5411c182..b38769c392652aa435179181d26386fba19f1ba1 100644 (file)
@@ -71,6 +71,7 @@ class NativeWindowViews : public NativeWindow,
   virtual bool IsKiosk() OVERRIDE;
   virtual void SetMenu(ui::MenuModel* menu_model) OVERRIDE;
   virtual gfx::NativeWindow GetNativeWindow() OVERRIDE;
+  virtual void SetProgressBar(double value) OVERRIDE;
 
   gfx::AcceleratedWidget GetAcceleratedWidget();