Decouple TaskbarHost from NativeWindow

This commit is contained in:
Cheng Zhao 2015-08-06 11:10:34 +08:00
Родитель 8f8c3aef87
Коммит a28f70e85c
8 изменённых файлов: 52 добавлений и 56 удалений

Просмотреть файл

@ -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<atom::NativeWindow::ThumbarButton> {
struct Converter<atom::TaskbarHost::ThumbarButton> {
static bool FromV8(v8::Isolate* isolate, v8::Handle<v8::Value> 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<atom::NativeWindow::ThumbarButton> {
};
} // 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<NativeWindow::ThumbarButton>& buttons) {
window_->SetThumbarButtons(buttons);
void Window::SetThumbarButtons(mate::Arguments* args) {
#if defined(OS_WIN)
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) {

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -60,14 +60,6 @@ class NativeWindow : public content::WebContentsObserver,
public brightray::InspectableWebContentsViewDelegate {
public:
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 {
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<ThumbarButton>& buttons);
virtual bool IsClosed() const { return is_closed_; }
// Webview APIs.
virtual void FocusOnWebView();
virtual void BlurWebView();
virtual bool IsWebViewFocused();

Просмотреть файл

@ -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<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() {
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;
}

Просмотреть файл

@ -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<NativeWindow::ThumbarButton>& 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<TaskbarHost> taskbar_host_;
TaskbarHost taskbar_host_;
#endif
// Handles unhandled keyboard messages coming back from the renderer process.

Просмотреть файл

@ -58,15 +58,14 @@ bool GetThumbarButtonFlags(const std::vector<std::string>& flags,
} // namespace
TaskbarHost::TaskbarHost(HWND window) : is_initialized_(false),
window_(window) {
TaskbarHost::TaskbarHost() : is_initialized_(false) {
}
TaskbarHost::~TaskbarHost() {
}
bool TaskbarHost::SetThumbarButtons(
const std::vector<atom::NativeWindow::ThumbarButton>& buttons) {
HWND window, const std::vector<ThumbarButton>& 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.

Просмотреть файл

@ -10,28 +10,33 @@
#include <map>
#include <vector>
#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<std::string> flags;
base::Closure clicked_callback;
};
TaskbarHost();
virtual ~TaskbarHost();
bool SetThumbarButtons(
const std::vector<NativeWindow::ThumbarButton>& buttons);
HWND window, const std::vector<ThumbarButton>& buttons);
bool HandleThumbarButtonEvent(int button_id);
private:
using ThumbarButtonClickedCallbackMap = std::map<
int, NativeWindow::ThumbarButtonClickedCallback>;
using ThumbarButtonClickedCallbackMap = std::map<int, base::Closure>;
ThumbarButtonClickedCallbackMap thumbar_button_clicked_callback_map_;
bool is_initialized_;
HWND window_;
DISALLOW_COPY_AND_ASSIGN(TaskbarHost);
};