OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" | 5 #include "chrome/browser/ui/panels/panel_mouse_watcher_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 public: | 29 public: |
30 PanelMouseWatcherWin(); | 30 PanelMouseWatcherWin(); |
31 ~PanelMouseWatcherWin(); | 31 ~PanelMouseWatcherWin(); |
32 | 32 |
33 private: | 33 private: |
34 static LRESULT CALLBACK MouseHookProc(int code, WPARAM wparam, LPARAM lparam); | 34 static LRESULT CALLBACK MouseHookProc(int code, WPARAM wparam, LPARAM lparam); |
35 | 35 |
36 void OnMouseAction(int mouse_x, int mouse_y); | 36 void OnMouseAction(int mouse_x, int mouse_y); |
37 | 37 |
38 HHOOK mouse_hook_; | 38 HHOOK mouse_hook_; |
39 bool bring_up_titlebar_; | 39 bool bring_up_titlebars_; |
40 | 40 |
41 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherWin); | 41 DISALLOW_COPY_AND_ASSIGN(PanelMouseWatcherWin); |
42 }; | 42 }; |
43 | 43 |
44 scoped_ptr<PanelMouseWatcherWin> mouse_watcher; | 44 scoped_ptr<PanelMouseWatcherWin> mouse_watcher; |
45 | 45 |
46 PanelMouseWatcherWin::PanelMouseWatcherWin() | 46 PanelMouseWatcherWin::PanelMouseWatcherWin() |
47 : mouse_hook_(NULL), | 47 : mouse_hook_(NULL), |
48 bring_up_titlebar_(false) { | 48 bring_up_titlebars_(false) { |
49 mouse_hook_ = ::SetWindowsHookEx( | 49 mouse_hook_ = ::SetWindowsHookEx( |
50 WH_MOUSE_LL, MouseHookProc, GetCurrentModuleHandle(), 0); | 50 WH_MOUSE_LL, MouseHookProc, GetCurrentModuleHandle(), 0); |
51 DCHECK(mouse_hook_); | 51 DCHECK(mouse_hook_); |
52 } | 52 } |
53 | 53 |
54 PanelMouseWatcherWin::~PanelMouseWatcherWin() { | 54 PanelMouseWatcherWin::~PanelMouseWatcherWin() { |
55 ::UnhookWindowsHookEx(mouse_hook_); | 55 ::UnhookWindowsHookEx(mouse_hook_); |
56 } | 56 } |
57 | 57 |
58 LRESULT CALLBACK PanelMouseWatcherWin::MouseHookProc(int code, | 58 LRESULT CALLBACK PanelMouseWatcherWin::MouseHookProc(int code, |
59 WPARAM wparam, | 59 WPARAM wparam, |
60 LPARAM lparam) { | 60 LPARAM lparam) { |
61 if (code == HC_ACTION) { | 61 if (code == HC_ACTION) { |
62 MOUSEHOOKSTRUCT* hook_struct = reinterpret_cast<MOUSEHOOKSTRUCT*>(lparam); | 62 MOUSEHOOKSTRUCT* hook_struct = reinterpret_cast<MOUSEHOOKSTRUCT*>(lparam); |
63 if (hook_struct) | 63 if (hook_struct) |
64 mouse_watcher->OnMouseAction(hook_struct->pt.x, hook_struct->pt.y); | 64 mouse_watcher->OnMouseAction(hook_struct->pt.x, hook_struct->pt.y); |
65 } | 65 } |
66 return ::CallNextHookEx(NULL, code, wparam, lparam); | 66 return ::CallNextHookEx(NULL, code, wparam, lparam); |
67 } | 67 } |
68 | 68 |
69 void PanelMouseWatcherWin::OnMouseAction(int mouse_x, int mouse_y) { | 69 void PanelMouseWatcherWin::OnMouseAction(int mouse_x, int mouse_y) { |
70 PanelManager* panel_manager = PanelManager::GetInstance(); | 70 PanelManager* panel_manager = PanelManager::GetInstance(); |
71 | 71 |
72 bool bring_up_titlebar = | 72 bool bring_up_titlebars = panel_manager->ShouldBringUpTitlebars( |
73 panel_manager->ShouldBringUpTitlebarForAllMinimizedPanels( | 73 mouse_x, mouse_y); |
74 mouse_x, mouse_y); | 74 if (bring_up_titlebars == bring_up_titlebars_) |
75 if (bring_up_titlebar == bring_up_titlebar_) | |
76 return; | 75 return; |
77 bring_up_titlebar_ = bring_up_titlebar; | 76 bring_up_titlebars_ = bring_up_titlebars; |
78 | 77 |
79 panel_manager->BringUpOrDownTitlebarForAllMinimizedPanels(bring_up_titlebar); | 78 panel_manager->BringUpOrDownTitlebars(bring_up_titlebars); |
80 } | 79 } |
81 | 80 |
82 } // namespace | 81 } // namespace |
83 | 82 |
84 void EnsureMouseWatcherStarted() { | 83 void EnsureMouseWatcherStarted() { |
85 if (!mouse_watcher.get()) | 84 if (!mouse_watcher.get()) |
86 mouse_watcher.reset(new PanelMouseWatcherWin()); | 85 mouse_watcher.reset(new PanelMouseWatcherWin()); |
87 } | 86 } |
88 | 87 |
89 void StopMouseWatcher() { | 88 void StopMouseWatcher() { |
90 mouse_watcher.reset(NULL); | 89 mouse_watcher.reset(NULL); |
91 } | 90 } |
92 | 91 |
93 bool IsMouseWatcherStarted() { | 92 bool IsMouseWatcherStarted() { |
94 return mouse_watcher.get() != NULL; | 93 return mouse_watcher.get() != NULL; |
95 } | 94 } |
OLD | NEW |