| 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/desktop/desktop_stacking_client.h" | 26 #include "ui/aura/client/stacking_client.h" |
| 27 #include "ui/aura/env.h" | 27 #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" |
| 28 #include "ui/views/widget/native_widget_aura.h" | 32 #include "ui/views/widget/native_widget_aura.h" |
| 29 #endif | 33 #endif |
| 30 | 34 |
| 31 namespace views { | 35 namespace views { |
| 32 namespace examples { | 36 namespace examples { |
| 37 namespace { |
| 38 #if defined(USE_AURA) |
| 39 class RootWindowStackingClient : public aura::client::StackingClient { |
| 40 public: |
| 41 explicit RootWindowStackingClient() { |
| 42 aura::client::SetStackingClient(this); |
| 43 } |
| 44 |
| 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 }; |
| 57 #endif |
| 58 } |
| 33 | 59 |
| 34 ExamplesBrowserMainParts::ExamplesBrowserMainParts( | 60 ExamplesBrowserMainParts::ExamplesBrowserMainParts( |
| 35 const content::MainFunctionParams& parameters) | 61 const content::MainFunctionParams& parameters) |
| 36 : BrowserMainParts(), | 62 : BrowserMainParts(), |
| 37 devtools_delegate_(NULL) { | 63 devtools_delegate_(NULL) { |
| 38 } | 64 } |
| 39 | 65 |
| 40 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { | 66 ExamplesBrowserMainParts::~ExamplesBrowserMainParts() { |
| 41 } | 67 } |
| 42 | 68 |
| 43 #if !defined(OS_MACOSX) | 69 #if !defined(OS_MACOSX) |
| 44 void ExamplesBrowserMainParts::PreMainMessageLoopStart() { | 70 void ExamplesBrowserMainParts::PreMainMessageLoopStart() { |
| 45 } | 71 } |
| 46 #endif | 72 #endif |
| 47 | 73 |
| 48 int ExamplesBrowserMainParts::PreCreateThreads() { | 74 int ExamplesBrowserMainParts::PreCreateThreads() { |
| 49 return 0; | 75 return 0; |
| 50 } | 76 } |
| 51 | 77 |
| 52 void ExamplesBrowserMainParts::PreMainMessageLoopRun() { | 78 void ExamplesBrowserMainParts::PreMainMessageLoopRun() { |
| 53 browser_context_.reset(new content::ShellBrowserContext); | 79 browser_context_.reset(new content::ShellBrowserContext); |
| 54 | 80 |
| 55 #if defined(USE_AURA) | 81 #if defined(USE_AURA) |
| 56 stacking_client_.reset(new aura::DesktopStackingClient); | 82 // TURN ON THE HAX. |
| 83 views::NativeWidgetAura::set_aura_desktop_hax(); |
| 84 ui::CompositorTestSupport::Initialize(); |
| 85 root_window_stacking_client_.reset(new RootWindowStackingClient); |
| 57 #endif | 86 #endif |
| 58 views_delegate_.reset(new views::TestViewsDelegate); | 87 views_delegate_.reset(new views::TestViewsDelegate); |
| 59 | 88 |
| 60 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE, | 89 views::examples::ShowExamplesWindow(views::examples::QUIT_ON_CLOSE, |
| 61 browser_context_.get()); | 90 browser_context_.get()); |
| 62 } | 91 } |
| 63 | 92 |
| 64 void ExamplesBrowserMainParts::PostMainMessageLoopRun() { | 93 void ExamplesBrowserMainParts::PostMainMessageLoopRun() { |
| 65 if (devtools_delegate_) | 94 if (devtools_delegate_) |
| 66 devtools_delegate_->Stop(); | 95 devtools_delegate_->Stop(); |
| 67 browser_context_.reset(); | 96 browser_context_.reset(); |
| 68 views_delegate_.reset(); | 97 views_delegate_.reset(); |
| 69 #if defined(USE_AURA) | 98 #if defined(USE_AURA) |
| 70 stacking_client_.reset(); | 99 root_window_stacking_client_.reset(); |
| 71 aura::Env::DeleteInstance(); | 100 aura::Env::DeleteInstance(); |
| 101 ui::CompositorTestSupport::Terminate(); |
| 72 #endif | 102 #endif |
| 73 } | 103 } |
| 74 | 104 |
| 75 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { | 105 bool ExamplesBrowserMainParts::MainMessageLoopRun(int* result_code) { |
| 76 // xxx: Hax here because this kills event handling. | 106 // xxx: Hax here because this kills event handling. |
| 77 #if !defined(USE_AURA) | 107 #if !defined(USE_AURA) |
| 78 views::AcceleratorHandler accelerator_handler; | 108 views::AcceleratorHandler accelerator_handler; |
| 79 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); | 109 MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler); |
| 80 #else | 110 #else |
| 81 MessageLoopForUI::current()->Run(); | 111 MessageLoopForUI::current()->Run(); |
| 82 #endif | 112 #endif |
| 83 return true; | 113 return true; |
| 84 } | 114 } |
| 85 | 115 |
| 86 ui::Clipboard* ExamplesBrowserMainParts::GetClipboard() { | 116 ui::Clipboard* ExamplesBrowserMainParts::GetClipboard() { |
| 87 if (!clipboard_.get()) | 117 if (!clipboard_.get()) |
| 88 clipboard_.reset(new ui::Clipboard()); | 118 clipboard_.reset(new ui::Clipboard()); |
| 89 return clipboard_.get(); | 119 return clipboard_.get(); |
| 90 } | 120 } |
| 91 | 121 |
| 92 } // namespace examples | 122 } // namespace examples |
| 93 } // namespace views | 123 } // namespace views |
| OLD | NEW |