OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/location_bar/content_setting_image_view.h" | 5 #include "chrome/browser/ui/views/location_bar/content_setting_image_view.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "chrome/browser/themes/theme_properties.h" | 8 #include "chrome/browser/themes/theme_properties.h" |
9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" | 9 #include "chrome/browser/ui/content_settings/content_setting_bubble_model.h" |
10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" | 10 #include "chrome/browser/ui/content_settings/content_setting_image_model.h" |
(...skipping 23 matching lines...) Expand all Loading... | |
34 ContentSettingImageView::ContentSettingImageView( | 34 ContentSettingImageView::ContentSettingImageView( |
35 std::unique_ptr<ContentSettingImageModel> image_model, | 35 std::unique_ptr<ContentSettingImageModel> image_model, |
36 LocationBarView* parent, | 36 LocationBarView* parent, |
37 const gfx::FontList& font_list) | 37 const gfx::FontList& font_list) |
38 : IconLabelBubbleView(font_list, false), | 38 : IconLabelBubbleView(font_list, false), |
39 parent_(parent), | 39 parent_(parent), |
40 content_setting_image_model_(std::move(image_model)), | 40 content_setting_image_model_(std::move(image_model)), |
41 slide_animator_(this), | 41 slide_animator_(this), |
42 pause_animation_(false), | 42 pause_animation_(false), |
43 pause_animation_state_(0.0), | 43 pause_animation_state_(0.0), |
44 bubble_view_(nullptr), | 44 bubble_view_(nullptr) { |
45 suppress_mouse_released_action_(false) { | |
46 set_next_element_interior_padding(LocationBarView::kIconInteriorPadding); | 45 set_next_element_interior_padding(LocationBarView::kIconInteriorPadding); |
47 SetInkDropMode(InkDropMode::ON); | 46 SetInkDropMode(InkDropMode::ON); |
48 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 47 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
49 image()->EnableCanvasFlippingForRTLUI(true); | 48 image()->EnableCanvasFlippingForRTLUI(true); |
50 label()->SetElideBehavior(gfx::NO_ELIDE); | 49 label()->SetElideBehavior(gfx::NO_ELIDE); |
51 label()->SetVisible(false); | 50 label()->SetVisible(false); |
52 | 51 |
53 slide_animator_.SetSlideDuration(kAnimationDurationMS); | 52 slide_animator_.SetSlideDuration(kAnimationDurationMS); |
54 slide_animator_.SetTweenType(gfx::Tween::LINEAR); | 53 slide_animator_.SetTweenType(gfx::Tween::LINEAR); |
55 } | 54 } |
(...skipping 18 matching lines...) Expand all Loading... | |
74 | 73 |
75 // If the content usage or blockage should be indicated to the user, start the | 74 // If the content usage or blockage should be indicated to the user, start the |
76 // animation and record that the icon has been shown. | 75 // animation and record that the icon has been shown. |
77 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) | 76 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) |
78 return; | 77 return; |
79 | 78 |
80 // We just ignore this blockage if we're already showing some other string to | 79 // We just ignore this blockage if we're already showing some other string to |
81 // the user. If this becomes a problem, we could design some sort of queueing | 80 // the user. If this becomes a problem, we could design some sort of queueing |
82 // mechanism to show one after the other, but it doesn't seem important now. | 81 // mechanism to show one after the other, but it doesn't seem important now. |
83 int string_id = content_setting_image_model_->explanatory_string_id(); | 82 int string_id = content_setting_image_model_->explanatory_string_id(); |
83 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); | |
84 if (string_id && !label()->visible()) { | 84 if (string_id && !label()->visible()) { |
85 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); | |
86 SetLabel(l10n_util::GetStringUTF16(string_id)); | 85 SetLabel(l10n_util::GetStringUTF16(string_id)); |
87 label()->SetVisible(true); | 86 label()->SetVisible(true); |
88 slide_animator_.Show(); | 87 slide_animator_.Show(); |
89 } | 88 } |
90 | 89 |
91 content_setting_image_model_->SetAnimationHasRun(web_contents); | 90 content_setting_image_model_->SetAnimationHasRun(web_contents); |
92 } | 91 } |
93 | 92 |
94 const char* ContentSettingImageView::GetClassName() const { | 93 const char* ContentSettingImageView::GetClassName() const { |
95 return "ContentSettingsImageView"; | 94 return "ContentSettingsImageView"; |
96 } | 95 } |
97 | 96 |
98 void ContentSettingImageView::OnBoundsChanged( | 97 void ContentSettingImageView::OnBoundsChanged( |
99 const gfx::Rect& previous_bounds) { | 98 const gfx::Rect& previous_bounds) { |
100 if (bubble_view_) | 99 if (bubble_view_) |
101 bubble_view_->OnAnchorBoundsChanged(); | 100 bubble_view_->OnAnchorBoundsChanged(); |
102 } | 101 IconLabelBubbleView::OnBoundsChanged(previous_bounds); |
103 | |
104 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | |
105 // If the bubble is showing then don't reshow it when the mouse is released. | |
106 suppress_mouse_released_action_ = bubble_view_ != nullptr; | |
107 if (!suppress_mouse_released_action_ && !label()->visible()) | |
108 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event); | |
109 | |
110 // We want to show the bubble on mouse release; that is the standard behavior | |
111 // for buttons. | |
112 return true; | |
113 } | |
114 | |
115 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { | |
116 // If this is the second click on this view then the bubble was showing on the | |
117 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by | |
118 // doing nothing here. | |
119 if (suppress_mouse_released_action_) { | |
120 suppress_mouse_released_action_ = false; | |
121 return; | |
122 } | |
123 const bool activated = HitTestPoint(event.location()); | |
124 if (!label()->visible() && !activated) | |
125 AnimateInkDrop(views::InkDropState::HIDDEN, &event); | |
126 if (activated) | |
127 OnActivate(event); | |
128 } | |
129 | |
130 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { | |
131 if (event->type() == ui::ET_GESTURE_TAP) | |
132 OnActivate(*event); | |
133 if ((event->type() == ui::ET_GESTURE_TAP) || | |
134 (event->type() == ui::ET_GESTURE_TAP_DOWN)) | |
135 event->SetHandled(); | |
136 } | 102 } |
137 | 103 |
138 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, | 104 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, |
139 base::string16* tooltip) const { | 105 base::string16* tooltip) const { |
140 *tooltip = content_setting_image_model_->get_tooltip(); | 106 *tooltip = content_setting_image_model_->get_tooltip(); |
141 return !tooltip->empty(); | 107 return !tooltip->empty(); |
142 } | 108 } |
143 | 109 |
144 void ContentSettingImageView::OnNativeThemeChanged( | 110 void ContentSettingImageView::OnNativeThemeChanged( |
145 const ui::NativeTheme* native_theme) { | 111 const ui::NativeTheme* native_theme) { |
146 UpdateImage(); | 112 UpdateImage(); |
147 IconLabelBubbleView::OnNativeThemeChanged(native_theme); | 113 IconLabelBubbleView::OnNativeThemeChanged(native_theme); |
148 } | 114 } |
149 | 115 |
150 std::unique_ptr<views::InkDrop> ContentSettingImageView::CreateInkDrop() { | |
151 std::unique_ptr<views::InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); | |
152 ink_drop->SetShowHighlightOnFocus(true); | |
153 return std::move(ink_drop); | |
154 } | |
155 | |
156 SkColor ContentSettingImageView::GetTextColor() const { | 116 SkColor ContentSettingImageView::GetTextColor() const { |
157 return GetNativeTheme()->GetSystemColor( | 117 return GetNativeTheme()->GetSystemColor( |
158 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 118 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
159 } | 119 } |
160 | 120 |
161 bool ContentSettingImageView::ShouldShowLabel() const { | 121 bool ContentSettingImageView::ShouldShowLabel() const { |
162 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && | 122 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && |
163 (slide_animator_.is_animating() || pause_animation_); | 123 (slide_animator_.is_animating() || pause_animation_); |
164 } | 124 } |
165 | 125 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
226 AnimateInkDrop(views::InkDropState::ACTIVATED, | 186 AnimateInkDrop(views::InkDropState::ACTIVATED, |
227 ui::LocatedEvent::FromIfValid(&event)); | 187 ui::LocatedEvent::FromIfValid(&event)); |
228 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 188 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
229 } | 189 } |
230 bubble_widget->Show(); | 190 bubble_widget->Show(); |
231 } | 191 } |
232 | 192 |
233 return true; | 193 return true; |
234 } | 194 } |
235 | 195 |
196 bool ContentSettingImageView::IsBubbleShown() const { | |
197 return bubble_view_ != nullptr; | |
198 } | |
199 | |
200 // TODO(bruthig): See crbug.com/669253. The ink drop highlight is artifially | |
bruthig
2017/03/24 20:48:02
nit: sp 'artifially' -> 'artificially'
spqchan
2017/03/27 23:41:51
Done.
| |
201 // inflated to accomodate for that bug. This override needs to be removed once | |
bruthig
2017/03/24 20:48:02
nit: 'inflated' -> 'larger'
spqchan
2017/03/27 23:41:51
Done.
| |
202 // that's fixed. | |
203 std::unique_ptr<views::InkDropHighlight> | |
204 ContentSettingImageView::CreateInkDropHighlight() const { | |
205 gfx::Size ink_drop_size = | |
206 GetMaxSizeForLabelWidth(label()->GetPreferredSize().width()); | |
207 gfx::RectF ink_drop_bounds = | |
208 gfx::RectF(ink_drop_size.width(), ink_drop_size.height()); | |
209 return InkDropHostView::CreateDefaultInkDropHighlight( | |
210 ink_drop_bounds.CenterPoint(), ink_drop_size); | |
211 } | |
212 | |
236 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 213 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
237 slide_animator_.Reset(); | 214 slide_animator_.Reset(); |
238 if (!pause_animation_) { | 215 if (!pause_animation_) { |
239 label()->SetVisible(false); | 216 label()->SetVisible(false); |
240 parent_->Layout(); | 217 parent_->Layout(); |
241 parent_->SchedulePaint(); | 218 parent_->SchedulePaint(); |
242 } | 219 } |
243 } | 220 } |
244 | 221 |
245 void ContentSettingImageView::AnimationProgressed( | 222 void ContentSettingImageView::AnimationProgressed( |
(...skipping 18 matching lines...) Expand all Loading... | |
264 if (pause_animation_) { | 241 if (pause_animation_) { |
265 slide_animator_.Reset(pause_animation_state_); | 242 slide_animator_.Reset(pause_animation_state_); |
266 pause_animation_ = false; | 243 pause_animation_ = false; |
267 slide_animator_.Show(); | 244 slide_animator_.Show(); |
268 } | 245 } |
269 } | 246 } |
270 | 247 |
271 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 248 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
272 bool visible) { | 249 bool visible) { |
273 // |widget| is a bubble that has just got shown / hidden. | 250 // |widget| is a bubble that has just got shown / hidden. |
274 if (!visible && !label()->visible()) | 251 if (!visible) |
275 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 252 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
276 } | 253 } |
277 | 254 |
278 void ContentSettingImageView::UpdateImage() { | 255 void ContentSettingImageView::UpdateImage() { |
279 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 256 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
280 } | 257 } |
OLD | NEW |