OLD | NEW |
---|---|
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/string_util.h" | |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
13 #include "ui/accessibility/ax_view_state.h" | |
12 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/font_list.h" | 15 #include "ui/gfx/font_list.h" |
14 #include "ui/views/bubble/bubble_border.h" | 16 #include "ui/views/bubble/bubble_border.h" |
15 #include "ui/views/controls/label.h" | 17 #include "ui/views/controls/label.h" |
16 #include "ui/views/controls/link.h" | 18 #include "ui/views/controls/link.h" |
17 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.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 // Delimiter indicating there should be a segment displayed as a keyboard key. | |
40 const char kKeyNameDelimiter[] = "|"; | |
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 |kKeyNameDelimiter|; each of these segments |
Matt Giuca
2016/06/24 04:21:12
I don't think this comment change is necessary. ("
Patti Lor
2016/06/27 05:10:39
Done.
| |
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. if |kKeyNameDelimiter| is set to |
46 // have "Alt" and "Q" rendered as keys. | 51 // a pipe ('|'), "Press |Alt|+|Q| to exit" will have "Alt" and "Q" rendered as |
52 // keys. | |
47 InstructionView(const base::string16& text, | 53 InstructionView(const base::string16& text, |
48 const gfx::FontList& font_list, | 54 const gfx::FontList& font_list, |
49 SkColor foreground_color, | 55 SkColor foreground_color, |
50 SkColor background_color); | 56 SkColor background_color); |
51 | 57 |
58 base::string16 text() { return text_; } | |
52 void SetText(const base::string16& text); | 59 void SetText(const base::string16& text); |
53 | 60 |
54 private: | 61 private: |
55 // Adds a label to the end of the notification text. If |format_as_key|, | 62 // 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 | 63 // surrounds the label in a rounded-rect border to indicate that it is a |
57 // keyboard key. | 64 // keyboard key. |
58 void AddTextSegment(const base::string16& text, bool format_as_key); | 65 void AddTextSegment(const base::string16& text, bool format_as_key); |
59 | 66 |
60 const gfx::FontList& font_list_; | 67 const gfx::FontList& font_list_; |
61 SkColor foreground_color_; | 68 SkColor foreground_color_; |
(...skipping 23 matching lines...) Expand all Loading... | |
85 void SubtleNotificationView::InstructionView::SetText( | 92 void SubtleNotificationView::InstructionView::SetText( |
86 const base::string16& text) { | 93 const base::string16& text) { |
87 // Avoid replacing the contents with the same text. | 94 // Avoid replacing the contents with the same text. |
88 if (text == text_) | 95 if (text == text_) |
89 return; | 96 return; |
90 | 97 |
91 RemoveAllChildViews(true); | 98 RemoveAllChildViews(true); |
92 | 99 |
93 // Parse |text|, looking for pipe-delimited segment. | 100 // Parse |text|, looking for pipe-delimited segment. |
94 std::vector<base::string16> segments = | 101 std::vector<base::string16> segments = |
95 base::SplitString(text, base::ASCIIToUTF16("|"), base::TRIM_WHITESPACE, | 102 base::SplitString(text, base::ASCIIToUTF16(kKeyNameDelimiter), |
96 base::SPLIT_WANT_ALL); | 103 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
97 // SplitString() returns empty strings for zero-length segments, so given an | 104 // SplitString() returns empty strings for zero-length segments, so given an |
98 // even number of pipes, there should always be an odd number of segments. | 105 // even number of pipes, there should always be an odd number of segments. |
99 // The exception is if |text| is entirely empty, in which case the returned | 106 // The exception is if |text| is entirely empty, in which case the returned |
100 // list is also empty (rather than containing a single empty string). | 107 // list is also empty (rather than containing a single empty string). |
101 DCHECK(segments.empty() || segments.size() % 2 == 1); | 108 DCHECK(segments.empty() || segments.size() % 2 == 1); |
102 | 109 |
103 // Add text segment, alternating between non-key (no border) and key (border) | 110 // Add text segment, alternating between non-key (no border) and key (border) |
104 // formatting. | 111 // formatting. |
105 bool format_as_key = false; | 112 bool format_as_key = false; |
106 for (const auto& segment : segments) { | 113 for (const auto& segment : segments) { |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 // We set layout manager to nullptr to prevent the widget from sizing its | 208 // 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 | 209 // 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 | 210 // shrinking while we animate the height of the popup to give the impression |
204 // that it is sliding off the top of the screen. | 211 // that it is sliding off the top of the screen. |
205 // TODO(mgiuca): This probably isn't necessary now that there is no slide | 212 // TODO(mgiuca): This probably isn't necessary now that there is no slide |
206 // animation. Remove it. | 213 // animation. Remove it. |
207 popup->GetRootView()->SetLayoutManager(nullptr); | 214 popup->GetRootView()->SetLayoutManager(nullptr); |
208 | 215 |
209 return popup; | 216 return popup; |
210 } | 217 } |
218 | |
219 void SubtleNotificationView::GetAccessibleState(ui::AXViewState* state) { | |
220 state->role = ui::AX_ROLE_LABEL_TEXT; | |
221 base::RemoveChars(instruction_view_->text(), | |
222 base::ASCIIToUTF16(kKeyNameDelimiter), &state->name); | |
223 } | |
OLD | NEW |