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 "ash/hostwm/host_window_manager.h" |
| 6 |
| 7 #include "ash/hostwm/host_window_container.h" |
| 8 #include "ash/shell.h" |
| 9 #include "ui/views/widget/widget.h" |
| 10 #include "ui/aura/window.h" |
| 11 #include "ui/gfx/screen.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 // TODO(reveman): This should not be a constant. |
| 16 const int kTitlebarHeight = 28; |
| 17 |
| 18 class HostWindowClientWidget : public views::Widget { |
| 19 public: |
| 20 virtual bool OnKeyEvent(const views::KeyEvent& event) { |
| 21 return false; |
| 22 } |
| 23 }; |
| 24 |
| 25 } |
| 26 |
| 27 namespace ash { |
| 28 namespace internal { |
| 29 |
| 30 gfx::NativeWindow HostWindowManager::OnHostWindowCreated( |
| 31 const gfx::Rect& bounds, bool decorated) { |
| 32 int top_offset = decorated ? kTitlebarHeight : 0; |
| 33 HostWindowClientWidget* client_widget = new HostWindowClientWidget; |
| 34 views::Widget::InitParams params( |
| 35 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |
| 36 params.delegate = NULL; |
| 37 params.parent = NULL; |
| 38 params.bounds = gfx::Rect(gfx::Point(0, top_offset), bounds.size()); |
| 39 params.can_activate = false; |
| 40 client_widget->Init(params); |
| 41 client_widget->GetNativeView()->SetName("HostWindowClient"); |
| 42 client_widget->Show(); |
| 43 |
| 44 gfx::Rect container_bounds(bounds.x(), bounds.y() - top_offset, |
| 45 bounds.width(), bounds.height() + top_offset); |
| 46 HostWindowContainer::CreateHostWindowContainerWidget(client_widget, |
| 47 container_bounds, decorated ? views::Widget::InitParams::TYPE_WINDOW : |
| 48 views::Widget::InitParams::TYPE_MENU); |
| 49 |
| 50 // Return the native client window. |
| 51 return client_widget->GetNativeWindow(); |
| 52 } |
| 53 |
| 54 void HostWindowManager::OnHostWindowDestroyed( |
| 55 gfx::NativeWindow window) { |
| 56 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
| 57 window->GetToplevelWindow()); |
| 58 if (!widget) |
| 59 return; |
| 60 widget->Close(); |
| 61 } |
| 62 |
| 63 void HostWindowManager::OnHostWindowMovedOrResized( |
| 64 gfx::NativeWindow window, const gfx::Rect& bounds) { |
| 65 views::Widget* client_widget = views::Widget::GetWidgetForNativeWindow( |
| 66 window); |
| 67 if (!client_widget) |
| 68 return; |
| 69 client_widget->SetSize(bounds.size()); |
| 70 DCHECK(!client_widget->GetNativeView()->bounds().x()); |
| 71 DCHECK(!client_widget->GetNativeView()->bounds().y()); |
| 72 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
| 73 window->GetToplevelWindow()); |
| 74 if (!widget) |
| 75 return; |
| 76 widget->SetBounds(bounds); |
| 77 } |
| 78 |
| 79 void HostWindowManager::OnHostWindowMovedOrResizedConstrained( |
| 80 gfx::NativeWindow window, const gfx::Rect& bounds) { |
| 81 views::Widget* client_widget = views::Widget::GetWidgetForNativeWindow( |
| 82 window); |
| 83 if (!client_widget) |
| 84 return; |
| 85 DCHECK(!client_widget->GetNativeView()->bounds().x()); |
| 86 int top_offset = client_widget->GetNativeView()->bounds().y(); |
| 87 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
| 88 window->GetToplevelWindow()); |
| 89 if (!widget) |
| 90 return; |
| 91 gfx::Rect container_bounds(bounds.x(), bounds.y() - top_offset, |
| 92 bounds.width(), bounds.height() + top_offset); |
| 93 // TODO(reveman): Use SetBoundsConstrained(). |
| 94 gfx::Rect work_area = gfx::Screen::GetDisplayNearestPoint( |
| 95 bounds.origin()).work_area(); |
| 96 if (work_area.IsEmpty()) |
| 97 widget->SetBounds(container_bounds); |
| 98 else |
| 99 widget->SetBounds(container_bounds.AdjustToFit(work_area)); |
| 100 } |
| 101 |
| 102 void HostWindowManager::OnHostWindowVisibilityChanged( |
| 103 gfx::NativeWindow window, bool visible) { |
| 104 views::Widget* widget = views::Widget::GetWidgetForNativeWindow( |
| 105 window->GetToplevelWindow()); |
| 106 if (!widget) |
| 107 return; |
| 108 if (visible) |
| 109 widget->Show(); |
| 110 else |
| 111 widget->Hide(); |
| 112 } |
| 113 |
| 114 aura::RootWindow* HostWindowManager::GetRootWindow() { |
| 115 return ash::Shell::GetPrimaryRootWindow(); |
| 116 } |
| 117 |
| 118 } // namespace internal |
| 119 } // namespace ash |
OLD | NEW |