| 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 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" | 5 #import "chrome/browser/ui/cocoa/profiles/avatar_base_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "chrome/app/chrome_command_ids.h" | 8 #include "chrome/app/chrome_command_ids.h" |
| 9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
| 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" | 10 #include "chrome/browser/profiles/profile_avatar_icon_util.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 if (profile_->GetPath() != profile_path) | 86 if (profile_->GetPath() != profile_path) |
| 87 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; | 87 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; |
| 88 } | 88 } |
| 89 | 89 |
| 90 void OnProfileNameChanged(const base::FilePath& profile_path, | 90 void OnProfileNameChanged(const base::FilePath& profile_path, |
| 91 const base::string16& old_profile_name) override { | 91 const base::string16& old_profile_name) override { |
| 92 if (profile_->GetPath() == profile_path) | 92 if (profile_->GetPath() == profile_path) |
| 93 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; | 93 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; |
| 94 } | 94 } |
| 95 | 95 |
| 96 void OnProfileAvatarChanged(const base::FilePath& profile_path) override { | |
| 97 if (!switches::IsNewAvatarMenu() && profile_->GetPath() == profile_path) | |
| 98 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; | |
| 99 } | |
| 100 | |
| 101 void OnProfileSupervisedUserIdChanged( | 96 void OnProfileSupervisedUserIdChanged( |
| 102 const base::FilePath& profile_path) override { | 97 const base::FilePath& profile_path) override { |
| 103 if (profile_->GetPath() == profile_path) | 98 if (profile_->GetPath() == profile_path) |
| 104 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; | 99 [avatarController_ updateAvatarButtonAndLayoutParent:YES]; |
| 105 } | 100 } |
| 106 | 101 |
| 107 // SigninErrorController::Observer: | 102 // SigninErrorController::Observer: |
| 108 void OnErrorChanged() override { | 103 void OnErrorChanged() override { |
| 109 SigninErrorController* errorController = | 104 SigninErrorController* errorController = |
| 110 profiles::GetSigninErrorController(profile_); | 105 profiles::GetSigninErrorController(profile_); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 | 140 |
| 146 - (NSButton*)buttonView { | 141 - (NSButton*)buttonView { |
| 147 CHECK(button_.get()); // Subclasses must set this. | 142 CHECK(button_.get()); // Subclasses must set this. |
| 148 return button_.get(); | 143 return button_.get(); |
| 149 } | 144 } |
| 150 | 145 |
| 151 - (void)showAvatarBubbleAnchoredAt:(NSView*)anchor | 146 - (void)showAvatarBubbleAnchoredAt:(NSView*)anchor |
| 152 withMode:(BrowserWindow::AvatarBubbleMode)mode | 147 withMode:(BrowserWindow::AvatarBubbleMode)mode |
| 153 withServiceType:(signin::GAIAServiceType)serviceType { | 148 withServiceType:(signin::GAIAServiceType)serviceType { |
| 154 if (menuController_) { | 149 if (menuController_) { |
| 155 if (switches::IsNewAvatarMenu()) { | 150 profiles::BubbleViewMode viewMode; |
| 156 profiles::BubbleViewMode viewMode; | 151 profiles::TutorialMode tutorialMode; |
| 157 profiles::TutorialMode tutorialMode; | 152 profiles::BubbleViewModeFromAvatarBubbleMode( |
| 158 profiles::BubbleViewModeFromAvatarBubbleMode( | 153 mode, &viewMode, &tutorialMode); |
| 159 mode, &viewMode, &tutorialMode); | 154 if (tutorialMode != profiles::TUTORIAL_MODE_NONE) { |
| 160 if (tutorialMode != profiles::TUTORIAL_MODE_NONE) { | 155 ProfileChooserController* profileChooserController = |
| 161 ProfileChooserController* profileChooserController = | 156 base::mac::ObjCCastStrict<ProfileChooserController>( |
| 162 base::mac::ObjCCastStrict<ProfileChooserController>( | 157 menuController_); |
| 163 menuController_); | 158 [profileChooserController setTutorialMode:tutorialMode]; |
| 164 [profileChooserController setTutorialMode:tutorialMode]; | 159 [profileChooserController initMenuContentsWithView:viewMode]; |
| 165 [profileChooserController initMenuContentsWithView:viewMode]; | |
| 166 } | |
| 167 } | 160 } |
| 168 return; | 161 return; |
| 169 } | 162 } |
| 170 | 163 |
| 171 DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU)); | 164 DCHECK(chrome::IsCommandEnabled(browser_, IDC_SHOW_AVATAR_MENU)); |
| 172 | 165 |
| 173 NSWindowController* wc = | 166 NSWindowController* wc = |
| 174 [browser_->window()->GetNativeWindow() windowController]; | 167 [browser_->window()->GetNativeWindow() windowController]; |
| 175 if ([wc isKindOfClass:[BrowserWindowController class]]) { | 168 if ([wc isKindOfClass:[BrowserWindowController class]]) { |
| 176 [static_cast<BrowserWindowController*>(wc) | 169 [static_cast<BrowserWindowController*>(wc) |
| 177 lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; | 170 lockBarVisibilityForOwner:self withAnimation:NO delay:NO]; |
| 178 } | 171 } |
| 179 | 172 |
| 180 // The new avatar bubble does not have an arrow, and it should be anchored | 173 // The new avatar bubble does not have an arrow, and it should be anchored |
| 181 // to the edge of the avatar button. | 174 // to the edge of the avatar button. |
| 182 int anchorX = switches::IsNewAvatarMenu() ? | 175 int anchorX = NSMaxX([anchor bounds]) - kMenuXOffsetAdjust; |
| 183 NSMaxX([anchor bounds]) - kMenuXOffsetAdjust : | |
| 184 NSMidX([anchor bounds]); | |
| 185 NSPoint point = NSMakePoint(anchorX, | 176 NSPoint point = NSMakePoint(anchorX, |
| 186 NSMaxY([anchor bounds]) + kMenuYOffsetAdjust); | 177 NSMaxY([anchor bounds]) + kMenuYOffsetAdjust); |
| 187 point = [anchor convertPoint:point toView:nil]; | 178 point = [anchor convertPoint:point toView:nil]; |
| 188 point = [[anchor window] convertBaseToScreen:point]; | 179 point = [[anchor window] convertBaseToScreen:point]; |
| 189 | 180 |
| 190 // |menuController_| will automatically release itself on close. | 181 // |menuController_| will automatically release itself on close. |
| 191 if (switches::IsNewAvatarMenu()) { | 182 profiles::BubbleViewMode viewMode; |
| 192 profiles::BubbleViewMode viewMode; | 183 profiles::TutorialMode tutorialMode; |
| 193 profiles::TutorialMode tutorialMode; | 184 profiles::BubbleViewModeFromAvatarBubbleMode( |
| 194 profiles::BubbleViewModeFromAvatarBubbleMode( | 185 mode, &viewMode, &tutorialMode); |
| 195 mode, &viewMode, &tutorialMode); | 186 // Don't start creating the view if it would be an empty fast user switcher. |
| 196 // Don't start creating the view if it would be an empty fast user switcher. | 187 // It has to happen here to prevent the view system from creating an empty |
| 197 // It has to happen here to prevent the view system from creating an empty | 188 // container. |
| 198 // container. | 189 if (viewMode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && |
| 199 if (viewMode == profiles::BUBBLE_VIEW_MODE_FAST_PROFILE_CHOOSER && | 190 !profiles::HasProfileSwitchTargets(browser_->profile())) { |
| 200 !profiles::HasProfileSwitchTargets(browser_->profile())) { | 191 return; |
| 201 return; | 192 } |
| 202 } | |
| 203 | 193 |
| 204 menuController_ = | 194 menuController_ = |
| 205 [[ProfileChooserController alloc] initWithBrowser:browser_ | 195 [[ProfileChooserController alloc] initWithBrowser:browser_ |
| 206 anchoredAt:point | 196 anchoredAt:point |
| 207 viewMode:viewMode | 197 viewMode:viewMode |
| 208 tutorialMode:tutorialMode | 198 tutorialMode:tutorialMode |
| 209 serviceType:serviceType]; | 199 serviceType:serviceType]; |
| 210 } else { | |
| 211 menuController_ = | |
| 212 [[AvatarMenuBubbleController alloc] initWithBrowser:browser_ | |
| 213 anchoredAt:point]; | |
| 214 } | |
| 215 | 200 |
| 216 [[NSNotificationCenter defaultCenter] | 201 [[NSNotificationCenter defaultCenter] |
| 217 addObserver:self | 202 addObserver:self |
| 218 selector:@selector(bubbleWillClose:) | 203 selector:@selector(bubbleWillClose:) |
| 219 name:NSWindowWillCloseNotification | 204 name:NSWindowWillCloseNotification |
| 220 object:[menuController_ window]]; | 205 object:[menuController_ window]]; |
| 221 [menuController_ showWindow:self]; | 206 [menuController_ showWindow:self]; |
| 222 | 207 |
| 223 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); | 208 ProfileMetrics::LogProfileOpenMethod(ProfileMetrics::ICON_AVATAR_BUBBLE); |
| 224 } | 209 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 262 } | 247 } |
| 263 | 248 |
| 264 - (void)updateErrorStatus:(BOOL)hasError { | 249 - (void)updateErrorStatus:(BOOL)hasError { |
| 265 } | 250 } |
| 266 | 251 |
| 267 - (BaseBubbleController*)menuController { | 252 - (BaseBubbleController*)menuController { |
| 268 return menuController_; | 253 return menuController_; |
| 269 } | 254 } |
| 270 | 255 |
| 271 @end | 256 @end |
| OLD | NEW |