Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(571)

Side by Side Diff: views/widget/tooltip_manager_views.cc

Issue 8417025: aura: Update how the tooltip manager works. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: compile fixes Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 "views/widget/tooltip_manager_views.h" 5 #include "views/widget/tooltip_manager_views.h"
6 6
7 #if defined(USE_X11) 7 #if defined(USE_X11)
8 #include <X11/Xlib.h> 8 #include <X11/Xlib.h>
9 #include <X11/extensions/XInput2.h> 9 #include <X11/extensions/XInput2.h>
10 #endif 10 #endif
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 TooltipManagerViews::TooltipManagerViews(views::View* root_view) 76 TooltipManagerViews::TooltipManagerViews(views::View* root_view)
77 : root_view_(root_view), 77 : root_view_(root_view),
78 tooltip_view_(NULL) { 78 tooltip_view_(NULL) {
79 tooltip_label_.set_background( 79 tooltip_label_.set_background(
80 views::Background::CreateSolidBackground(kTooltipBackground)); 80 views::Background::CreateSolidBackground(kTooltipBackground));
81 tooltip_widget_.reset(CreateTooltip()); 81 tooltip_widget_.reset(CreateTooltip());
82 tooltip_widget_->SetContentsView(&tooltip_label_); 82 tooltip_widget_->SetContentsView(&tooltip_label_);
83 tooltip_widget_->Activate(); 83 tooltip_widget_->Activate();
84 tooltip_widget_->SetAlwaysOnTop(true); 84 tooltip_widget_->SetAlwaysOnTop(true);
85 tooltip_timer_.Start(FROM_HERE,
86 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
87 this, &TooltipManagerViews::TooltipTimerFired);
88 MessageLoopForUI::current()->AddObserver(this);
89 } 85 }
90 86
91 TooltipManagerViews::~TooltipManagerViews() { 87 TooltipManagerViews::~TooltipManagerViews() {
92 MessageLoopForUI::current()->RemoveObserver(this);
93 tooltip_widget_->CloseNow(); 88 tooltip_widget_->CloseNow();
94 } 89 }
95 90
91 void TooltipManagerViews::UpdateForMouseEvent(const MouseEvent& event) {
92 if (event.type() == ui::ET_MOUSE_EXITED) {
sky 2011/10/28 17:47:27 nit: use a switch statement.
sadrul 2011/10/28 21:42:52 Done.
93 // Mouse is exiting this widget. Stop showing the tooltip and the timer.
94 if (tooltip_timer_.IsRunning())
95 tooltip_timer_.Stop();
96 if (tooltip_widget_->IsVisible())
97 tooltip_widget_->Hide();
98 } else if (event.type() == ui::ET_MOUSE_ENTERED) {
99 // Mouse just entered this widget. Start the timer to show the tooltip.
100 CHECK(!tooltip_timer_.IsRunning());
101 tooltip_timer_.Start(FROM_HERE,
102 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs),
103 this, &TooltipManagerViews::TooltipTimerFired);
104 } else if (event.type() == ui::ET_MOUSE_MOVED) {
105 OnMouseMoved(event.location().x(), event.location().y());
106 } else {
107 // Hide the tooltip for click, release, wheel events.
108 if (tooltip_widget_->IsVisible())
109 tooltip_widget_->Hide();
110 }
111 }
112
96 void TooltipManagerViews::UpdateTooltip() { 113 void TooltipManagerViews::UpdateTooltip() {
97 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); 114 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
98 } 115 }
99 116
100 void TooltipManagerViews::TooltipTextChanged(View* view) { 117 void TooltipManagerViews::TooltipTextChanged(View* view) {
101 if (tooltip_widget_->IsVisible()) 118 if (tooltip_widget_->IsVisible())
102 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); 119 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
103 } 120 }
104 121
105 void TooltipManagerViews::ShowKeyboardTooltip(View* view) { 122 void TooltipManagerViews::ShowKeyboardTooltip(View* view) {
106 NOTREACHED(); 123 NOTREACHED();
107 } 124 }
108 125
109 void TooltipManagerViews::HideKeyboardTooltip() { 126 void TooltipManagerViews::HideKeyboardTooltip() {
110 NOTREACHED(); 127 NOTREACHED();
111 } 128 }
112 129
113 #if defined(USE_WAYLAND)
114 base::MessagePumpObserver::EventStatus TooltipManagerViews::WillProcessEvent(
115 ui::WaylandEvent* event) {
116 if (event->type == ui::WAYLAND_MOTION)
117 OnMouseMoved(event->motion.x, event->motion.y);
118 return base::MessagePumpObserver::EVENT_CONTINUE;
119 }
120 #elif defined(USE_X11)
121 base::EventStatus TooltipManagerViews::WillProcessEvent(
122 const base::NativeEvent& native_event) {
123 if (!ui::IsMouseEvent(native_event))
124 return base::EVENT_CONTINUE;
125 #if defined(USE_AURA)
126 aura::MouseEvent event(native_event);
127 #else
128 MouseEvent event(native_event);
129 #endif
130 switch (event.type()) {
131 case ui::ET_MOUSE_MOVED:
132 OnMouseMoved(event.x(), event.y());
133 default:
134 break;
135 }
136 return base::EVENT_CONTINUE;
137 }
138
139 void TooltipManagerViews::DidProcessEvent(const base::NativeEvent& event) {
140 }
141 #elif defined(OS_WIN)
142 base::EventStatus TooltipManagerViews::WillProcessEvent(
143 const base::NativeEvent& event) {
144 if (event.message == WM_MOUSEMOVE)
145 OnMouseMoved(GET_X_LPARAM(event.lParam), GET_Y_LPARAM(event.lParam));
146 return base::EVENT_CONTINUE;
147 }
148
149 void TooltipManagerViews::DidProcessEvent(const base::NativeEvent& event) {
150 }
151 #endif
152
153 void TooltipManagerViews::TooltipTimerFired() { 130 void TooltipManagerViews::TooltipTimerFired() {
154 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); 131 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
155 } 132 }
156 133
157 View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) { 134 View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) {
158 View* view = NULL; 135 View* view = NULL;
159 if (!for_keyboard) { 136 if (!for_keyboard) {
160 // Convert x,y from screen coordinates to |root_view_| coordinates. 137 // Convert x,y from screen coordinates to |root_view_| coordinates.
161 gfx::Point point(x, y); 138 gfx::Point point(x, y);
162 gfx::Rect r = root_view_->GetWidget()->GetClientAreaScreenBounds();
163 point.SetPoint(point.x() - r.x(), point.y() - r.y());
164 View::ConvertPointFromWidget(root_view_, &point); 139 View::ConvertPointFromWidget(root_view_, &point);
165 view = root_view_->GetEventHandlerForPoint(point); 140 view = root_view_->GetEventHandlerForPoint(point);
166 } else { 141 } else {
167 FocusManager* focus_manager = root_view_->GetFocusManager(); 142 FocusManager* focus_manager = root_view_->GetFocusManager();
168 if (focus_manager) 143 if (focus_manager)
169 view = focus_manager->GetFocusedView(); 144 view = focus_manager->GetFocusedView();
170 } 145 }
171 return view; 146 return view;
172 } 147 }
173 148
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
247 if (tooltip_timer_.IsRunning()) 222 if (tooltip_timer_.IsRunning())
248 tooltip_timer_.Reset(); 223 tooltip_timer_.Reset();
249 curr_mouse_pos_.SetPoint(x, y); 224 curr_mouse_pos_.SetPoint(x, y);
250 225
251 // If tooltip is visible, we may want to hide it. If it is not, we are ok. 226 // If tooltip is visible, we may want to hide it. If it is not, we are ok.
252 if (tooltip_widget_->IsVisible()) 227 if (tooltip_widget_->IsVisible())
253 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); 228 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false);
254 } 229 }
255 230
256 } // namespace views 231 } // namespace views
OLDNEW
« views/widget/tooltip_manager_views.h ('K') | « views/widget/tooltip_manager_views.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698