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

Side by Side Diff: chrome/browser/ui/cocoa/profiles/profile_chooser_controller.mm

Issue 323143004: [Mac] Misc fixes for the new avatar bubble (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix custom cell Created 6 years, 6 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
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 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h" 7 #import "chrome/browser/ui/cocoa/profiles/profile_chooser_controller.h"
8 8
9 #include "base/mac/bundle_locations.h" 9 #include "base/mac/bundle_locations.h"
10 #include "base/prefs/pref_service.h" 10 #include "base/prefs/pref_service.h"
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // The observer can be removed both when closing the browser, and by just 325 // The observer can be removed both when closing the browser, and by just
326 // closing the avatar bubble. However, in the case of closing the browser, 326 // closing the avatar bubble. However, in the case of closing the browser,
327 // the avatar bubble will also be closed afterwards, resulting in a second 327 // the avatar bubble will also be closed afterwards, resulting in a second
328 // attempt to remove the observer. This ensures the observer is only 328 // attempt to remove the observer. This ensures the observer is only
329 // removed once. 329 // removed once.
330 bool token_observer_registered_; 330 bool token_observer_registered_;
331 331
332 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge); 332 DISALLOW_COPY_AND_ASSIGN(ActiveProfileObserverBridge);
333 }; 333 };
334 334
335 // Custom button cell that adds a left padding before the button image, and
336 // a custom spacing between the button image and title.
337 @interface CustomPaddingImageButtonCell : NSButtonCell {
338 @private
339 // Padding added to the left margin of the button.
340 int leftMarginSpacing_;
341 // Spacing between the cell image and title.
342 int imageTitleSpacing_;
343 }
344
345 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
346 imageTitleSpacing:(int)imageTitleSpacing;
347 @end
348
349 @implementation CustomPaddingImageButtonCell
350 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
351 imageTitleSpacing:(int)imageTitleSpacing {
352 if ((self = [super init])) {
353 leftMarginSpacing_ = leftMarginSpacing;
354 imageTitleSpacing_ = imageTitleSpacing;
355 }
356 return self;
357 }
358
359 - (NSRect)drawTitle:(NSAttributedString*)title
360 withFrame:(NSRect)frame
361 inView:(NSView*)controlView {
362 frame.origin.x += leftMarginSpacing_;
groby-ooo-7-16 2014/06/16 20:49:38 nit: Might want to use NSDivideRect for simplicity
noms (inactive) 2014/06/17 14:11:19 NSDivideRect is magical!!! <3 Done. On 2014/06/16
363 frame.size.width -= leftMarginSpacing_;
364
365 // The title frame origin isn't aware of the left margin spacing added
366 // in -drawImage, so it must be added when drawing the title as well.
367 if ([self imagePosition] == NSImageLeft) {
368 frame.origin.x += imageTitleSpacing_;
groby-ooo-7-16 2014/06/16 20:49:38 ditto
noms (inactive) 2014/06/17 14:11:19 Done.
369 frame.size.width -= imageTitleSpacing_;
370 }
371 return [super drawTitle:title withFrame:frame inView:controlView];
372 }
373
374 - (void)drawImage:(NSImage*)image
375 withFrame:(NSRect)frame
376 inView:(NSView*)controlView {
377 if ([self imagePosition] == NSImageLeft)
378 frame.origin.x = leftMarginSpacing_;
379 [super drawImage:image withFrame:frame inView:controlView];
380 }
381
382 - (NSSize)cellSize {
383 NSSize buttonSize = [super cellSize];
384 buttonSize.width += leftMarginSpacing_;
385 if ([self imagePosition] == NSImageLeft)
386 buttonSize.width += imageTitleSpacing_;
387 return buttonSize;
388 }
389
390 @end
391
335 // A custom button that has a transparent backround. 392 // A custom button that has a transparent backround.
336 @interface TransparentBackgroundButton : NSButton 393 @interface TransparentBackgroundButton : NSButton
337 @end 394 @end
338 395
339 @implementation TransparentBackgroundButton 396 @implementation TransparentBackgroundButton
340 - (id)initWithFrame:(NSRect)frameRect { 397 - (id)initWithFrame:(NSRect)frameRect {
341 if ((self = [super initWithFrame:frameRect])) { 398 if ((self = [super initWithFrame:frameRect])) {
342 [self setBordered:NO]; 399 [self setBordered:NO];
343 [self setFont:[NSFont labelFontOfSize:kTextFontSize]]; 400 [self setFont:[NSFont labelFontOfSize:kTextFontSize]];
344 [self setButtonType:NSMomentaryChangeButton]; 401 [self setButtonType:NSMomentaryChangeButton];
345 } 402 }
346 return self; 403 return self;
347 } 404 }
348 405
349 - (void)drawRect:(NSRect)dirtyRect { 406 - (void)drawRect:(NSRect)dirtyRect {
350 NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:1 alpha:0.4f]; 407 NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:1 alpha:0.6f];
351 [backgroundColor setFill]; 408 [backgroundColor setFill];
352 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceAtop); 409 NSRectFillUsingOperation(dirtyRect, NSCompositeSourceAtop);
353 [super drawRect:dirtyRect]; 410 [super drawRect:dirtyRect];
354 } 411 }
355 @end 412 @end
356 413
357 // A custom image control that shows a "Change" button when moused over. 414 // A custom image control that shows a "Change" button when moused over.
358 @interface EditableProfilePhoto : NSImageView { 415 @interface EditableProfilePhoto : NSImageView {
359 @private 416 @private
360 AvatarMenu* avatarMenu_; // Weak; Owned by ProfileChooserController. 417 AvatarMenu* avatarMenu_; // Weak; Owned by ProfileChooserController.
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 [button setImage:ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed( 507 [button setImage:ui::ResourceBundle::GetSharedInstance().GetNativeImageNamed(
451 IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()]; 508 IDR_ICON_PROFILES_EDIT_CAMERA).AsNSImage()];
452 [button setImagePosition:NSImageOnly]; 509 [button setImagePosition:NSImageOnly];
453 [button setTarget:self]; 510 [button setTarget:self];
454 [button setAction:@selector(editPhoto:)]; 511 [button setAction:@selector(editPhoto:)];
455 return button; 512 return button;
456 } 513 }
457 @end 514 @end
458 515
459 // A custom text control that turns into a textfield for editing when clicked. 516 // A custom text control that turns into a textfield for editing when clicked.
460 @interface EditableProfileNameButton : HoverImageButton<NSTextFieldDelegate> { 517 @interface EditableProfileNameButton : HoverImageButton {
461 @private 518 @private
462 base::scoped_nsobject<NSTextField> profileNameTextField_; 519 base::scoped_nsobject<NSTextField> profileNameTextField_;
463 Profile* profile_; // Weak. 520 Profile* profile_; // Weak.
464 ProfileChooserController* controller_; 521 ProfileChooserController* controller_;
465 } 522 }
466 523
467 - (id)initWithFrame:(NSRect)frameRect 524 - (id)initWithFrame:(NSRect)frameRect
468 profile:(Profile*)profile 525 profile:(Profile*)profile
469 profileName:(NSString*)profileName 526 profileName:(NSString*)profileName
470 editingAllowed:(BOOL)editingAllowed 527 editingAllowed:(BOOL)editingAllowed
471 withController:(ProfileChooserController*)controller; 528 withController:(ProfileChooserController*)controller;
472 529
473 // Called when the button is clicked. 530 // Called when the button is clicked.
474 - (void)showEditableView:(id)sender; 531 - (void)showEditableView:(id)sender;
475 532
476 // Called when the user presses "Enter" in the textfield. 533 // Called when enter is pressed in the text field.
477 - (void)controlTextDidEndEditing:(NSNotification *)obj; 534 - (void)saveProfileName:(id)sender;
535
478 @end 536 @end
479 537
480 @implementation EditableProfileNameButton 538 @implementation EditableProfileNameButton
481 - (id)initWithFrame:(NSRect)frameRect 539 - (id)initWithFrame:(NSRect)frameRect
482 profile:(Profile*)profile 540 profile:(Profile*)profile
483 profileName:(NSString*)profileName 541 profileName:(NSString*)profileName
484 editingAllowed:(BOOL)editingAllowed 542 editingAllowed:(BOOL)editingAllowed
485 withController:(ProfileChooserController*)controller { 543 withController:(ProfileChooserController*)controller {
486 if ((self = [super initWithFrame:frameRect])) { 544 if ((self = [super initWithFrame:frameRect])) {
487 profile_ = profile; 545 profile_ = profile;
488 controller_ = controller; 546 controller_ = controller;
489 547
490 [self setBordered:NO];
491 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]];
492 [self setAlignment:NSCenterTextAlignment];
493 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail];
494 [self setTitle:profileName];
495
496 if (editingAllowed) { 548 if (editingAllowed) {
497 // Show an "edit" pencil icon when hovering over. In the default state, 549 // Show an "edit" pencil icon when hovering over. In the default state,
498 // we need to create an empty placeholder of the correct size, so that 550 // we need to create an empty placeholder of the correct size, so that
499 // the text doesn't jump around when the hovered icon appears. 551 // the text doesn't jump around when the hovered icon appears.
500 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 552 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
501 NSImage* hoverImage = rb->GetNativeImageNamed( 553 NSImage* hoverImage = rb->GetNativeImageNamed(
502 IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage(); 554 IDR_ICON_PROFILES_EDIT_HOVER).AsNSImage();
555
556 // In order to center the button title, we need to add a left padding of
557 // the same width as the pencil icon.
558 base::scoped_nsobject<CustomPaddingImageButtonCell> cell(
559 [[CustomPaddingImageButtonCell alloc]
560 initWithLeftMarginSpacing:[hoverImage size].width
561 imageTitleSpacing:0]);
562 [self setCell:cell.get()];
563
503 NSImage* placeholder = [[NSImage alloc] initWithSize:[hoverImage size]]; 564 NSImage* placeholder = [[NSImage alloc] initWithSize:[hoverImage size]];
504 [self setDefaultImage:placeholder]; 565 [self setDefaultImage:placeholder];
505 [self setHoverImage:hoverImage]; 566 [self setHoverImage:hoverImage];
506 [self setAlternateImage: 567 [self setAlternateImage:
507 rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_PRESSED).AsNSImage()]; 568 rb->GetNativeImageNamed(IDR_ICON_PROFILES_EDIT_PRESSED).AsNSImage()];
508 [self setImagePosition:NSImageRight]; 569 [self setImagePosition:NSImageRight];
509 [self setTarget:self]; 570 [self setTarget:self];
510 [self setAction:@selector(showEditableView:)]; 571 [self setAction:@selector(showEditableView:)];
511 572
512 // We need to subtract the width of the bezel from the frame rect, so that 573 // We need to subtract the width of the bezel from the frame rect, so that
513 // the textfield can take the exact same space as the button. 574 // the textfield can take the exact same space as the button.
514 frameRect.size.height -= 2 * kBezelThickness; 575 frameRect.size.height -= 2 * kBezelThickness;
515 frameRect.origin = NSMakePoint(0, kBezelThickness); 576 frameRect.origin = NSMakePoint(0, kBezelThickness);
516 profileNameTextField_.reset( 577 profileNameTextField_.reset(
517 [[NSTextField alloc] initWithFrame:frameRect]); 578 [[NSTextField alloc] initWithFrame:frameRect]);
518 [profileNameTextField_ setStringValue:profileName]; 579 [profileNameTextField_ setStringValue:profileName];
519 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]]; 580 [profileNameTextField_ setFont:[NSFont labelFontOfSize:kTitleFontSize]];
520 [profileNameTextField_ setEditable:YES]; 581 [profileNameTextField_ setEditable:YES];
521 [profileNameTextField_ setDrawsBackground:YES]; 582 [profileNameTextField_ setDrawsBackground:YES];
522 [profileNameTextField_ setBezeled:YES]; 583 [profileNameTextField_ setBezeled:YES];
523 [profileNameTextField_ setAlignment:NSCenterTextAlignment]; 584 [profileNameTextField_ setAlignment:NSCenterTextAlignment];
524 [[profileNameTextField_ cell] setWraps:NO]; 585 [[profileNameTextField_ cell] setWraps:NO];
525 [[profileNameTextField_ cell] setLineBreakMode: 586 [[profileNameTextField_ cell] setLineBreakMode:
526 NSLineBreakByTruncatingTail]; 587 NSLineBreakByTruncatingTail];
527 [profileNameTextField_ setDelegate:self];
528 [self addSubview:profileNameTextField_]; 588 [self addSubview:profileNameTextField_];
589 [profileNameTextField_ setTarget:self];
590 [profileNameTextField_ setAction:@selector(saveProfileName:)];
529 591
530 // Hide the textfield until the user clicks on the button. 592 // Hide the textfield until the user clicks on the button.
531 [profileNameTextField_ setHidden:YES]; 593 [profileNameTextField_ setHidden:YES];
532 } 594 }
595
596 [self setBordered:NO];
597 [self setFont:[NSFont labelFontOfSize:kTitleFontSize]];
598 [self setAlignment:NSCenterTextAlignment];
599 [[self cell] setLineBreakMode:NSLineBreakByTruncatingTail];
600 [self setTitle:profileName];
533 } 601 }
534 return self; 602 return self;
535 } 603 }
536 604
537 // NSTextField objects send an NSNotification to a delegate if 605 - (void)saveProfileName:(id)sender {
538 // it implements this method:
539 - (void)controlTextDidEndEditing:(NSNotification *)obj {
540 NSString* text = [profileNameTextField_ stringValue]; 606 NSString* text = [profileNameTextField_ stringValue];
541 // Empty profile names are not allowed, and are treated as a cancel. 607 // Empty profile names are not allowed, and are treated as a cancel.
542 if ([text length] > 0) { 608 if ([text length] > 0) {
543 profiles::UpdateProfileName(profile_, base::SysNSStringToUTF16(text)); 609 profiles::UpdateProfileName(profile_, base::SysNSStringToUTF16(text));
544 [controller_ 610 [controller_
545 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME]; 611 postActionPerformed:ProfileMetrics::PROFILE_DESKTOP_MENU_EDIT_NAME];
546 [self setTitle:text]; 612 [self setTitle:text];
547 } 613 }
548 [profileNameTextField_ setHidden:YES]; 614 [profileNameTextField_ setHidden:YES];
549 [profileNameTextField_ resignFirstResponder];
550 } 615 }
551 616
552 - (void)showEditableView:(id)sender { 617 - (void)showEditableView:(id)sender {
553 [profileNameTextField_ setHidden:NO]; 618 [profileNameTextField_ setHidden:NO];
554 [profileNameTextField_ becomeFirstResponder]; 619 [[self window] makeFirstResponder:profileNameTextField_];
555 } 620 }
556 621
557 @end 622 @end
558
559 // Custom button cell that adds a left padding before the button image, and
560 // a custom spacing between the button image and title.
561 @interface CustomPaddingImageButtonCell : NSButtonCell {
562 @private
563 // Padding between the left margin of the button and the cell image.
564 int leftMarginSpacing_;
565 // Spacing between the cell image and title.
566 int imageTitleSpacing_;
567 }
568
569 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
570 imageTitleSpacing:(int)imageTitleSpacing;
571 @end
572
573 @implementation CustomPaddingImageButtonCell
574 - (id)initWithLeftMarginSpacing:(int)leftMarginSpacing
575 imageTitleSpacing:(int)imageTitleSpacing {
576 if ((self = [super init])) {
577 leftMarginSpacing_ = leftMarginSpacing;
578 imageTitleSpacing_ = imageTitleSpacing;
579 }
580 return self;
581 }
582
583 - (NSRect)drawTitle:(NSAttributedString*)title
584 withFrame:(NSRect)frame
585 inView:(NSView*)controlView {
586 // The title frame origin isn't aware of the left margin spacing added
587 // in -drawImage, so it must be added when drawing the title as well.
588 frame.origin.x += leftMarginSpacing_ + imageTitleSpacing_;
589 frame.size.width -= (imageTitleSpacing_ + leftMarginSpacing_);
590 return [super drawTitle:title withFrame:frame inView:controlView];
591 }
592
593 - (void)drawImage:(NSImage*)image
594 withFrame:(NSRect)frame
595 inView:(NSView*)controlView {
596 frame.origin.x = leftMarginSpacing_;
597 [super drawImage:image withFrame:frame inView:controlView];
598 }
599
600 - (NSSize)cellSize {
601 NSSize buttonSize = [super cellSize];
602 buttonSize.width += leftMarginSpacing_ + imageTitleSpacing_;
603 return buttonSize;
604 }
605
606 @end
607 623
608 // A custom button that allows for setting a background color when hovered over. 624 // A custom button that allows for setting a background color when hovered over.
609 @interface BackgroundColorHoverButton : HoverImageButton { 625 @interface BackgroundColorHoverButton : HoverImageButton {
610 @private 626 @private
611 base::scoped_nsobject<NSColor> backgroundColor_; 627 base::scoped_nsobject<NSColor> backgroundColor_;
612 base::scoped_nsobject<NSColor> hoverColor_; 628 base::scoped_nsobject<NSColor> hoverColor_;
613 } 629 }
614 @end 630 @end
615 631
616 @implementation BackgroundColorHoverButton 632 @implementation BackgroundColorHoverButton
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after
978 currentProfileView = [self createCurrentProfileView:item]; 994 currentProfileView = [self createCurrentProfileView:item];
979 enableLock = item.signed_in; 995 enableLock = item.signed_in;
980 } else { 996 } else {
981 [otherProfiles addObject:[self createOtherProfileView:i]]; 997 [otherProfiles addObject:[self createOtherProfileView:i]];
982 } 998 }
983 } 999 }
984 if (!currentProfileView) // Guest windows don't have an active profile. 1000 if (!currentProfileView) // Guest windows don't have an active profile.
985 currentProfileView = [self createGuestProfileView]; 1001 currentProfileView = [self createGuestProfileView];
986 1002
987 // |yOffset| is the next position at which to draw in |container| 1003 // |yOffset| is the next position at which to draw in |container|
988 // coordinates. 1004 // coordinates. Add a pixel offset so that the bottom option buttons don't
989 CGFloat yOffset = 0; 1005 // overlap the bubble's rounded corners.
1006 CGFloat yOffset = 1;
990 1007
991 // Option buttons. Only available with the new profile management flag. 1008 // Option buttons. Only available with the new profile management flag.
992 if (switches::IsNewProfileManagement()) { 1009 if (switches::IsNewProfileManagement()) {
993 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0); 1010 NSRect rect = NSMakeRect(0, yOffset, kFixedMenuWidth, 0);
994 NSView* optionsView = [self createOptionsViewWithRect:rect 1011 NSView* optionsView = [self createOptionsViewWithRect:rect
995 enableLock:enableLock]; 1012 enableLock:enableLock];
996 [container addSubview:optionsView]; 1013 [container addSubview:optionsView];
997 rect.origin.y = NSMaxY([optionsView frame]); 1014 rect.origin.y = NSMaxY([optionsView frame]);
998 1015
999 NSBox* separator = [self separatorWithFrame:rect]; 1016 NSBox* separator = [self horizontalSeparatorWithFrame:rect];
1000 [container addSubview:separator]; 1017 [container addSubview:separator];
1001 yOffset = NSMaxY([separator frame]); 1018 yOffset = NSMaxY([separator frame]);
1002 } 1019 }
1003 1020
1004 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER && 1021 if (viewMode_ == profiles::BUBBLE_VIEW_MODE_PROFILE_CHOOSER &&
1005 switches::IsFastUserSwitching()) { 1022 switches::IsFastUserSwitching()) {
1006 // Other profiles switcher. The profiles have already been sorted 1023 // Other profiles switcher. The profiles have already been sorted
1007 // by their y-coordinate, so they can be added in the existing order. 1024 // by their y-coordinate, so they can be added in the existing order.
1008 for (NSView *otherProfileView in otherProfiles.get()) { 1025 for (NSView *otherProfileView in otherProfiles.get()) {
1009 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1026 [otherProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1010 [container addSubview:otherProfileView]; 1027 [container addSubview:otherProfileView];
1011 yOffset = NSMaxY([otherProfileView frame]); 1028 yOffset = NSMaxY([otherProfileView frame]);
1012 1029
1013 NSBox* separator = 1030 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect(
1014 [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 1031 0, yOffset, kFixedMenuWidth, 0)];
1015 [container addSubview:separator]; 1032 [container addSubview:separator];
1016 yOffset = NSMaxY([separator frame]); 1033 yOffset = NSMaxY([separator frame]);
1017 } 1034 }
1018 } else if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) { 1035 } else if (viewMode_ == profiles::BUBBLE_VIEW_MODE_ACCOUNT_MANAGEMENT) {
1019 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView: 1036 NSView* currentProfileAccountsView = [self createCurrentProfileAccountsView:
1020 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 1037 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
1021 [container addSubview:currentProfileAccountsView]; 1038 [container addSubview:currentProfileAccountsView];
1022 yOffset = NSMaxY([currentProfileAccountsView frame]); 1039 yOffset = NSMaxY([currentProfileAccountsView frame]);
1023 1040
1024 NSBox* accountsSeparator = [self separatorWithFrame: 1041 NSBox* accountsSeparator = [self horizontalSeparatorWithFrame:
1025 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 1042 NSMakeRect(0, yOffset, kFixedMenuWidth, 0)];
1026 [container addSubview:accountsSeparator]; 1043 [container addSubview:accountsSeparator];
1027 yOffset = NSMaxY([accountsSeparator frame]); 1044 yOffset = NSMaxY([accountsSeparator frame]);
1028 } 1045 }
1029 1046
1030 // For supervised users, add the disclaimer text. 1047 // For supervised users, add the disclaimer text.
1031 if (browser_->profile()->IsSupervised()) { 1048 if (browser_->profile()->IsSupervised()) {
1032 yOffset += kSmallVerticalSpacing; 1049 yOffset += kSmallVerticalSpacing;
1033 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView]; 1050 NSView* disclaimerContainer = [self createSupervisedUserDisclaimerView];
1034 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)]; 1051 [disclaimerContainer setFrameOrigin:NSMakePoint(0, yOffset)];
1035 [container addSubview:disclaimerContainer]; 1052 [container addSubview:disclaimerContainer];
1036 yOffset = NSMaxY([disclaimerContainer frame]); 1053 yOffset = NSMaxY([disclaimerContainer frame]);
1037 yOffset += kSmallVerticalSpacing; 1054 yOffset += kSmallVerticalSpacing;
1038 1055
1039 NSBox* separator = 1056 NSBox* separator = [self horizontalSeparatorWithFrame:NSMakeRect(
1040 [self separatorWithFrame:NSMakeRect(0, yOffset, kFixedMenuWidth, 0)]; 1057 0, yOffset, kFixedMenuWidth, 0)];
1041 [container addSubview:separator]; 1058 [container addSubview:separator];
1042 yOffset = NSMaxY([separator frame]); 1059 yOffset = NSMaxY([separator frame]);
1043 } 1060 }
1044 1061
1045 // Active profile card. 1062 // Active profile card.
1046 if (currentProfileView) { 1063 if (currentProfileView) {
1047 yOffset += kVerticalSpacing; 1064 yOffset += kVerticalSpacing;
1048 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)]; 1065 [currentProfileView setFrameOrigin:NSMakePoint(0, yOffset)];
1049 [container addSubview:currentProfileView]; 1066 [container addSubview:currentProfileView];
1050 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing; 1067 yOffset = NSMaxY([currentProfileView frame]) + kVerticalSpacing;
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 [profileButton setBordered:NO]; 1433 [profileButton setBordered:NO];
1417 [profileButton setTag:itemIndex]; 1434 [profileButton setTag:itemIndex];
1418 [profileButton setTarget:self]; 1435 [profileButton setTarget:self];
1419 [profileButton setAction:@selector(switchToProfile:)]; 1436 [profileButton setAction:@selector(switchToProfile:)];
1420 1437
1421 return profileButton.autorelease(); 1438 return profileButton.autorelease();
1422 } 1439 }
1423 1440
1424 - (NSView*)createOptionsViewWithRect:(NSRect)rect 1441 - (NSView*)createOptionsViewWithRect:(NSRect)rect
1425 enableLock:(BOOL)enableLock { 1442 enableLock:(BOOL)enableLock {
1426 int widthOfLockButton = enableLock? 2 * kHorizontalSpacing + 12 : 0; 1443 int widthOfLockButton = enableLock ? 2 * kHorizontalSpacing + 14 : 0;
1427 NSRect viewRect = NSMakeRect(0, 0, 1444 NSRect viewRect = NSMakeRect(0, 0,
1428 rect.size.width - widthOfLockButton, 1445 rect.size.width - widthOfLockButton,
1429 kBlueButtonHeight + kVerticalSpacing); 1446 kBlueButtonHeight + kVerticalSpacing);
1430 NSString* text = isGuestSession_ ? 1447 NSString* text = isGuestSession_ ?
1431 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) : 1448 l10n_util::GetNSString(IDS_PROFILES_EXIT_GUEST) :
1432 l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU_BUTTON, 1449 l10n_util::GetNSStringF(IDS_PROFILES_NOT_YOU_BUTTON,
1433 profiles::GetAvatarNameForProfile(browser_->profile())); 1450 profiles::GetAvatarNameForProfile(browser_->profile()));
1434 NSButton* notYouButton = 1451 NSButton* notYouButton =
1435 [self hoverButtonWithRect:viewRect 1452 [self hoverButtonWithRect:viewRect
1436 text:text 1453 text:text
1437 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR 1454 imageResourceId:IDR_ICON_PROFILES_MENU_AVATAR
1438 alternateImageResourceId:IDR_ICON_PROFILES_MENU_AVATAR 1455 alternateImageResourceId:IDR_ICON_PROFILES_MENU_AVATAR
1439 action:isGuestSession_? @selector(exitGuest:) : 1456 action:isGuestSession_? @selector(exitGuest:) :
1440 @selector(showUserManager:)]; 1457 @selector(showUserManager:)];
1441 1458
1442 rect.size.height = NSMaxY([notYouButton frame]); 1459 rect.size.height = NSMaxY([notYouButton frame]);
1443 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]); 1460 base::scoped_nsobject<NSView> container([[NSView alloc] initWithFrame:rect]);
1444 [container addSubview:notYouButton]; 1461 [container addSubview:notYouButton];
1445 1462
1446 if (enableLock) { 1463 if (enableLock) {
1447 viewRect.origin.x = NSMaxX([notYouButton frame]); 1464 viewRect.origin.x = NSMaxX([notYouButton frame]);
1465 NSBox* separator = [self verticalSeparatorWithFrame:viewRect];
1466 [container addSubview:separator];
1467
1468 viewRect.origin.x = NSMaxX([separator frame]);
1448 viewRect.size.width = widthOfLockButton; 1469 viewRect.size.width = widthOfLockButton;
1449 NSButton* lockButton = 1470 NSButton* lockButton =
1450 [self hoverButtonWithRect:viewRect 1471 [self hoverButtonWithRect:viewRect
1451 text:@"" 1472 text:@""
1452 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK 1473 imageResourceId:IDR_ICON_PROFILES_MENU_LOCK
1453 alternateImageResourceId:IDR_ICON_PROFILES_MENU_LOCK 1474 alternateImageResourceId:IDR_ICON_PROFILES_MENU_LOCK
1454 action:@selector(lockProfile:)]; 1475 action:@selector(lockProfile:)];
1455 [container addSubview:lockButton]; 1476 [container addSubview:lockButton];
1456 } 1477 }
1457 1478
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
1545 source, false /* auto_close */, true /* is_constrained */), 1566 source, false /* auto_close */, true /* is_constrained */),
1546 content::Referrer(), 1567 content::Referrer(),
1547 content::PAGE_TRANSITION_AUTO_TOPLEVEL, 1568 content::PAGE_TRANSITION_AUTO_TOPLEVEL,
1548 std::string()); 1569 std::string());
1549 NSView* webview = webContents_->GetNativeView(); 1570 NSView* webview = webContents_->GetNativeView();
1550 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)]; 1571 [webview setFrameSize:NSMakeSize(kFixedGaiaViewWidth, kFixedGaiaViewHeight)];
1551 [container addSubview:webview]; 1572 [container addSubview:webview];
1552 yOffset = NSMaxY([webview frame]); 1573 yOffset = NSMaxY([webview frame]);
1553 1574
1554 // Adds the title card. 1575 // Adds the title card.
1555 NSBox* separator = [self separatorWithFrame: 1576 NSBox* separator = [self horizontalSeparatorWithFrame:
1556 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)]; 1577 NSMakeRect(0, yOffset, kFixedGaiaViewWidth, 0)];
1557 [container addSubview:separator]; 1578 [container addSubview:separator];
1558 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; 1579 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing;
1559 1580
1560 NSView* titleView = BuildTitleCard( 1581 NSView* titleView = BuildTitleCard(
1561 NSMakeRect(0, yOffset, kFixedGaiaViewWidth,0), 1582 NSMakeRect(0, yOffset, kFixedGaiaViewWidth,0),
1562 addSecondaryAccount ? IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE : 1583 addSecondaryAccount ? IDS_PROFILES_GAIA_ADD_ACCOUNT_TITLE :
1563 IDS_PROFILES_GAIA_SIGNIN_TITLE, 1584 IDS_PROFILES_GAIA_SIGNIN_TITLE,
1564 self /* backButtonTarget*/, 1585 self /* backButtonTarget*/,
1565 @selector(navigateBackFromSigninPage:) /* backButtonAction */); 1586 @selector(navigateBackFromSigninPage:) /* backButtonAction */);
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1617 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, 1638 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin,
1618 GetDialogBackgroundColor(), nil /* text_color */); 1639 GetDialogBackgroundColor(), nil /* text_color */);
1619 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; 1640 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1620 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; 1641 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel];
1621 contentView = contentLabel; 1642 contentView = contentLabel;
1622 } 1643 }
1623 [container addSubview:contentView]; 1644 [container addSubview:contentView];
1624 yOffset = NSMaxY([contentView frame]) + kVerticalSpacing; 1645 yOffset = NSMaxY([contentView frame]) + kVerticalSpacing;
1625 1646
1626 // Adds the title card. 1647 // Adds the title card.
1627 NSBox* separator = [self separatorWithFrame: 1648 NSBox* separator = [self horizontalSeparatorWithFrame:
1628 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth, 0)]; 1649 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth, 0)];
1629 [container addSubview:separator]; 1650 [container addSubview:separator];
1630 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; 1651 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing;
1631 1652
1632 NSView* titleView = BuildTitleCard( 1653 NSView* titleView = BuildTitleCard(
1633 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth,0), 1654 NSMakeRect(0, yOffset, kFixedAccountRemovalViewWidth,0),
1634 IDS_PROFILES_ACCOUNT_REMOVAL_TITLE, 1655 IDS_PROFILES_ACCOUNT_REMOVAL_TITLE,
1635 self /* backButtonTarget*/, 1656 self /* backButtonTarget*/,
1636 @selector(showAccountManagement:) /* backButtonAction */); 1657 @selector(showAccountManagement:) /* backButtonAction */);
1637 [container addSubview:titleView]; 1658 [container addSubview:titleView];
(...skipping 30 matching lines...) Expand all
1668 NSString* contentStr = 1689 NSString* contentStr =
1669 l10n_util::GetNSString(IDS_PROFILES_END_PREVIEW_TEXT); 1690 l10n_util::GetNSString(IDS_PROFILES_END_PREVIEW_TEXT);
1670 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin, 1691 NSTextField* contentLabel = BuildLabel(contentStr, contentFrameOrigin,
1671 GetDialogBackgroundColor(), nil /* text_color */); 1692 GetDialogBackgroundColor(), nil /* text_color */);
1672 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)]; 1693 [contentLabel setFrameSize:NSMakeSize(availableWidth, 0)];
1673 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel]; 1694 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:contentLabel];
1674 [container addSubview:contentLabel]; 1695 [container addSubview:contentLabel];
1675 yOffset = NSMaxY([contentLabel frame]) + kVerticalSpacing; 1696 yOffset = NSMaxY([contentLabel frame]) + kVerticalSpacing;
1676 1697
1677 // Adds the title card. 1698 // Adds the title card.
1678 NSBox* separator = [self separatorWithFrame: 1699 NSBox* separator = [self horizontalSeparatorWithFrame:
1679 NSMakeRect(0, yOffset, kFixedEndPreviewViewWidth, 0)]; 1700 NSMakeRect(0, yOffset, kFixedEndPreviewViewWidth, 0)];
1680 [container addSubview:separator]; 1701 [container addSubview:separator];
1681 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing; 1702 yOffset = NSMaxY([separator frame]) + kSmallVerticalSpacing;
1682 1703
1683 NSView* titleView = BuildTitleCard( 1704 NSView* titleView = BuildTitleCard(
1684 NSMakeRect(0, yOffset, kFixedEndPreviewViewWidth, 0), 1705 NSMakeRect(0, yOffset, kFixedEndPreviewViewWidth, 0),
1685 IDS_PROFILES_END_PREVIEW, 1706 IDS_PROFILES_END_PREVIEW,
1686 self /* backButtonTarget*/, 1707 self /* backButtonTarget*/,
1687 @selector(showSendFeedbackTutorial:) /* backButtonAction */); 1708 @selector(showSendFeedbackTutorial:) /* backButtonAction */);
1688 [container addSubview:titleView]; 1709 [container addSubview:titleView];
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
1783 [button addSubview:deleteButton]; 1804 [button addSubview:deleteButton];
1784 return button.autorelease(); 1805 return button.autorelease();
1785 } 1806 }
1786 1807
1787 - (void)postActionPerformed:(ProfileMetrics::ProfileDesktopMenu)action { 1808 - (void)postActionPerformed:(ProfileMetrics::ProfileDesktopMenu)action {
1788 ProfileMetrics::LogProfileDesktopMenu(action, serviceType_); 1809 ProfileMetrics::LogProfileDesktopMenu(action, serviceType_);
1789 serviceType_ = signin::GAIA_SERVICE_TYPE_NONE; 1810 serviceType_ = signin::GAIA_SERVICE_TYPE_NONE;
1790 } 1811 }
1791 1812
1792 @end 1813 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698