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 #include "chrome/browser/ui/views/autofill/tooltip_icon.h" | 5 #include "ui/views/bubble/tooltip_icon.h" |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
msw
2017/02/15 21:06:39
nit: remove
vasilii
2017/02/16 14:28:07
Done.
| |
8 #include "base/timer/timer.h" | 8 #include "base/timer/timer.h" |
9 #include "chrome/browser/ui/views/autofill/info_bubble.h" | |
10 #include "ui/accessibility/ax_node_data.h" | 9 #include "ui/accessibility/ax_node_data.h" |
11 #include "ui/gfx/paint_vector_icon.h" | 10 #include "ui/gfx/paint_vector_icon.h" |
12 #include "ui/gfx/vector_icons_public.h" | 11 #include "ui/gfx/vector_icons_public.h" |
13 #include "ui/views/bubble/bubble_frame_view.h" | 12 #include "ui/views/bubble/bubble_frame_view.h" |
13 #include "ui/views/bubble/info_bubble.h" | |
14 #include "ui/views/mouse_watcher_view_host.h" | 14 #include "ui/views/mouse_watcher_view_host.h" |
15 #include "ui/views/painter.h" | 15 #include "ui/views/painter.h" |
msw
2017/02/15 21:06:39
nit: remove?
vasilii
2017/02/16 14:28:06
Done.
| |
16 | 16 |
17 namespace autofill { | 17 namespace views { |
18 | |
19 namespace { | |
20 | |
21 gfx::Insets GetPreferredInsets(const views::View* view) { | |
22 gfx::Size pref_size = view->GetPreferredSize(); | |
23 gfx::Rect local_bounds = view->GetLocalBounds(); | |
24 gfx::Point origin = local_bounds.CenterPoint(); | |
25 origin.Offset(-pref_size.width() / 2, -pref_size.height() / 2); | |
26 return gfx::Insets(origin.y(), | |
27 origin.x(), | |
28 local_bounds.bottom() - (origin.y() + pref_size.height()), | |
29 local_bounds.right() - (origin.x() + pref_size.width())); | |
30 } | |
31 | |
32 // An info bubble with some extra positioning magic for tooltip icons. | |
33 class TooltipBubble : public InfoBubble { | |
34 public: | |
35 TooltipBubble(views::View* anchor, const base::string16& message) | |
36 : InfoBubble(anchor, message) {} | |
37 ~TooltipBubble() override {} | |
38 | |
39 protected: | |
40 // InfoBubble: | |
41 gfx::Rect GetAnchorRect() const override { | |
42 gfx::Rect bounds = views::BubbleDialogDelegateView::GetAnchorRect(); | |
43 bounds.Inset(GetPreferredInsets(anchor())); | |
44 return bounds; | |
45 } | |
46 | |
47 private: | |
48 DISALLOW_COPY_AND_ASSIGN(TooltipBubble); | |
49 }; | |
50 | |
51 } // namespace | |
52 | 18 |
53 TooltipIcon::TooltipIcon(const base::string16& tooltip) | 19 TooltipIcon::TooltipIcon(const base::string16& tooltip) |
54 : tooltip_(tooltip), | 20 : tooltip_(tooltip), |
55 mouse_inside_(false), | 21 mouse_inside_(false), |
56 bubble_(NULL), | 22 bubble_(NULL), |
57 bubble_arrow_(views::BubbleBorder::TOP_RIGHT), | 23 preferred_width_(0), |
24 bubble_arrow_(BubbleBorder::TOP_RIGHT), | |
58 observer_(this) { | 25 observer_(this) { |
59 SetDrawAsHovered(false); | 26 SetDrawAsHovered(false); |
60 } | 27 } |
61 | 28 |
62 TooltipIcon::~TooltipIcon() { | 29 TooltipIcon::~TooltipIcon() { |
63 HideBubble(); | 30 HideBubble(); |
64 } | 31 } |
65 | 32 |
66 // static | 33 // static |
67 const char TooltipIcon::kViewClassName[] = "autofill/TooltipIcon"; | 34 const char TooltipIcon::kViewClassName[] = "autofill/TooltipIcon"; |
msw
2017/02/15 21:06:39
nit: update 'autofill'
vasilii
2017/02/16 14:28:06
Done.
| |
68 | 35 |
69 const char* TooltipIcon::GetClassName() const { | 36 const char* TooltipIcon::GetClassName() const { |
70 return TooltipIcon::kViewClassName; | 37 return TooltipIcon::kViewClassName; |
71 } | 38 } |
72 | 39 |
73 void TooltipIcon::OnMouseEntered(const ui::MouseEvent& event) { | 40 void TooltipIcon::OnMouseEntered(const ui::MouseEvent& event) { |
74 mouse_inside_ = true; | 41 mouse_inside_ = true; |
75 show_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(150), this, | 42 show_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(150), this, |
76 &TooltipIcon::ShowBubble); | 43 &TooltipIcon::ShowBubble); |
77 } | 44 } |
(...skipping 17 matching lines...) Expand all Loading... | |
95 if (IsMouseHovered()) { | 62 if (IsMouseHovered()) { |
96 mouse_watcher_->Start(); | 63 mouse_watcher_->Start(); |
97 return; | 64 return; |
98 } | 65 } |
99 | 66 |
100 mouse_inside_ = false; | 67 mouse_inside_ = false; |
101 HideBubble(); | 68 HideBubble(); |
102 } | 69 } |
103 | 70 |
104 void TooltipIcon::SetDrawAsHovered(bool hovered) { | 71 void TooltipIcon::SetDrawAsHovered(bool hovered) { |
105 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::HELP_OUTLINE, 18, | 72 SetImage(gfx::CreateVectorIcon(gfx::VectorIconId::INFO_OUTLINE, 18, |
106 hovered | 73 hovered |
107 ? SkColorSetARGB(0xBD, 0, 0, 0) | 74 ? SkColorSetARGB(0xBD, 0, 0, 0) |
108 : SkColorSetARGB(0xBD, 0x44, 0x44, 0x44))); | 75 : SkColorSetARGB(0xBD, 0x44, 0x44, 0x44))); |
109 } | 76 } |
110 | 77 |
111 void TooltipIcon::ShowBubble() { | 78 void TooltipIcon::ShowBubble() { |
112 if (bubble_) | 79 if (bubble_) |
113 return; | 80 return; |
114 | 81 |
115 SetDrawAsHovered(true); | 82 SetDrawAsHovered(true); |
116 | 83 |
117 bubble_ = new TooltipBubble(this, tooltip_); | 84 bubble_ = new InfoBubble(this, tooltip_); |
85 bubble_->set_preferred_width(preferred_width_); | |
118 bubble_->set_arrow(bubble_arrow_); | 86 bubble_->set_arrow(bubble_arrow_); |
119 // When shown due to a gesture event, close on deactivate (i.e. don't use | 87 // When shown due to a gesture event, close on deactivate (i.e. don't use |
120 // "focusless"). | 88 // "focusless"). |
121 bubble_->set_can_activate(!mouse_inside_); | 89 bubble_->set_can_activate(!mouse_inside_); |
122 | 90 |
123 bubble_->Show(); | 91 bubble_->Show(); |
124 observer_.Add(bubble_->GetWidget()); | 92 observer_.Add(bubble_->GetWidget()); |
125 | 93 |
126 if (mouse_inside_) { | 94 if (mouse_inside_) { |
127 views::View* frame = bubble_->GetWidget()->non_client_view()->frame_view(); | 95 View* frame = bubble_->GetWidget()->non_client_view()->frame_view(); |
128 std::unique_ptr<views::MouseWatcherHost> host( | 96 std::unique_ptr<MouseWatcherHost> host( |
129 new views::MouseWatcherViewHost(frame, gfx::Insets())); | 97 new MouseWatcherViewHost(frame, gfx::Insets())); |
msw
2017/02/15 21:06:39
nit: base::MakeUnique here and below
vasilii
2017/02/16 14:28:07
Done.
| |
130 mouse_watcher_.reset(new views::MouseWatcher(host.release(), this)); | 98 mouse_watcher_.reset(new MouseWatcher(host.release(), this)); |
131 mouse_watcher_->Start(); | 99 mouse_watcher_->Start(); |
132 } | 100 } |
133 } | 101 } |
134 | 102 |
135 void TooltipIcon::HideBubble() { | 103 void TooltipIcon::HideBubble() { |
136 if (bubble_) | 104 if (bubble_) |
137 bubble_->Hide(); | 105 bubble_->Hide(); |
138 } | 106 } |
139 | 107 |
140 void TooltipIcon::OnWidgetDestroyed(views::Widget* widget) { | 108 void TooltipIcon::OnWidgetDestroyed(Widget* widget) { |
141 observer_.Remove(widget); | 109 observer_.Remove(widget); |
142 | 110 |
143 SetDrawAsHovered(false); | 111 SetDrawAsHovered(false); |
144 mouse_watcher_.reset(); | 112 mouse_watcher_.reset(); |
145 bubble_ = NULL; | 113 bubble_ = NULL; |
msw
2017/02/15 21:06:39
nit: nullptr here and elsewhere
vasilii
2017/02/16 14:28:07
Done.
| |
146 } | 114 } |
147 | 115 |
148 } // namespace autofill | 116 bool TooltipIcon::OnMousePressed(const ui::MouseEvent& event) { |
117 // Swallow the click so that the parent doesn't process it. | |
118 return true; | |
119 } | |
120 | |
121 } // namespace views | |
OLD | NEW |