Chromium Code Reviews| Index: chrome/browser/ui/app_list/launcher_page_event_dispatcher_views.cc |
| diff --git a/chrome/browser/ui/app_list/launcher_page_event_dispatcher_views.cc b/chrome/browser/ui/app_list/launcher_page_event_dispatcher_views.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..94815cb6e66ba464a3a50e9d84662bd6de005528 |
| --- /dev/null |
| +++ b/chrome/browser/ui/app_list/launcher_page_event_dispatcher_views.cc |
| @@ -0,0 +1,104 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/app_list/launcher_page_event_dispatcher_views.h" |
| + |
| +#include "ash/shell.h" |
| +#include "base/basictypes.h" |
| +#include "base/values.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/ui/app_list/app_list_service.h" |
| +#include "chrome/browser/ui/app_list/app_list_service_views.h" |
| +#include "chrome/common/extensions/api/launcher_page_private.h" |
| +#include "extensions/browser/event_router.h" |
| +#include "ui/app_list/app_list_model.h" |
| +#include "ui/app_list/pagination_model.h" |
| +#include "ui/app_list/views/app_list_view.h" |
| +#include "ui/app_list/views/contents_view.h" |
| + |
| +namespace OnTransitionChanged = |
| + extensions::api::launcher_page_private::OnTransitionChanged; |
| + |
| +namespace app_list { |
| + |
| +LauncherPageEventDispatcherViews::LauncherPageEventDispatcherViews( |
| + chrome::HostDesktopType host_desktop, |
| + Profile* profile, |
| + const std::string& extension_id) |
| + : profile_(profile), extension_id_(extension_id), main_view_(nullptr) { |
| + AppListView* app_list_view = nullptr; |
| + if (host_desktop == chrome::HOST_DESKTOP_TYPE_ASH) { |
| + app_list_view = ash::Shell::GetInstance()->GetAppListView(); |
|
tapted
2014/11/03 00:31:20
ash::Shell shouldn't be used here - Mac will need
calamity
2014/11/06 02:36:31
Done.
|
| + } else { |
| + AppListServiceViews* service = |
| + static_cast<AppListServiceViews*>(AppListService::Get(host_desktop)); |
| + app_list_view = service->shower().app_list(); |
| + } |
| + CHECK(app_list_view); |
| + main_view_ = app_list_view->app_list_main_view(); |
| + main_view_->AddObserver(this); |
| + main_view_->contents_view()->pagination_model()->AddObserver(this); |
|
Matt Giuca
2014/11/03 00:57:41
It might be worth adding a note here about why all
calamity
2014/11/06 02:36:31
Code is gone.
|
| +} |
| + |
| +LauncherPageEventDispatcherViews::~LauncherPageEventDispatcherViews() { |
| + main_view_->RemoveObserver(this); |
| + main_view_->contents_view()->pagination_model()->RemoveObserver(this); |
|
Matt Giuca
2014/11/03 00:57:41
Should there be null checks on contents_view() eve
calamity
2014/11/06 02:36:31
Code is gone.
|
| +} |
| + |
| +void LauncherPageEventDispatcherViews::SendEventToLauncherPage( |
| + const std::string& event_name, |
| + scoped_ptr<base::ListValue> args) { |
| + scoped_ptr<extensions::Event> event( |
| + new extensions::Event(event_name, args.Pass())); |
| + extensions::EventRouter::Get(profile_) |
| + ->DispatchEventToExtension(extension_id_, event.Pass()); |
| +} |
| + |
| +void LauncherPageEventDispatcherViews::SelectedPageChanged(int old_selected, |
| + int new_selected) { |
| + ContentsView* contents_view = main_view_->contents_view(); |
| + if (contents_view->GetStateForPageIndex(old_selected) == |
| + AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) { |
| + SendEventToLauncherPage(OnTransitionChanged::kEventName, |
| + OnTransitionChanged::Create(0)); |
| + } else if (contents_view->GetStateForPageIndex(new_selected) == |
| + AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) { |
| + SendEventToLauncherPage(OnTransitionChanged::kEventName, |
| + OnTransitionChanged::Create(1)); |
| + } |
| +} |
| + |
| +void LauncherPageEventDispatcherViews::TransitionStarted() { |
| +} |
| + |
| +void LauncherPageEventDispatcherViews::TransitionChanged() { |
| + ContentsView* contents_view = main_view_->contents_view(); |
|
Matt Giuca
2014/11/03 00:57:42
Null check here? (Maybe not necessary as in the de
calamity
2014/11/06 02:36:31
Code is gone.
|
| + PaginationModel* pagination_model = contents_view->pagination_model(); |
| + const PaginationModel::Transition& transition = |
| + pagination_model->transition(); |
| + app_list::AppListModel::State old_state = |
| + contents_view->GetStateForPageIndex(pagination_model->selected_page()); |
| + app_list::AppListModel::State new_state = |
| + contents_view->GetStateForPageIndex(transition.target_page); |
| + double progress = 0; |
| + if (old_state == AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) |
| + progress = 1 - transition.progress; |
| + else if (new_state == AppListModel::STATE_CUSTOM_LAUNCHER_PAGE) |
| + progress = transition.progress; |
| + else |
| + return; |
| + |
| + SendEventToLauncherPage(OnTransitionChanged::kEventName, |
| + OnTransitionChanged::Create(progress)); |
| +} |
| + |
| +void LauncherPageEventDispatcherViews::OnContentsViewCreated() { |
| + main_view_->contents_view()->pagination_model()->AddObserver(this); |
| +} |
| + |
| +void LauncherPageEventDispatcherViews::OnContentsViewDestroying() { |
| + main_view_->contents_view()->pagination_model()->RemoveObserver(this); |
| +} |
| + |
| +} // namespace app_list |