OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 UI_VIEWS_COREWM_TOOLTIP_AURA_H_ | 5 #ifndef UI_VIEWS_COREWM_TOOLTIP_AURA_H_ |
6 #define UI_VIEWS_COREWM_TOOLTIP_AURA_H_ | 6 #define UI_VIEWS_COREWM_TOOLTIP_AURA_H_ |
7 | 7 |
8 #include "ui/gfx/screen_type_delegate.h" | 8 #include "ui/gfx/screen_type_delegate.h" |
9 #include "ui/views/controls/label.h" | 9 #include "ui/views/controls/label.h" |
10 #include "ui/views/corewm/tooltip.h" | 10 #include "ui/views/corewm/tooltip.h" |
11 #include "ui/views/widget/widget_observer.h" | 11 #include "ui/views/widget/widget_observer.h" |
12 | 12 |
13 namespace gfx { | 13 namespace gfx { |
14 class FontList; | 14 class FontList; |
15 } // namespace gfx | 15 } // namespace gfx |
16 | 16 |
17 namespace views { | 17 namespace views { |
18 | 18 |
19 class Widget; | 19 class Widget; |
20 | 20 |
21 namespace corewm { | 21 namespace corewm { |
22 | 22 |
23 // Implementation of Tooltip that shows the tooltip using a Widget and Label. | 23 // Implementation of Tooltip that shows the tooltip using a Widget and Label. |
24 class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver { | 24 class VIEWS_EXPORT TooltipAura : public Tooltip, public WidgetObserver { |
25 public: | 25 public: |
26 explicit TooltipAura(gfx::ScreenType screen_type); | 26 TooltipAura(); |
27 ~TooltipAura() override; | 27 ~TooltipAura() override; |
28 | 28 |
29 // Trims the tooltip to fit in the width |max_width|, setting |text| to the | 29 // Trims the tooltip to fit in the width |max_width|, setting |text| to the |
30 // clipped result, |width| to the width (in pixels) of the clipped text | 30 // clipped result, |width| to the width (in pixels) of the clipped text |
31 // and |line_count| to the number of lines of text in the tooltip. |font_list| | 31 // and |line_count| to the number of lines of text in the tooltip. |font_list| |
32 // is used to layout |text|. |max_width| comes from GetMaxWidth(). | 32 // is used to layout |text|. |max_width| comes from GetMaxWidth(). |
33 static void TrimTooltipToFit(const gfx::FontList& font_list, | 33 static void TrimTooltipToFit(const gfx::FontList& font_list, |
34 int max_width, | 34 int max_width, |
35 base::string16* text, | 35 base::string16* text, |
36 int* width, | 36 int* width, |
37 int* line_count); | 37 int* line_count); |
38 | 38 |
39 private: | 39 private: |
40 // Returns the max width of the tooltip when shown at the specified location. | |
41 int GetMaxWidth(const gfx::Point& location) const; | |
42 | |
43 // Adjusts the bounds given by the arguments to fit inside the desktop | 40 // Adjusts the bounds given by the arguments to fit inside the desktop |
44 // and applies the adjusted bounds to the label_. | 41 // and applies the adjusted bounds to the label_. |
45 void SetTooltipBounds(const gfx::Point& mouse_pos, | 42 void SetTooltipBounds(const gfx::Point& mouse_pos, |
46 const gfx::Size& tooltip_size); | 43 const gfx::Size& tooltip_size); |
47 | 44 |
48 // Destroys |widget_|. | 45 // Destroys |widget_|. |
49 void DestroyWidget(); | 46 void DestroyWidget(); |
50 | 47 |
51 // Tooltip: | 48 // Tooltip: |
| 49 int GetMaxWidth(const gfx::Point& location, |
| 50 aura::Window* context) const override; |
52 void SetText(aura::Window* window, | 51 void SetText(aura::Window* window, |
53 const base::string16& tooltip_text, | 52 const base::string16& tooltip_text, |
54 const gfx::Point& location) override; | 53 const gfx::Point& location) override; |
55 void Show() override; | 54 void Show() override; |
56 void Hide() override; | 55 void Hide() override; |
57 bool IsVisible() override; | 56 bool IsVisible() override; |
58 | 57 |
59 // WidgetObserver: | 58 // WidgetObserver: |
60 void OnWidgetDestroying(Widget* widget) override; | 59 void OnWidgetDestroying(Widget* widget) override; |
61 | 60 |
62 const gfx::ScreenType screen_type_; | |
63 | |
64 // The label showing the tooltip. | 61 // The label showing the tooltip. |
65 Label label_; | 62 Label label_; |
66 | 63 |
67 // The widget containing the tooltip. May be NULL. | 64 // The widget containing the tooltip. May be NULL. |
68 Widget* widget_; | 65 Widget* widget_; |
69 | 66 |
70 // The window we're showing the tooltip for. Never NULL and valid while | 67 // The window we're showing the tooltip for. Never NULL and valid while |
71 // showing. | 68 // showing. |
72 aura::Window* tooltip_window_; | 69 aura::Window* tooltip_window_; |
73 | 70 |
74 DISALLOW_COPY_AND_ASSIGN(TooltipAura); | 71 DISALLOW_COPY_AND_ASSIGN(TooltipAura); |
75 }; | 72 }; |
76 | 73 |
77 } // namespace corewm | 74 } // namespace corewm |
78 } // namespace views | 75 } // namespace views |
79 | 76 |
80 #endif // UI_VIEWS_COREWM_TOOLTIP_AURA_H_ | 77 #endif // UI_VIEWS_COREWM_TOOLTIP_AURA_H_ |
OLD | NEW |