Chromium Code Reviews| Index: wm/foreign_window.cc |
| diff --git a/wm/foreign_window.cc b/wm/foreign_window.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9410159f75bd68b9d8c40cc1b3d23a292900432d |
| --- /dev/null |
| +++ b/wm/foreign_window.cc |
| @@ -0,0 +1,173 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "wm/foreign_window.h" |
| + |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_property.h" |
| +#include "ui/views/widget/widget.h" |
| +#include "wm/foreign_window_client_view.h" |
| +#include "wm/host/foreign_window_host.h" |
| + |
| +namespace wm { |
| + |
| +namespace { |
| + |
| +DECLARE_WINDOW_PROPERTY_TYPE(ForeignWindow*) |
| +DEFINE_LOCAL_WINDOW_PROPERTY_KEY(ForeignWindow*, kForeignWindowKey, NULL); |
| + |
| +ForeignWindowHost* CreateHost(ForeignWindow* foreign_window, |
| + gfx::PluginWindowHandle window_handle) { |
| + ForeignWindowHost* host = ForeignWindowHost::Create(window_handle); |
| + host->SetDelegate(foreign_window); |
| + return host; |
| +} |
| + |
| +} // namespace |
| + |
| +ForeignWindow::CreateParams::CreateParams( |
| + gfx::PluginWindowHandle a_window_handle, |
| + const gfx::Size& a_preferred_size) |
|
danakj
2013/02/21 01:33:15
by value
|
| + : window_handle(a_window_handle), |
| + preferred_size(a_preferred_size) { |
| +} |
| + |
| +ForeignWindow::ForeignWindow(const CreateParams& params) |
| + : ALLOW_THIS_IN_INITIALIZER_LIST( |
| + host_(CreateHost(this, params.window_handle))), |
| + preferred_size_(params.preferred_size), |
| + display_state_(DISPLAY_WITHDRAWN), |
| + destroyed_(false) { |
| +} |
| + |
| +ForeignWindow::~ForeignWindow() { |
| + if (!client_view_) |
| + return; |
| + |
| + client_view_->GetNativeView()->ClearProperty(kForeignWindowKey); |
| +} |
| + |
| +void ForeignWindow::OnWindowContentsChanged() { |
| + if (!client_view_) |
| + return; |
| + |
| + client_view_->OnWindowContentsChanged(); |
| +} |
| + |
| +ForeignWindow* ForeignWindow::AsForeignWindow() { |
| + return this; |
| +} |
| + |
| +views::WidgetDelegate* ForeignWindow::CreateWidgetDelegate() { |
| + AddRef(); // Balanced in DeleteDelegate(); |
|
danakj
2013/02/21 01:33:15
T_T
|
| + return this; |
| +} |
| + |
| +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
|
| + DCHECK(!client_view_); |
| + ForeignWindowClientView* client_view = new ForeignWindowClientView( |
| + host_->GetWindowHandle(), preferred_size_); |
| + client_view->GetNativeView()->SetProperty(kForeignWindowKey, this); |
| + client_view->GetNativeView()->Show(); |
| + widget->GetNativeView()->AddChild(client_view->GetNativeView()); |
| + |
| + // Keep a weak reference to the client view. |
| + client_view_ = client_view->AsWeakPtr(); |
| + |
| + return client_view; |
| +} |
| + |
| +views::Widget* ForeignWindow::GetWidget() { |
| + if (!client_view_) |
| + return NULL; |
| + |
| + return client_view_->GetWidget(); |
| +} |
| + |
| +const views::Widget* ForeignWindow::GetWidget() const { |
| + if (!client_view_) |
| + return NULL; |
| + |
| + return client_view_->GetWidget(); |
| +} |
| + |
| +void ForeignWindow::DeleteDelegate() { |
| + // The window has finished closing. Allow ourself to be deleted. |
| + Release(); |
| +} |
| + |
| +bool ForeignWindow::CanResize() const { |
| + return false; |
| +} |
| + |
| +bool ForeignWindow::CanMaximize() const { |
| + return false; |
| +} |
| + |
| +bool ForeignWindow::CanActivate() const { |
| + return true; |
| +} |
| + |
| +void ForeignWindow::Close() { |
| + host_->Close(); |
| +} |
| + |
| +gfx::PluginWindowHandle ForeignWindow::GetWindowHandle() const { |
| + return host_->GetWindowHandle(); |
| +} |
| + |
| +void ForeignWindow::SetWindowSize(const gfx::Size& size) { |
| + if (!client_view_) |
| + return; |
| + |
| + client_view_->SetWindowSize(size); |
| +} |
| + |
| +void ForeignWindow::SetWindowVisible(bool visible) { |
| + if (!client_view_) |
| + return; |
| + |
| + client_view_->SetWindowVisible(visible); |
| +} |
| + |
| +void ForeignWindow::OnWindowDestroyed() { |
| + DCHECK(!destroyed_); |
| + destroyed_ = true; |
| + |
| + if (!client_view_) |
| + return; |
| + |
| + client_view_->OnWindowDestroyed(); |
| +} |
| + |
| +gfx::NativeView ForeignWindow::GetNativeView() const { |
| + if (!client_view_) |
| + return NULL; |
| + |
| + return client_view_->GetNativeView(); |
| +} |
| + |
| +void ForeignWindow::SetDisplayState(ForeignWindow::DisplayState state) { |
| + display_state_ = state; |
| +} |
| + |
| +ForeignWindow::DisplayState ForeignWindow::GetDisplayState() const { |
| + return display_state_; |
| +} |
| + |
| +bool ForeignWindow::IsManaged() const { |
| + return true; |
| +} |
| + |
| +bool ForeignWindow::HasBeenDestroyed() const { |
| + return destroyed_; |
| +} |
| + |
| +// static |
| +ForeignWindow* ForeignWindow::GetForeignWindowForNativeView( |
| + gfx::NativeView native_view) { |
| + return native_view->GetProperty(kForeignWindowKey); |
| +} |
| + |
| +} // namespace wm |