tooltip_icon.h revision a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7
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 "base/basictypes.h" 9#include "base/compiler_specific.h" 10#include "base/memory/scoped_ptr.h" 11#include "base/strings/string16.h" 12#include "base/timer/timer.h" 13#include "ui/views/controls/image_view.h" 14#include "ui/views/mouse_watcher.h" 15 16namespace autofill { 17 18class InfoBubble; 19 20// A tooltip icon that shows a bubble on hover. Looks like (?). 21class TooltipIcon : public views::ImageView, 22 public views::MouseWatcherListener { 23 public: 24 static const char kViewClassName[]; 25 26 explicit TooltipIcon(const base::string16& tooltip); 27 virtual ~TooltipIcon(); 28 29 // views::ImageView: 30 virtual const char* GetClassName() const OVERRIDE; 31 virtual void OnMouseEntered(const ui::MouseEvent& event) OVERRIDE; 32 virtual void OnMouseExited(const ui::MouseEvent& event) OVERRIDE; 33 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 34 virtual void OnBoundsChanged(const gfx::Rect& prev_bounds) OVERRIDE; 35 virtual void OnFocus() OVERRIDE; 36 virtual void OnBlur() OVERRIDE; 37 38 // views::MouseWatcherListener: 39 virtual void MouseMovedOutOfHost() OVERRIDE; 40 41 private: 42 // Changes this view's image to the resource indicated by |idr|. 43 void ChangeImageTo(int idr); 44 45 // Creates and shows |bubble_|. If |bubble_| already exists, just cancels a 46 // potential close timer. 47 void ShowBubble(); 48 49 // Hides |bubble_| if necessary. 50 void HideBubble(); 51 52 // The text to show in a bubble when hovered. 53 base::string16 tooltip_; 54 55 // Whether the mouse is inside this tooltip. 56 bool mouse_inside_; 57 58 // A bubble shown on hover. Weak; owns itself. NULL while hiding. 59 InfoBubble* bubble_; 60 61 // A timer to delay showing |bubble_|. 62 base::OneShotTimer<TooltipIcon> show_timer_; 63 64 // A watcher that keeps |bubble_| open if the user's mouse enters it. 65 scoped_ptr<views::MouseWatcher> mouse_watcher_; 66 67 DISALLOW_COPY_AND_ASSIGN(TooltipIcon); 68}; 69 70} // namespace autofill 71 72#endif // CHROME_BROWSER_UI_VIEWS_AUTOFILL_TOOLTIP_ICON_H_ 73