Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell / xdg_shell_surface.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/xdg_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/input_device.h"
12 #include "ozone/wayland/shell/shell.h"
13 #include "ozone/wayland/shell/xdg-shell-client-protocol.h"
14
15 namespace ozonewayland {
16
17 XDGShellSurface::XDGShellSurface()
18     : WaylandShellSurface(),
19       xdg_surface_(NULL),
20       xdg_popup_(NULL),
21       maximized_(false),
22       minimized_(false) {
23 }
24
25 XDGShellSurface::~XDGShellSurface() {
26   if (xdg_surface_)
27     xdg_surface_destroy(xdg_surface_);
28   if (xdg_popup_)
29     xdg_popup_destroy(xdg_popup_);
30 }
31
32 void XDGShellSurface::InitializeShellSurface(WaylandWindow* window,
33                                              WaylandWindow::ShellType type) {
34   DCHECK(!xdg_surface_);
35   DCHECK(!xdg_popup_);
36   WaylandDisplay* display = WaylandDisplay::GetInstance();
37   DCHECK(display);
38   WaylandShell* shell = WaylandDisplay::GetInstance()->GetShell();
39   DCHECK(shell && shell->GetXDGShell());
40
41   if (type != WaylandWindow::POPUP) {
42     xdg_surface_ = xdg_shell_get_xdg_surface(shell->GetXDGShell(),
43                                              GetWLSurface());
44
45     static const xdg_surface_listener xdg_surface_listener = {
46       XDGShellSurface::HandleConfigure,
47       XDGShellSurface::HandleChangeState,
48       XDGShellSurface::HandleActivate,
49       XDGShellSurface::HandleDeactivate,
50       XDGShellSurface::HandleDelete
51     };
52
53     xdg_surface_add_listener(xdg_surface_,
54                              &xdg_surface_listener,
55                              window);
56
57     DCHECK(xdg_surface_);
58   }
59 }
60
61 void XDGShellSurface::UpdateShellSurface(WaylandWindow::ShellType type,
62                                          WaylandShellSurface* shell_parent,
63                                          unsigned x,
64                                          unsigned y) {
65   switch (type) {
66   case WaylandWindow::TOPLEVEL: {
67     if (maximized_) {
68       xdg_surface_request_change_state(xdg_surface_,
69                                        XDG_SURFACE_STATE_MAXIMIZED,
70                                        false, 0);
71       maximized_ = false;
72     }
73     break;
74   }
75   case WaylandWindow::POPUP: {
76     WaylandDisplay* display = WaylandDisplay::GetInstance();
77     WaylandInputDevice* input_device = display->PrimaryInput();
78     wl_surface* surface = GetWLSurface();
79     wl_surface* parent_surface = shell_parent->GetWLSurface();
80     xdg_popup_ = xdg_shell_get_xdg_popup(display->GetShell()->GetXDGShell(),
81                                          surface,
82                                          parent_surface,
83                                          input_device->GetInputSeat(),
84                                          display->GetSerial(),
85                                          x,
86                                          y,
87                                          0);
88     static const xdg_popup_listener xdg_popup_listener = {
89       XDGShellSurface::HandlePopupPopupDone
90     };
91     xdg_popup_add_listener(xdg_popup_,
92                            &xdg_popup_listener,
93                            NULL);
94     DCHECK(xdg_popup_);
95     break;
96   }
97   case WaylandWindow::FULLSCREEN:
98     xdg_surface_request_change_state(xdg_surface_,
99                                      XDG_SURFACE_STATE_FULLSCREEN,
100                                      true, 0);
101     break;
102   case WaylandWindow::CUSTOM:
103       NOTREACHED() << "Unsupported shell type: " << type;
104     break;
105     default:
106       break;
107   }
108
109   WaylandShellSurface::FlushDisplay();
110 }
111
112 void XDGShellSurface::SetWindowTitle(const base::string16& title) {
113   xdg_surface_set_title(xdg_surface_, UTF16ToUTF8(title).c_str());
114   WaylandShellSurface::FlushDisplay();
115 }
116
117 void XDGShellSurface::Maximize() {
118   xdg_surface_request_change_state(xdg_surface_,
119                                    XDG_SURFACE_STATE_MAXIMIZED,
120                                    true, 0);
121   maximized_ = true;
122   WaylandShellSurface::FlushDisplay();
123 }
124
125 void XDGShellSurface::Minimize() {
126   xdg_surface_set_minimized(xdg_surface_);
127   minimized_ = true;
128 }
129
130 void XDGShellSurface::Unminimize() {
131   minimized_ = false;
132 }
133
134 bool XDGShellSurface::IsMinimized() const {
135   return minimized_;
136 }
137
138 void XDGShellSurface::HandleConfigure(void* data,
139                                       struct xdg_surface* xdg_surface,
140                                       int32_t width,
141                                       int32_t height) {
142   WaylandShellSurface::WindowResized(data, width, height);
143 }
144
145 void XDGShellSurface::HandleChangeState(void* data,
146                                         struct xdg_surface* xdg_surface,
147                                         uint32_t state,
148                                         uint32_t value,
149                                         uint32_t serial) {
150   xdg_surface_ack_change_state(xdg_surface, state, value, serial);
151 }
152
153 void XDGShellSurface::HandleActivate(void* data,
154                                      struct xdg_surface* xdg_surface) {
155   WaylandShellSurface::WindowActivated(data);
156 }
157
158 void XDGShellSurface::HandleDeactivate(void* data,
159                                        struct xdg_surface* xdg_surface) {
160   WaylandShellSurface::WindowDeActivated(data);
161 }
162
163 void XDGShellSurface::HandleDelete(void* data,
164                                    struct xdg_surface* xdg_surface) {
165 }
166
167 void XDGShellSurface::HandlePopupPopupDone(void* data,
168                                            struct xdg_popup* xdg_popup,
169                                            uint32_t serial) {
170   WaylandShellSurface::PopupDone();
171 }
172
173 }  // namespace ozonewayland