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

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: Responsed to sky's comments and finished tests 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) {
19 } 21 }
20 22
21 NativeViewHostAura::~NativeViewHostAura() { 23 NativeViewHostAura::~NativeViewHostAura() {
22 if (host_->native_view()) { 24 if (host_->native_view()) {
23 host_->native_view()->ClearProperty(views::kHostViewKey); 25 host_->native_view()->ClearProperty(views::kHostViewKey);
24 host_->native_view()->RemoveObserver(this); 26 host_->native_view()->RemoveObserver(this);
25 } 27 }
26 } 28 }
27 29
28 //////////////////////////////////////////////////////////////////////////////// 30 ////////////////////////////////////////////////////////////////////////////////
29 // NativeViewHostAura, NativeViewHostWrapper implementation: 31 // NativeViewHostAura, NativeViewHostWrapper implementation:
30 void NativeViewHostAura::NativeViewWillAttach() { 32 void NativeViewHostAura::AttachNativeView() {
31 host_->native_view()->AddObserver(this); 33 host_->native_view()->AddObserver(this);
32 host_->native_view()->SetProperty(views::kHostViewKey, 34 host_->native_view()->SetProperty(views::kHostViewKey,
33 static_cast<View*>(host_)); 35 static_cast<View*>(host_));
36
37 Widget::ReparentNativeView(host_->native_view(),
sky 2013/10/01 15:06:43 Can't this be done using the clipping layer as the
rharrison 2013/10/02 19:02:50 I have moved all of the reparenting down into AddC
38 host_->GetWidget()->GetNativeView());
39
40 Widget* widget = Widget::GetWidgetForNativeView(host_->native_view());
sky 2013/10/01 15:06:43 Can these three lines be kept in NativeViewHost?
rharrison 2013/10/02 19:02:50 Done.
41 if (widget)
42 widget->SetNativeWindowProperty(kWidgetNativeViewHostKey, host_);
43 AddClippingWindow();
44 host_->Layout();
sky 2013/10/01 15:06:43 How come Layout is invoked at the end here, but no
rharrison 2013/10/02 19:02:50 I most likely moved it to the end, since the layou
34 } 45 }
35 46
36 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { 47 void NativeViewHostAura::NativeViewDetaching(bool destroyed) {
48 RemoveClippingWindow();
37 if (!destroyed) { 49 if (!destroyed) {
38 host_->native_view()->ClearProperty(views::kHostViewKey); 50 host_->native_view()->ClearProperty(views::kHostViewKey);
39 host_->native_view()->RemoveObserver(this); 51 host_->native_view()->RemoveObserver(this);
40 host_->native_view()->Hide(); 52 host_->native_view()->Hide();
53
41 if (host_->native_view()->parent()) 54 if (host_->native_view()->parent())
42 Widget::ReparentNativeView(host_->native_view(), NULL); 55 Widget::ReparentNativeView(host_->native_view(), NULL);
43 } 56 }
44 } 57 }
45 58
46 void NativeViewHostAura::AddedToWidget() { 59 void NativeViewHostAura::AddedToWidget() {
47 if (!host_->native_view()) 60 if (!host_->native_view())
48 return; 61 return;
49 62
50 aura::Window* widget_window = host_->GetWidget()->GetNativeView(); 63 aura::Window* widget_window = host_->GetWidget()->GetNativeView();
51 if (host_->native_view()->parent() != widget_window) 64 if (host_->native_view()->parent() != widget_window)
52 widget_window->AddChild(host_->native_view()); 65 AddClippingWindow();
66
53 if (host_->IsDrawn()) 67 if (host_->IsDrawn())
54 host_->native_view()->Show(); 68 host_->native_view()->Show();
55 else 69 else
56 host_->native_view()->Hide(); 70 host_->native_view()->Hide();
57 host_->Layout(); 71 host_->Layout();
58 } 72 }
59 73
60 void NativeViewHostAura::RemovedFromWidget() { 74 void NativeViewHostAura::RemovedFromWidget() {
61 if (host_->native_view()) { 75 if (host_->native_view()) {
62 host_->native_view()->Hide(); 76 host_->native_view()->Hide();
77 RemoveClippingWindow();
63 if (host_->native_view()->parent()) 78 if (host_->native_view()->parent())
64 host_->native_view()->parent()->RemoveChild(host_->native_view()); 79 host_->native_view()->parent()->RemoveChild(host_->native_view());
65 } 80 }
66 } 81 }
67 82
68 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { 83 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
69 // Note that this does not pose a problem functionality wise - it might 84 gfx::Rect input_rect(x, y, w, h);
70 // however pose a speed degradation if not implemented. 85
71 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; 86 if (!installed_clip_) {
87 orig_bounds_ = clipping_window_->layer()->bounds();
88 }
89
90 installed_clip_ = true;
91
92 gfx::Rect clipping_bounds(x, y, w, h);
93 clipping_window_->layer()->SetMasksToBounds(true);
94 clipping_window_->layer()->SetBounds(clipping_bounds);
95
96 gfx::Rect native_bounds = host_->native_view()->layer()->bounds();
97
98 gfx::Point native_origin = CalculateNativeViewOrigin(clipping_bounds,
99 native_bounds);
100 native_bounds.set_origin(native_origin);
101 host_->native_view()->layer()->SetBounds(native_bounds);
72 } 102 }
73 103
74 bool NativeViewHostAura::HasInstalledClip() { 104 bool NativeViewHostAura::HasInstalledClip() {
75 return installed_clip_; 105 return installed_clip_;
76 } 106 }
77 107
78 void NativeViewHostAura::UninstallClip() { 108 void NativeViewHostAura::UninstallClip() {
109 if (installed_clip_ == false)
110 return;
111
112 clipping_window_->layer()->SetMasksToBounds(false);
113 clipping_window_->layer()->SetBounds(orig_bounds_);
114 gfx::Rect layer_bounds = orig_bounds_;
115 layer_bounds.set_origin(gfx::Point(0,0));
116 host_->native_view()->layer()->SetBounds(layer_bounds);
117
79 installed_clip_ = false; 118 installed_clip_ = false;
80 } 119 }
81 120
82 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { 121 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) {
83 // TODO: need to support fast resize. 122 if (host_->fast_resize()) {
84 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); 123 UninstallClip();
124 InstallClip(x, y, w, h);
125 } else {
126 clipping_window_->SetBounds(gfx::Rect(x, y, w, h));
127 host_->native_view()->SetBounds(gfx::Rect(0, 0, w, h));
128 }
85 host_->native_view()->Show(); 129 host_->native_view()->Show();
86 } 130 }
87 131
88 void NativeViewHostAura::HideWidget() { 132 void NativeViewHostAura::HideWidget() {
89 host_->native_view()->Hide(); 133 host_->native_view()->Hide();
90 } 134 }
91 135
92 void NativeViewHostAura::SetFocus() { 136 void NativeViewHostAura::SetFocus() {
93 aura::Window* window = host_->native_view(); 137 aura::Window* window = host_->native_view();
94 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 138 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
95 if (client) 139 if (client)
96 client->FocusWindow(window); 140 client->FocusWindow(window);
97 } 141 }
98 142
99 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() { 143 gfx::NativeViewAccessible NativeViewHostAura::GetNativeViewAccessible() {
100 return NULL; 144 return NULL;
101 } 145 }
102 146
103 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) { 147 void NativeViewHostAura::OnWindowDestroyed(aura::Window* window) {
104 DCHECK(window == host_->native_view()); 148 if (window == host_->native_view())
105 host_->NativeViewDestroyed(); 149 host_->NativeViewDestroyed();
150 if (window == clipping_window_)
sky 2013/10/01 15:06:43 How will this ever happen since you don't add this
rharrison 2013/10/02 19:02:50 I have written the clipping_window_ ownership code
151 clipping_window_ = NULL;
106 } 152 }
107 153
108 // static 154 // static
109 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 155 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
110 NativeViewHost* host) { 156 NativeViewHost* host) {
111 return new NativeViewHostAura(host); 157 return new NativeViewHostAura(host);
112 } 158 }
113 159
160 gfx::Point NativeViewHostAura::CalculateNativeViewOrigin(
161 const gfx::Rect& input_rect,
162 const gfx::Rect& native_rect) const {
163 int new_x = gfx::ToRoundedInt(host_->GetWidthScaleFactor() *
164 (input_rect.width() -
165 native_rect.width()));
166 int new_y = gfx::ToRoundedInt(host_->GetHeightScaleFactor() *
167 (input_rect.height() -
168 native_rect.height()));
169 return gfx::Point(new_x, new_y);
170 }
171
172 void NativeViewHostAura::AddClippingWindow() {
173 if (!clipping_window_) {
174 clipping_window_ = new aura::Window(NULL);
175 clipping_window_->SetTransparent(true);
176 clipping_window_->Init(ui::LAYER_NOT_DRAWN);
177 clipping_window_->layer()->set_name("NativeViewHostAuraClip");
178 clipping_window_->layer()->SetMasksToBounds(false);
179 }
180
181 aura::Window* widget_window = host_->GetWidget()->GetNativeView();
182 widget_window->AddChild(clipping_window_);
183 clipping_window_->AddChild(host_->native_view());
184
185 gfx::Rect bounds = host_->native_view()->bounds();
186 bounds.set_origin(gfx::Point(0,0));
187 host_->native_view()->SetBounds(bounds);
188
189 clipping_window_->Show();
190 host_->Layout();
191 }
192
193 void NativeViewHostAura::RemoveClippingWindow() {
194 if (host_->native_view()->parent() == clipping_window_ &&
195 clipping_window_ != NULL) {
196 clipping_window_->parent()->AddChild(host_->native_view());
197 clipping_window_->parent()->RemoveChild(clipping_window_);
198 host_->native_view()->SetBounds(clipping_window_->bounds());
199 clipping_window_->Hide();
200 delete clipping_window_;
201 clipping_window_ = NULL;
202 }
203 }
204
114 } // namespace views 205 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698