OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "views/widget/aero_tooltip_manager.h" | |
6 | |
7 #include <windows.h> | |
8 #include <commctrl.h> | |
9 #include <shlobj.h> | |
10 | |
11 #include "base/bind.h" | |
12 #include "base/message_loop.h" | |
13 #include "ui/base/l10n/l10n_util_win.h" | |
14 #include "ui/base/win/hwnd_util.h" | |
15 #include "ui/gfx/point.h" | |
16 | |
17 namespace views { | |
18 | |
19 /////////////////////////////////////////////////////////////////////////////// | |
20 // AeroTooltipManager, public: | |
21 | |
22 AeroTooltipManager::AeroTooltipManager(Widget* widget) | |
23 : TooltipManagerWin(widget), | |
24 initial_delay_(0) { | |
25 } | |
26 | |
27 AeroTooltipManager::~AeroTooltipManager() { | |
28 if (initial_timer_) | |
29 initial_timer_->Disown(); | |
30 } | |
31 | |
32 void AeroTooltipManager::OnMouse(UINT u_msg, WPARAM w_param, LPARAM l_param) { | |
33 if (u_msg == WM_MOUSELEAVE) { | |
34 last_mouse_pos_.SetPoint(-1, -1); | |
35 UpdateTooltip(); | |
36 return; | |
37 } | |
38 | |
39 if (initial_timer_) | |
40 initial_timer_->Disown(); | |
41 | |
42 if (u_msg == WM_MOUSEMOVE || u_msg == WM_NCMOUSEMOVE) { | |
43 gfx::Point mouse_pos(l_param); | |
44 if (u_msg == WM_NCMOUSEMOVE) { | |
45 // NC message coordinates are in screen coordinates. | |
46 POINT temp = mouse_pos.ToPOINT(); | |
47 ::MapWindowPoints(HWND_DESKTOP, GetParent(), &temp, 1); | |
48 mouse_pos.SetPoint(temp.x, temp.y); | |
49 } | |
50 if (last_mouse_pos_ != mouse_pos) { | |
51 last_mouse_pos_ = mouse_pos; | |
52 HideKeyboardTooltip(); | |
53 UpdateTooltip(mouse_pos); | |
54 } | |
55 | |
56 // Delay opening of the tooltip just in case the user moves their | |
57 // mouse to another control. We defer this from Init because we get | |
58 // zero if we query it too soon. | |
59 if (!initial_delay_) { | |
60 initial_delay_ = static_cast<int>( | |
61 ::SendMessage(tooltip_hwnd_, TTM_GETDELAYTIME, TTDT_INITIAL, 0)); | |
62 } | |
63 initial_timer_ = new InitialTimer(this); | |
64 initial_timer_->Start(initial_delay_); | |
65 } else { | |
66 // Hide the tooltip and cancel any timers. | |
67 ::SendMessage(tooltip_hwnd_, TTM_POP, 0, 0); | |
68 ::SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, false, (LPARAM)&toolinfo_); | |
69 return; | |
70 } | |
71 } | |
72 | |
73 /////////////////////////////////////////////////////////////////////////////// | |
74 // AeroTooltipManager, private: | |
75 | |
76 void AeroTooltipManager::OnTimer() { | |
77 initial_timer_ = NULL; | |
78 | |
79 POINT pt = last_mouse_pos_.ToPOINT(); | |
80 ::ClientToScreen(GetParent(), &pt); | |
81 | |
82 // Set the position and visibility. | |
83 if (!tooltip_showing_) { | |
84 ::SendMessage(tooltip_hwnd_, TTM_POPUP, 0, 0); | |
85 ::SendMessage(tooltip_hwnd_, TTM_TRACKPOSITION, 0, MAKELPARAM(pt.x, pt.y)); | |
86 ::SendMessage(tooltip_hwnd_, TTM_TRACKACTIVATE, true, (LPARAM)&toolinfo_); | |
87 } | |
88 } | |
89 | |
90 /////////////////////////////////////////////////////////////////////////////// | |
91 // AeroTooltipManager::InitialTimer | |
92 | |
93 AeroTooltipManager::InitialTimer::InitialTimer(AeroTooltipManager* manager) | |
94 : manager_(manager) { | |
95 } | |
96 | |
97 void AeroTooltipManager::InitialTimer::Start(int time) { | |
98 MessageLoop::current()->PostDelayedTask( | |
99 FROM_HERE, base::Bind(&InitialTimer::Execute, this), time); | |
100 } | |
101 | |
102 void AeroTooltipManager::InitialTimer::Disown() { | |
103 manager_ = NULL; | |
104 } | |
105 | |
106 void AeroTooltipManager::InitialTimer::Execute() { | |
107 if (manager_) | |
108 manager_->OnTimer(); | |
109 } | |
110 | |
111 } // namespace views | |
OLD | NEW |