- add sources.
[platform/framework/web/crosswalk.git] / src / ozone / wayland / window.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Copyright 2013 Intel Corporation. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #include "ozone/wayland/window.h"
7
8 #include "base/logging.h"
9 #include "ozone/wayland/display.h"
10 #include "ozone/wayland/egl/egl_window.h"
11 #include "ozone/wayland/shell_surface.h"
12 #include "ozone/wayland/surface.h"
13
14 namespace ozonewayland {
15
16 WaylandWindow::WaylandWindow(unsigned handle) : shell_surface_(NULL),
17     handle_(handle),
18     window_(NULL),
19     type_(None),
20     allocation_(gfx::Rect(0, 0, 1, 1)) {
21 }
22
23 WaylandWindow::~WaylandWindow() {
24   wl_surface_set_user_data(GetSurface(), 0);
25   if (window_) {
26     delete window_;
27     window_ = NULL;
28   }
29
30   if (shell_surface_) {
31     delete shell_surface_;
32     shell_surface_ = NULL;
33   }
34 }
35
36 void WaylandWindow::SetShellAttributes(ShellType type) {
37   if (type_ == type)
38     return;
39
40   if (!shell_surface_) {
41     shell_surface_ = new WaylandShellSurface(this);
42     wl_surface_set_user_data(GetSurface(), this);
43   }
44
45   type_ = type;
46   shell_surface_->UpdateShellSurface(type_, NULL, 0, 0);
47 }
48
49 void WaylandWindow::SetShellAttributes(ShellType type,
50                                        WaylandShellSurface* shell_parent,
51                                        unsigned x,
52                                        unsigned y) {
53   DCHECK(shell_parent && (type == TRANSIENT));
54
55   if (!shell_surface_) {
56     shell_surface_ = new WaylandShellSurface(this);
57     wl_surface_set_user_data(GetSurface(), this);
58   }
59
60   type_ = type;
61   shell_surface_->UpdateShellSurface(type_, shell_parent, x, y);
62 }
63
64 void WaylandWindow::SetWindowTitle(const string16& title) {
65   shell_surface_->SetWindowTitle(title);
66 }
67
68 void WaylandWindow::Maximize() {
69   NOTIMPLEMENTED();
70 }
71
72 void WaylandWindow::Minimize() {
73   NOTIMPLEMENTED();
74 }
75
76 void WaylandWindow::Restore() {
77   NOTIMPLEMENTED();
78 }
79
80 void WaylandWindow::ToggleFullscreen() {
81   if (type_ == FULLSCREEN)
82     SetShellAttributes(TOPLEVEL);
83   else
84     SetShellAttributes(FULLSCREEN);
85 }
86
87 void WaylandWindow::RealizeAcceleratedWidget() {
88   if (!shell_surface_) {
89     LOG(ERROR) << "Shell type not set. Setting it to TopLevel";
90     SetShellAttributes(TOPLEVEL);
91   }
92
93   if (!window_)
94     window_ = new EGLWindow(shell_surface_->Surface()->wlSurface(),
95                             allocation_.width(), allocation_.height());
96 }
97
98 void WaylandWindow::HandleSwapBuffers() {
99   shell_surface_->Surface()->EnsureFrameCallBackDone();
100   shell_surface_->Surface()->AddFrameCallBack();
101 }
102
103 wl_egl_window* WaylandWindow::egl_window() const {
104   return window_ ? window_->egl_window() : 0;
105 }
106
107 struct wl_surface* WaylandWindow::GetSurface() const {
108   return shell_surface_ ? shell_surface_->Surface()->wlSurface() : 0;
109 }
110
111 bool WaylandWindow::SetBounds(const gfx::Rect& new_bounds) {
112   int width = new_bounds.width();
113   int height = new_bounds.height();
114   allocation_ = gfx::Rect(allocation_.x(), allocation_.y(), width, height);
115   if (!shell_surface_ || !window_)
116       return false;
117
118   return window_->Resize(shell_surface_->Surface(), width, height);
119 }
120
121 }  // namespace ozonewayland