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

Side by Side Diff: chrome/browser/ui/views/subtle_notification_view.cc

Issue 2734113006: "Bootstrap" a toolkit-views Typography spec. (Closed)
Patch Set: fix windows Created 3 years, 9 months 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 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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/subtle_notification_view.h" 5 #include "chrome/browser/ui/views/subtle_notification_view.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/strings/string_split.h" 9 #include "base/strings/string_split.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 16 matching lines...) Expand all
27 27
28 // Partially-transparent background color. 28 // Partially-transparent background color.
29 const SkColor kBackgroundColor = SkColorSetARGB(0xcc, 0x28, 0x2c, 0x32); 29 const SkColor kBackgroundColor = SkColorSetARGB(0xcc, 0x28, 0x2c, 0x32);
30 30
31 // Spacing around the key name. 31 // Spacing around the key name.
32 const int kKeyNameMarginHorizPx = 7; 32 const int kKeyNameMarginHorizPx = 7;
33 const int kKeyNameBorderPx = 1; 33 const int kKeyNameBorderPx = 1;
34 const int kKeyNameCornerRadius = 2; 34 const int kKeyNameCornerRadius = 2;
35 const int kKeyNamePaddingPx = 5; 35 const int kKeyNamePaddingPx = 5;
36 36
37 // The context used to obtain typography for the instruction text. It's not
38 // really a dialog, but a dialog title is a good fit.
39 constexpr views::TextContext kInstructionTextContext =
40 views::TextContext::DIALOG_TITLE;
41
37 } // namespace 42 } // namespace
38 43
39 // Class containing the instruction text. Contains fancy styling on the keyboard 44 // Class containing the instruction text. Contains fancy styling on the keyboard
40 // key (not just a simple label). 45 // key (not just a simple label).
41 class SubtleNotificationView::InstructionView : public views::View { 46 class SubtleNotificationView::InstructionView : public views::View {
42 public: 47 public:
43 // Creates an InstructionView with specific text. |text| may contain one or 48 // Creates an InstructionView with specific text. |text| may contain one or
44 // more segments delimited by a pair of pipes ('|'); each of these segments 49 // more segments delimited by a pair of pipes ('|'); each of these segments
45 // will be displayed as a keyboard key. e.g., "Press |Alt|+|Q| to exit" will 50 // will be displayed as a keyboard key. e.g., "Press |Alt|+|Q| to exit" will
46 // have "Alt" and "Q" rendered as keys. 51 // have "Alt" and "Q" rendered as keys.
47 InstructionView(const base::string16& text, 52 InstructionView(const base::string16& text,
48 const gfx::FontList& font_list,
49 SkColor foreground_color, 53 SkColor foreground_color,
50 SkColor background_color); 54 SkColor background_color);
51 55
52 void SetText(const base::string16& text); 56 void SetText(const base::string16& text);
53 57
54 private: 58 private:
55 // Adds a label to the end of the notification text. If |format_as_key|, 59 // Adds a label to the end of the notification text. If |format_as_key|,
56 // surrounds the label in a rounded-rect border to indicate that it is a 60 // surrounds the label in a rounded-rect border to indicate that it is a
57 // keyboard key. 61 // keyboard key.
58 void AddTextSegment(const base::string16& text, bool format_as_key); 62 void AddTextSegment(const base::string16& text, bool format_as_key);
59 63
60 const gfx::FontList& font_list_;
61 SkColor foreground_color_; 64 SkColor foreground_color_;
62 SkColor background_color_; 65 SkColor background_color_;
63 66
64 base::string16 text_; 67 base::string16 text_;
65 68
66 DISALLOW_COPY_AND_ASSIGN(InstructionView); 69 DISALLOW_COPY_AND_ASSIGN(InstructionView);
67 }; 70 };
68 71
69 SubtleNotificationView::InstructionView::InstructionView( 72 SubtleNotificationView::InstructionView::InstructionView(
70 const base::string16& text, 73 const base::string16& text,
71 const gfx::FontList& font_list,
72 SkColor foreground_color, 74 SkColor foreground_color,
73 SkColor background_color) 75 SkColor background_color)
74 : font_list_(font_list), 76 : foreground_color_(foreground_color), background_color_(background_color) {
75 foreground_color_(foreground_color),
76 background_color_(background_color) {
77 // The |between_child_spacing| is the horizontal margin of the key name. 77 // The |between_child_spacing| is the horizontal margin of the key name.
78 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 78 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
79 0, 0, kKeyNameMarginHorizPx); 79 0, 0, kKeyNameMarginHorizPx);
80 SetLayoutManager(layout); 80 SetLayoutManager(layout);
81 81
82 SetText(text); 82 SetText(text);
83 } 83 }
84 84
85 void SubtleNotificationView::InstructionView::SetText( 85 void SubtleNotificationView::InstructionView::SetText(
86 const base::string16& text) { 86 const base::string16& text) {
(...skipping 19 matching lines...) Expand all
106 for (const auto& segment : segments) { 106 for (const auto& segment : segments) {
107 AddTextSegment(segment, format_as_key); 107 AddTextSegment(segment, format_as_key);
108 format_as_key = !format_as_key; 108 format_as_key = !format_as_key;
109 } 109 }
110 110
111 text_ = text; 111 text_ = text;
112 } 112 }
113 113
114 void SubtleNotificationView::InstructionView::AddTextSegment( 114 void SubtleNotificationView::InstructionView::AddTextSegment(
115 const base::string16& text, bool format_as_key) { 115 const base::string16& text, bool format_as_key) {
116 views::Label* label = new views::Label(text, font_list_); 116 views::Label* label = new views::Label(text, kInstructionTextContext);
117 label->SetEnabledColor(foreground_color_); 117 label->SetEnabledColor(foreground_color_);
118 label->SetBackgroundColor(background_color_); 118 label->SetBackgroundColor(background_color_);
119 if (!format_as_key) { 119 if (!format_as_key) {
120 AddChildView(label); 120 AddChildView(label);
121 return; 121 return;
122 } 122 }
123 123
124 views::View* key = new views::View; 124 views::View* key = new views::View;
125 views::BoxLayout* key_name_layout = new views::BoxLayout( 125 views::BoxLayout* key_name_layout = new views::BoxLayout(
126 views::BoxLayout::kHorizontal, kKeyNamePaddingPx, 0, 0); 126 views::BoxLayout::kHorizontal, kKeyNamePaddingPx, 0, 0);
(...skipping 12 matching lines...) Expand all
139 views::LinkListener* link_listener) 139 views::LinkListener* link_listener)
140 : instruction_view_(nullptr), link_(nullptr) { 140 : instruction_view_(nullptr), link_(nullptr) {
141 const SkColor kForegroundColor = SK_ColorWHITE; 141 const SkColor kForegroundColor = SK_ColorWHITE;
142 142
143 std::unique_ptr<views::BubbleBorder> bubble_border(new views::BubbleBorder( 143 std::unique_ptr<views::BubbleBorder> bubble_border(new views::BubbleBorder(
144 views::BubbleBorder::NONE, views::BubbleBorder::NO_ASSETS, 144 views::BubbleBorder::NONE, views::BubbleBorder::NO_ASSETS,
145 kBackgroundColor)); 145 kBackgroundColor));
146 set_background(new views::BubbleBackground(bubble_border.get())); 146 set_background(new views::BubbleBackground(bubble_border.get()));
147 SetBorder(std::move(bubble_border)); 147 SetBorder(std::move(bubble_border));
148 148
149 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 149 instruction_view_ =
150 const gfx::FontList& font_list = 150 new InstructionView(base::string16(), kForegroundColor, kBackgroundColor);
151 rb.GetFontList(ui::ResourceBundle::MediumFont);
152
153 instruction_view_ = new InstructionView(base::string16(), font_list,
154 kForegroundColor, kBackgroundColor);
155 151
156 link_ = new views::Link(); 152 link_ = new views::Link();
157 link_->SetFocusBehavior(FocusBehavior::NEVER); 153 link_->SetFocusBehavior(FocusBehavior::NEVER);
158 link_->set_listener(link_listener); 154 link_->set_listener(link_listener);
159 link_->SetFontList(font_list); 155 link_->SetFontList(views::Typography::GetFont(kInstructionTextContext,
160 link_->SetEnabledColor(kForegroundColor); 156 views::TextStyle::LINK));
157 link_->SetEnabledColor(kForegroundColor); // Overrides TextStyle::LINK.
161 link_->SetBackgroundColor(kBackgroundColor); 158 link_->SetBackgroundColor(kBackgroundColor);
162 link_->SetVisible(false); 159 link_->SetVisible(false);
163 160
164 int outer_padding_horiz = kOuterPaddingHorizPx; 161 int outer_padding_horiz = kOuterPaddingHorizPx;
165 int outer_padding_vert = kOuterPaddingVertPx; 162 int outer_padding_vert = kOuterPaddingVertPx;
166 AddChildView(instruction_view_); 163 AddChildView(instruction_view_);
167 AddChildView(link_); 164 AddChildView(link_);
168 165
169 views::BoxLayout* layout = 166 views::BoxLayout* layout =
170 new views::BoxLayout(views::BoxLayout::kHorizontal, outer_padding_horiz, 167 new views::BoxLayout(views::BoxLayout::kHorizontal, outer_padding_horiz,
(...skipping 30 matching lines...) Expand all
201 // We set layout manager to nullptr to prevent the widget from sizing its 198 // We set layout manager to nullptr to prevent the widget from sizing its
202 // contents to the same size as itself. This prevents the widget contents from 199 // contents to the same size as itself. This prevents the widget contents from
203 // shrinking while we animate the height of the popup to give the impression 200 // shrinking while we animate the height of the popup to give the impression
204 // that it is sliding off the top of the screen. 201 // that it is sliding off the top of the screen.
205 // TODO(mgiuca): This probably isn't necessary now that there is no slide 202 // TODO(mgiuca): This probably isn't necessary now that there is no slide
206 // animation. Remove it. 203 // animation. Remove it.
207 popup->GetRootView()->SetLayoutManager(nullptr); 204 popup->GetRootView()->SetLayoutManager(nullptr);
208 205
209 return popup; 206 return popup;
210 } 207 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698