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