Chromium Code Reviews| 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 "skia/ext/skia_utils_mac.h" | 9 #include "skia/ext/skia_utils_mac.h" |
| 10 #include "ui/app_list/app_list_constants.h" | 10 #include "ui/app_list/app_list_constants.h" |
| 11 #include "ui/app_list/app_list_model.h" | 11 #include "ui/app_list/app_list_model.h" |
| 12 #include "ui/app_list/app_list_model_observer.h" | |
| 12 #include "ui/app_list/app_list_view_delegate.h" | 13 #include "ui/app_list/app_list_view_delegate.h" |
| 13 #include "ui/app_list/signin_delegate.h" | 14 #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" | 15 #import "ui/app_list/cocoa/app_list_pager_view.h" |
| 16 #import "ui/app_list/cocoa/apps_grid_controller.h" | 16 #import "ui/app_list/cocoa/apps_grid_controller.h" |
| 17 #import "ui/app_list/cocoa/signin_view_controller.h" | 17 #import "ui/app_list/cocoa/signin_view_controller.h" |
| 18 #import "ui/base/cocoa/flipped_view.h" | 18 #import "ui/base/cocoa/flipped_view.h" |
| 19 #include "ui/app_list/search_box_model.h" | 19 #include "ui/app_list/search_box_model.h" |
| 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 20 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 21 | 21 |
| 22 namespace { | 22 namespace { |
| 23 | 23 |
| 24 // The roundedness of the corners of the bubble. | 24 // 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]; | 68 [gfx::SkColorToSRGBNSColor(app_list::kTopSeparatorColor) set]; |
| 69 NSRectFill(separatorRect); | 69 NSRectFill(separatorRect); |
| 70 } | 70 } |
| 71 | 71 |
| 72 @end | 72 @end |
| 73 | 73 |
| 74 @interface AppListViewController () | 74 @interface AppListViewController () |
| 75 | 75 |
| 76 - (void)loadAndSetView; | 76 - (void)loadAndSetView; |
| 77 - (void)revealSearchResults:(BOOL)show; | 77 - (void)revealSearchResults:(BOOL)show; |
| 78 - (app_list::SigninDelegate*)signinDelegate; | 78 - (app_list::SigninDelegate*)signinDelegate; |
|
tapted
2013/08/14 03:53:11
Remove this function?
calamity
2013/08/14 09:19:00
Done.
| |
| 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(AppListModel* model, |
| 87 : parent_(parent) { | 87 AppListViewController* parent); |
| 88 [parent_ signinDelegate]->AddObserver(this); | 88 virtual ~AppListModelObserverBridge(); |
| 89 } | |
| 90 | |
| 91 virtual ~SigninDelegateObserverBridge() { | |
| 92 [parent_ signinDelegate]->RemoveObserver(this); | |
| 93 } | |
| 94 | 89 |
| 95 private: | 90 private: |
| 96 // SigninDelegateObserver override: | 91 // Overridden from app_list::AppListModelObserver: |
| 97 virtual void OnSigninSuccess() OVERRIDE { | 92 virtual void OnAppListModelCurrentUserChanged() OVERRIDE; |
| 98 [parent_ onSigninStatusChanged]; | 93 virtual void OnAppListModelSigninStatusChanged() OVERRIDE; |
| 99 } | |
| 100 | 94 |
| 95 AppListModel* model_; | |
|
tapted
2013/08/14 03:53:11
prevailing style on the Cocoa side is to not cache
calamity
2013/08/14 09:19:00
Done.
| |
| 101 AppListViewController* parent_; // Weak. Owns us. | 96 AppListViewController* parent_; // Weak. Owns us. |
| 102 | 97 |
| 103 DISALLOW_COPY_AND_ASSIGN(SigninDelegateObserverBridge); | 98 DISALLOW_COPY_AND_ASSIGN(AppListModelObserverBridge); |
| 104 }; | 99 }; |
| 105 | 100 |
| 101 AppListModelObserverBridge::AppListModelObserverBridge( | |
| 102 AppListModel* model, AppListViewController* parent) | |
| 103 : model_(model), parent_(parent) { | |
| 104 model_->AddObserver(this); | |
| 105 } | |
| 106 | |
| 107 AppListModelObserverBridge::~AppListModelObserverBridge() { | |
| 108 model_->RemoveObserver(this); | |
| 109 } | |
| 110 | |
| 111 void AppListModelObserverBridge::OnAppListModelCurrentUserChanged() { | |
| 112 [parent_ onSigninStatusChanged]; | |
| 113 } | |
| 114 | |
| 115 void AppListModelObserverBridge::OnAppListModelSigninStatusChanged() { | |
| 116 [parent_ onSigninStatusChanged]; | |
| 117 } | |
| 118 | |
| 106 } // namespace app_list | 119 } // namespace app_list |
| 107 | 120 |
| 108 @implementation AppListViewController | 121 @implementation AppListViewController |
| 109 | 122 |
| 110 - (id)init { | 123 - (id)init { |
| 111 if ((self = [super init])) { | 124 if ((self = [super init])) { |
| 112 appsGridController_.reset([[AppsGridController alloc] init]); | 125 appsGridController_.reset([[AppsGridController alloc] init]); |
| 113 [self loadAndSetView]; | 126 [self loadAndSetView]; |
| 114 | 127 |
| 115 [self totalPagesChanged]; | 128 [self totalPagesChanged]; |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 141 } | 154 } |
| 142 | 155 |
| 143 - (app_list::AppListViewDelegate*)delegate { | 156 - (app_list::AppListViewDelegate*)delegate { |
| 144 return delegate_.get(); | 157 return delegate_.get(); |
| 145 } | 158 } |
| 146 | 159 |
| 147 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate | 160 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate |
| 148 withTestModel:(scoped_ptr<app_list::AppListModel>)newModel { | 161 withTestModel:(scoped_ptr<app_list::AppListModel>)newModel { |
| 149 if (delegate_) { | 162 if (delegate_) { |
| 150 // First clean up, in reverse order. | 163 // First clean up, in reverse order. |
| 151 signin_observer_bridge_.reset(); | 164 app_list_model_observer_bridge_.reset(); |
| 152 [appsSearchResultsController_ setDelegate:nil]; | 165 [appsSearchResultsController_ setDelegate:nil]; |
| 153 [appsSearchBoxController_ setDelegate:nil]; | 166 [appsSearchBoxController_ setDelegate:nil]; |
| 154 } | 167 } |
| 155 delegate_.reset(newDelegate.release()); | 168 delegate_.reset(newDelegate.release()); |
| 156 [appsGridController_ setDelegate:delegate_.get()]; | 169 [appsGridController_ setDelegate:delegate_.get()]; |
| 157 if (newModel.get()) | 170 if (newModel.get()) |
| 158 [appsGridController_ setModel:newModel.Pass()]; | 171 [appsGridController_ setModel:newModel.Pass()]; |
| 159 [appsSearchBoxController_ setDelegate:self]; | 172 [appsSearchBoxController_ setDelegate:self]; |
| 160 [appsSearchResultsController_ setDelegate:self]; | 173 [appsSearchResultsController_ setDelegate:self]; |
| 174 app_list_model_observer_bridge_.reset( | |
| 175 new app_list::AppListModelObserverBridge( | |
| 176 [appsGridController_ model], self)); | |
| 161 [self onSigninStatusChanged]; | 177 [self onSigninStatusChanged]; |
| 162 } | 178 } |
| 163 | 179 |
| 164 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { | 180 - (void)setDelegate:(scoped_ptr<app_list::AppListViewDelegate>)newDelegate { |
| 165 [self setDelegate:newDelegate.Pass() | 181 [self setDelegate:newDelegate.Pass() |
| 166 withTestModel:scoped_ptr<app_list::AppListModel>()]; | 182 withTestModel:scoped_ptr<app_list::AppListModel>()]; |
| 167 } | 183 } |
| 168 | 184 |
| 169 -(void)loadAndSetView { | 185 -(void)loadAndSetView { |
| 170 pagerControl_.reset([[AppListPagerView alloc] init]); | 186 pagerControl_.reset([[AppListPagerView alloc] init]); |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 delegate_->OpenSearchResult(result, 0 /* event flags */); | 330 delegate_->OpenSearchResult(result, 0 /* event flags */); |
| 315 | 331 |
| 316 [appsSearchBoxController_ clearSearch]; | 332 [appsSearchBoxController_ clearSearch]; |
| 317 } | 333 } |
| 318 | 334 |
| 319 - (void)onSigninStatusChanged { | 335 - (void)onSigninStatusChanged { |
| 320 app_list::SigninDelegate* signinDelegate = [self signinDelegate]; | 336 app_list::SigninDelegate* signinDelegate = [self signinDelegate]; |
| 321 BOOL needsSignin = signinDelegate && signinDelegate->NeedSignin(); | 337 BOOL needsSignin = signinDelegate && signinDelegate->NeedSignin(); |
| 322 if (!needsSignin) { | 338 if (!needsSignin) { |
| 323 [[signinViewController_ view] removeFromSuperview]; | 339 [[signinViewController_ view] removeFromSuperview]; |
| 324 signin_observer_bridge_.reset(); | |
| 325 signinViewController_.reset(); | 340 signinViewController_.reset(); |
| 326 [backgroundView_ setHidden:NO]; | 341 [backgroundView_ setHidden:NO]; |
| 327 return; | 342 return; |
| 328 } | 343 } |
| 329 | 344 |
| 330 [backgroundView_ setHidden:YES]; | 345 [backgroundView_ setHidden:YES]; |
| 331 signinViewController_.reset( | 346 signinViewController_.reset( |
| 332 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] | 347 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] |
| 333 cornerRadius:kBubbleCornerRadius | 348 cornerRadius:kBubbleCornerRadius |
| 334 delegate:signinDelegate]); | 349 delegate:signinDelegate]); |
| 335 signin_observer_bridge_.reset( | |
| 336 new app_list::SigninDelegateObserverBridge(self)); | |
| 337 [[self view] addSubview:[signinViewController_ view]]; | 350 [[self view] addSubview:[signinViewController_ view]]; |
| 338 } | 351 } |
| 339 | 352 |
| 340 - (app_list::SigninDelegate*)signinDelegate { | 353 - (app_list::SigninDelegate*)signinDelegate { |
| 341 return delegate_ ? delegate_->GetSigninDelegate() : NULL; | 354 return delegate_ ? delegate_->GetSigninDelegate() : NULL; |
| 342 } | 355 } |
| 343 | 356 |
| 357 - (const base::string16&)currentUserName { | |
|
tapted
2013/08/14 03:53:11
nit: These should be grouped with the other protoc
calamity
2013/08/14 09:19:00
Done.
| |
| 358 return [appsGridController_ model]->current_user_name(); | |
| 359 } | |
| 360 | |
| 361 - (const base::string16&)currentUserEmail { | |
| 362 return [appsGridController_ model]->current_user_email(); | |
| 363 } | |
| 364 | |
| 344 @end | 365 @end |
| OLD | NEW |