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.
5 #include "content/public/browser/context_factory.h"
6 #include "content/shell/browser/shell_browser_context.h"
7 #include "ui/aura/test/test_screen.h"
8 #include "ui/aura/window.h"
9 #include "ui/gfx/screen.h"
10 #include "ui/views_content_client/views_content_client.h"
11 #include "ui/views_content_client/views_content_client_main_parts_aura.h"
12 #include "ui/wm/core/nested_accelerator_controller.h"
13 #include "ui/wm/core/nested_accelerator_delegate.h"
14 #include "ui/wm/test/wm_test_helper.h"
20 // A dummy version of the delegate usually provided by the Ash Shell.
21 class NestedAcceleratorDelegate
: public ::wm::NestedAcceleratorDelegate
{
23 NestedAcceleratorDelegate() {}
24 virtual ~NestedAcceleratorDelegate() {}
26 // ::wm::NestedAcceleratorDelegate:
27 virtual Result
ProcessAccelerator(
28 const ui::Accelerator
& accelerator
) OVERRIDE
{
29 return RESULT_NOT_PROCESSED
;
33 DISALLOW_COPY_AND_ASSIGN(NestedAcceleratorDelegate
);
36 class ViewsContentClientMainPartsChromeOS
37 : public ViewsContentClientMainPartsAura
{
39 ViewsContentClientMainPartsChromeOS(
40 const content::MainFunctionParams
& content_params
,
41 ViewsContentClient
* views_content_client
);
42 virtual ~ViewsContentClientMainPartsChromeOS() {}
44 // content::BrowserMainParts:
45 virtual void PreMainMessageLoopRun() OVERRIDE
;
46 virtual void PostMainMessageLoopRun() OVERRIDE
;
49 // Enable a minimal set of views::corewm to be initialized.
50 scoped_ptr
<gfx::Screen
> test_screen_
;
51 scoped_ptr
< ::wm::WMTestHelper
> wm_test_helper_
;
52 scoped_ptr
< ::wm::NestedAcceleratorController
> nested_accelerator_controller_
;
54 DISALLOW_COPY_AND_ASSIGN(ViewsContentClientMainPartsChromeOS
);
57 ViewsContentClientMainPartsChromeOS::ViewsContentClientMainPartsChromeOS(
58 const content::MainFunctionParams
& content_params
,
59 ViewsContentClient
* views_content_client
)
60 : ViewsContentClientMainPartsAura(content_params
, views_content_client
) {
63 void ViewsContentClientMainPartsChromeOS::PreMainMessageLoopRun() {
64 ViewsContentClientMainPartsAura::PreMainMessageLoopRun();
66 gfx::Size
host_size(800, 600);
67 test_screen_
.reset(aura::TestScreen::Create(host_size
));
68 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE
, test_screen_
.get());
69 // Set up basic pieces of views::corewm.
70 wm_test_helper_
.reset(
71 new ::wm::WMTestHelper(host_size
, content::GetContextFactory()));
72 // Ensure the X window gets mapped.
73 wm_test_helper_
->host()->Show();
75 // Ensure Aura knows where to open new windows.
76 aura::Window
* root_window
= wm_test_helper_
->host()->window();
77 views_content_client()->task().Run(browser_context(), root_window
);
79 nested_accelerator_controller_
.reset(
80 new ::wm::NestedAcceleratorController(new NestedAcceleratorDelegate
));
81 aura::client::SetDispatcherClient(root_window
,
82 nested_accelerator_controller_
.get());
85 void ViewsContentClientMainPartsChromeOS::PostMainMessageLoopRun() {
86 aura::client::SetDispatcherClient(wm_test_helper_
->host()->window(), NULL
);
87 nested_accelerator_controller_
.reset();
88 wm_test_helper_
.reset();
91 ViewsContentClientMainPartsAura::PostMainMessageLoopRun();
97 ViewsContentClientMainParts
* ViewsContentClientMainParts::Create(
98 const content::MainFunctionParams
& content_params
,
99 ViewsContentClient
* views_content_client
) {
100 return new ViewsContentClientMainPartsChromeOS(
101 content_params
, views_content_client
);