| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "ui/app_list/cocoa/app_list_view_controller.h" | 5 #import "ui/app_list/cocoa/app_list_view_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/foundation_util.h" | 7 #include "base/mac/foundation_util.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" |
| 9 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| 10 #include "ui/app_list/app_list_constants.h" | 11 #include "ui/app_list/app_list_constants.h" |
| 11 #include "ui/app_list/app_list_model.h" | 12 #include "ui/app_list/app_list_model.h" |
| 13 #include "ui/app_list/app_list_model_observer.h" |
| 12 #include "ui/app_list/app_list_view_delegate.h" | 14 #include "ui/app_list/app_list_view_delegate.h" |
| 13 #include "ui/app_list/signin_delegate.h" | 15 #include "ui/app_list/signin_delegate.h" |
| 14 #include "ui/app_list/signin_delegate_observer.h" | |
| 15 #import "ui/app_list/cocoa/app_list_pager_view.h" | 16 #import "ui/app_list/cocoa/app_list_pager_view.h" |
| 16 #import "ui/app_list/cocoa/apps_grid_controller.h" | 17 #import "ui/app_list/cocoa/apps_grid_controller.h" |
| 17 #import "ui/app_list/cocoa/signin_view_controller.h" | 18 #import "ui/app_list/cocoa/signin_view_controller.h" |
| 18 #import "ui/base/cocoa/flipped_view.h" | 19 #import "ui/base/cocoa/flipped_view.h" |
| 19 #include "ui/app_list/search_box_model.h" | 20 #include "ui/app_list/search_box_model.h" |
| 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 21 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // The roundedness of the corners of the bubble. | 25 // The roundedness of the corners of the bubble. |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 [gfx::SkColorToSRGBNSColor(app_list::kTopSeparatorColor) set]; | 69 [gfx::SkColorToSRGBNSColor(app_list::kTopSeparatorColor) set]; |
| 69 NSRectFill(separatorRect); | 70 NSRectFill(separatorRect); |
| 70 } | 71 } |
| 71 | 72 |
| 72 @end | 73 @end |
| 73 | 74 |
| 74 @interface AppListViewController () | 75 @interface AppListViewController () |
| 75 | 76 |
| 76 - (void)loadAndSetView; | 77 - (void)loadAndSetView; |
| 77 - (void)revealSearchResults:(BOOL)show; | 78 - (void)revealSearchResults:(BOOL)show; |
| 78 - (app_list::SigninDelegate*)signinDelegate; | |
| 79 | 79 |
| 80 @end | 80 @end |
| 81 | 81 |
| 82 namespace app_list { | 82 namespace app_list { |
| 83 | 83 |
| 84 class SigninDelegateObserverBridge : public SigninDelegateObserver { | 84 class AppListModelObserverBridge : public AppListModelObserver { |
| 85 public: | 85 public: |
| 86 SigninDelegateObserverBridge(AppListViewController* parent) | 86 AppListModelObserverBridge(AppListViewController* parent); |
| 87 : parent_(parent) { | 87 virtual ~AppListModelObserverBridge(); |
| 88 [parent_ signinDelegate]->AddObserver(this); | |
| 89 } | |
| 90 | |
| 91 virtual ~SigninDelegateObserverBridge() { | |
| 92 [parent_ signinDelegate]->RemoveObserver(this); | |
| 93 } | |
| 94 | 88 |
| 95 private: | 89 private: |
| 96 // SigninDelegateObserver override: | 90 // Overridden from app_list::AppListModelObserver: |
| 97 virtual void OnSigninSuccess() OVERRIDE { | 91 virtual void OnAppListModelCurrentUserChanged() OVERRIDE; |
| 98 [parent_ onSigninStatusChanged]; | 92 virtual void OnAppListModelSigninStatusChanged() OVERRIDE; |
| 99 } | |
| 100 | 93 |
| 101 AppListViewController* parent_; // Weak. Owns us. | 94 AppListViewController* parent_; // Weak. Owns us. |
| 102 | 95 |
| 103 DISALLOW_COPY_AND_ASSIGN(SigninDelegateObserverBridge); | 96 DISALLOW_COPY_AND_ASSIGN(AppListModelObserverBridge); |
| 104 }; | 97 }; |
| 105 | 98 |
| 99 AppListModelObserverBridge::AppListModelObserverBridge( |
| 100 AppListViewController* parent) |
| 101 : parent_(parent) { |
| 102 [[parent_ appsGridController] model]->AddObserver(this); |
| 103 } |
| 104 |
| 105 AppListModelObserverBridge::~AppListModelObserverBridge() { |
| 106 [[parent_ appsGridController] model]->RemoveObserver(this); |
| 107 } |
| 108 |
| 109 void AppListModelObserverBridge::OnAppListModelCurrentUserChanged() { |
| 110 [parent_ onSigninStatusChanged]; |
| 111 } |
| 112 |
| 113 void AppListModelObserverBridge::OnAppListModelSigninStatusChanged() { |
| 114 [parent_ onSigninStatusChanged]; |
| 115 } |
| 116 |
| 106 } // namespace app_list | 117 } // namespace app_list |
| 107 | 118 |
| 108 @implementation AppListViewController | 119 @implementation AppListViewController |
| 109 | 120 |
| 110 - (id)init { | 121 - (id)init { |
| 111 if ((self = [super init])) { | 122 if ((self = [super init])) { |
| 112 appsGridController_.reset([[AppsGridController alloc] init]); | 123 appsGridController_.reset([[AppsGridController alloc] init]); |
| 113 [self loadAndSetView]; | 124 [self loadAndSetView]; |
| 114 | 125 |
| 115 [self totalPagesChanged]; | 126 [self totalPagesChanged]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 141 } | 152 } |
| 142 | 153 |
| 143 - (app_list::AppListViewDelegate*)delegate { | 154 - (app_list::AppListViewDelegate*)delegate { |
| 144 return delegate_.get(); | 155 return delegate_.get(); |
| 145 } | 156 } |
| 146 | 157 |
| 147 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate | 158 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate |
| 148 withTestModel:(scoped_ptr<app_list::AppListModel>)newModel { | 159 withTestModel:(scoped_ptr<app_list::AppListModel>)newModel { |
| 149 if (delegate_) { | 160 if (delegate_) { |
| 150 // First clean up, in reverse order. | 161 // First clean up, in reverse order. |
| 151 signin_observer_bridge_.reset(); | 162 app_list_model_observer_bridge_.reset(); |
| 152 [appsSearchResultsController_ setDelegate:nil]; | 163 [appsSearchResultsController_ setDelegate:nil]; |
| 153 [appsSearchBoxController_ setDelegate:nil]; | 164 [appsSearchBoxController_ setDelegate:nil]; |
| 154 } | 165 } |
| 155 delegate_.reset(newDelegate.release()); | 166 delegate_.reset(newDelegate.release()); |
| 156 [appsGridController_ setDelegate:delegate_.get()]; | 167 [appsGridController_ setDelegate:delegate_.get()]; |
| 157 if (newModel.get()) | 168 if (newModel.get()) |
| 158 [appsGridController_ setModel:newModel.Pass()]; | 169 [appsGridController_ setModel:newModel.Pass()]; |
| 159 [appsSearchBoxController_ setDelegate:self]; | 170 [appsSearchBoxController_ setDelegate:self]; |
| 160 [appsSearchResultsController_ setDelegate:self]; | 171 [appsSearchResultsController_ setDelegate:self]; |
| 172 app_list_model_observer_bridge_.reset( |
| 173 new app_list::AppListModelObserverBridge(self)); |
| 161 [self onSigninStatusChanged]; | 174 [self onSigninStatusChanged]; |
| 162 } | 175 } |
| 163 | 176 |
| 164 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { | 177 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { |
| 165 [self setDelegate:newDelegate.Pass() | 178 [self setDelegate:newDelegate.Pass() |
| 166 withTestModel:scoped_ptr<app_list::AppListModel>()]; | 179 withTestModel:scoped_ptr<app_list::AppListModel>()]; |
| 167 } | 180 } |
| 168 | 181 |
| 169 -(void)loadAndSetView { | 182 -(void)loadAndSetView { |
| 170 pagerControl_.reset([[AppListPagerView alloc] init]); | 183 pagerControl_.reset([[AppListPagerView alloc] init]); |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 if (shouldShowSearch) | 315 if (shouldShowSearch) |
| 303 delegate_->StartSearch(); | 316 delegate_->StartSearch(); |
| 304 else | 317 else |
| 305 delegate_->StopSearch(); | 318 delegate_->StopSearch(); |
| 306 } | 319 } |
| 307 | 320 |
| 308 - (app_list::AppListModel*)appListModel { | 321 - (app_list::AppListModel*)appListModel { |
| 309 return [appsGridController_ model]; | 322 return [appsGridController_ model]; |
| 310 } | 323 } |
| 311 | 324 |
| 325 - (NSString*)currentUserName { |
| 326 return base::SysUTF16ToNSString( |
| 327 [appsGridController_ model]->current_user_name()); |
| 328 } |
| 329 |
| 330 - (NSString*)currentUserEmail { |
| 331 return base::SysUTF16ToNSString( |
| 332 [appsGridController_ model]->current_user_email()); |
| 333 } |
| 334 |
| 312 - (void)openResult:(app_list::SearchResult*)result { | 335 - (void)openResult:(app_list::SearchResult*)result { |
| 313 if (delegate_) | 336 if (delegate_) |
| 314 delegate_->OpenSearchResult(result, 0 /* event flags */); | 337 delegate_->OpenSearchResult(result, 0 /* event flags */); |
| 315 | 338 |
| 316 [appsSearchBoxController_ clearSearch]; | 339 [appsSearchBoxController_ clearSearch]; |
| 317 } | 340 } |
| 318 | 341 |
| 319 - (void)onSigninStatusChanged { | 342 - (void)onSigninStatusChanged { |
| 320 [appsSearchBoxController_ rebuildMenu]; | 343 [appsSearchBoxController_ rebuildMenu]; |
| 321 app_list::SigninDelegate* signinDelegate = [self signinDelegate]; | 344 app_list::SigninDelegate* signinDelegate = |
| 322 BOOL needsSignin = signinDelegate && signinDelegate->NeedSignin(); | 345 delegate_ ? delegate_->GetSigninDelegate() : NULL; |
| 323 if (!needsSignin) { | 346 BOOL show_signin_view = |
| 347 signinDelegate && ![appsGridController_ model]->signed_in(); |
| 348 if (!!signinViewController_ == show_signin_view) |
| 349 return; |
| 350 |
| 351 if (!show_signin_view) { |
| 324 [[signinViewController_ view] removeFromSuperview]; | 352 [[signinViewController_ view] removeFromSuperview]; |
| 325 signin_observer_bridge_.reset(); | |
| 326 signinViewController_.reset(); | 353 signinViewController_.reset(); |
| 327 [backgroundView_ setHidden:NO]; | 354 [backgroundView_ setHidden:NO]; |
| 328 return; | 355 return; |
| 329 } | 356 } |
| 330 | 357 |
| 331 [backgroundView_ setHidden:YES]; | 358 [backgroundView_ setHidden:YES]; |
| 332 signinViewController_.reset( | 359 signinViewController_.reset( |
| 333 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] | 360 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] |
| 334 cornerRadius:kBubbleCornerRadius | 361 cornerRadius:kBubbleCornerRadius |
| 335 delegate:signinDelegate]); | 362 delegate:signinDelegate]); |
| 336 signin_observer_bridge_.reset( | |
| 337 new app_list::SigninDelegateObserverBridge(self)); | |
| 338 [[self view] addSubview:[signinViewController_ view]]; | 363 [[self view] addSubview:[signinViewController_ view]]; |
| 339 } | 364 } |
| 340 | 365 |
| 341 - (app_list::SigninDelegate*)signinDelegate { | |
| 342 return delegate_ ? delegate_->GetSigninDelegate() : NULL; | |
| 343 } | |
| 344 | |
| 345 @end | 366 @end |
| OLD | NEW |