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