OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2012 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 const gfx::Size& a_preferred_size) | |
danakj
2013/02/21 01:33:15
by value
| |
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 ForeignWindow* ForeignWindow::AsForeignWindow() { | |
59 return this; | |
60 } | |
61 | |
62 views::WidgetDelegate* ForeignWindow::CreateWidgetDelegate() { | |
63 AddRef(); // Balanced in DeleteDelegate(); | |
danakj
2013/02/21 01:33:15
T_T
| |
64 return this; | |
65 } | |
66 | |
67 views::ClientView* ForeignWindow::CreateClientView(views::Widget* widget) { | |
danakj
2013/02/21 01:33:15
can you give |widget| a more descriptive name? is
reveman
2013/02/22 01:26:44
This is the implementation of WidgetDelegate. |wid
danakj
2013/02/22 21:42:59
I see, okay. I saw the AddChild() and was unsure w
| |
68 DCHECK(!client_view_); | |
69 ForeignWindowClientView* client_view = new ForeignWindowClientView( | |
70 host_->GetWindowHandle(), preferred_size_); | |
71 client_view->GetNativeView()->SetProperty(kForeignWindowKey, this); | |
72 client_view->GetNativeView()->Show(); | |
73 widget->GetNativeView()->AddChild(client_view->GetNativeView()); | |
74 | |
75 // Keep a weak reference to the client view. | |
76 client_view_ = client_view->AsWeakPtr(); | |
77 | |
78 return client_view; | |
79 } | |
80 | |
81 views::Widget* ForeignWindow::GetWidget() { | |
82 if (!client_view_) | |
83 return NULL; | |
84 | |
85 return client_view_->GetWidget(); | |
86 } | |
87 | |
88 const views::Widget* ForeignWindow::GetWidget() const { | |
89 if (!client_view_) | |
90 return NULL; | |
91 | |
92 return client_view_->GetWidget(); | |
93 } | |
94 | |
95 void ForeignWindow::DeleteDelegate() { | |
96 // The window has finished closing. Allow ourself to be deleted. | |
97 Release(); | |
98 } | |
99 | |
100 bool ForeignWindow::CanResize() const { | |
101 return false; | |
102 } | |
103 | |
104 bool ForeignWindow::CanMaximize() const { | |
105 return false; | |
106 } | |
107 | |
108 bool ForeignWindow::CanActivate() const { | |
109 return true; | |
110 } | |
111 | |
112 void ForeignWindow::Close() { | |
113 host_->Close(); | |
114 } | |
115 | |
116 gfx::PluginWindowHandle ForeignWindow::GetWindowHandle() const { | |
117 return host_->GetWindowHandle(); | |
118 } | |
119 | |
120 void ForeignWindow::SetWindowSize(const gfx::Size& size) { | |
121 if (!client_view_) | |
122 return; | |
123 | |
124 client_view_->SetWindowSize(size); | |
125 } | |
126 | |
127 void ForeignWindow::SetWindowVisible(bool visible) { | |
128 if (!client_view_) | |
129 return; | |
130 | |
131 client_view_->SetWindowVisible(visible); | |
132 } | |
133 | |
134 void ForeignWindow::OnWindowDestroyed() { | |
135 DCHECK(!destroyed_); | |
136 destroyed_ = true; | |
137 | |
138 if (!client_view_) | |
139 return; | |
140 | |
141 client_view_->OnWindowDestroyed(); | |
142 } | |
143 | |
144 gfx::NativeView ForeignWindow::GetNativeView() const { | |
145 if (!client_view_) | |
146 return NULL; | |
147 | |
148 return client_view_->GetNativeView(); | |
149 } | |
150 | |
151 void ForeignWindow::SetDisplayState(ForeignWindow::DisplayState state) { | |
152 display_state_ = state; | |
153 } | |
154 | |
155 ForeignWindow::DisplayState ForeignWindow::GetDisplayState() const { | |
156 return display_state_; | |
157 } | |
158 | |
159 bool ForeignWindow::IsManaged() const { | |
160 return true; | |
161 } | |
162 | |
163 bool ForeignWindow::HasBeenDestroyed() const { | |
164 return destroyed_; | |
165 } | |
166 | |
167 // static | |
168 ForeignWindow* ForeignWindow::GetForeignWindowForNativeView( | |
169 gfx::NativeView native_view) { | |
170 return native_view->GetProperty(kForeignWindowKey); | |
171 } | |
172 | |
173 } // namespace wm | |
OLD | NEW |