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/resource_manager.h" | 13 #include "ui/android/resources/resource_manager.h" |
14 | 14 |
15 namespace chrome { | 15 namespace chrome { |
16 namespace android { | 16 namespace android { |
17 | 17 |
18 // static | 18 // static |
19 scoped_refptr<ToolbarLayer> ToolbarLayer::Create( | 19 scoped_refptr<ToolbarLayer> ToolbarLayer::Create( |
20 ui::ResourceManager* resource_manager) { | 20 ui::ResourceManager* resource_manager) { |
21 return make_scoped_refptr(new ToolbarLayer(resource_manager)); | 21 return make_scoped_refptr(new ToolbarLayer(resource_manager)); |
22 } | 22 } |
23 | 23 |
24 scoped_refptr<cc::Layer> ToolbarLayer::layer() { | 24 scoped_refptr<cc::Layer> ToolbarLayer::layer() { |
25 return layer_; | 25 return layer_; |
26 } | 26 } |
27 | 27 |
28 void ToolbarLayer::PushResource( | 28 void ToolbarLayer::PushResource( |
29 int toolbar_resource_id, | 29 int toolbar_resource_id, |
| 30 int toolbar_shadow_resource_id, |
30 int toolbar_background_color, | 31 int toolbar_background_color, |
31 bool anonymize, | 32 bool anonymize, |
32 int toolbar_textbox_background_color, | 33 int toolbar_textbox_background_color, |
33 int url_bar_background_resource_id, | 34 int url_bar_background_resource_id, |
34 float url_bar_alpha, | 35 float url_bar_alpha, |
35 bool show_debug, | 36 bool show_debug, |
36 bool clip_shadow) { | 37 bool show_shadow) { |
37 ui::ResourceManager::Resource* resource = | 38 ui::ResourceManager::Resource* resource = |
38 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, | 39 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
39 toolbar_resource_id); | 40 toolbar_resource_id); |
| 41 ui::ResourceManager::Resource* shadow_resource = |
| 42 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 43 toolbar_shadow_resource_id); |
40 | 44 |
41 // Ensure the toolbar resource is available before making the layer visible. | 45 // Ensure the toolbar resource is available before making the layer visible. |
42 layer_->SetHideLayerAndSubtree(!resource); | 46 layer_->SetHideLayerAndSubtree(!resource); |
43 if (!resource) | 47 if (!resource) |
44 return; | 48 return; |
45 | 49 |
46 // 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 |
47 // 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. |
48 // 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 |
49 // it explicitly by adding y offset. | 53 // it explicitly by adding y offset. |
(...skipping 30 matching lines...) Expand all Loading... |
80 url_bar_background_layer_->SetAperture( | 84 url_bar_background_layer_->SetAperture( |
81 url_bar_background_resource->aperture); | 85 url_bar_background_resource->aperture); |
82 url_bar_background_layer_->SetBounds(url_bar_size); | 86 url_bar_background_layer_->SetBounds(url_bar_size); |
83 url_bar_background_layer_->SetPosition(url_bar_position); | 87 url_bar_background_layer_->SetPosition(url_bar_position); |
84 url_bar_background_layer_->SetOpacity(url_bar_alpha); | 88 url_bar_background_layer_->SetOpacity(url_bar_alpha); |
85 } | 89 } |
86 | 90 |
87 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); | 91 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); |
88 bitmap_layer_->SetBounds(resource->size); | 92 bitmap_layer_->SetBounds(resource->size); |
89 | 93 |
90 layer_->SetMasksToBounds(clip_shadow); | 94 if (shadow_resource) { |
| 95 toolbar_shadow_layer_->SetUIResourceId(shadow_resource->ui_resource->id()); |
| 96 toolbar_shadow_layer_->SetBounds( |
| 97 gfx::Size(resource->size.width(), shadow_resource->size.height())); |
| 98 toolbar_shadow_layer_->SetPosition( |
| 99 gfx::PointF(0.0f, resource->padding.size().height())); |
| 100 toolbar_shadow_layer_->SetHideLayerAndSubtree(!show_shadow); |
| 101 } |
91 | 102 |
92 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); | 103 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); |
93 if (anonymize) { | 104 if (anonymize) { |
94 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); | 105 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); |
95 anonymize_layer_->SetBounds(resource->aperture.size()); | 106 anonymize_layer_->SetBounds(resource->aperture.size()); |
96 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); | 107 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); |
97 } | 108 } |
98 | 109 |
99 debug_layer_->SetBounds(resource->size); | 110 debug_layer_->SetBounds(resource->size); |
100 if (show_debug && !debug_layer_->parent()) | 111 if (show_debug && !debug_layer_->parent()) |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 progress_bar_layer_->SetBounds( | 146 progress_bar_layer_->SetBounds( |
136 gfx::Size(progress_bar_width, progress_bar_height)); | 147 gfx::Size(progress_bar_width, progress_bar_height)); |
137 progress_bar_layer_->SetBackgroundColor(progress_bar_color); | 148 progress_bar_layer_->SetBackgroundColor(progress_bar_color); |
138 } | 149 } |
139 } | 150 } |
140 | 151 |
141 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager) | 152 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager) |
142 : resource_manager_(resource_manager), | 153 : resource_manager_(resource_manager), |
143 layer_(cc::Layer::Create()), | 154 layer_(cc::Layer::Create()), |
144 toolbar_background_layer_(cc::SolidColorLayer::Create()), | 155 toolbar_background_layer_(cc::SolidColorLayer::Create()), |
| 156 toolbar_shadow_layer_(cc::UIResourceLayer::Create()), |
145 url_bar_background_layer_(cc::NinePatchLayer::Create()), | 157 url_bar_background_layer_(cc::NinePatchLayer::Create()), |
146 bitmap_layer_(cc::UIResourceLayer::Create()), | 158 bitmap_layer_(cc::UIResourceLayer::Create()), |
147 progress_bar_layer_(cc::SolidColorLayer::Create()), | 159 progress_bar_layer_(cc::SolidColorLayer::Create()), |
148 progress_bar_background_layer_(cc::SolidColorLayer::Create()), | 160 progress_bar_background_layer_(cc::SolidColorLayer::Create()), |
149 anonymize_layer_(cc::SolidColorLayer::Create()), | 161 anonymize_layer_(cc::SolidColorLayer::Create()), |
150 debug_layer_(cc::SolidColorLayer::Create()) { | 162 debug_layer_(cc::SolidColorLayer::Create()) { |
151 toolbar_background_layer_->SetIsDrawable(true); | 163 toolbar_background_layer_->SetIsDrawable(true); |
152 layer_->AddChild(toolbar_background_layer_); | 164 layer_->AddChild(toolbar_background_layer_); |
153 | 165 |
| 166 toolbar_shadow_layer_->SetIsDrawable(true); |
| 167 layer_->AddChild(toolbar_shadow_layer_); |
| 168 |
154 url_bar_background_layer_->SetIsDrawable(true); | 169 url_bar_background_layer_->SetIsDrawable(true); |
155 url_bar_background_layer_->SetFillCenter(true); | 170 url_bar_background_layer_->SetFillCenter(true); |
156 layer_->AddChild(url_bar_background_layer_); | 171 layer_->AddChild(url_bar_background_layer_); |
157 | 172 |
158 bitmap_layer_->SetIsDrawable(true); | 173 bitmap_layer_->SetIsDrawable(true); |
159 layer_->AddChild(bitmap_layer_); | 174 layer_->AddChild(bitmap_layer_); |
160 | 175 |
161 progress_bar_background_layer_->SetIsDrawable(true); | 176 progress_bar_background_layer_->SetIsDrawable(true); |
162 progress_bar_background_layer_->SetHideLayerAndSubtree(true); | 177 progress_bar_background_layer_->SetHideLayerAndSubtree(true); |
163 layer_->AddChild(progress_bar_background_layer_); | 178 layer_->AddChild(progress_bar_background_layer_); |
164 | 179 |
165 progress_bar_layer_->SetIsDrawable(true); | 180 progress_bar_layer_->SetIsDrawable(true); |
166 progress_bar_layer_->SetHideLayerAndSubtree(true); | 181 progress_bar_layer_->SetHideLayerAndSubtree(true); |
167 layer_->AddChild(progress_bar_layer_); | 182 layer_->AddChild(progress_bar_layer_); |
168 | 183 |
169 anonymize_layer_->SetIsDrawable(true); | 184 anonymize_layer_->SetIsDrawable(true); |
170 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); | 185 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); |
171 layer_->AddChild(anonymize_layer_); | 186 layer_->AddChild(anonymize_layer_); |
172 | 187 |
173 debug_layer_->SetIsDrawable(true); | 188 debug_layer_->SetIsDrawable(true); |
174 debug_layer_->SetBackgroundColor(SK_ColorGREEN); | 189 debug_layer_->SetBackgroundColor(SK_ColorGREEN); |
175 debug_layer_->SetOpacity(0.5f); | 190 debug_layer_->SetOpacity(0.5f); |
176 } | 191 } |
177 | 192 |
178 ToolbarLayer::~ToolbarLayer() { | 193 ToolbarLayer::~ToolbarLayer() { |
179 } | 194 } |
180 | 195 |
181 } // namespace android | 196 } // namespace android |
182 } // namespace chrome | 197 } // namespace chrome |
OLD | NEW |