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
3 // found in the LICENSE file.
5 #ifndef ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_
6 #define ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_
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/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"
24 class BubbleDelegateView;
30 class ShelfTooltipManagerTest;
36 class ShelfLayoutManager;
38 // ShelfTooltipManager manages the tooltip balloon poping up on shelf items.
39 class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler,
40 public ShelfLayoutManagerObserver {
42 ShelfTooltipManager(ShelfLayoutManager* shelf_layout_manager,
43 ShelfView* shelf_view);
44 virtual ~ShelfTooltipManager();
46 ShelfLayoutManager* shelf_layout_manager() { return shelf_layout_manager_; }
48 // Called when the bubble is closed.
49 void OnBubbleClosed(views::BubbleDelegateView* view);
51 // Shows the tooltip after a delay. It also has the appearing animation.
52 void ShowDelayed(views::View* anchor, const base::string16& text);
54 // Shows the tooltip immediately. It omits the appearing animation.
55 void ShowImmediately(views::View* anchor, const base::string16& text);
57 // Closes the tooltip.
60 // Changes the arrow location of the tooltip in case that the launcher
61 // arrangement has changed.
64 // Resets the timer for the delayed showing |view_|. If the timer isn't
65 // running, it starts a new timer.
68 // Stops the timer for the delayed showing |view_|.
71 // Returns true if the tooltip is currently visible.
74 // Returns the view to which the tooltip bubble is anchored. May be NULL.
75 views::View* GetCurrentAnchorView() { return anchor_; }
77 // Create an instant timer for test purposes.
78 void CreateZeroDelayTimerForTest();
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;
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;
94 class ShelfTooltipBubble;
95 friend class test::ShelfViewTest;
96 friend class test::ShelfTooltipManagerTest;
98 void CancelHidingAnimation();
101 void CreateBubble(views::View* anchor, const base::string16& text);
102 void CreateTimer(int delay_in_ms);
104 ShelfTooltipBubble* view_;
105 views::Widget* widget_;
106 views::View* anchor_;
107 base::string16 text_;
108 scoped_ptr<base::Timer> timer_;
110 ShelfLayoutManager* shelf_layout_manager_;
111 ShelfView* shelf_view_;
113 base::WeakPtrFactory<ShelfTooltipManager> weak_factory_;
115 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager);
118 } // namespace internal
121 #endif // ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_