Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / views / examples / examples_main.cc
1 // Copyright 2012 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 "base/at_exit.h"
6 #include "base/command_line.h"
7 #include "base/files/file_path.h"
8 #include "base/i18n/icu_util.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/path_service.h"
11 #include "base/run_loop.h"
12 #include "ui/aura/env.h"
13 #include "ui/base/ime/input_method_initializer.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/compositor/test/in_process_context_factory.h"
16 #include "ui/gfx/screen.h"
17 #include "ui/gl/gl_surface.h"
18 #include "ui/views/examples/example_base.h"
19 #include "ui/views/examples/examples_window.h"
20 #include "ui/views/test/desktop_test_views_delegate.h"
21 #include "ui/wm/core/wm_state.h"
22
23 #if !defined(OS_CHROMEOS)
24 #include "ui/views/widget/desktop_aura/desktop_screen.h"
25 #endif
26
27 #if defined(OS_WIN)
28 #include "ui/base/win/scoped_ole_initializer.h"
29 #endif
30
31 #if defined(USE_X11)
32 #include "ui/gfx/x/x11_connection.h"
33 #endif
34
35 int main(int argc, char** argv) {
36 #if defined(OS_WIN)
37   ui::ScopedOleInitializer ole_initializer_;
38 #endif
39
40   CommandLine::Init(argc, argv);
41
42   base::AtExitManager at_exit;
43
44 #if defined(USE_X11)
45   // This demo uses InProcessContextFactory which uses X on a separate Gpu
46   // thread.
47   gfx::InitializeThreadedX11();
48 #endif
49
50   gfx::GLSurface::InitializeOneOff();
51
52   // The ContextFactory must exist before any Compositors are created.
53   scoped_ptr<ui::InProcessContextFactory> context_factory(
54       new ui::InProcessContextFactory());
55   ui::ContextFactory::SetInstance(context_factory.get());
56
57   base::MessageLoopForUI message_loop;
58
59   base::i18n::InitializeICU();
60
61   base::FilePath pak_dir;
62   PathService::Get(base::DIR_MODULE, &pak_dir);
63
64   base::FilePath pak_file;
65   pak_file = pak_dir.Append(FILE_PATH_LITERAL("ui_test.pak"));
66
67   ui::ResourceBundle::InitSharedInstanceWithPakPath(pak_file);
68
69   aura::Env::CreateInstance(true);
70
71   ui::InitializeInputMethodForTesting();
72
73   {
74     views::DesktopTestViewsDelegate views_delegate;
75     wm::WMState wm_state;
76
77 #if !defined(OS_CHROMEOS)
78     scoped_ptr<gfx::Screen> desktop_screen(views::CreateDesktopScreen());
79     gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE,
80                                    desktop_screen.get());
81 #endif
82
83     views::examples::ShowExamplesWindow(
84         views::examples::QUIT_ON_CLOSE,
85         NULL,
86         scoped_ptr<ScopedVector<views::examples::ExampleBase> >());
87
88     base::RunLoop().Run();
89
90     ui::ResourceBundle::CleanupSharedInstance();
91   }
92
93   ui::ShutdownInputMethod();
94
95   aura::Env::DeleteInstance();
96
97   return 0;
98 }