Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(856)

Side by Side Diff: chrome/browser/ui/views/infobars/infobar_view.cc

Issue 1525163004: First stab at MD text buttons (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: self review Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 13 matching lines...) Expand all
24 #include "ui/gfx/color_palette.h" 24 #include "ui/gfx/color_palette.h"
25 #include "ui/gfx/image/image.h" 25 #include "ui/gfx/image/image.h"
26 #include "ui/gfx/paint_vector_icon.h" 26 #include "ui/gfx/paint_vector_icon.h"
27 #include "ui/gfx/vector_icons_public.h" 27 #include "ui/gfx/vector_icons_public.h"
28 #include "ui/native_theme/common_theme.h" 28 #include "ui/native_theme/common_theme.h"
29 #include "ui/native_theme/native_theme.h" 29 #include "ui/native_theme/native_theme.h"
30 #include "ui/resources/grit/ui_resources.h" 30 #include "ui/resources/grit/ui_resources.h"
31 #include "ui/views/controls/button/image_button.h" 31 #include "ui/views/controls/button/image_button.h"
32 #include "ui/views/controls/button/label_button.h" 32 #include "ui/views/controls/button/label_button.h"
33 #include "ui/views/controls/button/label_button_border.h" 33 #include "ui/views/controls/button/label_button_border.h"
34 #include "ui/views/controls/button/md_text_button.h"
34 #include "ui/views/controls/button/menu_button.h" 35 #include "ui/views/controls/button/menu_button.h"
35 #include "ui/views/controls/image_view.h" 36 #include "ui/views/controls/image_view.h"
36 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
37 #include "ui/views/controls/link.h" 38 #include "ui/views/controls/link.h"
38 #include "ui/views/controls/menu/menu_runner.h" 39 #include "ui/views/controls/menu/menu_runner.h"
39 #include "ui/views/layout/layout_constants.h" 40 #include "ui/views/layout/layout_constants.h"
40 #include "ui/views/widget/widget.h" 41 #include "ui/views/widget/widget.h"
41 #include "ui/views/window/non_client_view.h" 42 #include "ui/views/window/non_client_view.h"
42 43
43 44
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
105 views::Link* link = new views::Link(text); 106 views::Link* link = new views::Link(text);
106 link->SetFontList(GetFontList()); 107 link->SetFontList(GetFontList());
107 link->SizeToPreferredSize(); 108 link->SizeToPreferredSize();
108 link->SetHorizontalAlignment(gfx::ALIGN_LEFT); 109 link->SetHorizontalAlignment(gfx::ALIGN_LEFT);
109 link->set_listener(listener); 110 link->set_listener(listener);
110 link->SetBackgroundColor(background()->get_color()); 111 link->SetBackgroundColor(background()->get_color());
111 return link; 112 return link;
112 } 113 }
113 114
114 // static 115 // static
116 views::Button* InfoBarView::CreateTextButton(
117 views::ButtonListener* listener,
118 const base::string16& text) {
119 if (!ui::MaterialDesignController::IsModeMaterial())
120 return CreateLabelButton(listener, text);
121
122 return new views::MdTextButton(listener, text);
123 }
124
125 // static
115 views::LabelButton* InfoBarView::CreateLabelButton( 126 views::LabelButton* InfoBarView::CreateLabelButton(
116 views::ButtonListener* listener, 127 views::ButtonListener* listener,
117 const base::string16& text) { 128 const base::string16& text) {
118 views::LabelButton* button = new views::LabelButton(listener, text); 129 views::LabelButton* button = new views::LabelButton(listener, text);
119 if (ui::MaterialDesignController::IsModeMaterial()) { 130 scoped_ptr<views::LabelButtonAssetBorder> button_border(
120 button->SetStyle(views::Button::STYLE_BUTTON); 131 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON));
121 } else { 132 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL);
122 scoped_ptr<views::LabelButtonAssetBorder> button_border( 133 button_border->SetPainter(
123 new views::LabelButtonAssetBorder(views::Button::STYLE_TEXTBUTTON)); 134 false, views::Button::STATE_NORMAL,
124 const int kNormalImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_NORMAL); 135 views::Painter::CreateImageGridPainter(kNormalImageSet));
125 button_border->SetPainter( 136 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER);
126 false, views::Button::STATE_NORMAL, 137 button_border->SetPainter(
127 views::Painter::CreateImageGridPainter(kNormalImageSet)); 138 false, views::Button::STATE_HOVERED,
128 const int kHoveredImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_HOVER); 139 views::Painter::CreateImageGridPainter(kHoveredImageSet));
129 button_border->SetPainter( 140 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED);
130 false, views::Button::STATE_HOVERED, 141 button_border->SetPainter(
131 views::Painter::CreateImageGridPainter(kHoveredImageSet)); 142 false, views::Button::STATE_PRESSED,
132 const int kPressedImageSet[] = IMAGE_GRID(IDR_INFOBARBUTTON_PRESSED); 143 views::Painter::CreateImageGridPainter(kPressedImageSet));
133 button_border->SetPainter(
134 false, views::Button::STATE_PRESSED,
135 views::Painter::CreateImageGridPainter(kPressedImageSet));
136 144
137 button->SetBorder(button_border.Pass()); 145 button->SetBorder(std::move(button_border));
138 button->set_animate_on_state_change(false); 146 button->set_animate_on_state_change(false);
139 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor()); 147 button->SetTextColor(views::Button::STATE_NORMAL, GetInfobarTextColor());
140 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor()); 148 button->SetTextColor(views::Button::STATE_HOVERED, GetInfobarTextColor());
141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
142 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont)); 150 button->SetFontList(rb.GetFontList(ui::ResourceBundle::MediumFont));
143 }
144 button->SetFocusable(true); 151 button->SetFocusable(true);
145 return button; 152 return button;
146 } 153 }
147 154
148 // static 155 // static
149 void InfoBarView::AssignWidths(Labels* labels, int available_width) { 156 void InfoBarView::AssignWidths(Labels* labels, int available_width) {
150 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth); 157 std::sort(labels->begin(), labels->end(), SortLabelsByDecreasingWidth);
151 AssignWidthsSorted(labels, available_width); 158 AssignWidthsSorted(labels, available_width);
152 } 159 }
153 160
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) { 411 void InfoBarView::OnWillChangeFocus(View* focused_before, View* focused_now) {
405 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now); 412 views::ExternalFocusTracker::OnWillChangeFocus(focused_before, focused_now);
406 413
407 // This will trigger some screen readers to read the entire contents of this 414 // This will trigger some screen readers to read the entire contents of this
408 // infobar. 415 // infobar.
409 if (focused_before && focused_now && !Contains(focused_before) && 416 if (focused_before && focused_now && !Contains(focused_before) &&
410 Contains(focused_now)) { 417 Contains(focused_now)) {
411 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true); 418 NotifyAccessibilityEvent(ui::AX_EVENT_ALERT, true);
412 } 419 }
413 } 420 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698