Chromium Code Reviews| 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. Since the ink drop highlight currently | |
| 201 // cannot handle host resizes, the highlight needs to be disabled when the | |
| 202 // animation is running. | |
| 203 std::unique_ptr<views::InkDropHighlight> | |
| 204 ContentSettingImageView::CreateInkDropHighlight() const { | |
| 205 return slide_animator_.is_animating() | |
| 206 ? nullptr | |
|
bruthig
2017/04/21 15:05:09
CreateInkDropHighlight() overrides shouldn't retur
spqchan
2017/04/27 21:40:06
Done.
| |
| 207 : IconLabelBubbleView::CreateInkDropHighlight(); | |
| 208 } | |
| 209 | |
| 236 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { | 210 void ContentSettingImageView::AnimationEnded(const gfx::Animation* animation) { |
| 237 slide_animator_.Reset(); | 211 slide_animator_.Reset(); |
| 238 if (!pause_animation_) { | 212 if (!pause_animation_) { |
| 239 label()->SetVisible(false); | 213 label()->SetVisible(false); |
| 240 parent_->Layout(); | 214 parent_->Layout(); |
| 241 parent_->SchedulePaint(); | 215 parent_->SchedulePaint(); |
| 242 } | 216 } |
| 243 } | 217 } |
| 244 | 218 |
| 245 void ContentSettingImageView::AnimationProgressed( | 219 void ContentSettingImageView::AnimationProgressed( |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 264 if (pause_animation_) { | 238 if (pause_animation_) { |
| 265 slide_animator_.Reset(pause_animation_state_); | 239 slide_animator_.Reset(pause_animation_state_); |
| 266 pause_animation_ = false; | 240 pause_animation_ = false; |
| 267 slide_animator_.Show(); | 241 slide_animator_.Show(); |
| 268 } | 242 } |
| 269 } | 243 } |
| 270 | 244 |
| 271 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 245 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 272 bool visible) { | 246 bool visible) { |
| 273 // |widget| is a bubble that has just got shown / hidden. | 247 // |widget| is a bubble that has just got shown / hidden. |
| 274 if (!visible && !label()->visible()) | 248 if (!visible) |
| 275 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 249 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 276 } | 250 } |
| 277 | 251 |
| 278 void ContentSettingImageView::UpdateImage() { | 252 void ContentSettingImageView::UpdateImage() { |
| 279 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 253 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 280 } | 254 } |
| OLD | NEW |