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

Side by Side 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, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ui/platform_window/platform_window_factory.h"
6
7 #include "base/at_exit.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "ui/events/platform/platform_event_source.h"
12 #include "ui/platform_window/types/platform_window.h"
13
14 #if defined(USE_X11)
15 #include "ui/platform_window/x11/x11_window.h"
16 #elif defined(OS_WIN)
17 #include "ui/platform_window/win/win_window.h"
18 #elif defined(USE_OZONE)
19 #include "ui/ozone/public/ozone_platform.h"
20 #endif
21
22 namespace ui {
23
24 namespace {
25
26 PlatformWindowFactory* instance = NULL;
27
28 class DefaultPlatformWindowFactory : public PlatformWindowFactory {
29 public:
30 DefaultPlatformWindowFactory()
31 : event_source_(PlatformEventSource::CreateDefault()) {}
32 virtual ~DefaultPlatformWindowFactory() {}
33
34 private:
35 // PlatformWindowFactory:
36 virtual scoped_ptr<PlatformWindow> CreatePlatformWindow(
37 PlatformWindowDelegate* delegate,
38 const gfx::Rect& bounds) OVERRIDE {
39 scoped_ptr<PlatformWindow> window;
40 #if defined(USE_X11)
41 window.reset(new X11Window(delegate));
42 window->SetBounds(bounds);
43 #elif defined(OS_WIN)
44 window.reset(new WinWindow(delegate, bounds));
45 #elif defined(USE_OZONE)
46 window =
47 OzonePlatform::GetInstance()->CreatePlatformWindow(delegate, bounds);
48 #else
49 NOTREACHED();
50 #endif
51 return window.Pass();
52 }
53
54 scoped_ptr<PlatformEventSource> event_source_;
55
56 DISALLOW_COPY_AND_ASSIGN(DefaultPlatformWindowFactory);
57 };
58
59 } // namespace
60
61 PlatformWindowFactory::PlatformWindowFactory() {
62 CHECK(!instance) << "There can only be a single PlatformWindowFactory.";
63 instance = this;
64 base::AtExitManager::RegisterTask(
65 base::Bind(&base::DeletePointer<PlatformWindowFactory>, instance));
66 }
67
68 PlatformWindowFactory::~PlatformWindowFactory() {
69 CHECK_EQ(instance, this);
70 instance = NULL;
71 }
72
73 // static
74 PlatformWindowFactory* PlatformWindowFactory::GetInstance() {
75 if (!instance)
76 new DefaultPlatformWindowFactory();
77 CHECK(instance);
78 return instance;
79 }
80
81 } // namespace ui
OLDNEW
« 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