Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/overlay_panel_layer.h" | 5 #include "chrome/browser/android/compositor/layer/overlay_panel_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 29 matching lines...) Expand all Loading... | |
| 40 panel_icon_->SetUIResourceId(panel_icon_resource->ui_resource()->id()); | 40 panel_icon_->SetUIResourceId(panel_icon_resource->ui_resource()->id()); |
| 41 panel_icon_->SetBounds(panel_icon_resource->size()); | 41 panel_icon_->SetBounds(panel_icon_resource->size()); |
| 42 | 42 |
| 43 return panel_icon_; | 43 return panel_icon_; |
| 44 } | 44 } |
| 45 | 45 |
| 46 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) { | 46 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) { |
| 47 text_container_->AddChild(text_layer); | 47 text_container_->AddChild(text_layer); |
| 48 } | 48 } |
| 49 | 49 |
| 50 void OverlayPanelLayer::SetResourceIds( | 50 void OverlayPanelLayer::SetResourceIds(int bar_text_resource_id, |
| 51 int bar_text_resource_id, | 51 int panel_shadow_resource_id, |
| 52 int panel_shadow_resource_id, | 52 int bar_shadow_resource_id, |
| 53 int bar_shadow_resource_id, | 53 int panel_icon_resource_id, |
| 54 int panel_icon_resource_id, | 54 int close_icon_resource_id, |
| 55 int close_icon_resource_id) { | 55 int handle_resource_id) { |
| 56 bar_text_resource_id_ = bar_text_resource_id; | 56 bar_text_resource_id_ = bar_text_resource_id; |
| 57 panel_shadow_resource_id_ = panel_shadow_resource_id; | 57 panel_shadow_resource_id_ = panel_shadow_resource_id; |
| 58 bar_shadow_resource_id_ = bar_shadow_resource_id; | 58 bar_shadow_resource_id_ = bar_shadow_resource_id; |
| 59 panel_icon_resource_id_ = panel_icon_resource_id; | 59 panel_icon_resource_id_ = panel_icon_resource_id; |
| 60 close_icon_resource_id_ = close_icon_resource_id; | 60 close_icon_resource_id_ = close_icon_resource_id; |
| 61 bar_handle_resource_id_ = handle_resource_id; | |
| 61 } | 62 } |
| 62 | 63 |
| 63 void OverlayPanelLayer::SetProperties( | 64 void OverlayPanelLayer::SetProperties( |
| 64 float dp_to_px, | 65 float dp_to_px, |
| 65 const scoped_refptr<cc::Layer>& content_layer, | 66 const scoped_refptr<cc::Layer>& content_layer, |
| 66 float content_offset_y, | 67 float content_offset_y, |
| 67 float panel_x, | 68 float panel_x, |
| 68 float panel_y, | 69 float panel_y, |
| 69 float panel_width, | 70 float panel_width, |
| 70 float panel_height, | 71 float panel_height, |
| 71 float bar_margin_side, | 72 float bar_margin_side, |
| 72 float bar_height, | 73 float bar_height, |
| 73 float bar_offset_y, | 74 float bar_offset_y, |
| 74 float bar_text_opacity, | 75 float bar_text_opacity, |
| 75 bool bar_border_visible, | 76 bool bar_border_visible, |
| 76 float bar_border_height, | 77 float bar_border_height, |
| 77 bool bar_shadow_visible, | 78 bool bar_shadow_visible, |
| 78 float bar_shadow_opacity, | 79 float bar_shadow_opacity, |
| 79 float close_icon_opacity) { | 80 float close_icon_opacity, |
| 80 | 81 float bar_handle_offset_y, |
| 82 float bar_padding_bottom) { | |
| 81 // Grabs required static resources. | 83 // Grabs required static resources. |
| 82 ui::NinePatchResource* panel_shadow_resource = | 84 ui::NinePatchResource* panel_shadow_resource = |
| 83 ui::NinePatchResource::From(resource_manager_->GetResource( | 85 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 84 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_shadow_resource_id_)); | 86 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_shadow_resource_id_)); |
| 85 | 87 |
| 86 DCHECK(panel_shadow_resource); | 88 DCHECK(panel_shadow_resource); |
| 87 | 89 |
| 88 // Round values to avoid pixel gap between layers. | 90 // Round values to avoid pixel gap between layers. |
| 89 bar_height = floor(bar_height); | 91 bar_height = floor(bar_height); |
| 90 | 92 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 112 panel_shadow_->SetPosition(shadow_position); | 114 panel_shadow_->SetPosition(shadow_position); |
| 113 | 115 |
| 114 // --------------------------------------------------------------------------- | 116 // --------------------------------------------------------------------------- |
| 115 // Bar Background | 117 // Bar Background |
| 116 // --------------------------------------------------------------------------- | 118 // --------------------------------------------------------------------------- |
| 117 gfx::Size background_size(panel_width, bar_height); | 119 gfx::Size background_size(panel_width, bar_height); |
| 118 bar_background_->SetBounds(background_size); | 120 bar_background_->SetBounds(background_size); |
| 119 bar_background_->SetPosition(gfx::PointF(0.f, bar_top)); | 121 bar_background_->SetPosition(gfx::PointF(0.f, bar_top)); |
| 120 | 122 |
| 121 // --------------------------------------------------------------------------- | 123 // --------------------------------------------------------------------------- |
| 124 // Bar Handle | |
| 125 // --------------------------------------------------------------------------- | |
| 126 | |
| 127 float bar_content_top = bar_top; | |
| 128 bar_content_height_ = bar_height - bar_padding_bottom; | |
| 129 | |
| 130 if (bar_handle_resource_id_ != 0) { | |
|
mdjones
2017/04/07 15:47:13
Do you think it makes sense to lazily create the l
Theresa
2017/04/07 16:26:43
Done.
| |
| 131 if (bar_handle_->parent() != layer_) | |
| 132 layer_->AddChild(bar_handle_); | |
| 133 | |
| 134 // Grab the bar handle resource. | |
| 135 ui::Resource* bar_handle_resource = resource_manager_->GetResource( | |
| 136 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_handle_resource_id_); | |
| 137 | |
| 138 // Center the handle horizontally. | |
| 139 float bar_handle_left = | |
| 140 (panel_width - bar_handle_resource->size().width()) / 2; | |
| 141 float bar_handle_top = bar_top + bar_handle_offset_y; | |
| 142 | |
| 143 bar_handle_->SetUIResourceId(bar_handle_resource->ui_resource()->id()); | |
| 144 bar_handle_->SetBounds(bar_handle_resource->size()); | |
| 145 bar_handle_->SetPosition(gfx::PointF(bar_handle_left, bar_handle_top)); | |
| 146 | |
| 147 bar_content_top = bar_handle_top + bar_handle_resource->size().height(); | |
| 148 bar_content_height_ = bar_height - bar_content_top - bar_padding_bottom; | |
| 149 } | |
| 150 | |
| 151 // --------------------------------------------------------------------------- | |
| 152 // Bar Content Layer | |
| 153 // --------------------------------------------------------------------------- | |
| 154 bar_content_layer_->SetBounds(gfx::Size(panel_width, bar_content_height_)); | |
| 155 bar_content_layer_->SetPosition(gfx::PointF(0.f, bar_content_top)); | |
| 156 | |
| 157 // --------------------------------------------------------------------------- | |
| 122 // Bar Text | 158 // Bar Text |
| 123 // --------------------------------------------------------------------------- | 159 // --------------------------------------------------------------------------- |
| 124 ui::Resource* bar_text_resource = resource_manager_->GetResource( | 160 ui::Resource* bar_text_resource = resource_manager_->GetResource( |
| 125 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_); | 161 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_); |
| 126 | 162 |
| 127 if (bar_text_resource) { | 163 if (bar_text_resource) { |
| 128 // Centers the text vertically in the Search Bar. | 164 // Centers the text vertically in the Search Bar. |
| 129 float bar_padding_top = | 165 float bar_padding_top = |
| 130 bar_top + bar_height / 2 - bar_text_resource->size().height() / 2; | 166 (bar_content_height_ - bar_text_resource->size().height()) / 2; |
| 131 bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id()); | 167 bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id()); |
| 132 bar_text_->SetBounds(bar_text_resource->size()); | 168 bar_text_->SetBounds(bar_text_resource->size()); |
| 133 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); | 169 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); |
| 134 bar_text_->SetOpacity(bar_text_opacity); | 170 bar_text_->SetOpacity(bar_text_opacity); |
| 135 } | 171 } |
| 136 | 172 |
| 137 // --------------------------------------------------------------------------- | 173 // --------------------------------------------------------------------------- |
| 138 // Panel Icon | 174 // Panel Icon |
| 139 // --------------------------------------------------------------------------- | 175 // --------------------------------------------------------------------------- |
| 140 scoped_refptr<cc::Layer> icon_layer = GetIconLayer(); | 176 scoped_refptr<cc::Layer> icon_layer = GetIconLayer(); |
| 141 if (icon_layer) { | 177 if (icon_layer) { |
| 142 // If the icon is not the default width, add or remove padding so it appears | 178 // If the icon is not the default width, add or remove padding so it appears |
| 143 // centered. | 179 // centered. |
| 144 float icon_padding = (kDefaultIconWidthDp * dp_to_px - | 180 float icon_padding = (kDefaultIconWidthDp * dp_to_px - |
| 145 icon_layer->bounds().width()) / 2.0f; | 181 icon_layer->bounds().width()) / 2.0f; |
| 146 | 182 |
| 147 // Positions the Icon at the start of the bar. | 183 // Positions the Icon at the start of the bar. |
| 148 float icon_x; | 184 float icon_x; |
| 149 if (is_rtl) { | 185 if (is_rtl) { |
| 150 icon_x = panel_width - icon_layer->bounds().width() - | 186 icon_x = panel_width - icon_layer->bounds().width() - |
| 151 (bar_margin_side + icon_padding); | 187 (bar_margin_side + icon_padding); |
| 152 } else { | 188 } else { |
| 153 icon_x = bar_margin_side + icon_padding; | 189 icon_x = bar_margin_side + icon_padding; |
| 154 } | 190 } |
| 155 | 191 |
| 156 // Centers the Icon vertically in the bar. | 192 // Centers the Icon vertically in the bar. |
| 157 float icon_y = bar_top + bar_height / 2 - | 193 float icon_y = (bar_content_height_ - icon_layer->bounds().height()) / 2; |
| 158 icon_layer->bounds().height() / 2; | |
| 159 | 194 |
| 160 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); | 195 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); |
| 161 } | 196 } |
| 162 | 197 |
| 163 // --------------------------------------------------------------------------- | 198 // --------------------------------------------------------------------------- |
| 164 // Close Icon | 199 // Close Icon |
| 165 // --------------------------------------------------------------------------- | 200 // --------------------------------------------------------------------------- |
| 166 // Grab the Close Icon resource. | 201 // Grab the Close Icon resource. |
| 167 ui::Resource* close_icon_resource = resource_manager_->GetResource( | 202 ui::Resource* close_icon_resource = resource_manager_->GetResource( |
| 168 ui::ANDROID_RESOURCE_TYPE_STATIC, close_icon_resource_id_); | 203 ui::ANDROID_RESOURCE_TYPE_STATIC, close_icon_resource_id_); |
| 169 | 204 |
| 170 // Positions the icon at the end of the bar. | 205 // Positions the icon at the end of the bar. |
| 171 float close_icon_left; | 206 float close_icon_left; |
| 172 if (is_rtl) { | 207 if (is_rtl) { |
| 173 close_icon_left = bar_margin_side; | 208 close_icon_left = bar_margin_side; |
| 174 } else { | 209 } else { |
| 175 close_icon_left = | 210 close_icon_left = |
| 176 panel_width - close_icon_resource->size().width() - bar_margin_side; | 211 panel_width - close_icon_resource->size().width() - bar_margin_side; |
| 177 } | 212 } |
| 178 | 213 |
| 179 // Centers the Close Icon vertically in the bar. | 214 // Centers the Close Icon vertically in the bar. |
| 180 float close_icon_top = | 215 float close_icon_top = |
| 181 bar_top + bar_height / 2 - close_icon_resource->size().height() / 2; | 216 (bar_content_height_ - close_icon_resource->size().height()) / 2; |
| 182 | 217 |
| 183 close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id()); | 218 close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id()); |
| 184 close_icon_->SetBounds(close_icon_resource->size()); | 219 close_icon_->SetBounds(close_icon_resource->size()); |
| 185 close_icon_->SetPosition( | 220 close_icon_->SetPosition( |
| 186 gfx::PointF(close_icon_left, close_icon_top)); | 221 gfx::PointF(close_icon_left, close_icon_top)); |
| 187 close_icon_->SetOpacity(close_icon_opacity); | 222 close_icon_->SetOpacity(close_icon_opacity); |
| 188 | 223 |
| 189 // --------------------------------------------------------------------------- | 224 // --------------------------------------------------------------------------- |
| 190 // Content | 225 // Content |
| 191 // --------------------------------------------------------------------------- | 226 // --------------------------------------------------------------------------- |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 : resource_manager_(resource_manager), | 283 : resource_manager_(resource_manager), |
| 249 layer_(cc::Layer::Create()), | 284 layer_(cc::Layer::Create()), |
| 250 panel_shadow_(cc::NinePatchLayer::Create()), | 285 panel_shadow_(cc::NinePatchLayer::Create()), |
| 251 bar_background_(cc::SolidColorLayer::Create()), | 286 bar_background_(cc::SolidColorLayer::Create()), |
| 252 bar_text_(cc::UIResourceLayer::Create()), | 287 bar_text_(cc::UIResourceLayer::Create()), |
| 253 bar_shadow_(cc::UIResourceLayer::Create()), | 288 bar_shadow_(cc::UIResourceLayer::Create()), |
| 254 panel_icon_(cc::UIResourceLayer::Create()), | 289 panel_icon_(cc::UIResourceLayer::Create()), |
| 255 close_icon_(cc::UIResourceLayer::Create()), | 290 close_icon_(cc::UIResourceLayer::Create()), |
| 256 content_container_(cc::SolidColorLayer::Create()), | 291 content_container_(cc::SolidColorLayer::Create()), |
| 257 text_container_(cc::Layer::Create()), | 292 text_container_(cc::Layer::Create()), |
| 258 bar_border_(cc::SolidColorLayer::Create()) { | 293 bar_border_(cc::SolidColorLayer::Create()), |
| 294 bar_handle_(cc::UIResourceLayer::Create()), | |
| 295 bar_content_layer_(cc::UIResourceLayer::Create()) { | |
| 259 layer_->SetMasksToBounds(false); | 296 layer_->SetMasksToBounds(false); |
| 260 layer_->SetIsDrawable(true); | 297 layer_->SetIsDrawable(true); |
| 261 | 298 |
| 262 // Panel Shadow | 299 // Panel Shadow |
| 263 panel_shadow_->SetIsDrawable(true); | 300 panel_shadow_->SetIsDrawable(true); |
| 264 panel_shadow_->SetFillCenter(false); | 301 panel_shadow_->SetFillCenter(false); |
| 265 layer_->AddChild(panel_shadow_); | 302 layer_->AddChild(panel_shadow_); |
| 266 | 303 |
| 267 // Bar Background | 304 // Bar Background |
| 268 bar_background_->SetIsDrawable(true); | 305 bar_background_->SetIsDrawable(true); |
| 269 bar_background_->SetBackgroundColor(kBarBackgroundColor); | 306 bar_background_->SetBackgroundColor(kBarBackgroundColor); |
| 270 layer_->AddChild(bar_background_); | 307 layer_->AddChild(bar_background_); |
| 271 | 308 |
| 309 // Bar Handle | |
| 310 bar_handle_->SetIsDrawable(true); | |
| 311 | |
| 312 // Bar Content Layer | |
| 313 bar_content_layer_->SetIsDrawable(true); | |
| 314 layer_->AddChild(bar_content_layer_); | |
| 315 | |
| 272 // Bar Text | 316 // Bar Text |
| 273 bar_text_->SetIsDrawable(true); | 317 bar_text_->SetIsDrawable(true); |
| 274 AddBarTextLayer(bar_text_); | 318 AddBarTextLayer(bar_text_); |
| 275 layer_->AddChild(text_container_); | 319 bar_content_layer_->AddChild(text_container_); |
| 276 | 320 |
| 277 // Panel Icon | 321 // Panel Icon |
| 278 panel_icon_->SetIsDrawable(true); | 322 panel_icon_->SetIsDrawable(true); |
| 279 | 323 |
| 280 // The container that any text in the bar will be added to. | 324 // The container that any text in the bar will be added to. |
| 281 text_container_->SetIsDrawable(true); | 325 text_container_->SetIsDrawable(true); |
| 282 | 326 |
| 283 // Close Icon | 327 // Close Icon |
| 284 close_icon_->SetIsDrawable(true); | 328 close_icon_->SetIsDrawable(true); |
| 285 layer_->AddChild(close_icon_); | 329 bar_content_layer_->AddChild(close_icon_); |
| 286 | 330 |
| 287 // Content Container | 331 // Content Container |
| 288 content_container_->SetIsDrawable(true); | 332 content_container_->SetIsDrawable(true); |
| 289 content_container_->SetBackgroundColor(kBarBackgroundColor); | 333 content_container_->SetBackgroundColor(kBarBackgroundColor); |
| 290 layer_->AddChild(content_container_); | 334 layer_->AddChild(content_container_); |
| 291 | 335 |
| 292 // Bar Border | 336 // Bar Border |
| 293 bar_border_->SetIsDrawable(true); | 337 bar_border_->SetIsDrawable(true); |
| 294 bar_border_->SetBackgroundColor(kBarBorderColor); | 338 bar_border_->SetBackgroundColor(kBarBorderColor); |
| 295 | 339 |
| 296 // Bar Shadow | 340 // Bar Shadow |
| 297 bar_shadow_->SetIsDrawable(true); | 341 bar_shadow_->SetIsDrawable(true); |
| 298 } | 342 } |
| 299 | 343 |
| 300 OverlayPanelLayer::~OverlayPanelLayer() { | 344 OverlayPanelLayer::~OverlayPanelLayer() { |
| 301 } | 345 } |
| 302 | 346 |
| 303 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() { | 347 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() { |
| 304 return layer_; | 348 return layer_; |
| 305 } | 349 } |
| 306 | 350 |
| 307 } // namespace android | 351 } // namespace android |
| OLD | NEW |