OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "wm/host/foreign_test_window_host_linux.h" | |
6 | |
7 #include "base/run_loop.h" | |
8 #include "ui/aura/env.h" | |
9 | |
10 namespace wm { | |
11 | |
12 ForeignTestWindowHostLinux::ForeignTestWindowHostLinux( | |
13 gfx::AcceleratedWidget parent) : display_(NULL), | |
danakj
2013/02/21 01:33:15
is this : on the same line thing legit style? neve
reveman
2013/02/22 01:26:44
I like this when possible as it creates a nice sep
| |
14 parent_(parent), | |
15 window_(0), | |
16 font_info_(NULL), | |
17 gc_(0) { | |
18 } | |
19 | |
20 ForeignTestWindowHostLinux::~ForeignTestWindowHostLinux() { | |
21 } | |
22 | |
23 void ForeignTestWindowHostLinux::Initialize() { | |
24 DCHECK(parent_); | |
25 display_ = XOpenDisplay(NULL); | |
26 size_ = gfx::Size(300, 300); | |
27 window_ = XCreateSimpleWindow( | |
28 display_, | |
29 parent_, | |
30 30, 30, size_.width(), size_.height(), 0, | |
31 BlackPixel(display_, DefaultScreen(display_)), | |
32 WhitePixel(display_, DefaultScreen(display_))); | |
33 XSelectInput(display_, window_, ExposureMask | StructureNotifyMask); | |
34 font_info_ = XLoadQueryFont(display_, "9x15"); | |
35 DCHECK(font_info_); | |
36 gc_ = XCreateGC(display_, window_, 0, NULL); | |
37 XSetFont(display_, gc_, font_info_->fid); | |
38 XSetForeground(display_, gc_, BlackPixel(display_, DefaultScreen(display_))); | |
39 | |
40 MessageLoopForIO::current()->WatchFileDescriptor( | |
41 ConnectionNumber(display_), true, MessageLoopForIO::WATCH_READ, | |
42 &connection_watcher_, this); | |
43 | |
44 PumpXEvents(); | |
45 } | |
46 | |
47 void ForeignTestWindowHostLinux::Delete() { | |
48 connection_watcher_.StopWatchingFileDescriptor(); | |
49 XFreeGC(display_, gc_); | |
50 XFreeFont(display_, font_info_); | |
51 XCloseDisplay(display_); | |
52 delete this; | |
53 } | |
54 | |
55 void ForeignTestWindowHostLinux::Show() { | |
56 DCHECK(window_); | |
57 XMapWindow(display_, window_); | |
58 } | |
59 | |
60 void ForeignTestWindowHostLinux::Hide() { | |
61 DCHECK(window_); | |
62 XUnmapWindow(display_, window_); | |
63 } | |
64 | |
65 void ForeignTestWindowHostLinux::Destroy() { | |
66 XDestroyWindow(display_, window_); | |
67 window_ = 0; | |
68 } | |
69 | |
70 void ForeignTestWindowHostLinux::Sync() { | |
71 XSync(display_, False); | |
72 } | |
73 | |
74 void ForeignTestWindowHostLinux::ProcessXEvent(XEvent *event) { | |
75 switch (event->type) { | |
76 case Expose: { | |
77 if (event->xexpose.count != 0) | |
78 break; | |
79 | |
80 std::string message("Hello, X Window System!"); | |
81 | |
82 // Center text. | |
83 int width = XTextWidth(font_info_, message.c_str(), message.length()); | |
84 int msg_x = (size_.width() - width) / 2; | |
85 | |
86 int font_height = font_info_->ascent + font_info_->descent; | |
87 int msg_y = (size_.height() + font_height) / 2; | |
88 | |
89 XDrawString(display_, | |
90 window_, | |
91 gc_, | |
92 msg_x, msg_y, | |
93 message.c_str(), message.length()); | |
94 } break; | |
95 case ConfigureNotify: { | |
96 size_ = gfx::Size(event->xconfigure.width, event->xconfigure.height); | |
97 } break; | |
98 } | |
99 } | |
100 | |
101 void ForeignTestWindowHostLinux::PumpXEvents() { | |
102 while (XPending(display_)) { | |
103 XEvent event; | |
104 XNextEvent(display_, &event); | |
105 ProcessXEvent(&event); | |
106 } | |
107 } | |
108 | |
109 void ForeignTestWindowHostLinux::OnFileCanReadWithoutBlocking(int fd) { | |
110 PumpXEvents(); | |
111 } | |
112 | |
113 void ForeignTestWindowHostLinux::OnFileCanWriteWithoutBlocking(int fd) { | |
114 } | |
115 | |
116 // static | |
117 ForeignTestWindowHost* ForeignTestWindowHost::Create( | |
118 gfx::AcceleratedWidget parent) { | |
danakj
2013/02/21 01:33:15
Why is an X window sometimes AcceleratedWidget and
reveman
2013/02/22 01:26:44
RootWindowHost uses AcceleratedWidget and BrowserG
danakj
2013/02/22 01:48:08
Oh argh. Do you think BGCHF could use AcceleratedW
reveman
2013/02/22 06:53:01
I tried that initially when adding CHROMIUM_textur
danakj
2013/02/22 21:42:59
I think I would prefer that. Keeping the Accelerat
| |
119 return new ForeignTestWindowHostLinux(parent); | |
120 } | |
121 | |
122 // static | |
123 void ForeignTestWindowHost::RunAllPendingInMessageLoop() { | |
124 Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay(); | |
125 XSync(display, False); | |
126 base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher()); | |
127 run_loop.RunUntilIdle(); | |
128 } | |
129 | |
130 } // namespace wm | |
OLD | NEW |