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

Powered by Google App Engine
This is Rietveld 408576698