| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/infobars/core/infobar.h" | 5 #include "components/infobars/core/infobar.h" |
| 6 | 6 |
| 7 #include <cmath> | 7 #include <cmath> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| 11 #include "components/infobars/core/infobar_container.h" | 11 #include "components/infobars/core/infobar_container.h" |
| 12 #include "components/infobars/core/infobar_manager.h" | 12 #include "components/infobars/core/infobar_manager.h" |
| 13 #include "ui/base/resource/material_design/material_design_controller.h" |
| 13 #include "ui/gfx/animation/slide_animation.h" | 14 #include "ui/gfx/animation/slide_animation.h" |
| 14 | 15 |
| 15 namespace infobars { | 16 namespace infobars { |
| 16 | 17 |
| 17 InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate) | 18 InfoBar::InfoBar(scoped_ptr<InfoBarDelegate> delegate) |
| 18 : owner_(NULL), | 19 : owner_(NULL), |
| 19 delegate_(delegate.Pass()), | 20 delegate_(delegate.Pass()), |
| 20 container_(NULL), | 21 container_(NULL), |
| 21 animation_(this), | 22 animation_(this), |
| 22 arrow_height_(0), | 23 arrow_height_(0), |
| 23 arrow_target_height_(0), | 24 arrow_target_height_(0), |
| 24 arrow_half_width_(0), | 25 arrow_half_width_(0), |
| 25 bar_height_(0), | 26 bar_height_(0), |
| 26 bar_target_height_(-1) { | 27 bar_target_height_(-1) { |
| 27 DCHECK(delegate_ != NULL); | 28 DCHECK(delegate_ != NULL); |
| 28 animation_.SetTweenType(gfx::Tween::LINEAR); | 29 animation_.SetTweenType(gfx::Tween::LINEAR); |
| 29 delegate_->set_infobar(this); | 30 delegate_->set_infobar(this); |
| 30 } | 31 } |
| 31 | 32 |
| 32 InfoBar::~InfoBar() { | 33 InfoBar::~InfoBar() { |
| 33 DCHECK(!owner_); | 34 DCHECK(!owner_); |
| 34 } | 35 } |
| 35 | 36 |
| 36 // static | 37 // static |
| 37 SkColor InfoBar::GetTopColor(InfoBarDelegate::Type infobar_type) { | 38 SkColor InfoBar::GetTopColor(InfoBarDelegate::Type infobar_type) { |
| 39 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 40 static const SkColor kWarningBackgroundColorMd = |
| 41 SkColorSetRGB(0xFF, 0xEC, 0xB3); // Yellow |
| 42 static const SkColor kPageActionBackgroundColorMd = SK_ColorWHITE; |
| 43 |
| 44 return infobar_type == InfoBarDelegate::WARNING_TYPE ? |
| 45 kWarningBackgroundColorMd : kPageActionBackgroundColorMd; |
| 46 } |
| 47 |
| 38 static const SkColor kWarningBackgroundColorTop = | 48 static const SkColor kWarningBackgroundColorTop = |
| 39 SkColorSetRGB(255, 242, 183); // Yellow | 49 SkColorSetRGB(255, 242, 183); // Yellow |
| 40 static const SkColor kPageActionBackgroundColorTop = | 50 static const SkColor kPageActionBackgroundColorTop = |
| 41 SkColorSetRGB(237, 237, 237); // Gray | 51 SkColorSetRGB(237, 237, 237); // Gray |
| 42 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? | 52 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? |
| 43 kWarningBackgroundColorTop : kPageActionBackgroundColorTop; | 53 kWarningBackgroundColorTop : kPageActionBackgroundColorTop; |
| 44 } | 54 } |
| 45 | 55 |
| 46 // static | 56 // static |
| 47 SkColor InfoBar::GetBottomColor(InfoBarDelegate::Type infobar_type) { | 57 SkColor InfoBar::GetBottomColor(InfoBarDelegate::Type infobar_type) { |
| 58 // No gradient in MD. |
| 59 if (ui::MaterialDesignController::IsModeMaterial()) |
| 60 return GetTopColor(infobar_type); |
| 61 |
| 48 static const SkColor kWarningBackgroundColorBottom = | 62 static const SkColor kWarningBackgroundColorBottom = |
| 49 SkColorSetRGB(250, 230, 145); // Yellow | 63 SkColorSetRGB(250, 230, 145); // Yellow |
| 50 static const SkColor kPageActionBackgroundColorBottom = | 64 static const SkColor kPageActionBackgroundColorBottom = |
| 51 SkColorSetRGB(217, 217, 217); // Gray | 65 SkColorSetRGB(217, 217, 217); // Gray |
| 52 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? | 66 return (infobar_type == InfoBarDelegate::WARNING_TYPE) ? |
| 53 kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; | 67 kWarningBackgroundColorBottom : kPageActionBackgroundColorBottom; |
| 54 } | 68 } |
| 55 | 69 |
| 56 void InfoBar::SetOwner(InfoBarManager* owner) { | 70 void InfoBar::SetOwner(InfoBarManager* owner) { |
| 57 DCHECK(!owner_); | 71 DCHECK(!owner_); |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 | 167 |
| 154 void InfoBar::MaybeDelete() { | 168 void InfoBar::MaybeDelete() { |
| 155 if (!owner_ && (animation_.GetCurrentValue() == 0.0)) { | 169 if (!owner_ && (animation_.GetCurrentValue() == 0.0)) { |
| 156 if (container_) | 170 if (container_) |
| 157 container_->RemoveInfoBar(this); | 171 container_->RemoveInfoBar(this); |
| 158 delete this; | 172 delete this; |
| 159 } | 173 } |
| 160 } | 174 } |
| 161 | 175 |
| 162 } // namespace infobars | 176 } // namespace infobars |
| OLD | NEW |