Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(590)

Side by Side Diff: ui/views/controls/native/native_view_host_aura.cc

Issue 339663003: Revert of Implement NativeViewHostAura::InstallClip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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"
9 #include "ui/aura/client/focus_client.h" 8 #include "ui/aura/client/focus_client.h"
10 #include "ui/aura/window.h" 9 #include "ui/aura/window.h"
11 #include "ui/base/cursor/cursor.h" 10 #include "ui/base/cursor/cursor.h"
12 #include "ui/views/controls/native/native_view_host.h" 11 #include "ui/views/controls/native/native_view_host.h"
13 #include "ui/views/view_constants_aura.h" 12 #include "ui/views/view_constants_aura.h"
14 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
15 14
16 namespace views { 15 namespace views {
17 16
18 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) 17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
19 : host_(host), 18 : host_(host),
20 clipping_window_(NULL) { 19 installed_clip_(false) {
21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN);
22 clipping_window_.set_owned_by_parent(false);
23 clipping_window_.SetName("NativeViewHostAuraClip");
24 clipping_window_.layer()->SetMasksToBounds(true);
25 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_));
26 } 20 }
27 21
28 NativeViewHostAura::~NativeViewHostAura() { 22 NativeViewHostAura::~NativeViewHostAura() {
29 if (host_->native_view()) { 23 if (host_->native_view()) {
24 host_->native_view()->ClearProperty(views::kHostViewKey);
30 host_->native_view()->RemoveObserver(this); 25 host_->native_view()->RemoveObserver(this);
31 host_->native_view()->ClearProperty(views::kHostViewKey);
32 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
33 clipping_window_.ClearProperty(views::kHostViewKey);
34 if (host_->native_view()->parent() == &clipping_window_)
35 clipping_window_.RemoveChild(host_->native_view());
36 } 26 }
37 } 27 }
38 28
39 //////////////////////////////////////////////////////////////////////////////// 29 ////////////////////////////////////////////////////////////////////////////////
40 // NativeViewHostAura, NativeViewHostWrapper implementation: 30 // NativeViewHostAura, NativeViewHostWrapper implementation:
41 void NativeViewHostAura::AttachNativeView() { 31 void NativeViewHostAura::NativeViewWillAttach() {
42 host_->native_view()->AddObserver(this); 32 host_->native_view()->AddObserver(this);
43 host_->native_view()->SetProperty(views::kHostViewKey, 33 host_->native_view()->SetProperty(views::kHostViewKey,
44 static_cast<View*>(host_)); 34 static_cast<View*>(host_));
45 AddClippingWindow();
46 } 35 }
47 36
48 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { 37 void NativeViewHostAura::NativeViewDetaching(bool destroyed) {
49 RemoveClippingWindow();
50 if (!destroyed) { 38 if (!destroyed) {
39 host_->native_view()->ClearProperty(views::kHostViewKey);
51 host_->native_view()->RemoveObserver(this); 40 host_->native_view()->RemoveObserver(this);
52 host_->native_view()->ClearProperty(views::kHostViewKey);
53 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
54 host_->native_view()->Hide(); 41 host_->native_view()->Hide();
55 if (host_->native_view()->parent()) 42 if (host_->native_view()->parent())
56 host_->native_view()->parent()->RemoveChild(host_->native_view()); 43 Widget::ReparentNativeView(host_->native_view(), NULL);
57 } 44 }
58 } 45 }
59 46
60 void NativeViewHostAura::AddedToWidget() { 47 void NativeViewHostAura::AddedToWidget() {
61 if (!host_->native_view()) 48 if (!host_->native_view())
62 return; 49 return;
63 50
64 AddClippingWindow(); 51 aura::Window* widget_window = host_->GetWidget()->GetNativeView();
52 if (host_->native_view()->parent() != widget_window)
53 widget_window->AddChild(host_->native_view());
65 if (host_->IsDrawn()) 54 if (host_->IsDrawn())
66 host_->native_view()->Show(); 55 host_->native_view()->Show();
67 else 56 else
68 host_->native_view()->Hide(); 57 host_->native_view()->Hide();
69 host_->Layout(); 58 host_->Layout();
70 } 59 }
71 60
72 void NativeViewHostAura::RemovedFromWidget() { 61 void NativeViewHostAura::RemovedFromWidget() {
73 if (host_->native_view()) { 62 if (host_->native_view()) {
74 host_->native_view()->Hide(); 63 host_->native_view()->Hide();
75 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
76 if (host_->native_view()->parent()) 64 if (host_->native_view()->parent())
77 host_->native_view()->parent()->RemoveChild(host_->native_view()); 65 host_->native_view()->parent()->RemoveChild(host_->native_view());
78 RemoveClippingWindow();
79 } 66 }
80 } 67 }
81 68
82 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { 69 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
83 clip_rect_.reset( 70 // Note that this does not pose a problem functionality wise - it might
84 new gfx::Rect(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h)))); 71 // however pose a speed degradation if not implemented.
72 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet.";
85 } 73 }
86 74
87 bool NativeViewHostAura::HasInstalledClip() { 75 bool NativeViewHostAura::HasInstalledClip() {
88 return clip_rect_; 76 return installed_clip_;
89 } 77 }
90 78
91 void NativeViewHostAura::UninstallClip() { 79 void NativeViewHostAura::UninstallClip() {
92 clip_rect_.reset(); 80 installed_clip_ = false;
93 } 81 }
94 82
95 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { 83 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) {
96 int width = w; 84 // TODO: need to support fast resize.
97 int height = h; 85 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h));
98 if (host_->fast_resize()) {
99 gfx::Point origin(x, y);
100 views::View::ConvertPointFromWidget(host_, &origin);
101 InstallClip(origin.x(), origin.y(), w, h);
102 width = host_->native_view()->bounds().width();
103 height = host_->native_view()->bounds().height();
104 }
105 clipping_window_.SetBounds(clip_rect_ ? *clip_rect_
106 : gfx::Rect(x, y, w, h));
107
108 gfx::Point clip_offset = clipping_window_.bounds().origin();
109 host_->native_view()->SetBounds(
110 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), width, height));
111 host_->native_view()->Show(); 86 host_->native_view()->Show();
112 } 87 }
113 88
114 void NativeViewHostAura::HideWidget() { 89 void NativeViewHostAura::HideWidget() {
115 host_->native_view()->Hide(); 90 host_->native_view()->Hide();
116 } 91 }
117 92
118 void NativeViewHostAura::SetFocus() { 93 void NativeViewHostAura::SetFocus() {
119 aura::Window* window = host_->native_view(); 94 aura::Window* window = host_->native_view();
120 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 95 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
(...skipping 15 matching lines...) Expand all
136 DCHECK(window == host_->native_view()); 111 DCHECK(window == host_->native_view());
137 host_->NativeViewDestroyed(); 112 host_->NativeViewDestroyed();
138 } 113 }
139 114
140 // static 115 // static
141 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 116 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
142 NativeViewHost* host) { 117 NativeViewHost* host) {
143 return new NativeViewHostAura(host); 118 return new NativeViewHostAura(host);
144 } 119 }
145 120
146 void NativeViewHostAura::AddClippingWindow() {
147 RemoveClippingWindow();
148
149 gfx::Rect bounds = host_->native_view()->bounds();
150 if (host_->GetWidget()->GetNativeView()) {
151 Widget::ReparentNativeView(&clipping_window_,
152 host_->GetWidget()->GetNativeView());
153 }
154 host_->native_view()->SetProperty(aura::client::kHostWindowKey,
155 host_->GetWidget()->GetNativeView());
156 Widget::ReparentNativeView(host_->native_view(),
157 &clipping_window_);
158 clipping_window_.SetBounds(bounds);
159 bounds.set_origin(gfx::Point(0, 0));
160 host_->native_view()->SetBounds(bounds);
161 clipping_window_.Show();
162 }
163
164 void NativeViewHostAura::RemoveClippingWindow() {
165 if (host_->native_view())
166 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
167
168 if (host_->native_view()->parent() == &clipping_window_) {
169 if (host_->GetWidget()->GetNativeView()) {
170 Widget::ReparentNativeView(host_->native_view(),
171 host_->GetWidget()->GetNativeView());
172 } else {
173 clipping_window_.RemoveChild(host_->native_view());
174 }
175 host_->native_view()->SetBounds(clipping_window_.bounds());
176 }
177 clipping_window_.Hide();
178 if (clipping_window_.parent())
179 clipping_window_.parent()->RemoveChild(&clipping_window_);
180 }
181
182 } // namespace views 121 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/native/native_view_host_aura.h ('k') | ui/views/controls/native/native_view_host_aura_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698