Upstream version 6.35.121.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell / shell.cc
1 // Copyright 2014 Intel Corporation. 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 "ozone/wayland/shell/shell.h"
6
7 #include "base/logging.h"
8 #include "ozone/wayland/display.h"
9 #include "ozone/wayland/shell/wl_shell_surface.h"
10 #if defined(ENABLE_XDG_SHELL)
11 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
12 #include "ozone/wayland/shell/xdg_shell_surface.h"
13 #endif
14
15 namespace ozonewayland {
16
17 WaylandShell::WaylandShell()
18     : shell_(NULL),
19       xdg_shell_(NULL) {
20 }
21
22 WaylandShell::~WaylandShell() {
23   if (shell_)
24     wl_shell_destroy(shell_);
25 #if defined(ENABLE_XDG_SHELL)
26   if (xdg_shell_)
27     xdg_shell_destroy(xdg_shell_);
28 #endif
29 }
30
31 WaylandShellSurface* WaylandShell::CreateShellSurface(WaylandWindow* window) {
32   DCHECK(shell_ || xdg_shell_);
33   WaylandDisplay* display = WaylandDisplay::GetInstance();
34   DCHECK(display);
35   WaylandShellSurface* surface = NULL;
36 #if defined(ENABLE_XDG_SHELL)
37   if (xdg_shell_)
38     surface = new XDGShellSurface();
39 #endif
40   if (!surface)
41     surface = new WLShellSurface();
42
43   DCHECK(surface);
44   surface->InitializeShellSurface(window);
45   wl_surface_set_user_data(surface->GetWLSurface(), window);
46   display->FlushDisplay();
47
48   return surface;
49 }
50
51 void WaylandShell::Initialize(struct wl_registry *registry,
52                               uint32_t name,
53                               const char *interface,
54                               uint32_t version) {
55   if (strcmp(interface, "wl_shell") == 0) {
56     DCHECK(!shell_);
57     shell_ = static_cast<wl_shell*>(
58         wl_registry_bind(registry, name, &wl_shell_interface, 1));
59 #if defined(ENABLE_XDG_SHELL)
60   } else if (strcmp(interface, "xdg_shell") == 0) {
61       DCHECK(!xdg_shell_);
62       xdg_shell_ = static_cast<xdg_shell*>(
63           wl_registry_bind(registry, name, &xdg_shell_interface, 1));
64       xdg_shell_use_unstable_version(xdg_shell_, XDG_SHELL_VERSION_CURRENT);
65 #endif
66   }
67 }
68
69 }  // namespace ozonewayland