OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ash/system/user/user_card_view.h" | 5 #include "ash/system/user/user_card_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 // contains a link. | 80 // contains a link. |
81 class PublicAccountUserDetails : public views::View, | 81 class PublicAccountUserDetails : public views::View, |
82 public views::LinkListener { | 82 public views::LinkListener { |
83 public: | 83 public: |
84 PublicAccountUserDetails(); | 84 PublicAccountUserDetails(); |
85 ~PublicAccountUserDetails() override; | 85 ~PublicAccountUserDetails() override; |
86 | 86 |
87 private: | 87 private: |
88 // Overridden from views::View. | 88 // Overridden from views::View. |
89 void Layout() override; | 89 void Layout() override; |
90 gfx::Size GetPreferredSize() const override; | |
91 void OnPaint(gfx::Canvas* canvas) override; | 90 void OnPaint(gfx::Canvas* canvas) override; |
92 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 91 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
93 | 92 |
94 // Overridden from views::LinkListener. | 93 // Overridden from views::LinkListener. |
95 void LinkClicked(views::Link* source, int event_flags) override; | 94 void LinkClicked(views::Link* source, int event_flags) override; |
96 | 95 |
97 // Calculate a preferred size that ensures the label text and the following | 96 // Calculate a preferred size that ensures the label text and the following |
98 // link do not wrap over more than three lines in total for aesthetic reasons | 97 // link do not wrap over more than three lines in total for aesthetic reasons |
99 // if possible. | 98 // if possible. |
100 void DeterminePreferredSize(); | 99 void DeterminePreferredSize(); |
101 | 100 |
102 base::string16 text_; | 101 base::string16 text_; |
103 views::Link* learn_more_; | 102 views::Link* learn_more_; |
104 gfx::Size preferred_size_; | |
105 std::vector<std::unique_ptr<gfx::RenderText>> lines_; | 103 std::vector<std::unique_ptr<gfx::RenderText>> lines_; |
106 | 104 |
107 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); | 105 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); |
108 }; | 106 }; |
109 | 107 |
110 PublicAccountUserDetails::PublicAccountUserDetails() : learn_more_(nullptr) { | 108 PublicAccountUserDetails::PublicAccountUserDetails() : learn_more_(nullptr) { |
111 const int inner_padding = | 109 const int inner_padding = |
112 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; | 110 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; |
113 const bool rtl = base::i18n::IsRTL(); | 111 const bool rtl = base::i18n::IsRTL(); |
114 SetBorder(views::CreateEmptyBorder( | 112 SetBorder(views::CreateEmptyBorder( |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 position.set_y(position.y() - learn_more_->GetInsets().top()); | 199 position.set_y(position.y() - learn_more_->GetInsets().top()); |
202 gfx::Rect learn_more_bounds(position, link_size); | 200 gfx::Rect learn_more_bounds(position, link_size); |
203 learn_more_bounds.Intersect(contents_area); | 201 learn_more_bounds.Intersect(contents_area); |
204 if (base::i18n::IsRTL()) { | 202 if (base::i18n::IsRTL()) { |
205 const gfx::Insets insets = GetInsets(); | 203 const gfx::Insets insets = GetInsets(); |
206 learn_more_bounds.Offset(insets.right() - insets.left(), 0); | 204 learn_more_bounds.Offset(insets.right() - insets.left(), 0); |
207 } | 205 } |
208 learn_more_->SetBoundsRect(learn_more_bounds); | 206 learn_more_->SetBoundsRect(learn_more_bounds); |
209 } | 207 } |
210 | 208 |
211 gfx::Size PublicAccountUserDetails::GetPreferredSize() const { | |
212 return preferred_size_; | |
213 } | |
214 | |
215 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { | 209 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { |
216 for (const auto& line : lines_) | 210 for (const auto& line : lines_) |
217 line->Draw(canvas); | 211 line->Draw(canvas); |
218 | 212 |
219 views::View::OnPaint(canvas); | 213 views::View::OnPaint(canvas); |
220 } | 214 } |
221 | 215 |
222 void PublicAccountUserDetails::GetAccessibleNodeData( | 216 void PublicAccountUserDetails::GetAccessibleNodeData( |
223 ui::AXNodeData* node_data) { | 217 ui::AXNodeData* node_data) { |
224 node_data->role = ui::AX_ROLE_STATIC_TEXT; | 218 node_data->role = ui::AX_ROLE_STATIC_TEXT; |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
269 gfx::ElideRectangleText(text_, font_list, min_width, INT_MAX, | 263 gfx::ElideRectangleText(text_, font_list, min_width, INT_MAX, |
270 gfx::TRUNCATE_LONG_WORDS, &lines); | 264 gfx::TRUNCATE_LONG_WORDS, &lines); |
271 int line_count = lines.size(); | 265 int line_count = lines.size(); |
272 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= | 266 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= |
273 space_width + link_size.width()) { | 267 space_width + link_size.width()) { |
274 ++line_count; | 268 ++line_count; |
275 } | 269 } |
276 const int line_height = font_list.GetHeight(); | 270 const int line_height = font_list.GetHeight(); |
277 const int link_extra_height = std::max( | 271 const int link_extra_height = std::max( |
278 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 272 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
279 preferred_size_ = | 273 set_preferred_size(gfx::Size( |
280 gfx::Size(min_width + insets.width(), | 274 min_width + insets.width(), |
281 line_count * line_height + link_extra_height + insets.height()); | 275 line_count * line_height + link_extra_height + insets.height())); |
282 } | 276 } |
283 | 277 |
284 } // namespace | 278 } // namespace |
285 | 279 |
286 UserCardView::UserCardView(LoginStatus login_status, int user_index) | 280 UserCardView::UserCardView(LoginStatus login_status, int user_index) |
287 : user_index_(user_index) { | 281 : user_index_(user_index) { |
288 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | 282 auto* layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
289 kTrayPopupLabelHorizontalPadding); | 283 kTrayPopupLabelHorizontalPadding); |
290 SetLayoutManager(layout); | 284 SetLayoutManager(layout); |
291 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); | 285 layout->set_minimum_cross_axis_size(kTrayPopupItemMinHeight); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 media_capture_container_ = new views::View(); | 435 media_capture_container_ = new views::View(); |
442 media_capture_container_->SetLayoutManager(new views::FillLayout()); | 436 media_capture_container_->SetLayoutManager(new views::FillLayout()); |
443 media_capture_container_->AddChildView(media_capture_icon_); | 437 media_capture_container_->AddChildView(media_capture_icon_); |
444 AddChildView(media_capture_container_); | 438 AddChildView(media_capture_container_); |
445 | 439 |
446 Shell::Get()->media_controller()->RequestCaptureState(); | 440 Shell::Get()->media_controller()->RequestCaptureState(); |
447 } | 441 } |
448 | 442 |
449 } // namespace tray | 443 } // namespace tray |
450 } // namespace ash | 444 } // namespace ash |
OLD | NEW |