| 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 ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ | 5 #ifndef ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ |
| 6 #define ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ | 6 #define ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ |
| 7 | 7 |
| 8 #include "ash/ash_export.h" | 8 #include "ash/ash_export.h" |
| 9 #include "ash/shelf/shelf_layout_manager_observer.h" | 9 #include "ash/shelf/shelf_layout_manager_observer.h" |
| 10 #include "ash/shelf/shelf_types.h" | |
| 11 #include "base/macros.h" | 10 #include "base/macros.h" |
| 12 #include "base/memory/weak_ptr.h" | 11 #include "base/memory/weak_ptr.h" |
| 13 #include "base/strings/string16.h" | 12 #include "base/strings/string16.h" |
| 13 #include "base/timer/timer.h" |
| 14 #include "ui/events/event_handler.h" | 14 #include "ui/events/event_handler.h" |
| 15 #include "ui/gfx/geometry/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 | 15 |
| 23 namespace views { | 16 namespace views { |
| 24 class BubbleDelegateView; | 17 class BubbleDelegateView; |
| 25 class Label; | 18 class View; |
| 26 } | 19 } |
| 27 | 20 |
| 28 namespace ash { | 21 namespace ash { |
| 22 class ShelfLayoutManager; |
| 29 class ShelfView; | 23 class ShelfView; |
| 30 class ShelfLayoutManager; | |
| 31 | 24 |
| 32 namespace test { | 25 namespace test { |
| 33 class ShelfTooltipManagerTest; | 26 class ShelfTooltipManagerTest; |
| 34 class ShelfViewTest; | 27 class ShelfViewTest; |
| 35 } | 28 } |
| 36 | 29 |
| 37 // ShelfTooltipManager manages the tooltip balloon poping up on shelf items. | 30 // ShelfTooltipManager manages the tooltip bubble that appears for shelf items. |
| 38 class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, | 31 class ASH_EXPORT ShelfTooltipManager : public ui::EventHandler, |
| 39 public ShelfLayoutManagerObserver { | 32 public ShelfLayoutManagerObserver { |
| 40 public: | 33 public: |
| 41 ShelfTooltipManager(ShelfLayoutManager* shelf_layout_manager, | 34 explicit ShelfTooltipManager(ShelfView* shelf_view); |
| 42 ShelfView* shelf_view); | |
| 43 ~ShelfTooltipManager() override; | 35 ~ShelfTooltipManager() override; |
| 44 | 36 |
| 45 ShelfLayoutManager* shelf_layout_manager() { return shelf_layout_manager_; } | 37 // Initializes the tooltip manager once the shelf is shown. |
| 46 | 38 void Init(); |
| 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 | 39 |
| 56 // Closes the tooltip. | 40 // Closes the tooltip. |
| 57 void Close(); | 41 void Close(); |
| 58 | 42 |
| 59 // Changes the arrow location of the tooltip in case that the launcher | 43 // Returns true if the tooltip is currently visible. |
| 60 // arrangement has changed. | 44 bool IsVisible() const; |
| 61 void UpdateArrow(); | |
| 62 | 45 |
| 63 // Resets the timer for the delayed showing |view_|. If the timer isn't | 46 // Returns the view to which the tooltip bubble is anchored. May be null. |
| 64 // running, it starts a new timer. | 47 views::View* GetCurrentAnchorView() const; |
| 65 void ResetTimer(); | |
| 66 | 48 |
| 67 // Stops the timer for the delayed showing |view_|. | 49 // Show the tooltip bubble for the specified view. |
| 68 void StopTimer(); | 50 void ShowTooltip(views::View* view); |
| 51 void ShowTooltipWithDelay(views::View* view); |
| 69 | 52 |
| 70 // Returns true if the tooltip is currently visible. | 53 // Set the timer delay in ms for testing. |
| 71 bool IsVisible(); | 54 void set_timer_delay_for_test(int timer_delay) { timer_delay_ = timer_delay; } |
| 72 | 55 |
| 73 // Returns the view to which the tooltip bubble is anchored. May be NULL. | 56 protected: |
| 74 views::View* GetCurrentAnchorView() { return anchor_; } | |
| 75 | |
| 76 // Create an instant timer for test purposes. | |
| 77 void CreateZeroDelayTimerForTest(); | |
| 78 | |
| 79 protected: | |
| 80 // ui::EventHandler overrides: | 57 // ui::EventHandler overrides: |
| 81 void OnMouseEvent(ui::MouseEvent* event) override; | 58 void OnEvent(ui::Event* event) override; |
| 82 void OnTouchEvent(ui::TouchEvent* event) override; | |
| 83 void OnGestureEvent(ui::GestureEvent* event) override; | |
| 84 void OnCancelMode(ui::CancelModeEvent* event) override; | |
| 85 | 59 |
| 86 // ShelfLayoutManagerObserver overrides: | 60 // ShelfLayoutManagerObserver overrides: |
| 87 void WillDeleteShelf() override; | 61 void WillDeleteShelf() override; |
| 88 void WillChangeVisibilityState(ShelfVisibilityState new_state) override; | 62 void WillChangeVisibilityState(ShelfVisibilityState new_state) override; |
| 89 void OnAutoHideStateChanged(ShelfAutoHideState new_state) override; | 63 void OnAutoHideStateChanged(ShelfAutoHideState new_state) override; |
| 90 | 64 |
| 91 private: | 65 private: |
| 92 class ShelfTooltipBubble; | 66 class ShelfTooltipBubble; |
| 93 friend class test::ShelfViewTest; | 67 friend class test::ShelfViewTest; |
| 94 friend class test::ShelfTooltipManagerTest; | 68 friend class test::ShelfTooltipManagerTest; |
| 95 | 69 |
| 96 void CancelHidingAnimation(); | 70 int timer_delay_; |
| 97 void CloseSoon(); | 71 base::OneShotTimer timer_; |
| 98 void ShowInternal(); | |
| 99 void CreateBubble(views::View* anchor, const base::string16& text); | |
| 100 void CreateTimer(int delay_in_ms); | |
| 101 | 72 |
| 102 ShelfTooltipBubble* view_; | 73 ShelfView* shelf_view_; |
| 103 views::Widget* widget_; | |
| 104 views::View* anchor_; | |
| 105 base::string16 text_; | |
| 106 scoped_ptr<base::Timer> timer_; | |
| 107 | |
| 108 ShelfLayoutManager* shelf_layout_manager_; | 74 ShelfLayoutManager* shelf_layout_manager_; |
| 109 ShelfView* shelf_view_; | 75 views::BubbleDelegateView* bubble_; |
| 110 | 76 |
| 111 base::WeakPtrFactory<ShelfTooltipManager> weak_factory_; | 77 base::WeakPtrFactory<ShelfTooltipManager> weak_factory_; |
| 112 | 78 |
| 113 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager); | 79 DISALLOW_COPY_AND_ASSIGN(ShelfTooltipManager); |
| 114 }; | 80 }; |
| 115 | 81 |
| 116 } // namespace ash | 82 } // namespace ash |
| 117 | 83 |
| 118 #endif // ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ | 84 #endif // ASH_SHELF_SHELF_TOOLTIP_MANAGER_H_ |
| OLD | NEW |