| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "ui/app_list/views/app_list_view.h" | 5 #include "ui/app_list/views/app_list_view.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "ui/app_list/app_list_constants.h" | 9 #include "ui/app_list/app_list_constants.h" |
| 10 #include "ui/app_list/app_list_model.h" | 10 #include "ui/app_list/app_list_model.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
| 45 // AppListView: | 45 // AppListView: |
| 46 | 46 |
| 47 AppListView::AppListView(AppListViewDelegate* delegate) | 47 AppListView::AppListView(AppListViewDelegate* delegate) |
| 48 : model_(new AppListModel), | 48 : model_(new AppListModel), |
| 49 delegate_(delegate), | 49 delegate_(delegate), |
| 50 app_list_main_view_(NULL), | 50 app_list_main_view_(NULL), |
| 51 signin_view_(NULL) { | 51 signin_view_(NULL) { |
| 52 if (delegate_) | 52 if (delegate_) |
| 53 delegate_->SetModel(model_.get()); | 53 delegate_->InitModel(model_.get()); |
| 54 if (GetSigninDelegate()) | 54 model_->AddObserver(this); |
| 55 GetSigninDelegate()->AddObserver(this); | |
| 56 } | 55 } |
| 57 | 56 |
| 58 AppListView::~AppListView() { | 57 AppListView::~AppListView() { |
| 59 if (GetSigninDelegate()) | 58 model_->RemoveObserver(this); |
| 60 GetSigninDelegate()->RemoveObserver(this); | |
| 61 | |
| 62 // Models are going away, ensure their references are cleared. | 59 // Models are going away, ensure their references are cleared. |
| 63 RemoveAllChildViews(true); | 60 RemoveAllChildViews(true); |
| 64 } | 61 } |
| 65 | 62 |
| 66 void AppListView::InitAsBubble(gfx::NativeView parent, | 63 void AppListView::InitAsBubble(gfx::NativeView parent, |
| 67 PaginationModel* pagination_model, | 64 PaginationModel* pagination_model, |
| 68 views::View* anchor, | 65 views::View* anchor, |
| 69 const gfx::Point& anchor_point, | 66 const gfx::Point& anchor_point, |
| 70 views::BubbleBorder::Arrow arrow, | 67 views::BubbleBorder::Arrow arrow, |
| 71 bool border_accepts_events) { | 68 bool border_accepts_events) { |
| 72 app_list_main_view_ = new AppListMainView(delegate_.get(), | 69 app_list_main_view_ = new AppListMainView(delegate_.get(), |
| 73 model_.get(), | 70 model_.get(), |
| 74 pagination_model, | 71 pagination_model, |
| 75 anchor); | 72 anchor); |
| 76 AddChildView(app_list_main_view_); | 73 AddChildView(app_list_main_view_); |
| 77 #if defined(USE_AURA) | 74 #if defined(USE_AURA) |
| 78 app_list_main_view_->SetPaintToLayer(true); | 75 app_list_main_view_->SetPaintToLayer(true); |
| 79 app_list_main_view_->SetFillsBoundsOpaquely(false); | 76 app_list_main_view_->SetFillsBoundsOpaquely(false); |
| 80 app_list_main_view_->layer()->SetMasksToBounds(true); | 77 app_list_main_view_->layer()->SetMasksToBounds(true); |
| 81 #endif | 78 #endif |
| 82 | 79 |
| 83 signin_view_ = new SigninView( | 80 signin_view_ = new SigninView( |
| 84 GetSigninDelegate(), | 81 delegate_ ? delegate_->GetSigninDelegate() |
| 82 : NULL, |
| 85 app_list_main_view_->GetPreferredSize().width()); | 83 app_list_main_view_->GetPreferredSize().width()); |
| 86 AddChildView(signin_view_); | 84 AddChildView(signin_view_); |
| 87 | 85 |
| 88 OnSigninStatusChanged(); | 86 OnSigninStatusChanged(); |
| 89 | 87 |
| 90 set_anchor_view(anchor); | 88 set_anchor_view(anchor); |
| 91 set_anchor_rect(gfx::Rect(anchor_point, gfx::Size())); | 89 set_anchor_rect(gfx::Rect(anchor_point, gfx::Size())); |
| 92 set_color(kContentsBackgroundColor); | 90 set_color(kContentsBackgroundColor); |
| 93 set_margins(gfx::Insets()); | 91 set_margins(gfx::Insets()); |
| 94 set_move_with_anchor(true); | 92 set_move_with_anchor(true); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 167 | 165 |
| 168 bool AppListView::ShouldHandleSystemCommands() const { | 166 bool AppListView::ShouldHandleSystemCommands() const { |
| 169 return true; | 167 return true; |
| 170 } | 168 } |
| 171 | 169 |
| 172 void AppListView::Prerender() { | 170 void AppListView::Prerender() { |
| 173 app_list_main_view_->Prerender(); | 171 app_list_main_view_->Prerender(); |
| 174 } | 172 } |
| 175 | 173 |
| 176 void AppListView::OnSigninStatusChanged() { | 174 void AppListView::OnSigninStatusChanged() { |
| 177 const bool needs_signin = | 175 signin_view_->SetVisible(!model_->signed_in()); |
| 178 GetSigninDelegate() && GetSigninDelegate()->NeedSignin(); | 176 app_list_main_view_->SetVisible(model_->signed_in()); |
| 179 | |
| 180 signin_view_->SetVisible(needs_signin); | |
| 181 app_list_main_view_->SetVisible(!needs_signin); | |
| 182 app_list_main_view_->search_box_view()->InvalidateMenu(); | 177 app_list_main_view_->search_box_view()->InvalidateMenu(); |
| 183 } | 178 } |
| 184 | 179 |
| 185 views::View* AppListView::GetInitiallyFocusedView() { | 180 views::View* AppListView::GetInitiallyFocusedView() { |
| 186 return app_list_main_view_->search_box_view()->search_box(); | 181 return app_list_main_view_->search_box_view()->search_box(); |
| 187 } | 182 } |
| 188 | 183 |
| 189 gfx::ImageSkia AppListView::GetWindowIcon() { | 184 gfx::ImageSkia AppListView::GetWindowIcon() { |
| 190 if (delegate_) | 185 if (delegate_) |
| 191 return delegate_->GetWindowIcon(); | 186 return delegate_->GetWindowIcon(); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 248 // We clear the search when hiding so the next time the app list appears it is | 243 // We clear the search when hiding so the next time the app list appears it is |
| 249 // not showing search results. | 244 // not showing search results. |
| 250 if (!visible) | 245 if (!visible) |
| 251 app_list_main_view_->search_box_view()->ClearSearch(); | 246 app_list_main_view_->search_box_view()->ClearSearch(); |
| 252 | 247 |
| 253 // Whether we need to signin or not may have changed since last time we were | 248 // Whether we need to signin or not may have changed since last time we were |
| 254 // shown. | 249 // shown. |
| 255 Layout(); | 250 Layout(); |
| 256 } | 251 } |
| 257 | 252 |
| 258 void AppListView::OnSigninSuccess() { | 253 void AppListView::OnAppListModelSigninStatusChanged() { |
| 259 OnSigninStatusChanged(); | 254 OnSigninStatusChanged(); |
| 260 } | 255 } |
| 261 | 256 |
| 262 SigninDelegate* AppListView::GetSigninDelegate() { | 257 void AppListView::OnAppListModelProfilesChanged() { |
| 263 return delegate_ ? delegate_->GetSigninDelegate() : NULL; | 258 OnSigninStatusChanged(); |
| 264 } | 259 } |
| 265 | 260 |
| 266 } // namespace app_list | 261 } // namespace app_list |
| OLD | NEW |