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

Side by Side Diff: chrome/browser/ui/views/avatar_menu_bubble_view.cc

Issue 12388073: Hide the add new profile menu item for managed users. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adress review comment. Created 7 years, 9 months 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_bubble_view.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/avatar_menu_bubble_view.h" 5 #include "chrome/browser/ui/views/avatar_menu_bubble_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/utf_string_conversions.h" 9 #include "base/utf_string_conversions.h"
10 #include "chrome/app/chrome_command_ids.h" 10 #include "chrome/app/chrome_command_ids.h"
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (IsShowing()) 420 if (IsShowing())
421 avatar_bubble_->GetWidget()->Close(); 421 avatar_bubble_->GetWidget()->Close();
422 } 422 }
423 423
424 AvatarMenuBubbleView::AvatarMenuBubbleView( 424 AvatarMenuBubbleView::AvatarMenuBubbleView(
425 views::View* anchor_view, 425 views::View* anchor_view,
426 views::BubbleBorder::ArrowLocation arrow_location, 426 views::BubbleBorder::ArrowLocation arrow_location,
427 const gfx::Rect& anchor_rect, 427 const gfx::Rect& anchor_rect,
428 Browser* browser) 428 Browser* browser)
429 : BubbleDelegateView(anchor_view, arrow_location), 429 : BubbleDelegateView(anchor_view, arrow_location),
430 add_profile_link_(NULL),
431 anchor_rect_(anchor_rect), 430 anchor_rect_(anchor_rect),
432 browser_(browser) { 431 browser_(browser),
432 separator_(NULL),
433 add_profile_link_(NULL) {
433 avatar_menu_model_.reset(new AvatarMenuModel( 434 avatar_menu_model_.reset(new AvatarMenuModel(
434 &g_browser_process->profile_manager()->GetProfileInfoCache(), 435 &g_browser_process->profile_manager()->GetProfileInfoCache(),
435 this, browser_)); 436 this, browser_));
436 } 437 }
437 438
438 AvatarMenuBubbleView::~AvatarMenuBubbleView() { 439 AvatarMenuBubbleView::~AvatarMenuBubbleView() {
439 } 440 }
440 441
441 gfx::Size AvatarMenuBubbleView::GetPreferredSize() { 442 gfx::Size AvatarMenuBubbleView::GetPreferredSize() {
442 if (!add_profile_link_)
443 return gfx::Size();
444
445 int max_width = 0; 443 int max_width = 0;
446 int total_height = 0; 444 int total_height = 0;
447 for (size_t i = 0; i < item_views_.size(); ++i) { 445 for (size_t i = 0; i < item_views_.size(); ++i) {
448 gfx::Size size = item_views_[i]->GetPreferredSize(); 446 gfx::Size size = item_views_[i]->GetPreferredSize();
449 max_width = std::max(max_width, size.width()); 447 max_width = std::max(max_width, size.width());
450 total_height += size.height() + kItemMarginY; 448 total_height += size.height() + kItemMarginY;
451 } 449 }
452 450
453 total_height += kSeparatorPaddingY * 2 + 451 if (add_profile_link_) {
454 separator_->GetPreferredSize().height(); 452 total_height += kSeparatorPaddingY * 2 +
453 separator_->GetPreferredSize().height();
455 454
456 gfx::Size add_profile_size = add_profile_link_->GetPreferredSize(); 455 gfx::Size add_profile_size = add_profile_link_->GetPreferredSize();
457 max_width = std::max(max_width, 456 max_width = std::max(max_width,
458 add_profile_size.width() + profiles::kAvatarIconWidth + kIconMarginX); 457 add_profile_size.width() + profiles::kAvatarIconWidth + kIconMarginX);
459 total_height += add_profile_link_->GetPreferredSize().height(); 458 total_height += add_profile_link_->GetPreferredSize().height();
459 }
460 460
461 const int kBubbleViewMaxWidth = 800; 461 const int kBubbleViewMaxWidth = 800;
462 const int kBubbleViewMinWidth = 175; 462 const int kBubbleViewMinWidth = 175;
463 int total_width = std::min(std::max(max_width, kBubbleViewMinWidth), 463 int total_width = std::min(std::max(max_width, kBubbleViewMinWidth),
464 kBubbleViewMaxWidth); 464 kBubbleViewMaxWidth);
465 return gfx::Size(total_width, total_height); 465 return gfx::Size(total_width, total_height);
466 } 466 }
467 467
468 void AvatarMenuBubbleView::Layout() { 468 void AvatarMenuBubbleView::Layout() {
469 int y = 0; 469 int y = 0;
470 for (size_t i = 0; i < item_views_.size(); ++i) { 470 for (size_t i = 0; i < item_views_.size(); ++i) {
471 views::CustomButton* item_view = item_views_[i]; 471 views::CustomButton* item_view = item_views_[i];
472 int item_height = item_view->GetPreferredSize().height(); 472 int item_height = item_view->GetPreferredSize().height();
473 int item_width = width(); 473 int item_width = width();
474 item_view->SetBounds(0, y, item_width, item_height); 474 item_view->SetBounds(0, y, item_width, item_height);
475 y += item_height + kItemMarginY; 475 y += item_height + kItemMarginY;
476 } 476 }
477 477
478 y += kSeparatorPaddingY; 478 if (add_profile_link_) {
479 int separator_height = separator_->GetPreferredSize().height(); 479 y += kSeparatorPaddingY;
480 separator_->SetBounds(0, y, width(), separator_height); 480 int separator_height = separator_->GetPreferredSize().height();
481 y += kSeparatorPaddingY + separator_height; 481 separator_->SetBounds(0, y, width(), separator_height);
482 y += kSeparatorPaddingY + separator_height;
482 483
483 add_profile_link_->SetBounds(profiles::kAvatarIconWidth + kIconMarginX, y, 484 add_profile_link_->SetBounds(profiles::kAvatarIconWidth + kIconMarginX, y,
484 width(), add_profile_link_->GetPreferredSize().height()); 485 width(), add_profile_link_->GetPreferredSize().height());
486 }
485 } 487 }
486 488
487 bool AvatarMenuBubbleView::AcceleratorPressed( 489 bool AvatarMenuBubbleView::AcceleratorPressed(
488 const ui::Accelerator& accelerator) { 490 const ui::Accelerator& accelerator) {
489 if (accelerator.key_code() != ui::VKEY_DOWN && 491 if (accelerator.key_code() != ui::VKEY_DOWN &&
490 accelerator.key_code() != ui::VKEY_UP) 492 accelerator.key_code() != ui::VKEY_UP)
491 return BubbleDelegateView::AcceleratorPressed(accelerator); 493 return BubbleDelegateView::AcceleratorPressed(accelerator);
492 494
493 if (item_views_.empty()) 495 if (item_views_.empty())
494 return true; 496 return true;
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 for (size_t i = 0; i < avatar_menu_model->GetNumberOfItems(); ++i) { 572 for (size_t i = 0; i < avatar_menu_model->GetNumberOfItems(); ++i) {
571 const AvatarMenuModel::Item& item = avatar_menu_model->GetItemAt(i); 573 const AvatarMenuModel::Item& item = avatar_menu_model->GetItemAt(i);
572 ProfileItemView* item_view = new ProfileItemView(item, this); 574 ProfileItemView* item_view = new ProfileItemView(item, this);
573 item_view->SetAccessibleName(l10n_util::GetStringFUTF16( 575 item_view->SetAccessibleName(l10n_util::GetStringFUTF16(
574 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name)); 576 IDS_PROFILES_SWITCH_TO_PROFILE_ACCESSIBLE_NAME, item.name));
575 item_view->set_focusable(true); 577 item_view->set_focusable(true);
576 AddChildView(item_view); 578 AddChildView(item_view);
577 item_views_.push_back(item_view); 579 item_views_.push_back(item_view);
578 } 580 }
579 581
580 separator_ = new views::Separator(); 582 if (avatar_menu_model_->ShouldShowAddNewProfileLink()) {
581 AddChildView(separator_); 583 separator_ = new views::Separator();
584 AddChildView(separator_);
582 585
583 add_profile_link_ = new views::Link( 586 add_profile_link_ = new views::Link(
584 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK)); 587 l10n_util::GetStringUTF16(IDS_PROFILES_CREATE_NEW_PROFILE_LINK));
585 add_profile_link_->set_listener(this); 588 add_profile_link_->set_listener(this);
586 add_profile_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT); 589 add_profile_link_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
587 add_profile_link_->SetBackgroundColor(color()); 590 add_profile_link_->SetBackgroundColor(color());
588 AddChildView(add_profile_link_); 591 AddChildView(add_profile_link_);
592 }
589 593
590 // If the bubble has already been shown then resize and reposition the bubble. 594 // If the bubble has already been shown then resize and reposition the bubble.
591 Layout(); 595 Layout();
592 if (GetBubbleFrameView()) 596 if (GetBubbleFrameView())
593 SizeToContents(); 597 SizeToContents();
594 } 598 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/avatar_menu_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698