| 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 <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 126 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 127 link->set_listener(listener); | 127 link->set_listener(listener); |
| 128 link->SetBackgroundColor(background()->get_color()); | 128 link->SetBackgroundColor(background()->get_color()); |
| 129 return link; | 129 return link; |
| 130 } | 130 } |
| 131 | 131 |
| 132 // static | 132 // static |
| 133 views::LabelButton* InfoBarView::CreateTextButton( | 133 views::LabelButton* InfoBarView::CreateTextButton( |
| 134 views::ButtonListener* listener, | 134 views::ButtonListener* listener, |
| 135 const base::string16& text) { | 135 const base::string16& text) { |
| 136 views::LabelButton* button = nullptr; | 136 DCHECK(!ui::MaterialDesignController::IsModeMaterial()); |
| 137 if (ui::MaterialDesignController::IsModeMaterial()) { | 137 views::LabelButton* button = new views::LabelButton(listener, text); |
| 138 button = views::MdTextButton::CreateStandardButton(listener, text); | 138 scoped_ptr<views::LabelButtonAssetBorder> button_border( |
| 139 } else { | 139 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); |
| 140 button = new views::LabelButton(listener, text); | 140 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); |
| 141 | 141 button_border->SetPainter( |
| 142 scoped_ptr<views::LabelButtonAssetBorder> button_border( | 142 false, views::Button::STATE_NORMAL, |
| 143 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); | 143 views::Painter::CreateImageGridPainter(kNormalImageSet)); |
| 144 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | 144 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); |
| 145 button_border->SetPainter( | 145 button_border->SetPainter( |
| 146 false, views::Button::STATE_NORMAL, | 146 false, views::Button::STATE_HOVERED, |
| 147 views::Painter::CreateImageGridPainter(kNormalImageSet)); | 147 views::Painter::CreateImageGridPainter(kHoveredImageSet)); |
| 148 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | 148 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); |
| 149 button_border->SetPainter( | 149 button_border->SetPainter( |
| 150 false, views::Button::STATE_HOVERED, | 150 false, views::Button::STATE_PRESSED, |
| 151 views::Painter::CreateImageGridPainter(kHoveredImageSet)); | 151 views::Painter::CreateImageGridPainter(kPressedImageSet)); |
| 152 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | 152 button->SetBorder(std::move(button_border)); |
| 153 button_border->SetPainter( | 153 button->set_animate_on_state_change(false); |
| 154 false, views::Button::STATE_PRESSED, | 154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 155 views::Painter::CreateImageGridPainter(kPressedImageSet)); | 155 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 156 button->SetBorder(std::move(button_border)); | 156 button->SetFocusable(true); |
| 157 button->set_animate_on_state_change(false); | |
| 158 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 159 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
| 160 button->SetFocusable(true); | |
| 161 } | |
| 162 | |
| 163 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); | 157 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); |
| 164 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); | 158 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); |
| 165 return button; | 159 return button; |
| 160 } |
| 161 |
| 162 views::MdTextButton* InfoBarView::CreateMdTextButton( |
| 163 views::ButtonListener* listener, |
| 164 const base::string16& text) { |
| 165 DCHECK(ui::MaterialDesignController::IsModeMaterial()); |
| 166 views::MdTextButton* button = |
| 167 views::MdTextButton::CreateMdButton(listener, text); |
| 168 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); |
| 169 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); |
| 170 return button; |
| 166 } | 171 } |
| 167 | 172 |
| 168 // static | 173 // static |
| 169 void InfoBarView::AssignWidths(Labels* labels, int available_width) { | 174 void InfoBarView::AssignWidths(Labels* labels, int available_width) { |
| 170 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); | 175 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); |
| 171 AssignWidthsSorted(labels, available_width); | 176 AssignWidthsSorted(labels, available_width); |
| 172 } | 177 } |
| 173 | 178 |
| 174 void InfoBarView::Layout() { | 179 void InfoBarView::Layout() { |
| 175 // Calculate the fill and stroke paths. We do this here, rather than in | 180 // Calculate the fill and stroke paths. We do this here, rather than in |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 431 } | 436 } |
| 432 | 437 |
| 433 bool InfoBarView::DoesIntersectRect(const View* target, | 438 bool InfoBarView::DoesIntersectRect(const View* target, |
| 434 const gfx::Rect& rect) const { | 439 const gfx::Rect& rect) const { |
| 435 DCHECK_EQ(this, target); | 440 DCHECK_EQ(this, target); |
| 436 // Only events that intersect the portion below the arrow are interesting. | 441 // Only events that intersect the portion below the arrow are interesting. |
| 437 gfx::Rect non_arrow_bounds = GetLocalBounds(); | 442 gfx::Rect non_arrow_bounds = GetLocalBounds(); |
| 438 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); | 443 non_arrow_bounds.Inset(0, arrow_height(), 0, 0); |
| 439 return rect.Intersects(non_arrow_bounds); | 444 return rect.Intersects(non_arrow_bounds); |
| 440 } | 445 } |
| OLD | NEW |