OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/native/native_view_host_aura.h" | 5 #include "ui/views/controls/native/native_view_host_aura.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
9 #include "ui/aura/client/focus_client.h" | 9 #include "ui/aura/client/focus_client.h" |
10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/aura/window_delegate.h" |
11 #include "ui/base/cursor/cursor.h" | 12 #include "ui/base/cursor/cursor.h" |
| 13 #include "ui/base/hit_test.h" |
12 #include "ui/views/controls/native/native_view_host.h" | 14 #include "ui/views/controls/native/native_view_host.h" |
13 #include "ui/views/view_constants_aura.h" | 15 #include "ui/views/view_constants_aura.h" |
14 #include "ui/views/widget/widget.h" | 16 #include "ui/views/widget/widget.h" |
15 | 17 |
16 namespace views { | 18 namespace views { |
17 | 19 |
| 20 class NativeViewHostAura::ClippingWindowDelegate : public aura::WindowDelegate { |
| 21 public: |
| 22 ClippingWindowDelegate() : native_view_(NULL) {} |
| 23 virtual ~ClippingWindowDelegate() {} |
| 24 |
| 25 void set_native_view(aura::Window* native_view) { |
| 26 native_view_ = native_view; |
| 27 } |
| 28 |
| 29 virtual gfx::Size GetMinimumSize() const OVERRIDE { return gfx::Size(); } |
| 30 virtual gfx::Size GetMaximumSize() const OVERRIDE { return gfx::Size(); } |
| 31 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, |
| 32 const gfx::Rect& new_bounds) OVERRIDE {} |
| 33 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { |
| 34 return gfx::kNullCursor; |
| 35 } |
| 36 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { |
| 37 return HTCLIENT; |
| 38 } |
| 39 virtual bool ShouldDescendIntoChildForEventHandling( |
| 40 aura::Window* child, |
| 41 const gfx::Point& location) OVERRIDE { return true; } |
| 42 virtual bool CanFocus() OVERRIDE { |
| 43 // Ask the hosted native view's delegate because directly calling |
| 44 // aura::Window::CanFocus() will call back into this when checking whether |
| 45 // parents can focus. |
| 46 return native_view_ && native_view_->delegate() |
| 47 ? native_view_->delegate()->CanFocus() |
| 48 : true; |
| 49 } |
| 50 virtual void OnCaptureLost() OVERRIDE {} |
| 51 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {} |
| 52 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} |
| 53 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} |
| 54 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} |
| 55 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} |
| 56 virtual bool HasHitTestMask() const OVERRIDE { return false; } |
| 57 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} |
| 58 |
| 59 private: |
| 60 aura::Window* native_view_; |
| 61 }; |
| 62 |
18 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) | 63 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
19 : host_(host), | 64 : host_(host), |
20 clipping_window_(NULL) { | 65 clipping_window_delegate_(new ClippingWindowDelegate()), |
| 66 clipping_window_(clipping_window_delegate_.get()) { |
21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 67 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
22 clipping_window_.set_owned_by_parent(false); | 68 clipping_window_.set_owned_by_parent(false); |
23 clipping_window_.SetName("NativeViewHostAuraClip"); | 69 clipping_window_.SetName("NativeViewHostAuraClip"); |
24 clipping_window_.layer()->SetMasksToBounds(true); | 70 clipping_window_.layer()->SetMasksToBounds(true); |
25 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_)); | 71 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_)); |
26 } | 72 } |
27 | 73 |
28 NativeViewHostAura::~NativeViewHostAura() { | 74 NativeViewHostAura::~NativeViewHostAura() { |
29 if (host_->native_view()) { | 75 if (host_->native_view()) { |
30 host_->native_view()->RemoveObserver(this); | 76 host_->native_view()->RemoveObserver(this); |
31 host_->native_view()->ClearProperty(views::kHostViewKey); | 77 host_->native_view()->ClearProperty(views::kHostViewKey); |
32 host_->native_view()->ClearProperty(aura::client::kHostWindowKey); | 78 host_->native_view()->ClearProperty(aura::client::kHostWindowKey); |
33 clipping_window_.ClearProperty(views::kHostViewKey); | 79 clipping_window_.ClearProperty(views::kHostViewKey); |
34 if (host_->native_view()->parent() == &clipping_window_) | 80 if (host_->native_view()->parent() == &clipping_window_) |
35 clipping_window_.RemoveChild(host_->native_view()); | 81 clipping_window_.RemoveChild(host_->native_view()); |
36 } | 82 } |
37 } | 83 } |
38 | 84 |
39 //////////////////////////////////////////////////////////////////////////////// | 85 //////////////////////////////////////////////////////////////////////////////// |
40 // NativeViewHostAura, NativeViewHostWrapper implementation: | 86 // NativeViewHostAura, NativeViewHostWrapper implementation: |
41 void NativeViewHostAura::AttachNativeView() { | 87 void NativeViewHostAura::AttachNativeView() { |
| 88 clipping_window_delegate_->set_native_view(host_->native_view()); |
42 host_->native_view()->AddObserver(this); | 89 host_->native_view()->AddObserver(this); |
43 host_->native_view()->SetProperty(views::kHostViewKey, | 90 host_->native_view()->SetProperty(views::kHostViewKey, |
44 static_cast<View*>(host_)); | 91 static_cast<View*>(host_)); |
45 AddClippingWindow(); | 92 AddClippingWindow(); |
46 } | 93 } |
47 | 94 |
48 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { | 95 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { |
| 96 clipping_window_delegate_->set_native_view(NULL); |
49 RemoveClippingWindow(); | 97 RemoveClippingWindow(); |
50 if (!destroyed) { | 98 if (!destroyed) { |
51 host_->native_view()->RemoveObserver(this); | 99 host_->native_view()->RemoveObserver(this); |
52 host_->native_view()->ClearProperty(views::kHostViewKey); | 100 host_->native_view()->ClearProperty(views::kHostViewKey); |
53 host_->native_view()->ClearProperty(aura::client::kHostWindowKey); | 101 host_->native_view()->ClearProperty(aura::client::kHostWindowKey); |
54 host_->native_view()->Hide(); | 102 host_->native_view()->Hide(); |
55 if (host_->native_view()->parent()) | 103 if (host_->native_view()->parent()) |
56 Widget::ReparentNativeView(host_->native_view(), NULL); | 104 Widget::ReparentNativeView(host_->native_view(), NULL); |
57 } | 105 } |
58 } | 106 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { | 173 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { |
126 return NULL; | 174 return NULL; |
127 } | 175 } |
128 | 176 |
129 gfx::NativeCursor NativeViewHostAura::GetCursor(int x, int y) { | 177 gfx::NativeCursor NativeViewHostAura::GetCursor(int x, int y) { |
130 if (host_->native_view()) | 178 if (host_->native_view()) |
131 return host_->native_view()->GetCursor(gfx::Point(x, y)); | 179 return host_->native_view()->GetCursor(gfx::Point(x, y)); |
132 return gfx::kNullCursor; | 180 return gfx::kNullCursor; |
133 } | 181 } |
134 | 182 |
| 183 void NativeViewHostAura::OnWindowDestroying(aura::Window* window) { |
| 184 DCHECK(window == host_->native_view()); |
| 185 clipping_window_delegate_->set_native_view(NULL); |
| 186 } |
| 187 |
135 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { | 188 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { |
136 DCHECK(window == host_->native_view()); | 189 DCHECK(window == host_->native_view()); |
137 host_->NativeViewDestroyed(); | 190 host_->NativeViewDestroyed(); |
138 } | 191 } |
139 | 192 |
140 // static | 193 // static |
141 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 194 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
142 NativeViewHost* host) { | 195 NativeViewHost* host) { |
143 return new NativeViewHostAura(host); | 196 return new NativeViewHostAura(host); |
144 } | 197 } |
(...skipping 28 matching lines...) Expand all Loading... |
173 } else { | 226 } else { |
174 clipping_window_.RemoveChild(host_->native_view()); | 227 clipping_window_.RemoveChild(host_->native_view()); |
175 } | 228 } |
176 host_->native_view()->SetBounds(clipping_window_.bounds()); | 229 host_->native_view()->SetBounds(clipping_window_.bounds()); |
177 } | 230 } |
178 if (clipping_window_.parent()) | 231 if (clipping_window_.parent()) |
179 clipping_window_.parent()->RemoveChild(&clipping_window_); | 232 clipping_window_.parent()->RemoveChild(&clipping_window_); |
180 } | 233 } |
181 | 234 |
182 } // namespace views | 235 } // namespace views |
OLD | NEW |