| 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/tab_layer.h" | 5 #include "chrome/browser/android/compositor/layer/tab_layer.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "cc/layers/layer.h" | 9 #include "cc/layers/layer.h" |
| 10 #include "cc/layers/layer_collections.h" | 10 #include "cc/layers/layer_collections.h" |
| 11 #include "cc/layers/nine_patch_layer.h" | 11 #include "cc/layers/nine_patch_layer.h" |
| 12 #include "cc/layers/solid_color_layer.h" | 12 #include "cc/layers/solid_color_layer.h" |
| 13 #include "cc/layers/ui_resource_layer.h" | 13 #include "cc/layers/ui_resource_layer.h" |
| 14 #include "cc/resources/scoped_ui_resource.h" | 14 #include "cc/resources/scoped_ui_resource.h" |
| 15 #include "chrome/browser/android/compositor/decoration_title.h" | 15 #include "chrome/browser/android/compositor/decoration_title.h" |
| 16 #include "chrome/browser/android/compositor/layer/content_layer.h" | 16 #include "chrome/browser/android/compositor/layer/content_layer.h" |
| 17 #include "chrome/browser/android/compositor/layer/toolbar_layer.h" | 17 #include "chrome/browser/android/compositor/layer/toolbar_layer.h" |
| 18 #include "chrome/browser/android/compositor/layer_title_cache.h" | 18 #include "chrome/browser/android/compositor/layer_title_cache.h" |
| 19 #include "chrome/browser/android/compositor/tab_content_manager.h" | 19 #include "chrome/browser/android/compositor/tab_content_manager.h" |
| 20 #include "content/public/browser/android/compositor.h" | 20 #include "content/public/browser/android/compositor.h" |
| 21 #include "ui/android/resources/nine_patch_resource.h" |
| 21 #include "ui/android/resources/resource_manager.h" | 22 #include "ui/android/resources/resource_manager.h" |
| 22 #include "ui/base/l10n/l10n_util_android.h" | 23 #include "ui/base/l10n/l10n_util_android.h" |
| 23 #include "ui/gfx/geometry/insets_f.h" | 24 #include "ui/gfx/geometry/insets_f.h" |
| 24 #include "ui/gfx/geometry/point_f.h" | 25 #include "ui/gfx/geometry/point_f.h" |
| 25 #include "ui/gfx/geometry/rect_f.h" | 26 #include "ui/gfx/geometry/rect_f.h" |
| 26 #include "ui/gfx/geometry/safe_integer_conversions.h" | 27 #include "ui/gfx/geometry/safe_integer_conversions.h" |
| 27 #include "ui/gfx/geometry/size.h" | 28 #include "ui/gfx/geometry/size.h" |
| 28 #include "ui/gfx/transform.h" | 29 #include "ui/gfx/transform.h" |
| 29 | 30 |
| 30 namespace android { | 31 namespace android { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 float side_border_scale, | 146 float side_border_scale, |
| 146 bool inset_border) { | 147 bool inset_border) { |
| 147 if (alpha <= 0) { | 148 if (alpha <= 0) { |
| 148 layer_->SetHideLayerAndSubtree(true); | 149 layer_->SetHideLayerAndSubtree(true); |
| 149 return; | 150 return; |
| 150 } | 151 } |
| 151 | 152 |
| 152 layer_->SetHideLayerAndSubtree(false); | 153 layer_->SetHideLayerAndSubtree(false); |
| 153 | 154 |
| 154 // Grab required resources | 155 // Grab required resources |
| 155 ui::ResourceManager::Resource* border_resource = | 156 ui::NinePatchResource* border_resource = |
| 156 resource_manager_->GetStaticResourceWithTint(border_resource_id, | 157 ui::NinePatchResource::From(resource_manager_->GetStaticResourceWithTint( |
| 157 toolbar_background_color); | 158 border_resource_id, toolbar_background_color)); |
| 158 ui::ResourceManager::Resource* border_inner_shadow_resource = | 159 ui::NinePatchResource* border_inner_shadow_resource = |
| 159 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 160 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 160 border_inner_shadow_resource_id); | 161 ui::ANDROID_RESOURCE_TYPE_STATIC, border_inner_shadow_resource_id)); |
| 161 ui::ResourceManager::Resource* shadow_resource = | 162 ui::NinePatchResource* shadow_resource = |
| 162 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 163 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 163 shadow_resource_id); | 164 ui::ANDROID_RESOURCE_TYPE_STATIC, shadow_resource_id)); |
| 164 ui::ResourceManager::Resource* contour_resource = | 165 ui::NinePatchResource* contour_resource = |
| 165 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 166 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 166 contour_resource_id); | 167 ui::ANDROID_RESOURCE_TYPE_STATIC, contour_resource_id)); |
| 167 ui::ResourceManager::Resource* close_btn_resource = | 168 ui::Resource* close_btn_resource = |
| 168 resource_manager_->GetStaticResourceWithTint(close_button_resource_id, | 169 resource_manager_->GetStaticResourceWithTint(close_button_resource_id, |
| 169 close_button_color); | 170 close_button_color); |
| 170 ui::ResourceManager::Resource* back_logo_resource = nullptr; | 171 ui::Resource* back_logo_resource = nullptr; |
| 171 | 172 |
| 172 DecorationTitle* title_layer = nullptr; | 173 DecorationTitle* title_layer = nullptr; |
| 173 | 174 |
| 174 //---------------------------------------------------------------------------- | 175 //---------------------------------------------------------------------------- |
| 175 // Handle Border Scaling (Upscale/Downscale everything until final scaling) | 176 // Handle Border Scaling (Upscale/Downscale everything until final scaling) |
| 176 //---------------------------------------------------------------------------- | 177 //---------------------------------------------------------------------------- |
| 177 width /= border_scale; | 178 width /= border_scale; |
| 178 height /= border_scale; | 179 height /= border_scale; |
| 179 shadow_x /= border_scale; | 180 shadow_x /= border_scale; |
| 180 shadow_y /= border_scale; | 181 shadow_y /= border_scale; |
| 181 shadow_width /= border_scale; | 182 shadow_width /= border_scale; |
| 182 shadow_height /= border_scale; | 183 shadow_height /= border_scale; |
| 183 | 184 |
| 184 //---------------------------------------------------------------------------- | 185 //---------------------------------------------------------------------------- |
| 185 // Precalculate Helper Values | 186 // Precalculate Helper Values |
| 186 //---------------------------------------------------------------------------- | 187 //---------------------------------------------------------------------------- |
| 187 const gfx::RectF border_padding(border_resource->padding); | 188 const gfx::RectF border_padding(border_resource->padding()); |
| 188 const gfx::RectF border_inner_shadow_padding( | 189 const gfx::RectF border_inner_shadow_padding( |
| 189 border_inner_shadow_resource->padding); | 190 border_inner_shadow_resource->padding()); |
| 190 const gfx::RectF shadow_padding(shadow_resource->padding); | 191 const gfx::RectF shadow_padding(shadow_resource->padding()); |
| 191 const gfx::RectF contour_padding(contour_resource->padding); | 192 const gfx::RectF contour_padding(contour_resource->padding()); |
| 192 | 193 |
| 193 // If we're in portrait and we're RTL, the close button is on the left. | 194 // If we're in portrait and we're RTL, the close button is on the left. |
| 194 // Similarly if we're in landscape and we're in LTR, the close button is on | 195 // Similarly if we're in landscape and we're in LTR, the close button is on |
| 195 // the left. | 196 // the left. |
| 196 const bool close_button_on_left = is_portrait == l10n_util::IsLayoutRtl(); | 197 const bool close_button_on_left = is_portrait == l10n_util::IsLayoutRtl(); |
| 197 const bool back_visible = cos(rotation_x * SK_MScalarPI / 180.0f) < 0 || | 198 const bool back_visible = cos(rotation_x * SK_MScalarPI / 180.0f) < 0 || |
| 198 cos(rotation_y * SK_MScalarPI / 180.0f) < 0; | 199 cos(rotation_y * SK_MScalarPI / 180.0f) < 0; |
| 199 | 200 |
| 200 const float content_scale = width / content_width; | 201 const float content_scale = width / content_width; |
| 201 gfx::RectF content_area(0.f, 0.f, content_width, content_height); | 202 gfx::RectF content_area(0.f, 0.f, content_width, content_height); |
| 202 gfx::RectF scaled_local_content_area(shadow_x, shadow_y, shadow_width, | 203 gfx::RectF scaled_local_content_area(shadow_x, shadow_y, shadow_width, |
| 203 shadow_height); | 204 shadow_height); |
| 204 gfx::RectF descaled_local_content_area( | 205 gfx::RectF descaled_local_content_area( |
| 205 scaled_local_content_area.x() / content_scale, | 206 scaled_local_content_area.x() / content_scale, |
| 206 scaled_local_content_area.y() / content_scale, | 207 scaled_local_content_area.y() / content_scale, |
| 207 scaled_local_content_area.width() / content_scale, | 208 scaled_local_content_area.width() / content_scale, |
| 208 scaled_local_content_area.height() / content_scale); | 209 scaled_local_content_area.height() / content_scale); |
| 209 | 210 |
| 210 const gfx::Size shadow_padding_size( | 211 const gfx::Size shadow_padding_size( |
| 211 shadow_resource->size.width() - shadow_padding.width(), | 212 shadow_resource->size().width() - shadow_padding.width(), |
| 212 shadow_resource->size.height() - shadow_padding.height()); | 213 shadow_resource->size().height() - shadow_padding.height()); |
| 213 const gfx::Size border_padding_size( | 214 const gfx::Size border_padding_size( |
| 214 border_resource->size.width() - border_padding.width(), | 215 border_resource->size().width() - border_padding.width(), |
| 215 border_resource->size.height() - border_padding.height()); | 216 border_resource->size().height() - border_padding.height()); |
| 216 const gfx::Size border_inner_shadow_padding_size( | 217 const gfx::Size border_inner_shadow_padding_size( |
| 217 border_inner_shadow_resource->size.width() | 218 border_inner_shadow_resource->size().width() - |
| 218 - border_inner_shadow_padding.width(), | 219 border_inner_shadow_padding.width(), |
| 219 border_inner_shadow_resource->size.height() | 220 border_inner_shadow_resource->size().height() - |
| 220 - border_inner_shadow_padding.height()); | 221 border_inner_shadow_padding.height()); |
| 221 const gfx::Size contour_padding_size( | 222 const gfx::Size contour_padding_size( |
| 222 contour_resource->size.width() - contour_padding.width(), | 223 contour_resource->size().width() - contour_padding.width(), |
| 223 contour_resource->size.height() - contour_padding.height()); | 224 contour_resource->size().height() - contour_padding.height()); |
| 224 | 225 |
| 225 const float close_btn_effective_width = close_btn_width * close_alpha; | 226 const float close_btn_effective_width = close_btn_width * close_alpha; |
| 226 | 227 |
| 227 //-------------------------------------------------------------------------- | 228 //-------------------------------------------------------------------------- |
| 228 // Update Resource Ids For Layers That Impact Layout | 229 // Update Resource Ids For Layers That Impact Layout |
| 229 //-------------------------------------------------------------------------- | 230 //-------------------------------------------------------------------------- |
| 230 | 231 |
| 231 // TODO(kkimlabs): Tab switcher doesn't show the progress bar. | 232 // TODO(kkimlabs): Tab switcher doesn't show the progress bar. |
| 232 toolbar_layer_->PushResource(toolbar_resource_id, | 233 toolbar_layer_->PushResource(toolbar_resource_id, |
| 233 toolbar_background_color, | 234 toolbar_background_color, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 height + contour_padding_size.height()); | 283 height + contour_padding_size.height()); |
| 283 gfx::Size close_button_size(close_btn_width, border_padding.y()); | 284 gfx::Size close_button_size(close_btn_width, border_padding.y()); |
| 284 gfx::Size title_size(width - close_btn_effective_width, border_padding.y()); | 285 gfx::Size title_size(width - close_btn_effective_width, border_padding.y()); |
| 285 gfx::Size back_logo_size; | 286 gfx::Size back_logo_size; |
| 286 // TODO(clholgat): Figure out why the back logo is null sometimes. | 287 // TODO(clholgat): Figure out why the back logo is null sometimes. |
| 287 if (back_visible) { | 288 if (back_visible) { |
| 288 back_logo_resource = | 289 back_logo_resource = |
| 289 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 290 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 290 back_logo_resource_id); | 291 back_logo_resource_id); |
| 291 if (back_logo_resource) | 292 if (back_logo_resource) |
| 292 back_logo_size = back_logo_resource->size; | 293 back_logo_size = back_logo_resource->size(); |
| 293 } | 294 } |
| 294 | 295 |
| 295 // Store this size at a point as it might go negative during the inset | 296 // Store this size at a point as it might go negative during the inset |
| 296 // calculations. | 297 // calculations. |
| 297 gfx::Point desired_content_size_pt( | 298 gfx::Point desired_content_size_pt( |
| 298 descaled_local_content_area.width(), | 299 descaled_local_content_area.width(), |
| 299 descaled_local_content_area.height() - toolbar_impact_height); | 300 descaled_local_content_area.height() - toolbar_impact_height); |
| 300 | 301 |
| 301 // Shrink the toolbar layer so we properly clip if it's offset. | 302 // Shrink the toolbar layer so we properly clip if it's offset. |
| 302 gfx::Size toolbar_size( | 303 gfx::Size toolbar_size( |
| (...skipping 28 matching lines...) Expand all Loading... |
| 331 title_position.set_y(-border_padding.y()); | 332 title_position.set_y(-border_padding.y()); |
| 332 if (!close_button_on_left) | 333 if (!close_button_on_left) |
| 333 close_button_position.set_x(width - close_button_size.width()); | 334 close_button_position.set_x(width - close_button_size.width()); |
| 334 else | 335 else |
| 335 title_position.set_x(close_btn_effective_width); | 336 title_position.set_x(close_btn_effective_width); |
| 336 | 337 |
| 337 //---------------------------------------------------------------------------- | 338 //---------------------------------------------------------------------------- |
| 338 // Center Specific Assets in the Rects | 339 // Center Specific Assets in the Rects |
| 339 //---------------------------------------------------------------------------- | 340 //---------------------------------------------------------------------------- |
| 340 close_button_position.Offset( | 341 close_button_position.Offset( |
| 341 (close_button_size.width() - close_btn_resource->size.width()) / 2.f, | 342 (close_button_size.width() - close_btn_resource->size().width()) / 2.f, |
| 342 (close_button_size.height() - close_btn_resource->size.height()) / 2.f); | 343 (close_button_size.height() - close_btn_resource->size().height()) / 2.f); |
| 343 close_button_size.SetSize(close_btn_resource->size.width(), | 344 close_button_size.SetSize(close_btn_resource->size().width(), |
| 344 close_btn_resource->size.height()); | 345 close_btn_resource->size().height()); |
| 345 | 346 |
| 346 //---------------------------------------------------------------------------- | 347 //---------------------------------------------------------------------------- |
| 347 // Handle Insetting the Top Border Component | 348 // Handle Insetting the Top Border Component |
| 348 //---------------------------------------------------------------------------- | 349 //---------------------------------------------------------------------------- |
| 349 if (inset_border) { | 350 if (inset_border) { |
| 350 float inset_diff = inset_border ? border_padding.y() : 0.f; | 351 float inset_diff = inset_border ? border_padding.y() : 0.f; |
| 351 descaled_local_content_area.set_height( | 352 descaled_local_content_area.set_height( |
| 352 descaled_local_content_area.height() - inset_diff); | 353 descaled_local_content_area.height() - inset_diff); |
| 353 scaled_local_content_area.set_height(scaled_local_content_area.height() - | 354 scaled_local_content_area.set_height(scaled_local_content_area.height() - |
| 354 inset_diff * content_scale); | 355 inset_diff * content_scale); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 406 close_button_position.Offset(0.5f, 0.5f); | 407 close_button_position.Offset(0.5f, 0.5f); |
| 407 toolbar_position.Offset(0.5f, 0.5f); | 408 toolbar_position.Offset(0.5f, 0.5f); |
| 408 | 409 |
| 409 border_size.Enlarge(-1.f, -1.f); | 410 border_size.Enlarge(-1.f, -1.f); |
| 410 border_inner_shadow_size.Enlarge(-1.f, -1.f); | 411 border_inner_shadow_size.Enlarge(-1.f, -1.f); |
| 411 shadow_size.Enlarge(-1.f, -1.f); | 412 shadow_size.Enlarge(-1.f, -1.f); |
| 412 | 413 |
| 413 //---------------------------------------------------------------------------- | 414 //---------------------------------------------------------------------------- |
| 414 // Update Resource Ids | 415 // Update Resource Ids |
| 415 //---------------------------------------------------------------------------- | 416 //---------------------------------------------------------------------------- |
| 416 shadow_->SetUIResourceId(shadow_resource->ui_resource->id()); | 417 shadow_->SetUIResourceId(shadow_resource->ui_resource()->id()); |
| 417 shadow_->SetBorder(shadow_resource->Border(shadow_size)); | 418 shadow_->SetBorder(shadow_resource->Border(shadow_size)); |
| 418 shadow_->SetAperture(shadow_resource->aperture); | 419 shadow_->SetAperture(shadow_resource->aperture()); |
| 419 | 420 |
| 420 contour_shadow_->SetUIResourceId(contour_resource->ui_resource->id()); | 421 contour_shadow_->SetUIResourceId(contour_resource->ui_resource()->id()); |
| 421 contour_shadow_->SetBorder(contour_resource->Border(contour_size)); | 422 contour_shadow_->SetBorder(contour_resource->Border(contour_size)); |
| 422 contour_shadow_->SetAperture(contour_resource->aperture); | 423 contour_shadow_->SetAperture(contour_resource->aperture()); |
| 423 | 424 |
| 424 front_border_->SetUIResourceId(border_resource->ui_resource->id()); | 425 front_border_->SetUIResourceId(border_resource->ui_resource()->id()); |
| 425 front_border_->SetAperture(border_resource->aperture); | 426 front_border_->SetAperture(border_resource->aperture()); |
| 426 front_border_->SetBorder(border_resource->Border( | 427 front_border_->SetBorder(border_resource->Border( |
| 427 border_size, | 428 border_size, |
| 428 gfx::InsetsF(1.f, side_border_scale, 1.f, side_border_scale))); | 429 gfx::InsetsF(1.f, side_border_scale, 1.f, side_border_scale))); |
| 429 | 430 |
| 430 front_border_inner_shadow_->SetUIResourceId( | 431 front_border_inner_shadow_->SetUIResourceId( |
| 431 border_inner_shadow_resource->ui_resource->id()); | 432 border_inner_shadow_resource->ui_resource()->id()); |
| 432 front_border_inner_shadow_->SetAperture( | 433 front_border_inner_shadow_->SetAperture( |
| 433 border_inner_shadow_resource->aperture); | 434 border_inner_shadow_resource->aperture()); |
| 434 front_border_inner_shadow_->SetBorder(border_inner_shadow_resource->Border( | 435 front_border_inner_shadow_->SetBorder(border_inner_shadow_resource->Border( |
| 435 border_inner_shadow_size)); | 436 border_inner_shadow_size)); |
| 436 | 437 |
| 437 side_padding_->SetBackgroundColor(back_visible ? back_logo_color | 438 side_padding_->SetBackgroundColor(back_visible ? back_logo_color |
| 438 : default_background_color); | 439 : default_background_color); |
| 439 bottom_padding_->SetBackgroundColor(back_visible ? back_logo_color | 440 bottom_padding_->SetBackgroundColor(back_visible ? back_logo_color |
| 440 : default_background_color); | 441 : default_background_color); |
| 441 | 442 |
| 442 if (title_visible && layer_title_cache_) | 443 if (title_visible && layer_title_cache_) |
| 443 title_layer = layer_title_cache_->GetTitleLayer(id); | 444 title_layer = layer_title_cache_->GetTitleLayer(id); |
| 444 SetTitle(title_layer); | 445 SetTitle(title_layer); |
| 445 | 446 |
| 446 close_button_->SetUIResourceId(close_btn_resource->ui_resource->id()); | 447 close_button_->SetUIResourceId(close_btn_resource->ui_resource()->id()); |
| 447 | 448 |
| 448 if (!back_visible) { | 449 if (!back_visible) { |
| 449 gfx::Rect rounded_descaled_content_area( | 450 gfx::Rect rounded_descaled_content_area( |
| 450 round(descaled_local_content_area.x()), | 451 round(descaled_local_content_area.x()), |
| 451 round(descaled_local_content_area.y()), | 452 round(descaled_local_content_area.y()), |
| 452 round(desired_content_size.width()), | 453 round(desired_content_size.width()), |
| 453 round(desired_content_size.height())); | 454 round(desired_content_size.height())); |
| 454 | 455 |
| 455 content_->SetProperties(id, can_use_live_layer, static_to_view_blend, | 456 content_->SetProperties(id, can_use_live_layer, static_to_view_blend, |
| 456 true, alpha, saturation, | 457 true, alpha, saturation, |
| 457 true, rounded_descaled_content_area); | 458 true, rounded_descaled_content_area); |
| 458 } else if (back_logo_resource) { | 459 } else if (back_logo_resource) { |
| 459 back_logo_->SetUIResourceId(back_logo_resource->ui_resource->id()); | 460 back_logo_->SetUIResourceId(back_logo_resource->ui_resource()->id()); |
| 460 } | 461 } |
| 461 | 462 |
| 462 //---------------------------------------------------------------------------- | 463 //---------------------------------------------------------------------------- |
| 463 // Push Size, Position, Alpha and Transformations to Layers | 464 // Push Size, Position, Alpha and Transformations to Layers |
| 464 //---------------------------------------------------------------------------- | 465 //---------------------------------------------------------------------------- |
| 465 shadow_->SetHideLayerAndSubtree(!shadow_visible); | 466 shadow_->SetHideLayerAndSubtree(!shadow_visible); |
| 466 if (shadow_visible) { | 467 if (shadow_visible) { |
| 467 shadow_->SetPosition(shadow_position); | 468 shadow_->SetPosition(shadow_position); |
| 468 shadow_->SetBounds(shadow_size); | 469 shadow_->SetBounds(shadow_size); |
| 469 shadow_->SetOpacity(shadow_alpha); | 470 shadow_->SetOpacity(shadow_alpha); |
| (...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 681 title_->RemoveAllChildren(); | 682 title_->RemoveAllChildren(); |
| 682 title_->AddChild(layer); | 683 title_->AddChild(layer); |
| 683 } | 684 } |
| 684 } | 685 } |
| 685 | 686 |
| 686 if (title) | 687 if (title) |
| 687 title->SetUIResourceIds(); | 688 title->SetUIResourceIds(); |
| 688 } | 689 } |
| 689 | 690 |
| 690 } // namespace android | 691 } // namespace android |
| OLD | NEW |