| 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 "base/strings/sys_string_conversions.h" |
| 10 #include "skia/ext/skia_utils_mac.h" | 10 #include "skia/ext/skia_utils_mac.h" |
| (...skipping 25 matching lines...) Expand all Loading... |
| 36 | 36 |
| 37 // Minimum margin on either side of the pager. If the pager grows beyond this, | 37 // Minimum margin on either side of the pager. If the pager grows beyond this, |
| 38 // the segment size is reduced. | 38 // the segment size is reduced. |
| 39 const CGFloat kMinPagerMargin = 40; | 39 const CGFloat kMinPagerMargin = 40; |
| 40 // Maximum width of a single segment. | 40 // Maximum width of a single segment. |
| 41 const CGFloat kMaxSegmentWidth = 80; | 41 const CGFloat kMaxSegmentWidth = 80; |
| 42 | 42 |
| 43 // Duration of the animation for sliding in and out search results. | 43 // Duration of the animation for sliding in and out search results. |
| 44 const NSTimeInterval kResultsAnimationDuration = 0.2; | 44 const NSTimeInterval kResultsAnimationDuration = 0.2; |
| 45 | 45 |
| 46 app_list::AppListModel::User* CurrentUser(app_list::AppListModel* model) { |
| 47 app_list::AppListModel::Users::const_iterator it = model->users().begin(); |
| 48 for (; it != model->users().end(); ++it) { |
| 49 if ((*it)->active) |
| 50 return *it; |
| 51 } |
| 52 NOTREACHED(); |
| 53 return NULL; |
| 54 } |
| 55 |
| 46 } // namespace | 56 } // namespace |
| 47 | 57 |
| 48 @interface BackgroundView : FlippedView; | 58 @interface BackgroundView : FlippedView; |
| 49 @end | 59 @end |
| 50 | 60 |
| 51 @implementation BackgroundView | 61 @implementation BackgroundView |
| 52 | 62 |
| 53 - (void)drawRect:(NSRect)dirtyRect { | 63 - (void)drawRect:(NSRect)dirtyRect { |
| 54 gfx::ScopedNSGraphicsContextSaveGState context; | 64 gfx::ScopedNSGraphicsContextSaveGState context; |
| 55 NSRect boundsRect = [self bounds]; | 65 NSRect boundsRect = [self bounds]; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 81 | 91 |
| 82 namespace app_list { | 92 namespace app_list { |
| 83 | 93 |
| 84 class AppListModelObserverBridge : public AppListModelObserver { | 94 class AppListModelObserverBridge : public AppListModelObserver { |
| 85 public: | 95 public: |
| 86 AppListModelObserverBridge(AppListViewController* parent); | 96 AppListModelObserverBridge(AppListViewController* parent); |
| 87 virtual ~AppListModelObserverBridge(); | 97 virtual ~AppListModelObserverBridge(); |
| 88 | 98 |
| 89 private: | 99 private: |
| 90 // Overridden from app_list::AppListModelObserver: | 100 // Overridden from app_list::AppListModelObserver: |
| 91 virtual void OnAppListModelCurrentUserChanged() OVERRIDE; | 101 virtual void OnAppListModelUsersChanged() OVERRIDE; |
| 92 virtual void OnAppListModelSigninStatusChanged() OVERRIDE; | 102 virtual void OnAppListModelSigninStatusChanged() OVERRIDE; |
| 93 | 103 |
| 94 AppListViewController* parent_; // Weak. Owns us. | 104 AppListViewController* parent_; // Weak. Owns us. |
| 95 | 105 |
| 96 DISALLOW_COPY_AND_ASSIGN(AppListModelObserverBridge); | 106 DISALLOW_COPY_AND_ASSIGN(AppListModelObserverBridge); |
| 97 }; | 107 }; |
| 98 | 108 |
| 99 AppListModelObserverBridge::AppListModelObserverBridge( | 109 AppListModelObserverBridge::AppListModelObserverBridge( |
| 100 AppListViewController* parent) | 110 AppListViewController* parent) |
| 101 : parent_(parent) { | 111 : parent_(parent) { |
| 102 [[parent_ appsGridController] model]->AddObserver(this); | 112 [[parent_ appsGridController] model]->AddObserver(this); |
| 103 } | 113 } |
| 104 | 114 |
| 105 AppListModelObserverBridge::~AppListModelObserverBridge() { | 115 AppListModelObserverBridge::~AppListModelObserverBridge() { |
| 106 [[parent_ appsGridController] model]->RemoveObserver(this); | 116 [[parent_ appsGridController] model]->RemoveObserver(this); |
| 107 } | 117 } |
| 108 | 118 |
| 109 void AppListModelObserverBridge::OnAppListModelCurrentUserChanged() { | 119 void AppListModelObserverBridge::OnAppListModelUsersChanged() { |
| 110 [parent_ onSigninStatusChanged]; | 120 [parent_ onSigninStatusChanged]; |
| 111 } | 121 } |
| 112 | 122 |
| 113 void AppListModelObserverBridge::OnAppListModelSigninStatusChanged() { | 123 void AppListModelObserverBridge::OnAppListModelSigninStatusChanged() { |
| 114 [parent_ onSigninStatusChanged]; | 124 [parent_ onSigninStatusChanged]; |
| 115 } | 125 } |
| 116 | 126 |
| 117 } // namespace app_list | 127 } // namespace app_list |
| 118 | 128 |
| 119 @implementation AppListViewController | 129 @implementation AppListViewController |
| (...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 317 else | 327 else |
| 318 delegate_->StopSearch(); | 328 delegate_->StopSearch(); |
| 319 } | 329 } |
| 320 | 330 |
| 321 - (app_list::AppListModel*)appListModel { | 331 - (app_list::AppListModel*)appListModel { |
| 322 return [appsGridController_ model]; | 332 return [appsGridController_ model]; |
| 323 } | 333 } |
| 324 | 334 |
| 325 - (NSString*)currentUserName { | 335 - (NSString*)currentUserName { |
| 326 return base::SysUTF16ToNSString( | 336 return base::SysUTF16ToNSString( |
| 327 [appsGridController_ model]->current_user_name()); | 337 CurrentUser([appsGridController_ model])->name); |
| 328 } | 338 } |
| 329 | 339 |
| 330 - (NSString*)currentUserEmail { | 340 - (NSString*)currentUserEmail { |
| 331 return base::SysUTF16ToNSString( | 341 return base::SysUTF16ToNSString( |
| 332 [appsGridController_ model]->current_user_email()); | 342 CurrentUser([appsGridController_ model])->email); |
| 333 } | 343 } |
| 334 | 344 |
| 335 - (void)openResult:(app_list::SearchResult*)result { | 345 - (void)openResult:(app_list::SearchResult*)result { |
| 336 if (delegate_) | 346 if (delegate_) |
| 337 delegate_->OpenSearchResult(result, 0 /* event flags */); | 347 delegate_->OpenSearchResult(result, 0 /* event flags */); |
| 338 | 348 |
| 339 [appsSearchBoxController_ clearSearch]; | 349 [appsSearchBoxController_ clearSearch]; |
| 340 } | 350 } |
| 341 | 351 |
| 342 - (void)redoSearch { | 352 - (void)redoSearch { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 361 | 371 |
| 362 [backgroundView_ setHidden:YES]; | 372 [backgroundView_ setHidden:YES]; |
| 363 signinViewController_.reset( | 373 signinViewController_.reset( |
| 364 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] | 374 [[SigninViewController alloc] initWithFrame:[backgroundView_ frame] |
| 365 cornerRadius:kBubbleCornerRadius | 375 cornerRadius:kBubbleCornerRadius |
| 366 delegate:signinDelegate]); | 376 delegate:signinDelegate]); |
| 367 [[self view] addSubview:[signinViewController_ view]]; | 377 [[self view] addSubview:[signinViewController_ view]]; |
| 368 } | 378 } |
| 369 | 379 |
| 370 @end | 380 @end |
| OLD | NEW |