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