Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(199)

Unified Diff: ui/platform_window/platform_window_factory.cc

Issue 403263002: platform-window: Add a PlatformWindowFactory for creating windows. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/platform_window/platform_window_factory.h ('k') | ui/platform_window/types/platform_window.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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
« no previous file with comments | « ui/platform_window/platform_window_factory.h ('k') | ui/platform_window/types/platform_window.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698