1 // Copyright (c) 2012 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 ASH_LAUNCHER_LAUNCHER_TOOLTIP_MANAGER_H_ 6 #define ASH_LAUNCHER_LAUNCHER_TOOLTIP_MANAGER_H_ 7 8 #include "ash/ash_export.h" 9 #include "ash/shelf/shelf_layout_manager_observer.h" 10 #include "ash/shelf/shelf_types.h" 11 #include "base/basictypes.h" 12 #include "base/memory/weak_ptr.h" 13 #include "base/strings/string16.h" 14 #include "ui/base/events/event_handler.h" 15 #include "ui/gfx/rect.h" 16 #include "ui/views/bubble/bubble_border.h" 17 #include "ui/views/bubble/bubble_delegate.h" 18 19 namespace base { 20 class Timer; 21 } 22 23 namespace views { 24 class BubbleDelegateView; 25 class Label; 26 } 27 28 namespace ash { 29 namespace test { 30 class LauncherTooltipManagerTest; 31 class LauncherViewTest; 32 } 33 34 namespace internal { 35 class LauncherView; 36 class ShelfLayoutManager; 37 38 // LauncherTooltipManager manages the tooltip balloon poping up on launcher 39 // items. 40 class ASH_EXPORT LauncherTooltipManager : public ui::EventHandler, 41 public ShelfLayoutManagerObserver { 42 public: 43 LauncherTooltipManager(ShelfLayoutManager* shelf_layout_manager, 44 LauncherView* launcher_view); 45 virtual ~LauncherTooltipManager(); 46 47 ShelfLayoutManager* shelf_layout_manager() { 48 return shelf_layout_manager_; 49 } 50 51 // Called when the bubble is closed. 52 void OnBubbleClosed(views::BubbleDelegateView* view); 53 54 // Shows the tooltip after a delay. It also has the appearing animation. 55 void ShowDelayed(views::View* anchor, const base::string16& text); 56 57 // Shows the tooltip immediately. It omits the appearing animation. 58 void ShowImmediately(views::View* anchor, const base::string16& text); 59 60 // Closes the tooltip. 61 void Close(); 62 63 // Changes the arrow location of the tooltip in case that the launcher 64 // arrangement has changed. 65 void UpdateArrow(); 66 67 // Resets the timer for the delayed showing |view_|. If the timer isn't 68 // running, it starts a new timer. 69 void ResetTimer(); 70 71 // Stops the timer for the delayed showing |view_|. 72 void StopTimer(); 73 74 // Returns true if the tooltip is currently visible. 75 bool IsVisible(); 76 77 // Create an instant timer for test purposes. 78 void CreateZeroDelayTimerForTest(); 79 80 protected: 81 // ui::EventHandler overrides: 82 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 83 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 84 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 85 virtual void OnCancelMode(ui::CancelModeEvent* event) OVERRIDE; 86 87 // ShelfLayoutManagerObserver overrides: 88 virtual void WillDeleteShelf() OVERRIDE; 89 virtual void WillChangeVisibilityState( 90 ShelfVisibilityState new_state) OVERRIDE; 91 virtual void OnAutoHideStateChanged(ShelfAutoHideState new_state) OVERRIDE; 92 93 private: 94 class LauncherTooltipBubble; 95 friend class test::LauncherViewTest; 96 friend class test::LauncherTooltipManagerTest; 97 98 void CancelHidingAnimation(); 99 void CloseSoon(); 100 void ShowInternal(); 101 void CreateBubble(views::View* anchor, const base::string16& text); 102 void CreateTimer(int delay_in_ms); 103 104 LauncherTooltipBubble* view_; 105 views::Widget* widget_; 106 views::View* anchor_; 107 base::string16 text_; 108 scoped_ptr<base::Timer> timer_; 109 110 ShelfLayoutManager* shelf_layout_manager_; 111 LauncherView* launcher_view_; 112 113 base::WeakPtrFactory<LauncherTooltipManager> weak_factory_; 114 115 DISALLOW_COPY_AND_ASSIGN(LauncherTooltipManager); 116 }; 117 118 } // namespace internal 119 } // namespace ash 120 121 #endif // ASH_LAUNCHER_LAUNCHER_TOOLTIP_MANAGER_H_ 122