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