- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell_surface.cc
1 // Copyright 2013 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_surface.h"
6
7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h"
9
10 #include "ozone/wayland/display.h"
11 #include "ozone/wayland/surface.h"
12
13 namespace ozonewayland {
14
15 WaylandShellSurface::WaylandShellSurface(WaylandWindow* window)
16     : surface_(NULL),
17       shell_surface_(NULL) {
18   WaylandDisplay* display = WaylandDisplay::GetInstance();
19   if (!display)
20       return;
21
22   surface_ = new WaylandSurface();
23   if (display->shell())
24     shell_surface_ = wl_shell_get_shell_surface(
25         display->shell(),
26         surface_->wlSurface());
27
28   if (shell_surface_) {
29     static const wl_shell_surface_listener shell_surface_listener = {
30       WaylandShellSurface::HandlePing,
31       WaylandShellSurface::HandleConfigure,
32       WaylandShellSurface::HandlePopupDone
33     };
34
35     wl_shell_surface_add_listener(shell_surface_,
36                                   &shell_surface_listener,
37                                   window);
38   }
39 }
40
41 WaylandShellSurface::~WaylandShellSurface() {
42   if (shell_surface_) {
43     wl_shell_surface_destroy(shell_surface_);
44     shell_surface_ = NULL;
45   }
46
47   if (surface_) {
48     delete surface_;
49     surface_ = NULL;
50   }
51 }
52
53 void WaylandShellSurface::UpdateShellSurface(WaylandWindow::ShellType type,
54                                              WaylandShellSurface* shell_parent,
55                                              unsigned x,
56                                              unsigned y) const {
57   switch (type) {
58   case WaylandWindow::TOPLEVEL:
59     wl_shell_surface_set_toplevel(shell_surface_);
60     break;
61   case WaylandWindow::TRANSIENT:
62     wl_shell_surface_set_transient(shell_surface_,
63                                    shell_parent->Surface()->wlSurface(),
64                                    x,
65                                    y,
66                                    WL_SHELL_SURFACE_TRANSIENT_INACTIVE);
67     break;
68   case WaylandWindow::FULLSCREEN:
69     wl_shell_surface_set_fullscreen(shell_surface_,
70                                     WL_SHELL_SURFACE_FULLSCREEN_METHOD_DEFAULT,
71                                     0,
72                                     NULL);
73     break;
74   case WaylandWindow::CUSTOM:
75       NOTREACHED() << "Unsupported shell type: " << type;
76     break;
77     default:
78       break;
79   }
80 }
81
82 void WaylandShellSurface::SetWindowTitle(const string16& title) {
83   wl_shell_surface_set_title(shell_surface_, UTF16ToUTF8(title).c_str());
84 }
85
86 void WaylandShellSurface::HandleConfigure(void *data,
87                                           struct wl_shell_surface *surface,
88                                           uint32_t edges,
89                                           int32_t width,
90                                           int32_t height) {
91 }
92
93 void WaylandShellSurface::HandlePopupDone(void *data,
94                                           struct wl_shell_surface *surface) {
95 }
96
97 void WaylandShellSurface::HandlePing(void *data,
98                                      struct wl_shell_surface *shell_surface,
99                                      uint32_t serial) {
100   wl_shell_surface_pong(shell_surface, serial);
101 }
102
103 }  // namespace ozonewayland