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

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

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

Powered by Google App Engine
This is Rietveld 408576698