Merge pull request #6788 from electron/felix-progress-enum

Use enum to declare ProgressState
This commit is contained in:
Cheng Zhao 2016-08-18 14:35:00 +09:00 committed by GitHub
commit 06d2dfe119
8 changed files with 36 additions and 13 deletions

View file

@ -587,9 +587,21 @@ void Window::SetFocusable(bool focusable) {
void Window::SetProgressBar(double progress, mate::Arguments* args) { void Window::SetProgressBar(double progress, mate::Arguments* args) {
mate::Dictionary options; mate::Dictionary options;
std::string mode; std::string mode;
NativeWindow::ProgressState state = NativeWindow::PROGRESS_NORMAL;
args->GetNext(&options) && options.Get("mode", &mode); 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, void Window::SetOverlayIcon(const gfx::Image& overlay,

View file

@ -143,8 +143,16 @@ class NativeWindow : public base::SupportsUserData,
virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0; virtual gfx::AcceleratedWidget GetAcceleratedWidget() = 0;
// Taskbar/Dock APIs. // 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, virtual void SetProgressBar(double progress,
const std::string& mode) = 0; const ProgressState state) = 0;
virtual void SetOverlayIcon(const gfx::Image& overlay, virtual void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) = 0; const std::string& description) = 0;

View file

@ -85,7 +85,7 @@ class NativeWindowMac : public NativeWindow,
void SetParentWindow(NativeWindow* parent) override; void SetParentWindow(NativeWindow* parent) override;
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;
gfx::AcceleratedWidget GetAcceleratedWidget() 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, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override; const std::string& description) override;
void SetVisibleOnAllWorkspaces(bool visible) override; void SetVisibleOnAllWorkspaces(bool visible) override;

View file

@ -983,7 +983,7 @@ gfx::AcceleratedWidget NativeWindowMac::GetAcceleratedWidget() {
return inspectable_web_contents()->GetView()->GetNativeView(); 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]; NSDockTile* dock_tile = [NSApp dockTile];
// For the first time API invoked, we need to create a ContentView in DockTile. // For the first time API invoked, we need to create a ContentView in DockTile.

View file

@ -907,9 +907,9 @@ gfx::NativeWindow NativeWindowViews::GetNativeWindow() {
} }
void NativeWindowViews::SetProgressBar( void NativeWindowViews::SetProgressBar(
double progress, const std::string& mode) { double progress, NativeWindow::ProgressState state) {
#if defined(OS_WIN) #if defined(OS_WIN)
taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, mode); taskbar_host_.SetProgressBar(GetAcceleratedWidget(), progress, state);
#elif defined(USE_X11) #elif defined(USE_X11)
if (unity::IsRunning()) { if (unity::IsRunning()) {
unity::SetProgressFraction(progress); unity::SetProgressFraction(progress);

View file

@ -104,7 +104,7 @@ class NativeWindowViews : public NativeWindow,
gfx::NativeWindow GetNativeWindow() override; gfx::NativeWindow GetNativeWindow() override;
void SetOverlayIcon(const gfx::Image& overlay, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description) override; 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; void SetAutoHideMenuBar(bool auto_hide) override;
bool IsMenuBarAutoHide() override; bool IsMenuBarAutoHide() override;
void SetMenuBarVisibility(bool visible) override; void SetMenuBarVisibility(bool visible) override;

View file

@ -12,6 +12,7 @@
#include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkBitmap.h"
#include "ui/display/win/screen_win.h" #include "ui/display/win/screen_win.h"
#include "ui/gfx/icon_util.h" #include "ui/gfx/icon_util.h"
#include "atom/browser/native_window.h"
namespace atom { namespace atom {
@ -127,23 +128,23 @@ void TaskbarHost::RestoreThumbarButtons(HWND window) {
} }
bool TaskbarHost::SetProgressBar( bool TaskbarHost::SetProgressBar(
HWND window, double value, const std::string& mode) { HWND window, double value, const NativeWindow::ProgressState state) {
if (!InitializeTaskbar()) if (!InitializeTaskbar())
return false; return false;
bool success; bool success;
if (value > 1.0 || mode == "indeterminate") { if (value > 1.0 || state == NativeWindow::PROGRESS_INDETERMINATE) {
success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_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)); success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_NOPROGRESS));
} else { } else {
// Unless SetProgressState set a blocking state (TBPF_ERROR, TBPF_PAUSED) // Unless SetProgressState set a blocking state (TBPF_ERROR, TBPF_PAUSED)
// for the window, a call to SetProgressValue assumes the TBPF_NORMAL // for the window, a call to SetProgressValue assumes the TBPF_NORMAL
// state even if it is not explicitly set. // state even if it is not explicitly set.
// SetProgressValue overrides and clears the TBPF_INDETERMINATE state. // SetProgressValue overrides and clears the TBPF_INDETERMINATE state.
if (mode == "error") { if (state == NativeWindow::PROGRESS_ERROR) {
success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_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)); success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_PAUSED));
} else { } else {
success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_NORMAL)); success = SUCCEEDED(taskbar_->SetProgressState(window, TBPF_NORMAL));

View file

@ -15,6 +15,7 @@
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "atom/browser/native_window.h"
namespace atom { namespace atom {
@ -37,7 +38,8 @@ class TaskbarHost {
void RestoreThumbarButtons(HWND window); void RestoreThumbarButtons(HWND window);
// Set the progress state in taskbar. // 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. // Set the overlay icon in taskbar.
bool SetOverlayIcon( bool SetOverlayIcon(