Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(252)

Side by Side Diff: wm/foreign_window.cc

Issue 11485006: Add window manager component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Push gfx::AcceleratedWidget usage into platform specific code. Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « wm/foreign_window.h ('k') | wm/foreign_window_client_view.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013 The Chromium Authors. 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 "wm/foreign_window.h"
6
7 #include "ui/aura/window.h"
8 #include "ui/aura/window_property.h"
9 #include "ui/views/widget/widget.h"
10 #include "wm/foreign_window_client_view.h"
11 #include "wm/host/foreign_window_host.h"
12
13 namespace wm {
14
15 namespace {
16
17 DECLARE_WINDOW_PROPERTY_TYPE(ForeignWindow*)
18 DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ForeignWindow*, kForeignWindowKey, NULL);
19
20 ForeignWindowHost* CreateHost(ForeignWindow* foreign_window,
21 gfx::PluginWindowHandle window_handle) {
22 ForeignWindowHost* host = ForeignWindowHost::Create(window_handle);
23 host->SetDelegate(foreign_window);
24 return host;
25 }
26
27 } // namespace
28
29 ForeignWindow::CreateParams::CreateParams(
30 gfx::PluginWindowHandle a_window_handle,
31 gfx::Size a_preferred_size)
32 : window_handle(a_window_handle),
33 preferred_size(a_preferred_size) {
34 }
35
36 ForeignWindow::ForeignWindow(const CreateParams& params)
37 : ALLOW_THIS_IN_INITIALIZER_LIST(
38 host_(CreateHost(this, params.window_handle))),
39 preferred_size_(params.preferred_size),
40 display_state_(DISPLAY_WITHDRAWN),
41 destroyed_(false) {
42 }
43
44 ForeignWindow::~ForeignWindow() {
45 if (!client_view_)
46 return;
47
48 client_view_->GetNativeView()->ClearProperty(kForeignWindowKey);
49 }
50
51 void ForeignWindow::OnWindowContentsChanged() {
52 if (!client_view_)
53 return;
54
55 client_view_->OnWindowContentsChanged();
56 }
57
58 views::WidgetDelegate* ForeignWindow::CreateWidgetDelegate() {
59 AddRef(); // Balanced in DeleteDelegate();
60 return this;
61 }
62
63 views::ClientView* ForeignWindow::CreateClientView(views::Widget* widget) {
64 DCHECK(!client_view_);
65 ForeignWindowClientView* client_view = new ForeignWindowClientView(
66 host_->GetWindowHandle(), preferred_size_);
67 client_view->GetNativeView()->SetProperty(kForeignWindowKey, this);
68 client_view->GetNativeView()->Show();
69 widget->GetNativeView()->AddChild(client_view->GetNativeView());
70
71 // Keep a weak reference to the client view.
72 client_view_ = client_view->AsWeakPtr();
73
74 return client_view;
75 }
76
77 views::Widget* ForeignWindow::GetWidget() {
78 if (!client_view_)
79 return NULL;
80
81 return client_view_->GetWidget();
82 }
83
84 const views::Widget* ForeignWindow::GetWidget() const {
85 if (!client_view_)
86 return NULL;
87
88 return client_view_->GetWidget();
89 }
90
91 void ForeignWindow::DeleteDelegate() {
92 // The window has finished closing. Allow ourself to be deleted.
93 Release();
94 }
95
96 bool ForeignWindow::CanResize() const {
97 return false;
98 }
99
100 bool ForeignWindow::CanMaximize() const {
101 return false;
102 }
103
104 bool ForeignWindow::CanActivate() const {
105 return true;
106 }
107
108 void ForeignWindow::Close() {
109 host_->Close();
110 }
111
112 gfx::PluginWindowHandle ForeignWindow::GetWindowHandle() const {
113 return host_->GetWindowHandle();
114 }
115
116 gfx::NativeView ForeignWindow::GetNativeView() const {
117 if (!client_view_)
118 return NULL;
119
120 return client_view_->GetNativeView();
121 }
122
123 void ForeignWindow::SetDisplayState(ForeignWindow::DisplayState state) {
124 display_state_ = state;
125 }
126
127 ForeignWindow::DisplayState ForeignWindow::GetDisplayState() const {
128 return display_state_;
129 }
130
131 bool ForeignWindow::IsManaged() const {
132 return true;
133 }
134
135 bool ForeignWindow::HasBeenDestroyed() const {
136 return destroyed_;
137 }
138
139 void ForeignWindow::OnWindowSizeChanged(const gfx::Size& size) {
140 if (!client_view_)
141 return;
142
143 client_view_->OnWindowSizeChanged(size);
144 }
145
146 void ForeignWindow::OnWindowVisibilityChanged(bool visible) {
147 if (!client_view_)
148 return;
149
150 client_view_->OnWindowVisibilityChanged(visible);
151 }
152
153 void ForeignWindow::OnWindowDestroyed() {
154 DCHECK(!destroyed_);
155 destroyed_ = true;
156
157 if (!client_view_)
158 return;
159
160 client_view_->OnWindowDestroyed();
161 }
162
163 // static
164 ForeignWindow* ForeignWindow::GetForeignWindowForNativeView(
165 gfx::NativeView native_view) {
166 return native_view->GetProperty(kForeignWindowKey);
167 }
168
169 } // namespace wm
OLDNEW
« no previous file with comments | « wm/foreign_window.h ('k') | wm/foreign_window_client_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698