Chromium Code Reviews| 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/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 11 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/accessibility/ax_view_state.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" |
| 18 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 42 public: | 43 public: |
| 43 // Creates an InstructionView with specific text. |text| may contain one or | 44 // Creates an InstructionView with specific text. |text| may contain one or |
| 44 // more segments delimited by a pair of pipes ('|'); each of these segments | 45 // 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 | 46 // will be displayed as a keyboard key. e.g., "Press |Alt|+|Q| to exit" will |
| 46 // have "Alt" and "Q" rendered as keys. | 47 // have "Alt" and "Q" rendered as keys. |
| 47 InstructionView(const base::string16& text, | 48 InstructionView(const base::string16& text, |
| 48 const gfx::FontList& font_list, | 49 const gfx::FontList& font_list, |
| 49 SkColor foreground_color, | 50 SkColor foreground_color, |
| 50 SkColor background_color); | 51 SkColor background_color); |
| 51 | 52 |
| 53 base::string16 text(); | |
|
tapted
2016/06/22 00:23:38
nit: declare const function
Patti Lor
2016/06/23 01:00:38
Done.
| |
| 52 void SetText(const base::string16& text); | 54 void SetText(const base::string16& text); |
| 53 | 55 |
| 54 private: | 56 private: |
| 55 // Adds a label to the end of the notification text. If |format_as_key|, | 57 // 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 | 58 // surrounds the label in a rounded-rect border to indicate that it is a |
| 57 // keyboard key. | 59 // keyboard key. |
| 58 void AddTextSegment(const base::string16& text, bool format_as_key); | 60 void AddTextSegment(const base::string16& text, bool format_as_key); |
| 59 | 61 |
| 60 const gfx::FontList& font_list_; | 62 const gfx::FontList& font_list_; |
| 61 SkColor foreground_color_; | 63 SkColor foreground_color_; |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 75 foreground_color_(foreground_color), | 77 foreground_color_(foreground_color), |
| 76 background_color_(background_color) { | 78 background_color_(background_color) { |
| 77 // The |between_child_spacing| is the horizontal margin of the key name. | 79 // The |between_child_spacing| is the horizontal margin of the key name. |
| 78 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, | 80 views::BoxLayout* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 79 0, 0, kKeyNameMarginHorizPx); | 81 0, 0, kKeyNameMarginHorizPx); |
| 80 SetLayoutManager(layout); | 82 SetLayoutManager(layout); |
| 81 | 83 |
| 82 SetText(text); | 84 SetText(text); |
| 83 } | 85 } |
| 84 | 86 |
| 87 base::string16 SubtleNotificationView::InstructionView::text() { | |
| 88 return text_; | |
|
tapted
2016/06/22 00:23:38
nit: declare this inline
Matt Giuca
2016/06/22 02:59:20
This needs to have the pipes removed (http://www.o
Patti Lor
2016/06/23 01:00:38
Done (as per option 2).
| |
| 89 } | |
| 90 | |
| 85 void SubtleNotificationView::InstructionView::SetText( | 91 void SubtleNotificationView::InstructionView::SetText( |
| 86 const base::string16& text) { | 92 const base::string16& text) { |
| 87 // Avoid replacing the contents with the same text. | 93 // Avoid replacing the contents with the same text. |
| 88 if (text == text_) | 94 if (text == text_) |
| 89 return; | 95 return; |
| 90 | 96 |
| 91 RemoveAllChildViews(true); | 97 RemoveAllChildViews(true); |
| 92 | 98 |
| 93 // Parse |text|, looking for pipe-delimited segment. | 99 // Parse |text|, looking for pipe-delimited segment. |
| 94 std::vector<base::string16> segments = | 100 std::vector<base::string16> segments = |
| (...skipping 106 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 | 207 // 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 | 208 // 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 | 209 // shrinking while we animate the height of the popup to give the impression |
| 204 // that it is sliding off the top of the screen. | 210 // that it is sliding off the top of the screen. |
| 205 // TODO(mgiuca): This probably isn't necessary now that there is no slide | 211 // TODO(mgiuca): This probably isn't necessary now that there is no slide |
| 206 // animation. Remove it. | 212 // animation. Remove it. |
| 207 popup->GetRootView()->SetLayoutManager(nullptr); | 213 popup->GetRootView()->SetLayoutManager(nullptr); |
| 208 | 214 |
| 209 return popup; | 215 return popup; |
| 210 } | 216 } |
| 217 | |
| 218 // views::View: | |
|
tapted
2016/06/22 00:23:38
nit: no need for this comment
Patti Lor
2016/06/23 01:00:39
Done.
| |
| 219 | |
| 220 void SubtleNotificationView::GetAccessibleState(ui::AXViewState* state) { | |
| 221 state->role = ui::AX_ROLE_LABEL_TEXT; | |
| 222 state->name = instruction_view_->text(); | |
|
Matt Giuca
2016/06/22 02:59:20
This needs to have the pipes removed (http://www.o
Patti Lor
2016/06/23 01:00:38
Done.
| |
| 223 } | |
| OLD | NEW |