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

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

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

Powered by Google App Engine
This is Rietveld 408576698