Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / autofill / tooltip_icon.h
blob8a7debdb680d0ac6f64a2d4d5ffba0c1b88265b0
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/controls/image_view.h"
15 #include "ui/views/mouse_watcher.h"
16 #include "ui/views/widget/widget_observer.h"
18 namespace autofill {
20 class InfoBubble;
22 // A tooltip icon that shows a bubble on hover. Looks like (?).
23 class TooltipIcon : public views::ImageView,
24 public views::MouseWatcherListener,
25 public views::WidgetObserver {
26 public:
27 static const char kViewClassName[];
29 explicit TooltipIcon(const base::string16& tooltip);
30 virtual ~TooltipIcon();
32 // views::ImageView:
33 virtual const char* GetClassName() const OVERRIDE;
34 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE;
35 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE;
36 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
37 virtual void OnBoundsChanged(const gfx::Rect& prev_bounds) OVERRIDE;
38 virtual void OnFocus() OVERRIDE;
39 virtual void OnBlur() OVERRIDE;
41 // views::MouseWatcherListener:
42 virtual void MouseMovedOutOfHost() OVERRIDE;
44 // views::WidgetObserver:
45 virtual void OnWidgetDestroyed(views::Widget* widget) OVERRIDE;
47 private:
48 // Changes this view's image to the resource indicated by |idr|.
49 void ChangeImageTo(int idr);
51 // Creates and shows |bubble_|. If |bubble_| already exists, just cancels a
52 // potential close timer.
53 void ShowBubble();
55 // Hides |bubble_| if necessary.
56 void HideBubble();
58 // The text to show in a bubble when hovered.
59 base::string16 tooltip_;
61 // Whether the mouse is inside this tooltip.
62 bool mouse_inside_;
64 // A bubble shown on hover. Weak; owns itself. NULL while hiding.
65 InfoBubble* bubble_;
67 // A timer to delay showing |bubble_|.
68 base::OneShotTimer<TooltipIcon> show_timer_;
70 // A watcher that keeps |bubble_| open if the user's mouse enters it.
71 scoped_ptr<views::MouseWatcher> mouse_watcher_;
73 ScopedObserver<views::Widget, TooltipIcon> observer_;
75 DISALLOW_COPY_AND_ASSIGN(TooltipIcon);
78 } // namespace autofill
80 #endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_TOOLTIP_ICON_H_