| Index: ui/platform_window/platform_window_factory.cc
|
| diff --git a/ui/platform_window/platform_window_factory.cc b/ui/platform_window/platform_window_factory.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9b95bc6e7df313a67782b6281a5b0d76592eed3a
|
| --- /dev/null
|
| +++ b/ui/platform_window/platform_window_factory.cc
|
| @@ -0,0 +1,81 @@
|
| +// Copyright 2014 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 "ui/platform_window/platform_window_factory.h"
|
| +
|
| +#include "base/at_exit.h"
|
| +#include "base/bind.h"
|
| +#include "base/logging.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| +#include "ui/events/platform/platform_event_source.h"
|
| +#include "ui/platform_window/types/platform_window.h"
|
| +
|
| +#if defined(USE_X11)
|
| +#include "ui/platform_window/x11/x11_window.h"
|
| +#elif defined(OS_WIN)
|
| +#include "ui/platform_window/win/win_window.h"
|
| +#elif defined(USE_OZONE)
|
| +#include "ui/ozone/public/ozone_platform.h"
|
| +#endif
|
| +
|
| +namespace ui {
|
| +
|
| +namespace {
|
| +
|
| +PlatformWindowFactory* instance = NULL;
|
| +
|
| +class DefaultPlatformWindowFactory : public PlatformWindowFactory {
|
| + public:
|
| + DefaultPlatformWindowFactory()
|
| + : event_source_(PlatformEventSource::CreateDefault()) {}
|
| + virtual ~DefaultPlatformWindowFactory() {}
|
| +
|
| + private:
|
| + // PlatformWindowFactory:
|
| + virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
|
| + PlatformWindowDelegate* delegate,
|
| + const gfx::Rect& bounds) OVERRIDE {
|
| + scoped_ptr<PlatformWindow> window;
|
| +#if defined(USE_X11)
|
| + window.reset(new X11Window(delegate));
|
| + window->SetBounds(bounds);
|
| +#elif defined(OS_WIN)
|
| + window.reset(new WinWindow(delegate, bounds));
|
| +#elif defined(USE_OZONE)
|
| + window =
|
| + OzonePlatform::GetInstance()->CreatePlatformWindow(delegate, bounds);
|
| +#else
|
| + NOTREACHED();
|
| +#endif
|
| + return window.Pass();
|
| + }
|
| +
|
| + scoped_ptr<PlatformEventSource> event_source_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(DefaultPlatformWindowFactory);
|
| +};
|
| +
|
| +} // namespace
|
| +
|
| +PlatformWindowFactory::PlatformWindowFactory() {
|
| + CHECK(!instance) << "There can only be a single PlatformWindowFactory.";
|
| + instance = this;
|
| + base::AtExitManager::RegisterTask(
|
| + base::Bind(&base::DeletePointer<PlatformWindowFactory>, instance));
|
| +}
|
| +
|
| +PlatformWindowFactory::~PlatformWindowFactory() {
|
| + CHECK_EQ(instance, this);
|
| + instance = NULL;
|
| +}
|
| +
|
| +// static
|
| +PlatformWindowFactory* PlatformWindowFactory::GetInstance() {
|
| + if (!instance)
|
| + new DefaultPlatformWindowFactory();
|
| + CHECK(instance);
|
| + return instance;
|
| +}
|
| +
|
| +} // namespace ui
|
|
|