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

Unified Diff: wm/host/foreign_test_window_host_linux.cc

Issue 11485006: Add window manager component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Push gfx::AcceleratedWidget usage into platform specific code. Created 7 years, 10 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 | « wm/host/foreign_test_window_host_linux.h ('k') | wm/host/foreign_window_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: wm/host/foreign_test_window_host_linux.cc
diff --git a/wm/host/foreign_test_window_host_linux.cc b/wm/host/foreign_test_window_host_linux.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2c843fbf652d389468ccff050051f447a9b8389e
--- /dev/null
+++ b/wm/host/foreign_test_window_host_linux.cc
@@ -0,0 +1,132 @@
+// Copyright (c) 2013 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 "wm/host/foreign_test_window_host_linux.h"
+
+#include "base/run_loop.h"
+#include "ui/aura/env.h"
+#include "ui/aura/root_window.h"
+
+namespace wm {
+
+ForeignTestWindowHostLinux::ForeignTestWindowHostLinux(
+ aura::RootWindow* root_window)
+ : display_(NULL),
+ parent_(root_window->GetAcceleratedWidget()),
+ window_(0),
+ font_info_(NULL),
+ gc_(0) {
+}
+
+ForeignTestWindowHostLinux::~ForeignTestWindowHostLinux() {
+}
+
+void ForeignTestWindowHostLinux::Initialize() {
+ DCHECK(parent_);
+ display_ = XOpenDisplay(NULL);
+ size_ = gfx::Size(300, 300);
+ window_ = XCreateSimpleWindow(
+ display_,
+ parent_,
+ 30, 30, size_.width(), size_.height(), 0,
+ BlackPixel(display_, DefaultScreen(display_)),
+ WhitePixel(display_, DefaultScreen(display_)));
+ XSelectInput(display_, window_, ExposureMask | StructureNotifyMask);
+ font_info_ = XLoadQueryFont(display_, "9x15");
+ DCHECK(font_info_);
+ gc_ = XCreateGC(display_, window_, 0, NULL);
+ XSetFont(display_, gc_, font_info_->fid);
+ XSetForeground(display_, gc_, BlackPixel(display_, DefaultScreen(display_)));
+
+ MessageLoopForIO::current()->WatchFileDescriptor(
+ ConnectionNumber(display_), true, MessageLoopForIO::WATCH_READ,
+ &connection_watcher_, this);
+
+ PumpXEvents();
+}
+
+void ForeignTestWindowHostLinux::Delete() {
+ connection_watcher_.StopWatchingFileDescriptor();
+ XFreeGC(display_, gc_);
+ XFreeFont(display_, font_info_);
+ XCloseDisplay(display_);
+ delete this;
+}
+
+void ForeignTestWindowHostLinux::Show() {
+ DCHECK(window_);
+ XMapWindow(display_, window_);
+}
+
+void ForeignTestWindowHostLinux::Hide() {
+ DCHECK(window_);
+ XUnmapWindow(display_, window_);
+}
+
+void ForeignTestWindowHostLinux::Destroy() {
+ XDestroyWindow(display_, window_);
+ window_ = 0;
+}
+
+void ForeignTestWindowHostLinux::Sync() {
+ XSync(display_, False);
+}
+
+void ForeignTestWindowHostLinux::ProcessXEvent(XEvent *event) {
+ switch (event->type) {
+ case Expose: {
+ if (event->xexpose.count != 0)
+ break;
+
+ std::string message("Hello, X Window System!");
+
+ // Center text.
+ int width = XTextWidth(font_info_, message.c_str(), message.length());
+ int msg_x = (size_.width() - width) / 2;
+
+ int font_height = font_info_->ascent + font_info_->descent;
+ int msg_y = (size_.height() + font_height) / 2;
+
+ XDrawString(display_,
+ window_,
+ gc_,
+ msg_x, msg_y,
+ message.c_str(), message.length());
+ } break;
+ case ConfigureNotify: {
+ size_ = gfx::Size(event->xconfigure.width, event->xconfigure.height);
+ } break;
+ }
+}
+
+void ForeignTestWindowHostLinux::PumpXEvents() {
+ while (XPending(display_)) {
+ XEvent event;
+ XNextEvent(display_, &event);
+ ProcessXEvent(&event);
+ }
+}
+
+void ForeignTestWindowHostLinux::OnFileCanReadWithoutBlocking(int fd) {
+ PumpXEvents();
+}
+
+void ForeignTestWindowHostLinux::OnFileCanWriteWithoutBlocking(int fd) {
+}
+
+// static
+ForeignTestWindowHost* ForeignTestWindowHost::Create(
+ aura::RootWindow* root_window) {
+ return new ForeignTestWindowHostLinux(root_window);
+}
+
+// static
+void ForeignTestWindowHost::RunAllPendingInMessageLoop() {
+ Display* display = base::MessagePumpAuraX11::GetDefaultXDisplay();
+ XSync(display, False);
+ base::RunLoop run_loop(aura::Env::GetInstance()->GetDispatcher());
+ run_loop.RunUntilIdle();
+}
+
+} // namespace wm
« no previous file with comments | « wm/host/foreign_test_window_host_linux.h ('k') | wm/host/foreign_window_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698