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

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: 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/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/base/cursor/cursor.h" 10 #include "ui/base/cursor/cursor.h"
11 #include "ui/views/controls/native/native_view_host.h" 11 #include "ui/views/controls/native/native_view_host.h"
12 #include "ui/views/view_constants_aura.h" 12 #include "ui/views/view_constants_aura.h"
13 #include "ui/views/widget/widget.h" 13 #include "ui/views/widget/widget.h"
14 14
15 namespace views { 15 namespace views {
16 16
17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host) 17 NativeViewHostAura::NativeViewHostAura(NativeViewHost* host)
18 : host_(host), 18 : host_(host), installed_clip_(false), clipping_window_(NULL) {
sky 2014/06/05 15:49:01 nit: one param per line.
calamity 2014/06/06 08:13:44 Done.
19 installed_clip_(false) { 19 clipping_window_.Init(aura::WINDOW_LAYER_NOT_DRAWN);
20 clipping_window_.set_owned_by_parent(false);
21 clipping_window_.layer()->set_name("NativeViewHostAuraClip");
22 clipping_window_.layer()->SetMasksToBounds(false);
20 } 23 }
21 24
22 NativeViewHostAura::~NativeViewHostAura() { 25 NativeViewHostAura::~NativeViewHostAura() {
23 if (host_->native_view()) { 26 if (host_->native_view()) {
24 host_->native_view()->ClearProperty(views::kHostViewKey); 27 host_->native_view()->ClearProperty(views::kHostViewKey);
25 host_->native_view()->RemoveObserver(this); 28 host_->native_view()->RemoveObserver(this);
29 RemoveClippingWindow();
sky 2014/06/05 15:49:01 Are you sure this is necessary here? In particular
calamity 2014/06/06 08:13:44 Removing this crashes NativeViewHostAuraTest.HostV
sky 2014/06/06 15:53:57 What does the trace look like?
calamity 2014/06/10 08:48:46 Evidently we need to remove the native view from t
26 } 30 }
27 } 31 }
28 32
29 //////////////////////////////////////////////////////////////////////////////// 33 ////////////////////////////////////////////////////////////////////////////////
30 // NativeViewHostAura, NativeViewHostWrapper implementation: 34 // NativeViewHostAura, NativeViewHostWrapper implementation:
31 void NativeViewHostAura::NativeViewWillAttach() { 35 void NativeViewHostAura::AttachNativeView() {
32 host_->native_view()->AddObserver(this); 36 host_->native_view()->AddObserver(this);
33 host_->native_view()->SetProperty(views::kHostViewKey, 37 host_->native_view()->SetProperty(views::kHostViewKey,
34 static_cast<View*>(host_)); 38 static_cast<View*>(host_));
39 AddClippingWindow();
35 } 40 }
36 41
37 void NativeViewHostAura::NativeViewDetaching(bool destroyed) { 42 void NativeViewHostAura::NativeViewDetaching(bool destroyed) {
38 if (!destroyed) { 43 if (!destroyed) {
44 RemoveClippingWindow();
39 host_->native_view()->ClearProperty(views::kHostViewKey); 45 host_->native_view()->ClearProperty(views::kHostViewKey);
40 host_->native_view()->RemoveObserver(this); 46 host_->native_view()->RemoveObserver(this);
41 host_->native_view()->Hide(); 47 host_->native_view()->Hide();
42 if (host_->native_view()->parent()) 48 if (host_->native_view()->parent())
43 Widget::ReparentNativeView(host_->native_view(), NULL); 49 Widget::ReparentNativeView(host_->native_view(), NULL);
50 } else {
51 clipping_window_.Hide();
sky 2014/06/05 15:49:01 Why is this in an else? Shouldn't you always do it
calamity 2014/06/06 08:13:44 RemoveClippingView actually takes care of this. Fi
52 if (clipping_window_.parent())
53 clipping_window_.parent()->RemoveChild(&clipping_window_);
44 } 54 }
45 } 55 }
46 56
47 void NativeViewHostAura::AddedToWidget() { 57 void NativeViewHostAura::AddedToWidget() {
48 if (!host_->native_view()) 58 if (!host_->native_view())
49 return; 59 return;
50 60
51 aura::Window* widget_window = host_->GetWidget()->GetNativeView(); 61 AddClippingWindow();
52 if (host_->native_view()->parent() != widget_window)
53 widget_window->AddChild(host_->native_view());
54 if (host_->IsDrawn()) 62 if (host_->IsDrawn())
55 host_->native_view()->Show(); 63 host_->native_view()->Show();
56 else 64 else
57 host_->native_view()->Hide(); 65 host_->native_view()->Hide();
58 host_->Layout(); 66 host_->Layout();
59 } 67 }
60 68
61 void NativeViewHostAura::RemovedFromWidget() { 69 void NativeViewHostAura::RemovedFromWidget() {
62 if (host_->native_view()) { 70 if (host_->native_view()) {
63 host_->native_view()->Hide(); 71 host_->native_view()->Hide();
72 RemoveClippingWindow();
sky 2014/06/05 15:49:01 Seems weird to reparent the native_view to the wid
calamity 2014/06/06 08:13:44 Switched the order. RemoveClippingWindow() won't r
64 if (host_->native_view()->parent()) 73 if (host_->native_view()->parent())
65 host_->native_view()->parent()->RemoveChild(host_->native_view()); 74 host_->native_view()->parent()->RemoveChild(host_->native_view());
66 } 75 }
67 } 76 }
68 77
69 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) { 78 void NativeViewHostAura::InstallClip(int x, int y, int w, int h) {
70 // Note that this does not pose a problem functionality wise - it might 79 installed_clip_ = true;
71 // however pose a speed degradation if not implemented. 80 clipping_window_.SetBounds(host_->ConvertRectToWidget(gfx::Rect(x, y, w, h)));
72 LOG(WARNING) << "NativeViewHostAura::InstallClip is not implemented yet."; 81 clipping_window_.layer()->SetMasksToBounds(true);
sky 2014/06/05 15:49:01 Can't you always set mask to bounds true?
calamity 2014/06/06 08:13:44 It's set to false so that the native view can draw
sky 2014/06/06 15:53:57 Isn't the only time the size of the clipping_windo
calamity 2014/06/10 08:48:46 Oops, this comment was outdated. Yeah. Since I set
73 } 82 }
74 83
75 bool NativeViewHostAura::HasInstalledClip() { 84 bool NativeViewHostAura::HasInstalledClip() {
76 return installed_clip_; 85 return installed_clip_;
77 } 86 }
78 87
79 void NativeViewHostAura::UninstallClip() { 88 void NativeViewHostAura::UninstallClip() {
89 if (installed_clip_ == false)
90 return;
91
80 installed_clip_ = false; 92 installed_clip_ = false;
93 clipping_window_.layer()->SetMasksToBounds(false);
81 } 94 }
82 95
83 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) { 96 void NativeViewHostAura::ShowWidget(int x, int y, int w, int h) {
84 // TODO: need to support fast resize. 97 if (host_->fast_resize()) {
85 host_->native_view()->SetBounds(gfx::Rect(x, y, w, h)); 98 InstallClip(x, y, w, h);
86 host_->native_view()->Show(); 99 } else {
100 gfx::Point clip_offset = clipping_window_.bounds().origin();
101 host_->native_view()->SetBounds(
102 gfx::Rect(x - clip_offset.x(), y - clip_offset.y(), w, h));
103 host_->native_view()->Show();
104 }
87 } 105 }
88 106
89 void NativeViewHostAura::HideWidget() { 107 void NativeViewHostAura::HideWidget() {
90 host_->native_view()->Hide(); 108 host_->native_view()->Hide();
91 } 109 }
92 110
93 void NativeViewHostAura::SetFocus() { 111 void NativeViewHostAura::SetFocus() {
94 aura::Window* window = host_->native_view(); 112 aura::Window* window = host_->native_view();
95 aura::client::FocusClient* client = aura::client::GetFocusClient(window); 113 aura::client::FocusClient* client = aura::client::GetFocusClient(window);
96 if (client) 114 if (client)
(...skipping 14 matching lines...) Expand all
111 DCHECK(window == host_->native_view()); 129 DCHECK(window == host_->native_view());
112 host_->NativeViewDestroyed(); 130 host_->NativeViewDestroyed();
113 } 131 }
114 132
115 // static 133 // static
116 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper( 134 NativeViewHostWrapper* NativeViewHostWrapper::CreateWrapper(
117 NativeViewHost* host) { 135 NativeViewHost* host) {
118 return new NativeViewHostAura(host); 136 return new NativeViewHostAura(host);
119 } 137 }
120 138
139 void NativeViewHostAura::AddClippingWindow() {
140 gfx::Rect bounds = host_->native_view()->bounds();
141
142 if (host_->GetWidget()->GetNativeView()) {
143 Widget::ReparentNativeView(&clipping_window_,
144 host_->GetWidget()->GetNativeView());
145 }
146 Widget::ReparentNativeView(host_->native_view(), &clipping_window_);
147
148 clipping_window_.SetBounds(bounds);
149 bounds.set_origin(gfx::Point(0, 0));
150 host_->native_view()->SetBounds(bounds);
151 clipping_window_.Show();
152 }
153
154 void NativeViewHostAura::RemoveClippingWindow() {
155 if (host_->native_view()->parent() == &clipping_window_) {
156 if (host_->GetWidget()->GetNativeView()) {
157 Widget::ReparentNativeView(host_->native_view(),
158 host_->GetWidget()->GetNativeView());
159 } else {
160 clipping_window_.RemoveChild(host_->native_view());
161 }
162 host_->native_view()->SetBounds(clipping_window_.bounds());
163 }
164 clipping_window_.Hide();
165 if (clipping_window_.parent())
166 clipping_window_.parent()->RemoveChild(&clipping_window_);
167 }
168
121 } // namespace views 169 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698