OLD | NEW |
| (Empty) |
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 CHROME_BROWSER_UI_VIEWS_AUTOFILL_TOOLTIP_ICON_H_ | |
6 #define CHROME_BROWSER_UI_VIEWS_AUTOFILL_TOOLTIP_ICON_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "base/macros.h" | |
12 #include "base/scoped_observer.h" | |
13 #include "base/strings/string16.h" | |
14 #include "base/timer/timer.h" | |
15 #include "ui/views/bubble/bubble_border.h" | |
16 #include "ui/views/controls/image_view.h" | |
17 #include "ui/views/mouse_watcher.h" | |
18 #include "ui/views/widget/widget_observer.h" | |
19 | |
20 namespace autofill { | |
21 | |
22 class InfoBubble; | |
23 | |
24 // A tooltip icon that shows a bubble on hover. Looks like (?). | |
25 class TooltipIcon : public views::ImageView, | |
26 public views::MouseWatcherListener, | |
27 public views::WidgetObserver { | |
28 public: | |
29 static const char kViewClassName[]; | |
30 | |
31 explicit TooltipIcon(const base::string16& tooltip); | |
32 ~TooltipIcon() override; | |
33 | |
34 // views::ImageView: | |
35 const char* GetClassName() const override; | |
36 void OnMouseEntered(const ui::MouseEvent& event) override; | |
37 void OnMouseExited(const ui::MouseEvent& event) override; | |
38 void OnGestureEvent(ui::GestureEvent* event) override; | |
39 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | |
40 | |
41 // views::MouseWatcherListener: | |
42 void MouseMovedOutOfHost() override; | |
43 | |
44 // views::WidgetObserver: | |
45 void OnWidgetDestroyed(views::Widget* widget) override; | |
46 | |
47 void set_bubble_arrow(views::BubbleBorder::Arrow arrow) { | |
48 bubble_arrow_ = arrow; | |
49 } | |
50 | |
51 private: | |
52 // Changes the color to reflect the hover node_data. | |
53 void SetDrawAsHovered(bool hovered); | |
54 | |
55 // Creates and shows |bubble_|. If |bubble_| already exists, just cancels a | |
56 // potential close timer. | |
57 void ShowBubble(); | |
58 | |
59 // Hides |bubble_| if necessary. | |
60 void HideBubble(); | |
61 | |
62 // The text to show in a bubble when hovered. | |
63 base::string16 tooltip_; | |
64 | |
65 // Whether the mouse is inside this tooltip. | |
66 bool mouse_inside_; | |
67 | |
68 // A bubble shown on hover. Weak; owns itself. NULL while hiding. | |
69 InfoBubble* bubble_; | |
70 | |
71 // The position of the bubble's arrow. | |
72 views::BubbleBorder::Arrow bubble_arrow_; | |
73 | |
74 // A timer to delay showing |bubble_|. | |
75 base::OneShotTimer show_timer_; | |
76 | |
77 // A watcher that keeps |bubble_| open if the user's mouse enters it. | |
78 std::unique_ptr<views::MouseWatcher> mouse_watcher_; | |
79 | |
80 ScopedObserver<views::Widget, TooltipIcon> observer_; | |
81 | |
82 DISALLOW_COPY_AND_ASSIGN(TooltipIcon); | |
83 }; | |
84 | |
85 } // namespace autofill | |
86 | |
87 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_TOOLTIP_ICON_H_ | |
OLD | NEW |