| 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/solid_color_layer.h" | 8 #include "cc/layers/solid_color_layer.h" |
| 8 #include "cc/layers/ui_resource_layer.h" | 9 #include "cc/layers/ui_resource_layer.h" |
| 9 #include "cc/resources/scoped_ui_resource.h" | 10 #include "cc/resources/scoped_ui_resource.h" |
| 10 #include "content/public/browser/android/compositor.h" | 11 #include "content/public/browser/android/compositor.h" |
| 11 #include "third_party/skia/include/core/SkColor.h" | 12 #include "third_party/skia/include/core/SkColor.h" |
| 12 #include "ui/android/resources/resource_manager.h" | 13 #include "ui/android/resources/resource_manager.h" |
| 13 | 14 |
| 14 namespace chrome { | 15 namespace chrome { |
| 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 return make_scoped_refptr(new ToolbarLayer()); | 20 ui::ResourceManager* resource_manager) { |
| 21 return make_scoped_refptr(new ToolbarLayer(resource_manager)); |
| 20 } | 22 } |
| 21 | 23 |
| 22 scoped_refptr<cc::Layer> ToolbarLayer::layer() { | 24 scoped_refptr<cc::Layer> ToolbarLayer::layer() { |
| 23 return layer_; | 25 return layer_; |
| 24 } | 26 } |
| 25 | 27 |
| 26 void ToolbarLayer::PushResource( | 28 void ToolbarLayer::PushResource( |
| 27 ui::ResourceManager::Resource* resource, | 29 ui::ResourceManager::Resource* resource, |
| 28 int toolbar_background_color, | 30 int toolbar_background_color, |
| 29 bool anonymize, | 31 bool anonymize, |
| 30 int toolbar_textbox_background_color, | 32 int toolbar_textbox_background_color, |
| 33 int url_bar_background_resource_id, |
| 34 float url_bar_alpha, |
| 31 bool show_debug, | 35 bool show_debug, |
| 32 float brightness) { | 36 float brightness) { |
| 33 DCHECK(resource); | 37 DCHECK(resource); |
| 34 | 38 |
| 35 // This layer effectively draws over the space it takes for shadows. Set the | 39 // This layer effectively draws over the space it takes for shadows. Set the |
| 36 // bounds to the non-shadow size so that other things can properly line up. | 40 // bounds to the non-shadow size so that other things can properly line up. |
| 37 // Padding height does not include the height of the tabstrip, so we add | 41 // Padding height does not include the height of the tabstrip, so we add |
| 38 // it explicitly by adding y offset. | 42 // it explicitly by adding y offset. |
| 39 gfx::Size size = gfx::Size( | 43 gfx::Size size = gfx::Size( |
| 40 resource->padding.width(), | 44 resource->padding.width(), |
| 41 resource->padding.height() + resource->padding.y()); | 45 resource->padding.height() + resource->padding.y()); |
| 42 layer_->SetBounds(size); | 46 layer_->SetBounds(size); |
| 43 | 47 |
| 44 toolbar_background_layer_->SetBounds(resource->padding.size()); | 48 toolbar_background_layer_->SetBounds(resource->padding.size()); |
| 45 toolbar_background_layer_->SetPosition(resource->padding.origin()); | 49 toolbar_background_layer_->SetPosition(resource->padding.origin()); |
| 46 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); | 50 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); |
| 47 | 51 |
| 52 bool url_bar_visible = (resource->aperture.width() != 0); |
| 53 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible); |
| 54 if (url_bar_visible) { |
| 55 ui::ResourceManager::Resource* url_bar_background_resource = |
| 56 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 57 url_bar_background_resource_id); |
| 58 gfx::Size url_bar_size( |
| 59 resource->aperture.width() + url_bar_background_resource->size.width() |
| 60 - url_bar_background_resource->padding.width(), |
| 61 resource->aperture.height() + url_bar_background_resource->size.height() |
| 62 - url_bar_background_resource->padding.height()); |
| 63 gfx::Rect url_bar_border( |
| 64 url_bar_background_resource->Border(url_bar_size)); |
| 65 gfx::PointF url_bar_position = gfx::PointF( |
| 66 resource->aperture.x() - url_bar_background_resource->padding.x(), |
| 67 resource->aperture.y() - url_bar_background_resource->padding.y()); |
| 68 |
| 69 url_bar_background_layer_->SetUIResourceId( |
| 70 url_bar_background_resource->ui_resource->id()); |
| 71 url_bar_background_layer_->SetBorder(url_bar_border); |
| 72 url_bar_background_layer_->SetAperture( |
| 73 url_bar_background_resource->aperture); |
| 74 url_bar_background_layer_->SetBounds(url_bar_size); |
| 75 url_bar_background_layer_->SetPosition(url_bar_position); |
| 76 url_bar_background_layer_->SetOpacity(url_bar_alpha); |
| 77 } |
| 78 |
| 48 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); | 79 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); |
| 49 bitmap_layer_->SetBounds(resource->size); | 80 bitmap_layer_->SetBounds(resource->size); |
| 50 | 81 |
| 51 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); | 82 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); |
| 52 if (anonymize) { | 83 if (anonymize) { |
| 53 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); | 84 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); |
| 54 anonymize_layer_->SetBounds(resource->aperture.size()); | 85 anonymize_layer_->SetBounds(resource->aperture.size()); |
| 55 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); | 86 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); |
| 56 } | 87 } |
| 57 | 88 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 98 progress_bar_layer_->SetHideLayerAndSubtree(!is_progress_bar_visible); | 129 progress_bar_layer_->SetHideLayerAndSubtree(!is_progress_bar_visible); |
| 99 if (is_progress_bar_visible) { | 130 if (is_progress_bar_visible) { |
| 100 progress_bar_layer_->SetPosition( | 131 progress_bar_layer_->SetPosition( |
| 101 gfx::PointF(progress_bar_x, progress_bar_y)); | 132 gfx::PointF(progress_bar_x, progress_bar_y)); |
| 102 progress_bar_layer_->SetBounds( | 133 progress_bar_layer_->SetBounds( |
| 103 gfx::Size(progress_bar_width, progress_bar_height)); | 134 gfx::Size(progress_bar_width, progress_bar_height)); |
| 104 progress_bar_layer_->SetBackgroundColor(progress_bar_color); | 135 progress_bar_layer_->SetBackgroundColor(progress_bar_color); |
| 105 } | 136 } |
| 106 } | 137 } |
| 107 | 138 |
| 108 ToolbarLayer::ToolbarLayer() | 139 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager) |
| 109 : layer_(cc::Layer::Create(content::Compositor::LayerSettings())), | 140 : resource_manager_(resource_manager), |
| 141 layer_(cc::Layer::Create(content::Compositor::LayerSettings())), |
| 110 toolbar_background_layer_( | 142 toolbar_background_layer_( |
| 111 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 143 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 144 url_bar_background_layer_( |
| 145 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
| 112 bitmap_layer_( | 146 bitmap_layer_( |
| 113 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 147 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
| 114 progress_bar_layer_( | 148 progress_bar_layer_( |
| 115 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 149 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 116 progress_bar_background_layer_( | 150 progress_bar_background_layer_( |
| 117 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 151 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 118 anonymize_layer_( | 152 anonymize_layer_( |
| 119 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 153 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 120 debug_layer_( | 154 debug_layer_( |
| 121 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 155 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 122 brightness_(1.f) { | 156 brightness_(1.f) { |
| 123 toolbar_background_layer_->SetIsDrawable(true); | 157 toolbar_background_layer_->SetIsDrawable(true); |
| 124 layer_->AddChild(toolbar_background_layer_); | 158 layer_->AddChild(toolbar_background_layer_); |
| 125 | 159 |
| 160 url_bar_background_layer_->SetIsDrawable(true); |
| 161 url_bar_background_layer_->SetFillCenter(true); |
| 162 layer_->AddChild(url_bar_background_layer_); |
| 163 |
| 126 bitmap_layer_->SetIsDrawable(true); | 164 bitmap_layer_->SetIsDrawable(true); |
| 127 layer_->AddChild(bitmap_layer_); | 165 layer_->AddChild(bitmap_layer_); |
| 128 | 166 |
| 129 progress_bar_background_layer_->SetIsDrawable(true); | 167 progress_bar_background_layer_->SetIsDrawable(true); |
| 130 progress_bar_background_layer_->SetHideLayerAndSubtree(true); | 168 progress_bar_background_layer_->SetHideLayerAndSubtree(true); |
| 131 layer_->AddChild(progress_bar_background_layer_); | 169 layer_->AddChild(progress_bar_background_layer_); |
| 132 | 170 |
| 133 progress_bar_layer_->SetIsDrawable(true); | 171 progress_bar_layer_->SetIsDrawable(true); |
| 134 progress_bar_layer_->SetHideLayerAndSubtree(true); | 172 progress_bar_layer_->SetHideLayerAndSubtree(true); |
| 135 layer_->AddChild(progress_bar_layer_); | 173 layer_->AddChild(progress_bar_layer_); |
| 136 | 174 |
| 137 anonymize_layer_->SetIsDrawable(true); | 175 anonymize_layer_->SetIsDrawable(true); |
| 138 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); | 176 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); |
| 139 layer_->AddChild(anonymize_layer_); | 177 layer_->AddChild(anonymize_layer_); |
| 140 | 178 |
| 141 debug_layer_->SetIsDrawable(true); | 179 debug_layer_->SetIsDrawable(true); |
| 142 debug_layer_->SetBackgroundColor(SK_ColorGREEN); | 180 debug_layer_->SetBackgroundColor(SK_ColorGREEN); |
| 143 debug_layer_->SetOpacity(0.5f); | 181 debug_layer_->SetOpacity(0.5f); |
| 144 } | 182 } |
| 145 | 183 |
| 146 ToolbarLayer::~ToolbarLayer() { | 184 ToolbarLayer::~ToolbarLayer() { |
| 147 } | 185 } |
| 148 | 186 |
| 149 } // namespace android | 187 } // namespace android |
| 150 } // namespace chrome | 188 } // namespace chrome |
| OLD | NEW |