| 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" |
| 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 "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/android/resources/crushed_sprite_resource.h" | 14 #include "ui/android/resources/crushed_sprite_resource.h" |
| 15 #include "ui/android/resources/nine_patch_resource.h" |
| 15 #include "ui/android/resources/resource_manager.h" | 16 #include "ui/android/resources/resource_manager.h" |
| 16 #include "ui/base/l10n/l10n_util_android.h" | 17 #include "ui/base/l10n/l10n_util_android.h" |
| 17 #include "ui/gfx/color_utils.h" | 18 #include "ui/gfx/color_utils.h" |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const SkColor kBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); | 22 const SkColor kBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); |
| 22 const SkColor kBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); | 23 const SkColor kBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); |
| 23 | 24 |
| 24 // This is the default width for any icon displayed on an OverlayPanel. | 25 // This is the default width for any icon displayed on an OverlayPanel. |
| 25 const float kDefaultIconWidthDp = 36.0f; | 26 const float kDefaultIconWidthDp = 36.0f; |
| 26 | 27 |
| 27 } // namespace | 28 } // namespace |
| 28 | 29 |
| 29 namespace android { | 30 namespace android { |
| 30 | 31 |
| 31 scoped_refptr<cc::Layer> OverlayPanelLayer::GetIconLayer() { | 32 scoped_refptr<cc::Layer> OverlayPanelLayer::GetIconLayer() { |
| 32 ui::ResourceManager::Resource* panel_icon_resource = | 33 ui::Resource* panel_icon_resource = resource_manager_->GetResource( |
| 33 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 34 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_icon_resource_id_); |
| 34 panel_icon_resource_id_); | |
| 35 DCHECK(panel_icon_resource); | 35 DCHECK(panel_icon_resource); |
| 36 | 36 |
| 37 if (panel_icon_->parent() != layer_) { | 37 if (panel_icon_->parent() != layer_) { |
| 38 layer_->AddChild(panel_icon_); | 38 layer_->AddChild(panel_icon_); |
| 39 } | 39 } |
| 40 | 40 |
| 41 panel_icon_->SetUIResourceId( | 41 panel_icon_->SetUIResourceId(panel_icon_resource->ui_resource()->id()); |
| 42 panel_icon_resource->ui_resource->id()); | 42 panel_icon_->SetBounds(panel_icon_resource->size()); |
| 43 panel_icon_->SetBounds(panel_icon_resource->size); | |
| 44 | 43 |
| 45 return panel_icon_; | 44 return panel_icon_; |
| 46 } | 45 } |
| 47 | 46 |
| 48 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) { | 47 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) { |
| 49 text_container_->AddChild(text_layer); | 48 text_container_->AddChild(text_layer); |
| 50 } | 49 } |
| 51 | 50 |
| 52 void OverlayPanelLayer::SetResourceIds( | 51 void OverlayPanelLayer::SetResourceIds( |
| 53 int bar_text_resource_id, | 52 int bar_text_resource_id, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 74 float bar_height, | 73 float bar_height, |
| 75 float bar_offset_y, | 74 float bar_offset_y, |
| 76 float bar_text_opacity, | 75 float bar_text_opacity, |
| 77 bool bar_border_visible, | 76 bool bar_border_visible, |
| 78 float bar_border_height, | 77 float bar_border_height, |
| 79 bool bar_shadow_visible, | 78 bool bar_shadow_visible, |
| 80 float bar_shadow_opacity, | 79 float bar_shadow_opacity, |
| 81 float close_icon_opacity) { | 80 float close_icon_opacity) { |
| 82 | 81 |
| 83 // Grabs required static resources. | 82 // Grabs required static resources. |
| 84 ui::ResourceManager::Resource* panel_shadow_resource = | 83 ui::NinePatchResource* panel_shadow_resource = |
| 85 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 84 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 86 panel_shadow_resource_id_); | 85 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_shadow_resource_id_)); |
| 87 | 86 |
| 88 DCHECK(panel_shadow_resource); | 87 DCHECK(panel_shadow_resource); |
| 89 | 88 |
| 90 // Round values to avoid pixel gap between layers. | 89 // Round values to avoid pixel gap between layers. |
| 91 bar_height = floor(bar_height); | 90 bar_height = floor(bar_height); |
| 92 | 91 |
| 93 float bar_top = bar_offset_y; | 92 float bar_top = bar_offset_y; |
| 94 float bar_bottom = bar_top + bar_height; | 93 float bar_bottom = bar_top + bar_height; |
| 95 | 94 |
| 96 bool is_rtl = l10n_util::IsLayoutRtl(); | 95 bool is_rtl = l10n_util::IsLayoutRtl(); |
| 97 | 96 |
| 98 // --------------------------------------------------------------------------- | 97 // --------------------------------------------------------------------------- |
| 99 // Panel Shadow | 98 // Panel Shadow |
| 100 // --------------------------------------------------------------------------- | 99 // --------------------------------------------------------------------------- |
| 101 gfx::Size shadow_res_size = panel_shadow_resource->size; | 100 gfx::Size shadow_res_size = panel_shadow_resource->size(); |
| 102 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; | 101 gfx::Rect shadow_res_padding = panel_shadow_resource->padding(); |
| 103 gfx::Size shadow_bounds( | 102 gfx::Size shadow_bounds( |
| 104 panel_width + shadow_res_size.width() | 103 panel_width + shadow_res_size.width() |
| 105 - shadow_res_padding.size().width(), | 104 - shadow_res_padding.size().width(), |
| 106 panel_height + shadow_res_size.height() | 105 panel_height + shadow_res_size.height() |
| 107 - shadow_res_padding.size().height()); | 106 - shadow_res_padding.size().height()); |
| 108 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource->id()); | 107 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource()->id()); |
| 109 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds)); | 108 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds)); |
| 110 panel_shadow_->SetAperture(panel_shadow_resource->aperture); | 109 panel_shadow_->SetAperture(panel_shadow_resource->aperture()); |
| 111 panel_shadow_->SetBounds(shadow_bounds); | 110 panel_shadow_->SetBounds(shadow_bounds); |
| 112 gfx::PointF shadow_position(-shadow_res_padding.origin().x(), | 111 gfx::PointF shadow_position(-shadow_res_padding.origin().x(), |
| 113 -shadow_res_padding.origin().y()); | 112 -shadow_res_padding.origin().y()); |
| 114 panel_shadow_->SetPosition(shadow_position); | 113 panel_shadow_->SetPosition(shadow_position); |
| 115 | 114 |
| 116 // --------------------------------------------------------------------------- | 115 // --------------------------------------------------------------------------- |
| 117 // Bar Background | 116 // Bar Background |
| 118 // --------------------------------------------------------------------------- | 117 // --------------------------------------------------------------------------- |
| 119 gfx::Size background_size(panel_width, bar_height); | 118 gfx::Size background_size(panel_width, bar_height); |
| 120 bar_background_->SetBounds(background_size); | 119 bar_background_->SetBounds(background_size); |
| 121 bar_background_->SetPosition(gfx::PointF(0.f, bar_top)); | 120 bar_background_->SetPosition(gfx::PointF(0.f, bar_top)); |
| 122 | 121 |
| 123 // --------------------------------------------------------------------------- | 122 // --------------------------------------------------------------------------- |
| 124 // Bar Text | 123 // Bar Text |
| 125 // --------------------------------------------------------------------------- | 124 // --------------------------------------------------------------------------- |
| 126 ui::ResourceManager::Resource* bar_text_resource = | 125 ui::Resource* bar_text_resource = resource_manager_->GetResource( |
| 127 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 126 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_); |
| 128 bar_text_resource_id_); | |
| 129 | 127 |
| 130 if (bar_text_resource) { | 128 if (bar_text_resource) { |
| 131 // Centers the text vertically in the Search Bar. | 129 // Centers the text vertically in the Search Bar. |
| 132 float bar_padding_top = | 130 float bar_padding_top = |
| 133 bar_top + | 131 bar_top + bar_height / 2 - bar_text_resource->size().height() / 2; |
| 134 bar_height / 2 - | 132 bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id()); |
| 135 bar_text_resource->size.height() / 2; | 133 bar_text_->SetBounds(bar_text_resource->size()); |
| 136 bar_text_->SetUIResourceId(bar_text_resource->ui_resource->id()); | |
| 137 bar_text_->SetBounds(bar_text_resource->size); | |
| 138 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); | 134 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); |
| 139 bar_text_->SetOpacity(bar_text_opacity); | 135 bar_text_->SetOpacity(bar_text_opacity); |
| 140 } | 136 } |
| 141 | 137 |
| 142 // --------------------------------------------------------------------------- | 138 // --------------------------------------------------------------------------- |
| 143 // Panel Icon | 139 // Panel Icon |
| 144 // --------------------------------------------------------------------------- | 140 // --------------------------------------------------------------------------- |
| 145 scoped_refptr<cc::Layer> icon_layer = GetIconLayer(); | 141 scoped_refptr<cc::Layer> icon_layer = GetIconLayer(); |
| 146 if (icon_layer) { | 142 if (icon_layer) { |
| 147 // If the icon is not the default width, add or remove padding so it appears | 143 // If the icon is not the default width, add or remove padding so it appears |
| (...skipping 14 matching lines...) Expand all Loading... |
| 162 float icon_y = bar_top + bar_height / 2 - | 158 float icon_y = bar_top + bar_height / 2 - |
| 163 icon_layer->bounds().height() / 2; | 159 icon_layer->bounds().height() / 2; |
| 164 | 160 |
| 165 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); | 161 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); |
| 166 } | 162 } |
| 167 | 163 |
| 168 // --------------------------------------------------------------------------- | 164 // --------------------------------------------------------------------------- |
| 169 // Close Icon | 165 // Close Icon |
| 170 // --------------------------------------------------------------------------- | 166 // --------------------------------------------------------------------------- |
| 171 // Grab the Close Icon resource. | 167 // Grab the Close Icon resource. |
| 172 ui::ResourceManager::Resource* close_icon_resource = | 168 ui::Resource* close_icon_resource = resource_manager_->GetResource( |
| 173 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 169 ui::ANDROID_RESOURCE_TYPE_STATIC, close_icon_resource_id_); |
| 174 close_icon_resource_id_); | |
| 175 | 170 |
| 176 // Positions the icon at the end of the bar. | 171 // Positions the icon at the end of the bar. |
| 177 float close_icon_left; | 172 float close_icon_left; |
| 178 if (is_rtl) { | 173 if (is_rtl) { |
| 179 close_icon_left = bar_margin_side; | 174 close_icon_left = bar_margin_side; |
| 180 } else { | 175 } else { |
| 181 close_icon_left = panel_width - | 176 close_icon_left = |
| 182 close_icon_resource->size.width() - bar_margin_side; | 177 panel_width - close_icon_resource->size().width() - bar_margin_side; |
| 183 } | 178 } |
| 184 | 179 |
| 185 // Centers the Close Icon vertically in the bar. | 180 // Centers the Close Icon vertically in the bar. |
| 186 float close_icon_top = | 181 float close_icon_top = |
| 187 bar_top + | 182 bar_top + bar_height / 2 - close_icon_resource->size().height() / 2; |
| 188 bar_height / 2 - | |
| 189 close_icon_resource->size.height() / 2; | |
| 190 | 183 |
| 191 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); | 184 close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id()); |
| 192 close_icon_->SetBounds(close_icon_resource->size); | 185 close_icon_->SetBounds(close_icon_resource->size()); |
| 193 close_icon_->SetPosition( | 186 close_icon_->SetPosition( |
| 194 gfx::PointF(close_icon_left, close_icon_top)); | 187 gfx::PointF(close_icon_left, close_icon_top)); |
| 195 close_icon_->SetOpacity(close_icon_opacity); | 188 close_icon_->SetOpacity(close_icon_opacity); |
| 196 | 189 |
| 197 // --------------------------------------------------------------------------- | 190 // --------------------------------------------------------------------------- |
| 198 // Content | 191 // Content |
| 199 // --------------------------------------------------------------------------- | 192 // --------------------------------------------------------------------------- |
| 200 content_container_->SetPosition( | 193 content_container_->SetPosition( |
| 201 gfx::PointF(0.f, content_offset_y)); | 194 gfx::PointF(0.f, content_offset_y)); |
| 202 content_container_->SetBounds(gfx::Size(panel_width, panel_height)); | 195 content_container_->SetBounds(gfx::Size(panel_width, panel_height)); |
| 203 if (content_layer) { | 196 if (content_layer) { |
| 204 if (content_layer->parent() != content_container_) | 197 if (content_layer->parent() != content_container_) |
| 205 content_container_->AddChild(content_layer); | 198 content_container_->AddChild(content_layer); |
| 206 } else { | 199 } else { |
| 207 content_container_->RemoveAllChildren(); | 200 content_container_->RemoveAllChildren(); |
| 208 } | 201 } |
| 209 | 202 |
| 210 // --------------------------------------------------------------------------- | 203 // --------------------------------------------------------------------------- |
| 211 // Bar Shadow | 204 // Bar Shadow |
| 212 // --------------------------------------------------------------------------- | 205 // --------------------------------------------------------------------------- |
| 213 if (bar_shadow_visible) { | 206 if (bar_shadow_visible) { |
| 214 ui::ResourceManager::Resource* bar_shadow_resource = | 207 ui::Resource* bar_shadow_resource = resource_manager_->GetResource( |
| 215 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 208 ui::ANDROID_RESOURCE_TYPE_STATIC, bar_shadow_resource_id_); |
| 216 bar_shadow_resource_id_); | |
| 217 | 209 |
| 218 if (bar_shadow_resource) { | 210 if (bar_shadow_resource) { |
| 219 if (bar_shadow_->parent() != layer_) | 211 if (bar_shadow_->parent() != layer_) |
| 220 layer_->AddChild(bar_shadow_); | 212 layer_->AddChild(bar_shadow_); |
| 221 | 213 |
| 222 int shadow_height = bar_shadow_resource->size.height(); | 214 int shadow_height = bar_shadow_resource->size().height(); |
| 223 gfx::Size shadow_size(panel_width, shadow_height); | 215 gfx::Size shadow_size(panel_width, shadow_height); |
| 224 | 216 |
| 225 bar_shadow_->SetUIResourceId( | 217 bar_shadow_->SetUIResourceId(bar_shadow_resource->ui_resource()->id()); |
| 226 bar_shadow_resource->ui_resource->id()); | |
| 227 bar_shadow_->SetBounds(shadow_size); | 218 bar_shadow_->SetBounds(shadow_size); |
| 228 bar_shadow_->SetPosition(gfx::PointF(0.f, bar_bottom)); | 219 bar_shadow_->SetPosition(gfx::PointF(0.f, bar_bottom)); |
| 229 bar_shadow_->SetOpacity(bar_shadow_opacity); | 220 bar_shadow_->SetOpacity(bar_shadow_opacity); |
| 230 } | 221 } |
| 231 } else { | 222 } else { |
| 232 if (bar_shadow_.get() && bar_shadow_->parent()) | 223 if (bar_shadow_.get() && bar_shadow_->parent()) |
| 233 bar_shadow_->RemoveFromParent(); | 224 bar_shadow_->RemoveFromParent(); |
| 234 } | 225 } |
| 235 | 226 |
| 236 // --------------------------------------------------------------------------- | 227 // --------------------------------------------------------------------------- |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 } | 299 } |
| 309 | 300 |
| 310 OverlayPanelLayer::~OverlayPanelLayer() { | 301 OverlayPanelLayer::~OverlayPanelLayer() { |
| 311 } | 302 } |
| 312 | 303 |
| 313 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() { | 304 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() { |
| 314 return layer_; | 305 return layer_; |
| 315 } | 306 } |
| 316 | 307 |
| 317 } // namespace android | 308 } // namespace android |
| OLD | NEW |