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 14 matching lines...) Expand all Loading... |
25 #include "ui/gfx/color_palette.h" | 25 #include "ui/gfx/color_palette.h" |
26 #include "ui/gfx/image/image.h" | 26 #include "ui/gfx/image/image.h" |
27 #include "ui/gfx/paint_vector_icon.h" | 27 #include "ui/gfx/paint_vector_icon.h" |
28 #include "ui/gfx/vector_icons_public.h" | 28 #include "ui/gfx/vector_icons_public.h" |
29 #include "ui/native_theme/common_theme.h" | 29 #include "ui/native_theme/common_theme.h" |
30 #include "ui/native_theme/native_theme.h" | 30 #include "ui/native_theme/native_theme.h" |
31 #include "ui/resources/grit/ui_resources.h" | 31 #include "ui/resources/grit/ui_resources.h" |
32 #include "ui/views/controls/button/image_button.h" | 32 #include "ui/views/controls/button/image_button.h" |
33 #include "ui/views/controls/button/label_button.h" | 33 #include "ui/views/controls/button/label_button.h" |
34 #include "ui/views/controls/button/label_button_border.h" | 34 #include "ui/views/controls/button/label_button_border.h" |
| 35 #include "ui/views/controls/button/md_text_button.h" |
35 #include "ui/views/controls/button/menu_button.h" | 36 #include "ui/views/controls/button/menu_button.h" |
36 #include "ui/views/controls/image_view.h" | 37 #include "ui/views/controls/image_view.h" |
37 #include "ui/views/controls/label.h" | 38 #include "ui/views/controls/label.h" |
38 #include "ui/views/controls/link.h" | 39 #include "ui/views/controls/link.h" |
39 #include "ui/views/controls/menu/menu_runner.h" | 40 #include "ui/views/controls/menu/menu_runner.h" |
40 #include "ui/views/layout/layout_constants.h" | 41 #include "ui/views/layout/layout_constants.h" |
41 #include "ui/views/widget/widget.h" | 42 #include "ui/views/widget/widget.h" |
42 #include "ui/views/window/non_client_view.h" | 43 #include "ui/views/window/non_client_view.h" |
43 | 44 |
44 | 45 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
118 views::Link* link = new views::Link(text); | 119 views::Link* link = new views::Link(text); |
119 link->SetFontList(GetFontList()); | 120 link->SetFontList(GetFontList()); |
120 link->SizeToPreferredSize(); | 121 link->SizeToPreferredSize(); |
121 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 122 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
122 link->set_listener(listener); | 123 link->set_listener(listener); |
123 link->SetBackgroundColor(background()->get_color()); | 124 link->SetBackgroundColor(background()->get_color()); |
124 return link; | 125 return link; |
125 } | 126 } |
126 | 127 |
127 // static | 128 // static |
128 views::Button* InfoBarView::CreateTextButton( | 129 views::LabelButton* InfoBarView::CreateTextButton( |
129 views::ButtonListener* listener, | 130 views::ButtonListener* listener, |
130 const base::string16& text) { | 131 const base::string16& text) { |
131 views::LabelButton* button = CreateLabelButton(listener, text); | 132 views::LabelButton* button = nullptr; |
132 if (ui::MaterialDesignController::IsModeMaterial()) | 133 if (ui::MaterialDesignController::IsModeMaterial()) { |
133 button->SetFontList(GetFontList()); | 134 button = views::MdTextButton::CreateStandardButton(listener, text); |
| 135 } else { |
| 136 button = new views::LabelButton(listener, text); |
134 | 137 |
| 138 scoped_ptr<views::LabelButtonAssetBorder> button_border( |
| 139 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); |
| 140 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); |
| 141 button_border->SetPainter( |
| 142 false, views::Button::STATE_NORMAL, |
| 143 views::Painter::CreateImageGridPainter(kNormalImageSet)); |
| 144 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); |
| 145 button_border->SetPainter( |
| 146 false, views::Button::STATE_HOVERED, |
| 147 views::Painter::CreateImageGridPainter(kHoveredImageSet)); |
| 148 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); |
| 149 button_border->SetPainter( |
| 150 false, views::Button::STATE_PRESSED, |
| 151 views::Painter::CreateImageGridPainter(kPressedImageSet)); |
| 152 button->SetBorder(std::move(button_border)); |
| 153 button->set_animate_on_state_change(false); |
| 154 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 155 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); |
| 156 button->SetFocusable(true); |
| 157 } |
| 158 |
| 159 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); |
| 160 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); |
135 return button; | 161 return button; |
136 } | 162 } |
137 | 163 |
138 // static | |
139 views::LabelButton* InfoBarView::CreateLabelButton( | |
140 views::ButtonListener* listener, | |
141 const base::string16& text) { | |
142 views::LabelButton* button = new views::LabelButton(listener, text); | |
143 scoped_ptr<views::LabelButtonAssetBorder> button_border( | |
144 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); | |
145 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); | |
146 button_border->SetPainter( | |
147 false, views::Button::STATE_NORMAL, | |
148 views::Painter::CreateImageGridPainter(kNormalImageSet)); | |
149 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); | |
150 button_border->SetPainter( | |
151 false, views::Button::STATE_HOVERED, | |
152 views::Painter::CreateImageGridPainter(kHoveredImageSet)); | |
153 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); | |
154 button_border->SetPainter( | |
155 false, views::Button::STATE_PRESSED, | |
156 views::Painter::CreateImageGridPainter(kPressedImageSet)); | |
157 | |
158 button->SetBorder(std::move(button_border)); | |
159 button->set_animate_on_state_change(false); | |
160 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); | |
161 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); | |
162 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
163 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); | |
164 button->SetFocusable(true); | |
165 return button; | |
166 } | |
167 | |
168 // static | 164 // static |
169 void InfoBarView::AssignWidths(Labels* labels, int available_width) { | 165 void InfoBarView::AssignWidths(Labels* labels, int available_width) { |
170 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); | 166 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); |
171 AssignWidthsSorted(labels, available_width); | 167 AssignWidthsSorted(labels, available_width); |
172 } | 168 } |
173 | 169 |
174 void InfoBarView::Layout() { | 170 void InfoBarView::Layout() { |
175 // Calculate the fill and stroke paths. We do this here, rather than in | 171 // Calculate the fill and stroke paths. We do this here, rather than in |
176 // PlatformSpecificRecalculateHeight(), because this is also reached when our | 172 // PlatformSpecificRecalculateHeight(), because this is also reached when our |
177 // width is changed, which affects both paths. | 173 // width is changed, which affects both paths. |
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
422 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { | 418 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { |
423 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); | 419 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); |
424 | 420 |
425 // This will trigger some screen readers to read the entire contents of this | 421 // This will trigger some screen readers to read the entire contents of this |
426 // infobar. | 422 // infobar. |
427 if (focused_before && focused_now && !Contains(focused_before) && | 423 if (focused_before && focused_now && !Contains(focused_before) && |
428 Contains(focused_now)) { | 424 Contains(focused_now)) { |
429 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); | 425 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); |
430 } | 426 } |
431 } | 427 } |
OLD | NEW |