| 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 "ui/views/examples/content_client/examples_browser_main_parts.h" | 5 #include "ui/views/examples/content_client/examples_browser_main_parts.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/threading/thread.h" | 11 #include "base/threading/thread.h" |
| 12 #include "base/threading/thread_restrictions.h" | 12 #include "base/threading/thread_restrictions.h" |
| 13 #include "content/public/common/content_switches.h" | 13 #include "content/public/common/content_switches.h" |
| 14 #include "content/shell/shell.h" | 14 #include "content/shell/shell.h" |
| 15 #include "content/shell/shell_browser_context.h" | 15 #include "content/shell/shell_browser_context.h" |
| 16 #include "content/shell/shell_devtools_delegate.h" | 16 #include "content/shell/shell_devtools_delegate.h" |
| 17 #include "content/shell/shell_switches.h" | 17 #include "content/shell/shell_switches.h" |
| 18 #include "googleurl/src/gurl.h" | 18 #include "googleurl/src/gurl.h" |
| 19 #include "net/base/net_module.h" | 19 #include "net/base/net_module.h" |
| 20 #include "ui/base/clipboard/clipboard.h" | 20 #include "ui/base/clipboard/clipboard.h" |
| 21 #include "ui/views/examples/examples_window.h" | 21 #include "ui/views/examples/examples_window.h" |
| 22 #include "ui/views/test/test_views_delegate.h" | 22 #include "ui/views/test/test_views_delegate.h" |
| 23 #include "ui/views/focus/accelerator_handler.h" | 23 #include "ui/views/focus/accelerator_handler.h" |
| 24 | 24 |
| 25 #if defined(USE_AURA) | 25 #if defined(USE_AURA) |
| 26 #include "ui/aura/client/stacking_client.h" | 26 #if !defined(USE_ASH) |
| 27 #include "ui/views/widget/desktop_native_widget_helper_aura.h" |
| 28 #endif |
| 29 #include "ui/aura/desktop/desktop_stacking_client.h" |
| 27 #include "ui/aura/env.h" | 30 #include "ui/aura/env.h" |
| 28 #include "ui/aura/root_window.h" | |
| 29 #include "ui/aura/window.h" | |
| 30 #include "ui/gfx/compositor/compositor.h" | |
| 31 #include "ui/gfx/compositor/test/compositor_test_support.h" | |
| 32 #include "ui/views/widget/native_widget_aura.h" | 31 #include "ui/views/widget/native_widget_aura.h" |
| 33 #endif | 32 #endif |
| 34 | 33 |
| 35 namespace views { | 34 namespace views { |
| 36 namespace examples { | 35 namespace examples { |
| 36 |
| 37 namespace { | 37 namespace { |
| 38 #if defined(USE_AURA) | 38 class ExamplesViewsDelegate : public views::TestViewsDelegate { |
| 39 class RootWindowStackingClient : public aura::client::StackingClient { | |
| 40 public: | 39 public: |
| 41 explicit RootWindowStackingClient() { | 40 #if defined(USE_AURA) && !defined(USE_ASH) |
| 42 aura::client::SetStackingClient(this); | 41 virtual views::NativeWidgetHelperAura* CreateNativeWidgetHelper( |
| 42 views::NativeWidgetAura* native_widget) OVERRIDE { |
| 43 return new views::DesktopNativeWidgetHelperAura(native_widget); |
| 43 } | 44 } |
| 44 | 45 #endif // !USE_ASH |
| 45 virtual ~RootWindowStackingClient() { | |
| 46 aura::client::SetStackingClient(NULL); | |
| 47 } | |
| 48 | |
| 49 // Overridden from aura::client::StackingClient: | |
| 50 virtual aura::Window* GetDefaultParent(aura::Window* window) OVERRIDE { | |
| 51 return window->GetRootWindow(); | |
| 52 } | |
| 53 | |
| 54 private: | |
| 55 DISALLOW_COPY_AND_ASSIGN(RootWindowStackingClient); | |
| 56 }; | 46 }; |
| 57 #endif | 47 } // namespace |
| 58 } | |
| 59 | 48 |
| 60 ExamplesBrowserMainParts::ExamplesBrowserMainParts( | 49 ExamplesBrowserMainParts::ExamplesBrowserMainParts( |
| 61 const content::MainFunctionParams& parameters) | 50 const content::MainFunctionParams& parameters) |
| 62 : BrowserMainParts(), | 51 : BrowserMainParts(), |
| 63 devtools_delegate_(NULL) { | 52 devtools_delegate_(NULL) { |
| 64 } | 53 } |
| 65 | 54 |
| 66 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { | 55 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { |
| 67 } | 56 } |
| 68 | 57 |
| 69 #if !defined(OS_MACOSX) | 58 #if !defined(OS_MACOSX) |
| 70 void ExamplesBrowserMainParts::PreMainMessageLoopStart() { | 59 void ExamplesBrowserMainParts::PreMainMessageLoopStart() { |
| 71 } | 60 } |
| 72 #endif | 61 #endif |
| 73 | 62 |
| 74 int ExamplesBrowserMainParts::PreCreateThreads() { | 63 int ExamplesBrowserMainParts::PreCreateThreads() { |
| 75 return 0; | 64 return 0; |
| 76 } | 65 } |
| 77 | 66 |
| 78 void ExamplesBrowserMainParts::PreMainMessageLoopRun() { | 67 void ExamplesBrowserMainParts::PreMainMessageLoopRun() { |
| 79 browser_context_.reset(new content::ShellBrowserContext); | 68 browser_context_.reset(new content::ShellBrowserContext); |
| 80 | 69 |
| 81 #if defined(USE_AURA) | 70 #if defined(USE_AURA) |
| 82 // TURN ON THE HAX. | 71 stacking_client_.reset(new aura::DesktopStackingClient); |
| 83 views::NativeWidgetAura::set_aura_desktop_hax(); | |
| 84 ui::CompositorTestSupport::Initialize(); | |
| 85 root_window_stacking_client_.reset(new RootWindowStackingClient); | |
| 86 #endif | 72 #endif |
| 87 views_delegate_.reset(new views::TestViewsDelegate); | 73 views_delegate_.reset(new ExamplesViewsDelegate); |
| 88 | 74 |
| 89 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE, | 75 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE, |
| 90 browser_context_.get()); | 76 browser_context_.get()); |
| 91 } | 77 } |
| 92 | 78 |
| 93 void ExamplesBrowserMainParts::PostMainMessageLoopRun() { | 79 void ExamplesBrowserMainParts::PostMainMessageLoopRun() { |
| 94 if (devtools_delegate_) | 80 if (devtools_delegate_) |
| 95 devtools_delegate_->Stop(); | 81 devtools_delegate_->Stop(); |
| 96 browser_context_.reset(); | 82 browser_context_.reset(); |
| 97 views_delegate_.reset(); | 83 views_delegate_.reset(); |
| 98 #if defined(USE_AURA) | 84 #if defined(USE_AURA) |
| 99 root_window_stacking_client_.reset(); | 85 stacking_client_.reset(); |
| 100 aura::Env::DeleteInstance(); | 86 aura::Env::DeleteInstance(); |
| 101 ui::CompositorTestSupport::Terminate(); | |
| 102 #endif | 87 #endif |
| 103 } | 88 } |
| 104 | 89 |
| 105 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { | 90 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 106 // xxx: Hax here because this kills event handling. | 91 // xxx: Hax here because this kills event handling. |
| 107 #if !defined(USE_AURA) | 92 #if !defined(USE_AURA) |
| 108 views::AcceleratorHandler accelerator_handler; | 93 views::AcceleratorHandler accelerator_handler; |
| 109 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 94 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
| 110 #else | 95 #else |
| 111 MessageLoopForUI::current()->Run(); | 96 MessageLoopForUI::current()->Run(); |
| 112 #endif | 97 #endif |
| 113 return true; | 98 return true; |
| 114 } | 99 } |
| 115 | 100 |
| 116 ui::Clipboard* ExamplesBrowserMainParts::GetClipboard() { | 101 ui::Clipboard* ExamplesBrowserMainParts::GetClipboard() { |
| 117 if (!clipboard_.get()) | 102 if (!clipboard_.get()) |
| 118 clipboard_.reset(new ui::Clipboard()); | 103 clipboard_.reset(new ui::Clipboard()); |
| 119 return clipboard_.get(); | 104 return clipboard_.get(); |
| 120 } | 105 } |
| 121 | 106 |
| 122 } // namespace examples | 107 } // namespace examples |
| 123 } // namespace views | 108 } // namespace views |
| OLD | NEW |