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

Side by Side Diff: ash/common/system/user/user_view.cc

Issue 2480813003: Reduce views::Border creation verbosity by promoting factory functions (Closed)
Patch Set: fix bad merge Created 4 years, 1 month 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
« no previous file with comments | « ash/common/system/user/user_card_view.cc ('k') | ash/common/wm/overview/window_selector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/common/system/user/user_view.h" 5 #include "ash/common/system/user/user_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 9
10 #include "ash/common/material_design/material_design_controller.h" 10 #include "ash/common/material_design/material_design_controller.h"
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 add_user_ = new views::View; 198 add_user_ = new views::View;
199 add_user_->SetLayoutManager(new views::BoxLayout( 199 add_user_->SetLayoutManager(new views::BoxLayout(
200 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems)); 200 views::BoxLayout::kHorizontal, 0, 0, kTrayPopupPaddingBetweenItems));
201 AddChildViewAt(add_user_, 0); 201 AddChildViewAt(add_user_, 0);
202 202
203 // Add the icon which is also the anchor for messages. 203 // Add the icon which is also the anchor for messages.
204 if (UseMd()) { 204 if (UseMd()) {
205 views::ImageView* icon = new views::ImageView(); 205 views::ImageView* icon = new views::ImageView();
206 icon->SetImage( 206 icon->SetImage(
207 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor)); 207 gfx::CreateVectorIcon(kSystemMenuNewUserIcon, kMenuIconColor));
208 icon->SetBorder(views::Border::CreateEmptyBorder(gfx::Insets( 208 icon->SetBorder(views::CreateEmptyBorder(gfx::Insets(
209 (GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH) - 209 (GetTrayConstant(TRAY_POPUP_ITEM_MAIN_IMAGE_CONTAINER_WIDTH) -
210 icon->GetPreferredSize().width()) / 210 icon->GetPreferredSize().width()) /
211 2))); 211 2)));
212 anchor_ = icon; 212 anchor_ = icon;
213 add_user_->AddChildView(icon); 213 add_user_->AddChildView(icon);
214 } else { 214 } else {
215 add_user_->SetBorder(views::Border::CreateEmptyBorder( 215 add_user_->SetBorder(
216 0, kTrayUserTileHoverBorderInset, 0, 0)); 216 views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
217 RoundedImageView* icon = 217 RoundedImageView* icon =
218 new RoundedImageView(kTrayRoundedBorderRadius, true); 218 new RoundedImageView(kTrayRoundedBorderRadius, true);
219 anchor_ = icon; 219 anchor_ = icon;
220 icon->SetImage(*ui::ResourceBundle::GetSharedInstance() 220 icon->SetImage(*ui::ResourceBundle::GetSharedInstance()
221 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER) 221 .GetImageNamed(IDR_AURA_UBER_TRAY_ADD_MULTIPROFILE_USER)
222 .ToImageSkia(), 222 .ToImageSkia(),
223 gfx::Size(kTrayItemSize, kTrayItemSize)); 223 gfx::Size(kTrayItemSize, kTrayItemSize));
224 add_user_->AddChildView(icon); 224 add_user_->AddChildView(icon);
225 } 225 }
226 226
(...skipping 28 matching lines...) Expand all
255 AddUserCard(login); 255 AddUserCard(login);
256 256
257 if (UseMd()) { 257 if (UseMd()) {
258 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal, 258 auto layout = new views::BoxLayout(views::BoxLayout::kHorizontal,
259 kMenuExtraMarginFromLeftEdge, 0, 0); 259 kMenuExtraMarginFromLeftEdge, 0, 0);
260 SetLayoutManager(layout); 260 SetLayoutManager(layout);
261 layout->set_cross_axis_alignment( 261 layout->set_cross_axis_alignment(
262 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); 262 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER);
263 layout->SetFlexForView(user_card_view_, 1); 263 layout->SetFlexForView(user_card_view_, 1);
264 int separator_width = user_index_ == 0 ? kSeparatorWidth : 0; 264 int separator_width = user_index_ == 0 ? kSeparatorWidth : 0;
265 SetBorder(views::Border::CreatePaddedBorder( 265 SetBorder(views::CreatePaddedBorder(
266 views::Border::CreateSolidSidedBorder(0, 0, separator_width, 0, 266 views::CreateSolidSidedBorder(0, 0, separator_width, 0,
267 kSeparatorColor), 267 kSeparatorColor),
268 gfx::Insets(kMenuSeparatorVerticalPadding, 0, 268 gfx::Insets(kMenuSeparatorVerticalPadding, 0,
269 kMenuSeparatorVerticalPadding - separator_width, 0))); 269 kMenuSeparatorVerticalPadding - separator_width, 0)));
270 } 270 }
271 } 271 }
272 272
273 UserView::~UserView() { 273 UserView::~UserView() {
274 RemoveAddUserMenuOption(); 274 RemoveAddUserMenuOption();
275 } 275 }
276 276
277 void UserView::MouseMovedOutOfHost() { 277 void UserView::MouseMovedOutOfHost() {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
404 } 404 }
405 405
406 void UserView::AddLogoutButton(LoginStatus login) { 406 void UserView::AddLogoutButton(LoginStatus login) {
407 const base::string16 title = 407 const base::string16 title =
408 user::GetLocalizedSignOutStringForStatus(login, true); 408 user::GetLocalizedSignOutStringForStatus(login, true);
409 auto* logout_button = CreateTrayPopupBorderlessButton(this, title); 409 auto* logout_button = CreateTrayPopupBorderlessButton(this, title);
410 logout_button->SetAccessibleName(title); 410 logout_button->SetAccessibleName(title);
411 logout_button_ = logout_button; 411 logout_button_ = logout_button;
412 if (UseMd()) { 412 if (UseMd()) {
413 views::View* separator = CreateVerticalSeparator(); 413 views::View* separator = CreateVerticalSeparator();
414 separator->SetBorder(views::Border::CreateEmptyBorder( 414 separator->SetBorder(views::CreateEmptyBorder(
415 gfx::Insets(0, 0, 0, kTrayPopupLabelHorizontalPadding))); 415 gfx::Insets(0, 0, 0, kTrayPopupLabelHorizontalPadding)));
416 AddChildView(separator); 416 AddChildView(separator);
417 } else if (login == LoginStatus::PUBLIC) { 417 } else if (login == LoginStatus::PUBLIC) {
418 // In public account mode, the logout button border has a custom color. 418 // In public account mode, the logout button border has a custom color.
419 std::unique_ptr<TrayPopupLabelButtonBorder> border( 419 std::unique_ptr<TrayPopupLabelButtonBorder> border(
420 new TrayPopupLabelButtonBorder()); 420 new TrayPopupLabelButtonBorder());
421 border->SetPainter(false, views::Button::STATE_NORMAL, 421 border->SetPainter(false, views::Button::STATE_NORMAL,
422 views::Painter::CreateImageGridPainter( 422 views::Painter::CreateImageGridPainter(
423 kPublicAccountLogoutButtonBorderImagesNormal)); 423 kPublicAccountLogoutButtonBorderImagesNormal));
424 border->SetPainter(false, views::Button::STATE_HOVERED, 424 border->SetPainter(false, views::Button::STATE_HOVERED,
425 views::Painter::CreateImageGridPainter( 425 views::Painter::CreateImageGridPainter(
426 kPublicAccountLogoutButtonBorderImagesHovered)); 426 kPublicAccountLogoutButtonBorderImagesHovered));
427 border->SetPainter(false, views::Button::STATE_PRESSED, 427 border->SetPainter(false, views::Button::STATE_PRESSED,
428 views::Painter::CreateImageGridPainter( 428 views::Painter::CreateImageGridPainter(
429 kPublicAccountLogoutButtonBorderImagesHovered)); 429 kPublicAccountLogoutButtonBorderImagesHovered));
430 logout_button_->SetBorder(std::move(border)); 430 logout_button_->SetBorder(std::move(border));
431 } 431 }
432 AddChildView(logout_button_); 432 AddChildView(logout_button_);
433 } 433 }
434 434
435 void UserView::AddUserCard(LoginStatus login) { 435 void UserView::AddUserCard(LoginStatus login) {
436 if (UseMd()) 436 if (UseMd())
437 return AddUserCardMd(login); 437 return AddUserCardMd(login);
438 438
439 // Add padding around the panel. 439 // Add padding around the panel.
440 const int kSidePadding = kTrayPopupPaddingHorizontal; 440 const int kSidePadding = kTrayPopupPaddingHorizontal;
441 SetBorder(views::Border::CreateEmptyBorder( 441 SetBorder(views::CreateEmptyBorder(
442 kTrayPopupUserCardVerticalPadding, kSidePadding, 442 kTrayPopupUserCardVerticalPadding, kSidePadding,
443 kTrayPopupUserCardVerticalPadding, kSidePadding)); 443 kTrayPopupUserCardVerticalPadding, kSidePadding));
444 444
445 views::TrayBubbleView* bubble_view = 445 views::TrayBubbleView* bubble_view =
446 owner_->system_tray()->GetSystemBubble()->bubble_view(); 446 owner_->system_tray()->GetSystemBubble()->bubble_view();
447 int max_card_width = bubble_view->GetMaximumSize().width() - 447 int max_card_width = bubble_view->GetMaximumSize().width() -
448 (2 * kSidePadding + kTrayPopupPaddingBetweenItems); 448 (2 * kSidePadding + kTrayPopupPaddingBetweenItems);
449 if (logout_button_) 449 if (logout_button_)
450 max_card_width -= logout_button_->GetPreferredSize().width(); 450 max_card_width -= logout_button_->GetPreferredSize().width();
451 user_card_view_ = new UserCardView(login, max_card_width, user_index_); 451 user_card_view_ = new UserCardView(login, max_card_width, user_index_);
452 // The entry is clickable when no system modal dialog is open and the multi 452 // The entry is clickable when no system modal dialog is open and the multi
453 // profile option is active. 453 // profile option is active.
454 bool clickable = !WmShell::Get()->IsSystemModalWindowOpen() && 454 bool clickable = !WmShell::Get()->IsSystemModalWindowOpen() &&
455 IsMultiProfileSupportedAndUserActive(); 455 IsMultiProfileSupportedAndUserActive();
456 if (clickable) { 456 if (clickable) {
457 // To allow the border to start before the icon, reduce the size before and 457 // To allow the border to start before the icon, reduce the size before and
458 // add an inset to the icon to get the spacing. 458 // add an inset to the icon to get the spacing.
459 if (!user_index_) { 459 if (!user_index_) {
460 SetBorder(views::Border::CreateEmptyBorder( 460 SetBorder(views::CreateEmptyBorder(
461 kTrayPopupUserCardVerticalPadding, 461 kTrayPopupUserCardVerticalPadding,
462 kSidePadding - kTrayUserTileHoverBorderInset, 462 kSidePadding - kTrayUserTileHoverBorderInset,
463 kTrayPopupUserCardVerticalPadding, kSidePadding)); 463 kTrayPopupUserCardVerticalPadding, kSidePadding));
464 user_card_view_->SetBorder(views::Border::CreateEmptyBorder( 464 user_card_view_->SetBorder(
465 0, kTrayUserTileHoverBorderInset, 0, 0)); 465 views::CreateEmptyBorder(0, kTrayUserTileHoverBorderInset, 0, 0));
466 } 466 }
467 gfx::Insets insets = gfx::Insets(1, 1, 1, 1); 467 gfx::Insets insets = gfx::Insets(1, 1, 1, 1);
468 views::View* contents_view = user_card_view_; 468 views::View* contents_view = user_card_view_;
469 if (user_index_) { 469 if (user_index_) {
470 // Since the activation border needs to be drawn around the tile, we 470 // Since the activation border needs to be drawn around the tile, we
471 // have to put the tile into another view which fills the menu panel, 471 // have to put the tile into another view which fills the menu panel,
472 // but keeping the offsets of the content. 472 // but keeping the offsets of the content.
473 contents_view = new views::View(); 473 contents_view = new views::View();
474 contents_view->SetBorder(views::Border::CreateEmptyBorder( 474 contents_view->SetBorder(views::CreateEmptyBorder(
475 kTrayPopupUserCardVerticalPadding, kSidePadding, 475 kTrayPopupUserCardVerticalPadding, kSidePadding,
476 kTrayPopupUserCardVerticalPadding, kSidePadding)); 476 kTrayPopupUserCardVerticalPadding, kSidePadding));
477 contents_view->SetLayoutManager(new views::FillLayout()); 477 contents_view->SetLayoutManager(new views::FillLayout());
478 SetBorder(nullptr); 478 SetBorder(nullptr);
479 contents_view->AddChildView(user_card_view_); 479 contents_view->AddChildView(user_card_view_);
480 insets = gfx::Insets(1, 1, 1, 3); 480 insets = gfx::Insets(1, 1, 1, 3);
481 } 481 }
482 bool highlight = !UseMd() && user_index_ == 0; 482 bool highlight = !UseMd() && user_index_ == 0;
483 auto* button = new ButtonFromView(contents_view, this, highlight, insets); 483 auto* button = new ButtonFromView(contents_view, this, highlight, insets);
484 user_card_view_ = button; 484 user_card_view_ = button;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
560 // system menu). The top half of the widget will be transparent to allow 560 // system menu). The top half of the widget will be transparent to allow
561 // the active user to show through. 561 // the active user to show through.
562 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 562 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
563 bounds.set_width(bounds.width() + kSeparatorWidth); 563 bounds.set_width(bounds.width() + kSeparatorWidth);
564 int row_height = bounds.height(); 564 int row_height = bounds.height();
565 bounds.set_height(row_height * 2); 565 bounds.set_height(row_height * 2);
566 add_menu_option_->SetBounds(bounds); 566 add_menu_option_->SetBounds(bounds);
567 567
568 views::View* container = new AddUserWidgetContents( 568 views::View* container = new AddUserWidgetContents(
569 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this))); 569 base::Bind(&UserView::RemoveAddUserMenuOption, base::Unretained(this)));
570 container->SetBorder(views::Border::CreatePaddedBorder( 570 container->SetBorder(views::CreatePaddedBorder(
571 views::Border::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth, 571 views::CreateSolidSidedBorder(0, 0, 0, kSeparatorWidth,
572 kBackgroundColor), 572 kBackgroundColor),
573 gfx::Insets(row_height, 0, 0, 0))); 573 gfx::Insets(row_height, 0, 0, 0)));
574 container->SetLayoutManager(new views::FillLayout()); 574 container->SetLayoutManager(new views::FillLayout());
575 container->AddChildView(button); 575 container->AddChildView(button);
576 add_menu_option_->SetContentsView(container); 576 add_menu_option_->SetContentsView(container);
577 } else { 577 } else {
578 add_menu_option_->SetOpacity(1.f); 578 add_menu_option_->SetOpacity(1.f);
579 add_menu_option_->SetContentsView(button); 579 add_menu_option_->SetContentsView(button);
580 // Position it below our user card. 580 // Position it below our user card.
581 gfx::Rect bounds = user_card_view_->GetBoundsInScreen(); 581 gfx::Rect bounds = user_card_view_->GetBoundsInScreen();
582 bounds.set_y(bounds.y() + bounds.height()); 582 bounds.set_y(bounds.y() + bounds.height());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
640 focus_manager_ = nullptr; 640 focus_manager_ = nullptr;
641 if (user_card_view_->GetFocusManager()) 641 if (user_card_view_->GetFocusManager())
642 user_card_view_->GetFocusManager()->ClearFocus(); 642 user_card_view_->GetFocusManager()->ClearFocus();
643 popup_message_.reset(); 643 popup_message_.reset();
644 mouse_watcher_.reset(); 644 mouse_watcher_.reset();
645 add_menu_option_.reset(); 645 add_menu_option_.reset();
646 } 646 }
647 647
648 } // namespace tray 648 } // namespace tray
649 } // namespace ash 649 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/user/user_card_view.cc ('k') | ash/common/wm/overview/window_selector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698