diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index bcdc57c3c704..0b2c8c9ece79 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -20,17 +20,12 @@ #include "atom/common/node_includes.h" -#if defined(OS_WIN) -#include "atom/browser/ui/win/thumbar_host.h" -#endif - namespace mate { -#if defined(OS_WIN) template<> -struct Converter { +struct Converter { static bool FromV8(v8::Isolate* isolate, v8::Handle val, - atom::ThumbarHost::ThumbarButton* out) { + atom::NativeWindow::ThumbarButton* out) { mate::Dictionary dict; if (!ConvertFromV8(isolate, val, &dict)) return false; @@ -40,7 +35,6 @@ struct Converter { return dict.Get("icon", &(out->icon)); } }; -#endif } // namespace mate @@ -437,12 +431,10 @@ void Window::SetOverlayIcon(const gfx::Image& overlay, window_->SetOverlayIcon(overlay, description); } -#if defined(OS_WIN) void Window::SetThumbarButtons( - const std::vector& buttons) { + const std::vector& buttons) { window_->SetThumbarButtons(buttons); } -#endif void Window::SetMenu(v8::Isolate* isolate, v8::Local value) { mate::Handle menu; @@ -569,9 +561,7 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("capturePage", &Window::CapturePage) .SetMethod("setProgressBar", &Window::SetProgressBar) .SetMethod("setOverlayIcon", &Window::SetOverlayIcon) -#if defined(OS_WIN) .SetMethod("setThumbarButtons", &Window::SetThumbarButtons) -#endif .SetMethod("setMenu", &Window::SetMenu) .SetMethod("setAutoHideMenuBar", &Window::SetAutoHideMenuBar) .SetMethod("isMenuBarAutoHide", &Window::IsMenuBarAutoHide) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index fdb10825a6ca..7742c8a9fa9b 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -11,13 +11,10 @@ #include "base/memory/scoped_ptr.h" #include "ui/gfx/image/image.h" #include "atom/browser/api/trackable_object.h" +#include "atom/browser/native_window.h" #include "atom/browser/native_window_observer.h" #include "native_mate/handle.h" -#if defined(OS_WIN) -#include "atom/browser/ui/win/thumbar_host.h" -#endif - class GURL; namespace gfx { @@ -133,10 +130,8 @@ class Window : public mate::TrackableObject, void SetProgressBar(double progress); void SetOverlayIcon(const gfx::Image& overlay, const std::string& description); -#if defined(OS_WIN) void SetThumbarButtons( - const std::vector& buttons); -#endif + const std::vector& buttons); 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 96085846bca8..91770af316e3 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -277,6 +277,11 @@ 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 0ae22214f563..d461215222d6 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -23,10 +23,6 @@ #include "ui/gfx/image/image.h" #include "ui/gfx/image/image_skia.h" -#if defined(OS_WIN) -#include "atom/browser/ui/win/thumbar_host.h" -#endif - class SkRegion; namespace base { @@ -63,7 +59,15 @@ struct DraggableRegion; class NativeWindow : public content::WebContentsObserver, public brightray::InspectableWebContentsViewDelegate { public: - typedef base::Callback CapturePageCallback; + 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: @@ -148,10 +152,8 @@ class NativeWindow : public content::WebContentsObserver, const std::string& description) = 0; virtual void SetVisibleOnAllWorkspaces(bool visible) = 0; virtual bool IsVisibleOnAllWorkspaces() = 0; -#if defined(OS_WIN) virtual bool SetThumbarButtons( - const std::vector& buttons) = 0; -#endif + const std::vector& buttons); virtual bool IsClosed() const { return is_closed_; } diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index eda98dc4f853..acb7de33f4d6 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -717,17 +717,17 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() { return false; } -#if defined(OS_WIN) bool NativeWindowViews::SetThumbarButtons( - const std::vector& buttons) { + const std::vector& buttons) { +#if defined(OS_WIN) if (atom_desktop_window_tree_host_win_) { return atom_desktop_window_tree_host_win_->SetThumbarButtons( views::HWNDForNativeWindow(window_->GetNativeWindow()), buttons); } +#endif return false; } -#endif gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() { return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 94c0c04373f7..792a72c75624 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -82,10 +82,8 @@ class NativeWindowViews : public NativeWindow, bool IsMenuBarVisible() override; void SetVisibleOnAllWorkspaces(bool visible) override; bool IsVisibleOnAllWorkspaces() override; -#if defined(OS_WIN) bool SetThumbarButtons( - const std::vector& buttons) override; -#endif + const std::vector& buttons) override; gfx::AcceleratedWidget GetAcceleratedWidget(); diff --git a/atom/browser/ui/win/atom_desktop_window_tree_host_win.cc b/atom/browser/ui/win/atom_desktop_window_tree_host_win.cc index 5c5833f64c09..157cb610fb3a 100644 --- a/atom/browser/ui/win/atom_desktop_window_tree_host_win.cc +++ b/atom/browser/ui/win/atom_desktop_window_tree_host_win.cc @@ -6,6 +6,7 @@ #include +#include "atom/browser/native_window.h" #include "atom/browser/ui/win/thumbar_host.h" namespace atom { @@ -22,7 +23,7 @@ AtomDesktopWindowTreeHostWin::~AtomDesktopWindowTreeHostWin() { bool AtomDesktopWindowTreeHostWin::SetThumbarButtons( HWND window, - const std::vector& buttons) { + const std::vector& buttons) { if (!thumbar_host_.get()) { thumbar_host_.reset(new ThumbarHost(window)); } diff --git a/atom/browser/ui/win/atom_desktop_window_tree_host_win.h b/atom/browser/ui/win/atom_desktop_window_tree_host_win.h index 7f2abf801ad3..fc09b6503b80 100644 --- a/atom/browser/ui/win/atom_desktop_window_tree_host_win.h +++ b/atom/browser/ui/win/atom_desktop_window_tree_host_win.h @@ -9,6 +9,7 @@ #include +#include "atom/browser/native_window.h" #include "atom/browser/ui/win/thumbar_host.h" #include "base/memory/scoped_ptr.h" #include "ui/views/widget/desktop_aura/desktop_window_tree_host_win.h" @@ -24,7 +25,7 @@ class AtomDesktopWindowTreeHostWin : public views::DesktopWindowTreeHostWin { bool SetThumbarButtons( HWND window, - const std::vector& buttons); + const std::vector& buttons); protected: bool PreHandleMSG(UINT message, diff --git a/atom/browser/ui/win/thumbar_host.cc b/atom/browser/ui/win/thumbar_host.cc index 2d82cd4c6cdb..af57ef4e5c64 100644 --- a/atom/browser/ui/win/thumbar_host.cc +++ b/atom/browser/ui/win/thumbar_host.cc @@ -6,6 +6,8 @@ #include +#include + #include "base/win/scoped_comptr.h" #include "base/win/win_util.h" #include "base/win/wrapped_window_proc.h" @@ -64,7 +66,7 @@ ThumbarHost::~ThumbarHost() { } bool ThumbarHost::SetThumbarButtons( - const std::vector& buttons) { + const std::vector& buttons) { if (buttons.size() > kMaxButtonsCount) return false; @@ -112,7 +114,7 @@ bool ThumbarHost::SetThumbarButtons( if (!is_initialized_) { is_initialized_ = true; is_success = taskbar->ThumbBarAddButtons( - window_, kMaxButtonsCount, thumb_buttons) == S_OK; + window_, buttons.size(), thumb_buttons) == S_OK; } else { is_success = taskbar->ThumbBarUpdateButtons( window_, kMaxButtonsCount, thumb_buttons) == S_OK; diff --git a/atom/browser/ui/win/thumbar_host.h b/atom/browser/ui/win/thumbar_host.h index 40d0ae7400e8..d14bbaeda305 100644 --- a/atom/browser/ui/win/thumbar_host.h +++ b/atom/browser/ui/win/thumbar_host.h @@ -8,35 +8,24 @@ #include #include -#include #include -#include "base/callback.h" -#include "ui/gfx/image/image.h" +#include "atom/browser/native_window.h" namespace atom { class ThumbarHost { public: - using ThumbarButtonClickedCallback = base::Closure; - - struct ThumbarButton { - std::string tooltip; - gfx::Image icon; - std::vector flags; - ThumbarButtonClickedCallback clicked_callback; - }; - explicit ThumbarHost(HWND window); ~ThumbarHost(); bool SetThumbarButtons( - const std::vector& buttons); + const std::vector& buttons); bool HandleThumbarButtonEvent(int button_id); private: using ThumbarButtonClickedCallbackMap = std::map< - int, ThumbarButtonClickedCallback>; + int, NativeWindow::ThumbarButtonClickedCallback>; ThumbarButtonClickedCallbackMap thumbar_button_clicked_callback_map_; bool is_initialized_;