| 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 "cc/resources/scoped_ui_resource.h" | 11 #include "cc/resources/scoped_ui_resource.h" |
| 12 #include "content/public/browser/android/compositor.h" | 12 #include "content/public/browser/android/compositor.h" |
| 13 #include "content/public/browser/android/content_view_core.h" | 13 #include "content/public/browser/android/content_view_core.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 14 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "ui/android/resources/resource_manager.h" | 15 #include "ui/android/resources/resource_manager.h" |
| 16 #include "ui/base/l10n/l10n_util_android.h" | 16 #include "ui/base/l10n/l10n_util_android.h" |
| 17 #include "ui/gfx/color_utils.h" |
| 17 | 18 |
| 18 namespace { | 19 namespace { |
| 19 | 20 |
| 20 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); | 21 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); |
| 21 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); | 22 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); |
| 22 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); | 23 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); |
| 24 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4); |
| 25 |
| 26 // The alpha blend used in the Peek Promo Background in order to achieve |
| 27 // a lighter shade of the color of the Peek Promo Ripple. |
| 28 const SkAlpha kPeekPromoBackgroundMaximumAlphaBlend = 0.25f * 255; |
| 23 | 29 |
| 24 } // namespace | 30 } // namespace |
| 25 | 31 |
| 26 namespace chrome { | 32 namespace chrome { |
| 27 namespace android { | 33 namespace android { |
| 28 | 34 |
| 29 // static | 35 // static |
| 30 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( | 36 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( |
| 31 ui::ResourceManager* resource_manager) { | 37 ui::ResourceManager* resource_manager) { |
| 32 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); | 38 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); |
| 33 } | 39 } |
| 34 | 40 |
| 35 void ContextualSearchLayer::SetProperties( | 41 void ContextualSearchLayer::SetProperties( |
| 36 int panel_shadow_resource_id, | 42 int panel_shadow_resource_id, |
| 37 int search_context_resource_id, | 43 int search_context_resource_id, |
| 38 int search_term_resource_id, | 44 int search_term_resource_id, |
| 39 int search_bar_shadow_resource_id, | 45 int search_bar_shadow_resource_id, |
| 40 int search_provider_icon_resource_id, | 46 int search_provider_icon_resource_id, |
| 41 int arrow_up_resource_id, | 47 int arrow_up_resource_id, |
| 42 int close_icon_resource_id, | 48 int close_icon_resource_id, |
| 43 int progress_bar_background_resource_id, | 49 int progress_bar_background_resource_id, |
| 44 int progress_bar_resource_id, | 50 int progress_bar_resource_id, |
| 45 int search_promo_resource_id, | 51 int search_promo_resource_id, |
| 52 int peek_promo_ripple_resource_id, |
| 53 int peek_promo_text_resource_id, |
| 46 content::ContentViewCore* content_view_core, | 54 content::ContentViewCore* content_view_core, |
| 47 bool search_promo_visible, | 55 bool search_promo_visible, |
| 48 float search_promo_height, | 56 float search_promo_height, |
| 49 float search_promo_opacity, | 57 float search_promo_opacity, |
| 58 bool search_peek_promo_visible, |
| 59 float search_peek_promo_height, |
| 60 float search_peek_promo_padding, |
| 61 float search_peek_promo_ripple_width, |
| 62 float search_peek_promo_ripple_opacity, |
| 63 float search_peek_promo_text_opacity, |
| 50 float search_panel_x, | 64 float search_panel_x, |
| 51 float search_panel_y, | 65 float search_panel_y, |
| 52 float search_panel_width, | 66 float search_panel_width, |
| 53 float search_panel_height, | 67 float search_panel_height, |
| 54 float search_bar_margin_side, | 68 float search_bar_margin_side, |
| 55 float search_bar_height, | 69 float search_bar_height, |
| 56 float search_context_opacity, | 70 float search_context_opacity, |
| 57 float search_term_opacity, | 71 float search_term_opacity, |
| 58 bool search_bar_border_visible, | 72 bool search_bar_border_visible, |
| 59 float search_bar_border_y, | |
| 60 float search_bar_border_height, | 73 float search_bar_border_height, |
| 61 bool search_bar_shadow_visible, | 74 bool search_bar_shadow_visible, |
| 62 float search_bar_shadow_opacity, | 75 float search_bar_shadow_opacity, |
| 63 float arrow_icon_opacity, | 76 float arrow_icon_opacity, |
| 64 float arrow_icon_rotation, | 77 float arrow_icon_rotation, |
| 65 float close_icon_opacity, | 78 float close_icon_opacity, |
| 66 bool progress_bar_visible, | 79 bool progress_bar_visible, |
| 67 float progress_bar_y, | |
| 68 float progress_bar_height, | 80 float progress_bar_height, |
| 69 float progress_bar_opacity, | 81 float progress_bar_opacity, |
| 70 int progress_bar_completion) { | 82 int progress_bar_completion) { |
| 71 // Grabs the dynamic Search Bar Text resource. | 83 // Grabs the dynamic Search Bar Text resource. |
| 72 ui::ResourceManager::Resource* search_context_resource = | 84 ui::ResourceManager::Resource* search_context_resource = |
| 73 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 74 search_context_resource_id); | 86 search_context_resource_id); |
| 75 ui::ResourceManager::Resource* search_term_resource = | 87 ui::ResourceManager::Resource* search_term_resource = |
| 76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 88 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 77 search_term_resource_id); | 89 search_term_resource_id); |
| 78 | 90 |
| 79 // Grabs required static resources. | 91 // Grabs required static resources. |
| 80 ui::ResourceManager::Resource* panel_shadow_resource = | 92 ui::ResourceManager::Resource* panel_shadow_resource = |
| 81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 93 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 82 panel_shadow_resource_id); | 94 panel_shadow_resource_id); |
| 83 ui::ResourceManager::Resource* search_provider_icon_resource = | 95 ui::ResourceManager::Resource* search_provider_icon_resource = |
| 84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 96 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 85 search_provider_icon_resource_id); | 97 search_provider_icon_resource_id); |
| 86 | 98 |
| 87 DCHECK(panel_shadow_resource); | 99 DCHECK(panel_shadow_resource); |
| 88 DCHECK(search_provider_icon_resource); | 100 DCHECK(search_provider_icon_resource); |
| 89 | 101 |
| 90 // Round values to avoid pixel gap between layers. | 102 // Round values to avoid pixel gap between layers. |
| 91 search_bar_height = floor(search_bar_height); | 103 search_bar_height = floor(search_bar_height); |
| 92 | 104 |
| 105 float search_bar_top = search_peek_promo_height; |
| 106 float search_bar_bottom = search_bar_top + search_bar_height; |
| 107 |
| 93 bool is_rtl = l10n_util::IsLayoutRtl(); | 108 bool is_rtl = l10n_util::IsLayoutRtl(); |
| 94 | 109 |
| 95 // --------------------------------------------------------------------------- | 110 // --------------------------------------------------------------------------- |
| 96 // Panel Shadow | 111 // Panel Shadow |
| 97 // --------------------------------------------------------------------------- | 112 // --------------------------------------------------------------------------- |
| 98 gfx::Size shadow_res_size = panel_shadow_resource->size; | 113 gfx::Size shadow_res_size = panel_shadow_resource->size; |
| 99 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; | 114 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; |
| 100 gfx::Size shadow_bounds( | 115 gfx::Size shadow_bounds( |
| 101 search_panel_width + shadow_res_size.width() | 116 search_panel_width + shadow_res_size.width() |
| 102 - shadow_res_padding.size().width(), | 117 - shadow_res_padding.size().width(), |
| 103 search_panel_height + shadow_res_size.height() | 118 search_panel_height + shadow_res_size.height() |
| 104 - shadow_res_padding.size().height()); | 119 - shadow_res_padding.size().height()); |
| 105 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource->id()); | 120 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource->id()); |
| 106 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds)); | 121 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds)); |
| 107 panel_shadow_->SetAperture(panel_shadow_resource->aperture); | 122 panel_shadow_->SetAperture(panel_shadow_resource->aperture); |
| 108 panel_shadow_->SetBounds(shadow_bounds); | 123 panel_shadow_->SetBounds(shadow_bounds); |
| 109 gfx::Point shadow_position( | 124 gfx::Point shadow_position( |
| 110 -shadow_res_padding.origin().x(), | 125 -shadow_res_padding.origin().x(), |
| 111 -shadow_res_padding.origin().y()); | 126 -shadow_res_padding.origin().y()); |
| 112 panel_shadow_->SetPosition(shadow_position); | 127 panel_shadow_->SetPosition(shadow_position); |
| 113 | 128 |
| 114 // --------------------------------------------------------------------------- | 129 // --------------------------------------------------------------------------- |
| 130 // Peek Promo |
| 131 // --------------------------------------------------------------------------- |
| 132 if (search_peek_promo_visible) { |
| 133 // Grabs the Search Opt Out Promo resource. |
| 134 ui::ResourceManager::Resource* peek_promo_text_resource = |
| 135 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 136 peek_promo_text_resource_id); |
| 137 |
| 138 ui::ResourceManager::Resource* peek_promo_ripple_resource = |
| 139 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 140 peek_promo_ripple_resource_id); |
| 141 |
| 142 // ----------------------------------------------------------------- |
| 143 // Peek Promo Container |
| 144 // ----------------------------------------------------------------- |
| 145 if (peek_promo_container_->parent() != layer_) { |
| 146 layer_->AddChild(peek_promo_container_); |
| 147 } |
| 148 |
| 149 gfx::Size peek_promo_size(search_panel_width, search_peek_promo_height); |
| 150 peek_promo_container_->SetBounds(peek_promo_size); |
| 151 peek_promo_container_->SetPosition(gfx::PointF(0.f, 0.f)); |
| 152 peek_promo_container_->SetMasksToBounds(true); |
| 153 |
| 154 // Apply a blend based on the ripple opacity. The resulting color will |
| 155 // be an interpolation between the background color of the Search Bar and |
| 156 // a lighter shade of the background color of the Ripple. The range of |
| 157 // the alpha value used in the blend will be: |
| 158 // [0.f, kPeekPromoBackgroundMaximumAlphaBlend] |
| 159 peek_promo_container_->SetBackgroundColor( |
| 160 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor, |
| 161 kSearchBarBackgroundColor, |
| 162 kPeekPromoBackgroundMaximumAlphaBlend * |
| 163 search_peek_promo_ripple_opacity |
| 164 )); |
| 165 |
| 166 // ----------------------------------------------------------------- |
| 167 // Peek Promo Ripple |
| 168 // ----------------------------------------------------------------- |
| 169 gfx::Size peek_promo_ripple_size( |
| 170 search_peek_promo_ripple_width, search_peek_promo_height); |
| 171 gfx::Rect peek_promo_ripple_border( |
| 172 peek_promo_ripple_resource->Border(peek_promo_ripple_size)); |
| 173 |
| 174 // Add padding so the ripple will occupy the whole width at 100%. |
| 175 peek_promo_ripple_size.set_width( |
| 176 peek_promo_ripple_size.width() + peek_promo_ripple_border.width()); |
| 177 |
| 178 float ripple_rotation = 0.f; |
| 179 float ripple_left = 0.f; |
| 180 if (is_rtl) { |
| 181 // Rotate the ripple 180 degrees to make it point to the left side. |
| 182 ripple_rotation = 180.f; |
| 183 ripple_left = search_panel_width - peek_promo_ripple_size.width(); |
| 184 } |
| 185 |
| 186 peek_promo_ripple_->SetUIResourceId( |
| 187 peek_promo_ripple_resource->ui_resource->id()); |
| 188 peek_promo_ripple_->SetBorder(peek_promo_ripple_border); |
| 189 peek_promo_ripple_->SetAperture(peek_promo_ripple_resource->aperture); |
| 190 peek_promo_ripple_->SetBounds(peek_promo_ripple_size); |
| 191 peek_promo_ripple_->SetPosition(gfx::PointF(ripple_left, 0.f)); |
| 192 peek_promo_ripple_->SetOpacity(search_peek_promo_ripple_opacity); |
| 193 |
| 194 if (ripple_rotation != 0.f) { |
| 195 // Apply rotation about the center of the resource. |
| 196 float pivot_x = floor(peek_promo_ripple_size.width() / 2); |
| 197 float pivot_y = floor(peek_promo_ripple_size.height() / 2); |
| 198 gfx::PointF pivot_origin(pivot_x, pivot_y); |
| 199 gfx::Transform transform; |
| 200 transform.Translate(pivot_origin.x(), pivot_origin.y()); |
| 201 transform.RotateAboutZAxis(ripple_rotation); |
| 202 transform.Translate(-pivot_origin.x(), -pivot_origin.y()); |
| 203 peek_promo_ripple_->SetTransform(transform); |
| 204 } |
| 205 |
| 206 // ----------------------------------------------------------------- |
| 207 // Peek Promo Text |
| 208 // ----------------------------------------------------------------- |
| 209 if (peek_promo_text_resource) { |
| 210 peek_promo_text_->SetUIResourceId( |
| 211 peek_promo_text_resource->ui_resource->id()); |
| 212 peek_promo_text_->SetBounds(peek_promo_text_resource->size); |
| 213 peek_promo_text_->SetPosition( |
| 214 gfx::PointF(0.f, search_peek_promo_padding)); |
| 215 peek_promo_text_->SetOpacity(search_peek_promo_text_opacity); |
| 216 } |
| 217 } else { |
| 218 // Peek Promo Container |
| 219 if (peek_promo_container_.get() && peek_promo_container_->parent()) |
| 220 peek_promo_container_->RemoveFromParent(); |
| 221 } |
| 222 |
| 223 // --------------------------------------------------------------------------- |
| 115 // Search Bar Background | 224 // Search Bar Background |
| 116 // --------------------------------------------------------------------------- | 225 // --------------------------------------------------------------------------- |
| 117 gfx::Size background_size(search_panel_width, search_bar_height); | 226 gfx::Size background_size(search_panel_width, search_bar_height); |
| 118 search_bar_background_->SetBounds(background_size); | 227 search_bar_background_->SetBounds(background_size); |
| 119 search_bar_background_->SetPosition(gfx::PointF(0.f, 0.f)); | 228 search_bar_background_->SetPosition(gfx::PointF(0.f, search_bar_top)); |
| 120 | 229 |
| 121 // --------------------------------------------------------------------------- | 230 // --------------------------------------------------------------------------- |
| 122 // Search Bar Text | 231 // Search Bar Text |
| 123 // --------------------------------------------------------------------------- | 232 // --------------------------------------------------------------------------- |
| 124 if (search_context_resource) { | 233 if (search_context_resource) { |
| 125 // Centers the text vertically in the Search Bar. | 234 // Centers the text vertically in the Search Bar. |
| 126 float search_bar_padding_top = | 235 float search_bar_padding_top = |
| 236 search_bar_top + |
| 127 search_bar_height / 2 - | 237 search_bar_height / 2 - |
| 128 search_context_resource->size.height() / 2; | 238 search_context_resource->size.height() / 2; |
| 129 search_context_->SetUIResourceId( | 239 search_context_->SetUIResourceId( |
| 130 search_context_resource->ui_resource->id()); | 240 search_context_resource->ui_resource->id()); |
| 131 search_context_->SetBounds(search_context_resource->size); | 241 search_context_->SetBounds(search_context_resource->size); |
| 132 search_context_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 242 search_context_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
| 133 search_context_->SetOpacity(search_context_opacity); | 243 search_context_->SetOpacity(search_context_opacity); |
| 134 } | 244 } |
| 135 | 245 |
| 136 if (search_term_resource) { | 246 if (search_term_resource) { |
| 137 // Centers the text vertically in the Search Bar. | 247 // Centers the text vertically in the Search Bar. |
| 138 float search_bar_padding_top = | 248 float search_bar_padding_top = |
| 249 search_bar_top + |
| 139 search_bar_height / 2 - | 250 search_bar_height / 2 - |
| 140 search_term_resource->size.height() / 2; | 251 search_term_resource->size.height() / 2; |
| 141 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); | 252 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); |
| 142 search_term_->SetBounds(search_term_resource->size); | 253 search_term_->SetBounds(search_term_resource->size); |
| 143 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); | 254 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); |
| 144 search_term_->SetOpacity(search_term_opacity); | 255 search_term_->SetOpacity(search_term_opacity); |
| 145 } | 256 } |
| 146 | 257 |
| 147 // --------------------------------------------------------------------------- | 258 // --------------------------------------------------------------------------- |
| 148 // Search Provider Icon | 259 // Search Provider Icon |
| 149 // --------------------------------------------------------------------------- | 260 // --------------------------------------------------------------------------- |
| 150 // Positions the Search Provider Icon at the start of the Search Bar. | 261 // Positions the Search Provider Icon at the start of the Search Bar. |
| 151 float search_provider_icon_left; | 262 float search_provider_icon_left; |
| 152 if (is_rtl) { | 263 if (is_rtl) { |
| 153 search_provider_icon_left = search_panel_width - | 264 search_provider_icon_left = search_panel_width - |
| 154 search_provider_icon_resource->size.width() - search_bar_margin_side; | 265 search_provider_icon_resource->size.width() - search_bar_margin_side; |
| 155 } else { | 266 } else { |
| 156 search_provider_icon_left = search_bar_margin_side; | 267 search_provider_icon_left = search_bar_margin_side; |
| 157 } | 268 } |
| 158 | 269 |
| 159 // Centers the Search Provider Icon vertically in the Search Bar. | 270 // Centers the Search Provider Icon vertically in the Search Bar. |
| 160 float search_provider_icon_top = | 271 float search_provider_icon_top = search_bar_top + |
| 161 search_bar_height / 2 - | 272 search_bar_height / 2 - |
| 162 search_provider_icon_resource->size.height() / 2; | 273 search_provider_icon_resource->size.height() / 2; |
| 163 | 274 |
| 164 search_provider_icon_->SetUIResourceId( | 275 search_provider_icon_->SetUIResourceId( |
| 165 search_provider_icon_resource->ui_resource->id()); | 276 search_provider_icon_resource->ui_resource->id()); |
| 166 search_provider_icon_->SetBounds(search_provider_icon_resource->size); | 277 search_provider_icon_->SetBounds(search_provider_icon_resource->size); |
| 167 search_provider_icon_->SetPosition( | 278 search_provider_icon_->SetPosition( |
| 168 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); | 279 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); |
| 169 | 280 |
| 170 // --------------------------------------------------------------------------- | 281 // --------------------------------------------------------------------------- |
| 171 // Arrow Icon | 282 // Arrow Icon |
| 172 // --------------------------------------------------------------------------- | 283 // --------------------------------------------------------------------------- |
| 173 // Grabs the Search Arrow Icon resource. | 284 // Grabs the Search Arrow Icon resource. |
| 174 ui::ResourceManager::Resource* arrow_icon_resource = | 285 ui::ResourceManager::Resource* arrow_icon_resource = |
| 175 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 286 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 176 arrow_up_resource_id); | 287 arrow_up_resource_id); |
| 177 | 288 |
| 178 // Positions the icon at the end of the Search Bar. | 289 // Positions the icon at the end of the Search Bar. |
| 179 float arrow_icon_left; | 290 float arrow_icon_left; |
| 180 if (is_rtl) { | 291 if (is_rtl) { |
| 181 arrow_icon_left = search_bar_margin_side; | 292 arrow_icon_left = search_bar_margin_side; |
| 182 } else { | 293 } else { |
| 183 arrow_icon_left = search_panel_width - | 294 arrow_icon_left = search_panel_width - |
| 184 arrow_icon_resource->size.width() - search_bar_margin_side; | 295 arrow_icon_resource->size.width() - search_bar_margin_side; |
| 185 } | 296 } |
| 186 | 297 |
| 187 // Centers the Arrow Icon vertically in the Search Bar. | 298 // Centers the Arrow Icon vertically in the Search Bar. |
| 188 float arrow_icon_top = search_bar_height / 2 - | 299 float arrow_icon_top = search_bar_top + |
| 300 search_bar_height / 2 - |
| 189 arrow_icon_resource->size.height() / 2; | 301 arrow_icon_resource->size.height() / 2; |
| 190 | 302 |
| 191 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource->id()); | 303 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource->id()); |
| 192 arrow_icon_->SetBounds(arrow_icon_resource->size); | 304 arrow_icon_->SetBounds(arrow_icon_resource->size); |
| 193 arrow_icon_->SetPosition( | 305 arrow_icon_->SetPosition( |
| 194 gfx::PointF(arrow_icon_left, arrow_icon_top)); | 306 gfx::PointF(arrow_icon_left, arrow_icon_top)); |
| 195 arrow_icon_->SetOpacity(arrow_icon_opacity); | 307 arrow_icon_->SetOpacity(arrow_icon_opacity); |
| 196 | 308 |
| 197 gfx::Transform transform; | 309 gfx::Transform transform; |
| 198 if (arrow_icon_rotation != 0.f) { | 310 if (arrow_icon_rotation != 0.f) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 218 float close_icon_left; | 330 float close_icon_left; |
| 219 if (is_rtl) { | 331 if (is_rtl) { |
| 220 close_icon_left = search_bar_margin_side; | 332 close_icon_left = search_bar_margin_side; |
| 221 } else { | 333 } else { |
| 222 close_icon_left = search_panel_width - | 334 close_icon_left = search_panel_width - |
| 223 close_icon_resource->size.width() - search_bar_margin_side; | 335 close_icon_resource->size.width() - search_bar_margin_side; |
| 224 } | 336 } |
| 225 | 337 |
| 226 // Centers the Close Icon vertically in the Search Bar. | 338 // Centers the Close Icon vertically in the Search Bar. |
| 227 float close_icon_top = | 339 float close_icon_top = |
| 340 search_bar_top + |
| 228 search_bar_height / 2 - | 341 search_bar_height / 2 - |
| 229 close_icon_resource->size.height() / 2; | 342 close_icon_resource->size.height() / 2; |
| 230 | 343 |
| 231 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); | 344 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); |
| 232 close_icon_->SetBounds(close_icon_resource->size); | 345 close_icon_->SetBounds(close_icon_resource->size); |
| 233 close_icon_->SetPosition( | 346 close_icon_->SetPosition( |
| 234 gfx::PointF(close_icon_left, close_icon_top)); | 347 gfx::PointF(close_icon_left, close_icon_top)); |
| 235 close_icon_->SetOpacity(close_icon_opacity); | 348 close_icon_->SetOpacity(close_icon_opacity); |
| 236 | 349 |
| 237 // --------------------------------------------------------------------------- | 350 // --------------------------------------------------------------------------- |
| 238 // Search Promo | 351 // Search Promo |
| 239 // --------------------------------------------------------------------------- | 352 // --------------------------------------------------------------------------- |
| 240 if (search_promo_visible) { | 353 if (search_promo_visible) { |
| 241 // Grabs the Search Opt Out Promo resource. | 354 // Grabs the Search Opt Out Promo resource. |
| 242 ui::ResourceManager::Resource* search_promo_resource = | 355 ui::ResourceManager::Resource* search_promo_resource = |
| 243 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 356 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 244 search_promo_resource_id); | 357 search_promo_resource_id); |
| 245 // Search Promo Container | 358 // Search Promo Container |
| 246 if (search_promo_container_->parent() != layer_) { | 359 if (search_promo_container_->parent() != layer_) { |
| 247 // NOTE(pedrosimonetti): The Promo layer should be always placed before | 360 // NOTE(pedrosimonetti): The Promo layer should be always placed before |
| 248 // Search Bar Shadow to make sure it won't occlude the shadow. | 361 // Search Bar Shadow to make sure it won't occlude the shadow. |
| 249 layer_->InsertChild(search_promo_container_, 0); | 362 layer_->InsertChild(search_promo_container_, 0); |
| 250 } | 363 } |
| 251 | 364 |
| 252 if (search_promo_resource) { | 365 if (search_promo_resource) { |
| 253 int search_promo_content_height = search_promo_resource->size.height(); | 366 int search_promo_content_height = search_promo_resource->size.height(); |
| 254 gfx::Size search_promo_size(search_panel_width, search_promo_height); | 367 gfx::Size search_promo_size(search_panel_width, search_promo_height); |
| 255 search_promo_container_->SetBounds(search_promo_size); | 368 search_promo_container_->SetBounds(search_promo_size); |
| 256 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); | 369 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_bottom)); |
| 257 search_promo_container_->SetMasksToBounds(true); | 370 search_promo_container_->SetMasksToBounds(true); |
| 258 | 371 |
| 259 // Search Promo | 372 // Search Promo |
| 260 if (search_promo_->parent() != search_promo_container_) | 373 if (search_promo_->parent() != search_promo_container_) |
| 261 search_promo_container_->AddChild(search_promo_); | 374 search_promo_container_->AddChild(search_promo_); |
| 262 | 375 |
| 263 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id()); | 376 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id()); |
| 264 search_promo_->SetBounds(search_promo_resource->size); | 377 search_promo_->SetBounds(search_promo_resource->size); |
| 265 // Align promo at the bottom of the container so the confirmation button | 378 // Align promo at the bottom of the container so the confirmation button |
| 266 // is is not clipped when resizing the promo. | 379 // is is not clipped when resizing the promo. |
| 267 search_promo_->SetPosition( | 380 search_promo_->SetPosition( |
| 268 gfx::PointF(0.f, search_promo_height - search_promo_content_height)); | 381 gfx::PointF(0.f, search_promo_height - search_promo_content_height)); |
| 269 search_promo_->SetOpacity(search_promo_opacity); | 382 search_promo_->SetOpacity(search_promo_opacity); |
| 270 } | 383 } |
| 271 } else { | 384 } else { |
| 272 // Search Promo Container | 385 // Search Promo Container |
| 273 if (search_promo_container_.get() && search_promo_container_->parent()) | 386 if (search_promo_container_.get() && search_promo_container_->parent()) |
| 274 search_promo_container_->RemoveFromParent(); | 387 search_promo_container_->RemoveFromParent(); |
| 275 } | 388 } |
| 276 | 389 |
| 277 // --------------------------------------------------------------------------- | 390 // --------------------------------------------------------------------------- |
| 278 // Search Content View | 391 // Search Content View |
| 279 // --------------------------------------------------------------------------- | 392 // --------------------------------------------------------------------------- |
| 280 content_view_container_->SetPosition( | 393 content_view_container_->SetPosition( |
| 281 gfx::PointF(0.f, search_bar_height + search_promo_height)); | 394 gfx::PointF(0.f, search_bar_bottom + search_promo_height)); |
| 282 if (content_view_core && content_view_core->GetLayer().get()) { | 395 if (content_view_core && content_view_core->GetLayer().get()) { |
| 283 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); | 396 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); |
| 284 if (content_view_layer->parent() != content_view_container_) | 397 if (content_view_layer->parent() != content_view_container_) |
| 285 content_view_container_->AddChild(content_view_layer); | 398 content_view_container_->AddChild(content_view_layer); |
| 286 } else { | 399 } else { |
| 287 content_view_container_->RemoveAllChildren(); | 400 content_view_container_->RemoveAllChildren(); |
| 288 } | 401 } |
| 289 | 402 |
| 290 // --------------------------------------------------------------------------- | 403 // --------------------------------------------------------------------------- |
| 291 // Search Bar Shadow | 404 // Search Bar Shadow |
| 292 // --------------------------------------------------------------------------- | 405 // --------------------------------------------------------------------------- |
| 293 if (search_bar_shadow_visible) { | 406 if (search_bar_shadow_visible) { |
| 294 ui::ResourceManager::Resource* search_bar_shadow_resource = | 407 ui::ResourceManager::Resource* search_bar_shadow_resource = |
| 295 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 408 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 296 search_bar_shadow_resource_id); | 409 search_bar_shadow_resource_id); |
| 297 | 410 |
| 298 if (search_bar_shadow_resource) { | 411 if (search_bar_shadow_resource) { |
| 299 if (search_bar_shadow_->parent() != layer_) | 412 if (search_bar_shadow_->parent() != layer_) |
| 300 layer_->AddChild(search_bar_shadow_); | 413 layer_->AddChild(search_bar_shadow_); |
| 301 | 414 |
| 302 int shadow_height = search_bar_shadow_resource->size.height(); | 415 int shadow_height = search_bar_shadow_resource->size.height(); |
| 303 gfx::Size shadow_size(search_panel_width, shadow_height); | 416 gfx::Size shadow_size(search_panel_width, shadow_height); |
| 304 | 417 |
| 305 search_bar_shadow_->SetUIResourceId( | 418 search_bar_shadow_->SetUIResourceId( |
| 306 search_bar_shadow_resource->ui_resource->id()); | 419 search_bar_shadow_resource->ui_resource->id()); |
| 307 search_bar_shadow_->SetBounds(shadow_size); | 420 search_bar_shadow_->SetBounds(shadow_size); |
| 308 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_height)); | 421 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_bottom)); |
| 309 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity); | 422 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity); |
| 310 } | 423 } |
| 311 } else { | 424 } else { |
| 312 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) | 425 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) |
| 313 search_bar_shadow_->RemoveFromParent(); | 426 search_bar_shadow_->RemoveFromParent(); |
| 314 } | 427 } |
| 315 | 428 |
| 316 // --------------------------------------------------------------------------- | 429 // --------------------------------------------------------------------------- |
| 317 // Search Panel. | 430 // Search Panel. |
| 318 // --------------------------------------------------------------------------- | 431 // --------------------------------------------------------------------------- |
| 319 layer_->SetPosition(gfx::PointF(search_panel_x, search_panel_y)); | 432 layer_->SetPosition( |
| 433 gfx::PointF(search_panel_x, search_panel_y)); |
| 320 | 434 |
| 321 // --------------------------------------------------------------------------- | 435 // --------------------------------------------------------------------------- |
| 322 // Progress Bar | 436 // Progress Bar |
| 323 // --------------------------------------------------------------------------- | 437 // --------------------------------------------------------------------------- |
| 324 bool should_render_progress_bar = | 438 bool should_render_progress_bar = |
| 325 progress_bar_visible && progress_bar_opacity > 0.f; | 439 progress_bar_visible && progress_bar_opacity > 0.f; |
| 326 if (should_render_progress_bar) { | 440 if (should_render_progress_bar) { |
| 327 // Grabs Progress Bar resources. | 441 // Grabs Progress Bar resources. |
| 328 ui::ResourceManager::Resource* progress_bar_background_resource = | 442 ui::ResourceManager::Resource* progress_bar_background_resource = |
| 329 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 443 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 330 progress_bar_background_resource_id); | 444 progress_bar_background_resource_id); |
| 331 ui::ResourceManager::Resource* progress_bar_resource = | 445 ui::ResourceManager::Resource* progress_bar_resource = |
| 332 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 446 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 333 progress_bar_resource_id); | 447 progress_bar_resource_id); |
| 334 | 448 |
| 335 DCHECK(progress_bar_background_resource); | 449 DCHECK(progress_bar_background_resource); |
| 336 DCHECK(progress_bar_resource); | 450 DCHECK(progress_bar_resource); |
| 337 | 451 |
| 338 // Progress Bar Background | 452 // Progress Bar Background |
| 339 if (progress_bar_background_->parent() != layer_) | 453 if (progress_bar_background_->parent() != layer_) |
| 340 layer_->AddChild(progress_bar_background_); | 454 layer_->AddChild(progress_bar_background_); |
| 341 | 455 |
| 456 float progress_bar_y = search_bar_bottom - progress_bar_height; |
| 342 gfx::Size progress_bar_background_size(search_panel_width, | 457 gfx::Size progress_bar_background_size(search_panel_width, |
| 343 progress_bar_height); | 458 progress_bar_height); |
| 459 |
| 344 progress_bar_background_->SetUIResourceId( | 460 progress_bar_background_->SetUIResourceId( |
| 345 progress_bar_background_resource->ui_resource->id()); | 461 progress_bar_background_resource->ui_resource->id()); |
| 346 progress_bar_background_->SetBorder( | 462 progress_bar_background_->SetBorder( |
| 347 progress_bar_background_resource->Border(progress_bar_background_size)); | 463 progress_bar_background_resource->Border(progress_bar_background_size)); |
| 348 progress_bar_background_->SetAperture( | 464 progress_bar_background_->SetAperture( |
| 349 progress_bar_background_resource->aperture); | 465 progress_bar_background_resource->aperture); |
| 350 progress_bar_background_->SetBounds(progress_bar_background_size); | 466 progress_bar_background_->SetBounds(progress_bar_background_size); |
| 351 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y)); | 467 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y)); |
| 352 progress_bar_background_->SetOpacity(progress_bar_opacity); | 468 progress_bar_background_->SetOpacity(progress_bar_opacity); |
| 353 | 469 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 372 if (progress_bar_.get() && progress_bar_->parent()) | 488 if (progress_bar_.get() && progress_bar_->parent()) |
| 373 progress_bar_->RemoveFromParent(); | 489 progress_bar_->RemoveFromParent(); |
| 374 } | 490 } |
| 375 | 491 |
| 376 // --------------------------------------------------------------------------- | 492 // --------------------------------------------------------------------------- |
| 377 // Search Bar border. | 493 // Search Bar border. |
| 378 // --------------------------------------------------------------------------- | 494 // --------------------------------------------------------------------------- |
| 379 if (!should_render_progress_bar && search_bar_border_visible) { | 495 if (!should_render_progress_bar && search_bar_border_visible) { |
| 380 gfx::Size search_bar_border_size(search_panel_width, | 496 gfx::Size search_bar_border_size(search_panel_width, |
| 381 search_bar_border_height); | 497 search_bar_border_height); |
| 498 float border_y = search_bar_bottom - search_bar_border_height; |
| 382 search_bar_border_->SetBounds(search_bar_border_size); | 499 search_bar_border_->SetBounds(search_bar_border_size); |
| 383 search_bar_border_->SetPosition(gfx::PointF(0.f, search_bar_border_y)); | 500 search_bar_border_->SetPosition( |
| 501 gfx::PointF(0.f, border_y)); |
| 384 layer_->AddChild(search_bar_border_); | 502 layer_->AddChild(search_bar_border_); |
| 385 } else if (search_bar_border_.get() && search_bar_border_->parent()) { | 503 } else if (search_bar_border_.get() && search_bar_border_->parent()) { |
| 386 search_bar_border_->RemoveFromParent(); | 504 search_bar_border_->RemoveFromParent(); |
| 387 } | 505 } |
| 388 } | 506 } |
| 389 | 507 |
| 390 ContextualSearchLayer::ContextualSearchLayer( | 508 ContextualSearchLayer::ContextualSearchLayer( |
| 391 ui::ResourceManager* resource_manager) | 509 ui::ResourceManager* resource_manager) |
| 392 : resource_manager_(resource_manager), | 510 : resource_manager_(resource_manager), |
| 393 layer_(cc::Layer::Create(content::Compositor::LayerSettings())), | 511 layer_(cc::Layer::Create(content::Compositor::LayerSettings())), |
| (...skipping 17 matching lines...) Expand all Loading... |
| 411 cc::Layer::Create(content::Compositor::LayerSettings())), | 529 cc::Layer::Create(content::Compositor::LayerSettings())), |
| 412 search_bar_border_( | 530 search_bar_border_( |
| 413 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 531 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 414 progress_bar_( | 532 progress_bar_( |
| 415 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 533 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 416 progress_bar_background_( | 534 progress_bar_background_( |
| 417 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), | 535 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 418 search_promo_( | 536 search_promo_( |
| 419 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 537 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 420 search_promo_container_( | 538 search_promo_container_( |
| 421 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())) { | 539 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 540 peek_promo_container_( |
| 541 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 542 peek_promo_ripple_( |
| 543 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 544 peek_promo_text_( |
| 545 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())) { |
| 422 layer_->SetMasksToBounds(false); | 546 layer_->SetMasksToBounds(false); |
| 423 layer_->SetIsDrawable(true); | 547 layer_->SetIsDrawable(true); |
| 424 | 548 |
| 425 // Panel Shadow | 549 // Panel Shadow |
| 426 panel_shadow_->SetIsDrawable(true); | 550 panel_shadow_->SetIsDrawable(true); |
| 427 panel_shadow_->SetFillCenter(false); | 551 panel_shadow_->SetFillCenter(false); |
| 428 layer_->AddChild(panel_shadow_); | 552 layer_->AddChild(panel_shadow_); |
| 429 | 553 |
| 554 // Search Peek Promo |
| 555 peek_promo_container_->SetIsDrawable(true); |
| 556 peek_promo_container_->SetBackgroundColor(kSearchBarBackgroundColor); |
| 557 peek_promo_ripple_->SetIsDrawable(true); |
| 558 peek_promo_ripple_->SetFillCenter(true); |
| 559 peek_promo_text_->SetIsDrawable(true); |
| 560 peek_promo_container_->AddChild(peek_promo_ripple_); |
| 561 peek_promo_container_->AddChild(peek_promo_text_); |
| 562 |
| 430 // Search Bar Background | 563 // Search Bar Background |
| 431 search_bar_background_->SetIsDrawable(true); | 564 search_bar_background_->SetIsDrawable(true); |
| 432 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); | 565 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); |
| 433 layer_->AddChild(search_bar_background_); | 566 layer_->AddChild(search_bar_background_); |
| 434 | 567 |
| 435 // Search Bar Text | 568 // Search Bar Text |
| 436 search_context_->SetIsDrawable(true); | 569 search_context_->SetIsDrawable(true); |
| 437 layer_->AddChild(search_context_); | 570 layer_->AddChild(search_context_); |
| 438 search_term_->SetIsDrawable(true); | 571 search_term_->SetIsDrawable(true); |
| 439 layer_->AddChild(search_term_); | 572 layer_->AddChild(search_term_); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 476 | 609 |
| 477 ContextualSearchLayer::~ContextualSearchLayer() { | 610 ContextualSearchLayer::~ContextualSearchLayer() { |
| 478 } | 611 } |
| 479 | 612 |
| 480 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { | 613 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { |
| 481 return layer_; | 614 return layer_; |
| 482 } | 615 } |
| 483 | 616 |
| 484 } // namespace android | 617 } // namespace android |
| 485 } // namespace chrome | 618 } // namespace chrome |
| OLD | NEW |