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