| 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 |
| 97 bool ContentSettingImageView::CanClick() const { |
| 98 return true; |
| 99 } |
| 100 |
| 98 void ContentSettingImageView::OnBoundsChanged( | 101 void ContentSettingImageView::OnBoundsChanged( |
| 99 const gfx::Rect& previous_bounds) { | 102 const gfx::Rect& previous_bounds) { |
| 100 if (bubble_view_) | 103 if (bubble_view_) |
| 101 bubble_view_->OnAnchorBoundsChanged(); | 104 bubble_view_->OnAnchorBoundsChanged(); |
| 102 } | 105 } |
| 103 | 106 |
| 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) { | 107 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { |
| 131 if (event->type() == ui::ET_GESTURE_TAP) | 108 if (event->type() == ui::ET_GESTURE_TAP) |
| 132 OnActivate(*event); | 109 OnActivate(*event); |
| 133 if ((event->type() == ui::ET_GESTURE_TAP) || | 110 if ((event->type() == ui::ET_GESTURE_TAP) || |
| 134 (event->type() == ui::ET_GESTURE_TAP_DOWN)) | 111 (event->type() == ui::ET_GESTURE_TAP_DOWN)) |
| 135 event->SetHandled(); | 112 event->SetHandled(); |
| 136 } | 113 } |
| 137 | 114 |
| 138 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, | 115 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, |
| 139 base::string16* tooltip) const { | 116 base::string16* tooltip) const { |
| 140 *tooltip = content_setting_image_model_->get_tooltip(); | 117 *tooltip = content_setting_image_model_->get_tooltip(); |
| 141 return !tooltip->empty(); | 118 return !tooltip->empty(); |
| 142 } | 119 } |
| 143 | 120 |
| 144 void ContentSettingImageView::OnNativeThemeChanged( | 121 void ContentSettingImageView::OnNativeThemeChanged( |
| 145 const ui::NativeTheme* native_theme) { | 122 const ui::NativeTheme* native_theme) { |
| 146 UpdateImage(); | 123 UpdateImage(); |
| 147 IconLabelBubbleView::OnNativeThemeChanged(native_theme); | 124 IconLabelBubbleView::OnNativeThemeChanged(native_theme); |
| 148 } | 125 } |
| 149 | 126 |
| 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 { | 127 SkColor ContentSettingImageView::GetTextColor() const { |
| 157 return GetNativeTheme()->GetSystemColor( | 128 return GetNativeTheme()->GetSystemColor( |
| 158 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 129 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 159 } | 130 } |
| 160 | 131 |
| 161 bool ContentSettingImageView::ShouldShowLabel() const { | 132 bool ContentSettingImageView::ShouldShowLabel() const { |
| 162 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && | 133 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && |
| 163 (slide_animator_.is_animating() || pause_animation_); | 134 (slide_animator_.is_animating() || pause_animation_); |
| 164 } | 135 } |
| 165 | 136 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 AnimateInkDrop(views::InkDropState::ACTIVATED, | 197 AnimateInkDrop(views::InkDropState::ACTIVATED, |
| 227 ui::LocatedEvent::FromIfValid(&event)); | 198 ui::LocatedEvent::FromIfValid(&event)); |
| 228 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 199 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
| 229 } | 200 } |
| 230 bubble_widget->Show(); | 201 bubble_widget->Show(); |
| 231 } | 202 } |
| 232 | 203 |
| 233 return true; | 204 return true; |
| 234 } | 205 } |
| 235 | 206 |
| 207 bool ContentSettingImageView::IsBubbleShown() const { |
| 208 return bubble_view_ != nullptr; |
| 209 } |
| 210 |
| 236 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 211 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
| 237 slide_animator_.Reset(); | 212 slide_animator_.Reset(); |
| 238 if (!pause_animation_) { | 213 if (!pause_animation_) { |
| 239 label()->SetVisible(false); | 214 label()->SetVisible(false); |
| 240 parent_->Layout(); | 215 parent_->Layout(); |
| 241 parent_->SchedulePaint(); | 216 parent_->SchedulePaint(); |
| 242 } | 217 } |
| 243 } | 218 } |
| 244 | 219 |
| 245 void ContentSettingImageView::AnimationProgressed( | 220 void ContentSettingImageView::AnimationProgressed( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 264 if (pause_animation_) { | 239 if (pause_animation_) { |
| 265 slide_animator_.Reset(pause_animation_state_); | 240 slide_animator_.Reset(pause_animation_state_); |
| 266 pause_animation_ = false; | 241 pause_animation_ = false; |
| 267 slide_animator_.Show(); | 242 slide_animator_.Show(); |
| 268 } | 243 } |
| 269 } | 244 } |
| 270 | 245 |
| 271 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 246 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 272 bool visible) { | 247 bool visible) { |
| 273 // |widget| is a bubble that has just got shown / hidden. | 248 // |widget| is a bubble that has just got shown / hidden. |
| 274 if (!visible && !label()->visible()) | 249 if (!visible) |
| 275 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 250 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 276 } | 251 } |
| 277 | 252 |
| 278 void ContentSettingImageView::UpdateImage() { | 253 void ContentSettingImageView::UpdateImage() { |
| 279 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 254 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 280 } | 255 } |
| OLD | NEW |