]> khamidou — GitHub mirrors - electron.git/commitdiff
Decouple TaskbarHost from NativeWindow
authorCheng Zhao <zcbenz@gmail.com>
Thu, 6 Aug 2015 03:10:34 +0000 (11:10 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 6 Aug 2015 03:10:34 +0000 (11:10 +0800)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/browser/ui/win/taskbar_host.cc
atom/browser/ui/win/taskbar_host.h

index 0b2c8c9ece79a29bb033441604f73533910a2111..2cbe8be566e217fda76089ea8bdf9b1d2b98e43d 100644 (file)
 #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) {
index 7742c8a9fa9befb5a96e690f461341a265168d29..389c03ab9d40a92ceaa57b756e280975a63288fd 100644 (file)
@@ -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();
index 91770af316e3d8fb9b5cddf448128d0d916f7fa7..96085846bca8b08f09906eb65bc9d33cf78b85cc 100644 (file)
@@ -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();
 }
index d461215222d6f25e661e8204c8e556a2b9293ee4..b9294d38c9316b052815351bf5408c4666f7460f 100644 (file)
@@ -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();
index c7fd0b8b3524038e54ec8b71959cc04fb123f905..759249e5aa4ef039de29f4286c27ab3f8896ad93 100644 (file)
@@ -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;
 }
index 0cc79facab12d54a7a17701d8d6c40728ff78231..355f5bd38ef37147807b56412ee4cf40ff66b826 100644 (file)
@@ -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.
index 6f74a7d9cb37011d5deb979ec2afc78279006ec2..3173215a4f6b2a73cd4781180741face1b305a29 100644 (file)
@@ -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.
index e0a9dc89ff4b7a26d03e77bbaa65265e5379dff9..2c81a9cdb371c50e2c8afcb9a6f71f8afbdd65ad 100644 (file)
 #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);
 };