| 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 "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 Loading... |
| 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 switch (event.type()) { |
| 93 case ui::ET_MOUSE_EXITED: |
| 94 // Mouse is exiting this widget. Stop showing the tooltip and the timer. |
| 95 if (tooltip_timer_.IsRunning()) |
| 96 tooltip_timer_.Stop(); |
| 97 if (tooltip_widget_->IsVisible()) |
| 98 tooltip_widget_->Hide(); |
| 99 break; |
| 100 case ui::ET_MOUSE_ENTERED: |
| 101 // Mouse just entered this widget. Start the timer to show the tooltip. |
| 102 CHECK(!tooltip_timer_.IsRunning()); |
| 103 tooltip_timer_.Start(FROM_HERE, |
| 104 base::TimeDelta::FromMilliseconds(kTooltipTimeoutMs), |
| 105 this, &TooltipManagerViews::TooltipTimerFired); |
| 106 break; |
| 107 case ui::ET_MOUSE_MOVED: |
| 108 OnMouseMoved(event.location().x(), event.location().y()); |
| 109 break; |
| 110 case ui::ET_MOUSE_PRESSED: |
| 111 case ui::ET_MOUSE_RELEASED: |
| 112 case ui::ET_MOUSE_DRAGGED: |
| 113 case ui::ET_MOUSEWHEEL: |
| 114 // Hide the tooltip for click, release, drag, wheel events. |
| 115 if (tooltip_widget_->IsVisible()) |
| 116 tooltip_widget_->Hide(); |
| 117 break; |
| 118 default: |
| 119 NOTIMPLEMENTED(); |
| 120 } |
| 121 } |
| 122 |
| 96 void TooltipManagerViews::UpdateTooltip() { | 123 void TooltipManagerViews::UpdateTooltip() { |
| 97 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); | 124 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); |
| 98 } | 125 } |
| 99 | 126 |
| 100 void TooltipManagerViews::TooltipTextChanged(View* view) { | 127 void TooltipManagerViews::TooltipTextChanged(View* view) { |
| 101 if (tooltip_widget_->IsVisible()) | 128 if (tooltip_widget_->IsVisible()) |
| 102 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); | 129 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); |
| 103 } | 130 } |
| 104 | 131 |
| 105 void TooltipManagerViews::ShowKeyboardTooltip(View* view) { | 132 void TooltipManagerViews::ShowKeyboardTooltip(View* view) { |
| 106 NOTREACHED(); | 133 NOTREACHED(); |
| 107 } | 134 } |
| 108 | 135 |
| 109 void TooltipManagerViews::HideKeyboardTooltip() { | 136 void TooltipManagerViews::HideKeyboardTooltip() { |
| 110 NOTREACHED(); | 137 NOTREACHED(); |
| 111 } | 138 } |
| 112 | 139 |
| 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() { | 140 void TooltipManagerViews::TooltipTimerFired() { |
| 154 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); | 141 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); |
| 155 } | 142 } |
| 156 | 143 |
| 157 View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) { | 144 View* TooltipManagerViews::GetViewForTooltip(int x, int y, bool for_keyboard) { |
| 158 View* view = NULL; | 145 View* view = NULL; |
| 159 if (!for_keyboard) { | 146 if (!for_keyboard) { |
| 160 // Convert x,y from screen coordinates to |root_view_| coordinates. | 147 // Convert x,y from screen coordinates to |root_view_| coordinates. |
| 161 gfx::Point point(x, y); | 148 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); | 149 View::ConvertPointFromWidget(root_view_, &point); |
| 165 view = root_view_->GetEventHandlerForPoint(point); | 150 view = root_view_->GetEventHandlerForPoint(point); |
| 166 } else { | 151 } else { |
| 167 FocusManager* focus_manager = root_view_->GetFocusManager(); | 152 FocusManager* focus_manager = root_view_->GetFocusManager(); |
| 168 if (focus_manager) | 153 if (focus_manager) |
| 169 view = focus_manager->GetFocusedView(); | 154 view = focus_manager->GetFocusedView(); |
| 170 } | 155 } |
| 171 return view; | 156 return view; |
| 172 } | 157 } |
| 173 | 158 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 if (tooltip_timer_.IsRunning()) | 232 if (tooltip_timer_.IsRunning()) |
| 248 tooltip_timer_.Reset(); | 233 tooltip_timer_.Reset(); |
| 249 curr_mouse_pos_.SetPoint(x, y); | 234 curr_mouse_pos_.SetPoint(x, y); |
| 250 | 235 |
| 251 // If tooltip is visible, we may want to hide it. If it is not, we are ok. | 236 // If tooltip is visible, we may want to hide it. If it is not, we are ok. |
| 252 if (tooltip_widget_->IsVisible()) | 237 if (tooltip_widget_->IsVisible()) |
| 253 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); | 238 UpdateIfRequired(curr_mouse_pos_.x(), curr_mouse_pos_.y(), false); |
| 254 } | 239 } |
| 255 | 240 |
| 256 } // namespace views | 241 } // namespace views |
| OLD | NEW |