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

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

Issue 48113013: Re-Reland: Implement features in NativeViewHostAura for scroll end effect Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Moved ownership of clipping_window_ solely into NHVA Created 7 years, 1 month 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/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/gfx/safe_integer_conversions.h"
10 #include "ui/views/controls/native/native_view_host.h" 11 #include "ui/views/controls/native/native_view_host.h"
11 #include "ui/views/view_constants_aura.h" 12 #include "ui/views/view_constants_aura.h"
12 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
13 14
14 namespace views { 15 namespace views {
15 16
16 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) 17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
17 : host_(host), 18 : host_(host),
18 installed_clip_(false) { 19 installed_clip_(false),
20 clipping_window_(NULL) {
19 } 21 }
20 22
21 NativeViewHostAura::~NativeViewHostAura() { 23 NativeViewHostAura::~NativeViewHostAura() {
24 if (clipping_window_)
sky 2013/11/21 23:15:14 Don't you need to destroy clipping_window_ now?
rharrison 2013/11/25 20:46:18 Done.
25 host_->native_view()->ClearProperty(views::kHostViewKey);
26
22 if (host_->native_view()) { 27 if (host_->native_view()) {
28 host_->native_view()->RemoveObserver(this);
23 host_->native_view()->ClearProperty(views::kHostViewKey); 29 host_->native_view()->ClearProperty(views::kHostViewKey);
24 host_->native_view()->RemoveObserver(this);
25 } 30 }
26 } 31 }
27 32
28 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
29 // NativeViewHostAura, NativeViewHostWrapper implementation: 34 // NativeViewHostAura, NativeViewHostWrapper implementation:
30 void NativeViewHostAura::NativeViewWillAttach() { 35 void NativeViewHostAura::AttachNativeView() {
31 host_->native_view()->AddObserver(this); 36 host_->native_view()->AddObserver(this);
32 host_->native_view()->SetProperty(views::kHostViewKey, 37 host_->native_view()->SetProperty(views::kHostViewKey,
33 static_cast<View*>(host_)); 38 static_cast<View*>(host_));
39 AddClippingWindow();
34 } 40 }
35 41
36 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { 42 void NativeViewHostAura::NativeViewDetaching(bool destroyed) {
37 if (!destroyed) { 43 if (!destroyed) {
38 host_->native_view()->ClearProperty(views::kHostViewKey); 44 host_->native_view()->ClearProperty(views::kHostViewKey);
39 host_->native_view()->RemoveObserver(this); 45 host_->native_view()->RemoveObserver(this);
40 host_->native_view()->Hide(); 46 host_->native_view()->Hide();
41 if (host_->native_view()->parent()) 47 RemoveClippingWindow();
42 Widget::ReparentNativeView(host_->native_view(), NULL); 48 } else {
49 if (clipping_window_) {
50 delete clipping_window_;
51 clipping_window_ = NULL;
52 }
43 } 53 }
44 } 54 }
45 55
46 void NativeViewHostAura::AddedToWidget() { 56 void NativeViewHostAura::AddedToWidget() {
47 if (!host_->native_view()) 57 if (!host_->native_view())
48 return; 58 return;
49 59 AddClippingWindow();
50 aura::Window* widget_window = host_->GetWidget()->GetNativeView();
51 if (host_->native_view()->parent() != widget_window)
52 widget_window->AddChild(host_->native_view());
53 if (host_->IsDrawn()) 60 if (host_->IsDrawn())
54 host_->native_view()->Show(); 61 host_->native_view()->Show();
55 else 62 else
56 host_->native_view()->Hide(); 63 host_->native_view()->Hide();
57 host_->Layout(); 64 host_->Layout();
58 } 65 }
59 66
60 void NativeViewHostAura::RemovedFromWidget() { 67 void NativeViewHostAura::RemovedFromWidget() {
61 if (host_->native_view()) { 68 if (host_->native_view()) {
62 host_->native_view()->Hide(); 69 host_->native_view()->Hide();
63 if (host_->native_view()->parent())
64 host_->native_view()->parent()->RemoveChild(host_->native_view());
65 } 70 }
71 RemoveClippingWindow();
66 } 72 }
67 73
68 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { 74 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
69 // Note that this does not pose a problem functionality wise - it might 75 installed_clip_ = true;
70 // however pose a speed degradation if not implemented. 76 clip_rect_ = gfx::Rect(x + orig_bounds_.x(),
71 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; 77 y + orig_bounds_.y(),
78 w,
79 h);
80 UpdateClippingWindow();
81 clipping_window_->layer()->SetMasksToBounds(true);
72 } 82 }
73 83
74 bool NativeViewHostAura::HasInstalledClip() { 84 bool NativeViewHostAura::HasInstalledClip() {
75 return installed_clip_; 85 return installed_clip_;
76 } 86 }
77 87
78 void NativeViewHostAura::UninstallClip() { 88 void NativeViewHostAura::UninstallClip() {
89 if (installed_clip_ == false)
90 return;
79 installed_clip_ = false; 91 installed_clip_ = false;
92 clipping_window_->layer()->SetMasksToBounds(false);
80 } 93 }
81 94
82 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { 95 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) {
83 // TODO: need to support fast resize. 96 if (host_->fast_resize()) {
84 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); 97 gfx::Rect native_view_bounds = host_->native_view()->bounds();
98 gfx::Point native_view_origin =
99 CalculateNativeViewOrigin(clipping_window_->bounds(),
100 native_view_bounds);
101 orig_bounds_ = gfx::Rect(x + native_view_origin.x(),
102 y + native_view_origin.y(),
103 native_view_bounds.width(),
104 native_view_bounds.height());
105
106 InstallClip(x - orig_bounds_.x(),
107 y - orig_bounds_.y(),
108 w,
109 h);
110 } else {
111 clip_rect_.Offset(x - orig_bounds_.x(), y - orig_bounds_.y());
112 orig_bounds_ = gfx::Rect(x, y, w, h);
113 UpdateClippingWindow();
114 }
85 host_->native_view()->Show(); 115 host_->native_view()->Show();
86 } 116 }
87 117
88 void NativeViewHostAura::HideWidget() { 118 void NativeViewHostAura::HideWidget() {
89 host_->native_view()->Hide(); 119 host_->native_view()->Hide();
90 } 120 }
91 121
92 void NativeViewHostAura::SetFocus() { 122 void NativeViewHostAura::SetFocus() {
93 aura::Window* window = host_->native_view(); 123 aura::Window* window = host_->native_view();
94 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 124 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
95 if (client) 125 if (client)
96 client->FocusWindow(window); 126 client->FocusWindow(window);
97 } 127 }
98 128
99 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { 129 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() {
100 return NULL; 130 return NULL;
101 } 131 }
102 132
103 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { 133 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) {
104 DCHECK(window == host_->native_view()); 134 DCHECK(window == host_->native_view());
105 host_->NativeViewDestroyed(); 135 host_->NativeViewDestroyed();
106 } 136 }
107 137
108 // static 138 // static
109 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 139 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
110 NativeViewHost* host) { 140 NativeViewHost* host) {
111 return new NativeViewHostAura(host); 141 return new NativeViewHostAura(host);
112 } 142 }
113 143
144 gfx::Point NativeViewHostAura::CalculateNativeViewOrigin(
145 const gfx::Rect& input_rect,
146 const gfx::Rect& native_rect) const {
147 int new_x = gfx::ToRoundedInt(host_->GetWidthScaleFactor() *
148 (input_rect.width() -
149 native_rect.width()));
150 int new_y = gfx::ToRoundedInt(host_->GetHeightScaleFactor() *
151 (input_rect.height() -
152 native_rect.height()));
153 return gfx::Point(new_x, new_y);
154 }
155
156 void NativeViewHostAura::AddClippingWindow() {
157 RemoveClippingWindow();
158 clipping_window_ = new aura::Window(NULL);
159 clipping_window_->set_owned_by_parent(false);
160 clipping_window_->SetTransparent(true);
161 clipping_window_->Init(ui::LAYER_NOT_DRAWN);
162 clipping_window_->SetName("NativeViewHostAuraClip");
163 clipping_window_->layer()->SetMasksToBounds(false);
164
165 gfx::Rect bounds = host_->native_view()->bounds();
166 orig_bounds_ = bounds;
167 clipping_window_->SetBounds(bounds);
168 bounds.set_origin(gfx::Point(0, 0));
169 host_->native_view()->SetBounds(bounds);
170
171 clipping_window_->AddChild(host_->native_view());
172 clipping_window_->SetProperty(views::kHostViewKey,
rharrison 2013/11/21 18:38:01 Setting the kHostViewKey is needed to make sure th
sky 2013/11/21 23:15:14 Ah, right. In that case I don't think you need to
rharrison 2013/11/25 20:46:18 Done.
173 static_cast<View*>(host_));
174 Widget::ReparentNativeView(clipping_window_,
175 host_->GetWidget()->GetNativeView());
176 clipping_window_->Show();
177 host_->native_view()->SetName("ClippedContent");
178 }
179
180 void NativeViewHostAura::RemoveClippingWindow() {
181 if (clipping_window_) {
182 if (host_->native_view() &&
183 host_->native_view()->parent() == clipping_window_) {
184 host_->native_view()->SetBounds(clipping_window_->bounds());
185 if (clipping_window_ && clipping_window_->parent()) {
186 Widget::ReparentNativeView(host_->native_view(), NULL);
187 } else {
188 clipping_window_->RemoveChild(host_->native_view());
189 }
190 }
191 delete clipping_window_;
192 clipping_window_ = NULL;
193 }
194 }
195
196 void NativeViewHostAura::UpdateClippingWindow() {
197 if (!installed_clip_)
198 clip_rect_ = orig_bounds_;
199
200 clipping_window_->SetBounds(clip_rect_);
201
202 gfx::Rect native_view_bounds = orig_bounds_;
203 native_view_bounds.Offset(-clip_rect_.x(), -clip_rect_.y());
204 host_->native_view()->SetBounds(native_view_bounds);
205 }
206
114 } // namespace views 207 } // 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