OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/command_line.h" | 6 #include "base/command_line.h" |
7 #include "base/i18n/icu_util.h" | 7 #include "base/i18n/icu_util.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "third_party/skia/include/core/SkXfermode.h" | 10 #include "third_party/skia/include/core/SkXfermode.h" |
11 #include "ui/aura/client/default_capture_client.h" | 11 #include "ui/aura/client/default_capture_client.h" |
12 #include "ui/aura/client/stacking_client.h" | 12 #include "ui/aura/client/window_tree_client.h" |
13 #include "ui/aura/env.h" | 13 #include "ui/aura/env.h" |
14 #include "ui/aura/root_window.h" | 14 #include "ui/aura/root_window.h" |
15 #include "ui/aura/test/test_focus_client.h" | 15 #include "ui/aura/test/test_focus_client.h" |
16 #include "ui/aura/test/test_screen.h" | 16 #include "ui/aura/test/test_screen.h" |
17 #include "ui/aura/window.h" | 17 #include "ui/aura/window.h" |
18 #include "ui/aura/window_delegate.h" | 18 #include "ui/aura/window_delegate.h" |
19 #include "ui/base/hit_test.h" | 19 #include "ui/base/hit_test.h" |
20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/base/ui_base_paths.h" | 21 #include "ui/base/ui_base_paths.h" |
22 #include "ui/compositor/compositor.h" | 22 #include "ui/compositor/compositor.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | 70 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
71 virtual void DidRecreateLayer(ui::Layer* old_layer, | 71 virtual void DidRecreateLayer(ui::Layer* old_layer, |
72 ui::Layer* new_layer) OVERRIDE {} | 72 ui::Layer* new_layer) OVERRIDE {} |
73 | 73 |
74 private: | 74 private: |
75 SkColor color_; | 75 SkColor color_; |
76 | 76 |
77 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); | 77 DISALLOW_COPY_AND_ASSIGN(DemoWindowDelegate); |
78 }; | 78 }; |
79 | 79 |
80 class DemoStackingClient : public aura::client::StackingClient { | 80 class DemoWindowTreeClient : public aura::client::WindowTreeClient { |
81 public: | 81 public: |
82 explicit DemoStackingClient(aura::RootWindow* root_window) | 82 explicit DemoWindowTreeClient(aura::Window* window) : window_(window) { |
83 : root_window_(root_window) { | 83 aura::client::SetWindowTreeClient(window_, this); |
84 aura::client::SetStackingClient(root_window_, this); | |
85 } | 84 } |
86 | 85 |
87 virtual ~DemoStackingClient() { | 86 virtual ~DemoWindowTreeClient() { |
88 aura::client::SetStackingClient(root_window_, NULL); | 87 aura::client::SetWindowTreeClient(window_, NULL); |
89 } | 88 } |
90 | 89 |
91 // Overridden from aura::client::StackingClient: | 90 // Overridden from aura::client::WindowTreeClient: |
92 virtual aura::Window* GetDefaultParent(aura::Window* context, | 91 virtual aura::Window* GetDefaultParent(aura::Window* context, |
93 aura::Window* window, | 92 aura::Window* window, |
94 const gfx::Rect& bounds) OVERRIDE { | 93 const gfx::Rect& bounds) OVERRIDE { |
95 if (!capture_client_) { | 94 if (!capture_client_) { |
96 capture_client_.reset( | 95 capture_client_.reset( |
97 new aura::client::DefaultCaptureClient(root_window_)); | 96 new aura::client::DefaultCaptureClient(window_->GetRootWindow())); |
98 } | 97 } |
99 return root_window_; | 98 return window_; |
100 } | 99 } |
101 | 100 |
102 private: | 101 private: |
103 aura::RootWindow* root_window_; | 102 aura::Window* window_; |
104 | 103 |
105 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; | 104 scoped_ptr<aura::client::DefaultCaptureClient> capture_client_; |
106 | 105 |
107 DISALLOW_COPY_AND_ASSIGN(DemoStackingClient); | 106 DISALLOW_COPY_AND_ASSIGN(DemoWindowTreeClient); |
108 }; | 107 }; |
109 | 108 |
110 int DemoMain() { | 109 int DemoMain() { |
111 // Create the message-loop here before creating the root window. | 110 // Create the message-loop here before creating the root window. |
112 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); | 111 base::MessageLoop message_loop(base::MessageLoop::TYPE_UI); |
113 | 112 |
114 // The ContextFactory must exist before any Compositors are created. | 113 // The ContextFactory must exist before any Compositors are created. |
115 bool allow_test_contexts = false; | 114 bool allow_test_contexts = false; |
116 ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); | 115 ui::Compositor::InitializeContextFactoryForTests(allow_test_contexts); |
117 | 116 |
118 aura::Env::CreateInstance(); | 117 aura::Env::CreateInstance(); |
119 scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create()); | 118 scoped_ptr<aura::TestScreen> test_screen(aura::TestScreen::Create()); |
120 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); | 119 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen.get()); |
121 scoped_ptr<aura::RootWindow> root_window( | 120 scoped_ptr<aura::RootWindow> root_window( |
122 test_screen->CreateRootWindowForPrimaryDisplay()); | 121 test_screen->CreateRootWindowForPrimaryDisplay()); |
123 scoped_ptr<DemoStackingClient> stacking_client(new DemoStackingClient( | 122 scoped_ptr<DemoWindowTreeClient> window_tree_client(new DemoWindowTreeClient( |
124 root_window.get())); | 123 root_window.get())); |
125 aura::test::TestFocusClient focus_client; | 124 aura::test::TestFocusClient focus_client; |
126 aura::client::SetFocusClient(root_window.get(), &focus_client); | 125 aura::client::SetFocusClient(root_window.get(), &focus_client); |
127 | 126 |
128 // Create a hierarchy of test windows. | 127 // Create a hierarchy of test windows. |
129 DemoWindowDelegate window_delegate1(SK_ColorBLUE); | 128 DemoWindowDelegate window_delegate1(SK_ColorBLUE); |
130 aura::Window window1(&window_delegate1); | 129 aura::Window window1(&window_delegate1); |
131 window1.set_id(1); | 130 window1.set_id(1); |
132 window1.Init(ui::LAYER_TEXTURED); | 131 window1.Init(ui::LAYER_TEXTURED); |
133 window1.SetBounds(gfx::Rect(100, 100, 400, 400)); | 132 window1.SetBounds(gfx::Rect(100, 100, 400, 400)); |
134 window1.Show(); | 133 window1.Show(); |
135 window1.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect()); | 134 aura::client::ParentWindowWithContext( |
| 135 &window1, root_window.get(), gfx::Rect()); |
136 | 136 |
137 DemoWindowDelegate window_delegate2(SK_ColorRED); | 137 DemoWindowDelegate window_delegate2(SK_ColorRED); |
138 aura::Window window2(&window_delegate2); | 138 aura::Window window2(&window_delegate2); |
139 window2.set_id(2); | 139 window2.set_id(2); |
140 window2.Init(ui::LAYER_TEXTURED); | 140 window2.Init(ui::LAYER_TEXTURED); |
141 window2.SetBounds(gfx::Rect(200, 200, 350, 350)); | 141 window2.SetBounds(gfx::Rect(200, 200, 350, 350)); |
142 window2.Show(); | 142 window2.Show(); |
143 window2.SetDefaultParentByRootWindow(root_window.get(), gfx::Rect()); | 143 aura::client::ParentWindowWithContext( |
| 144 &window2, root_window.get(), gfx::Rect()); |
144 | 145 |
145 DemoWindowDelegate window_delegate3(SK_ColorGREEN); | 146 DemoWindowDelegate window_delegate3(SK_ColorGREEN); |
146 aura::Window window3(&window_delegate3); | 147 aura::Window window3(&window_delegate3); |
147 window3.set_id(3); | 148 window3.set_id(3); |
148 window3.Init(ui::LAYER_TEXTURED); | 149 window3.Init(ui::LAYER_TEXTURED); |
149 window3.SetBounds(gfx::Rect(10, 10, 50, 50)); | 150 window3.SetBounds(gfx::Rect(10, 10, 50, 50)); |
150 window3.Show(); | 151 window3.Show(); |
151 window2.AddChild(&window3); | 152 window2.AddChild(&window3); |
152 | 153 |
153 root_window->ShowRootWindow(); | 154 root_window->ShowRootWindow(); |
154 base::MessageLoopForUI::current()->Run(); | 155 base::MessageLoopForUI::current()->Run(); |
155 | 156 |
156 return 0; | 157 return 0; |
157 } | 158 } |
158 | 159 |
159 } // namespace | 160 } // namespace |
160 | 161 |
161 int main(int argc, char** argv) { | 162 int main(int argc, char** argv) { |
162 CommandLine::Init(argc, argv); | 163 CommandLine::Init(argc, argv); |
163 | 164 |
164 // The exit manager is in charge of calling the dtors of singleton objects. | 165 // The exit manager is in charge of calling the dtors of singleton objects. |
165 base::AtExitManager exit_manager; | 166 base::AtExitManager exit_manager; |
166 | 167 |
167 ui::RegisterPathProvider(); | 168 ui::RegisterPathProvider(); |
168 base::i18n::InitializeICU(); | 169 base::i18n::InitializeICU(); |
169 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); | 170 ResourceBundle::InitSharedInstanceWithLocale("en-US", NULL); |
170 | 171 |
171 return DemoMain(); | 172 return DemoMain(); |
172 } | 173 } |
OLD | NEW |