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"
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
{
28 static const char kViewClassName
[];
30 explicit TooltipIcon(const base::string16
& tooltip
);
31 ~TooltipIcon() override
;
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
;
51 // Changes this view's image to the resource indicated by |idr|.
52 void ChangeImageTo(int idr
);
54 // Creates and shows |bubble_|. If |bubble_| already exists, just cancels a
55 // potential close timer.
58 // Hides |bubble_| if necessary.
61 // The text to show in a bubble when hovered.
62 base::string16 tooltip_
;
64 // Whether the mouse is inside this tooltip.
67 // A bubble shown on hover. Weak; owns itself. NULL while hiding.
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_