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" | |
12 #include "ui/base/cursor/cursor.h" | 11 #include "ui/base/cursor/cursor.h" |
13 #include "ui/base/hit_test.h" | |
14 #include "ui/views/controls/native/native_view_host.h" | 12 #include "ui/views/controls/native/native_view_host.h" |
15 #include "ui/views/view_constants_aura.h" | 13 #include "ui/views/view_constants_aura.h" |
16 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
17 | 15 |
18 namespace views { | 16 namespace views { |
19 | 17 |
20 class NativeViewHostAura::ClippingWindowDelegate : public aura::WindowDelegate { | |
21 public: | |
22 explicit ClippingWindowDelegate(const NativeViewHost* host) : host_(host) {} | |
23 virtual ~ClippingWindowDelegate() {} | |
24 | |
25 virtual gfx::Size GetMinimumSize() const OVERRIDE { return gfx::Size(); } | |
26 virtual gfx::Size GetMaximumSize() const OVERRIDE { return gfx::Size(); } | |
27 virtual void OnBoundsChanged(const gfx::Rect& old_bounds, | |
28 const gfx::Rect& new_bounds) OVERRIDE {} | |
29 virtual gfx::NativeCursor GetCursor(const gfx::Point& point) OVERRIDE { | |
30 return gfx::kNullCursor; | |
31 } | |
32 virtual int GetNonClientComponent(const gfx::Point& point) const OVERRIDE { | |
33 return HTCLIENT; | |
34 } | |
35 virtual bool ShouldDescendIntoChildForEventHandling( | |
36 aura::Window* child, | |
37 const gfx::Point& location) OVERRIDE { return true; } | |
38 virtual bool CanFocus() OVERRIDE { | |
39 // Ask the hosted native view's delegate because directly calling | |
40 // aura::Window::CanFocus() will call back into this when checking whether | |
41 // parents can focus. | |
42 return host_->native_view() && host_->native_view()->delegate() | |
43 ? host_->native_view()->delegate()->CanFocus() | |
44 : true; | |
45 } | |
46 virtual void OnCaptureLost() OVERRIDE {} | |
47 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {} | |
48 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE {} | |
49 virtual void OnWindowDestroying(aura::Window* window) OVERRIDE {} | |
50 virtual void OnWindowDestroyed(aura::Window* window) OVERRIDE {} | |
51 virtual void OnWindowTargetVisibilityChanged(bool visible) OVERRIDE {} | |
52 virtual bool HasHitTestMask() const OVERRIDE { return false; } | |
53 virtual void GetHitTestMask(gfx::Path* mask) const OVERRIDE {} | |
54 | |
55 private: | |
56 const NativeViewHost* host_; | |
57 }; | |
58 | |
59 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) | 18 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
60 : host_(host), | 19 : host_(host), |
61 clipping_window_delegate_(new ClippingWindowDelegate(host)), | 20 clipping_window_(NULL) { |
62 clipping_window_(clipping_window_delegate_.get()) { | |
63 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); | 21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); |
64 clipping_window_.set_owned_by_parent(false); | 22 clipping_window_.set_owned_by_parent(false); |
65 clipping_window_.SetName("NativeViewHostAuraClip"); | 23 clipping_window_.SetName("NativeViewHostAuraClip"); |
66 clipping_window_.layer()->SetMasksToBounds(true); | 24 clipping_window_.layer()->SetMasksToBounds(true); |
67 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_)); | 25 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_)); |
68 } | 26 } |
69 | 27 |
70 NativeViewHostAura::~NativeViewHostAura() { | 28 NativeViewHostAura::~NativeViewHostAura() { |
71 if (host_->native_view()) { | 29 if (host_->native_view()) { |
72 host_->native_view()->RemoveObserver(this); | 30 host_->native_view()->RemoveObserver(this); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
215 } else { | 173 } else { |
216 clipping_window_.RemoveChild(host_->native_view()); | 174 clipping_window_.RemoveChild(host_->native_view()); |
217 } | 175 } |
218 host_->native_view()->SetBounds(clipping_window_.bounds()); | 176 host_->native_view()->SetBounds(clipping_window_.bounds()); |
219 } | 177 } |
220 if (clipping_window_.parent()) | 178 if (clipping_window_.parent()) |
221 clipping_window_.parent()->RemoveChild(&clipping_window_); | 179 clipping_window_.parent()->RemoveChild(&clipping_window_); |
222 } | 180 } |
223 | 181 |
224 } // namespace views | 182 } // namespace views |
OLD | NEW |