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