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

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

Issue 1979193002: Factor ExclusiveAccessView out to SubtleNotificationView. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fullscreen-remove-old-theming-code
Patch Set: Remove unnecessary TODO. Created 4 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/subtle_notification_view.h"
6
7 #include <memory>
8
9 #include "base/strings/string_split.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "third_party/skia/include/core/SkColor.h"
12 #include "ui/base/resource/resource_bundle.h"
13 #include "ui/gfx/font_list.h"
14 #include "ui/views/bubble/bubble_border.h"
15 #include "ui/views/controls/label.h"
16 #include "ui/views/controls/link.h"
17 #include "ui/views/layout/box_layout.h"
18 #include "ui/views/widget/widget.h"
19
20 namespace {
21
22 // Space between the site info label and the link.
23 const int kMiddlePaddingPx = 30;
24
25 const int kOuterPaddingHorizPx = 40;
26 const int kOuterPaddingVertPx = 8;
27
28 // Partially-transparent background color.
29 const SkColor kBackgroundColor = SkColorSetARGB(0xcc, 0x28, 0x2c, 0x32);
30
31 } // namespace
32
33 // Class containing the exit instruction text. Contains fancy styling on the
msw 2016/05/18 18:38:32 nit: remove references to 'exit' (except in exampl
Matt Giuca 2016/05/19 01:50:31 Done.
34 // keyboard key (not just a simple label).
35 class SubtleNotificationView::InstructionView : public views::View {
36 public:
37 // Creates an InstructionView with specific text. |text| may contain a single
38 // segment delimited by a pair of pipes ('|'); this segment will be displayed
39 // as a keyboard key. e.g., "Press |Esc| to exit" will have "Esc" rendered as
40 // a key.
41 InstructionView(const base::string16& text,
42 const gfx::FontList& font_list,
43 SkColor foreground_color,
44 SkColor background_color);
45
46 void SetText(const base::string16& text);
47
48 private:
49 views::Label* before_key_;
50 views::Label* key_name_label_;
51 views::View* key_name_;
52 views::Label* after_key_;
53
54 DISALLOW_COPY_AND_ASSIGN(InstructionView);
55 };
56
57 SubtleNotificationView::InstructionView::InstructionView(
58 const base::string16& text,
59 const gfx::FontList& font_list,
60 SkColor foreground_color,
61 SkColor background_color) {
62 // Spacing around the escape key name.
msw 2016/05/18 18:38:32 nit: remove 'escape'
Matt Giuca 2016/05/19 01:50:31 Done.
63 const int kKeyNameMarginHorizPx = 7;
64 const int kKeyNameBorderPx = 1;
65 const int kKeyNameCornerRadius = 2;
66 const int kKeyNamePaddingPx = 5;
67
68 // The |between_child_spacing| is the horizontal margin of the key name.
69 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
70 0, 0, kKeyNameMarginHorizPx);
71 SetLayoutManager(layout);
72
73 before_key_ = new views::Label(base::string16(), font_list);
74 before_key_->SetEnabledColor(foreground_color);
75 before_key_->SetBackgroundColor(background_color);
76 AddChildView(before_key_);
77
78 key_name_label_ = new views::Label(base::string16(), font_list);
79 key_name_label_->SetEnabledColor(foreground_color);
80 key_name_label_->SetBackgroundColor(background_color);
81
82 key_name_ = new views::View;
83 views::BoxLayout* key_name_layout = new views::BoxLayout(
84 views::BoxLayout::kHorizontal, kKeyNamePaddingPx, 0, 0);
85 key_name_layout->set_minimum_cross_axis_size(
86 key_name_label_->GetPreferredSize().height() + kKeyNamePaddingPx * 2);
87 key_name_->SetLayoutManager(key_name_layout);
88 key_name_->AddChildView(key_name_label_);
89 // The key name has a border around it.
90 std::unique_ptr<views::Border> border(views::Border::CreateRoundedRectBorder(
91 kKeyNameBorderPx, kKeyNameCornerRadius, foreground_color));
92 key_name_->SetBorder(std::move(border));
93 AddChildView(key_name_);
94
95 after_key_ = new views::Label(base::string16(), font_list);
96 after_key_->SetEnabledColor(foreground_color);
97 after_key_->SetBackgroundColor(background_color);
98 AddChildView(after_key_);
99
100 SetText(text);
101 }
102
103 void SubtleNotificationView::InstructionView::SetText(
104 const base::string16& text) {
105 // Parse |text|, looking for pipe-delimited segment.
106 std::vector<base::string16> segments =
107 base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE,
108 base::SPLIT_WANT_ALL);
109 // Expect 1 or 3 pieces (either no pipe-delimited segments, or one).
110 DCHECK(segments.size() <= 1 || segments.size() == 3);
111
112 before_key_->SetText(segments.size() ? segments[0] : base::string16());
113
114 if (segments.size() < 3) {
115 key_name_->SetVisible(false);
116 after_key_->SetVisible(false);
117 return;
118 }
119
120 before_key_->SetText(segments[0]);
121 key_name_label_->SetText(segments[1]);
122 key_name_->SetVisible(true);
123 after_key_->SetVisible(true);
124 after_key_->SetText(segments[2]);
125 }
126
127 SubtleNotificationView::SubtleNotificationView(
128 const base::string16& instruction_text,
129 const base::string16& link_text,
130 views::LinkListener* link_listener)
131 : link_(nullptr), exit_instruction_(nullptr) {
132 const SkColor kForegroundColor = SK_ColorWHITE;
133
134 std::unique_ptr<views::BubbleBorder> bubble_border(new views::BubbleBorder(
135 views::BubbleBorder::NONE, views::BubbleBorder::NO_ASSETS,
136 kBackgroundColor));
137 set_background(new views::BubbleBackground(bubble_border.get()));
138 SetBorder(std::move(bubble_border));
139
140 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
141 const gfx::FontList& font_list =
142 rb.GetFontList(ui::ResourceBundle::MediumFont);
143
144 exit_instruction_ = new InstructionView(base::string16(), font_list,
145 kForegroundColor, kBackgroundColor);
146
147 link_ = new views::Link();
148 link_->SetFocusBehavior(FocusBehavior::NEVER);
149 link_->set_listener(link_listener);
150 link_->SetFontList(font_list);
151 link_->SetPressedColor(kForegroundColor);
152 link_->SetEnabledColor(kForegroundColor);
153 link_->SetBackgroundColor(kBackgroundColor);
154 link_->SetVisible(false);
155
156 int outer_padding_horiz = kOuterPaddingHorizPx;
157 int outer_padding_vert = kOuterPaddingVertPx;
158 AddChildView(exit_instruction_);
159 AddChildView(link_);
160
161 views::BoxLayout* layout =
162 new views::BoxLayout(views::BoxLayout::kHorizontal, outer_padding_horiz,
163 outer_padding_vert, kMiddlePaddingPx);
164 SetLayoutManager(layout);
165
166 UpdateContent(instruction_text, link_text);
167 }
168
169 SubtleNotificationView::~SubtleNotificationView() {}
170
171 void SubtleNotificationView::UpdateContent(
172 const base::string16& instruction_text,
173 const base::string16& link_text) {
174 exit_instruction_->SetText(instruction_text);
175 exit_instruction_->SetVisible(!instruction_text.empty());
176 link_->SetText(link_text);
177 link_->SetVisible(!link_text.empty());
178 }
179
180 // static
181 views::Widget* SubtleNotificationView::CreatePopupWidget(
182 gfx::NativeView parent_view,
183 SubtleNotificationView* view,
184 bool accept_events) {
185 // TODO(yzshen): Change to use the new views bubble, BubbleDelegateView.
msw 2016/05/18 18:38:32 nit: remove/reassign TODOs? (somewhat stale at thi
Matt Giuca 2016/05/19 01:50:31 Just removed. I think this works fine as it is (I'
186 // TODO(pkotwicz): When this becomes a views bubble, make sure that this
187 // bubble is ignored by ImmersiveModeControllerAsh::BubbleManager.
188 // Initialize the popup.
189 views::Widget* popup = new views::Widget;
190 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
191 params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
192 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
193 params.parent = parent_view;
194 params.accept_events = accept_events;
195 popup->Init(params);
196 popup->SetContentsView(view);
197 // We set layout manager to nullptr to prevent the widget from sizing its
msw 2016/05/18 18:38:31 nit: this is probably unnecessary w/fade animation
Matt Giuca 2016/05/19 01:50:31 OK. Note, I'm a little hesitant to remove too much
198 // contents to the same size as itself. This prevents the widget contents from
199 // shrinking while we animate the height of the popup to give the impression
200 // that it is sliding off the top of the screen.
201 popup->GetRootView()->SetLayoutManager(nullptr);
202
203 return popup;
204 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698