| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "athena/main/public/athena_launcher.h" | |
| 6 | |
| 7 #include "athena/activity/public/activity_factory.h" | |
| 8 #include "athena/activity/public/activity_manager.h" | |
| 9 #include "athena/content/public/app_registry.h" | |
| 10 #include "athena/content/public/content_activity_factory_creator.h" | |
| 11 #include "athena/env/public/athena_env.h" | |
| 12 #include "athena/extensions/public/apps_search_controller_factory.h" | |
| 13 #include "athena/extensions/public/extension_app_model_builder.h" | |
| 14 #include "athena/extensions/public/extensions_delegate.h" | |
| 15 #include "athena/home/public/home_card.h" | |
| 16 #include "athena/home/public/search_controller_factory.h" | |
| 17 #include "athena/input/public/input_manager.h" | |
| 18 #include "athena/main/athena_views_delegate.h" | |
| 19 #include "athena/main/debug_accelerator_handler.h" | |
| 20 #include "athena/main/placeholder.h" | |
| 21 #include "athena/main/placeholder.h" | |
| 22 #include "athena/resource_manager/public/resource_manager.h" | |
| 23 #include "athena/screen/public/screen_manager.h" | |
| 24 #include "athena/screen_lock/public/screen_lock_manager.h" | |
| 25 #include "athena/system/public/system_ui.h" | |
| 26 #include "athena/virtual_keyboard/public/virtual_keyboard_manager.h" | |
| 27 #include "athena/wm/public/window_manager.h" | |
| 28 #include "base/command_line.h" | |
| 29 #include "base/memory/scoped_ptr.h" | |
| 30 #include "content/public/common/content_switches.h" | |
| 31 #include "ui/app_list/app_list_switches.h" | |
| 32 #include "ui/aura/window_property.h" | |
| 33 #include "ui/aura/window_tree_host.h" | |
| 34 #include "ui/keyboard/keyboard_controller.h" | |
| 35 #include "ui/keyboard/keyboard_controller_observer.h" | |
| 36 #include "ui/native_theme/native_theme_switches.h" | |
| 37 #include "ui/wm/core/visibility_controller.h" | |
| 38 | |
| 39 #if defined(USE_X11) | |
| 40 #include "ui/events/devices/x11/touch_factory_x11.h" | |
| 41 #endif | |
| 42 | |
| 43 namespace athena { | |
| 44 struct AthenaEnvState; | |
| 45 } | |
| 46 | |
| 47 DECLARE_WINDOW_PROPERTY_TYPE(athena::AthenaEnvState*); | |
| 48 | |
| 49 namespace athena { | |
| 50 | |
| 51 namespace { | |
| 52 | |
| 53 bool session_started = false; | |
| 54 | |
| 55 } // namespace | |
| 56 | |
| 57 class VirtualKeyboardObserver; | |
| 58 | |
| 59 // Athena's env state. | |
| 60 struct AthenaEnvState { | |
| 61 scoped_ptr< ::wm::VisibilityController> visibility_client; | |
| 62 scoped_ptr<VirtualKeyboardObserver> virtual_keyboard_observer; | |
| 63 scoped_ptr<DebugAcceleratorHandler> debug_accelerator_handler; | |
| 64 }; | |
| 65 | |
| 66 DEFINE_OWNED_WINDOW_PROPERTY_KEY(athena::AthenaEnvState, | |
| 67 kAthenaEnvStateKey, | |
| 68 nullptr); | |
| 69 | |
| 70 // This class observes the change of the virtual keyboard and distribute the | |
| 71 // change to appropriate modules of athena. | |
| 72 // TODO(oshima): move the VK bounds logic to screen manager. | |
| 73 class VirtualKeyboardObserver : public keyboard::KeyboardControllerObserver { | |
| 74 public: | |
| 75 VirtualKeyboardObserver() { | |
| 76 keyboard::KeyboardController::GetInstance()->AddObserver(this); | |
| 77 } | |
| 78 | |
| 79 ~VirtualKeyboardObserver() override { | |
| 80 keyboard::KeyboardController::GetInstance()->RemoveObserver(this); | |
| 81 } | |
| 82 | |
| 83 private: | |
| 84 virtual void OnKeyboardBoundsChanging(const gfx::Rect& new_bounds) override { | |
| 85 HomeCard::Get()->UpdateVirtualKeyboardBounds(new_bounds); | |
| 86 } | |
| 87 | |
| 88 DISALLOW_COPY_AND_ASSIGN(VirtualKeyboardObserver); | |
| 89 }; | |
| 90 | |
| 91 void StartAthenaEnv(scoped_refptr<base::TaskRunner> blocking_task_runner) { | |
| 92 athena::AthenaEnv::Create(); | |
| 93 | |
| 94 base::CommandLine* command_line = base::CommandLine::ForCurrentProcess(); | |
| 95 | |
| 96 // Force showing in the experimental app-list view. | |
| 97 command_line->AppendSwitch(app_list::switches::kEnableExperimentalAppList); | |
| 98 command_line->AppendSwitch(switches::kEnableOverlayScrollbar); | |
| 99 | |
| 100 // Enable vertical overscroll. | |
| 101 command_line->AppendSwitchASCII(switches::kScrollEndEffect, "1"); | |
| 102 | |
| 103 #if defined(USE_X11) | |
| 104 ui::TouchFactory::SetTouchDeviceListFromCommandLine(); | |
| 105 #endif | |
| 106 | |
| 107 CreateAthenaViewsDelegate(); | |
| 108 | |
| 109 AthenaEnvState* env_state = new AthenaEnvState; | |
| 110 | |
| 111 // Setup VisibilityClient | |
| 112 env_state->visibility_client.reset(new ::wm::VisibilityController); | |
| 113 aura::Window* root_window = athena::AthenaEnv::Get()->GetHost()->window(); | |
| 114 | |
| 115 aura::client::SetVisibilityClient(root_window, | |
| 116 env_state->visibility_client.get()); | |
| 117 | |
| 118 athena::InputManager::Create()->OnRootWindowCreated(root_window); | |
| 119 athena::ScreenManager::Create(root_window); | |
| 120 athena::WindowManager::Create(); | |
| 121 athena::SystemUI::Create(blocking_task_runner); | |
| 122 athena::AppRegistry::Create(); | |
| 123 SetupBackgroundImage(); | |
| 124 | |
| 125 env_state->debug_accelerator_handler.reset( | |
| 126 new DebugAcceleratorHandler(root_window)); | |
| 127 | |
| 128 athena::ScreenManager::Get()->GetContext()->SetProperty( | |
| 129 kAthenaEnvStateKey, env_state); | |
| 130 } | |
| 131 | |
| 132 void CreateVirtualKeyboardWithContext(content::BrowserContext* context) { | |
| 133 athena::VirtualKeyboardManager::Create(context); | |
| 134 } | |
| 135 | |
| 136 void StartAthenaSessionWithContext(content::BrowserContext* context) { | |
| 137 athena::ScreenLockManager::Create(); | |
| 138 athena::ExtensionsDelegate::CreateExtensionsDelegate(context); | |
| 139 StartAthenaSession( | |
| 140 athena::CreateContentActivityFactory(), | |
| 141 make_scoped_ptr(new athena::ExtensionAppModelBuilder(context)), | |
| 142 athena::CreateSearchControllerFactory(context)); | |
| 143 AthenaEnvState* env_state = | |
| 144 athena::ScreenManager::Get()->GetContext()->GetProperty( | |
| 145 kAthenaEnvStateKey); | |
| 146 | |
| 147 env_state->virtual_keyboard_observer.reset(new VirtualKeyboardObserver); | |
| 148 CreateTestPages(context); | |
| 149 } | |
| 150 | |
| 151 void StartAthenaSession( | |
| 152 athena::ActivityFactory* activity_factory, | |
| 153 scoped_ptr<athena::AppModelBuilder> app_model_builder, | |
| 154 scoped_ptr<athena::SearchControllerFactory> search_factory) { | |
| 155 DCHECK(!session_started); | |
| 156 session_started = true; | |
| 157 athena::HomeCard::Create(app_model_builder.Pass(), search_factory.Pass()); | |
| 158 athena::ActivityManager::Create(); | |
| 159 athena::ResourceManager::Create(); | |
| 160 athena::ActivityFactory::RegisterActivityFactory(activity_factory); | |
| 161 } | |
| 162 | |
| 163 void ShutdownAthena() { | |
| 164 if (session_started) { | |
| 165 athena::ActivityFactory::Shutdown(); | |
| 166 athena::ResourceManager::Shutdown(); | |
| 167 athena::ActivityManager::Shutdown(); | |
| 168 athena::HomeCard::Shutdown(); | |
| 169 athena::ExtensionsDelegate::Shutdown(); | |
| 170 athena::ScreenLockManager::Shutdown(); | |
| 171 session_started = false; | |
| 172 } | |
| 173 athena::AppRegistry::ShutDown(); | |
| 174 athena::SystemUI::Shutdown(); | |
| 175 athena::WindowManager::Shutdown(); | |
| 176 athena::ScreenManager::Shutdown(); | |
| 177 athena::InputManager::Shutdown(); | |
| 178 athena::AthenaEnv::Shutdown(); | |
| 179 | |
| 180 ShutdownAthenaViewsDelegate(); | |
| 181 } | |
| 182 | |
| 183 } // namespace athena | |
| OLD | NEW |