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 installed_clip_(false), |
20 clipping_window_(NULL) { | |
21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN); | |
22 clipping_window_.set_owned_by_parent(false); | |
23 clipping_window_.layer()->set_name("NativeViewHostAuraClip"); | |
24 clipping_window_.layer()->SetMasksToBounds(true); | |
20 } | 25 } |
21 | 26 |
22 NativeViewHostAura::~NativeViewHostAura() { | 27 NativeViewHostAura::~NativeViewHostAura() { |
23 if (host_->native_view()) { | 28 if (host_->native_view()) { |
24 host_->native_view()->ClearProperty(views::kHostViewKey); | 29 host_->native_view()->ClearProperty(views::kHostViewKey); |
25 host_->native_view()->RemoveObserver(this); | 30 host_->native_view()->RemoveObserver(this); |
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) { |
38 if (!destroyed) { | 46 if (!destroyed) { |
47 host_->native_view()->RemoveObserver(this); | |
39 host_->native_view()->ClearProperty(views::kHostViewKey); | 48 host_->native_view()->ClearProperty(views::kHostViewKey); |
40 host_->native_view()->RemoveObserver(this); | |
41 host_->native_view()->Hide(); | 49 host_->native_view()->Hide(); |
42 if (host_->native_view()->parent()) | 50 if (host_->native_view()->parent()) |
43 Widget::ReparentNativeView(host_->native_view(), NULL); | 51 Widget::ReparentNativeView(host_->native_view(), NULL); |
44 } | 52 } |
53 RemoveClippingWindow(); | |
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 installed_clip_ = true; |
sky
2014/06/10 16:11:06
Is it possible to nuke installed_clip_ and use cli
calamity
2014/06/11 09:50:26
Done.
| |
71 // however pose a speed degradation if not implemented. | 79 clip_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 installed_clip_; |
77 } | 84 } |
78 | 85 |
79 void NativeViewHostAura::UninstallClip() { | 86 void NativeViewHostAura::UninstallClip() { |
80 installed_clip_ = false; | 87 installed_clip_ = false; |
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 if (host_->fast_resize()) |
85 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); | 92 InstallClip(x, y, w, h); |
sky
2014/06/10 16:11:06
Doesn't InstallClip expect coordinates in the view
calamity
2014/06/11 09:50:26
Hmm. Yeah. I think that this is actually completel
| |
93 | |
94 clipping_window_.SetBounds(installed_clip_ ? clip_rect_ | |
95 : gfx::Rect(x, y, w, h)); | |
96 | |
97 gfx::Point clip_offset = clipping_window_.bounds().origin(); | |
98 host_->native_view()->SetBounds( | |
99 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), w, h)); | |
86 host_->native_view()->Show(); | 100 host_->native_view()->Show(); |
87 } | 101 } |
88 | 102 |
89 void NativeViewHostAura::HideWidget() { | 103 void NativeViewHostAura::HideWidget() { |
90 host_->native_view()->Hide(); | 104 host_->native_view()->Hide(); |
91 } | 105 } |
92 | 106 |
93 void NativeViewHostAura::SetFocus() { | 107 void NativeViewHostAura::SetFocus() { |
94 aura::Window* window = host_->native_view(); | 108 aura::Window* window = host_->native_view(); |
95 aura::client::FocusClient* client = aura::client::GetFocusClient(window); | 109 aura::client::FocusClient* client = aura::client::GetFocusClient(window); |
(...skipping 15 matching lines...) Expand all Loading... | |
111 DCHECK(window == host_->native_view()); | 125 DCHECK(window == host_->native_view()); |
112 host_->NativeViewDestroyed(); | 126 host_->NativeViewDestroyed(); |
113 } | 127 } |
114 | 128 |
115 // static | 129 // static |
116 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( | 130 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( |
117 NativeViewHost* host) { | 131 NativeViewHost* host) { |
118 return new NativeViewHostAura(host); | 132 return new NativeViewHostAura(host); |
119 } | 133 } |
120 | 134 |
135 void NativeViewHostAura::AddClippingWindow() { | |
136 RemoveClippingWindow(); | |
137 clipping_window_.AddChild(host_->native_view()); | |
138 | |
139 gfx::Rect bounds = host_->native_view()->bounds(); | |
140 if (host_->GetWidget()->GetNativeView()) { | |
141 Widget::ReparentNativeView(&clipping_window_, | |
142 host_->GetWidget()->GetNativeView()); | |
143 } | |
144 | |
145 clipping_window_.SetBounds(bounds); | |
146 bounds.set_origin(gfx::Point(0, 0)); | |
147 host_->native_view()->SetBounds(bounds); | |
148 clipping_window_.Show(); | |
149 } | |
150 | |
151 void NativeViewHostAura::RemoveClippingWindow() { | |
152 if (host_->native_view()->parent() == &clipping_window_) { | |
153 if (host_->GetWidget()->GetNativeView()) { | |
154 Widget::ReparentNativeView(host_->native_view(), | |
155 host_->GetWidget()->GetNativeView()); | |
156 } else { | |
157 clipping_window_.RemoveChild(host_->native_view()); | |
158 } | |
159 host_->native_view()->SetBounds(clipping_window_.bounds()); | |
160 } | |
161 clipping_window_.Hide(); | |
162 if (clipping_window_.parent()) | |
163 clipping_window_.parent()->RemoveChild(&clipping_window_); | |
164 } | |
165 | |
121 } // namespace views | 166 } // namespace views |
OLD | NEW |