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