Chromium Code Reviews| 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 "wm/foreign_window_client_view.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "ui/aura/window.h" | |
| 9 #include "ui/aura/window_delegate.h" | |
| 10 #include "ui/base/hit_test.h" | |
| 11 #include "ui/gfx/canvas.h" | |
| 12 #include "ui/views/widget/widget.h" | |
| 13 #include "wm/gpu/foreign_window_texture_factory.h" | |
| 14 | |
| 15 namespace { | |
| 16 | |
| 17 class ContentsViewImpl : public views::View { | |
| 18 public: | |
| 19 ContentsViewImpl() {} | |
| 20 virtual ~ContentsViewImpl() {} | |
| 21 | |
| 22 // Overridden from views::View: | |
| 23 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE { | |
| 24 canvas->FillRect(GetLocalBounds(), SK_ColorDKGRAY); | |
| 25 } | |
| 26 | |
| 27 private: | |
| 28 DISALLOW_COPY_AND_ASSIGN(ContentsViewImpl); | |
| 29 }; | |
| 30 | |
| 31 class WindowDelegateImpl : public aura::WindowDelegate { | |
| 32 public: | |
| 33 WindowDelegateImpl() {} | |
| 34 virtual ~WindowDelegateImpl() {} | |
| 35 | |
| 36 // Overridden from aura::WindowDelegate: | |
| 37 virtual gfx::Size GetMinimumSize() const OVERRIDE { | |
| 38 return gfx::Size(); | |
| 39 } | |
| 40 virtual gfx::Size GetMaximumSize() const OVERRIDE { | |
| 41 return gfx::Size(); | |
| 42 } | |
| 43 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 44 const gfx::Rect& new_bounds) OVERRIDE {} | |
| 45 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { | |
| 46 return gfx::kNullCursor; | |
| 47 } | |
| 48 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
| 49 return HTCLIENT; | |
| 50 } | |
| 51 virtual bool ShouldDescendIntoChildForEventHandling( | |
| 52 aura::Window* child, | |
| 53 const gfx::Point& location) OVERRIDE { | |
| 54 return false; | |
| 55 } | |
| 56 virtual bool CanFocus() OVERRIDE { | |
| 57 return true; | |
| 58 } | |
| 59 virtual void OnCaptureLost() OVERRIDE {} | |
| 60 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {} | |
| 61 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE { | |
| 62 } | |
| 63 virtual void OnWindowDestroying() OVERRIDE {} | |
| 64 virtual void OnWindowDestroyed() OVERRIDE { | |
| 65 delete this; | |
| 66 } | |
| 67 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} | |
| 68 virtual bool HasHitTestMask() const OVERRIDE { | |
| 69 return false; | |
| 70 } | |
| 71 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | |
| 72 virtual scoped_refptr<ui::Texture> CopyTexture() OVERRIDE { | |
| 73 NOTIMPLEMENTED(); | |
| 74 return scoped_refptr<ui::Texture>(); | |
| 75 } | |
| 76 | |
| 77 private: | |
| 78 DISALLOW_COPY_AND_ASSIGN(WindowDelegateImpl); | |
| 79 }; | |
| 80 | |
| 81 } // namespace | |
| 82 | |
| 83 namespace wm { | |
| 84 | |
| 85 ForeignWindowClientView::ForeignWindowClientView( | |
| 86 gfx::PluginWindowHandle window_handle, | |
| 87 gfx::Size preferred_size) | |
| 88 : views::ClientView(NULL, NULL), | |
| 89 window_handle_(window_handle), | |
| 90 preferred_size_(preferred_size), | |
| 91 window_visible_(false), | |
| 92 window_destroyed_(false), | |
| 93 pending_texture_created_count_(0) { | |
| 94 ForeignWindowTextureFactory::GetInstance()->AddObserver(this); | |
| 95 contents_view_.reset(new ContentsViewImpl); | |
| 96 set_contents_view(contents_view_.get()); | |
| 97 window_.reset(new aura::Window(new WindowDelegateImpl)); | |
| 98 window_->set_owned_by_parent(false); | |
| 99 window_->SetType(aura::client::WINDOW_TYPE_CONTROL); | |
| 100 window_->SetTransparent(false); | |
| 101 window_->Init(ui::LAYER_TEXTURED); | |
| 102 window_->layer()->SetMasksToBounds(true); | |
| 103 window_->SetName("ForeignWindowClientView"); | |
| 104 } | |
| 105 | |
| 106 ForeignWindowClientView::~ForeignWindowClientView() { | |
| 107 ForeignWindowTextureFactory::GetInstance()->RemoveObserver(this); | |
| 108 } | |
| 109 | |
| 110 gfx::Size ForeignWindowClientView::GetPreferredSize() { | |
| 111 return preferred_size_; | |
| 112 } | |
| 113 | |
| 114 gfx::Size ForeignWindowClientView::GetMinimumSize() { | |
| 115 return gfx::Size(1, 1); | |
| 116 } | |
| 117 | |
| 118 void ForeignWindowClientView::OnBoundsChanged( | |
| 119 const gfx::Rect& previous_bounds) { | |
| 120 window_->SetBounds(bounds()); | |
| 121 } | |
| 122 | |
| 123 void ForeignWindowClientView::OnLostResources() { | |
| 124 window_->SetExternalTexture(NULL); | |
|
danakj
2013/02/21 01:33:15
how come this doesn't set texture_ to NULL as well
reveman
2013/02/22 01:26:44
we could but it's not necessary. not doing this is
| |
| 125 | |
| 126 if (window_visible_) | |
| 127 CreateTexture(); | |
| 128 } | |
| 129 | |
| 130 gfx::NativeView ForeignWindowClientView::GetNativeView() const { | |
| 131 return window_.get(); | |
| 132 } | |
| 133 | |
| 134 void ForeignWindowClientView::OnWindowContentsChanged() { | |
| 135 if (pending_texture_created_count_) | |
| 136 return; | |
| 137 | |
| 138 if (texture_) { | |
| 139 texture_->OnContentsChanged(); | |
| 140 | |
| 141 GetNativeView()->SchedulePaintInRect( | |
| 142 gfx::Rect(GetNativeView()->bounds().size())); | |
| 143 } else { | |
| 144 CreateTexture(); | |
| 145 } | |
| 146 } | |
| 147 | |
| 148 void ForeignWindowClientView::OnWindowDestroyed() { | |
| 149 window_destroyed_ = true; | |
| 150 } | |
| 151 | |
| 152 void ForeignWindowClientView::SetWindowSize(const gfx::Size& size) { | |
| 153 if (window_size_ == size) | |
| 154 return; | |
| 155 | |
| 156 window_size_ = size; | |
| 157 | |
| 158 if (window_visible_) | |
| 159 CreateTexture(); | |
| 160 } | |
| 161 | |
| 162 void ForeignWindowClientView::SetWindowVisible(bool visible) { | |
| 163 window_visible_ = visible; | |
| 164 | |
| 165 if (!visible) | |
| 166 texture_ = NULL; | |
|
danakj
2013/02/21 01:33:15
how come this doesn't call window->SetExternalText
reveman
2013/02/22 01:26:44
that would prevent any ash window animations that
| |
| 167 } | |
| 168 | |
| 169 void ForeignWindowClientView::CreateTexture() { | |
| 170 ++pending_texture_created_count_; | |
| 171 | |
| 172 DCHECK(!window_destroyed_); | |
| 173 ForeignWindowTextureFactory* factory = | |
| 174 ForeignWindowTextureFactory::GetInstance(); | |
| 175 factory->CreateTextureForForeignWindow( | |
| 176 window_handle_, | |
| 177 false, | |
| 178 1.0, | |
| 179 base::Bind(&ForeignWindowClientView::OnTextureCreated, AsWeakPtr())); | |
| 180 } | |
| 181 | |
| 182 void ForeignWindowClientView::OnTextureCreated( | |
| 183 scoped_refptr<ForeignWindowTexture> texture) { | |
| 184 --pending_texture_created_count_; | |
| 185 | |
| 186 if (!texture) | |
| 187 return; | |
| 188 | |
| 189 texture_ = texture; | |
| 190 window_->SetExternalTexture(texture); | |
| 191 } | |
| 192 | |
| 193 } // namespace wm | |
| OLD | NEW |