| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "ash/common/login_status.h" | 10 #include "ash/common/login_status.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 ScopedVector<gfx::RenderText> lines_; | 147 ScopedVector<gfx::RenderText> lines_; |
| 148 | 148 |
| 149 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); | 149 DISALLOW_COPY_AND_ASSIGN(PublicAccountUserDetails); |
| 150 }; | 150 }; |
| 151 | 151 |
| 152 PublicAccountUserDetails::PublicAccountUserDetails(int max_width) | 152 PublicAccountUserDetails::PublicAccountUserDetails(int max_width) |
| 153 : learn_more_(NULL) { | 153 : learn_more_(NULL) { |
| 154 const int inner_padding = | 154 const int inner_padding = |
| 155 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; | 155 kTrayPopupPaddingHorizontal - kTrayPopupPaddingBetweenItems; |
| 156 const bool rtl = base::i18n::IsRTL(); | 156 const bool rtl = base::i18n::IsRTL(); |
| 157 SetBorder(views::Border::CreateEmptyBorder(kUserDetailsVerticalPadding, | 157 SetBorder(views::Border::CreateEmptyBorder( |
| 158 rtl ? 0 : inner_padding, | 158 kUserDetailsVerticalPadding, rtl ? 0 : inner_padding, |
| 159 kUserDetailsVerticalPadding, | 159 kUserDetailsVerticalPadding, rtl ? inner_padding : 0)); |
| 160 rtl ? inner_padding : 0)); | |
| 161 | 160 |
| 162 // Retrieve the user's display name and wrap it with markers. | 161 // Retrieve the user's display name and wrap it with markers. |
| 163 // Note that since this is a public account it always has to be the primary | 162 // Note that since this is a public account it always has to be the primary |
| 164 // user. | 163 // user. |
| 165 base::string16 display_name = WmShell::Get() | 164 base::string16 display_name = WmShell::Get() |
| 166 ->GetSessionStateDelegate() | 165 ->GetSessionStateDelegate() |
| 167 ->GetUserInfo(0) | 166 ->GetUserInfo(0) |
| 168 ->GetDisplayName(); | 167 ->GetDisplayName(); |
| 169 base::RemoveChars(display_name, kDisplayNameMark, &display_name); | 168 base::RemoveChars(display_name, kDisplayNameMark, &display_name); |
| 170 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; | 169 display_name = kDisplayNameMark[0] + display_name + kDisplayNameMark[0]; |
| 171 // Retrieve the domain managing the device and wrap it with markers. | 170 // Retrieve the domain managing the device and wrap it with markers. |
| 172 base::string16 domain = base::UTF8ToUTF16( | 171 base::string16 domain = base::UTF8ToUTF16( |
| 173 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); | 172 WmShell::Get()->system_tray_delegate()->GetEnterpriseDomain()); |
| 174 base::RemoveChars(domain, kDisplayNameMark, &domain); | 173 base::RemoveChars(domain, kDisplayNameMark, &domain); |
| 175 base::i18n::WrapStringWithLTRFormatting(&domain); | 174 base::i18n::WrapStringWithLTRFormatting(&domain); |
| 176 // Retrieve the label text, inserting the display name and domain. | 175 // Retrieve the label text, inserting the display name and domain. |
| 177 text_ = l10n_util::GetStringFUTF16( | 176 text_ = l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, |
| 178 IDS_ASH_STATUS_TRAY_PUBLIC_LABEL, display_name, domain); | 177 display_name, domain); |
| 179 | 178 |
| 180 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); | 179 learn_more_ = new views::Link(l10n_util::GetStringUTF16(IDS_ASH_LEARN_MORE)); |
| 181 learn_more_->SetUnderline(false); | 180 learn_more_->SetUnderline(false); |
| 182 learn_more_->set_listener(this); | 181 learn_more_->set_listener(this); |
| 183 AddChildView(learn_more_); | 182 AddChildView(learn_more_); |
| 184 | 183 |
| 185 CalculatePreferredSize(max_width); | 184 CalculatePreferredSize(max_width); |
| 186 } | 185 } |
| 187 | 186 |
| 188 PublicAccountUserDetails::~PublicAccountUserDetails() {} | 187 PublicAccountUserDetails::~PublicAccountUserDetails() {} |
| 189 | 188 |
| 190 void PublicAccountUserDetails::Layout() { | 189 void PublicAccountUserDetails::Layout() { |
| 191 lines_.clear(); | 190 lines_.clear(); |
| 192 const gfx::Rect contents_area = GetContentsBounds(); | 191 const gfx::Rect contents_area = GetContentsBounds(); |
| 193 if (contents_area.IsEmpty()) | 192 if (contents_area.IsEmpty()) |
| 194 return; | 193 return; |
| 195 | 194 |
| 196 // Word-wrap the label text. | 195 // Word-wrap the label text. |
| 197 const gfx::FontList font_list; | 196 const gfx::FontList font_list; |
| 198 std::vector<base::string16> lines; | 197 std::vector<base::string16> lines; |
| 199 gfx::ElideRectangleText(text_, | 198 gfx::ElideRectangleText(text_, font_list, contents_area.width(), |
| 200 font_list, | 199 contents_area.height(), gfx::ELIDE_LONG_WORDS, |
| 201 contents_area.width(), | |
| 202 contents_area.height(), | |
| 203 gfx::ELIDE_LONG_WORDS, | |
| 204 &lines); | 200 &lines); |
| 205 // Loop through the lines, creating a renderer for each. | 201 // Loop through the lines, creating a renderer for each. |
| 206 gfx::Point position = contents_area.origin(); | 202 gfx::Point position = contents_area.origin(); |
| 207 gfx::Range display_name(gfx::Range::InvalidRange()); | 203 gfx::Range display_name(gfx::Range::InvalidRange()); |
| 208 for (std::vector<base::string16>::const_iterator it = lines.begin(); | 204 for (std::vector<base::string16>::const_iterator it = lines.begin(); |
| 209 it != lines.end(); | 205 it != lines.end(); ++it) { |
| 210 ++it) { | |
| 211 gfx::RenderText* line = gfx::RenderText::CreateInstance(); | 206 gfx::RenderText* line = gfx::RenderText::CreateInstance(); |
| 212 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); | 207 line->SetDirectionalityMode(gfx::DIRECTIONALITY_FROM_UI); |
| 213 line->SetText(*it); | 208 line->SetText(*it); |
| 214 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); | 209 const gfx::Size size(contents_area.width(), line->GetStringSize().height()); |
| 215 line->SetDisplayRect(gfx::Rect(position, size)); | 210 line->SetDisplayRect(gfx::Rect(position, size)); |
| 216 position.set_y(position.y() + size.height()); | 211 position.set_y(position.y() + size.height()); |
| 217 | 212 |
| 218 // Set the default text color for the line. | 213 // Set the default text color for the line. |
| 219 line->SetColor(kPublicAccountUserCardTextColor); | 214 line->SetColor(kPublicAccountUserCardTextColor); |
| 220 | 215 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 253 } |
| 259 learn_more_->SetBoundsRect(learn_more_bounds); | 254 learn_more_->SetBoundsRect(learn_more_bounds); |
| 260 } | 255 } |
| 261 | 256 |
| 262 gfx::Size PublicAccountUserDetails::GetPreferredSize() const { | 257 gfx::Size PublicAccountUserDetails::GetPreferredSize() const { |
| 263 return preferred_size_; | 258 return preferred_size_; |
| 264 } | 259 } |
| 265 | 260 |
| 266 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { | 261 void PublicAccountUserDetails::OnPaint(gfx::Canvas* canvas) { |
| 267 for (ScopedVector<gfx::RenderText>::const_iterator it = lines_.begin(); | 262 for (ScopedVector<gfx::RenderText>::const_iterator it = lines_.begin(); |
| 268 it != lines_.end(); | 263 it != lines_.end(); ++it) { |
| 269 ++it) { | |
| 270 (*it)->Draw(canvas); | 264 (*it)->Draw(canvas); |
| 271 } | 265 } |
| 272 views::View::OnPaint(canvas); | 266 views::View::OnPaint(canvas); |
| 273 } | 267 } |
| 274 | 268 |
| 275 void PublicAccountUserDetails::LinkClicked(views::Link* source, | 269 void PublicAccountUserDetails::LinkClicked(views::Link* source, |
| 276 int event_flags) { | 270 int event_flags) { |
| 277 DCHECK_EQ(source, learn_more_); | 271 DCHECK_EQ(source, learn_more_); |
| 278 WmShell::Get()->system_tray_delegate()->ShowPublicAccountInfo(); | 272 WmShell::Get()->system_tray_delegate()->ShowPublicAccountInfo(); |
| 279 } | 273 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 290 max_allowed_width - insets.width()); | 284 max_allowed_width - insets.width()); |
| 291 // Do a binary search for the minimum width that ensures no more than three | 285 // Do a binary search for the minimum width that ensures no more than three |
| 292 // lines are needed. The lower bound is the minimum of the current bubble | 286 // lines are needed. The lower bound is the minimum of the current bubble |
| 293 // width and the width of the link (as no wrapping is permitted inside the | 287 // width and the width of the link (as no wrapping is permitted inside the |
| 294 // link). The upper bound is the maximum of the largest allowed bubble width | 288 // link). The upper bound is the maximum of the largest allowed bubble width |
| 295 // and the sum of the label text and link widths when put on a single line. | 289 // and the sum of the label text and link widths when put on a single line. |
| 296 std::vector<base::string16> lines; | 290 std::vector<base::string16> lines; |
| 297 while (min_width < max_width) { | 291 while (min_width < max_width) { |
| 298 lines.clear(); | 292 lines.clear(); |
| 299 const int width = (min_width + max_width) / 2; | 293 const int width = (min_width + max_width) / 2; |
| 300 const bool too_narrow = gfx::ElideRectangleText(text_, | 294 const bool too_narrow = |
| 301 font_list, | 295 gfx::ElideRectangleText(text_, font_list, width, INT_MAX, |
| 302 width, | 296 gfx::TRUNCATE_LONG_WORDS, &lines) != 0; |
| 303 INT_MAX, | |
| 304 gfx::TRUNCATE_LONG_WORDS, | |
| 305 &lines) != 0; | |
| 306 int line_count = lines.size(); | 297 int line_count = lines.size(); |
| 307 if (!too_narrow && line_count == 3 && | 298 if (!too_narrow && line_count == 3 && |
| 308 width - gfx::GetStringWidth(lines.back(), font_list) <= | 299 width - gfx::GetStringWidth(lines.back(), font_list) <= |
| 309 space_width + link_size.width()) | 300 space_width + link_size.width()) |
| 310 ++line_count; | 301 ++line_count; |
| 311 if (too_narrow || line_count > 3) | 302 if (too_narrow || line_count > 3) |
| 312 min_width = width + 1; | 303 min_width = width + 1; |
| 313 else | 304 else |
| 314 max_width = width; | 305 max_width = width; |
| 315 } | 306 } |
| 316 | 307 |
| 317 // Calculate the corresponding height and set the preferred size. | 308 // Calculate the corresponding height and set the preferred size. |
| 318 lines.clear(); | 309 lines.clear(); |
| 319 gfx::ElideRectangleText( | 310 gfx::ElideRectangleText(text_, font_list, min_width, INT_MAX, |
| 320 text_, font_list, min_width, INT_MAX, gfx::TRUNCATE_LONG_WORDS, &lines); | 311 gfx::TRUNCATE_LONG_WORDS, &lines); |
| 321 int line_count = lines.size(); | 312 int line_count = lines.size(); |
| 322 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= | 313 if (min_width - gfx::GetStringWidth(lines.back(), font_list) <= |
| 323 space_width + link_size.width()) { | 314 space_width + link_size.width()) { |
| 324 ++line_count; | 315 ++line_count; |
| 325 } | 316 } |
| 326 const int line_height = font_list.GetHeight(); | 317 const int line_height = font_list.GetHeight(); |
| 327 const int link_extra_height = std::max( | 318 const int link_extra_height = std::max( |
| 328 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); | 319 link_size.height() - learn_more_->GetInsets().top() - line_height, 0); |
| 329 preferred_size_ = | 320 preferred_size_ = |
| 330 gfx::Size(min_width + insets.width(), | 321 gfx::Size(min_width + insets.width(), |
| 331 line_count * line_height + link_extra_height + insets.height()); | 322 line_count * line_height + link_extra_height + insets.height()); |
| 332 } | 323 } |
| 333 | 324 |
| 334 } // namespace | 325 } // namespace |
| 335 | 326 |
| 336 UserCardView::UserCardView(LoginStatus login_status, | 327 UserCardView::UserCardView(LoginStatus login_status, |
| 337 int max_width, | 328 int max_width, |
| 338 int user_index) { | 329 int user_index) { |
| 339 SetLayoutManager(new views::BoxLayout( | 330 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, |
| 340 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); | 331 kTrayPopupPaddingBetweenItems)); |
| 341 if (login_status == LoginStatus::PUBLIC) { | 332 if (login_status == LoginStatus::PUBLIC) { |
| 342 AddPublicModeUserContent(max_width); | 333 AddPublicModeUserContent(max_width); |
| 343 } else { | 334 } else { |
| 344 AddUserContent(login_status, user_index); | 335 AddUserContent(login_status, user_index); |
| 345 } | 336 } |
| 346 } | 337 } |
| 347 | 338 |
| 348 UserCardView::~UserCardView() {} | 339 UserCardView::~UserCardView() {} |
| 349 | 340 |
| 350 void UserCardView::GetAccessibleState(ui::AXViewState* state) { | 341 void UserCardView::GetAccessibleState(ui::AXViewState* state) { |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 451 } else { | 442 } else { |
| 452 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); | 443 SessionStateDelegate* delegate = WmShell::Get()->GetSessionStateDelegate(); |
| 453 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(), | 444 icon->SetImage(delegate->GetUserInfo(user_index)->GetImage(), |
| 454 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); | 445 gfx::Size(kTrayAvatarSize, kTrayAvatarSize)); |
| 455 } | 446 } |
| 456 return icon; | 447 return icon; |
| 457 } | 448 } |
| 458 | 449 |
| 459 } // namespace tray | 450 } // namespace tray |
| 460 } // namespace ash | 451 } // namespace ash |
| OLD | NEW |