Index: chrome/browser/ui/panels/panel_mouse_watcher_win.cc |
=================================================================== |
--- chrome/browser/ui/panels/panel_mouse_watcher_win.cc (revision 0) |
+++ chrome/browser/ui/panels/panel_mouse_watcher_win.cc (revision 0) |
@@ -0,0 +1,93 @@ |
+// Copyright (c) 2011 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" |
+ |
+#include "base/logging.h" |
+#include "base/scoped_ptr.h" |
+#include "chrome/browser/ui/panels/panel.h" |
+#include "chrome/browser/ui/panels/panel_manager.h" |
+ |
+#include <windows.h> |
+ |
+namespace { |
+ |
+HMODULE GetModuleHandleFromAddress(void *address) { |
+ MEMORY_BASIC_INFORMATION mbi; |
+ SIZE_T result = ::VirtualQuery(address, &mbi, sizeof(mbi)); |
+ return static_cast<HMODULE>(mbi.AllocationBase); |
+} |
+ |
+ |
+// Gets the handle to the currently executing module. |
+HMODULE GetCurrentModuleHandle() { |
+ return ::GetModuleHandleFromAddress(GetCurrentModuleHandle); |
+} |
+ |
+class PanelMouseWatcherWin { |
+ public: |
+ PanelMouseWatcherWin(); |
+ ~PanelMouseWatcherWin(); |
+ |
+ private: |
+ static LRESULT CALLBACK MouseHookProc(int code, WPARAM wparam, LPARAM lparam); |
+ |
+ void OnMouseAction(int mouse_x, int mouse_y); |
+ |
+ HHOOK mouse_hook_; |
+ bool bring_up_titlebar_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherWin); |
+}; |
+ |
+scoped_ptr<PanelMouseWatcherWin> mouse_watcher; |
+ |
+PanelMouseWatcherWin::PanelMouseWatcherWin() |
+ : mouse_hook_(NULL), |
+ bring_up_titlebar_(false) { |
+ mouse_hook_ = ::SetWindowsHookEx( |
+ WH_MOUSE_LL, MouseHookProc, GetCurrentModuleHandle(), 0); |
+ DCHECK(mouse_hook_); |
+} |
+ |
+PanelMouseWatcherWin::~PanelMouseWatcherWin() { |
+ ::UnhookWindowsHookEx(mouse_hook_); |
+} |
+ |
+LRESULT CALLBACK PanelMouseWatcherWin::MouseHookProc(int code, |
+ WPARAM wparam, |
+ LPARAM lparam) { |
+ if (code == HC_ACTION) { |
+ MOUSEHOOKSTRUCT* hook_struct = reinterpret_cast<MOUSEHOOKSTRUCT*>(lparam); |
+ if (hook_struct) |
+ mouse_watcher->OnMouseAction(hook_struct->pt.x, hook_struct->pt.y); |
+ } |
+ return ::CallNextHookEx(NULL, code, wparam, lparam); |
+} |
+ |
+void PanelMouseWatcherWin::OnMouseAction(int mouse_x, int mouse_y) { |
+ PanelManager* panel_manager = PanelManager::GetInstance(); |
+ |
+ bool bring_up_titlebar = |
+ panel_manager->ShouldBringUpTitleBarForAllMinimizedPanels( |
+ mouse_x, mouse_y); |
+ if (bring_up_titlebar == bring_up_titlebar_) |
+ return; |
+ bring_up_titlebar_ = bring_up_titlebar; |
+ |
+ panel_manager->BringUpOrDownTitleBarForAllMinimizedPanels(bring_up_titlebar); |
+} |
+ |
+} |
+ |
+void EnsureMouseWatcherStarted() { |
+ if (!mouse_watcher.get()) { |
+ mouse_watcher.reset( |
+ new PanelMouseWatcherWin()); |
jennb
2011/06/29 23:17:54
could fit on above line
jianli
2011/06/30 01:28:33
Done.
|
+ } |
+} |
+ |
+void StopMouseWatcher() { |
+ mouse_watcher.reset(NULL); |
+} |
Property changes on: chrome\browser\ui\panels\panel_mouse_watcher_win.cc |
___________________________________________________________________ |
Added: svn:eol-style |
+ LF |