Upstream version 9.38.204.0
[platform/framework/web/crosswalk.git] / src / ozone / wayland / shell / 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/shell_surface.h"
6
7 #include "ozone/ui/events/event_factory_ozone_wayland.h"
8 #include "ozone/wayland/display.h"
9 #include "ozone/wayland/input_device.h"
10
11 namespace ozonewayland {
12
13 WaylandShellSurface::WaylandShellSurface()
14     : surface_(NULL) {
15   WaylandDisplay* display = WaylandDisplay::GetInstance();
16   surface_ = wl_compositor_create_surface(display->GetCompositor());
17 }
18
19 WaylandShellSurface::~WaylandShellSurface() {
20   DCHECK(surface_);
21   wl_surface_destroy(surface_);
22   FlushDisplay();
23 }
24
25 struct wl_surface* WaylandShellSurface::GetWLSurface() const {
26     return surface_;
27 }
28
29 void WaylandShellSurface::FlushDisplay() const {
30   WaylandDisplay* display = WaylandDisplay::GetInstance();
31   DCHECK(display);
32   display->FlushDisplay();
33 }
34
35 void WaylandShellSurface::PopupDone() {
36   WaylandInputDevice* input = WaylandDisplay::GetInstance()->PrimaryInput();
37   ui::EventConverterOzoneWayland* dispatcher =
38       ui::EventFactoryOzoneWayland::GetInstance()->EventConverter();
39
40   if (!input->GetGrabWindowHandle())
41     return;
42   dispatcher->CloseWidget(input->GetGrabWindowHandle());
43   input->SetGrabWindowHandle(0, 0);
44 }
45
46 void WaylandShellSurface::WindowResized(void* data,
47                                  unsigned width,
48                                  unsigned height) {
49   WaylandWindow *window = static_cast<WaylandWindow*>(data);
50   ui::EventConverterOzoneWayland* dispatcher =
51       ui::EventFactoryOzoneWayland::GetInstance()->EventConverter();
52   dispatcher->WindowResized(window->Handle(), width, height);
53 }
54
55 void WaylandShellSurface::WindowActivated(void *data) {
56   WaylandWindow *window = static_cast<WaylandWindow*>(data);
57   WaylandShellSurface* shellSurface = window->ShellSurface();
58
59   if (shellSurface->IsMinimized()) {
60     shellSurface->Unminimize();
61
62     ui::EventConverterOzoneWayland* dispatcher =
63       ui::EventFactoryOzoneWayland::GetInstance()->EventConverter();
64     dispatcher->WindowUnminimized(window->Handle());
65   }
66 }
67
68 }  // namespace ozonewayland