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_container.h" |
| 6 #include "ash/wm/property_util.h" |
| 7 #include "base/utf_string_conversions.h" |
| 8 #include "ui/aura/hostwm/host_window_delegate.h" |
| 9 #include "ui/aura/window.h" |
| 10 #include "ui/gfx/canvas.h" |
| 11 #include "ui/views/widget/widget.h" |
| 12 |
| 13 namespace ash { |
| 14 namespace internal { |
| 15 |
| 16 class HostWindowWidget : public views::Widget { |
| 17 public: |
| 18 explicit HostWindowWidget(views::Widget* client_widget) |
| 19 : client_widget_(client_widget) { |
| 20 } |
| 21 |
| 22 virtual bool OnKeyEvent(const views::KeyEvent& event) OVERRIDE { |
| 23 return false; |
| 24 } |
| 25 |
| 26 virtual void Close() OVERRIDE { |
| 27 aura::HostWindowDelegate* delegate = aura::GetHostWindowDelegate( |
| 28 client_widget_->GetNativeWindow()); |
| 29 if (delegate) { |
| 30 delegate->CloseWindow(); |
| 31 return; |
| 32 } |
| 33 Widget::Close(); |
| 34 } |
| 35 |
| 36 private: |
| 37 views::Widget* client_widget_; |
| 38 }; |
| 39 |
| 40 views::Widget* HostWindowContainer::CreateHostWindowContainerWidget( |
| 41 views::Widget* client_widget, |
| 42 const gfx::Rect& bounds, |
| 43 views::Widget::InitParams::Type type) { |
| 44 HostWindowWidget* widget = new HostWindowWidget(client_widget); |
| 45 views::Widget::InitParams params(type); |
| 46 params.delegate = new HostWindowContainer(client_widget); |
| 47 params.parent = NULL; |
| 48 params.bounds = bounds; |
| 49 widget->Init(params); |
| 50 widget->GetNativeView()->SetName("HostWindowContainer"); |
| 51 SetPersistsAcrossAllWorkspaces( |
| 52 widget->GetNativeView(), |
| 53 WINDOW_PERSISTS_ACROSS_ALL_WORKSPACES_VALUE_YES); |
| 54 widget->GetNativeView()->AddChild(client_widget->GetNativeView()); |
| 55 return widget; |
| 56 } |
| 57 |
| 58 HostWindowContainer::HostWindowContainer(views::Widget* client_widget) |
| 59 : client_widget_(client_widget) { |
| 60 } |
| 61 |
| 62 HostWindowContainer::~HostWindowContainer() { |
| 63 } |
| 64 |
| 65 void HostWindowContainer::OnPaint(gfx::Canvas* canvas) { |
| 66 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY); |
| 67 } |
| 68 |
| 69 gfx::Size HostWindowContainer::GetPreferredSize() { |
| 70 // TODO(reveman): depends on host window state |
| 71 return gfx::Size(1, 1); |
| 72 } |
| 73 |
| 74 void HostWindowContainer::Layout() { |
| 75 client_widget_->SetBounds( |
| 76 gfx::Rect(gfx::Point(client_widget_->GetNativeView()->bounds().origin()), |
| 77 gfx::Size(width(), height()))); |
| 78 } |
| 79 |
| 80 string16 HostWindowContainer::GetWindowTitle() const { |
| 81 // TODO(danakj): return the real title |
| 82 return ASCIIToUTF16(""); |
| 83 } |
| 84 |
| 85 views::View* HostWindowContainer::GetContentsView() { |
| 86 return this; |
| 87 } |
| 88 |
| 89 bool HostWindowContainer::CanResize() const { |
| 90 aura::HostWindowDelegate* delegate = aura::GetHostWindowDelegate( |
| 91 client_widget_->GetNativeWindow()); |
| 92 if (delegate) |
| 93 return delegate->CanResize(); |
| 94 |
| 95 return false; |
| 96 } |
| 97 |
| 98 bool HostWindowContainer::CanMaximize() const { |
| 99 // TODO(danakj): depends on host window state |
| 100 return false; |
| 101 } |
| 102 |
| 103 void HostWindowContainer::DeleteDelegate() { |
| 104 delete this; |
| 105 } |
| 106 |
| 107 } // namespace internal |
| 108 } // namespace ash |
OLD | NEW |