diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 0b2c8c9ece79..2cbe8be566e2 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -18,14 +18,20 @@ #include "native_mate/dictionary.h" #include "ui/gfx/geometry/rect.h" +#if defined(OS_WIN) +#include "atom/browser/native_window_views.h" +#include "atom/browser/ui/win/taskbar_host.h" +#endif + #include "atom/common/node_includes.h" +#if defined(OS_WIN) namespace mate { template<> -struct Converter { +struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, - atom::NativeWindow::ThumbarButton* out) { + atom::TaskbarHost::ThumbarButton* out) { mate::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; @@ -37,6 +43,7 @@ struct Converter { }; } // namespace mate +#endif namespace atom { @@ -431,9 +438,17 @@ void Window::SetOverlayIcon(const gfx::Image& overlay, window_->SetOverlayIcon(overlay, description); } -void Window::SetThumbarButtons( - const std::vector& buttons) { - window_->SetThumbarButtons(buttons); +void Window::SetThumbarButtons(mate::Arguments* args) { +#if defined(OS_WIN) + std::vector buttons; + if (!args->GetNext(&buttons)) { + args->ThrowError(); + return; + } + auto window = static_cast(window_.get()); + window->taskbar_host().SetThumbarButtons(window->GetAcceleratedWidget(), + buttons); +#endif } void Window::SetMenu(v8::Isolate* isolate, v8::Local value) { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 7742c8a9fa9b..389c03ab9d40 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -130,8 +130,7 @@ class Window : public mate::TrackableObject, void SetProgressBar(double progress); void SetOverlayIcon(const gfx::Image& overlay, const std::string& description); - void SetThumbarButtons( - const std::vector& buttons); + void SetThumbarButtons(mate::Arguments* args); void SetMenu(v8::Isolate* isolate, v8::Local menu); void SetAutoHideMenuBar(bool auto_hide); bool IsMenuBarAutoHide(); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 91770af316e3..96085846bca8 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -277,11 +277,6 @@ bool NativeWindow::HasModalDialog() { return has_dialog_attached_; } -bool NativeWindow::SetThumbarButtons( - const std::vector& buttons) { - return false; -} - void NativeWindow::FocusOnWebView() { web_contents()->GetRenderViewHost()->Focus(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d461215222d6..b9294d38c931 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -60,14 +60,6 @@ class NativeWindow : public content::WebContentsObserver, public brightray::InspectableWebContentsViewDelegate { public: using CapturePageCallback = base::Callback; - using ThumbarButtonClickedCallback = base::Closure; - - struct ThumbarButton { - std::string tooltip; - gfx::Image icon; - std::vector flags; - ThumbarButtonClickedCallback clicked_callback; - }; class DialogScope { public: @@ -103,6 +95,7 @@ class NativeWindow : public content::WebContentsObserver, virtual void Close() = 0; virtual void CloseImmediately() = 0; + virtual bool IsClosed() const { return is_closed_; } virtual void Focus(bool focus) = 0; virtual bool IsFocused() = 0; virtual void Show() = 0; @@ -147,16 +140,17 @@ class NativeWindow : public content::WebContentsObserver, virtual void SetMenu(ui::MenuModel* menu); virtual bool HasModalDialog(); virtual gfx::NativeWindow GetNativeWindow() = 0; + + // Taskbar/Dock APIs. virtual void SetProgressBar(double progress) = 0; virtual void SetOverlayIcon(const gfx::Image& overlay, const std::string& description) = 0; + + // Workspace APIs. virtual void SetVisibleOnAllWorkspaces(bool visible) = 0; virtual bool IsVisibleOnAllWorkspaces() = 0; - virtual bool SetThumbarButtons( - const std::vector& buttons); - - virtual bool IsClosed() const { return is_closed_; } + // Webview APIs. virtual void FocusOnWebView(); virtual void BlurWebView(); virtual bool IsWebViewFocused(); diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index c7fd0b8b3524..759249e5aa4e 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -46,7 +46,6 @@ #elif defined(OS_WIN) #include "atom/browser/ui/views/win_frame_view.h" #include "atom/browser/ui/win/atom_desktop_window_tree_host_win.h" -#include "atom/browser/ui/win/taskbar_host.h" #include "base/win/scoped_comptr.h" #include "base/win/windows_version.h" #include "ui/base/win/shell.h" @@ -718,17 +717,6 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() { return false; } -bool NativeWindowViews::SetThumbarButtons( - const std::vector& buttons) { -#if defined(OS_WIN) - if (!taskbar_host_) - taskbar_host_.reset(new TaskbarHost(GetAcceleratedWidget())); - return taskbar_host_->SetThumbarButtons(buttons); -#else - return false; -#endif -} - gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); } @@ -894,9 +882,8 @@ void NativeWindowViews::GetDevToolsWindowWMClass( bool NativeWindowViews::PreHandleMSG( UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) { // Handle thumbar button click message. - if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED && - taskbar_host_) - return taskbar_host_->HandleThumbarButtonEvent(LOWORD(w_param)); + if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED) + return taskbar_host_.HandleThumbarButtonEvent(LOWORD(w_param)); else return false; } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 0cc79facab12..355f5bd38ef3 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -16,6 +16,7 @@ #if defined(OS_WIN) #include "atom/browser/ui/win/message_handler_delegate.h" +#include "atom/browser/ui/win/taskbar_host.h" #endif namespace views { @@ -30,7 +31,6 @@ class WindowStateWatcher; #if defined(OS_WIN) class AtomDesktopWindowTreeHostWin; -class TaskbarHost; #endif class NativeWindowViews : public NativeWindow, @@ -91,13 +91,15 @@ class NativeWindowViews : public NativeWindow, bool IsMenuBarVisible() override; void SetVisibleOnAllWorkspaces(bool visible) override; bool IsVisibleOnAllWorkspaces() override; - bool SetThumbarButtons( - const std::vector& buttons) override; gfx::AcceleratedWidget GetAcceleratedWidget(); views::Widget* widget() const { return window_.get(); } +#if defined(OS_WIN) + TaskbarHost& taskbar_host() { return taskbar_host_; } +#endif + private: // views::WidgetObserver: void OnWidgetActivationChanged( @@ -180,7 +182,7 @@ class NativeWindowViews : public NativeWindow, // state. bool is_minimized_; // In charge of running taskbar related APIs. - scoped_ptr taskbar_host_; + TaskbarHost taskbar_host_; #endif // Handles unhandled keyboard messages coming back from the renderer process. diff --git a/atom/browser/ui/win/taskbar_host.cc b/atom/browser/ui/win/taskbar_host.cc index 6f74a7d9cb37..3173215a4f6b 100644 --- a/atom/browser/ui/win/taskbar_host.cc +++ b/atom/browser/ui/win/taskbar_host.cc @@ -58,15 +58,14 @@ bool GetThumbarButtonFlags(const std::vector& flags, } // namespace -TaskbarHost::TaskbarHost(HWND window) : is_initialized_(false), - window_(window) { +TaskbarHost::TaskbarHost() : is_initialized_(false) { } TaskbarHost::~TaskbarHost() { } bool TaskbarHost::SetThumbarButtons( - const std::vector& buttons) { + HWND window, const std::vector& buttons) { if (buttons.size() > kMaxButtonsCount) return false; @@ -114,10 +113,10 @@ bool TaskbarHost::SetThumbarButtons( if (!is_initialized_) { is_initialized_ = true; is_success = taskbar->ThumbBarAddButtons( - window_, buttons.size(), thumb_buttons) == S_OK; + window, buttons.size(), thumb_buttons) == S_OK; } else { is_success = taskbar->ThumbBarUpdateButtons( - window_, kMaxButtonsCount, thumb_buttons) == S_OK; + window, kMaxButtonsCount, thumb_buttons) == S_OK; } // Release thumb_buttons' icons, the taskbar makes its own copy. diff --git a/atom/browser/ui/win/taskbar_host.h b/atom/browser/ui/win/taskbar_host.h index e0a9dc89ff4b..2c81a9cdb371 100644 --- a/atom/browser/ui/win/taskbar_host.h +++ b/atom/browser/ui/win/taskbar_host.h @@ -10,28 +10,33 @@ #include #include -#include "atom/browser/native_window.h" +#include "base/callback.h" +#include "ui/gfx/image/image.h" namespace atom { class TaskbarHost { public: - explicit TaskbarHost(HWND window); - ~TaskbarHost(); + struct ThumbarButton { + std::string tooltip; + gfx::Image icon; + std::vector flags; + base::Closure clicked_callback; + }; + + TaskbarHost(); + virtual ~TaskbarHost(); bool SetThumbarButtons( - const std::vector& buttons); + HWND window, const std::vector& buttons); bool HandleThumbarButtonEvent(int button_id); private: - using ThumbarButtonClickedCallbackMap = std::map< - int, NativeWindow::ThumbarButtonClickedCallback>; + using ThumbarButtonClickedCallbackMap = std::map; ThumbarButtonClickedCallbackMap thumbar_button_clicked_callback_map_; bool is_initialized_; - HWND window_; - DISALLOW_COPY_AND_ASSIGN(TaskbarHost); };