| 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 <memory> |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 label_2->GetPreferredSize().width(); | 57 label_2->GetPreferredSize().width(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 const gfx::FontList& GetFontList() { | 60 const gfx::FontList& GetFontList() { |
| 61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 61 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 62 return rb.GetFontList(ui::MaterialDesignController::IsModeMaterial() | 62 return rb.GetFontList(ui::MaterialDesignController::IsModeMaterial() |
| 63 ? ui::ResourceBundle::BaseFont | 63 ? ui::ResourceBundle::BaseFont |
| 64 : ui::ResourceBundle::MediumFont); | 64 : ui::ResourceBundle::MediumFont); |
| 65 } | 65 } |
| 66 | 66 |
| 67 SkColor GetInfobarTextColor() { | 67 constexpr SkColor GetInfobarTextColor() { |
| 68 return SK_ColorBLACK; | 68 return SK_ColorBLACK; |
| 69 } | 69 } |
| 70 | 70 |
| 71 } // namespace | 71 } // namespace |
| 72 | 72 |
| 73 | 73 |
| 74 // InfoBarView ---------------------------------------------------------------- | 74 // InfoBarView ---------------------------------------------------------------- |
| 75 | 75 |
| 76 // static | 76 // static |
| 77 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; | 77 const int InfoBarView::kButtonButtonSpacing = views::kRelatedButtonHSpacing; |
| 78 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; | 78 const int InfoBarView::kEndOfLabelSpacing = views::kItemLabelSpacing; |
| 79 const SkColor InfoBarView::kTextColor = GetInfobarTextColor(); |
| 79 | 80 |
| 80 InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate) | 81 InfoBarView::InfoBarView(std::unique_ptr<infobars::InfoBarDelegate> delegate) |
| 81 : infobars::InfoBar(std::move(delegate)), | 82 : infobars::InfoBar(std::move(delegate)), |
| 82 views::ExternalFocusTracker(this, nullptr), | 83 views::ExternalFocusTracker(this, nullptr), |
| 83 child_container_(new views::View()), | 84 child_container_(new views::View()), |
| 84 icon_(nullptr), | 85 icon_(nullptr), |
| 85 close_button_(nullptr) { | 86 close_button_(nullptr) { |
| 86 set_owned_by_client(); // InfoBar deletes itself at the appropriate time. | 87 set_owned_by_client(); // InfoBar deletes itself at the appropriate time. |
| 87 set_background( | 88 set_background( |
| 88 new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType())); | 89 new InfoBarBackground(infobars::InfoBar::delegate()->GetInfoBarType())); |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 160 button->set_animate_on_state_change(false); | 161 button->set_animate_on_state_change(false); |
| 161 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 162 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 162 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | 163 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 163 button->SetFocusForPlatform(); | 164 button->SetFocusForPlatform(); |
| 164 button->set_request_focus_on_press(true); | 165 button->set_request_focus_on_press(true); |
| 165 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); | 166 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); |
| 166 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); | 167 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); |
| 167 return button; | 168 return button; |
| 168 } | 169 } |
| 169 | 170 |
| 170 views::MdTextButton* InfoBarView::CreateMdTextButton( | |
| 171 views::ButtonListener* listener, | |
| 172 const base::string16& text) { | |
| 173 DCHECK(ui::MaterialDesignController::IsModeMaterial()); | |
| 174 views::MdTextButton* button = | |
| 175 views::MdTextButton::CreateMdButton(listener, text); | |
| 176 // TODO(estade): can we just remove this? | |
| 177 button->SetEnabledTextColors(GetInfobarTextColor()); | |
| 178 return button; | |
| 179 } | |
| 180 | |
| 181 // static | 171 // static |
| 182 void InfoBarView::AssignWidths(Labels* labels, int available_width) { | 172 void InfoBarView::AssignWidths(Labels* labels, int available_width) { |
| 183 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); | 173 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); |
| 184 AssignWidthsSorted(labels, available_width); | 174 AssignWidthsSorted(labels, available_width); |
| 185 } | 175 } |
| 186 | 176 |
| 187 void InfoBarView::Layout() { | 177 void InfoBarView::Layout() { |
| 188 // Calculate the fill and stroke paths. We do this here, rather than in | 178 // Calculate the fill and stroke paths. We do this here, rather than in |
| 189 // PlatformSpecificRecalculateHeight(), because this is also reached when our | 179 // PlatformSpecificRecalculateHeight(), because this is also reached when our |
| 190 // width is changed, which affects both paths. | 180 // width is changed, which affects both paths. |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 437 } | 427 } |
| 438 | 428 |
| 439 bool InfoBarView::DoesIntersectRect(const View* target, | 429 bool InfoBarView::DoesIntersectRect(const View* target, |
| 440 const gfx::Rect& rect) const { | 430 const gfx::Rect& rect) const { |
| 441 DCHECK_EQ(this, target); | 431 DCHECK_EQ(this, target); |
| 442 // Only events that intersect the portion below the arrow are interesting. | 432 // Only events that intersect the portion below the arrow are interesting. |
| 443 gfx::Rect non_arrow_bounds = GetLocalBounds(); | 433 gfx::Rect non_arrow_bounds = GetLocalBounds(); |
| 444 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); | 434 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); |
| 445 return rect.Intersects(non_arrow_bounds); | 435 return rect.Intersects(non_arrow_bounds); |
| 446 } | 436 } |
| OLD | NEW |