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

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

Issue 317823002: Implement NativeViewHostAura::InstallClip. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: remove stray whitespace Created 6 years, 6 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/client/aura_constants.h"
8 #include "ui/aura/client/focus_client.h" 9 #include "ui/aura/client/focus_client.h"
9 #include "ui/aura/window.h" 10 #include "ui/aura/window.h"
10 #include "ui/base/cursor/cursor.h" 11 #include "ui/base/cursor/cursor.h"
11 #include "ui/views/controls/native/native_view_host.h" 12 #include "ui/views/controls/native/native_view_host.h"
12 #include "ui/views/view_constants_aura.h" 13 #include "ui/views/view_constants_aura.h"
13 #include "ui/views/widget/widget.h" 14 #include "ui/views/widget/widget.h"
14 15
15 namespace views { 16 namespace views {
16 17
17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) 18 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
18 : host_(host), 19 : host_(host),
19 installed_clip_(false) { 20 clipping_window_(NULL) {
21 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN);
22 clipping_window_.set_owned_by_parent(false);
23 clipping_window_.SetName("NativeViewHostAuraClip");
24 clipping_window_.layer()->SetMasksToBounds(true);
25 clipping_window_.SetProperty(views::kHostViewKey, static_cast<View*>(host_));
20 } 26 }
21 27
22 NativeViewHostAura::~NativeViewHostAura() { 28 NativeViewHostAura::~NativeViewHostAura() {
23 if (host_->native_view()) { 29 if (host_->native_view()) {
30 host_->native_view()->RemoveObserver(this);
24 host_->native_view()->ClearProperty(views::kHostViewKey); 31 host_->native_view()->ClearProperty(views::kHostViewKey);
25 host_->native_view()->RemoveObserver(this); 32 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
33 clipping_window_.ClearProperty(views::kHostViewKey);
34 if (host_->native_view()->parent() == &clipping_window_)
35 clipping_window_.RemoveChild(host_->native_view());
26 } 36 }
27 } 37 }
28 38
29 //////////////////////////////////////////////////////////////////////////////// 39 ////////////////////////////////////////////////////////////////////////////////
30 // NativeViewHostAura, NativeViewHostWrapper implementation: 40 // NativeViewHostAura, NativeViewHostWrapper implementation:
31 void NativeViewHostAura::NativeViewWillAttach() { 41 void NativeViewHostAura::AttachNativeView() {
32 host_->native_view()->AddObserver(this); 42 host_->native_view()->AddObserver(this);
33 host_->native_view()->SetProperty(views::kHostViewKey, 43 host_->native_view()->SetProperty(views::kHostViewKey,
34 static_cast<View*>(host_)); 44 static_cast<View*>(host_));
45 AddClippingWindow();
35 } 46 }
36 47
37 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { 48 void NativeViewHostAura::NativeViewDetaching(bool destroyed) {
49 RemoveClippingWindow();
38 if (!destroyed) { 50 if (!destroyed) {
51 host_->native_view()->RemoveObserver(this);
39 host_->native_view()->ClearProperty(views::kHostViewKey); 52 host_->native_view()->ClearProperty(views::kHostViewKey);
40 host_->native_view()->RemoveObserver(this); 53 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
41 host_->native_view()->Hide(); 54 host_->native_view()->Hide();
42 if (host_->native_view()->parent()) 55 if (host_->native_view()->parent())
43 Widget::ReparentNativeView(host_->native_view(), NULL); 56 host_->native_view()->parent()->RemoveChild(host_->native_view());
44 } 57 }
45 } 58 }
46 59
47 void NativeViewHostAura::AddedToWidget() { 60 void NativeViewHostAura::AddedToWidget() {
48 if (!host_->native_view()) 61 if (!host_->native_view())
49 return; 62 return;
50 63
51 aura::Window* widget_window = host_->GetWidget()->GetNativeView(); 64 AddClippingWindow();
52 if (host_->native_view()->parent() != widget_window)
53 widget_window->AddChild(host_->native_view());
54 if (host_->IsDrawn()) 65 if (host_->IsDrawn())
55 host_->native_view()->Show(); 66 host_->native_view()->Show();
56 else 67 else
57 host_->native_view()->Hide(); 68 host_->native_view()->Hide();
58 host_->Layout(); 69 host_->Layout();
59 } 70 }
60 71
61 void NativeViewHostAura::RemovedFromWidget() { 72 void NativeViewHostAura::RemovedFromWidget() {
62 if (host_->native_view()) { 73 if (host_->native_view()) {
63 host_->native_view()->Hide(); 74 host_->native_view()->Hide();
75 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
64 if (host_->native_view()->parent()) 76 if (host_->native_view()->parent())
65 host_->native_view()->parent()->RemoveChild(host_->native_view()); 77 host_->native_view()->parent()->RemoveChild(host_->native_view());
78 RemoveClippingWindow();
66 } 79 }
67 } 80 }
68 81
69 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { 82 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
70 // Note that this does not pose a problem functionality wise - it might 83 clip_rect_.reset(
71 // however pose a speed degradation if not implemented. 84 new gfx::Rect(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h))));
72 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet.";
73 } 85 }
74 86
75 bool NativeViewHostAura::HasInstalledClip() { 87 bool NativeViewHostAura::HasInstalledClip() {
76 return installed_clip_; 88 return clip_rect_;
77 } 89 }
78 90
79 void NativeViewHostAura::UninstallClip() { 91 void NativeViewHostAura::UninstallClip() {
80 installed_clip_ = false; 92 clip_rect_.reset();
81 } 93 }
82 94
83 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { 95 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) {
84 // TODO: need to support fast resize. 96 int width = w;
85 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); 97 int height = h;
98 if (host_->fast_resize()) {
99 gfx::Point origin(x, y);
100 views::View::ConvertPointFromWidget(host_, &origin);
101 InstallClip(origin.x(), origin.y(), w, h);
102 width = host_->native_view()->bounds().width();
103 height = host_->native_view()->bounds().height();
104 }
105 clipping_window_.SetBounds(clip_rect_ ? *clip_rect_
106 : gfx::Rect(x, y, w, h));
107
108 gfx::Point clip_offset = clipping_window_.bounds().origin();
109 host_->native_view()->SetBounds(
110 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), width, height));
86 host_->native_view()->Show(); 111 host_->native_view()->Show();
87 } 112 }
88 113
89 void NativeViewHostAura::HideWidget() { 114 void NativeViewHostAura::HideWidget() {
90 host_->native_view()->Hide(); 115 host_->native_view()->Hide();
91 } 116 }
92 117
93 void NativeViewHostAura::SetFocus() { 118 void NativeViewHostAura::SetFocus() {
94 aura::Window* window = host_->native_view(); 119 aura::Window* window = host_->native_view();
95 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 120 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
(...skipping 15 matching lines...) Expand all
111 DCHECK(window == host_->native_view()); 136 DCHECK(window == host_->native_view());
112 host_->NativeViewDestroyed(); 137 host_->NativeViewDestroyed();
113 } 138 }
114 139
115 // static 140 // static
116 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 141 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
117 NativeViewHost* host) { 142 NativeViewHost* host) {
118 return new NativeViewHostAura(host); 143 return new NativeViewHostAura(host);
119 } 144 }
120 145
146 void NativeViewHostAura::AddClippingWindow() {
147 RemoveClippingWindow();
148
149 gfx::Rect bounds = host_->native_view()->bounds();
150 if (host_->GetWidget()->GetNativeView()) {
151 Widget::ReparentNativeView(&clipping_window_,
152 host_->GetWidget()->GetNativeView());
153 }
154 host_->native_view()->SetProperty(aura::client::kHostWindowKey,
155 host_->GetWidget()->GetNativeView());
156 Widget::ReparentNativeView(host_->native_view(),
157 &clipping_window_);
158 clipping_window_.SetBounds(bounds);
159 bounds.set_origin(gfx::Point(0, 0));
160 host_->native_view()->SetBounds(bounds);
161 clipping_window_.Show();
162 }
163
164 void NativeViewHostAura::RemoveClippingWindow() {
165 if (host_->native_view())
166 host_->native_view()->ClearProperty(aura::client::kHostWindowKey);
167
168 if (host_->native_view()->parent() == &clipping_window_) {
169 if (host_->GetWidget()->GetNativeView()) {
170 Widget::ReparentNativeView(host_->native_view(),
171 host_->GetWidget()->GetNativeView());
172 } else {
173 clipping_window_.RemoveChild(host_->native_view());
174 }
175 host_->native_view()->SetBounds(clipping_window_.bounds());
176 }
177 clipping_window_.Hide();
178 if (clipping_window_.parent())
179 clipping_window_.parent()->RemoveChild(&clipping_window_);
180 }
181
121 } // namespace views 182 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698