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 3 // found in the LICENSE file. 4 5 #ifndef UI_VIEWS_WIDGET_TOOLTIP_MANAGER_H_ 6 #define UI_VIEWS_WIDGET_TOOLTIP_MANAGER_H_ 7 8 #include <string> 9 10 #include "base/basictypes.h" 11 #include "base/strings/string16.h" 12 #include "ui/gfx/native_widget_types.h" 13 #include "ui/views/views_export.h" 14 15 namespace gfx { 16 class Font; 17 } // namespace gfx 18 19 namespace views { 20 21 class View; 22 23 // TooltipManager takes care of the wiring to support tooltips for Views. You 24 // almost never need to interact directly with TooltipManager, rather look to 25 // the various tooltip methods on View. 26 class VIEWS_EXPORT TooltipManager { 27 public: 28 // Returns the height of tooltips. This should only be invoked from within 29 // GetTooltipTextOrigin. 30 static int GetTooltipHeight(); 31 32 // Returns the default font used by tooltips. 33 static gfx::Font GetDefaultFont(); 34 35 // Returns the maximum width of the tooltip. |x| and |y| give the location 36 // the tooltip is to be displayed on in screen coordinates. |context| is 37 // used to determine which gfx::Screen should be used. 38 static int GetMaxWidth(int x, int y, gfx::NativeView context); 39 40 TooltipManager() {} 41 virtual ~TooltipManager() {} 42 43 // Notification that the view hierarchy has changed in some way. 44 virtual void UpdateTooltip() = 0; 45 46 // Invoked when the tooltip text changes for the specified views. 47 virtual void TooltipTextChanged(View* view) = 0; 48 49 // Invoked when toolbar icon gets focus. 50 virtual void ShowKeyboardTooltip(View* view) = 0; 51 52 // Invoked when toolbar loses focus. 53 virtual void HideKeyboardTooltip() = 0; 54 55 protected: 56 // Trims the tooltip to fit, setting |text| to the clipped result, 57 // |max_width| to the width (in pixels) of the clipped text and |line_count| 58 // to the number of lines of text in the tooltip. |x| and |y| give the 59 // location of the tooltip in screen coordinates. |context| is used to 60 // determine which gfx::Screen should be used. 61 static void TrimTooltipToFit(string16* text, 62 int* max_width, 63 int* line_count, 64 int x, 65 int y, 66 gfx::NativeView context); 67 }; 68 69 } // namespace views 70 71 #endif // UI_VIEWS_WIDGET_TOOLTIP_MANAGER_H_ 72