| 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/layout_constants.h" |
| 12 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" | 12 #include "chrome/browser/ui/views/content_setting_bubble_contents.h" |
| 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" | 13 #include "chrome/browser/ui/views/location_bar/location_bar_view.h" |
| 14 #include "chrome/grit/theme_resources.h" | 14 #include "chrome/grit/theme_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.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/controls/image_view.h" | 21 #include "ui/views/controls/image_view.h" |
| 21 #include "ui/views/controls/label.h" | 22 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 23 | 24 |
| 24 namespace { | 25 namespace { |
| 25 // Time spent with animation fully open. | 26 // Time spent with animation fully open. |
| 26 const int kStayOpenTimeMS = 3200; | 27 const int kStayOpenTimeMS = 3200; |
| 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 : IconLabelBubbleView(font_list, false), | 38 : IconLabelBubbleView(font_list, false), |
| 39 parent_(parent), | 39 parent_(parent), |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 // an image visible will look broken. | 202 // an image visible will look broken. |
| 203 if (!pause_animation_ && ShouldShowLabel()) { | 203 if (!pause_animation_ && ShouldShowLabel()) { |
| 204 pause_animation_ = true; | 204 pause_animation_ = true; |
| 205 pause_animation_state_ = slide_animator_.GetCurrentValue(); | 205 pause_animation_state_ = slide_animator_.GetCurrentValue(); |
| 206 } | 206 } |
| 207 slide_animator_.Reset(); | 207 slide_animator_.Reset(); |
| 208 } | 208 } |
| 209 | 209 |
| 210 content::WebContents* web_contents = parent_->GetWebContents(); | 210 content::WebContents* web_contents = parent_->GetWebContents(); |
| 211 if (web_contents && !bubble_view_) { | 211 if (web_contents && !bubble_view_) { |
| 212 views::View* anchor = this; |
| 213 if (ui::MaterialDesignController::IsSecondaryUiMaterial()) |
| 214 anchor = parent_; |
| 212 bubble_view_ = new ContentSettingBubbleContents( | 215 bubble_view_ = new ContentSettingBubbleContents( |
| 213 content_setting_image_model_->CreateBubbleModel( | 216 content_setting_image_model_->CreateBubbleModel( |
| 214 parent_->delegate()->GetContentSettingBubbleModelDelegate(), | 217 parent_->delegate()->GetContentSettingBubbleModelDelegate(), |
| 215 web_contents, parent_->profile()), | 218 web_contents, parent_->profile()), |
| 216 web_contents, this, views::BubbleBorder::TOP_RIGHT); | 219 web_contents, anchor, views::BubbleBorder::TOP_RIGHT); |
| 217 views::Widget* bubble_widget = | 220 views::Widget* bubble_widget = |
| 218 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); | 221 views::BubbleDialogDelegateView::CreateBubble(bubble_view_); |
| 219 bubble_widget->AddObserver(this); | 222 bubble_widget->AddObserver(this); |
| 220 // This is triggered by an input event. If the user clicks the icon while | 223 // This is triggered by an input event. If the user clicks the icon while |
| 221 // it's not animating, the icon will be placed in an active state, so the | 224 // it's not animating, the icon will be placed in an active state, so the |
| 222 // bubble doesn't need an arrow. If the user clicks during an animation, | 225 // bubble doesn't need an arrow. If the user clicks during an animation, |
| 223 // the animation simply pauses and no other visible state change occurs, so | 226 // the animation simply pauses and no other visible state change occurs, so |
| 224 // show the arrow in this case. | 227 // show the arrow in this case. |
| 225 if (!pause_animation_) { | 228 if (!pause_animation_) { |
| 226 AnimateInkDrop(views::InkDropState::ACTIVATED, | 229 AnimateInkDrop(views::InkDropState::ACTIVATED, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, | 274 void ContentSettingImageView::OnWidgetVisibilityChanged(views::Widget* widget, |
| 272 bool visible) { | 275 bool visible) { |
| 273 // |widget| is a bubble that has just got shown / hidden. | 276 // |widget| is a bubble that has just got shown / hidden. |
| 274 if (!visible && !label()->visible()) | 277 if (!visible && !label()->visible()) |
| 275 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); | 278 AnimateInkDrop(views::InkDropState::DEACTIVATED, nullptr /* event */); |
| 276 } | 279 } |
| 277 | 280 |
| 278 void ContentSettingImageView::UpdateImage() { | 281 void ContentSettingImageView::UpdateImage() { |
| 279 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); | 282 SetImage(content_setting_image_model_->GetIcon(GetTextColor()).AsImageSkia()); |
| 280 } | 283 } |
| OLD | NEW |