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 #ifndef VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ | 5 #ifndef VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ |
6 #define VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ | 6 #define VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/timer.h" | 10 #include "base/timer.h" |
11 #include "views/controls/label.h" | 11 #include "views/controls/label.h" |
12 #include "views/widget/native_widget.h" | 12 #include "views/widget/native_widget.h" |
13 #include "views/widget/tooltip_manager.h" | 13 #include "views/widget/tooltip_manager.h" |
14 #include "views/widget/widget_delegate.h" | 14 #include "views/widget/widget_delegate.h" |
15 #include "views/view.h" | 15 #include "views/view.h" |
16 | 16 |
17 #if defined(USE_X11) | 17 #if defined(USE_X11) |
18 typedef union _XEvent XEvent; | 18 typedef union _XEvent XEvent; |
19 namespace ui { | 19 namespace ui { |
20 union WaylandEvent; | 20 union WaylandEvent; |
21 } | 21 } |
22 #endif | 22 #endif |
23 | 23 |
24 namespace views { | 24 namespace views { |
25 | 25 |
26 class Widget; | 26 class Widget; |
27 | 27 |
28 // TooltipManager implementation for Views. | 28 // TooltipManager implementation for Views. |
29 class TooltipManagerViews : public TooltipManager, | 29 class TooltipManagerViews : public TooltipManager, |
30 public MessageLoopForUI::Observer { | 30 public MessageLoopForUI::Observer, |
| 31 public Widget::Observer { |
31 public: | 32 public: |
32 explicit TooltipManagerViews(views::View* root_view); | 33 explicit TooltipManagerViews(views::View* root_view); |
33 virtual ~TooltipManagerViews(); | 34 virtual ~TooltipManagerViews(); |
34 | 35 |
35 // TooltipManager. | 36 // TooltipManager. |
36 virtual void UpdateTooltip() OVERRIDE; | 37 virtual void UpdateTooltip() OVERRIDE; |
37 virtual void TooltipTextChanged(View* view) OVERRIDE; | 38 virtual void TooltipTextChanged(View* view) OVERRIDE; |
38 virtual void ShowKeyboardTooltip(View* view) OVERRIDE; | 39 virtual void ShowKeyboardTooltip(View* view) OVERRIDE; |
39 virtual void HideKeyboardTooltip() OVERRIDE; | 40 virtual void HideKeyboardTooltip() OVERRIDE; |
40 | 41 |
41 #if defined(USE_WAYLAND) | 42 #if defined(USE_WAYLAND) |
42 virtual base::MessagePumpObserver::EventStatus WillProcessEvent( | 43 virtual base::MessagePumpObserver::EventStatus WillProcessEvent( |
43 ui::WaylandEvent* event) OVERRIDE; | 44 ui::WaylandEvent* event) OVERRIDE; |
44 #else | 45 #else |
45 // MessageLoopForUI::Observer | 46 // MessageLoopForUI::Observer |
46 virtual base::EventStatus WillProcessEvent( | 47 virtual base::EventStatus WillProcessEvent( |
47 const base::NativeEvent& event) OVERRIDE; | 48 const base::NativeEvent& event) OVERRIDE; |
48 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; | 49 virtual void DidProcessEvent(const base::NativeEvent& event) OVERRIDE; |
49 #endif | 50 #endif |
50 | 51 |
| 52 // Widget::Observer |
| 53 virtual void OnWidgetClosing(Widget* widget) OVERRIDE; |
| 54 |
51 private: | 55 private: |
52 void TooltipTimerFired(); | 56 void TooltipTimerFired(); |
53 View* GetViewForTooltip(int x, int y, bool for_keyboard); | 57 View* GetViewForTooltip(int x, int y, bool for_keyboard); |
54 | 58 |
55 // Updates the tooltip if required (if there is any change in the tooltip | 59 // Updates the tooltip if required (if there is any change in the tooltip |
56 // text or the view. | 60 // text or the view. |
57 void UpdateIfRequired(int x, int y, bool for_keyboard); | 61 void UpdateIfRequired(int x, int y, bool for_keyboard); |
58 | 62 |
59 // Updates the tooltip. Gets the tooltip text from tooltip_view_ and displays | 63 // Updates the tooltip. Gets the tooltip text from tooltip_view_ and displays |
60 // it at the current mouse position. | 64 // it at the current mouse position. |
(...skipping 12 matching lines...) Expand all Loading... |
73 | 77 |
74 scoped_ptr<Widget> tooltip_widget_; | 78 scoped_ptr<Widget> tooltip_widget_; |
75 views::View* root_view_; | 79 views::View* root_view_; |
76 View* tooltip_view_; | 80 View* tooltip_view_; |
77 string16 tooltip_text_; | 81 string16 tooltip_text_; |
78 Label tooltip_label_; | 82 Label tooltip_label_; |
79 | 83 |
80 gfx::Point curr_mouse_pos_; | 84 gfx::Point curr_mouse_pos_; |
81 base::RepeatingTimer<TooltipManagerViews> tooltip_timer_; | 85 base::RepeatingTimer<TooltipManagerViews> tooltip_timer_; |
82 | 86 |
| 87 // true when the widget that owns us has closed. |
| 88 bool widget_closed_; |
| 89 |
83 DISALLOW_COPY_AND_ASSIGN(TooltipManagerViews); | 90 DISALLOW_COPY_AND_ASSIGN(TooltipManagerViews); |
84 }; | 91 }; |
85 | 92 |
86 } // namespace views | 93 } // namespace views |
87 | 94 |
88 #endif // VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ | 95 #endif // VIEWS_WIDGET_TOOLTIP_MANAGER_VIEWS_H_ |
OLD | NEW |