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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « wm/foreign_window.h ('k') | wm/foreign_window_client_view.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: wm/foreign_window.cc
diff --git a/wm/foreign_window.cc b/wm/foreign_window.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2d1476c5db489f28d3771090a73d0fc8ec073001
--- /dev/null
+++ b/wm/foreign_window.cc
@@ -0,0 +1,169 @@
+// Copyright (c) 2013 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,
+ gfx::Size a_preferred_size)
+ : 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();
+}
+
+views::WidgetDelegate* ForeignWindow::CreateWidgetDelegate() {
+ AddRef(); // Balanced in DeleteDelegate();
+ return this;
+}
+
+views::ClientView* ForeignWindow::CreateClientView(views::Widget* widget) {
+ 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();
+}
+
+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_;
+}
+
+void ForeignWindow::OnWindowSizeChanged(const gfx::Size& size) {
+ if (!client_view_)
+ return;
+
+ client_view_->OnWindowSizeChanged(size);
+}
+
+void ForeignWindow::OnWindowVisibilityChanged(bool visible) {
+ if (!client_view_)
+ return;
+
+ client_view_->OnWindowVisibilityChanged(visible);
+}
+
+void ForeignWindow::OnWindowDestroyed() {
+ DCHECK(!destroyed_);
+ destroyed_ = true;
+
+ if (!client_view_)
+ return;
+
+ client_view_->OnWindowDestroyed();
+}
+
+// static
+ForeignWindow* ForeignWindow::GetForeignWindowForNativeView(
+ gfx::NativeView native_view) {
+ return native_view->GetProperty(kForeignWindowKey);
+}
+
+} // namespace wm
« 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