| 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/toolbar_layer.h" | 5 #include "chrome/browser/android/compositor/layer/toolbar_layer.h" |
| 6 | 6 |
| 7 #include "cc/layers/nine_patch_layer.h" | 7 #include "cc/layers/nine_patch_layer.h" |
| 8 #include "cc/layers/solid_color_layer.h" | 8 #include "cc/layers/solid_color_layer.h" |
| 9 #include "cc/layers/ui_resource_layer.h" | 9 #include "cc/layers/ui_resource_layer.h" |
| 10 #include "cc/resources/scoped_ui_resource.h" | 10 #include "cc/resources/scoped_ui_resource.h" |
| 11 #include "content/public/browser/android/compositor.h" | 11 #include "content/public/browser/android/compositor.h" |
| 12 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 13 #include "ui/android/resources/nine_patch_resource.h" |
| 13 #include "ui/android/resources/resource_manager.h" | 14 #include "ui/android/resources/resource_manager.h" |
| 14 | 15 |
| 15 namespace android { | 16 namespace android { |
| 16 | 17 |
| 17 // static | 18 // static |
| 18 scoped_refptr<ToolbarLayer> ToolbarLayer::Create( | 19 scoped_refptr<ToolbarLayer> ToolbarLayer::Create( |
| 19 ui::ResourceManager* resource_manager) { | 20 ui::ResourceManager* resource_manager) { |
| 20 return make_scoped_refptr(new ToolbarLayer(resource_manager)); | 21 return make_scoped_refptr(new ToolbarLayer(resource_manager)); |
| 21 } | 22 } |
| 22 | 23 |
| 23 scoped_refptr<cc::Layer> ToolbarLayer::layer() { | 24 scoped_refptr<cc::Layer> ToolbarLayer::layer() { |
| 24 return layer_; | 25 return layer_; |
| 25 } | 26 } |
| 26 | 27 |
| 27 void ToolbarLayer::PushResource( | 28 void ToolbarLayer::PushResource( |
| 28 int toolbar_resource_id, | 29 int toolbar_resource_id, |
| 29 int toolbar_background_color, | 30 int toolbar_background_color, |
| 30 bool anonymize, | 31 bool anonymize, |
| 31 int toolbar_textbox_background_color, | 32 int toolbar_textbox_background_color, |
| 32 int url_bar_background_resource_id, | 33 int url_bar_background_resource_id, |
| 33 float url_bar_alpha, | 34 float url_bar_alpha, |
| 34 float window_height, | 35 float window_height, |
| 35 float y_offset, | 36 float y_offset, |
| 36 bool show_debug, | 37 bool show_debug, |
| 37 bool clip_shadow, | 38 bool clip_shadow, |
| 38 bool browser_controls_at_bottom) { | 39 bool browser_controls_at_bottom) { |
| 39 ui::ResourceManager::Resource* resource = | 40 // TODO(khushalsagar): This should not be a nine-patch resource. |
| 40 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 41 ui::NinePatchResource* resource = |
| 41 toolbar_resource_id); | 42 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 43 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, toolbar_resource_id)); |
| 42 | 44 |
| 43 // Ensure the toolbar resource is available before making the layer visible. | 45 // Ensure the toolbar resource is available before making the layer visible. |
| 44 layer_->SetHideLayerAndSubtree(!resource); | 46 layer_->SetHideLayerAndSubtree(!resource); |
| 45 if (!resource) | 47 if (!resource) |
| 46 return; | 48 return; |
| 47 | 49 |
| 48 // This layer effectively draws over the space it takes for shadows. Set the | 50 // This layer effectively draws over the space it takes for shadows. Set the |
| 49 // bounds to the non-shadow size so that other things can properly line up. | 51 // bounds to the non-shadow size so that other things can properly line up. |
| 50 // Padding height does not include the height of the tabstrip, so we add | 52 // Padding height does not include the height of the tabstrip, so we add |
| 51 // it explicitly by adding y offset. | 53 // it explicitly by adding y offset. |
| 52 gfx::Size size = gfx::Size( | 54 gfx::Size size = |
| 53 resource->padding.width(), | 55 gfx::Size(resource->padding().width(), |
| 54 resource->padding.height() + resource->padding.y()); | 56 resource->padding().height() + resource->padding().y()); |
| 55 layer_->SetBounds(size); | 57 layer_->SetBounds(size); |
| 56 | 58 |
| 57 // The toolbar_root_ contains all of the layers that make up the toolbar. The | 59 // The toolbar_root_ contains all of the layers that make up the toolbar. The |
| 58 // toolbar_root_ is moved around inside of layer_ to allow appropriate | 60 // toolbar_root_ is moved around inside of layer_ to allow appropriate |
| 59 // clipping of the shadow. | 61 // clipping of the shadow. |
| 60 toolbar_root_->SetBounds(resource->padding.size()); | 62 toolbar_root_->SetBounds(resource->padding().size()); |
| 61 | 63 |
| 62 gfx::PointF root_layer_position(0, y_offset); | 64 gfx::PointF root_layer_position(0, y_offset); |
| 63 gfx::PointF background_position(resource->padding.origin()); | 65 gfx::PointF background_position(resource->padding().origin()); |
| 64 if (browser_controls_at_bottom) { | 66 if (browser_controls_at_bottom) { |
| 65 // The toolbar's position as if it were completely shown. | 67 // The toolbar's position as if it were completely shown. |
| 66 float base_toolbar_y = window_height - resource->padding.size().height(); | 68 float base_toolbar_y = window_height - resource->padding().size().height(); |
| 67 float layer_offset = | 69 float layer_offset = |
| 68 resource->size.height() - resource->padding.size().height(); | 70 resource->size().height() - resource->padding().size().height(); |
| 69 | 71 |
| 70 root_layer_position.set_y(base_toolbar_y + y_offset); | 72 root_layer_position.set_y(base_toolbar_y + y_offset); |
| 71 toolbar_root_->SetPosition(gfx::PointF(0, -layer_offset)); | 73 toolbar_root_->SetPosition(gfx::PointF(0, -layer_offset)); |
| 72 background_position.set_y(layer_offset); | 74 background_position.set_y(layer_offset); |
| 73 } | 75 } |
| 74 layer_->SetPosition(root_layer_position); | 76 layer_->SetPosition(root_layer_position); |
| 75 | 77 |
| 76 toolbar_background_layer_->SetBounds(resource->padding.size()); | 78 toolbar_background_layer_->SetBounds(resource->padding().size()); |
| 77 toolbar_background_layer_->SetPosition(background_position); | 79 toolbar_background_layer_->SetPosition(background_position); |
| 78 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); | 80 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); |
| 79 | 81 |
| 80 bool url_bar_visible = (resource->aperture.width() != 0); | 82 bool url_bar_visible = (resource->aperture().width() != 0); |
| 81 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible); | 83 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible); |
| 82 if (url_bar_visible) { | 84 if (url_bar_visible) { |
| 83 ui::ResourceManager::Resource* url_bar_background_resource = | 85 ui::NinePatchResource* url_bar_background_resource = |
| 84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, | 86 ui::NinePatchResource::From(resource_manager_->GetResource( |
| 85 url_bar_background_resource_id); | 87 ui::ANDROID_RESOURCE_TYPE_STATIC, url_bar_background_resource_id)); |
| 86 gfx::Size url_bar_size( | 88 gfx::Size url_bar_size(resource->aperture().width() + |
| 87 resource->aperture.width() + url_bar_background_resource->size.width() | 89 url_bar_background_resource->size().width() - |
| 88 - url_bar_background_resource->padding.width(), | 90 url_bar_background_resource->padding().width(), |
| 89 resource->aperture.height() + url_bar_background_resource->size.height() | 91 resource->aperture().height() + |
| 90 - url_bar_background_resource->padding.height()); | 92 url_bar_background_resource->size().height() - |
| 93 url_bar_background_resource->padding().height()); |
| 91 gfx::Rect url_bar_border( | 94 gfx::Rect url_bar_border( |
| 92 url_bar_background_resource->Border(url_bar_size)); | 95 url_bar_background_resource->Border(url_bar_size)); |
| 93 gfx::PointF url_bar_position = gfx::PointF( | 96 gfx::PointF url_bar_position = gfx::PointF( |
| 94 resource->aperture.x() - url_bar_background_resource->padding.x(), | 97 resource->aperture().x() - url_bar_background_resource->padding().x(), |
| 95 resource->aperture.y() - url_bar_background_resource->padding.y()); | 98 resource->aperture().y() - url_bar_background_resource->padding().y()); |
| 96 | 99 |
| 97 url_bar_background_layer_->SetUIResourceId( | 100 url_bar_background_layer_->SetUIResourceId( |
| 98 url_bar_background_resource->ui_resource->id()); | 101 url_bar_background_resource->ui_resource()->id()); |
| 99 url_bar_background_layer_->SetBorder(url_bar_border); | 102 url_bar_background_layer_->SetBorder(url_bar_border); |
| 100 url_bar_background_layer_->SetAperture( | 103 url_bar_background_layer_->SetAperture( |
| 101 url_bar_background_resource->aperture); | 104 url_bar_background_resource->aperture()); |
| 102 url_bar_background_layer_->SetBounds(url_bar_size); | 105 url_bar_background_layer_->SetBounds(url_bar_size); |
| 103 url_bar_background_layer_->SetPosition(url_bar_position); | 106 url_bar_background_layer_->SetPosition(url_bar_position); |
| 104 url_bar_background_layer_->SetOpacity(url_bar_alpha); | 107 url_bar_background_layer_->SetOpacity(url_bar_alpha); |
| 105 } | 108 } |
| 106 | 109 |
| 107 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); | 110 bitmap_layer_->SetUIResourceId(resource->ui_resource()->id()); |
| 108 bitmap_layer_->SetBounds(resource->size); | 111 bitmap_layer_->SetBounds(resource->size()); |
| 109 | 112 |
| 110 layer_->SetMasksToBounds(clip_shadow); | 113 layer_->SetMasksToBounds(clip_shadow); |
| 111 | 114 |
| 112 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); | 115 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); |
| 113 if (anonymize) { | 116 if (anonymize) { |
| 114 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); | 117 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture().origin())); |
| 115 anonymize_layer_->SetBounds(resource->aperture.size()); | 118 anonymize_layer_->SetBounds(resource->aperture().size()); |
| 116 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); | 119 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); |
| 117 } | 120 } |
| 118 | 121 |
| 119 debug_layer_->SetBounds(resource->size); | 122 debug_layer_->SetBounds(resource->size()); |
| 120 if (show_debug && !debug_layer_->parent()) | 123 if (show_debug && !debug_layer_->parent()) |
| 121 layer_->AddChild(debug_layer_); | 124 layer_->AddChild(debug_layer_); |
| 122 else if (!show_debug && debug_layer_->parent()) | 125 else if (!show_debug && debug_layer_->parent()) |
| 123 debug_layer_->RemoveFromParent(); | 126 debug_layer_->RemoveFromParent(); |
| 124 } | 127 } |
| 125 | 128 |
| 126 void ToolbarLayer::UpdateProgressBar(int progress_bar_x, | 129 void ToolbarLayer::UpdateProgressBar(int progress_bar_x, |
| 127 int progress_bar_y, | 130 int progress_bar_y, |
| 128 int progress_bar_width, | 131 int progress_bar_width, |
| 129 int progress_bar_height, | 132 int progress_bar_height, |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 195 | 198 |
| 196 debug_layer_->SetIsDrawable(true); | 199 debug_layer_->SetIsDrawable(true); |
| 197 debug_layer_->SetBackgroundColor(SK_ColorGREEN); | 200 debug_layer_->SetBackgroundColor(SK_ColorGREEN); |
| 198 debug_layer_->SetOpacity(0.5f); | 201 debug_layer_->SetOpacity(0.5f); |
| 199 } | 202 } |
| 200 | 203 |
| 201 ToolbarLayer::~ToolbarLayer() { | 204 ToolbarLayer::~ToolbarLayer() { |
| 202 } | 205 } |
| 203 | 206 |
| 204 } // namespace android | 207 } // namespace android |
| OLD | NEW |