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

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

Issue 1379183003: [ContextualSearch] Adds long press promo for Contextual Search. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 2 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 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/contextual_search_layer.h" 5 #include "chrome/browser/android/compositor/layer/contextual_search_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"
11 #include "cc/resources/scoped_ui_resource.h" 11 #include "cc/resources/scoped_ui_resource.h"
12 #include "content/public/browser/android/compositor.h" 12 #include "content/public/browser/android/compositor.h"
13 #include "content/public/browser/android/content_view_core.h" 13 #include "content/public/browser/android/content_view_core.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/android/resources/resource_manager.h" 15 #include "ui/android/resources/resource_manager.h"
16 #include "ui/base/l10n/l10n_util_android.h" 16 #include "ui/base/l10n/l10n_util_android.h"
17 #include "ui/gfx/color_utils.h"
17 18
18 namespace { 19 namespace {
19 20
20 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee); 21 const SkColor kSearchBackgroundColor = SkColorSetRGB(0xee, 0xee, 0xee);
21 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff); 22 const SkColor kSearchBarBackgroundColor = SkColorSetRGB(0xff, 0xff, 0xff);
22 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1); 23 const SkColor kSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1);
24 const SkColor kPeekPromoRippleBackgroundColor = SkColorSetRGB(0x42, 0x85, 0xF4);
23 25
24 } // namespace 26 } // namespace
25 27
26 namespace chrome { 28 namespace chrome {
27 namespace android { 29 namespace android {
28 30
29 // static 31 // static
30 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create( 32 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create(
31 ui::ResourceManager* resource_manager) { 33 ui::ResourceManager* resource_manager) {
32 return make_scoped_refptr(new ContextualSearchLayer(resource_manager)); 34 return make_scoped_refptr(new ContextualSearchLayer(resource_manager));
33 } 35 }
34 36
35 void ContextualSearchLayer::SetProperties( 37 void ContextualSearchLayer::SetProperties(
36 int panel_shadow_resource_id, 38 int panel_shadow_resource_id,
37 int search_context_resource_id, 39 int search_context_resource_id,
38 int search_term_resource_id, 40 int search_term_resource_id,
39 int search_bar_shadow_resource_id, 41 int search_bar_shadow_resource_id,
40 int search_provider_icon_resource_id, 42 int search_provider_icon_resource_id,
41 int arrow_up_resource_id, 43 int arrow_up_resource_id,
42 int close_icon_resource_id, 44 int close_icon_resource_id,
43 int progress_bar_background_resource_id, 45 int progress_bar_background_resource_id,
44 int progress_bar_resource_id, 46 int progress_bar_resource_id,
45 int search_promo_resource_id, 47 int search_promo_resource_id,
48 int peek_promo_ripple_resource_id,
49 int peek_promo_text_resource_id,
46 content::ContentViewCore* content_view_core, 50 content::ContentViewCore* content_view_core,
47 bool search_promo_visible, 51 bool search_promo_visible,
48 float search_promo_height, 52 float search_promo_height,
49 float search_promo_opacity, 53 float search_promo_opacity,
54 bool search_peek_promo_visible,
55 float search_peek_promo_height,
56 float search_peek_promo_padding,
57 float search_peek_promo_ripple_width,
58 float search_peek_promo_ripple_opacity,
59 float search_peek_promo_text_opacity,
50 float search_panel_x, 60 float search_panel_x,
51 float search_panel_y, 61 float search_panel_y,
52 float search_panel_width, 62 float search_panel_width,
53 float search_panel_height, 63 float search_panel_height,
54 float search_bar_margin_side, 64 float search_bar_margin_side,
55 float search_bar_height, 65 float search_bar_height,
56 float search_context_opacity, 66 float search_context_opacity,
57 float search_term_opacity, 67 float search_term_opacity,
58 bool search_bar_border_visible, 68 bool search_bar_border_visible,
59 float search_bar_border_y,
60 float search_bar_border_height, 69 float search_bar_border_height,
61 bool search_bar_shadow_visible, 70 bool search_bar_shadow_visible,
62 float search_bar_shadow_opacity, 71 float search_bar_shadow_opacity,
63 float arrow_icon_opacity, 72 float arrow_icon_opacity,
64 float arrow_icon_rotation, 73 float arrow_icon_rotation,
65 float close_icon_opacity, 74 float close_icon_opacity,
66 bool progress_bar_visible, 75 bool progress_bar_visible,
67 float progress_bar_y,
68 float progress_bar_height, 76 float progress_bar_height,
69 float progress_bar_opacity, 77 float progress_bar_opacity,
70 int progress_bar_completion) { 78 int progress_bar_completion) {
71 // Grabs the dynamic Search Bar Text resource. 79 // Grabs the dynamic Search Bar Text resource.
72 ui::ResourceManager::Resource* search_context_resource = 80 ui::ResourceManager::Resource* search_context_resource =
73 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
74 search_context_resource_id); 82 search_context_resource_id);
75 ui::ResourceManager::Resource* search_term_resource = 83 ui::ResourceManager::Resource* search_term_resource =
76 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
77 search_term_resource_id); 85 search_term_resource_id);
78 86
79 // Grabs required static resources. 87 // Grabs required static resources.
80 ui::ResourceManager::Resource* panel_shadow_resource = 88 ui::ResourceManager::Resource* panel_shadow_resource =
81 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 89 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
82 panel_shadow_resource_id); 90 panel_shadow_resource_id);
83 ui::ResourceManager::Resource* search_provider_icon_resource = 91 ui::ResourceManager::Resource* search_provider_icon_resource =
84 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 92 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
85 search_provider_icon_resource_id); 93 search_provider_icon_resource_id);
86 94
87 DCHECK(panel_shadow_resource); 95 DCHECK(panel_shadow_resource);
88 DCHECK(search_provider_icon_resource); 96 DCHECK(search_provider_icon_resource);
89 97
90 // Round values to avoid pixel gap between layers. 98 // Round values to avoid pixel gap between layers.
91 search_bar_height = floor(search_bar_height); 99 search_bar_height = floor(search_bar_height);
92 100
101 float search_bar_top = search_peek_promo_height;
102 float search_bar_bottom = search_bar_top + search_bar_height;
103
93 bool is_rtl = l10n_util::IsLayoutRtl(); 104 bool is_rtl = l10n_util::IsLayoutRtl();
94 105
95 // --------------------------------------------------------------------------- 106 // ---------------------------------------------------------------------------
96 // Panel Shadow 107 // Panel Shadow
97 // --------------------------------------------------------------------------- 108 // ---------------------------------------------------------------------------
98 gfx::Size shadow_res_size = panel_shadow_resource->size; 109 gfx::Size shadow_res_size = panel_shadow_resource->size;
99 gfx::Rect shadow_res_padding = panel_shadow_resource->padding; 110 gfx::Rect shadow_res_padding = panel_shadow_resource->padding;
100 gfx::Size shadow_bounds( 111 gfx::Size shadow_bounds(
101 search_panel_width + shadow_res_size.width() 112 search_panel_width + shadow_res_size.width()
102 - shadow_res_padding.size().width(), 113 - shadow_res_padding.size().width(),
103 search_panel_height + shadow_res_size.height() 114 search_panel_height + shadow_res_size.height()
104 - shadow_res_padding.size().height()); 115 - shadow_res_padding.size().height());
105 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource->id()); 116 panel_shadow_->SetUIResourceId(panel_shadow_resource->ui_resource->id());
106 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds)); 117 panel_shadow_->SetBorder(panel_shadow_resource->Border(shadow_bounds));
107 panel_shadow_->SetAperture(panel_shadow_resource->aperture); 118 panel_shadow_->SetAperture(panel_shadow_resource->aperture);
108 panel_shadow_->SetBounds(shadow_bounds); 119 panel_shadow_->SetBounds(shadow_bounds);
109 gfx::Point shadow_position( 120 gfx::Point shadow_position(
110 -shadow_res_padding.origin().x(), 121 -shadow_res_padding.origin().x(),
111 -shadow_res_padding.origin().y()); 122 -shadow_res_padding.origin().y());
112 panel_shadow_->SetPosition(shadow_position); 123 panel_shadow_->SetPosition(shadow_position);
113 124
114 // --------------------------------------------------------------------------- 125 // ---------------------------------------------------------------------------
126 // Peek Promo
127 // ---------------------------------------------------------------------------
128 if (search_peek_promo_visible) {
129 // Grabs the Search Opt Out Promo resource.
130 ui::ResourceManager::Resource* search_peek_promo_resource =
131 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
132 peek_promo_text_resource_id);
133
134 ui::ResourceManager::Resource* peek_promo_ripple_resource =
135 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
136 peek_promo_ripple_resource_id);
137
138 // Peek Promo Container
Theresa 2015/10/02 17:34:45 nit: add a //-------------- line above this line?
pedro (no code reviews) 2015/10/02 20:29:08 It was intentional, supposed to be more subtle tha
139 // -----------------------------------------------------------------
140 if (peek_promo_container_->parent() != layer_) {
141 layer_->AddChild(peek_promo_container_);
142 }
143
144 gfx::Size peek_promo_size(search_panel_width, search_peek_promo_height);
145 peek_promo_container_->SetBounds(peek_promo_size);
146 peek_promo_container_->SetPosition(gfx::PointF(0.f, 0.f));
147 peek_promo_container_->SetMasksToBounds(true);
148
149 // Apply a 25% blend based on the ripple opacity. The resulting color
150 // will be an interpolation of the background color of the Search Bar,
151 // and a lighter shade of the background color of the ripple.
152 peek_promo_container_->SetBackgroundColor(
153 color_utils::AlphaBlend(kPeekPromoRippleBackgroundColor,
pedro (no code reviews) 2015/10/02 10:35:53 Question to reviewers: should I be concerned about
David Trainor- moved to gerrit 2015/10/02 20:49:20 IIRC this isn't very expensive right? It just nor
pedro (no code reviews) 2015/10/02 22:15:57 Yeah, pretty much. Then it converts back to back t
154 kSearchBarBackgroundColor,
155 63 * search_peek_promo_ripple_opacity));
156
157 // Peek Promo Ripple
158 // -----------------------------------------------------------------
159 gfx::Size peek_promo_ripple_size(
160 search_peek_promo_ripple_width, search_peek_promo_height);
161 gfx::Rect peek_promo_ripple_border(
162 peek_promo_ripple_resource->Border(peek_promo_ripple_size));
163
164 // Add padding so the ripple will occupy the whole width at 100%.
165 peek_promo_ripple_size.set_width(
166 peek_promo_ripple_size.width() + peek_promo_ripple_border.width());
167
168 float ripple_rotation = 0.f;
169 float ripple_left = 0.f;
170 if (is_rtl) {
171 // Rotate the ripple 180 degrees to make it point to the left side.
172 ripple_rotation = 180.f;
173 ripple_left = search_panel_width - peek_promo_ripple_size.width();
174 }
175
176 peek_promo_ripple_->SetUIResourceId(
177 peek_promo_ripple_resource->ui_resource->id());
178 peek_promo_ripple_->SetBorder(peek_promo_ripple_border);
179 peek_promo_ripple_->SetAperture(peek_promo_ripple_resource->aperture);
180 peek_promo_ripple_->SetBounds(peek_promo_ripple_size);
181 peek_promo_ripple_->SetPosition(gfx::PointF(ripple_left, 0.f));
182 peek_promo_ripple_->SetOpacity(search_peek_promo_ripple_opacity);
183
184 if (ripple_rotation != 0.f) {
185 // Apply rotation about the center of the resource.
186 float pivot_x = floor(peek_promo_ripple_size.width() / 2);
187 float pivot_y = floor(peek_promo_ripple_size.height() / 2);
188 gfx::PointF pivot_origin(pivot_x, pivot_y);
189 gfx::Transform transform;
190 transform.Translate(pivot_origin.x(), pivot_origin.y());
191 transform.RotateAboutZAxis(ripple_rotation);
192 transform.Translate(-pivot_origin.x(), -pivot_origin.y());
193 peek_promo_ripple_->SetTransform(transform);
194 }
195
196 // Peek Promo Text
197 // -----------------------------------------------------------------
198 if (search_peek_promo_resource) {
199 peek_promo_text_->SetUIResourceId(
Theresa 2015/10/02 17:34:45 Does the "NEW" button and promo text get reversed
pedro (no code reviews) 2015/10/02 20:29:09 Yes.
200 search_peek_promo_resource->ui_resource->id());
201 peek_promo_text_->SetBounds(search_peek_promo_resource->size);
202 peek_promo_text_->SetPosition(
203 gfx::PointF(0.f, search_peek_promo_padding));
204 peek_promo_text_->SetOpacity(search_peek_promo_text_opacity);
205 }
206 } else {
207 // Peek Promo Container
208 if (peek_promo_container_.get() && peek_promo_container_->parent())
209 peek_promo_container_->RemoveFromParent();
210 }
211
212 // ---------------------------------------------------------------------------
115 // Search Bar Background 213 // Search Bar Background
116 // --------------------------------------------------------------------------- 214 // ---------------------------------------------------------------------------
117 gfx::Size background_size(search_panel_width, search_bar_height); 215 gfx::Size background_size(search_panel_width, search_bar_height);
118 search_bar_background_->SetBounds(background_size); 216 search_bar_background_->SetBounds(background_size);
119 search_bar_background_->SetPosition(gfx::PointF(0.f, 0.f)); 217 search_bar_background_->SetPosition(gfx::PointF(0.f, search_bar_top));
120 218
121 // --------------------------------------------------------------------------- 219 // ---------------------------------------------------------------------------
122 // Search Bar Text 220 // Search Bar Text
123 // --------------------------------------------------------------------------- 221 // ---------------------------------------------------------------------------
124 if (search_context_resource) { 222 if (search_context_resource) {
125 // Centers the text vertically in the Search Bar. 223 // Centers the text vertically in the Search Bar.
126 float search_bar_padding_top = 224 float search_bar_padding_top =
225 search_bar_top +
127 search_bar_height / 2 - 226 search_bar_height / 2 -
128 search_context_resource->size.height() / 2; 227 search_context_resource->size.height() / 2;
129 search_context_->SetUIResourceId( 228 search_context_->SetUIResourceId(
130 search_context_resource->ui_resource->id()); 229 search_context_resource->ui_resource->id());
131 search_context_->SetBounds(search_context_resource->size); 230 search_context_->SetBounds(search_context_resource->size);
132 search_context_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); 231 search_context_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
133 search_context_->SetOpacity(search_context_opacity); 232 search_context_->SetOpacity(search_context_opacity);
134 } 233 }
135 234
136 if (search_term_resource) { 235 if (search_term_resource) {
137 // Centers the text vertically in the Search Bar. 236 // Centers the text vertically in the Search Bar.
138 float search_bar_padding_top = 237 float search_bar_padding_top =
238 search_bar_top +
139 search_bar_height / 2 - 239 search_bar_height / 2 -
140 search_term_resource->size.height() / 2; 240 search_term_resource->size.height() / 2;
141 search_term_->SetUIResourceId(search_term_resource->ui_resource->id()); 241 search_term_->SetUIResourceId(search_term_resource->ui_resource->id());
142 search_term_->SetBounds(search_term_resource->size); 242 search_term_->SetBounds(search_term_resource->size);
143 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top)); 243 search_term_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
144 search_term_->SetOpacity(search_term_opacity); 244 search_term_->SetOpacity(search_term_opacity);
145 } 245 }
146 246
147 // --------------------------------------------------------------------------- 247 // ---------------------------------------------------------------------------
148 // Search Provider Icon 248 // Search Provider Icon
149 // --------------------------------------------------------------------------- 249 // ---------------------------------------------------------------------------
150 // Positions the Search Provider Icon at the start of the Search Bar. 250 // Positions the Search Provider Icon at the start of the Search Bar.
151 float search_provider_icon_left; 251 float search_provider_icon_left;
152 if (is_rtl) { 252 if (is_rtl) {
153 search_provider_icon_left = search_panel_width - 253 search_provider_icon_left = search_panel_width -
154 search_provider_icon_resource->size.width() - search_bar_margin_side; 254 search_provider_icon_resource->size.width() - search_bar_margin_side;
155 } else { 255 } else {
156 search_provider_icon_left = search_bar_margin_side; 256 search_provider_icon_left = search_bar_margin_side;
157 } 257 }
158 258
159 // Centers the Search Provider Icon vertically in the Search Bar. 259 // Centers the Search Provider Icon vertically in the Search Bar.
160 float search_provider_icon_top = 260 float search_provider_icon_top = search_bar_top +
161 search_bar_height / 2 - 261 search_bar_height / 2 -
162 search_provider_icon_resource->size.height() / 2; 262 search_provider_icon_resource->size.height() / 2;
163 263
164 search_provider_icon_->SetUIResourceId( 264 search_provider_icon_->SetUIResourceId(
165 search_provider_icon_resource->ui_resource->id()); 265 search_provider_icon_resource->ui_resource->id());
166 search_provider_icon_->SetBounds(search_provider_icon_resource->size); 266 search_provider_icon_->SetBounds(search_provider_icon_resource->size);
167 search_provider_icon_->SetPosition( 267 search_provider_icon_->SetPosition(
168 gfx::PointF(search_provider_icon_left, search_provider_icon_top)); 268 gfx::PointF(search_provider_icon_left, search_provider_icon_top));
169 269
170 // --------------------------------------------------------------------------- 270 // ---------------------------------------------------------------------------
171 // Arrow Icon 271 // Arrow Icon
172 // --------------------------------------------------------------------------- 272 // ---------------------------------------------------------------------------
173 // Grabs the Search Arrow Icon resource. 273 // Grabs the Search Arrow Icon resource.
174 ui::ResourceManager::Resource* arrow_icon_resource = 274 ui::ResourceManager::Resource* arrow_icon_resource =
175 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 275 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
176 arrow_up_resource_id); 276 arrow_up_resource_id);
177 277
178 // Positions the icon at the end of the Search Bar. 278 // Positions the icon at the end of the Search Bar.
179 float arrow_icon_left; 279 float arrow_icon_left;
180 if (is_rtl) { 280 if (is_rtl) {
181 arrow_icon_left = search_bar_margin_side; 281 arrow_icon_left = search_bar_margin_side;
182 } else { 282 } else {
183 arrow_icon_left = search_panel_width - 283 arrow_icon_left = search_panel_width -
184 arrow_icon_resource->size.width() - search_bar_margin_side; 284 arrow_icon_resource->size.width() - search_bar_margin_side;
185 } 285 }
186 286
187 // Centers the Arrow Icon vertically in the Search Bar. 287 // Centers the Arrow Icon vertically in the Search Bar.
188 float arrow_icon_top = search_bar_height / 2 - 288 float arrow_icon_top = search_bar_top +
289 search_bar_height / 2 -
189 arrow_icon_resource->size.height() / 2; 290 arrow_icon_resource->size.height() / 2;
190 291
191 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource->id()); 292 arrow_icon_->SetUIResourceId(arrow_icon_resource->ui_resource->id());
192 arrow_icon_->SetBounds(arrow_icon_resource->size); 293 arrow_icon_->SetBounds(arrow_icon_resource->size);
193 arrow_icon_->SetPosition( 294 arrow_icon_->SetPosition(
194 gfx::PointF(arrow_icon_left, arrow_icon_top)); 295 gfx::PointF(arrow_icon_left, arrow_icon_top));
195 arrow_icon_->SetOpacity(arrow_icon_opacity); 296 arrow_icon_->SetOpacity(arrow_icon_opacity);
196 297
197 gfx::Transform transform; 298 gfx::Transform transform;
198 if (arrow_icon_rotation != 0.f) { 299 if (arrow_icon_rotation != 0.f) {
(...skipping 19 matching lines...) Expand all
218 float close_icon_left; 319 float close_icon_left;
219 if (is_rtl) { 320 if (is_rtl) {
220 close_icon_left = search_bar_margin_side; 321 close_icon_left = search_bar_margin_side;
221 } else { 322 } else {
222 close_icon_left = search_panel_width - 323 close_icon_left = search_panel_width -
223 close_icon_resource->size.width() - search_bar_margin_side; 324 close_icon_resource->size.width() - search_bar_margin_side;
224 } 325 }
225 326
226 // Centers the Close Icon vertically in the Search Bar. 327 // Centers the Close Icon vertically in the Search Bar.
227 float close_icon_top = 328 float close_icon_top =
329 search_bar_top +
228 search_bar_height / 2 - 330 search_bar_height / 2 -
229 close_icon_resource->size.height() / 2; 331 close_icon_resource->size.height() / 2;
230 332
231 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id()); 333 close_icon_->SetUIResourceId(close_icon_resource->ui_resource->id());
232 close_icon_->SetBounds(close_icon_resource->size); 334 close_icon_->SetBounds(close_icon_resource->size);
233 close_icon_->SetPosition( 335 close_icon_->SetPosition(
234 gfx::PointF(close_icon_left, close_icon_top)); 336 gfx::PointF(close_icon_left, close_icon_top));
235 close_icon_->SetOpacity(close_icon_opacity); 337 close_icon_->SetOpacity(close_icon_opacity);
236 338
237 // --------------------------------------------------------------------------- 339 // ---------------------------------------------------------------------------
238 // Search Promo 340 // Search Promo
239 // --------------------------------------------------------------------------- 341 // ---------------------------------------------------------------------------
240 if (search_promo_visible) { 342 if (search_promo_visible) {
241 // Grabs the Search Opt Out Promo resource. 343 // Grabs the Search Opt Out Promo resource.
242 ui::ResourceManager::Resource* search_promo_resource = 344 ui::ResourceManager::Resource* search_promo_resource =
243 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 345 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
244 search_promo_resource_id); 346 search_promo_resource_id);
245 // Search Promo Container 347 // Search Promo Container
246 if (search_promo_container_->parent() != layer_) { 348 if (search_promo_container_->parent() != layer_) {
247 // NOTE(pedrosimonetti): The Promo layer should be always placed before 349 // NOTE(pedrosimonetti): The Promo layer should be always placed before
248 // Search Bar Shadow to make sure it won't occlude the shadow. 350 // Search Bar Shadow to make sure it won't occlude the shadow.
249 layer_->InsertChild(search_promo_container_, 0); 351 layer_->InsertChild(search_promo_container_, 0);
250 } 352 }
251 353
252 if (search_promo_resource) { 354 if (search_promo_resource) {
253 int search_promo_content_height = search_promo_resource->size.height(); 355 int search_promo_content_height = search_promo_resource->size.height();
254 gfx::Size search_promo_size(search_panel_width, search_promo_height); 356 gfx::Size search_promo_size(search_panel_width, search_promo_height);
255 search_promo_container_->SetBounds(search_promo_size); 357 search_promo_container_->SetBounds(search_promo_size);
256 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_height)); 358 search_promo_container_->SetPosition(gfx::PointF(0.f, search_bar_bottom));
257 search_promo_container_->SetMasksToBounds(true); 359 search_promo_container_->SetMasksToBounds(true);
258 360
259 // Search Promo 361 // Search Promo
260 if (search_promo_->parent() != search_promo_container_) 362 if (search_promo_->parent() != search_promo_container_)
261 search_promo_container_->AddChild(search_promo_); 363 search_promo_container_->AddChild(search_promo_);
262 364
263 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id()); 365 search_promo_->SetUIResourceId(search_promo_resource->ui_resource->id());
264 search_promo_->SetBounds(search_promo_resource->size); 366 search_promo_->SetBounds(search_promo_resource->size);
265 // Align promo at the bottom of the container so the confirmation button 367 // Align promo at the bottom of the container so the confirmation button
266 // is is not clipped when resizing the promo. 368 // is is not clipped when resizing the promo.
267 search_promo_->SetPosition( 369 search_promo_->SetPosition(
268 gfx::PointF(0.f, search_promo_height - search_promo_content_height)); 370 gfx::PointF(0.f, search_promo_height - search_promo_content_height));
269 search_promo_->SetOpacity(search_promo_opacity); 371 search_promo_->SetOpacity(search_promo_opacity);
270 } 372 }
271 } else { 373 } else {
272 // Search Promo Container 374 // Search Promo Container
273 if (search_promo_container_.get() && search_promo_container_->parent()) 375 if (search_promo_container_.get() && search_promo_container_->parent())
274 search_promo_container_->RemoveFromParent(); 376 search_promo_container_->RemoveFromParent();
275 } 377 }
276 378
277 // --------------------------------------------------------------------------- 379 // ---------------------------------------------------------------------------
278 // Search Content View 380 // Search Content View
279 // --------------------------------------------------------------------------- 381 // ---------------------------------------------------------------------------
280 content_view_container_->SetPosition( 382 content_view_container_->SetPosition(
281 gfx::PointF(0.f, search_bar_height + search_promo_height)); 383 gfx::PointF(0.f, search_bar_bottom + search_promo_height));
282 if (content_view_core && content_view_core->GetLayer().get()) { 384 if (content_view_core && content_view_core->GetLayer().get()) {
283 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer(); 385 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer();
284 if (content_view_layer->parent() != content_view_container_) 386 if (content_view_layer->parent() != content_view_container_)
285 content_view_container_->AddChild(content_view_layer); 387 content_view_container_->AddChild(content_view_layer);
286 } else { 388 } else {
287 content_view_container_->RemoveAllChildren(); 389 content_view_container_->RemoveAllChildren();
288 } 390 }
289 391
290 // --------------------------------------------------------------------------- 392 // ---------------------------------------------------------------------------
291 // Search Bar Shadow 393 // Search Bar Shadow
292 // --------------------------------------------------------------------------- 394 // ---------------------------------------------------------------------------
293 if (search_bar_shadow_visible) { 395 if (search_bar_shadow_visible) {
294 ui::ResourceManager::Resource* search_bar_shadow_resource = 396 ui::ResourceManager::Resource* search_bar_shadow_resource =
295 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 397 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
296 search_bar_shadow_resource_id); 398 search_bar_shadow_resource_id);
297 399
298 if (search_bar_shadow_resource) { 400 if (search_bar_shadow_resource) {
299 if (search_bar_shadow_->parent() != layer_) 401 if (search_bar_shadow_->parent() != layer_)
300 layer_->AddChild(search_bar_shadow_); 402 layer_->AddChild(search_bar_shadow_);
301 403
302 int shadow_height = search_bar_shadow_resource->size.height(); 404 int shadow_height = search_bar_shadow_resource->size.height();
303 gfx::Size shadow_size(search_panel_width, shadow_height); 405 gfx::Size shadow_size(search_panel_width, shadow_height);
304 406
305 search_bar_shadow_->SetUIResourceId( 407 search_bar_shadow_->SetUIResourceId(
306 search_bar_shadow_resource->ui_resource->id()); 408 search_bar_shadow_resource->ui_resource->id());
307 search_bar_shadow_->SetBounds(shadow_size); 409 search_bar_shadow_->SetBounds(shadow_size);
308 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_height)); 410 search_bar_shadow_->SetPosition(gfx::PointF(0.f, search_bar_bottom));
309 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity); 411 search_bar_shadow_->SetOpacity(search_bar_shadow_opacity);
310 } 412 }
311 } else { 413 } else {
312 if (search_bar_shadow_.get() && search_bar_shadow_->parent()) 414 if (search_bar_shadow_.get() && search_bar_shadow_->parent())
313 search_bar_shadow_->RemoveFromParent(); 415 search_bar_shadow_->RemoveFromParent();
314 } 416 }
315 417
316 // --------------------------------------------------------------------------- 418 // ---------------------------------------------------------------------------
317 // Search Panel. 419 // Search Panel.
318 // --------------------------------------------------------------------------- 420 // ---------------------------------------------------------------------------
319 layer_->SetPosition(gfx::PointF(search_panel_x, search_panel_y)); 421 layer_->SetPosition(
422 gfx::PointF(search_panel_x, search_panel_y - search_bar_top));
320 423
321 // --------------------------------------------------------------------------- 424 // ---------------------------------------------------------------------------
322 // Progress Bar 425 // Progress Bar
323 // --------------------------------------------------------------------------- 426 // ---------------------------------------------------------------------------
324 bool should_render_progress_bar = 427 bool should_render_progress_bar =
325 progress_bar_visible && progress_bar_opacity > 0.f; 428 progress_bar_visible && progress_bar_opacity > 0.f;
326 if (should_render_progress_bar) { 429 if (should_render_progress_bar) {
327 // Grabs Progress Bar resources. 430 // Grabs Progress Bar resources.
328 ui::ResourceManager::Resource* progress_bar_background_resource = 431 ui::ResourceManager::Resource* progress_bar_background_resource =
329 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 432 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
330 progress_bar_background_resource_id); 433 progress_bar_background_resource_id);
331 ui::ResourceManager::Resource* progress_bar_resource = 434 ui::ResourceManager::Resource* progress_bar_resource =
332 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 435 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
333 progress_bar_resource_id); 436 progress_bar_resource_id);
334 437
335 DCHECK(progress_bar_background_resource); 438 DCHECK(progress_bar_background_resource);
336 DCHECK(progress_bar_resource); 439 DCHECK(progress_bar_resource);
337 440
338 // Progress Bar Background 441 // Progress Bar Background
339 if (progress_bar_background_->parent() != layer_) 442 if (progress_bar_background_->parent() != layer_)
340 layer_->AddChild(progress_bar_background_); 443 layer_->AddChild(progress_bar_background_);
341 444
445 float progress_bar_y = search_bar_bottom - progress_bar_height;
342 gfx::Size progress_bar_background_size(search_panel_width, 446 gfx::Size progress_bar_background_size(search_panel_width,
343 progress_bar_height); 447 progress_bar_height);
448
344 progress_bar_background_->SetUIResourceId( 449 progress_bar_background_->SetUIResourceId(
345 progress_bar_background_resource->ui_resource->id()); 450 progress_bar_background_resource->ui_resource->id());
346 progress_bar_background_->SetBorder( 451 progress_bar_background_->SetBorder(
347 progress_bar_background_resource->Border(progress_bar_background_size)); 452 progress_bar_background_resource->Border(progress_bar_background_size));
348 progress_bar_background_->SetAperture( 453 progress_bar_background_->SetAperture(
349 progress_bar_background_resource->aperture); 454 progress_bar_background_resource->aperture);
350 progress_bar_background_->SetBounds(progress_bar_background_size); 455 progress_bar_background_->SetBounds(progress_bar_background_size);
351 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y)); 456 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y));
352 progress_bar_background_->SetOpacity(progress_bar_opacity); 457 progress_bar_background_->SetOpacity(progress_bar_opacity);
353 458
(...skipping 18 matching lines...) Expand all
372 if (progress_bar_.get() && progress_bar_->parent()) 477 if (progress_bar_.get() && progress_bar_->parent())
373 progress_bar_->RemoveFromParent(); 478 progress_bar_->RemoveFromParent();
374 } 479 }
375 480
376 // --------------------------------------------------------------------------- 481 // ---------------------------------------------------------------------------
377 // Search Bar border. 482 // Search Bar border.
378 // --------------------------------------------------------------------------- 483 // ---------------------------------------------------------------------------
379 if (!should_render_progress_bar && search_bar_border_visible) { 484 if (!should_render_progress_bar && search_bar_border_visible) {
380 gfx::Size search_bar_border_size(search_panel_width, 485 gfx::Size search_bar_border_size(search_panel_width,
381 search_bar_border_height); 486 search_bar_border_height);
487 float border_y = search_bar_bottom - search_bar_border_height;
382 search_bar_border_->SetBounds(search_bar_border_size); 488 search_bar_border_->SetBounds(search_bar_border_size);
383 search_bar_border_->SetPosition(gfx::PointF(0.f, search_bar_border_y)); 489 search_bar_border_->SetPosition(
490 gfx::PointF(0.f, border_y));
384 layer_->AddChild(search_bar_border_); 491 layer_->AddChild(search_bar_border_);
385 } else if (search_bar_border_.get() && search_bar_border_->parent()) { 492 } else if (search_bar_border_.get() && search_bar_border_->parent()) {
386 search_bar_border_->RemoveFromParent(); 493 search_bar_border_->RemoveFromParent();
387 } 494 }
388 } 495 }
389 496
390 ContextualSearchLayer::ContextualSearchLayer( 497 ContextualSearchLayer::ContextualSearchLayer(
391 ui::ResourceManager* resource_manager) 498 ui::ResourceManager* resource_manager)
392 : resource_manager_(resource_manager), 499 : resource_manager_(resource_manager),
393 layer_(cc::Layer::Create(content::Compositor::LayerSettings())), 500 layer_(cc::Layer::Create(content::Compositor::LayerSettings())),
(...skipping 17 matching lines...) Expand all
411 cc::Layer::Create(content::Compositor::LayerSettings())), 518 cc::Layer::Create(content::Compositor::LayerSettings())),
412 search_bar_border_( 519 search_bar_border_(
413 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())), 520 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
414 progress_bar_( 521 progress_bar_(
415 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 522 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
416 progress_bar_background_( 523 progress_bar_background_(
417 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())), 524 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
418 search_promo_( 525 search_promo_(
419 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())), 526 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
420 search_promo_container_( 527 search_promo_container_(
421 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())) { 528 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
529 peek_promo_container_(
530 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
531 peek_promo_ripple_(
532 cc::NinePatchLayer::Create(content::Compositor::LayerSettings())),
533 peek_promo_text_(
534 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())) {
422 layer_->SetMasksToBounds(false); 535 layer_->SetMasksToBounds(false);
423 layer_->SetIsDrawable(true); 536 layer_->SetIsDrawable(true);
424 537
425 // Panel Shadow 538 // Panel Shadow
426 panel_shadow_->SetIsDrawable(true); 539 panel_shadow_->SetIsDrawable(true);
427 panel_shadow_->SetFillCenter(false); 540 panel_shadow_->SetFillCenter(false);
428 layer_->AddChild(panel_shadow_); 541 layer_->AddChild(panel_shadow_);
429 542
543 // Search Peek Promo
544 peek_promo_container_->SetIsDrawable(true);
545 peek_promo_container_->SetBackgroundColor(kSearchBarBackgroundColor);
546 peek_promo_ripple_->SetIsDrawable(true);
547 peek_promo_ripple_->SetFillCenter(true);
548 peek_promo_text_->SetIsDrawable(true);
549 peek_promo_container_->AddChild(peek_promo_ripple_);
550 peek_promo_container_->AddChild(peek_promo_text_);
551
430 // Search Bar Background 552 // Search Bar Background
431 search_bar_background_->SetIsDrawable(true); 553 search_bar_background_->SetIsDrawable(true);
432 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor); 554 search_bar_background_->SetBackgroundColor(kSearchBarBackgroundColor);
433 layer_->AddChild(search_bar_background_); 555 layer_->AddChild(search_bar_background_);
434 556
435 // Search Bar Text 557 // Search Bar Text
436 search_context_->SetIsDrawable(true); 558 search_context_->SetIsDrawable(true);
437 layer_->AddChild(search_context_); 559 layer_->AddChild(search_context_);
438 search_term_->SetIsDrawable(true); 560 search_term_->SetIsDrawable(true);
439 layer_->AddChild(search_term_); 561 layer_->AddChild(search_term_);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 598
477 ContextualSearchLayer::~ContextualSearchLayer() { 599 ContextualSearchLayer::~ContextualSearchLayer() {
478 } 600 }
479 601
480 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() { 602 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
481 return layer_; 603 return layer_;
482 } 604 }
483 605
484 } // namespace android 606 } // namespace android
485 } // namespace chrome 607 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698