Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(29)

Side by Side Diff: chrome/browser/android/compositor/layer/overlay_panel_layer.cc

Issue 2801153003: [Contextual Search] Add a handle to the bar when Chrome Home is enabled (Closed)
Patch Set: Revert changes to OverlayPanelBase#initializeUiState() Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/overlay_panel_layer.h" 5 #include "chrome/browser/android/compositor/layer/overlay_panel_layer.h"
6 6
7 #include "cc/layers/layer.h" 7 #include "cc/layers/layer.h"
8 #include "cc/layers/nine_patch_layer.h" 8 #include "cc/layers/nine_patch_layer.h"
9 #include "cc/layers/solid_color_layer.h" 9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/layers/ui_resource_layer.h" 10 #include "cc/layers/ui_resource_layer.h"
(...skipping 29 matching lines...) Expand all
40 panel_icon_->SetUIResourceId(panel_icon_resource->ui_resource()->id()); 40 panel_icon_->SetUIResourceId(panel_icon_resource->ui_resource()->id());
41 panel_icon_->SetBounds(panel_icon_resource->size()); 41 panel_icon_->SetBounds(panel_icon_resource->size());
42 42
43 return panel_icon_; 43 return panel_icon_;
44 } 44 }
45 45
46 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) { 46 void OverlayPanelLayer::AddBarTextLayer(scoped_refptr<cc::Layer> text_layer) {
47 text_container_->AddChild(text_layer); 47 text_container_->AddChild(text_layer);
48 } 48 }
49 49
50 void OverlayPanelLayer::SetResourceIds( 50 void OverlayPanelLayer::SetResourceIds(int bar_text_resource_id,
51 int bar_text_resource_id, 51 int panel_shadow_resource_id,
52 int panel_shadow_resource_id, 52 int bar_shadow_resource_id,
53 int bar_shadow_resource_id, 53 int panel_icon_resource_id,
54 int panel_icon_resource_id, 54 int close_icon_resource_id,
55 int close_icon_resource_id) { 55 int handle_resource_id) {
56 bar_text_resource_id_ = bar_text_resource_id; 56 bar_text_resource_id_ = bar_text_resource_id;
57 panel_shadow_resource_id_ = panel_shadow_resource_id; 57 panel_shadow_resource_id_ = panel_shadow_resource_id;
58 bar_shadow_resource_id_ = bar_shadow_resource_id; 58 bar_shadow_resource_id_ = bar_shadow_resource_id;
59 panel_icon_resource_id_ = panel_icon_resource_id; 59 panel_icon_resource_id_ = panel_icon_resource_id;
60 close_icon_resource_id_ = close_icon_resource_id; 60 close_icon_resource_id_ = close_icon_resource_id;
61 bar_handle_resource_id_ = handle_resource_id;
61 } 62 }
62 63
63 void OverlayPanelLayer::SetProperties( 64 void OverlayPanelLayer::SetProperties(
64 float dp_to_px, 65 float dp_to_px,
65 const scoped_refptr<cc::Layer>& content_layer, 66 const scoped_refptr<cc::Layer>& content_layer,
66 float content_offset_y, 67 float content_offset_y,
67 float panel_x, 68 float panel_x,
68 float panel_y, 69 float panel_y,
69 float panel_width, 70 float panel_width,
70 float panel_height, 71 float panel_height,
71 float bar_margin_side, 72 float bar_margin_side,
72 float bar_height, 73 float bar_height,
73 float bar_offset_y, 74 float bar_offset_y,
74 float bar_text_opacity, 75 float bar_text_opacity,
75 bool bar_border_visible, 76 bool bar_border_visible,
76 float bar_border_height, 77 float bar_border_height,
77 bool bar_shadow_visible, 78 bool bar_shadow_visible,
78 float bar_shadow_opacity, 79 float bar_shadow_opacity,
79 float close_icon_opacity) { 80 float close_icon_opacity,
80 81 float bar_handle_offset_y,
82 float bar_padding_bottom) {
81 // Grabs required static resources. 83 // Grabs required static resources.
82 ui::NinePatchResource* panel_shadow_resource = 84 ui::NinePatchResource* panel_shadow_resource =
83 ui::NinePatchResource::From(resource_manager_->GetResource( 85 ui::NinePatchResource::From(resource_manager_->GetResource(
84 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_shadow_resource_id_)); 86 ui::ANDROID_RESOURCE_TYPE_STATIC, panel_shadow_resource_id_));
85 87
86 DCHECK(panel_shadow_resource); 88 DCHECK(panel_shadow_resource);
87 89
88 // Round values to avoid pixel gap between layers. 90 // Round values to avoid pixel gap between layers.
89 bar_height = floor(bar_height); 91 bar_height = floor(bar_height);
90 92
(...skipping 21 matching lines...) Expand all
112 panel_shadow_->SetPosition(shadow_position); 114 panel_shadow_->SetPosition(shadow_position);
113 115
114 // --------------------------------------------------------------------------- 116 // ---------------------------------------------------------------------------
115 // Bar Background 117 // Bar Background
116 // --------------------------------------------------------------------------- 118 // ---------------------------------------------------------------------------
117 gfx::Size background_size(panel_width, bar_height); 119 gfx::Size background_size(panel_width, bar_height);
118 bar_background_->SetBounds(background_size); 120 bar_background_->SetBounds(background_size);
119 bar_background_->SetPosition(gfx::PointF(0.f, bar_top)); 121 bar_background_->SetPosition(gfx::PointF(0.f, bar_top));
120 122
121 // --------------------------------------------------------------------------- 123 // ---------------------------------------------------------------------------
124 // Bar Handle
125 // ---------------------------------------------------------------------------
126
127 float bar_content_top = bar_top;
128 bar_content_height_ = bar_height - bar_padding_bottom;
129
130 if (bar_handle_resource_id_ != 0) {
131 if (bar_handle_ == nullptr) {
132 bar_handle_ = cc::UIResourceLayer::Create();
133 bar_handle_->SetIsDrawable(true);
134 layer_->AddChild(bar_handle_);
135 }
136
137 // Grab the bar handle resource.
138 ui::Resource* bar_handle_resource = resource_manager_->GetResource(
139 ui::ANDROID_RESOURCE_TYPE_STATIC, bar_handle_resource_id_);
140
141 // Center the handle horizontally.
142 float bar_handle_left =
143 (panel_width - bar_handle_resource->size().width()) / 2;
144 float bar_handle_top = bar_top + bar_handle_offset_y;
145
146 bar_handle_->SetUIResourceId(bar_handle_resource->ui_resource()->id());
147 bar_handle_->SetBounds(bar_handle_resource->size());
148 bar_handle_->SetPosition(gfx::PointF(bar_handle_left, bar_handle_top));
149
150 bar_content_top = bar_handle_top + bar_handle_resource->size().height();
151 bar_content_height_ = bar_height - bar_content_top - bar_padding_bottom;
152 }
153
154 // ---------------------------------------------------------------------------
155 // Bar Content Layer
156 // ---------------------------------------------------------------------------
157 bar_content_layer_->SetBounds(gfx::Size(panel_width, bar_content_height_));
158 bar_content_layer_->SetPosition(gfx::PointF(0.f, bar_content_top));
159
160 // ---------------------------------------------------------------------------
122 // Bar Text 161 // Bar Text
123 // --------------------------------------------------------------------------- 162 // ---------------------------------------------------------------------------
124 ui::Resource* bar_text_resource = resource_manager_->GetResource( 163 ui::Resource* bar_text_resource = resource_manager_->GetResource(
125 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_); 164 ui::ANDROID_RESOURCE_TYPE_DYNAMIC, bar_text_resource_id_);
126 165
127 if (bar_text_resource) { 166 if (bar_text_resource) {
128 // Centers the text vertically in the Search Bar. 167 // Centers the text vertically in the Search Bar.
129 float bar_padding_top = 168 float bar_padding_top =
130 bar_top + bar_height / 2 - bar_text_resource->size().height() / 2; 169 (bar_content_height_ - bar_text_resource->size().height()) / 2;
131 bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id()); 170 bar_text_->SetUIResourceId(bar_text_resource->ui_resource()->id());
132 bar_text_->SetBounds(bar_text_resource->size()); 171 bar_text_->SetBounds(bar_text_resource->size());
133 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top)); 172 bar_text_->SetPosition(gfx::PointF(0.f, bar_padding_top));
134 bar_text_->SetOpacity(bar_text_opacity); 173 bar_text_->SetOpacity(bar_text_opacity);
135 } 174 }
136 175
137 // --------------------------------------------------------------------------- 176 // ---------------------------------------------------------------------------
138 // Panel Icon 177 // Panel Icon
139 // --------------------------------------------------------------------------- 178 // ---------------------------------------------------------------------------
140 scoped_refptr<cc::Layer> icon_layer = GetIconLayer(); 179 scoped_refptr<cc::Layer> icon_layer = GetIconLayer();
141 if (icon_layer) { 180 if (icon_layer) {
142 // If the icon is not the default width, add or remove padding so it appears 181 // If the icon is not the default width, add or remove padding so it appears
143 // centered. 182 // centered.
144 float icon_padding = (kDefaultIconWidthDp * dp_to_px - 183 float icon_padding = (kDefaultIconWidthDp * dp_to_px -
145 icon_layer->bounds().width()) / 2.0f; 184 icon_layer->bounds().width()) / 2.0f;
146 185
147 // Positions the Icon at the start of the bar. 186 // Positions the Icon at the start of the bar.
148 float icon_x; 187 float icon_x;
149 if (is_rtl) { 188 if (is_rtl) {
150 icon_x = panel_width - icon_layer->bounds().width() - 189 icon_x = panel_width - icon_layer->bounds().width() -
151 (bar_margin_side + icon_padding); 190 (bar_margin_side + icon_padding);
152 } else { 191 } else {
153 icon_x = bar_margin_side + icon_padding; 192 icon_x = bar_margin_side + icon_padding;
154 } 193 }
155 194
156 // Centers the Icon vertically in the bar. 195 // Centers the Icon vertically in the bar.
157 float icon_y = bar_top + bar_height / 2 - 196 float icon_y = (bar_content_height_ - icon_layer->bounds().height()) / 2;
158 icon_layer->bounds().height() / 2;
159 197
160 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y)); 198 icon_layer->SetPosition(gfx::PointF(icon_x, icon_y));
161 } 199 }
162 200
163 // --------------------------------------------------------------------------- 201 // ---------------------------------------------------------------------------
164 // Close Icon 202 // Close Icon
165 // --------------------------------------------------------------------------- 203 // ---------------------------------------------------------------------------
166 // Grab the Close Icon resource. 204 // Grab the Close Icon resource.
167 ui::Resource* close_icon_resource = resource_manager_->GetResource( 205 ui::Resource* close_icon_resource = resource_manager_->GetResource(
168 ui::ANDROID_RESOURCE_TYPE_STATIC, close_icon_resource_id_); 206 ui::ANDROID_RESOURCE_TYPE_STATIC, close_icon_resource_id_);
169 207
170 // Positions the icon at the end of the bar. 208 // Positions the icon at the end of the bar.
171 float close_icon_left; 209 float close_icon_left;
172 if (is_rtl) { 210 if (is_rtl) {
173 close_icon_left = bar_margin_side; 211 close_icon_left = bar_margin_side;
174 } else { 212 } else {
175 close_icon_left = 213 close_icon_left =
176 panel_width - close_icon_resource->size().width() - bar_margin_side; 214 panel_width - close_icon_resource->size().width() - bar_margin_side;
177 } 215 }
178 216
179 // Centers the Close Icon vertically in the bar. 217 // Centers the Close Icon vertically in the bar.
180 float close_icon_top = 218 float close_icon_top =
181 bar_top + bar_height / 2 - close_icon_resource->size().height() / 2; 219 (bar_content_height_ - close_icon_resource->size().height()) / 2;
182 220
183 close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id()); 221 close_icon_->SetUIResourceId(close_icon_resource->ui_resource()->id());
184 close_icon_->SetBounds(close_icon_resource->size()); 222 close_icon_->SetBounds(close_icon_resource->size());
185 close_icon_->SetPosition( 223 close_icon_->SetPosition(
186 gfx::PointF(close_icon_left, close_icon_top)); 224 gfx::PointF(close_icon_left, close_icon_top));
187 close_icon_->SetOpacity(close_icon_opacity); 225 close_icon_->SetOpacity(close_icon_opacity);
188 226
189 // --------------------------------------------------------------------------- 227 // ---------------------------------------------------------------------------
190 // Content 228 // Content
191 // --------------------------------------------------------------------------- 229 // ---------------------------------------------------------------------------
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 : resource_manager_(resource_manager), 286 : resource_manager_(resource_manager),
249 layer_(cc::Layer::Create()), 287 layer_(cc::Layer::Create()),
250 panel_shadow_(cc::NinePatchLayer::Create()), 288 panel_shadow_(cc::NinePatchLayer::Create()),
251 bar_background_(cc::SolidColorLayer::Create()), 289 bar_background_(cc::SolidColorLayer::Create()),
252 bar_text_(cc::UIResourceLayer::Create()), 290 bar_text_(cc::UIResourceLayer::Create()),
253 bar_shadow_(cc::UIResourceLayer::Create()), 291 bar_shadow_(cc::UIResourceLayer::Create()),
254 panel_icon_(cc::UIResourceLayer::Create()), 292 panel_icon_(cc::UIResourceLayer::Create()),
255 close_icon_(cc::UIResourceLayer::Create()), 293 close_icon_(cc::UIResourceLayer::Create()),
256 content_container_(cc::SolidColorLayer::Create()), 294 content_container_(cc::SolidColorLayer::Create()),
257 text_container_(cc::Layer::Create()), 295 text_container_(cc::Layer::Create()),
258 bar_border_(cc::SolidColorLayer::Create()) { 296 bar_border_(cc::SolidColorLayer::Create()),
297 bar_content_layer_(cc::UIResourceLayer::Create()) {
259 layer_->SetMasksToBounds(false); 298 layer_->SetMasksToBounds(false);
260 layer_->SetIsDrawable(true); 299 layer_->SetIsDrawable(true);
261 300
262 // Panel Shadow 301 // Panel Shadow
263 panel_shadow_->SetIsDrawable(true); 302 panel_shadow_->SetIsDrawable(true);
264 panel_shadow_->SetFillCenter(false); 303 panel_shadow_->SetFillCenter(false);
265 layer_->AddChild(panel_shadow_); 304 layer_->AddChild(panel_shadow_);
266 305
267 // Bar Background 306 // Bar Background
268 bar_background_->SetIsDrawable(true); 307 bar_background_->SetIsDrawable(true);
269 bar_background_->SetBackgroundColor(kBarBackgroundColor); 308 bar_background_->SetBackgroundColor(kBarBackgroundColor);
270 layer_->AddChild(bar_background_); 309 layer_->AddChild(bar_background_);
271 310
311 // Bar Content Layer
312 bar_content_layer_->SetIsDrawable(true);
313 layer_->AddChild(bar_content_layer_);
314
272 // Bar Text 315 // Bar Text
273 bar_text_->SetIsDrawable(true); 316 bar_text_->SetIsDrawable(true);
274 AddBarTextLayer(bar_text_); 317 AddBarTextLayer(bar_text_);
275 layer_->AddChild(text_container_); 318 bar_content_layer_->AddChild(text_container_);
276 319
277 // Panel Icon 320 // Panel Icon
278 panel_icon_->SetIsDrawable(true); 321 panel_icon_->SetIsDrawable(true);
279 322
280 // The container that any text in the bar will be added to. 323 // The container that any text in the bar will be added to.
281 text_container_->SetIsDrawable(true); 324 text_container_->SetIsDrawable(true);
282 325
283 // Close Icon 326 // Close Icon
284 close_icon_->SetIsDrawable(true); 327 close_icon_->SetIsDrawable(true);
285 layer_->AddChild(close_icon_); 328 bar_content_layer_->AddChild(close_icon_);
286 329
287 // Content Container 330 // Content Container
288 content_container_->SetIsDrawable(true); 331 content_container_->SetIsDrawable(true);
289 content_container_->SetBackgroundColor(kBarBackgroundColor); 332 content_container_->SetBackgroundColor(kBarBackgroundColor);
290 layer_->AddChild(content_container_); 333 layer_->AddChild(content_container_);
291 334
292 // Bar Border 335 // Bar Border
293 bar_border_->SetIsDrawable(true); 336 bar_border_->SetIsDrawable(true);
294 bar_border_->SetBackgroundColor(kBarBorderColor); 337 bar_border_->SetBackgroundColor(kBarBorderColor);
295 338
296 // Bar Shadow 339 // Bar Shadow
297 bar_shadow_->SetIsDrawable(true); 340 bar_shadow_->SetIsDrawable(true);
298 } 341 }
299 342
300 OverlayPanelLayer::~OverlayPanelLayer() { 343 OverlayPanelLayer::~OverlayPanelLayer() {
301 } 344 }
302 345
303 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() { 346 scoped_refptr<cc::Layer> OverlayPanelLayer::layer() {
304 return layer_; 347 return layer_;
305 } 348 }
306 349
307 } // namespace android 350 } // namespace android
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698