Index: ash/hostwm/host_window_manager.cc |
diff --git a/ash/hostwm/host_window_manager.cc b/ash/hostwm/host_window_manager.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..543ea07cb6b78ae9052614e514c346620af1be59 |
--- /dev/null |
+++ b/ash/hostwm/host_window_manager.cc |
@@ -0,0 +1,119 @@ |
+// 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 "ash/hostwm/host_window_manager.h" |
+ |
+#include "ash/hostwm/host_window_container.h" |
+#include "ash/shell.h" |
+#include "ui/views/widget/widget.h" |
+#include "ui/aura/window.h" |
+#include "ui/gfx/screen.h" |
+ |
+namespace { |
+ |
+// TODO(reveman): This should not be a constant. |
+const int kTitlebarHeight = 28; |
+ |
+class HostWindowClientWidget : public views::Widget { |
+public: |
+ virtual bool OnKeyEvent(const views::KeyEvent& event) { |
+ return false; |
+ } |
+}; |
+ |
+} |
+ |
+namespace ash { |
+namespace internal { |
+ |
+gfx::NativeWindow HostWindowManager::OnHostWindowCreated( |
+ const gfx::Rect& bounds, bool decorated) { |
+ int top_offset = decorated ? kTitlebarHeight : 0; |
+ HostWindowClientWidget* client_widget = new HostWindowClientWidget; |
+ views::Widget::InitParams params( |
+ views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
+ params.delegate = NULL; |
+ params.parent = NULL; |
+ params.bounds = gfx::Rect(gfx::Point(0, top_offset), bounds.size()); |
+ params.can_activate = false; |
+ client_widget->Init(params); |
+ client_widget->GetNativeView()->SetName("HostWindowClient"); |
+ client_widget->Show(); |
+ |
+ gfx::Rect container_bounds(bounds.x(), bounds.y() - top_offset, |
+ bounds.width(), bounds.height() + top_offset); |
+ HostWindowContainer::CreateHostWindowContainerWidget(client_widget, |
+ container_bounds, decorated ? views::Widget::InitParams::TYPE_WINDOW : |
+ views::Widget::InitParams::TYPE_MENU); |
+ |
+ // Return the native client window. |
+ return client_widget->GetNativeWindow(); |
+} |
+ |
+void HostWindowManager::OnHostWindowDestroyed( |
+ gfx::NativeWindow window) { |
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
+ window->GetToplevelWindow()); |
+ if (!widget) |
+ return; |
+ widget->Close(); |
+} |
+ |
+void HostWindowManager::OnHostWindowMovedOrResized( |
+ gfx::NativeWindow window, const gfx::Rect& bounds) { |
+ views::Widget* client_widget = views::Widget::GetWidgetForNativeWindow( |
+ window); |
+ if (!client_widget) |
+ return; |
+ client_widget->SetSize(bounds.size()); |
+ DCHECK(!client_widget->GetNativeView()->bounds().x()); |
+ DCHECK(!client_widget->GetNativeView()->bounds().y()); |
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
+ window->GetToplevelWindow()); |
+ if (!widget) |
+ return; |
+ widget->SetBounds(bounds); |
+} |
+ |
+void HostWindowManager::OnHostWindowMovedOrResizedConstrained( |
+ gfx::NativeWindow window, const gfx::Rect& bounds) { |
+ views::Widget* client_widget = views::Widget::GetWidgetForNativeWindow( |
+ window); |
+ if (!client_widget) |
+ return; |
+ DCHECK(!client_widget->GetNativeView()->bounds().x()); |
+ int top_offset = client_widget->GetNativeView()->bounds().y(); |
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
+ window->GetToplevelWindow()); |
+ if (!widget) |
+ return; |
+ gfx::Rect container_bounds(bounds.x(), bounds.y() - top_offset, |
+ bounds.width(), bounds.height() + top_offset); |
+ // TODO(reveman): Use SetBoundsConstrained(). |
+ gfx::Rect work_area = gfx::Screen::GetDisplayNearestPoint( |
+ bounds.origin()).work_area(); |
+ if (work_area.IsEmpty()) |
+ widget->SetBounds(container_bounds); |
+ else |
+ widget->SetBounds(container_bounds.AdjustToFit(work_area)); |
+} |
+ |
+void HostWindowManager::OnHostWindowVisibilityChanged( |
+ gfx::NativeWindow window, bool visible) { |
+ views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
+ window->GetToplevelWindow()); |
+ if (!widget) |
+ return; |
+ if (visible) |
+ widget->Show(); |
+ else |
+ widget->Hide(); |
+} |
+ |
+aura::RootWindow* HostWindowManager::GetRootWindow() { |
+ return ash::Shell::GetPrimaryRootWindow(); |
+} |
+ |
+} // namespace internal |
+} // namespace ash |