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 int toolbar_resource_id, |
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 bool clip_shadow) { |
| 38 ui::ResourceManager::Resource* resource = |
| 39 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, |
| 40 toolbar_resource_id); |
| 41 |
| 42 // Ensure the toolbar resource is available before making the layer visible. |
| 43 layer_->SetHideLayerAndSubtree(!resource); |
| 44 if (!resource) |
| 45 return; |
34 | 46 |
35 // This layer effectively draws over the space it takes for shadows. Set the | 47 // 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. | 48 // 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 | 49 // Padding height does not include the height of the tabstrip, so we add |
38 // it explicitly by adding y offset. | 50 // it explicitly by adding y offset. |
39 gfx::Size size = gfx::Size( | 51 gfx::Size size = gfx::Size( |
40 resource->padding.width(), | 52 resource->padding.width(), |
41 resource->padding.height() + resource->padding.y()); | 53 resource->padding.height() + resource->padding.y()); |
42 layer_->SetBounds(size); | 54 layer_->SetBounds(size); |
43 | 55 |
44 toolbar_background_layer_->SetBounds(resource->padding.size()); | 56 toolbar_background_layer_->SetBounds(resource->padding.size()); |
45 toolbar_background_layer_->SetPosition(resource->padding.origin()); | 57 toolbar_background_layer_->SetPosition(resource->padding.origin()); |
46 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); | 58 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); |
47 | 59 |
| 60 bool url_bar_visible = (resource->aperture.width() != 0); |
| 61 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible); |
| 62 if (url_bar_visible) { |
| 63 ui::ResourceManager::Resource* url_bar_background_resource = |
| 64 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, |
| 65 url_bar_background_resource_id); |
| 66 gfx::Size url_bar_size( |
| 67 resource->aperture.width() + url_bar_background_resource->size.width() |
| 68 - url_bar_background_resource->padding.width(), |
| 69 resource->aperture.height() + url_bar_background_resource->size.height() |
| 70 - url_bar_background_resource->padding.height()); |
| 71 gfx::Rect url_bar_border( |
| 72 url_bar_background_resource->Border(url_bar_size)); |
| 73 gfx::PointF url_bar_position = gfx::PointF( |
| 74 resource->aperture.x() - url_bar_background_resource->padding.x(), |
| 75 resource->aperture.y() - url_bar_background_resource->padding.y()); |
| 76 |
| 77 url_bar_background_layer_->SetUIResourceId( |
| 78 url_bar_background_resource->ui_resource->id()); |
| 79 url_bar_background_layer_->SetBorder(url_bar_border); |
| 80 url_bar_background_layer_->SetAperture( |
| 81 url_bar_background_resource->aperture); |
| 82 url_bar_background_layer_->SetBounds(url_bar_size); |
| 83 url_bar_background_layer_->SetPosition(url_bar_position); |
| 84 url_bar_background_layer_->SetOpacity(url_bar_alpha); |
| 85 } |
| 86 |
48 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); | 87 bitmap_layer_->SetUIResourceId(resource->ui_resource->id()); |
49 bitmap_layer_->SetBounds(resource->size); | 88 bitmap_layer_->SetBounds(resource->size); |
50 | 89 |
| 90 layer_->SetMasksToBounds(clip_shadow); |
| 91 |
51 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); | 92 anonymize_layer_->SetHideLayerAndSubtree(!anonymize); |
52 if (anonymize) { | 93 if (anonymize) { |
53 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); | 94 anonymize_layer_->SetPosition(gfx::PointF(resource->aperture.origin())); |
54 anonymize_layer_->SetBounds(resource->aperture.size()); | 95 anonymize_layer_->SetBounds(resource->aperture.size()); |
55 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); | 96 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color); |
56 } | 97 } |
57 | 98 |
58 debug_layer_->SetBounds(resource->size); | 99 debug_layer_->SetBounds(resource->size); |
59 if (show_debug && !debug_layer_->parent()) | 100 if (show_debug && !debug_layer_->parent()) |
60 layer_->AddChild(debug_layer_); | 101 layer_->AddChild(debug_layer_); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 progress_bar_layer_->SetHideLayerAndSubtree(!is_progress_bar_visible); | 139 progress_bar_layer_->SetHideLayerAndSubtree(!is_progress_bar_visible); |
99 if (is_progress_bar_visible) { | 140 if (is_progress_bar_visible) { |
100 progress_bar_layer_->SetPosition( | 141 progress_bar_layer_->SetPosition( |
101 gfx::PointF(progress_bar_x, progress_bar_y)); | 142 gfx::PointF(progress_bar_x, progress_bar_y)); |
102 progress_bar_layer_->SetBounds( | 143 progress_bar_layer_->SetBounds( |
103 gfx::Size(progress_bar_width, progress_bar_height)); | 144 gfx::Size(progress_bar_width, progress_bar_height)); |
104 progress_bar_layer_->SetBackgroundColor(progress_bar_color); | 145 progress_bar_layer_->SetBackgroundColor(progress_bar_color); |
105 } | 146 } |
106 } | 147 } |
107 | 148 |
108 ToolbarLayer::ToolbarLayer() | 149 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager) |
109 : layer_(cc::Layer::Create(content::Compositor::LayerSettings())), | 150 : resource_manager_(resource_manager), |
| 151 layer_(cc::Layer::Create(content::Compositor::LayerSettings())), |
110 toolbar_background_layer_( | 152 toolbar_background_layer_( |
111 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 153 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
| 154 url_bar_background_layer_( |
| 155 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), |
112 bitmap_layer_( | 156 bitmap_layer_( |
113 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), | 157 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), |
114 progress_bar_layer_( | 158 progress_bar_layer_( |
115 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 159 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
116 progress_bar_background_layer_( | 160 progress_bar_background_layer_( |
117 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 161 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
118 anonymize_layer_( | 162 anonymize_layer_( |
119 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 163 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
120 debug_layer_( | 164 debug_layer_( |
121 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), | 165 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), |
122 brightness_(1.f) { | 166 brightness_(1.f) { |
123 toolbar_background_layer_->SetIsDrawable(true); | 167 toolbar_background_layer_->SetIsDrawable(true); |
124 layer_->AddChild(toolbar_background_layer_); | 168 layer_->AddChild(toolbar_background_layer_); |
125 | 169 |
| 170 url_bar_background_layer_->SetIsDrawable(true); |
| 171 url_bar_background_layer_->SetFillCenter(true); |
| 172 layer_->AddChild(url_bar_background_layer_); |
| 173 |
126 bitmap_layer_->SetIsDrawable(true); | 174 bitmap_layer_->SetIsDrawable(true); |
127 layer_->AddChild(bitmap_layer_); | 175 layer_->AddChild(bitmap_layer_); |
128 | 176 |
129 progress_bar_background_layer_->SetIsDrawable(true); | 177 progress_bar_background_layer_->SetIsDrawable(true); |
130 progress_bar_background_layer_->SetHideLayerAndSubtree(true); | 178 progress_bar_background_layer_->SetHideLayerAndSubtree(true); |
131 layer_->AddChild(progress_bar_background_layer_); | 179 layer_->AddChild(progress_bar_background_layer_); |
132 | 180 |
133 progress_bar_layer_->SetIsDrawable(true); | 181 progress_bar_layer_->SetIsDrawable(true); |
134 progress_bar_layer_->SetHideLayerAndSubtree(true); | 182 progress_bar_layer_->SetHideLayerAndSubtree(true); |
135 layer_->AddChild(progress_bar_layer_); | 183 layer_->AddChild(progress_bar_layer_); |
136 | 184 |
137 anonymize_layer_->SetIsDrawable(true); | 185 anonymize_layer_->SetIsDrawable(true); |
138 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); | 186 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); |
139 layer_->AddChild(anonymize_layer_); | 187 layer_->AddChild(anonymize_layer_); |
140 | 188 |
141 debug_layer_->SetIsDrawable(true); | 189 debug_layer_->SetIsDrawable(true); |
142 debug_layer_->SetBackgroundColor(SK_ColorGREEN); | 190 debug_layer_->SetBackgroundColor(SK_ColorGREEN); |
143 debug_layer_->SetOpacity(0.5f); | 191 debug_layer_->SetOpacity(0.5f); |
144 } | 192 } |
145 | 193 |
146 ToolbarLayer::~ToolbarLayer() { | 194 ToolbarLayer::~ToolbarLayer() { |
147 } | 195 } |
148 | 196 |
149 } // namespace android | 197 } // namespace android |
150 } // namespace chrome | 198 } // namespace chrome |
OLD | NEW |