| 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" |
| 11 #include "content/public/browser/android/content_view_core.h" | 11 #include "content/public/browser/android/content_view_core.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/android/resources/resource_manager.h" | 13 #include "ui/android/resources/resource_manager.h" |
| 14 #include "ui/android/resources/ui_resource_android.h" | 14 #include "ui/android/resources/ui_resource_android.h" |
| 15 | 15 |
| 16 namespace { | 16 namespace { |
| 17 | 17 |
| 18 const SkColor kContextualSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); | 18 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| 19 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); |
| 19 | 20 |
| 20 } // namespace | 21 } // namespace |
| 21 | 22 |
| 22 namespace chrome { | 23 namespace chrome { |
| 23 namespace android { | 24 namespace android { |
| 24 | 25 |
| 25 // static | 26 // static |
| 26 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( | 27 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( |
| 27 ui::ResourceManager* resource_manager) { | 28 ui::ResourceManager* resource_manager) { |
| 28 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 29 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
| 29 } | 30 } |
| 30 | 31 |
| 31 void ContextualSearchLayer::SetProperties( | 32 void ContextualSearchLayer::SetProperties( |
| 32 int search_bar_background_resource_id, | 33 int search_bar_background_resource_id, |
| 33 int search_bar_text_resource_id, | 34 int search_bar_text_resource_id, |
| 35 int search_bar_shadow_resource_id, |
| 34 int search_provider_icon_resource_id, | 36 int search_provider_icon_resource_id, |
| 35 int search_icon_resource_id, | 37 int search_icon_resource_id, |
| 36 int progress_bar_background_resource_id, | 38 int progress_bar_background_resource_id, |
| 37 int progress_bar_resource_id, | 39 int progress_bar_resource_id, |
| 40 int search_promo_resource_id, |
| 38 content::ContentViewCore* content_view_core, | 41 content::ContentViewCore* content_view_core, |
| 42 bool search_promo_visible, |
| 43 float search_promo_height, |
| 44 float search_promo_opacity, |
| 39 float search_panel_y, | 45 float search_panel_y, |
| 40 float search_panel_width, | 46 float search_panel_width, |
| 41 float search_bar_margin_top, | 47 float search_bar_margin_top, |
| 42 float search_bar_height, | 48 float search_bar_height, |
| 43 float search_bar_text_opacity, | 49 float search_bar_text_opacity, |
| 44 bool search_bar_border_visible, | 50 bool search_bar_border_visible, |
| 45 float search_bar_border_y, | 51 float search_bar_border_y, |
| 46 float search_bar_border_height, | 52 float search_bar_border_height, |
| 53 bool search_bar_shadow_visible, |
| 54 float search_bar_shadow_opacity, |
| 47 float search_provider_icon_opacity, | 55 float search_provider_icon_opacity, |
| 48 float search_icon_padding_left, | 56 float search_icon_padding_left, |
| 49 float search_icon_opacity, | 57 float search_icon_opacity, |
| 50 bool progress_bar_visible, | 58 bool progress_bar_visible, |
| 51 float progress_bar_y, | 59 float progress_bar_y, |
| 52 float progress_bar_height, | 60 float progress_bar_height, |
| 53 float progress_bar_opacity, | 61 float progress_bar_opacity, |
| 54 int progress_bar_completion) { | 62 int progress_bar_completion) { |
| 55 // Grab the dynamic Search Bar Text resource. | 63 // Grab the dynamic Search Bar Text resource. |
| 56 ui::ResourceManager::Resource* search_bar_text_resource = | 64 ui::ResourceManager::Resource* search_bar_text_resource = |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 float search_icon_padding_top = | 132 float search_icon_padding_top = |
| 125 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 - | 133 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 - |
| 126 search_icon_resource->size.height() / 2; | 134 search_icon_resource->size.height() / 2; |
| 127 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); | 135 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); |
| 128 search_icon_->SetBounds(search_icon_resource->size); | 136 search_icon_->SetBounds(search_icon_resource->size); |
| 129 search_icon_->SetPosition( | 137 search_icon_->SetPosition( |
| 130 gfx::PointF(search_icon_padding_left, search_icon_padding_top)); | 138 gfx::PointF(search_icon_padding_left, search_icon_padding_top)); |
| 131 search_icon_->SetOpacity(search_icon_opacity); | 139 search_icon_->SetOpacity(search_icon_opacity); |
| 132 | 140 |
| 133 // --------------------------------------------------------------------------- | 141 // --------------------------------------------------------------------------- |
| 142 // Search Promo |
| 143 // --------------------------------------------------------------------------- |
| 144 if (search_promo_visible) { |
| 145 // Grab the Search Opt Out Promo resource. |
| 146 ui::ResourceManager::Resource* search_promo_resource = |
| 147 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 148 search_promo_resource_id); |
| 149 |
| 150 if (search_promo_resource) { |
| 151 // Search Promo Container |
| 152 if (search_promo_container_->parent() != layer_) |
| 153 layer_->AddChild(search_promo_container_); |
| 154 |
| 155 int search_promo_content_height = search_promo_resource->size.height(); |
| 156 gfx::Size search_promo_size(search_panel_width, search_promo_height); |
| 157 search_promo_container_->SetBounds(search_promo_size); |
| 158 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); |
| 159 search_promo_container_->SetMasksToBounds(true); |
| 160 |
| 161 // Search Promo |
| 162 if (search_promo_->parent() != search_promo_container_) |
| 163 search_promo_container_->AddChild(search_promo_); |
| 164 |
| 165 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id()); |
| 166 search_promo_->SetBounds(search_promo_resource->size); |
| 167 // Align promo at the bottom of the container so the confirmation button |
| 168 // is is not clipped when resizing the promo. |
| 169 search_promo_->SetPosition( |
| 170 gfx::PointF(0.f, search_promo_height - search_promo_content_height)); |
| 171 search_promo_->SetOpacity(search_promo_opacity); |
| 172 } |
| 173 } else { |
| 174 // TODO(pedrosimonetti): confirm with dtrainor@ that we don't need to remove |
| 175 // the child too (since it's going to be removed when the parent is gone). |
| 176 |
| 177 // Search Promo Container |
| 178 if (search_promo_container_.get() && search_promo_container_->parent()) |
| 179 search_promo_container_->RemoveFromParent(); |
| 180 } |
| 181 |
| 182 // --------------------------------------------------------------------------- |
| 134 // Search Content View | 183 // Search Content View |
| 135 // --------------------------------------------------------------------------- | 184 // --------------------------------------------------------------------------- |
| 136 content_view_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); | 185 content_view_container_->SetPosition( |
| 186 gfx::PointF(0.f, search_bar_height + search_promo_height)); |
| 137 if (content_view_core && content_view_core->GetLayer().get()) { | 187 if (content_view_core && content_view_core->GetLayer().get()) { |
| 138 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); | 188 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); |
| 139 if (content_view_layer->parent() != content_view_container_) | 189 if (content_view_layer->parent() != content_view_container_) |
| 140 content_view_container_->AddChild(content_view_layer); | 190 content_view_container_->AddChild(content_view_layer); |
| 141 } else { | 191 } else { |
| 142 content_view_container_->RemoveAllChildren(); | 192 content_view_container_->RemoveAllChildren(); |
| 143 } | 193 } |
| 144 | 194 |
| 145 // --------------------------------------------------------------------------- | 195 // --------------------------------------------------------------------------- |
| 196 // Search Bar Shadow |
| 197 // --------------------------------------------------------------------------- |
| 198 if (search_bar_shadow_visible) { |
| 199 ui::ResourceManager::Resource* search_bar_shadow_resource = |
| 200 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 201 search_bar_shadow_resource_id); |
| 202 |
| 203 if (search_bar_shadow_resource) { |
| 204 if (search_bar_shadow_->parent() != layer_) |
| 205 layer_->AddChild(search_bar_shadow_); |
| 206 } |
| 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 { |
| 217 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) |
| 218 search_bar_shadow_->RemoveFromParent(); |
| 219 } |
| 220 |
| 221 // --------------------------------------------------------------------------- |
| 146 // Search Panel. | 222 // Search Panel. |
| 147 // --------------------------------------------------------------------------- | 223 // --------------------------------------------------------------------------- |
| 148 layer_->SetPosition(gfx::PointF(0.f, search_panel_y)); | 224 layer_->SetPosition(gfx::PointF(0.f, search_panel_y)); |
| 149 | 225 |
| 150 // --------------------------------------------------------------------------- | 226 // --------------------------------------------------------------------------- |
| 151 // Progress Bar | 227 // Progress Bar |
| 152 // --------------------------------------------------------------------------- | 228 // --------------------------------------------------------------------------- |
| 153 bool should_render_progress_bar = | 229 bool should_render_progress_bar = |
| 154 progress_bar_visible && progress_bar_opacity > 0.f; | 230 progress_bar_visible && progress_bar_opacity > 0.f; |
| 155 if (should_render_progress_bar) { | 231 if (should_render_progress_bar) { |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 search_bar_border_->RemoveFromParent(); | 291 search_bar_border_->RemoveFromParent(); |
| 216 } | 292 } |
| 217 } | 293 } |
| 218 | 294 |
| 219 ContextualSearchLayer::ContextualSearchLayer( | 295 ContextualSearchLayer::ContextualSearchLayer( |
| 220 ui::ResourceManager* resource_manager) | 296 ui::ResourceManager* resource_manager) |
| 221 : resource_manager_(resource_manager), | 297 : resource_manager_(resource_manager), |
| 222 layer_(cc::Layer::Create()), | 298 layer_(cc::Layer::Create()), |
| 223 search_bar_background_(cc::NinePatchLayer::Create()), | 299 search_bar_background_(cc::NinePatchLayer::Create()), |
| 224 search_bar_text_(cc::UIResourceLayer::Create()), | 300 search_bar_text_(cc::UIResourceLayer::Create()), |
| 301 search_bar_shadow_(cc::UIResourceLayer::Create()), |
| 225 search_provider_icon_(cc::UIResourceLayer::Create()), | 302 search_provider_icon_(cc::UIResourceLayer::Create()), |
| 226 search_icon_(cc::UIResourceLayer::Create()), | 303 search_icon_(cc::UIResourceLayer::Create()), |
| 227 content_view_container_(cc::Layer::Create()), | 304 content_view_container_(cc::Layer::Create()), |
| 228 search_bar_border_(cc::SolidColorLayer::Create()), | 305 search_bar_border_(cc::SolidColorLayer::Create()), |
| 229 progress_bar_(cc::NinePatchLayer::Create()), | 306 progress_bar_(cc::NinePatchLayer::Create()), |
| 230 progress_bar_background_(cc::NinePatchLayer::Create()) { | 307 progress_bar_background_(cc::NinePatchLayer::Create()), |
| 308 search_promo_(cc::UIResourceLayer::Create()), |
| 309 search_promo_container_(cc::SolidColorLayer::Create()) { |
| 231 layer_->SetMasksToBounds(false); | 310 layer_->SetMasksToBounds(false); |
| 232 layer_->SetIsDrawable(true); | 311 layer_->SetIsDrawable(true); |
| 233 | 312 |
| 234 // Search Bar Background | 313 // Search Bar Background |
| 235 search_bar_background_->SetIsDrawable(true); | 314 search_bar_background_->SetIsDrawable(true); |
| 236 search_bar_background_->SetFillCenter(true); | 315 search_bar_background_->SetFillCenter(true); |
| 237 layer_->AddChild(search_bar_background_); | 316 layer_->AddChild(search_bar_background_); |
| 238 | 317 |
| 239 // Search Bar Text | 318 // Search Bar Text |
| 240 search_bar_text_->SetIsDrawable(true); | 319 search_bar_text_->SetIsDrawable(true); |
| 241 layer_->AddChild(search_bar_text_); | 320 layer_->AddChild(search_bar_text_); |
| 242 | 321 |
| 243 // Search Provider Icon | 322 // Search Provider Icon |
| 244 search_provider_icon_->SetIsDrawable(true); | 323 search_provider_icon_->SetIsDrawable(true); |
| 245 layer_->AddChild(search_provider_icon_); | 324 layer_->AddChild(search_provider_icon_); |
| 246 | 325 |
| 247 // Search Icon | 326 // Search Icon |
| 248 search_icon_->SetIsDrawable(true); | 327 search_icon_->SetIsDrawable(true); |
| 249 layer_->AddChild(search_icon_); | 328 layer_->AddChild(search_icon_); |
| 250 | 329 |
| 330 // Search Opt Out Promo |
| 331 search_promo_container_->SetIsDrawable(true); |
| 332 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); |
| 333 search_promo_->SetIsDrawable(true); |
| 334 |
| 251 // Search Bar Border | 335 // Search Bar Border |
| 252 search_bar_border_->SetIsDrawable(true); | 336 search_bar_border_->SetIsDrawable(true); |
| 253 search_bar_border_->SetBackgroundColor(kContextualSearchBarBorderColor); | 337 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor); |
| 254 | 338 |
| 255 // Progress Bar Background | 339 // Progress Bar Background |
| 256 progress_bar_background_->SetIsDrawable(true); | 340 progress_bar_background_->SetIsDrawable(true); |
| 257 progress_bar_background_->SetFillCenter(true); | 341 progress_bar_background_->SetFillCenter(true); |
| 258 | 342 |
| 259 // Progress Bar | 343 // Progress Bar |
| 260 progress_bar_->SetIsDrawable(true); | 344 progress_bar_->SetIsDrawable(true); |
| 261 progress_bar_->SetFillCenter(true); | 345 progress_bar_->SetFillCenter(true); |
| 262 | 346 |
| 263 // Search Content View | 347 // Search Content View Container |
| 264 layer_->AddChild(content_view_container_); | 348 layer_->AddChild(content_view_container_); |
| 349 |
| 350 // Search Bar Shadow |
| 351 search_bar_shadow_->SetIsDrawable(true); |
| 265 } | 352 } |
| 266 | 353 |
| 267 ContextualSearchLayer::~ContextualSearchLayer() { | 354 ContextualSearchLayer::~ContextualSearchLayer() { |
| 268 } | 355 } |
| 269 | 356 |
| 270 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 357 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
| 271 return layer_; | 358 return layer_; |
| 272 } | 359 } |
| 273 | 360 |
| 274 } // namespace android | 361 } // namespace android |
| 275 } // namespace chrome | 362 } // namespace chrome |
| OLD | NEW |