diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 1327d8de6f..acc4d60581 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -587,9 +587,21 @@ void Window::SetFocusable(bool focusable) { void Window::SetProgressBar(double progress, mate::Arguments* args) { mate::Dictionary options; std::string mode; + NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL; + args->GetNext(&options) && options.Get("mode", &mode); - window_->SetProgressBar(progress, mode); + if (mode == "error") { + state = NativeWindow::PROGRESS_ERROR; + } else if (mode == "paused") { + state = NativeWindow::PROGRESS_PAUSED; + } else if (mode == "indeterminate") { + state = NativeWindow::PROGRESS_INDETERMINATE; + } else if (mode == "none") { + state = NativeWindow::PROGRESS_NONE; + } + + window_->SetProgressBar(progress, state); } void Window::SetOverlayIcon(const gfx::Image& overlay, diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 974daf8d3b..76c47417bd 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -143,8 +143,16 @@ class NativeWindow : public base::SupportsUserData, virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; // Taskbar/Dock APIs. + enum ProgressState { + PROGRESS_NONE, // no progress, no marking + PROGRESS_INDETERMINATE, // progress, indeterminate + PROGRESS_ERROR, // progress, errored (red) + PROGRESS_PAUSED, // progress, paused (yellow) + PROGRESS_NORMAL, // progress, not marked (green) + }; + virtual void SetProgressBar(double progress, - const std::string& mode) = 0; + const ProgressState state) = 0; virtual void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 1a04ff9a49..5d8d7dacc6 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -85,7 +85,7 @@ class NativeWindowMac : public NativeWindow, void SetParentWindow(NativeWindow* parent) override; gfx::NativeWindow GetNativeWindow() override; gfx::AcceleratedWidget GetAcceleratedWidget() override; - void SetProgressBar(double progress, const std::string& mode) override; + void SetProgressBar(double progress, const ProgressState state) override; void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) override; void SetVisibleOnAllWorkspaces(bool visible) override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f1145348e8..12063d23ba 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -983,7 +983,7 @@ gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() { return inspectable_web_contents()->GetView()->GetNativeView(); } -void NativeWindowMac::SetProgressBar(double progress, const std::string& mode) { +void NativeWindowMac::SetProgressBar(double progress, const NativeWindow::ProgressState state) { NSDockTile* dock_tile = [NSApp dockTile]; // For the first time API invoked, we need to create a ContentView in DockTile. diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 5f5ca68749..30ff4f962a 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -907,9 +907,9 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() { } void NativeWindowViews::SetProgressBar( - double progress, const std::string& mode) { + double progress, NativeWindow::ProgressState state) { #if defined(OS_WIN) - taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, mode); + taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, state); #elif defined(USE_X11) if (unity::IsRunning()) { unity::SetProgressFraction(progress); diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 82c260aeb5..d0d45fc535 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -104,7 +104,7 @@ class NativeWindowViews : public NativeWindow, gfx::NativeWindow GetNativeWindow() override; void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) override; - void SetProgressBar(double value, const std::string& mode) override; + void SetProgressBar(double progress, const ProgressState state) override; void SetAutoHideMenuBar(bool auto_hide) override; bool IsMenuBarAutoHide() override; void SetMenuBarVisibility(bool visible) override; diff --git a/atom/browser/ui/win/taskbar_host.cc b/atom/browser/ui/win/taskbar_host.cc index 00bff1c88a..913e97c9da 100644 --- a/atom/browser/ui/win/taskbar_host.cc +++ b/atom/browser/ui/win/taskbar_host.cc @@ -12,6 +12,7 @@ #include "third_party/skia/include/core/SkBitmap.h" #include "ui/display/win/screen_win.h" #include "ui/gfx/icon_util.h" +#include "atom/browser/native_window.h" namespace atom { @@ -127,23 +128,23 @@ void TaskbarHost::RestoreThumbarButtons(HWND window) { } bool TaskbarHost::SetProgressBar( - HWND window, double value, const std::string& mode) { + HWND window, double value, const NativeWindow::ProgressState state) { if (!InitializeTaskbar()) return false; bool success; - if (value > 1.0 || mode == "indeterminate") { + if (value > 1.0 || state == NativeWindow::PROGRESS_INDETERMINATE) { success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_INDETERMINATE)); - } else if (value < 0 || mode == "none") { + } else if (value < 0 || state == NativeWindow::PROGRESS_NONE) { success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_NOPROGRESS)); } else { // Unless SetProgressState set a blocking state (TBPF_ERROR, TBPF_PAUSED) // for the window, a call to SetProgressValue assumes the TBPF_NORMAL // state even if it is not explicitly set. // SetProgressValue overrides and clears the TBPF_INDETERMINATE state. - if (mode == "error") { + if (state == NativeWindow::PROGRESS_ERROR) { success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_ERROR)); - } else if (mode == "paused") { + } else if (state == NativeWindow::PROGRESS_PAUSED) { success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_PAUSED)); } else { success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_NORMAL)); diff --git a/atom/browser/ui/win/taskbar_host.h b/atom/browser/ui/win/taskbar_host.h index a9263d9e89..cbfcff57f8 100644 --- a/atom/browser/ui/win/taskbar_host.h +++ b/atom/browser/ui/win/taskbar_host.h @@ -15,6 +15,7 @@ #include "base/win/scoped_comptr.h" #include "ui/gfx/geometry/rect.h" #include "ui/gfx/image/image.h" +#include "atom/browser/native_window.h" namespace atom { @@ -37,7 +38,8 @@ class TaskbarHost { void RestoreThumbarButtons(HWND window); // Set the progress state in taskbar. - bool SetProgressBar(HWND window, double value, const std::string& mode); + bool SetProgressBar( + HWND window, double value, const NativeWindow::ProgressState state); // Set the overlay icon in taskbar. bool SetOverlayIcon(