]> khamidou — GitHub mirrors - electron.git/commitdiff
views: Add WindowStateWatcher
authorCheng Zhao <zcbenz@gmail.com>
Tue, 25 Nov 2014 03:46:30 +0000 (11:46 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Tue, 25 Nov 2014 03:46:30 +0000 (11:46 +0800)
atom.gyp
atom/browser/native_window_views.cc
atom/browser/native_window_views.h
atom/browser/ui/views/window_state_watcher.cc [new file with mode: 0644]
atom/browser/ui/views/window_state_watcher.h [new file with mode: 0644]

index 9805db874f80e1c46cd5347a53f13783252371a5..61ace73f4e5765cb6b361f45271e37d5223c2691 100644 (file)
--- a/atom.gyp
+++ b/atom.gyp
       'atom/browser/ui/views/submenu_button.h',
       'atom/browser/ui/views/win_frame_view.cc',
       'atom/browser/ui/views/win_frame_view.h',
+      'atom/browser/ui/views/window_state_watcher.cc',
+      'atom/browser/ui/views/window_state_watcher.h',
       'atom/browser/ui/win/notify_icon_host.cc',
       'atom/browser/ui/win/notify_icon_host.h',
       'atom/browser/ui/win/notify_icon.cc',
index 05a72fbe559615ab1a84fd5926e816cea590df09..beba0891f6da89cd2a9fccf6c3f212bec90b38cd 100644 (file)
@@ -13,6 +13,7 @@
 
 #include "atom/browser/ui/views/menu_bar.h"
 #include "atom/browser/ui/views/menu_layout.h"
+#include "atom/browser/ui/views/window_state_watcher.h"
 #include "atom/common/draggable_region.h"
 #include "atom/common/options_switches.h"
 #include "base/strings/utf_string_conversions.h"
@@ -188,6 +189,9 @@ NativeWindowViews::NativeWindowViews(content::WebContents* web_contents,
 
   window_->Init(params);
 
+  // Start monitoring window states.
+  window_state_watcher_.reset(new WindowStateWatcher(this));
+
 #if defined(USE_X11)
   // Set _GTK_THEME_VARIANT to dark if we have "dark-theme" option set.
   bool use_dark_theme = false;
index 97baa2a4630b7b1191d72c55fabada64a4184175..dd0e901e9857b3c64a28c4de78217e86217cf551 100644 (file)
@@ -22,6 +22,7 @@ namespace atom {
 
 class GlobalMenuBarX11;
 class MenuBar;
+class WindowStateWatcher;
 
 class NativeWindowViews : public NativeWindow,
                           public views::WidgetDelegateView,
@@ -146,6 +147,9 @@ class NativeWindowViews : public NativeWindow,
   scoped_ptr<GlobalMenuBarX11> global_menu_bar_;
 #endif
 
+  // Handles window state events.
+  scoped_ptr<WindowStateWatcher> window_state_watcher_;
+
   // Handles unhandled keyboard messages coming back from the renderer process.
   scoped_ptr<views::UnhandledKeyboardEventHandler> keyboard_event_handler_;
 
diff --git a/atom/browser/ui/views/window_state_watcher.cc b/atom/browser/ui/views/window_state_watcher.cc
new file mode 100644 (file)
index 0000000..2d45452
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (c) 2014 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "atom/browser/ui/views/window_state_watcher.h"
+
+#include "ui/events/platform/platform_event_source.h"
+
+namespace atom {
+
+WindowStateWatcher::WindowStateWatcher(NativeWindowViews* window)
+    : window_(window),
+      widget_(window->GetAcceleratedWidget()) {
+  ui::PlatformEventSource::GetInstance()->AddPlatformEventObserver(this);
+}
+
+WindowStateWatcher::~WindowStateWatcher() {
+  ui::PlatformEventSource::GetInstance()->RemovePlatformEventObserver(this);
+}
+
+void WindowStateWatcher::WillProcessEvent(const ui::PlatformEvent& event) {
+  LOG(ERROR) << "WillProcessEvent";
+}
+
+void WindowStateWatcher::DidProcessEvent(const ui::PlatformEvent& event) {
+}
+
+}  // namespace atom
diff --git a/atom/browser/ui/views/window_state_watcher.h b/atom/browser/ui/views/window_state_watcher.h
new file mode 100644 (file)
index 0000000..b78086c
--- /dev/null
@@ -0,0 +1,28 @@
+// Copyright (c) 2014 GitHub, Inc.
+// Use of this source code is governed by the MIT license that can be
+// found in the LICENSE file.
+
+#include "ui/events/platform/platform_event_observer.h"
+
+#include "atom/browser/native_window_views.h"
+
+namespace atom {
+
+class WindowStateWatcher : public ui::PlatformEventObserver {
+ public:
+  explicit WindowStateWatcher(NativeWindowViews* window);
+  virtual ~WindowStateWatcher();
+
+ protected:
+  // ui::PlatformEventObserver:
+  void WillProcessEvent(const ui::PlatformEvent& event) override;
+  void DidProcessEvent(const ui::PlatformEvent& event) override;
+
+ private:
+  NativeWindowViews* window_;
+  gfx::AcceleratedWidget widget_;
+
+  DISALLOW_COPY_AND_ASSIGN(WindowStateWatcher);
+};
+
+}  // namespace atom