Index: chrome/browser/ui/cocoa/browser/avatar_icon_controller.mm |
diff --git a/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm b/chrome/browser/ui/cocoa/browser/avatar_icon_controller.mm |
similarity index 64% |
copy from chrome/browser/ui/cocoa/browser/avatar_button_controller.mm |
copy to chrome/browser/ui/cocoa/browser/avatar_icon_controller.mm |
index 9a0f49aa24865ffe7e91276dab02b77018cb99a3..ca1f78f4d2b5595ee523d495c02131b47574a427 100644 |
--- a/chrome/browser/ui/cocoa/browser/avatar_button_controller.mm |
+++ b/chrome/browser/ui/cocoa/browser/avatar_icon_controller.mm |
@@ -1,30 +1,19 @@ |
-// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
+// Copyright 2014 The Chromium Authors. All rights reserved. |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#import "chrome/browser/ui/cocoa/browser/avatar_button_controller.h" |
+#import "chrome/browser/ui/cocoa/browser/avatar_icon_controller.h" |
#include "base/strings/sys_string_conversions.h" |
-#include "chrome/app/chrome_command_ids.h" |
#include "chrome/browser/browser_process.h" |
-#include "chrome/browser/chrome_notification_types.h" |
-#include "chrome/browser/command_updater.h" |
#include "chrome/browser/profiles/profile.h" |
#include "chrome/browser/profiles/profile_info_cache.h" |
#include "chrome/browser/profiles/profile_info_util.h" |
#include "chrome/browser/profiles/profile_manager.h" |
-#include "chrome/browser/profiles/profile_metrics.h" |
-#include "chrome/browser/profiles/profiles_state.h" |
#include "chrome/browser/ui/browser.h" |
-#include "chrome/browser/ui/browser_commands.h" |
#include "chrome/browser/ui/browser_window.h" |
#import "chrome/browser/ui/cocoa/browser/avatar_label_button.h" |
-#import "chrome/browser/ui/cocoa/browser/avatar_menu_bubble_controller.h" |
-#import "chrome/browser/ui/cocoa/base_bubble_controller.h" |
-#import "chrome/browser/ui/cocoa/browser/profile_chooser_controller.h" |
#import "chrome/browser/ui/cocoa/browser_window_controller.h" |
-#include "chrome/common/profile_management_switches.h" |
-#include "content/public/browser/notification_service.h" |
#include "grit/generated_resources.h" |
#include "grit/theme_resources.h" |
#include "ui/base/l10n/l10n_util_mac.h" |
@@ -34,9 +23,6 @@ |
namespace { |
-// Space between the avatar icon and the avatar menu bubble. |
-const CGFloat kMenuYOffsetAdjust = 1.0; |
- |
// Space between the avatar label and the left edge of the container containing |
// the label and the icon. |
const CGFloat kAvatarSpacing = 4; |
@@ -51,12 +37,10 @@ const CGFloat kAvatarLabelRightSpacing = 2; |
} // namespace |
-@interface AvatarButtonController (Private) |
+@interface AvatarIconController (Private) |
- (void)setButtonEnabled:(BOOL)flag; |
-- (IBAction)buttonClicked:(id)sender; |
-- (void)bubbleWillClose:(NSNotification*)notif; |
- (NSImage*)compositeImageWithShadow:(NSImage*)image; |
-- (void)updateAvatar; |
+- (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent; |
- (void)addOrRemoveButtonIfNecessary; |
@end |
@@ -66,50 +50,17 @@ const CGFloat kAvatarLabelRightSpacing = 2; |
- (void)_tileTitlebarAndRedisplay:(BOOL)redisplay; |
@end |
-namespace AvatarButtonControllerInternal { |
- |
-class Observer : public content::NotificationObserver { |
- public: |
- Observer(AvatarButtonController* button) : button_(button) { |
- registrar_.Add(this, chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED, |
- content::NotificationService::AllSources()); |
- } |
- |
- // NotificationObserver: |
- virtual void Observe(int type, |
- const content::NotificationSource& source, |
- const content::NotificationDetails& details) OVERRIDE { |
- switch (type) { |
- case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: |
- [button_ updateAvatar]; |
- [button_ addOrRemoveButtonIfNecessary]; |
- break; |
- default: |
- NOTREACHED(); |
- break; |
- } |
- } |
- |
- private: |
- content::NotificationRegistrar registrar_; |
- |
- AvatarButtonController* button_; // Weak; owns this. |
-}; |
- |
-} // namespace AvatarButtonControllerInternal |
- |
-//////////////////////////////////////////////////////////////////////////////// |
- |
-@implementation AvatarButtonController |
+@implementation AvatarIconController |
- (id)initWithBrowser:(Browser*)browser { |
- if ((self = [super init])) { |
+ if ((self = [super initWithBrowser:browser])) { |
browser_ = browser; |
base::scoped_nsobject<NSView> container( |
[[NSView alloc] initWithFrame:NSMakeRect( |
0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]); |
[self setView:container]; |
+ |
button_.reset([[NSButton alloc] initWithFrame:NSMakeRect( |
0, 0, profiles::kAvatarIconWidth, profiles::kAvatarIconHeight)]); |
NSButtonCell* cell = [button_ cell]; |
@@ -156,8 +107,7 @@ class Observer : public content::NotificationObserver { |
[self setButtonEnabled:profile->IsGuestSession()]; |
} else { |
[self setButtonEnabled:YES]; |
- observer_.reset(new AvatarButtonControllerInternal::Observer(self)); |
- [self updateAvatar]; |
+ [self updateAvatarButtonAndLayoutParent:NO]; |
// Managed users cannot enter incognito mode, so we only need to check |
// it in this code path. |
@@ -186,18 +136,6 @@ class Observer : public content::NotificationObserver { |
return self; |
} |
-- (void)dealloc { |
- [[NSNotificationCenter defaultCenter] |
- removeObserver:self |
- name:NSWindowWillCloseNotification |
- object:[menuController_ window]]; |
- [super dealloc]; |
-} |
- |
-- (NSButton*)buttonView { |
- return button_.get(); |
-} |
- |
- (NSButton*)labelButtonView { |
return labelButton_.get(); |
} |
@@ -206,65 +144,10 @@ class Observer : public content::NotificationObserver { |
[button_ setImage:image]; |
} |
-- (void)showAvatarBubble:(NSView*)anchor { |
- if (menuController_) |
- return; |
- |
- DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU)); |
- |
- NSWindowController* wc = |
- [browser_->window()->GetNativeWindow() windowController]; |
- if ([wc isKindOfClass:[BrowserWindowController class]]) { |
- [static_cast<BrowserWindowController*>(wc) |
- lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
- } |
- |
- NSPoint point = NSMakePoint(NSMidX([anchor bounds]), |
- NSMaxY([anchor bounds]) - kMenuYOffsetAdjust); |
- point = [anchor convertPoint:point toView:nil]; |
- point = [[anchor window] convertBaseToScreen:point]; |
- |
- // |menuController_| will automatically release itself on close. |
- if (switches::IsNewProfileManagement()) { |
- menuController_ = |
- [[ProfileChooserController alloc] initWithBrowser:browser_ |
- anchoredAt:point]; |
- } else { |
- menuController_ = |
- [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ |
- anchoredAt:point]; |
- } |
- [[NSNotificationCenter defaultCenter] |
- addObserver:self |
- selector:@selector(bubbleWillClose:) |
- name:NSWindowWillCloseNotification |
- object:[menuController_ window]]; |
- [menuController_ showWindow:self]; |
- |
- ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
-} |
- |
-// Private ///////////////////////////////////////////////////////////////////// |
- |
- (void)setButtonEnabled:(BOOL)flag { |
[button_ setEnabled:flag]; |
} |
-- (IBAction)buttonClicked:(id)sender { |
- DCHECK(sender == button_.get() || sender == labelButton_.get()); |
- [self showAvatarBubble:button_]; |
-} |
- |
-- (void)bubbleWillClose:(NSNotification*)notif { |
- NSWindowController* wc = |
- [browser_->window()->GetNativeWindow() windowController]; |
- if ([wc isKindOfClass:[BrowserWindowController class]]) { |
- [static_cast<BrowserWindowController*>(wc) |
- releaseBarVisibilityForOwner:self withAnimation:YES delay:NO]; |
- } |
- menuController_ = nil; |
-} |
- |
// This will take in an original image and redraw it with a shadow. |
- (NSImage*)compositeImageWithShadow:(NSImage*)image { |
gfx::ScopedNSGraphicsContextSaveGState scopedGState; |
@@ -297,13 +180,14 @@ class Observer : public content::NotificationObserver { |
} |
// Updates the avatar information from the profile cache. |
-- (void)updateAvatar { |
+- (void)updateAvatarButtonAndLayoutParent:(BOOL)layoutParent { |
ProfileInfoCache& cache = |
g_browser_process->profile_manager()->GetProfileInfoCache(); |
size_t index = |
cache.GetIndexOfProfileWithPath(browser_->profile()->GetPath()); |
if (index == std::string::npos) |
return; |
+ |
BOOL is_gaia_picture = |
cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
cache.GetGAIAPictureOfProfileAtIndex(index); |
@@ -318,6 +202,8 @@ class Observer : public content::NotificationObserver { |
[[button_ cell] |
accessibilitySetOverrideValue:nsName |
forAttribute:NSAccessibilityValueAttribute]; |
+ if (layoutParent) |
+ [self addOrRemoveButtonIfNecessary]; |
} |
// If the second-to-last profile was removed or a second profile was added, |
@@ -346,10 +232,4 @@ class Observer : public content::NotificationObserver { |
[themeFrame _tileTitlebarAndRedisplay:YES]; |
} |
-// Testing ///////////////////////////////////////////////////////////////////// |
- |
-- (BaseBubbleController*)menuController { |
- return menuController_; |
-} |
- |
@end |