| 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/infobars/infobar_view.h" | 5 #include "chrome/browser/ui/views/infobars/infobar_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/ptr_util.h" |
| 11 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
| 12 #include "chrome/browser/ui/infobar_container_delegate.h" | 13 #include "chrome/browser/ui/infobar_container_delegate.h" |
| 13 #include "chrome/browser/ui/views/bar_control_button.h" | 14 #include "chrome/browser/ui/views/bar_control_button.h" |
| 14 #include "chrome/browser/ui/views/infobars/infobar_background.h" | 15 #include "chrome/browser/ui/views/infobars/infobar_background.h" |
| 15 #include "chrome/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 16 #include "components/infobars/core/infobar_delegate.h" | 17 #include "components/infobars/core/infobar_delegate.h" |
| 17 #include "grit/components_strings.h" | 18 #include "grit/components_strings.h" |
| 18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
| 19 #include "third_party/skia/include/effects/SkGradientShader.h" | 20 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 20 #include "ui/accessibility/ax_view_state.h" | 21 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 | 70 |
| 70 } // namespace | 71 } // namespace |
| 71 | 72 |
| 72 | 73 |
| 73 // InfoBarView ---------------------------------------------------------------- | 74 // InfoBarView ---------------------------------------------------------------- |
| 74 | 75 |
| 75 // static | 76 // static |
| 76 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; | 77 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; |
| 77 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; | 78 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; |
| 78 | 79 |
| 79 InfoBarView::InfoBarView(scoped_ptr<infobars::InfoBarDelegate> delegate) | 80 InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate) |
| 80 : infobars::InfoBar(std::move(delegate)), | 81 : infobars::InfoBar(std::move(delegate)), |
| 81 views::ExternalFocusTracker(this, nullptr), | 82 views::ExternalFocusTracker(this, nullptr), |
| 82 child_container_(new views::View()), | 83 child_container_(new views::View()), |
| 83 icon_(nullptr), | 84 icon_(nullptr), |
| 84 close_button_(nullptr) { | 85 close_button_(nullptr) { |
| 85 set_owned_by_client(); // InfoBar deletes itself at the appropriate time. | 86 set_owned_by_client(); // InfoBar deletes itself at the appropriate time. |
| 86 set_background( | 87 set_background( |
| 87 new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType())); | 88 new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType())); |
| 88 SetEventTargeter(make_scoped_ptr(new views::ViewTargeter(this))); | 89 SetEventTargeter(base::WrapUnique(new views::ViewTargeter(this))); |
| 89 | 90 |
| 90 AddChildView(child_container_); | 91 AddChildView(child_container_); |
| 91 | 92 |
| 92 SetPaintToLayer(true); | 93 SetPaintToLayer(true); |
| 93 layer()->SetFillsBoundsOpaquely(false); | 94 layer()->SetFillsBoundsOpaquely(false); |
| 94 | 95 |
| 95 if (ui::MaterialDesignController::IsModeMaterial()) { | 96 if (ui::MaterialDesignController::IsModeMaterial()) { |
| 96 child_container_->SetPaintToLayer(true); | 97 child_container_->SetPaintToLayer(true); |
| 97 child_container_->layer()->SetMasksToBounds(true); | 98 child_container_->layer()->SetMasksToBounds(true); |
| 98 // Since MD doesn't use a gradient, we can set a solid bg color. | 99 // Since MD doesn't use a gradient, we can set a solid bg color. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 link->SetBackgroundColor(background()->get_color()); | 135 link->SetBackgroundColor(background()->get_color()); |
| 135 return link; | 136 return link; |
| 136 } | 137 } |
| 137 | 138 |
| 138 // static | 139 // static |
| 139 views::LabelButton* InfoBarView::CreateTextButton( | 140 views::LabelButton* InfoBarView::CreateTextButton( |
| 140 views::ButtonListener* listener, | 141 views::ButtonListener* listener, |
| 141 const base::string16& text) { | 142 const base::string16& text) { |
| 142 DCHECK(!ui::MaterialDesignController::IsModeMaterial()); | 143 DCHECK(!ui::MaterialDesignController::IsModeMaterial()); |
| 143 views::LabelButton* button = new views::LabelButton(listener, text); | 144 views::LabelButton* button = new views::LabelButton(listener, text); |
| 144 scoped_ptr<views::LabelButtonAssetBorder> button_border( | 145 std::unique_ptr<views::LabelButtonAssetBorder> button_border( |
| 145 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); | 146 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); |
| 146 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | 147 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); |
| 147 button_border->SetPainter( | 148 button_border->SetPainter( |
| 148 false, views::Button::STATE_NORMAL, | 149 false, views::Button::STATE_NORMAL, |
| 149 views::Painter::CreateImageGridPainter(kNormalImageSet)); | 150 views::Painter::CreateImageGridPainter(kNormalImageSet)); |
| 150 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | 151 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); |
| 151 button_border->SetPainter( | 152 button_border->SetPainter( |
| 152 false, views::Button::STATE_HOVERED, | 153 false, views::Button::STATE_HOVERED, |
| 153 views::Painter::CreateImageGridPainter(kHoveredImageSet)); | 154 views::Painter::CreateImageGridPainter(kHoveredImageSet)); |
| 154 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | 155 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 } | 436 } |
| 436 | 437 |
| 437 bool InfoBarView::DoesIntersectRect(const View* target, | 438 bool InfoBarView::DoesIntersectRect(const View* target, |
| 438 const gfx::Rect& rect) const { | 439 const gfx::Rect& rect) const { |
| 439 DCHECK_EQ(this, target); | 440 DCHECK_EQ(this, target); |
| 440 // Only events that intersect the portion below the arrow are interesting. | 441 // Only events that intersect the portion below the arrow are interesting. |
| 441 gfx::Rect non_arrow_bounds = GetLocalBounds(); | 442 gfx::Rect non_arrow_bounds = GetLocalBounds(); |
| 442 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); | 443 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); |
| 443 return rect.Intersects(non_arrow_bounds); | 444 return rect.Intersects(non_arrow_bounds); |
| 444 } | 445 } |
| OLD | NEW |