OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/tab_handle_layer.h" | 5 #include "chrome/browser/android/compositor/layer/tab_handle_layer.h" |
6 | 6 |
7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
8 #include "cc/layers/layer.h" | 8 #include "cc/layers/layer.h" |
9 #include "cc/layers/solid_color_layer.h" | 9 #include "cc/layers/solid_color_layer.h" |
10 #include "cc/resources/scoped_ui_resource.h" | 10 #include "cc/resources/scoped_ui_resource.h" |
11 #include "chrome/browser/android/compositor/decoration_title.h" | 11 #include "chrome/browser/android/compositor/decoration_title.h" |
12 #include "chrome/browser/android/compositor/layer_title_cache.h" | 12 #include "chrome/browser/android/compositor/layer_title_cache.h" |
13 #include "content/public/browser/android/compositor.h" | 13 #include "content/public/browser/android/compositor.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 #include "ui/base/l10n/l10n_util_android.h" | 16 #include "ui/base/l10n/l10n_util_android.h" |
16 | 17 |
17 namespace android { | 18 namespace android { |
18 | 19 |
19 // static | 20 // static |
20 scoped_refptr<TabHandleLayer> TabHandleLayer::Create( | 21 scoped_refptr<TabHandleLayer> TabHandleLayer::Create( |
21 LayerTitleCache* layer_title_cache) { | 22 LayerTitleCache* layer_title_cache) { |
22 return make_scoped_refptr(new TabHandleLayer(layer_title_cache)); | 23 return make_scoped_refptr(new TabHandleLayer(layer_title_cache)); |
23 } | 24 } |
24 | 25 |
25 void TabHandleLayer::SetProperties( | 26 void TabHandleLayer::SetProperties(int id, |
26 int id, | 27 ui::Resource* close_button_resource, |
27 ui::ResourceManager::Resource* close_button_resource, | 28 ui::NinePatchResource* tab_handle_resource, |
28 ui::ResourceManager::Resource* tab_handle_resource, | 29 bool foreground, |
29 bool foreground, | 30 bool close_pressed, |
30 bool close_pressed, | 31 float toolbar_width, |
31 float toolbar_width, | 32 float x, |
32 float x, | 33 float y, |
33 float y, | 34 float width, |
34 float width, | 35 float height, |
35 float height, | 36 float content_offset_x, |
36 float content_offset_x, | 37 float close_button_alpha, |
37 float close_button_alpha, | 38 bool is_loading, |
38 bool is_loading, | 39 float spinner_rotation, |
39 float spinner_rotation, | 40 float brightness, |
40 float brightness, | 41 float border_opacity) { |
41 float border_opacity) { | |
42 if (brightness != brightness_ || foreground != foreground_) { | 42 if (brightness != brightness_ || foreground != foreground_) { |
43 brightness_ = brightness; | 43 brightness_ = brightness; |
44 foreground_ = foreground; | 44 foreground_ = foreground; |
45 cc::FilterOperations filters; | 45 cc::FilterOperations filters; |
46 if (brightness_ != 1.0f && !foreground_) | 46 if (brightness_ != 1.0f && !foreground_) |
47 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_)); | 47 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_)); |
48 layer_->SetFilters(filters); | 48 layer_->SetFilters(filters); |
49 } | 49 } |
50 | 50 |
51 float original_x = x; | 51 float original_x = x; |
52 float original_y = y; | 52 float original_y = y; |
53 if (foreground_) { | 53 if (foreground_) { |
54 if (!border_->parent()) { | 54 if (!border_->parent()) { |
55 layer_->InsertChild(border_, 0); | 55 layer_->InsertChild(border_, 0); |
56 border_->SetIsDrawable(true); | 56 border_->SetIsDrawable(true); |
57 } | 57 } |
58 border_->SetBackgroundColor(SK_ColorBLACK); | 58 border_->SetBackgroundColor(SK_ColorBLACK); |
59 border_->SetPosition(gfx::PointF(0, height - 1)); | 59 border_->SetPosition(gfx::PointF(0, height - 1)); |
60 border_->SetBounds(gfx::Size(toolbar_width, 1)); | 60 border_->SetBounds(gfx::Size(toolbar_width, 1)); |
61 border_->SetOpacity(border_opacity); | 61 border_->SetOpacity(border_opacity); |
62 | 62 |
63 x = 0; | 63 x = 0; |
64 y = 0; | 64 y = 0; |
65 } else if (border_->parent()) { | 65 } else if (border_->parent()) { |
66 border_->RemoveFromParent(); | 66 border_->RemoveFromParent(); |
67 } | 67 } |
68 | 68 |
69 bool is_rtl = l10n_util::IsLayoutRtl(); | 69 bool is_rtl = l10n_util::IsLayoutRtl(); |
70 | 70 |
71 float margin_width = | 71 float margin_width = tab_handle_resource->size().width() - |
72 tab_handle_resource->size.width() - tab_handle_resource->aperture.width(); | 72 tab_handle_resource->aperture().width(); |
73 float margin_height = tab_handle_resource->size.height() - | 73 float margin_height = tab_handle_resource->size().height() - |
74 tab_handle_resource->aperture.height(); | 74 tab_handle_resource->aperture().height(); |
75 | 75 |
76 // In the inset case, the |decoration_tab_| nine-patch layer should not have a | 76 // In the inset case, the |decoration_tab_| nine-patch layer should not have a |
77 // margin that is greater than the content size of the layer. This case can | 77 // margin that is greater than the content size of the layer. This case can |
78 // happen at initialization. The sizes used below are just temp values until | 78 // happen at initialization. The sizes used below are just temp values until |
79 // the real content sizes arrive. | 79 // the real content sizes arrive. |
80 if (margin_width >= width) { | 80 if (margin_width >= width) { |
81 // Shift the left edge over by the adjusted amount for more | 81 // Shift the left edge over by the adjusted amount for more |
82 // aesthetic animations. | 82 // aesthetic animations. |
83 x = x - (margin_width - width); | 83 x = x - (margin_width - width); |
84 width = margin_width; | 84 width = margin_width; |
(...skipping 21 matching lines...) Expand all Loading... |
106 title_layer_->id()) { | 106 title_layer_->id()) { |
107 layer_->ReplaceChild((layer_->children()[expected_children - 1]).get(), | 107 layer_->ReplaceChild((layer_->children()[expected_children - 1]).get(), |
108 title_layer_); | 108 title_layer_); |
109 } | 109 } |
110 title_layer->SetUIResourceIds(); | 110 title_layer->SetUIResourceIds(); |
111 } else if (title_layer_.get()) { | 111 } else if (title_layer_.get()) { |
112 title_layer_->RemoveFromParent(); | 112 title_layer_->RemoveFromParent(); |
113 title_layer_ = nullptr; | 113 title_layer_ = nullptr; |
114 } | 114 } |
115 | 115 |
116 decoration_tab_->SetUIResourceId(tab_handle_resource->ui_resource->id()); | 116 decoration_tab_->SetUIResourceId(tab_handle_resource->ui_resource()->id()); |
117 decoration_tab_->SetAperture(tab_handle_resource->aperture); | 117 decoration_tab_->SetAperture(tab_handle_resource->aperture()); |
118 decoration_tab_->SetFillCenter(true); | 118 decoration_tab_->SetFillCenter(true); |
119 decoration_tab_->SetBounds(tab_bounds); | 119 decoration_tab_->SetBounds(tab_bounds); |
120 decoration_tab_->SetBorder( | 120 decoration_tab_->SetBorder( |
121 tab_handle_resource->Border(decoration_tab_->bounds())); | 121 tab_handle_resource->Border(decoration_tab_->bounds())); |
122 | 122 |
123 if (foreground_) | 123 if (foreground_) |
124 decoration_tab_->SetPosition(gfx::PointF(original_x, original_y)); | 124 decoration_tab_->SetPosition(gfx::PointF(original_x, original_y)); |
125 else | 125 else |
126 decoration_tab_->SetPosition(gfx::PointF(0, 0)); | 126 decoration_tab_->SetPosition(gfx::PointF(0, 0)); |
127 | 127 |
128 close_button_->SetUIResourceId(close_button_resource->ui_resource->id()); | 128 close_button_->SetUIResourceId(close_button_resource->ui_resource()->id()); |
129 close_button_->SetBounds(close_button_resource->size); | 129 close_button_->SetBounds(close_button_resource->size()); |
130 const float padding_right = | 130 const float padding_right = tab_handle_resource->size().width() - |
131 tab_handle_resource->size.width() - tab_handle_resource->padding.right(); | 131 tab_handle_resource->padding().right(); |
132 const float padding_left = tab_handle_resource->padding.x(); | 132 const float padding_left = tab_handle_resource->padding().x(); |
133 const float close_width = close_button_->bounds().width(); | 133 const float close_width = close_button_->bounds().width(); |
134 if (title_layer) { | 134 if (title_layer) { |
135 int title_y = tab_handle_resource->padding.y() / 2 + height / 2 - | 135 int title_y = tab_handle_resource->padding().y() / 2 + height / 2 - |
136 title_layer->size().height() / 2; | 136 title_layer->size().height() / 2; |
137 int title_x = is_rtl ? padding_left + close_width : padding_left; | 137 int title_x = is_rtl ? padding_left + close_width : padding_left; |
138 title_x += is_rtl ? 0 : content_offset_x; | 138 title_x += is_rtl ? 0 : content_offset_x; |
139 title_layer->setBounds(gfx::Size( | 139 title_layer->setBounds(gfx::Size( |
140 width - padding_right - padding_left - close_width - content_offset_x, | 140 width - padding_right - padding_left - close_width - content_offset_x, |
141 height)); | 141 height)); |
142 if (foreground_) { | 142 if (foreground_) { |
143 title_x += original_x; | 143 title_x += original_x; |
144 title_y += original_y; | 144 title_y += original_y; |
145 } | 145 } |
146 title_layer->layer()->SetPosition(gfx::PointF(title_x, title_y)); | 146 title_layer->layer()->SetPosition(gfx::PointF(title_x, title_y)); |
147 if (is_loading) { | 147 if (is_loading) { |
148 title_layer->SetIsLoading(true); | 148 title_layer->SetIsLoading(true); |
149 title_layer->SetSpinnerRotation(spinner_rotation); | 149 title_layer->SetSpinnerRotation(spinner_rotation); |
150 } else { | 150 } else { |
151 title_layer->SetIsLoading(false); | 151 title_layer->SetIsLoading(false); |
152 } | 152 } |
153 } | 153 } |
154 | 154 |
155 if (close_button_alpha == 0.f) { | 155 if (close_button_alpha == 0.f) { |
156 close_button_->SetIsDrawable(false); | 156 close_button_->SetIsDrawable(false); |
157 } else { | 157 } else { |
158 close_button_->SetIsDrawable(true); | 158 close_button_->SetIsDrawable(true); |
159 const float close_max_width = close_button_->bounds().width(); | 159 const float close_max_width = close_button_->bounds().width(); |
160 int close_y = (tab_handle_resource->padding.y() + height) / 2 - | 160 int close_y = (tab_handle_resource->padding().y() + height) / 2 - |
161 close_button_->bounds().height() / 2; | 161 close_button_->bounds().height() / 2; |
162 int close_x = is_rtl ? padding_left - close_max_width + close_width | 162 int close_x = is_rtl ? padding_left - close_max_width + close_width |
163 : width - padding_right - close_width; | 163 : width - padding_right - close_width; |
164 if (foreground_) { | 164 if (foreground_) { |
165 close_y += original_y; | 165 close_y += original_y; |
166 close_x += original_x; | 166 close_x += original_x; |
167 } | 167 } |
168 | 168 |
169 close_button_->SetPosition(gfx::PointF(close_x, close_y)); | 169 close_button_->SetPosition(gfx::PointF(close_x, close_y)); |
170 close_button_->SetOpacity(close_button_alpha); | 170 close_button_->SetOpacity(close_button_alpha); |
(...skipping 14 matching lines...) Expand all Loading... |
185 foreground_(false) { | 185 foreground_(false) { |
186 decoration_tab_->SetIsDrawable(true); | 186 decoration_tab_->SetIsDrawable(true); |
187 layer_->AddChild(decoration_tab_); | 187 layer_->AddChild(decoration_tab_); |
188 layer_->AddChild(close_button_); | 188 layer_->AddChild(close_button_); |
189 } | 189 } |
190 | 190 |
191 TabHandleLayer::~TabHandleLayer() { | 191 TabHandleLayer::~TabHandleLayer() { |
192 } | 192 } |
193 | 193 |
194 } // namespace android | 194 } // namespace android |
OLD | NEW |