| 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 "chrome/grit/theme_resources.h" | 13 #include "chrome/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" | |
| 16 #include "ui/base/theme_provider.h" | 15 #include "ui/base/theme_provider.h" |
| 17 #include "ui/events/event_utils.h" | 16 #include "ui/events/event_utils.h" |
| 18 #include "ui/gfx/color_palette.h" | 17 #include "ui/gfx/color_palette.h" |
| 19 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 20 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 21 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/widget/widget.h" | 21 #include "ui/views/widget/widget.h" |
| 23 | 22 |
| 24 namespace { | 23 namespace { |
| 25 // Time spent with animation fully open. | 24 // Time spent with animation fully open. |
| 26 const int kStayOpenTimeMS = 3200; | 25 const int kStayOpenTimeMS = 3200; |
| 27 } | 26 } |
| 28 | 27 |
| 29 | 28 |
| 30 // static | 29 // static |
| 31 const int ContentSettingImageView::kAnimationDurationMS = | 30 const int ContentSettingImageView::kAnimationDurationMS = |
| 32 (IconLabelBubbleView::kOpenTimeMS * 2) + kStayOpenTimeMS; | 31 (IconLabelBubbleView::kOpenTimeMS * 2) + kStayOpenTimeMS; |
| 33 | 32 |
| 34 ContentSettingImageView::ContentSettingImageView( | 33 ContentSettingImageView::ContentSettingImageView( |
| 35 ContentSettingImageModel* image_model, | 34 ContentSettingImageModel* image_model, |
| 36 LocationBarView* parent, | 35 LocationBarView* parent, |
| 37 const gfx::FontList& font_list, | 36 const gfx::FontList& font_list) |
| 38 SkColor parent_background_color) | 37 : IconLabelBubbleView(font_list, false), |
| 39 : IconLabelBubbleView(0, font_list, parent_background_color, false), | |
| 40 parent_(parent), | 38 parent_(parent), |
| 41 content_setting_image_model_(image_model), | 39 content_setting_image_model_(image_model), |
| 42 slide_animator_(this), | 40 slide_animator_(this), |
| 43 pause_animation_(false), | 41 pause_animation_(false), |
| 44 pause_animation_state_(0.0), | 42 pause_animation_state_(0.0), |
| 45 bubble_view_(nullptr), | 43 bubble_view_(nullptr), |
| 46 suppress_mouse_released_action_(false) { | 44 suppress_mouse_released_action_(false) { |
| 47 if (ui::MaterialDesignController::IsModeMaterial()) { | 45 SetInkDropMode(InkDropMode::ON); |
| 48 SetInkDropMode(InkDropMode::ON); | 46 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 49 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 50 } else { | |
| 51 static const int kBackgroundImages[] = | |
| 52 IMAGE_GRID(IDR_OMNIBOX_CONTENT_SETTING_BUBBLE); | |
| 53 SetBackgroundImageGrid(kBackgroundImages); | |
| 54 image()->set_interactive(true); | |
| 55 image()->SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | |
| 56 } | |
| 57 | |
| 58 image()->SetHorizontalAlignment(base::i18n::IsRTL() | 47 image()->SetHorizontalAlignment(base::i18n::IsRTL() |
| 59 ? views::ImageView::TRAILING | 48 ? views::ImageView::TRAILING |
| 60 : views::ImageView::LEADING); | 49 : views::ImageView::LEADING); |
| 61 image()->EnableCanvasFlippingForRTLUI(true); | 50 image()->EnableCanvasFlippingForRTLUI(true); |
| 62 label()->SetElideBehavior(gfx::NO_ELIDE); | 51 label()->SetElideBehavior(gfx::NO_ELIDE); |
| 63 label()->SetVisible(false); | 52 label()->SetVisible(false); |
| 64 | 53 |
| 65 slide_animator_.SetSlideDuration(kAnimationDurationMS); | 54 slide_animator_.SetSlideDuration(kAnimationDurationMS); |
| 66 slide_animator_.SetTweenType(gfx::Tween::LINEAR); | 55 slide_animator_.SetTweenType(gfx::Tween::LINEAR); |
| 67 } | 56 } |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 148 } | 137 } |
| 149 | 138 |
| 150 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, | 139 bool ContentSettingImageView::GetTooltipText(const gfx::Point& p, |
| 151 base::string16* tooltip) const { | 140 base::string16* tooltip) const { |
| 152 *tooltip = content_setting_image_model_->get_tooltip(); | 141 *tooltip = content_setting_image_model_->get_tooltip(); |
| 153 return !tooltip->empty(); | 142 return !tooltip->empty(); |
| 154 } | 143 } |
| 155 | 144 |
| 156 void ContentSettingImageView::OnNativeThemeChanged( | 145 void ContentSettingImageView::OnNativeThemeChanged( |
| 157 const ui::NativeTheme* native_theme) { | 146 const ui::NativeTheme* native_theme) { |
| 158 if (ui::MaterialDesignController::IsModeMaterial()) | 147 UpdateImage(); |
| 159 UpdateImage(); | |
| 160 | |
| 161 IconLabelBubbleView::OnNativeThemeChanged(native_theme); | 148 IconLabelBubbleView::OnNativeThemeChanged(native_theme); |
| 162 } | 149 } |
| 163 | 150 |
| 164 bool ContentSettingImageView::ShouldShowInkDropForFocus() const { | 151 bool ContentSettingImageView::ShouldShowInkDropForFocus() const { |
| 165 return true; | 152 return true; |
| 166 } | 153 } |
| 167 | 154 |
| 168 SkColor ContentSettingImageView::GetTextColor() const { | 155 SkColor ContentSettingImageView::GetTextColor() const { |
| 169 return GetNativeTheme()->GetSystemColor( | 156 return GetNativeTheme()->GetSystemColor( |
| 170 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 157 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 171 } | 158 } |
| 172 | 159 |
| 173 SkColor ContentSettingImageView::GetBorderColor() const { | 160 SkColor ContentSettingImageView::GetBorderColor() const { |
| 174 return gfx::kGoogleYellow700; | 161 return gfx::kGoogleYellow700; |
| 175 } | 162 } |
| 176 | 163 |
| 177 bool ContentSettingImageView::ShouldShowBackground() const { | 164 bool ContentSettingImageView::ShouldShowLabel() const { |
| 178 return (!IsShrinking() || | 165 return (!IsShrinking() || |
| 179 (width() >= MinimumWidthForImageWithBackgroundShown())) && | 166 (width() >= MinimumWidthForImageWithBackgroundShown())) && |
| 180 (slide_animator_.is_animating() || pause_animation_); | 167 (slide_animator_.is_animating() || pause_animation_); |
| 181 } | 168 } |
| 182 | 169 |
| 183 double ContentSettingImageView::WidthMultiplier() const { | 170 double ContentSettingImageView::WidthMultiplier() const { |
| 184 double state = pause_animation_ ? pause_animation_state_ | 171 double state = pause_animation_ ? pause_animation_state_ |
| 185 : slide_animator_.GetCurrentValue(); | 172 : slide_animator_.GetCurrentValue(); |
| 186 // The fraction of the animation we'll spend animating the string into view, | 173 // The fraction of the animation we'll spend animating the string into view, |
| 187 // which is also the fraction we'll spend animating it closed; total | 174 // which is also the fraction we'll spend animating it closed; total |
| (...skipping 19 matching lines...) Expand all Loading... |
| 207 if (slide_animator_.is_animating()) { | 194 if (slide_animator_.is_animating()) { |
| 208 // If the user clicks while we're animating, the bubble arrow will be | 195 // If the user clicks while we're animating, the bubble arrow will be |
| 209 // pointing to the image, and if we allow the animation to keep running, the | 196 // pointing to the image, and if we allow the animation to keep running, the |
| 210 // image will move away from the arrow (or we'll have to move the bubble, | 197 // image will move away from the arrow (or we'll have to move the bubble, |
| 211 // which is even worse). So we want to stop the animation. We have two | 198 // which is even worse). So we want to stop the animation. We have two |
| 212 // choices: jump to the final post-animation state (no label visible), or | 199 // choices: jump to the final post-animation state (no label visible), or |
| 213 // pause the animation where we are and continue running after the bubble | 200 // pause the animation where we are and continue running after the bubble |
| 214 // closes. The former looks more jerky, so we avoid it unless the animation | 201 // closes. The former looks more jerky, so we avoid it unless the animation |
| 215 // hasn't even fully exposed the image yet, in which case pausing with half | 202 // hasn't even fully exposed the image yet, in which case pausing with half |
| 216 // an image visible will look broken. | 203 // an image visible will look broken. |
| 217 if (!pause_animation_ && ShouldShowBackground() && | 204 if (!pause_animation_ && ShouldShowLabel() && |
| 218 (width() > MinimumWidthForImageWithBackgroundShown())) { | 205 (width() > MinimumWidthForImageWithBackgroundShown())) { |
| 219 pause_animation_ = true; | 206 pause_animation_ = true; |
| 220 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 207 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
| 221 } | 208 } |
| 222 slide_animator_.Reset(); | 209 slide_animator_.Reset(); |
| 223 } | 210 } |
| 224 | 211 |
| 225 content::WebContents* web_contents = parent_->GetWebContents(); | 212 content::WebContents* web_contents = parent_->GetWebContents(); |
| 226 if (web_contents && !bubble_view_) { | 213 if (web_contents && !bubble_view_) { |
| 227 bubble_view_ = new ContentSettingBubbleContents( | 214 bubble_view_ = new ContentSettingBubbleContents( |
| 228 content_setting_image_model_->CreateBubbleModel( | 215 content_setting_image_model_->CreateBubbleModel( |
| 229 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 216 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
| 230 web_contents, parent_->profile()), | 217 web_contents, parent_->profile()), |
| 231 web_contents, this, views::BubbleBorder::TOP_RIGHT); | 218 web_contents, this, views::BubbleBorder::TOP_RIGHT); |
| 232 views::Widget* bubble_widget = | 219 views::Widget* bubble_widget = |
| 233 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); | 220 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); |
| 234 bubble_widget->AddObserver(this); | 221 bubble_widget->AddObserver(this); |
| 235 // This is triggered by an input event. If the user clicks the icon while | 222 // This is triggered by an input event. If the user clicks the icon while |
| 236 // it's not animating, the icon will be placed in an active state, so the | 223 // it's not animating, the icon will be placed in an active state, so the |
| 237 // bubble doesn't need an arrow. If the user clicks during an animation, | 224 // bubble doesn't need an arrow. If the user clicks during an animation, |
| 238 // the animation simply pauses and no other visible state change occurs, so | 225 // the animation simply pauses and no other visible state change occurs, so |
| 239 // show the arrow in this case. | 226 // show the arrow in this case. |
| 240 if (ui::MaterialDesignController::IsModeMaterial() && !pause_animation_) { | 227 if (!pause_animation_) { |
| 241 AnimateInkDrop(views::InkDropState::ACTIVATED, | 228 AnimateInkDrop(views::InkDropState::ACTIVATED, |
| 242 ui::LocatedEvent::FromIfValid(&event)); | 229 ui::LocatedEvent::FromIfValid(&event)); |
| 243 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); | 230 bubble_view_->SetArrowPaintType(views::BubbleBorder::PAINT_TRANSPARENT); |
| 244 } | 231 } |
| 245 bubble_widget->Show(); | 232 bubble_widget->Show(); |
| 246 } | 233 } |
| 247 | 234 |
| 248 return true; | 235 return true; |
| 249 } | 236 } |
| 250 | 237 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 273 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 287 bool visible) { | 274 bool visible) { |
| 288 // |widget| is a bubble that has just got shown / hidden. | 275 // |widget| is a bubble that has just got shown / hidden. |
| 289 if (!visible && !label()->visible()) | 276 if (!visible && !label()->visible()) |
| 290 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 277 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 291 } | 278 } |
| 292 | 279 |
| 293 void ContentSettingImageView::UpdateImage() { | 280 void ContentSettingImageView::UpdateImage() { |
| 294 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 281 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 295 } | 282 } |
| OLD | NEW |