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

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

Powered by Google App Engine
This is Rietveld 408576698