summaryrefslogtreecommitdiffstats
path: root/ui/views/examples/examples_main.cc
blob: cd48f6b01eae41b8b107997191e9e926ea61ce8b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Copyright (c) 2012 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 "base/at_exit.h"
#include "base/command_line.h"
#include "base/i18n/icu_util.h"
#include "base/logging.h"
#include "base/message_loop.h"
#include "base/process_util.h"
#include "base/stl_util.h"
#include "base/utf_string_conversions.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/base/ui_base_paths.h"
#include "ui/views/examples/examples_window.h"
#include "ui/views/focus/accelerator_handler.h"
#include "ui/views/test/test_views_delegate.h"
#include "ui/views/widget/widget.h"

#if defined(OS_WIN)
#include "ui/base/win/scoped_ole_initializer.h"
#endif

#if defined(USE_AURA)
#include "ui/aura/client/stacking_client.h"
#include "ui/aura/env.h"
#include "ui/aura/window.h"
#include "ui/aura/root_window.h"
#include "ui/gfx/compositor/compositor.h"
#include "ui/gfx/compositor/test/compositor_test_support.h"
#include "ui/views/widget/native_widget_aura.h"
#endif

#if defined(USE_AURA)
class RootWindowStackingClient : public aura::client::StackingClient {
 public:
  explicit RootWindowStackingClient() {
    aura::client::SetStackingClient(this);
  }

  virtual ~RootWindowStackingClient() {
    aura::client::SetStackingClient(NULL);
  }

  // Overridden from aura::client::StackingClient:
  virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE {
    return window->GetRootWindow();
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(RootWindowStackingClient);
};
#endif

int main(int argc, char** argv) {
#if defined(OS_WIN)
  ui::ScopedOleInitializer ole_initializer;
#endif
  CommandLine::Init(argc, argv);

  logging::InitLogging(NULL,
                       logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG,
                       logging::LOCK_LOG_FILE,
                       logging::DELETE_OLD_LOG_FILE,
                       logging::DISABLE_DCHECK_FOR_NON_OFFICIAL_RELEASE_BUILDS);

  base::EnableTerminationOnHeapCorruption();

  // The exit manager is in charge of calling the dtors of singleton objects.
  base::AtExitManager exit_manager;

  ui::RegisterPathProvider();
  bool icu_result = icu_util::Initialize();
  CHECK(icu_result);
  ui::ResourceBundle::InitSharedInstanceWithLocale("en-US");

  MessageLoop main_message_loop(MessageLoop::TYPE_UI);
#if defined(USE_AURA)

  // TURN ON THE HAX.
  views::NativeWidgetAura::set_aura_desktop_hax();

  ui::CompositorTestSupport::Initialize();

  {
  RootWindowStackingClient root_window_stacking_client;
#endif

  views::TestViewsDelegate delegate;

  views::examples::ShowExamplesWindow(true);

  // xxx: Hax here because this kills event handling.
#if !defined(USE_AURA)
  views::AcceleratorHandler accelerator_handler;
  MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler);
#else
  MessageLoopForUI::current()->Run();
#endif

#if defined(USE_AURA)
  }
  aura::Env::DeleteInstance();
  ui::CompositorTestSupport::Terminate();
#endif

  return 0;
}