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" |
11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
13 #include "grit/theme_resources.h" | 13 #include "grit/theme_resources.h" |
14 #include "ui/base/l10n/l10n_util.h" | 14 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/material_design/material_design_controller.h" | 15 #include "ui/base/material_design/material_design_controller.h" |
16 #include "ui/base/theme_provider.h" | 16 #include "ui/base/theme_provider.h" |
| 17 #include "ui/events/event_utils.h" |
17 #include "ui/gfx/color_palette.h" | 18 #include "ui/gfx/color_palette.h" |
18 #include "ui/gfx/color_utils.h" | 19 #include "ui/gfx/color_utils.h" |
19 #include "ui/views/controls/image_view.h" | 20 #include "ui/views/controls/image_view.h" |
20 #include "ui/views/controls/label.h" | 21 #include "ui/views/controls/label.h" |
21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
22 | 23 |
23 namespace { | 24 namespace { |
24 // Time spent with animation fully open. | 25 // Time spent with animation fully open. |
25 const int kStayOpenTimeMS = 3200; | 26 const int kStayOpenTimeMS = 3200; |
26 } | 27 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 // If the content usage or blockage should be indicated to the user, start the | 87 // If the content usage or blockage should be indicated to the user, start the |
87 // animation and record that the icon has been shown. | 88 // animation and record that the icon has been shown. |
88 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) | 89 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) |
89 return; | 90 return; |
90 | 91 |
91 // We just ignore this blockage if we're already showing some other string to | 92 // We just ignore this blockage if we're already showing some other string to |
92 // the user. If this becomes a problem, we could design some sort of queueing | 93 // the user. If this becomes a problem, we could design some sort of queueing |
93 // mechanism to show one after the other, but it doesn't seem important now. | 94 // mechanism to show one after the other, but it doesn't seem important now. |
94 int string_id = content_setting_image_model_->explanatory_string_id(); | 95 int string_id = content_setting_image_model_->explanatory_string_id(); |
95 if (string_id && !label()->visible()) { | 96 if (string_id && !label()->visible()) { |
96 AnimateInkDrop(views::InkDropState::HIDDEN); | 97 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); |
97 SetLabel(l10n_util::GetStringUTF16(string_id)); | 98 SetLabel(l10n_util::GetStringUTF16(string_id)); |
98 label()->SetVisible(true); | 99 label()->SetVisible(true); |
99 slide_animator_.Show(); | 100 slide_animator_.Show(); |
100 } | 101 } |
101 | 102 |
102 content_setting_image_model_->SetAnimationHasRun(web_contents); | 103 content_setting_image_model_->SetAnimationHasRun(web_contents); |
103 } | 104 } |
104 | 105 |
105 const char* ContentSettingImageView::GetClassName() const { | 106 const char* ContentSettingImageView::GetClassName() const { |
106 return "ContentSettingsImageView"; | 107 return "ContentSettingsImageView"; |
107 } | 108 } |
108 | 109 |
109 void ContentSettingImageView::OnBoundsChanged( | 110 void ContentSettingImageView::OnBoundsChanged( |
110 const gfx::Rect& previous_bounds) { | 111 const gfx::Rect& previous_bounds) { |
111 if (bubble_view_) | 112 if (bubble_view_) |
112 bubble_view_->OnAnchorBoundsChanged(); | 113 bubble_view_->OnAnchorBoundsChanged(); |
113 } | 114 } |
114 | 115 |
115 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | 116 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { |
116 // If the bubble is showing then don't reshow it when the mouse is released. | 117 // If the bubble is showing then don't reshow it when the mouse is released. |
117 suppress_mouse_released_action_ = bubble_view_ != nullptr; | 118 suppress_mouse_released_action_ = bubble_view_ != nullptr; |
118 if (!suppress_mouse_released_action_ && !label()->visible()) | 119 if (!suppress_mouse_released_action_ && !label()->visible()) |
119 AnimateInkDrop(views::InkDropState::ACTION_PENDING); | 120 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event); |
120 | 121 |
121 // We want to show the bubble on mouse release; that is the standard behavior | 122 // We want to show the bubble on mouse release; that is the standard behavior |
122 // for buttons. | 123 // for buttons. |
123 return true; | 124 return true; |
124 } | 125 } |
125 | 126 |
126 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { | 127 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { |
127 // If this is the second click on this view then the bubble was showing on the | 128 // If this is the second click on this view then the bubble was showing on the |
128 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by | 129 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by |
129 // doing nothing here. | 130 // doing nothing here. |
130 if (suppress_mouse_released_action_) { | 131 if (suppress_mouse_released_action_) { |
131 suppress_mouse_released_action_ = false; | 132 suppress_mouse_released_action_ = false; |
132 return; | 133 return; |
133 } | 134 } |
134 const bool activated = HitTestPoint(event.location()); | 135 const bool activated = HitTestPoint(event.location()); |
135 if (!label()->visible() && !activated) | 136 if (!label()->visible() && !activated) |
136 AnimateInkDrop(views::InkDropState::HIDDEN); | 137 AnimateInkDrop(views::InkDropState::HIDDEN, &event); |
137 if (activated) | 138 if (activated) |
138 OnActivate(); | 139 OnActivate(event); |
139 } | 140 } |
140 | 141 |
141 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { | 142 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { |
142 if (event->type() == ui::ET_GESTURE_TAP) | 143 if (event->type() == ui::ET_GESTURE_TAP) |
143 OnActivate(); | 144 OnActivate(*event); |
144 if ((event->type() == ui::ET_GESTURE_TAP) || | 145 if ((event->type() == ui::ET_GESTURE_TAP) || |
145 (event->type() == ui::ET_GESTURE_TAP_DOWN)) | 146 (event->type() == ui::ET_GESTURE_TAP_DOWN)) |
146 event->SetHandled(); | 147 event->SetHandled(); |
147 } | 148 } |
148 | 149 |
149 void ContentSettingImageView::OnNativeThemeChanged( | 150 void ContentSettingImageView::OnNativeThemeChanged( |
150 const ui::NativeTheme* native_theme) { | 151 const ui::NativeTheme* native_theme) { |
151 if (ui::MaterialDesignController::IsModeMaterial()) | 152 if (ui::MaterialDesignController::IsModeMaterial()) |
152 UpdateImage(); | 153 UpdateImage(); |
153 | 154 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 return size_fraction; | 186 return size_fraction; |
186 } | 187 } |
187 | 188 |
188 bool ContentSettingImageView::IsShrinking() const { | 189 bool ContentSettingImageView::IsShrinking() const { |
189 const double kOpenFraction = | 190 const double kOpenFraction = |
190 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; | 191 static_cast<double>(kOpenTimeMS) / kAnimationDurationMS; |
191 return (!pause_animation_ && slide_animator_.is_animating() && | 192 return (!pause_animation_ && slide_animator_.is_animating() && |
192 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); | 193 slide_animator_.GetCurrentValue() > (1.0 - kOpenFraction)); |
193 } | 194 } |
194 | 195 |
195 bool ContentSettingImageView::OnActivate() { | 196 bool ContentSettingImageView::OnActivate(const ui::Event& event) { |
196 if (slide_animator_.is_animating()) { | 197 if (slide_animator_.is_animating()) { |
197 // If the user clicks while we're animating, the bubble arrow will be | 198 // If the user clicks while we're animating, the bubble arrow will be |
198 // pointing to the image, and if we allow the animation to keep running, the | 199 // pointing to the image, and if we allow the animation to keep running, the |
199 // image will move away from the arrow (or we'll have to move the bubble, | 200 // image will move away from the arrow (or we'll have to move the bubble, |
200 // which is even worse). So we want to stop the animation. We have two | 201 // which is even worse). So we want to stop the animation. We have two |
201 // choices: jump to the final post-animation state (no label visible), or | 202 // choices: jump to the final post-animation state (no label visible), or |
202 // pause the animation where we are and continue running after the bubble | 203 // pause the animation where we are and continue running after the bubble |
203 // closes. The former looks more jerky, so we avoid it unless the animation | 204 // closes. The former looks more jerky, so we avoid it unless the animation |
204 // hasn't even fully exposed the image yet, in which case pausing with half | 205 // hasn't even fully exposed the image yet, in which case pausing with half |
205 // an image visible will look broken. | 206 // an image visible will look broken. |
(...skipping 14 matching lines...) Expand all Loading... |
220 web_contents, this, views::BubbleBorder::TOP_RIGHT); | 221 web_contents, this, views::BubbleBorder::TOP_RIGHT); |
221 views::Widget* bubble_widget = | 222 views::Widget* bubble_widget = |
222 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); | 223 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); |
223 bubble_widget->AddObserver(this); | 224 bubble_widget->AddObserver(this); |
224 // This is triggered by an input event. If the user clicks the icon while | 225 // This is triggered by an input event. If the user clicks the icon while |
225 // it's not animating, the icon will be placed in an active state, so the | 226 // it's not animating, the icon will be placed in an active state, so the |
226 // bubble doesn't need an arrow. If the user clicks during an animation, | 227 // bubble doesn't need an arrow. If the user clicks during an animation, |
227 // the animation simply pauses and no other visible state change occurs, so | 228 // the animation simply pauses and no other visible state change occurs, so |
228 // show the arrow in this case. | 229 // show the arrow in this case. |
229 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { | 230 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { |
230 AnimateInkDrop(views::InkDropState::ACTIVATED); | 231 AnimateInkDrop(views::InkDropState::ACTIVATED, |
| 232 ui::LocatedEvent::FromIfValid(&event)); |
231 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 233 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
232 } | 234 } |
233 bubble_widget->Show(); | 235 bubble_widget->Show(); |
234 } | 236 } |
235 | 237 |
236 return true; | 238 return true; |
237 } | 239 } |
238 | 240 |
239 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 241 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
240 slide_animator_.Reset(); | 242 slide_animator_.Reset(); |
(...skipping 27 matching lines...) Expand all Loading... |
268 slide_animator_.Reset(pause_animation_state_); | 270 slide_animator_.Reset(pause_animation_state_); |
269 pause_animation_ = false; | 271 pause_animation_ = false; |
270 slide_animator_.Show(); | 272 slide_animator_.Show(); |
271 } | 273 } |
272 } | 274 } |
273 | 275 |
274 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 276 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
275 bool visible) { | 277 bool visible) { |
276 // |widget| is a bubble that has just got shown / hidden. | 278 // |widget| is a bubble that has just got shown / hidden. |
277 if (!visible && !label()->visible()) | 279 if (!visible && !label()->visible()) |
278 AnimateInkDrop(views::InkDropState::DEACTIVATED); | 280 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
279 } | 281 } |
280 | 282 |
281 void ContentSettingImageView::UpdateImage() { | 283 void ContentSettingImageView::UpdateImage() { |
282 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 284 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
283 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); | 285 image()->SetTooltipText(content_setting_image_model_->get_tooltip()); |
284 } | 286 } |
OLD | NEW |