| 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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 | 74 |
| 75 // If the content usage or blockage should be indicated to the user, start the | 75 // If the content usage or blockage should be indicated to the user, start the |
| 76 // animation and record that the icon has been shown. | 76 // animation and record that the icon has been shown. |
| 77 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) | 77 if (!content_setting_image_model_->ShouldRunAnimation(web_contents)) |
| 78 return; | 78 return; |
| 79 | 79 |
| 80 // We just ignore this blockage if we're already showing some other string to | 80 // 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 | 81 // 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. | 82 // 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(); | 83 int string_id = content_setting_image_model_->explanatory_string_id(); |
| 84 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); |
| 84 if (string_id && !label()->visible()) { | 85 if (string_id && !label()->visible()) { |
| 85 AnimateInkDrop(views::InkDropState::HIDDEN, nullptr /* event */); | |
| 86 SetLabel(l10n_util::GetStringUTF16(string_id)); | 86 SetLabel(l10n_util::GetStringUTF16(string_id)); |
| 87 label()->SetVisible(true); | 87 label()->SetVisible(true); |
| 88 slide_animator_.Show(); | 88 slide_animator_.Show(); |
| 89 } | 89 } |
| 90 | 90 |
| 91 content_setting_image_model_->SetAnimationHasRun(web_contents); | 91 content_setting_image_model_->SetAnimationHasRun(web_contents); |
| 92 } | 92 } |
| 93 | 93 |
| 94 const char* ContentSettingImageView::GetClassName() const { | 94 const char* ContentSettingImageView::GetClassName() const { |
| 95 return "ContentSettingsImageView"; | 95 return "ContentSettingsImageView"; |
| 96 } | 96 } |
| 97 | 97 |
| 98 bool ContentSettingImageView::IsInkDropEnabled() const { |
| 99 return true; |
| 100 } |
| 101 |
| 98 void ContentSettingImageView::OnBoundsChanged( | 102 void ContentSettingImageView::OnBoundsChanged( |
| 99 const gfx::Rect& previous_bounds) { | 103 const gfx::Rect& previous_bounds) { |
| 100 if (bubble_view_) | 104 if (bubble_view_) |
| 101 bubble_view_->OnAnchorBoundsChanged(); | 105 bubble_view_->OnAnchorBoundsChanged(); |
| 102 } | 106 } |
| 103 | 107 |
| 104 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { | 108 bool ContentSettingImageView::OnMousePressed(const ui::MouseEvent& event) { |
| 105 // If the bubble is showing then don't reshow it when the mouse is released. | 109 // If the bubble is showing then don't reshow it when the mouse is released. |
| 106 suppress_mouse_released_action_ = bubble_view_ != nullptr; | 110 suppress_mouse_released_action_ = bubble_view_ != nullptr; |
| 107 if (!suppress_mouse_released_action_ && !label()->visible()) | 111 if (!suppress_mouse_released_action_) |
| 108 AnimateInkDrop(views::InkDropState::ACTION_PENDING, &event); | 112 IconLabelBubbleView::OnMousePressed(event); |
| 109 | 113 |
| 110 // We want to show the bubble on mouse release; that is the standard behavior | 114 // We want to show the bubble on mouse release; that is the standard behavior |
| 111 // for buttons. | 115 // for buttons. |
| 112 return true; | 116 return true; |
| 113 } | 117 } |
| 114 | 118 |
| 115 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { | 119 void ContentSettingImageView::OnMouseReleased(const ui::MouseEvent& event) { |
| 116 // If this is the second click on this view then the bubble was showing on the | 120 // 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 | 121 // mouse pressed event and is hidden now. Prevent the bubble from reshowing by |
| 118 // doing nothing here. | 122 // doing nothing here. |
| 119 if (suppress_mouse_released_action_) { | 123 if (suppress_mouse_released_action_) { |
| 120 suppress_mouse_released_action_ = false; | 124 suppress_mouse_released_action_ = false; |
| 121 return; | 125 return; |
| 122 } | 126 } |
| 123 const bool activated = HitTestPoint(event.location()); | 127 const bool activated = HitTestPoint(event.location()); |
| 124 if (!label()->visible() && !activated) | 128 if (!activated) |
| 125 AnimateInkDrop(views::InkDropState::HIDDEN, &event); | 129 AnimateInkDrop(views::InkDropState::HIDDEN, &event); |
| 126 if (activated) | 130 if (activated) |
| 127 OnActivate(event); | 131 OnActivate(event); |
| 128 } | 132 } |
| 129 | 133 |
| 130 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { | 134 void ContentSettingImageView::OnGestureEvent(ui::GestureEvent* event) { |
| 131 if (event->type() == ui::ET_GESTURE_TAP) | 135 if (event->type() == ui::ET_GESTURE_TAP) |
| 132 OnActivate(*event); | 136 OnActivate(*event); |
| 133 if ((event->type() == ui::ET_GESTURE_TAP) || | 137 if ((event->type() == ui::ET_GESTURE_TAP) || |
| 134 (event->type() == ui::ET_GESTURE_TAP_DOWN)) | 138 (event->type() == ui::ET_GESTURE_TAP_DOWN)) |
| 135 event->SetHandled(); | 139 event->SetHandled(); |
| 136 } | 140 } |
| 137 | 141 |
| 138 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, | 142 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, |
| 139 base::string16* tooltip) const { | 143 base::string16* tooltip) const { |
| 140 *tooltip = content_setting_image_model_->get_tooltip(); | 144 *tooltip = content_setting_image_model_->get_tooltip(); |
| 141 return !tooltip->empty(); | 145 return !tooltip->empty(); |
| 142 } | 146 } |
| 143 | 147 |
| 144 void ContentSettingImageView::OnNativeThemeChanged( | 148 void ContentSettingImageView::OnNativeThemeChanged( |
| 145 const ui::NativeTheme* native_theme) { | 149 const ui::NativeTheme* native_theme) { |
| 146 UpdateImage(); | 150 UpdateImage(); |
| 147 IconLabelBubbleView::OnNativeThemeChanged(native_theme); | 151 IconLabelBubbleView::OnNativeThemeChanged(native_theme); |
| 148 } | 152 } |
| 149 | 153 |
| 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 { | 154 SkColor ContentSettingImageView::GetTextColor() const { |
| 157 return GetNativeTheme()->GetSystemColor( | 155 return GetNativeTheme()->GetSystemColor( |
| 158 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 156 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 159 } | 157 } |
| 160 | 158 |
| 161 bool ContentSettingImageView::ShouldShowLabel() const { | 159 bool ContentSettingImageView::ShouldShowLabel() const { |
| 162 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && | 160 return (!IsShrinking() || (width() > image()->GetPreferredSize().width())) && |
| 163 (slide_animator_.is_animating() || pause_animation_); | 161 (slide_animator_.is_animating() || pause_animation_); |
| 164 } | 162 } |
| 165 | 163 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 264 if (pause_animation_) { | 262 if (pause_animation_) { |
| 265 slide_animator_.Reset(pause_animation_state_); | 263 slide_animator_.Reset(pause_animation_state_); |
| 266 pause_animation_ = false; | 264 pause_animation_ = false; |
| 267 slide_animator_.Show(); | 265 slide_animator_.Show(); |
| 268 } | 266 } |
| 269 } | 267 } |
| 270 | 268 |
| 271 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 269 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 272 bool visible) { | 270 bool visible) { |
| 273 // |widget| is a bubble that has just got shown / hidden. | 271 // |widget| is a bubble that has just got shown / hidden. |
| 274 if (!visible && !label()->visible()) | 272 if (!visible) |
| 275 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 273 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 276 } | 274 } |
| 277 | 275 |
| 278 void ContentSettingImageView::UpdateImage() { | 276 void ContentSettingImageView::UpdateImage() { |
| 279 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 277 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 280 } | 278 } |
| OLD | NEW |