Decouple TaskbarHost from NativeWindow

This commit is contained in:
Cheng Zhao 2015-08-06 11:10:34 +08:00
parent 8f8c3aef87
commit a28f70e85c
8 changed files with 52 additions and 56 deletions

View file

@ -18,14 +18,20 @@
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "ui/gfx/geometry/rect.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" #include "atom/common/node_includes.h"
#if defined(OS_WIN)
namespace mate { namespace mate {
template<> template<>
struct Converter<atom::NativeWindow::ThumbarButton> { struct Converter<atom::TaskbarHost::ThumbarButton> {
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val, static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> val,
atom::NativeWindow::ThumbarButton* out) { atom::TaskbarHost::ThumbarButton* out) {
mate::Dictionary dict; mate::Dictionary dict;
if (!ConvertFromV8(isolate, val, &dict)) if (!ConvertFromV8(isolate, val, &dict))
return false; return false;
@ -37,6 +43,7 @@ struct Converter<atom::NativeWindow::ThumbarButton> {
}; };
} // namespace mate } // namespace mate
#endif
namespace atom { namespace atom {
@ -431,9 +438,17 @@ void Window::SetOverlayIcon(const gfx::Image& overlay,
window_->SetOverlayIcon(overlay, description); window_->SetOverlayIcon(overlay, description);
} }
void Window::SetThumbarButtons( void Window::SetThumbarButtons(mate::Arguments* args) {
const std::vector<NativeWindow::ThumbarButton>& buttons) { #if defined(OS_WIN)
window_->SetThumbarButtons(buttons); std::vector<TaskbarHost::ThumbarButton> buttons;
if (!args->GetNext(&buttons)) {
args->ThrowError();
return;
}
auto window = static_cast<NativeWindowViews*>(window_.get());
window->taskbar_host().SetThumbarButtons(window->GetAcceleratedWidget(),
buttons);
#endif
} }
void Window::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) { void Window::SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> value) {

View file

@ -130,8 +130,7 @@ class Window : public mate::TrackableObject<Window>,
void SetProgressBar(double progress); void SetProgressBar(double progress);
void SetOverlayIcon(const gfx::Image& overlay, void SetOverlayIcon(const gfx::Image& overlay,
const std::string& description); const std::string& description);
void SetThumbarButtons( void SetThumbarButtons(mate::Arguments* args);
const std::vector<NativeWindow::ThumbarButton>& buttons);
void SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> menu); void SetMenu(v8::Isolate* isolate, v8::Local<v8::Value> menu);
void SetAutoHideMenuBar(bool auto_hide); void SetAutoHideMenuBar(bool auto_hide);
bool IsMenuBarAutoHide(); bool IsMenuBarAutoHide();

View file

@ -277,11 +277,6 @@ bool NativeWindow::HasModalDialog() {
return has_dialog_attached_; return has_dialog_attached_;
} }
bool NativeWindow::SetThumbarButtons(
const std::vector<ThumbarButton>& buttons) {
return false;
}
void NativeWindow::FocusOnWebView() { void NativeWindow::FocusOnWebView() {
web_contents()->GetRenderViewHost()->Focus(); web_contents()->GetRenderViewHost()->Focus();
} }

View file

@ -60,14 +60,6 @@ class NativeWindow : public content::WebContentsObserver,
public brightray::InspectableWebContentsViewDelegate { public brightray::InspectableWebContentsViewDelegate {
public: public:
using CapturePageCallback = base::Callback<void(const SkBitmap& bitmap)>; using CapturePageCallback = base::Callback<void(const SkBitmap& bitmap)>;
using ThumbarButtonClickedCallback = base::Closure;
struct ThumbarButton {
std::string tooltip;
gfx::Image icon;
std::vector<std::string> flags;
ThumbarButtonClickedCallback clicked_callback;
};
class DialogScope { class DialogScope {
public: public:
@ -103,6 +95,7 @@ class NativeWindow : public content::WebContentsObserver,
virtual void Close() = 0; virtual void Close() = 0;
virtual void CloseImmediately() = 0; virtual void CloseImmediately() = 0;
virtual bool IsClosed() const { return is_closed_; }
virtual void Focus(bool focus) = 0; virtual void Focus(bool focus) = 0;
virtual bool IsFocused() = 0; virtual bool IsFocused() = 0;
virtual void Show() = 0; virtual void Show() = 0;
@ -147,16 +140,17 @@ class NativeWindow : public content::WebContentsObserver,
virtual void SetMenu(ui::MenuModel* menu); virtual void SetMenu(ui::MenuModel* menu);
virtual bool HasModalDialog(); virtual bool HasModalDialog();
virtual gfx::NativeWindow GetNativeWindow() = 0; virtual gfx::NativeWindow GetNativeWindow() = 0;
// Taskbar/Dock APIs.
virtual void SetProgressBar(double progress) = 0; virtual void SetProgressBar(double progress) = 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;
// Workspace APIs.
virtual void SetVisibleOnAllWorkspaces(bool visible) = 0; virtual void SetVisibleOnAllWorkspaces(bool visible) = 0;
virtual bool IsVisibleOnAllWorkspaces() = 0; virtual bool IsVisibleOnAllWorkspaces() = 0;
virtual bool SetThumbarButtons(
const std::vector<ThumbarButton>& buttons);
virtual bool IsClosed() const { return is_closed_; }
// Webview APIs.
virtual void FocusOnWebView(); virtual void FocusOnWebView();
virtual void BlurWebView(); virtual void BlurWebView();
virtual bool IsWebViewFocused(); virtual bool IsWebViewFocused();

View file

@ -46,7 +46,6 @@
#elif defined(OS_WIN) #elif defined(OS_WIN)
#include "atom/browser/ui/views/win_frame_view.h" #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/atom_desktop_window_tree_host_win.h"
#include "atom/browser/ui/win/taskbar_host.h"
#include "base/win/scoped_comptr.h" #include "base/win/scoped_comptr.h"
#include "base/win/windows_version.h" #include "base/win/windows_version.h"
#include "ui/base/win/shell.h" #include "ui/base/win/shell.h"
@ -718,17 +717,6 @@ bool NativeWindowViews::IsVisibleOnAllWorkspaces() {
return false; return false;
} }
bool NativeWindowViews::SetThumbarButtons(
const std::vector<NativeWindow::ThumbarButton>& 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() { gfx::AcceleratedWidget NativeWindowViews::GetAcceleratedWidget() {
return GetNativeWindow()->GetHost()->GetAcceleratedWidget(); return GetNativeWindow()->GetHost()->GetAcceleratedWidget();
} }
@ -894,9 +882,8 @@ void NativeWindowViews::GetDevToolsWindowWMClass(
bool NativeWindowViews::PreHandleMSG( bool NativeWindowViews::PreHandleMSG(
UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) { UINT message, WPARAM w_param, LPARAM l_param, LRESULT* result) {
// Handle thumbar button click message. // Handle thumbar button click message.
if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED && if (message == WM_COMMAND && HIWORD(w_param) == THBN_CLICKED)
taskbar_host_) return taskbar_host_.HandleThumbarButtonEvent(LOWORD(w_param));
return taskbar_host_->HandleThumbarButtonEvent(LOWORD(w_param));
else else
return false; return false;
} }

View file

@ -16,6 +16,7 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "atom/browser/ui/win/message_handler_delegate.h" #include "atom/browser/ui/win/message_handler_delegate.h"
#include "atom/browser/ui/win/taskbar_host.h"
#endif #endif
namespace views { namespace views {
@ -30,7 +31,6 @@ class WindowStateWatcher;
#if defined(OS_WIN) #if defined(OS_WIN)
class AtomDesktopWindowTreeHostWin; class AtomDesktopWindowTreeHostWin;
class TaskbarHost;
#endif #endif
class NativeWindowViews : public NativeWindow, class NativeWindowViews : public NativeWindow,
@ -91,13 +91,15 @@ class NativeWindowViews : public NativeWindow,
bool IsMenuBarVisible() override; bool IsMenuBarVisible() override;
void SetVisibleOnAllWorkspaces(bool visible) override; void SetVisibleOnAllWorkspaces(bool visible) override;
bool IsVisibleOnAllWorkspaces() override; bool IsVisibleOnAllWorkspaces() override;
bool SetThumbarButtons(
const std::vector<NativeWindow::ThumbarButton>& buttons) override;
gfx::AcceleratedWidget GetAcceleratedWidget(); gfx::AcceleratedWidget GetAcceleratedWidget();
views::Widget* widget() const { return window_.get(); } views::Widget* widget() const { return window_.get(); }
#if defined(OS_WIN)
TaskbarHost& taskbar_host() { return taskbar_host_; }
#endif
private: private:
// views::WidgetObserver: // views::WidgetObserver:
void OnWidgetActivationChanged( void OnWidgetActivationChanged(
@ -180,7 +182,7 @@ class NativeWindowViews : public NativeWindow,
// state. // state.
bool is_minimized_; bool is_minimized_;
// In charge of running taskbar related APIs. // In charge of running taskbar related APIs.
scoped_ptr<TaskbarHost> taskbar_host_; TaskbarHost taskbar_host_;
#endif #endif
// Handles unhandled keyboard messages coming back from the renderer process. // Handles unhandled keyboard messages coming back from the renderer process.

View file

@ -58,15 +58,14 @@ bool GetThumbarButtonFlags(const std::vector<std::string>& flags,
} // namespace } // namespace
TaskbarHost::TaskbarHost(HWND window) : is_initialized_(false), TaskbarHost::TaskbarHost() : is_initialized_(false) {
window_(window) {
} }
TaskbarHost::~TaskbarHost() { TaskbarHost::~TaskbarHost() {
} }
bool TaskbarHost::SetThumbarButtons( bool TaskbarHost::SetThumbarButtons(
const std::vector<atom::NativeWindow::ThumbarButton>& buttons) { HWND window, const std::vector<ThumbarButton>& buttons) {
if (buttons.size() > kMaxButtonsCount) if (buttons.size() > kMaxButtonsCount)
return false; return false;
@ -114,10 +113,10 @@ bool TaskbarHost::SetThumbarButtons(
if (!is_initialized_) { if (!is_initialized_) {
is_initialized_ = true; is_initialized_ = true;
is_success = taskbar->ThumbBarAddButtons( is_success = taskbar->ThumbBarAddButtons(
window_, buttons.size(), thumb_buttons) == S_OK; window, buttons.size(), thumb_buttons) == S_OK;
} else { } else {
is_success = taskbar->ThumbBarUpdateButtons( 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. // Release thumb_buttons' icons, the taskbar makes its own copy.

View file

@ -10,28 +10,33 @@
#include <map> #include <map>
#include <vector> #include <vector>
#include "atom/browser/native_window.h" #include "base/callback.h"
#include "ui/gfx/image/image.h"
namespace atom { namespace atom {
class TaskbarHost { class TaskbarHost {
public: public:
explicit TaskbarHost(HWND window); struct ThumbarButton {
~TaskbarHost(); std::string tooltip;
gfx::Image icon;
std::vector<std::string> flags;
base::Closure clicked_callback;
};
TaskbarHost();
virtual ~TaskbarHost();
bool SetThumbarButtons( bool SetThumbarButtons(
const std::vector<NativeWindow::ThumbarButton>& buttons); HWND window, const std::vector<ThumbarButton>& buttons);
bool HandleThumbarButtonEvent(int button_id); bool HandleThumbarButtonEvent(int button_id);
private: private:
using ThumbarButtonClickedCallbackMap = std::map< using ThumbarButtonClickedCallbackMap = std::map<int, base::Closure>;
int, NativeWindow::ThumbarButtonClickedCallback>;
ThumbarButtonClickedCallbackMap thumbar_button_clicked_callback_map_; ThumbarButtonClickedCallbackMap thumbar_button_clicked_callback_map_;
bool is_initialized_; bool is_initialized_;
HWND window_;
DISALLOW_COPY_AND_ASSIGN(TaskbarHost); DISALLOW_COPY_AND_ASSIGN(TaskbarHost);
}; };