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/focus_client.h" | 8 #include "ui/aura/client/focus_client.h" |
9 #include "ui/aura/window.h" | 9 #include "ui/aura/window.h" |
10 #include "ui/base/cursor/cursor.h" | 10 #include "ui/base/cursor/cursor.h" |
11 #include "ui/views/controls/native/native_view_host.h" | 11 #include "ui/views/controls/native/native_view_host.h" |
12 #include "ui/views/view_constants_aura.h" | 12 #include "ui/views/view_constants_aura.h" |
13 #include "ui/views/widget/widget.h" | 13 #include "ui/views/widget/widget.h" |
14 | 14 |
15 namespace views { | 15 namespace views { |
16 | 16 |
17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) | 17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) |
18 : host_(host), | 18 : host_(host), |
19 installed_clip_(false) { | 19 clipping_window_(NULL) { |
20 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
21 clipping_window_.set_owned_by_parent(false); | |
22 clipping_window_.SetName("NativeViewHostAuraClip"); | |
23 clipping_window_.layer()->SetMasksToBounds(true); | |
20 } | 24 } |
21 | 25 |
22 NativeViewHostAura::~NativeViewHostAura() { | 26 NativeViewHostAura::~NativeViewHostAura() { |
23 if (host_->native_view()) { | 27 if (host_->native_view()) { |
28 host_->native_view()->RemoveObserver(this); | |
24 host_->native_view()->ClearProperty(views::kHostViewKey); | 29 host_->native_view()->ClearProperty(views::kHostViewKey); |
25 host_->native_view()->RemoveObserver(this); | 30 clipping_window_.ClearProperty(views::kHostViewKey); |
31 if (host_->native_view()->parent() == &clipping_window_) | |
32 clipping_window_.RemoveChild(host_->native_view()); | |
26 } | 33 } |
27 } | 34 } |
28 | 35 |
29 //////////////////////////////////////////////////////////////////////////////// | 36 //////////////////////////////////////////////////////////////////////////////// |
30 // NativeViewHostAura, NativeViewHostWrapper implementation: | 37 // NativeViewHostAura, NativeViewHostWrapper implementation: |
31 void NativeViewHostAura::NativeViewWillAttach() { | 38 void NativeViewHostAura::AttachNativeView() { |
32 host_->native_view()->AddObserver(this); | 39 host_->native_view()->AddObserver(this); |
33 host_->native_view()->SetProperty(views::kHostViewKey, | 40 host_->native_view()->SetProperty(views::kHostViewKey, |
34 static_cast<View*>(host_)); | 41 static_cast<View*>(host_)); |
42 AddClippingWindow(); | |
35 } | 43 } |
36 | 44 |
37 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { | 45 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { |
46 RemoveClippingWindow(); | |
38 if (!destroyed) { | 47 if (!destroyed) { |
48 host_->native_view()->RemoveObserver(this); | |
39 host_->native_view()->ClearProperty(views::kHostViewKey); | 49 host_->native_view()->ClearProperty(views::kHostViewKey); |
40 host_->native_view()->RemoveObserver(this); | |
41 host_->native_view()->Hide(); | 50 host_->native_view()->Hide(); |
42 if (host_->native_view()->parent()) | 51 if (host_->native_view()->parent()) |
43 Widget::ReparentNativeView(host_->native_view(), NULL); | 52 host_->native_view()->parent()->RemoveChild(host_->native_view()); |
44 } | 53 } |
45 } | 54 } |
46 | 55 |
47 void NativeViewHostAura::AddedToWidget() { | 56 void NativeViewHostAura::AddedToWidget() { |
48 if (!host_->native_view()) | 57 if (!host_->native_view()) |
49 return; | 58 return; |
50 | 59 |
51 aura::Window* widget_window = host_->GetWidget()->GetNativeView(); | 60 AddClippingWindow(); |
52 if (host_->native_view()->parent() != widget_window) | |
53 widget_window->AddChild(host_->native_view()); | |
54 if (host_->IsDrawn()) | 61 if (host_->IsDrawn()) |
55 host_->native_view()->Show(); | 62 host_->native_view()->Show(); |
56 else | 63 else |
57 host_->native_view()->Hide(); | 64 host_->native_view()->Hide(); |
58 host_->Layout(); | 65 host_->Layout(); |
59 } | 66 } |
60 | 67 |
61 void NativeViewHostAura::RemovedFromWidget() { | 68 void NativeViewHostAura::RemovedFromWidget() { |
62 if (host_->native_view()) { | 69 if (host_->native_view()) { |
63 host_->native_view()->Hide(); | 70 host_->native_view()->Hide(); |
64 if (host_->native_view()->parent()) | 71 if (host_->native_view()->parent()) |
65 host_->native_view()->parent()->RemoveChild(host_->native_view()); | 72 host_->native_view()->parent()->RemoveChild(host_->native_view()); |
73 RemoveClippingWindow(); | |
66 } | 74 } |
67 } | 75 } |
68 | 76 |
69 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { | 77 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { |
70 // Note that this does not pose a problem functionality wise - it might | 78 clip_rect_.reset( |
71 // however pose a speed degradation if not implemented. | 79 new gfx::Rect(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h)))); |
72 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; | |
73 } | 80 } |
74 | 81 |
75 bool NativeViewHostAura::HasInstalledClip() { | 82 bool NativeViewHostAura::HasInstalledClip() { |
76 return installed_clip_; | 83 return clip_rect_; |
77 } | 84 } |
78 | 85 |
79 void NativeViewHostAura::UninstallClip() { | 86 void NativeViewHostAura::UninstallClip() { |
80 installed_clip_ = false; | 87 clip_rect_.reset(); |
81 } | 88 } |
82 | 89 |
83 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { | 90 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { |
84 // TODO: need to support fast resize. | 91 int width = w; |
85 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); | 92 int height = h; |
93 if (host_->fast_resize()) { | |
94 gfx::Point origin(x, y); | |
95 views::View::ConvertPointFromWidget(host_, &origin); | |
96 InstallClip(origin.x(), origin.y(), w, h); | |
97 width = host_->native_view()->bounds().width(); | |
98 height = host_->native_view()->bounds().height(); | |
99 } | |
100 clipping_window_.SetBounds(clip_rect_ ? *clip_rect_ | |
101 : gfx::Rect(x, y, w, h)); | |
102 | |
103 gfx::Point clip_offset = clipping_window_.bounds().origin(); | |
104 host_->native_view()->SetBounds( | |
105 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), width, height)); | |
86 host_->native_view()->Show(); | 106 host_->native_view()->Show(); |
87 } | 107 } |
88 | 108 |
89 void NativeViewHostAura::HideWidget() { | 109 void NativeViewHostAura::HideWidget() { |
90 host_->native_view()->Hide(); | 110 host_->native_view()->Hide(); |
91 } | 111 } |
92 | 112 |
93 void NativeViewHostAura::SetFocus() { | 113 void NativeViewHostAura::SetFocus() { |
94 aura::Window* window = host_->native_view(); | 114 aura::Window* window = host_->native_view(); |
95 aura::client::FocusClient* client = aura::client::GetFocusClient(window); | 115 aura::client::FocusClient* client = aura::client::GetFocusClient(window); |
(...skipping 15 matching lines...) Expand all Loading... | |
111 DCHECK(window == host_->native_view()); | 131 DCHECK(window == host_->native_view()); |
112 host_->NativeViewDestroyed(); | 132 host_->NativeViewDestroyed(); |
113 } | 133 } |
114 | 134 |
115 // static | 135 // static |
116 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 136 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
117 NativeViewHost* host) { | 137 NativeViewHost* host) { |
118 return new NativeViewHostAura(host); | 138 return new NativeViewHostAura(host); |
119 } | 139 } |
120 | 140 |
141 void NativeViewHostAura::AddClippingWindow() { | |
142 RemoveClippingWindow(); | |
143 clipping_window_.SetProperty(views::kHostViewKey, | |
sky
2014/06/16 17:11:03
Can't you set this in the constructor once and not
calamity
2014/06/17 05:01:12
Done.
| |
144 static_cast<View*>(host_)); | |
145 | |
146 gfx::Rect bounds = host_->native_view()->bounds(); | |
147 if (host_->GetWidget()->GetNativeView()) { | |
148 Widget::ReparentNativeView(&clipping_window_, | |
149 host_->GetWidget()->GetNativeView()); | |
150 } | |
151 Widget::ReparentNativeView(host_->native_view(), | |
152 &clipping_window_); | |
153 clipping_window_.SetBounds(bounds); | |
154 bounds.set_origin(gfx::Point(0, 0)); | |
155 host_->native_view()->SetBounds(bounds); | |
156 clipping_window_.Show(); | |
157 } | |
158 | |
159 void NativeViewHostAura::RemoveClippingWindow() { | |
160 if (host_->native_view()->parent() == &clipping_window_) { | |
161 if (host_->GetWidget()->GetNativeView()) { | |
162 Widget::ReparentNativeView(host_->native_view(), | |
163 host_->GetWidget()->GetNativeView()); | |
164 } else { | |
165 clipping_window_.RemoveChild(host_->native_view()); | |
166 } | |
167 host_->native_view()->SetBounds(clipping_window_.bounds()); | |
168 } | |
169 clipping_window_.ClearProperty(views::kHostViewKey); | |
170 clipping_window_.Hide(); | |
171 if (clipping_window_.parent()) | |
172 clipping_window_.parent()->RemoveChild(&clipping_window_); | |
173 } | |
174 | |
121 } // namespace views | 175 } // namespace views |
OLD | NEW |