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