| 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/layout_constants.h" |
| 11 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 12 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 12 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 13 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 15 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
| 16 #include "ui/base/theme_provider.h" | 17 #include "ui/base/theme_provider.h" |
| 17 #include "ui/events/event_utils.h" | 18 #include "ui/events/event_utils.h" |
| 18 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
| 19 #include "ui/gfx/color_utils.h" | 20 #include "ui/gfx/color_utils.h" |
| 20 #include "ui/views/animation/ink_drop_impl.h" | 21 #include "ui/views/animation/ink_drop_impl.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 36 LocationBarView* parent, | 37 LocationBarView* parent, |
| 37 const gfx::FontList& font_list) | 38 const gfx::FontList& font_list) |
| 38 : IconLabelBubbleView(font_list, false), | 39 : IconLabelBubbleView(font_list, false), |
| 39 parent_(parent), | 40 parent_(parent), |
| 40 content_setting_image_model_(std::move(image_model)), | 41 content_setting_image_model_(std::move(image_model)), |
| 41 slide_animator_(this), | 42 slide_animator_(this), |
| 42 pause_animation_(false), | 43 pause_animation_(false), |
| 43 pause_animation_state_(0.0), | 44 pause_animation_state_(0.0), |
| 44 bubble_view_(nullptr), | 45 bubble_view_(nullptr), |
| 45 suppress_mouse_released_action_(false) { | 46 suppress_mouse_released_action_(false) { |
| 47 set_next_element_interior_padding(LocationBarView::kIconInteriorPadding); |
| 46 SetInkDropMode(InkDropMode::ON); | 48 SetInkDropMode(InkDropMode::ON); |
| 47 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); | 49 SetFocusBehavior(FocusBehavior::ACCESSIBLE_ONLY); |
| 48 image()->SetHorizontalAlignment(base::i18n::IsRTL() | |
| 49 ? views::ImageView::TRAILING | |
| 50 : views::ImageView::LEADING); | |
| 51 image()->EnableCanvasFlippingForRTLUI(true); | 50 image()->EnableCanvasFlippingForRTLUI(true); |
| 52 label()->SetElideBehavior(gfx::NO_ELIDE); | 51 label()->SetElideBehavior(gfx::NO_ELIDE); |
| 53 label()->SetVisible(false); | 52 label()->SetVisible(false); |
| 54 | 53 |
| 55 slide_animator_.SetSlideDuration(kAnimationDurationMS); | 54 slide_animator_.SetSlideDuration(kAnimationDurationMS); |
| 56 slide_animator_.SetTweenType(gfx::Tween::LINEAR); | 55 slide_animator_.SetTweenType(gfx::Tween::LINEAR); |
| 57 } | 56 } |
| 58 | 57 |
| 59 ContentSettingImageView::~ContentSettingImageView() { | 58 ContentSettingImageView::~ContentSettingImageView() { |
| 60 if (bubble_view_ && bubble_view_->GetWidget()) | 59 if (bubble_view_ && bubble_view_->GetWidget()) |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 } | 155 } |
| 157 | 156 |
| 158 SkColor ContentSettingImageView::GetTextColor() const { | 157 SkColor ContentSettingImageView::GetTextColor() const { |
| 159 return GetNativeTheme()->GetSystemColor( | 158 return GetNativeTheme()->GetSystemColor( |
| 160 ui::NativeTheme::kColorId_TextfieldDefaultColor); | 159 ui::NativeTheme::kColorId_TextfieldDefaultColor); |
| 161 } | 160 } |
| 162 | 161 |
| 163 bool ContentSettingImageView::ShouldShowLabel() const { | 162 bool ContentSettingImageView::ShouldShowLabel() const { |
| 164 return (!IsShrinking() || | 163 return (!IsShrinking() || |
| 165 (width() > (image()->GetPreferredSize().width() + | 164 (width() > (image()->GetPreferredSize().width() + |
| 166 2 * LocationBarView::kHorizontalPadding))) && | 165 2 * GetLayoutConstant(LOCATION_BAR_ELEMENT_PADDING)))) && |
| 167 (slide_animator_.is_animating() || pause_animation_); | 166 (slide_animator_.is_animating() || pause_animation_); |
| 168 } | 167 } |
| 169 | 168 |
| 170 double ContentSettingImageView::WidthMultiplier() const { | 169 double ContentSettingImageView::WidthMultiplier() const { |
| 171 double state = pause_animation_ ? pause_animation_state_ | 170 double state = pause_animation_ ? pause_animation_state_ |
| 172 : slide_animator_.GetCurrentValue(); | 171 : slide_animator_.GetCurrentValue(); |
| 173 // The fraction of the animation we'll spend animating the string into view, | 172 // The fraction of the animation we'll spend animating the string into view, |
| 174 // which is also the fraction we'll spend animating it closed; total | 173 // which is also the fraction we'll spend animating it closed; total |
| 175 // animation (slide out, show, then slide in) is 1.0. | 174 // animation (slide out, show, then slide in) is 1.0. |
| 176 const double kOpenFraction = | 175 const double kOpenFraction = |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 274 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 276 bool visible) { | 275 bool visible) { |
| 277 // |widget| is a bubble that has just got shown / hidden. | 276 // |widget| is a bubble that has just got shown / hidden. |
| 278 if (!visible && !label()->visible()) | 277 if (!visible && !label()->visible()) |
| 279 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 278 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 280 } | 279 } |
| 281 | 280 |
| 282 void ContentSettingImageView::UpdateImage() { | 281 void ContentSettingImageView::UpdateImage() { |
| 283 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 282 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 284 } | 283 } |
| OLD | NEW |