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 20 matching lines...) Expand all Loading... | |
31 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 31 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
32 } | 32 } |
33 | 33 |
34 void ContextualSearchLayer::SetProperties( | 34 void ContextualSearchLayer::SetProperties( |
35 int search_bar_background_resource_id, | 35 int search_bar_background_resource_id, |
36 int search_bar_text_resource_id, | 36 int search_bar_text_resource_id, |
37 int search_bar_shadow_resource_id, | 37 int search_bar_shadow_resource_id, |
38 int search_provider_icon_resource_id, | 38 int search_provider_icon_resource_id, |
39 int search_icon_resource_id, | 39 int search_icon_resource_id, |
40 int arrow_up_resource_id, | 40 int arrow_up_resource_id, |
41 int close_icon_resource_id, | |
41 int progress_bar_background_resource_id, | 42 int progress_bar_background_resource_id, |
42 int progress_bar_resource_id, | 43 int progress_bar_resource_id, |
43 int search_promo_resource_id, | 44 int search_promo_resource_id, |
44 content::ContentViewCore* content_view_core, | 45 content::ContentViewCore* content_view_core, |
45 bool search_promo_visible, | 46 bool search_promo_visible, |
46 float search_promo_height, | 47 float search_promo_height, |
47 float search_promo_opacity, | 48 float search_promo_opacity, |
48 float search_panel_y, | 49 float search_panel_y, |
49 float search_panel_width, | 50 float search_panel_width, |
50 float search_bar_margin_top, | 51 float search_bar_margin_top, |
51 float search_bar_margin_side, | 52 float search_bar_margin_side, |
52 float search_bar_height, | 53 float search_bar_height, |
53 float search_bar_text_opacity, | 54 float search_bar_text_opacity, |
54 bool search_bar_border_visible, | 55 bool search_bar_border_visible, |
55 float search_bar_border_y, | 56 float search_bar_border_y, |
56 float search_bar_border_height, | 57 float search_bar_border_height, |
57 bool search_bar_shadow_visible, | 58 bool search_bar_shadow_visible, |
58 float search_bar_shadow_opacity, | 59 float search_bar_shadow_opacity, |
59 float search_provider_icon_opacity, | 60 float search_provider_icon_opacity, |
60 float search_icon_opacity, | 61 float search_icon_opacity, |
61 bool arrow_icon_visible, | 62 bool arrow_icon_visible, |
62 float arrow_icon_opacity, | 63 float arrow_icon_opacity, |
63 float arrow_icon_rotation, | 64 float arrow_icon_rotation, |
65 bool close_icon_visible, | |
66 float close_icon_opacity, | |
64 bool progress_bar_visible, | 67 bool progress_bar_visible, |
65 float progress_bar_y, | 68 float progress_bar_y, |
66 float progress_bar_height, | 69 float progress_bar_height, |
67 float progress_bar_opacity, | 70 float progress_bar_opacity, |
68 int progress_bar_completion) { | 71 int progress_bar_completion) { |
69 // Grab the dynamic Search Bar Text resource. | 72 // Grab the dynamic Search Bar Text resource. |
70 ui::ResourceManager::Resource* search_bar_text_resource = | 73 ui::ResourceManager::Resource* search_bar_text_resource = |
71 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 74 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
72 search_bar_text_resource_id); | 75 search_bar_text_resource_id); |
73 | 76 |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
140 float search_icon_left; | 143 float search_icon_left; |
141 if (is_rtl) { | 144 if (is_rtl) { |
142 search_icon_left = search_panel_width - | 145 search_icon_left = search_panel_width - |
143 search_icon_resource->size.width() - search_bar_margin_side; | 146 search_icon_resource->size.width() - search_bar_margin_side; |
144 } else { | 147 } else { |
145 search_icon_left = search_bar_margin_side; | 148 search_icon_left = search_bar_margin_side; |
146 } | 149 } |
147 | 150 |
148 // Centers the Search Icon vertically in the Search Bar. | 151 // Centers the Search Icon vertically in the Search Bar. |
149 float search_icon_top = | 152 float search_icon_top = |
150 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 - | 153 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 |
151 search_icon_resource->size.height() / 2; | 154 - search_icon_resource->size.height() / 2; |
pedro (no code reviews)
2015/07/08 20:15:05
Nit: Differently from Java, the operator should be
Theresa
2015/07/08 21:04:59
Done.
| |
152 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); | 155 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id()); |
153 search_icon_->SetBounds(search_icon_resource->size); | 156 search_icon_->SetBounds(search_icon_resource->size); |
154 search_icon_->SetPosition( | 157 search_icon_->SetPosition( |
155 gfx::PointF(search_icon_left, search_icon_top)); | 158 gfx::PointF(search_icon_left, search_icon_top)); |
156 search_icon_->SetOpacity(search_icon_opacity); | 159 search_icon_->SetOpacity(search_icon_opacity); |
157 | 160 |
158 // --------------------------------------------------------------------------- | 161 // --------------------------------------------------------------------------- |
159 // Arrow Icon | 162 // Arrow Icon |
160 // --------------------------------------------------------------------------- | 163 // --------------------------------------------------------------------------- |
161 if (arrow_icon_visible) { | 164 if (arrow_icon_visible) { |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
197 transform.RotateAboutZAxis(arrow_icon_rotation); | 200 transform.RotateAboutZAxis(arrow_icon_rotation); |
198 transform.Translate(-pivot_origin.x(), -pivot_origin.y()); | 201 transform.Translate(-pivot_origin.x(), -pivot_origin.y()); |
199 } | 202 } |
200 arrow_icon_->SetTransform(transform); | 203 arrow_icon_->SetTransform(transform); |
201 } else { | 204 } else { |
202 if (arrow_icon_.get() && arrow_icon_->parent()) | 205 if (arrow_icon_.get() && arrow_icon_->parent()) |
203 arrow_icon_->RemoveFromParent(); | 206 arrow_icon_->RemoveFromParent(); |
204 } | 207 } |
205 | 208 |
206 // --------------------------------------------------------------------------- | 209 // --------------------------------------------------------------------------- |
210 // Close Icon | |
211 // --------------------------------------------------------------------------- | |
212 if (close_icon_visible) { | |
213 // Grab the Close Icon resource. | |
214 ui::ResourceManager::Resource* close_icon_resource = | |
215 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | |
216 close_icon_resource_id); | |
217 if (close_icon_->parent() != layer_) { | |
218 layer_->AddChild(close_icon_); | |
219 } | |
220 | |
221 // Positions the icon at the end of the Search Bar. | |
222 float close_icon_left; | |
223 if (is_rtl) { | |
224 close_icon_left = search_bar_margin_side; | |
225 } else { | |
226 close_icon_left = search_panel_width - | |
227 close_icon_resource->size.width() - search_bar_margin_side; | |
228 } | |
229 | |
230 // Centers the Close Icon vertically in the Search Bar. | |
231 float close_icon_top = search_bar_margin_top + | |
232 (search_bar_height - search_bar_margin_top) / 2 - | |
233 close_icon_resource->size.height() / 2; | |
234 | |
235 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); | |
236 close_icon_->SetBounds(close_icon_resource->size); | |
237 close_icon_->SetPosition( | |
238 gfx::PointF(close_icon_left, close_icon_top)); | |
239 close_icon_->SetOpacity(close_icon_opacity); | |
240 } else { | |
241 if (close_icon_.get() && close_icon_->parent()) | |
242 close_icon_->RemoveFromParent(); | |
243 } | |
244 | |
245 // --------------------------------------------------------------------------- | |
207 // Search Promo | 246 // Search Promo |
208 // --------------------------------------------------------------------------- | 247 // --------------------------------------------------------------------------- |
209 if (search_promo_visible) { | 248 if (search_promo_visible) { |
210 // Grab the Search Opt Out Promo resource. | 249 // Grab the Search Opt Out Promo resource. |
211 ui::ResourceManager::Resource* search_promo_resource = | 250 ui::ResourceManager::Resource* search_promo_resource = |
212 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 251 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
213 search_promo_resource_id); | 252 search_promo_resource_id); |
214 // Search Promo Container | 253 // Search Promo Container |
215 if (search_promo_container_->parent() != layer_) { | 254 if (search_promo_container_->parent() != layer_) { |
216 // NOTE(pedrosimonetti): The Promo layer should be always placed before | 255 // NOTE(pedrosimonetti): The Promo layer should be always placed before |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
365 search_bar_text_( | 404 search_bar_text_( |
366 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 405 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
367 search_bar_shadow_( | 406 search_bar_shadow_( |
368 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 407 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
369 search_provider_icon_( | 408 search_provider_icon_( |
370 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 409 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
371 search_icon_( | 410 search_icon_( |
372 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 411 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
373 arrow_icon_( | 412 arrow_icon_( |
374 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 413 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
414 close_icon_( | |
415 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | |
375 content_view_container_( | 416 content_view_container_( |
376 cc::Layer::Create(content::Compositor::LayerSettings())), | 417 cc::Layer::Create(content::Compositor::LayerSettings())), |
377 search_bar_border_( | 418 search_bar_border_( |
378 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 419 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
379 progress_bar_( | 420 progress_bar_( |
380 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 421 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
381 progress_bar_background_( | 422 progress_bar_background_( |
382 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 423 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
383 search_promo_( | 424 search_promo_( |
384 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 425 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
(...skipping 15 matching lines...) Expand all Loading... | |
400 search_provider_icon_->SetIsDrawable(true); | 441 search_provider_icon_->SetIsDrawable(true); |
401 layer_->AddChild(search_provider_icon_); | 442 layer_->AddChild(search_provider_icon_); |
402 | 443 |
403 // Search Icon | 444 // Search Icon |
404 search_icon_->SetIsDrawable(true); | 445 search_icon_->SetIsDrawable(true); |
405 layer_->AddChild(search_icon_); | 446 layer_->AddChild(search_icon_); |
406 | 447 |
407 // Arrow Icon | 448 // Arrow Icon |
408 arrow_icon_->SetIsDrawable(true); | 449 arrow_icon_->SetIsDrawable(true); |
409 | 450 |
451 // Close Icon | |
452 close_icon_->SetIsDrawable(true); | |
453 | |
410 // Search Opt Out Promo | 454 // Search Opt Out Promo |
411 search_promo_container_->SetIsDrawable(true); | 455 search_promo_container_->SetIsDrawable(true); |
412 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); | 456 search_promo_container_->SetBackgroundColor(kSearchBackgroundColor); |
413 search_promo_->SetIsDrawable(true); | 457 search_promo_->SetIsDrawable(true); |
414 | 458 |
415 // Search Bar Border | 459 // Search Bar Border |
416 search_bar_border_->SetIsDrawable(true); | 460 search_bar_border_->SetIsDrawable(true); |
417 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor); | 461 search_bar_border_->SetBackgroundColor(kSearchBarBorderColor); |
418 | 462 |
419 // Progress Bar Background | 463 // Progress Bar Background |
(...skipping 13 matching lines...) Expand all Loading... | |
433 | 477 |
434 ContextualSearchLayer::~ContextualSearchLayer() { | 478 ContextualSearchLayer::~ContextualSearchLayer() { |
435 } | 479 } |
436 | 480 |
437 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 481 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
438 return layer_; | 482 return layer_; |
439 } | 483 } |
440 | 484 |
441 } // namespace android | 485 } // namespace android |
442 } // namespace chrome | 486 } // namespace chrome |
OLD | NEW |