OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "chrome/browser/android/compositor/layer/contextual_search_layer.h" | 5 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h" |
6 | 6 |
7 #include "cc/layers/layer.h" | 7 #include "cc/layers/layer.h" |
8 #include "cc/layers/nine_patch_layer.h" | 8 #include "cc/layers/nine_patch_layer.h" |
9 #include "cc/layers/solid_color_layer.h" | 9 #include "cc/layers/solid_color_layer.h" |
10 #include "cc/layers/ui_resource_layer.h" | 10 #include "cc/layers/ui_resource_layer.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
134 search_icon_resource->size.height() / 2; | 134 search_icon_resource->size.height() / 2; |
135 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); | 135 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); |
136 search_icon_->SetBounds(search_icon_resource->size); | 136 search_icon_->SetBounds(search_icon_resource->size); |
137 search_icon_->SetPosition( | 137 search_icon_->SetPosition( |
138 gfx::PointF(search_icon_padding_left, search_icon_padding_top)); | 138 gfx::PointF(search_icon_padding_left, search_icon_padding_top)); |
139 search_icon_->SetOpacity(search_icon_opacity); | 139 search_icon_->SetOpacity(search_icon_opacity); |
140 | 140 |
141 // --------------------------------------------------------------------------- | 141 // --------------------------------------------------------------------------- |
142 // Search Promo | 142 // Search Promo |
143 // --------------------------------------------------------------------------- | 143 // --------------------------------------------------------------------------- |
144 bool is_search_promo_resource_ready = false; | |
144 if (search_promo_visible) { | 145 if (search_promo_visible) { |
145 // Grab the Search Opt Out Promo resource. | 146 // Grab the Search Opt Out Promo resource. |
146 ui::ResourceManager::Resource* search_promo_resource = | 147 ui::ResourceManager::Resource* search_promo_resource = |
147 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 148 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
148 search_promo_resource_id); | 149 search_promo_resource_id); |
149 | 150 |
150 if (search_promo_resource) { | 151 if (search_promo_resource) { |
152 is_search_promo_resource_ready = true; | |
153 | |
151 // Search Promo Container | 154 // Search Promo Container |
152 if (search_promo_container_->parent() != layer_) | 155 if (search_promo_container_->parent() != layer_) |
153 layer_->AddChild(search_promo_container_); | 156 layer_->AddChild(search_promo_container_); |
154 | 157 |
155 int search_promo_content_height = search_promo_resource->size.height(); | 158 int search_promo_content_height = search_promo_resource->size.height(); |
156 gfx::Size search_promo_size(search_panel_width, search_promo_height); | 159 gfx::Size search_promo_size(search_panel_width, search_promo_height); |
157 search_promo_container_->SetBounds(search_promo_size); | 160 search_promo_container_->SetBounds(search_promo_size); |
158 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); | 161 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); |
159 search_promo_container_->SetMasksToBounds(true); | 162 search_promo_container_->SetMasksToBounds(true); |
160 | 163 |
(...skipping 27 matching lines...) Expand all Loading... | |
188 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); | 191 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); |
189 if (content_view_layer->parent() != content_view_container_) | 192 if (content_view_layer->parent() != content_view_container_) |
190 content_view_container_->AddChild(content_view_layer); | 193 content_view_container_->AddChild(content_view_layer); |
191 } else { | 194 } else { |
192 content_view_container_->RemoveAllChildren(); | 195 content_view_container_->RemoveAllChildren(); |
193 } | 196 } |
194 | 197 |
195 // --------------------------------------------------------------------------- | 198 // --------------------------------------------------------------------------- |
196 // Search Bar Shadow | 199 // Search Bar Shadow |
197 // --------------------------------------------------------------------------- | 200 // --------------------------------------------------------------------------- |
198 if (search_bar_shadow_visible) { | 201 // NOTE(pedrosimonetti): Since the Promo resource is a dynamic one (it will |
202 // take a snapshot of the Promo View) it will always be available before | |
Donn Denman
2015/04/14 23:50:04
This is confusing to me. If the promo will always
pedro (no code reviews)
2015/04/16 19:05:29
It was supposed to read: "it will NOT always be av
| |
203 // the Shadow resource. Therefore, we need to confirm that the Promo resource | |
204 // is ready before adding the Shadow layer, otherwise the Promo layer will | |
205 // be placed over the Shadow layer, making it not visible. | |
David Trainor- moved to gerrit
2015/04/15 07:36:15
You can insert children at specific points in the
pedro (no code reviews)
2015/04/16 19:05:29
Good idea. I'm using InsertChild() now.
On the ot
David Trainor- moved to gerrit
2015/04/16 20:51:45
Yeah, I wonder if we could make that public. I do
| |
206 if (is_search_promo_resource_ready && search_bar_shadow_visible) { | |
199 ui::ResourceManager::Resource* search_bar_shadow_resource = | 207 ui::ResourceManager::Resource* search_bar_shadow_resource = |
200 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 208 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
201 search_bar_shadow_resource_id); | 209 search_bar_shadow_resource_id); |
202 | 210 |
203 if (search_bar_shadow_resource) { | 211 if (search_bar_shadow_resource) { |
204 if (search_bar_shadow_->parent() != layer_) | 212 if (search_bar_shadow_->parent() != layer_) |
205 layer_->AddChild(search_bar_shadow_); | 213 layer_->AddChild(search_bar_shadow_); |
214 | |
215 int shadow_height = search_bar_shadow_resource->size.height(); | |
216 gfx::Size shadow_size(search_panel_width, shadow_height); | |
217 | |
218 search_bar_shadow_->SetUIResourceId( | |
219 search_bar_shadow_resource->ui_resource->id()); | |
220 search_bar_shadow_->SetBounds(shadow_size); | |
221 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_height)); | |
222 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity); | |
206 } | 223 } |
207 | |
208 int shadow_height = search_bar_shadow_resource->size.height(); | |
209 gfx::Size shadow_size(search_panel_width, shadow_height); | |
210 | |
211 search_bar_shadow_->SetUIResourceId( | |
212 search_bar_shadow_resource->ui_resource->id()); | |
213 search_bar_shadow_->SetBounds(shadow_size); | |
214 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_height)); | |
215 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity); | |
216 } else { | 224 } else { |
217 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) | 225 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) |
218 search_bar_shadow_->RemoveFromParent(); | 226 search_bar_shadow_->RemoveFromParent(); |
219 } | 227 } |
220 | 228 |
221 // --------------------------------------------------------------------------- | 229 // --------------------------------------------------------------------------- |
222 // Search Panel. | 230 // Search Panel. |
223 // --------------------------------------------------------------------------- | 231 // --------------------------------------------------------------------------- |
224 layer_->SetPosition(gfx::PointF(0.f, search_panel_y)); | 232 layer_->SetPosition(gfx::PointF(0.f, search_panel_y)); |
225 | 233 |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
353 | 361 |
354 ContextualSearchLayer::~ContextualSearchLayer() { | 362 ContextualSearchLayer::~ContextualSearchLayer() { |
355 } | 363 } |
356 | 364 |
357 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 365 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
358 return layer_; | 366 return layer_; |
359 } | 367 } |
360 | 368 |
361 } // namespace android | 369 } // namespace android |
362 } // namespace chrome | 370 } // namespace chrome |
OLD | NEW |