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

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

Issue 787023002: Upstream more layers, decoration title, layer_title_cache (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: updated creation year Created 6 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/compositor/layer/contextual_search_layer.h"
6
7 #include "cc/layers/layer.h"
8 #include "cc/layers/nine_patch_layer.h"
9 #include "cc/layers/solid_color_layer.h"
10 #include "cc/layers/ui_resource_layer.h"
11 #include "content/public/browser/android/content_view_core.h"
12 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/android/resources/resource_manager.h"
14 #include "ui/android/resources/ui_resource_android.h"
15
16 namespace {
17
18 const SkColor kContextualSearchBarBorderColor = SkColorSetRGB(0xf1, 0xf1, 0xf1);
19
20 } // namespace
21
22 namespace chrome {
23 namespace android {
24
25 // static
26 scoped_refptr<ContextualSearchLayer> ContextualSearchLayer::Create(
27 ui::ResourceManager* resource_manager) {
28 return make_scoped_refptr(new ContextualSearchLayer(resource_manager));
29 }
30
31 void ContextualSearchLayer::SetProperties(
32 int search_bar_background_resource_id,
33 int search_bar_text_resource_id,
34 int search_provider_icon_resource_id,
35 int search_icon_resource_id,
36 int progress_bar_background_resource_id,
37 int progress_bar_resource_id,
38 content::ContentViewCore* content_view_core,
39 float search_panel_y,
40 float search_panel_width,
41 float search_bar_margin_top,
42 float search_bar_height,
43 float search_bar_text_opacity,
44 bool search_bar_border_visible,
45 float search_bar_border_y,
46 float search_bar_border_height,
47 float search_provider_icon_opacity,
48 float search_icon_padding_left,
49 float search_icon_opacity,
50 bool progress_bar_visible,
51 float progress_bar_y,
52 float progress_bar_height,
53 float progress_bar_opacity,
54 int progress_bar_completion) {
55 // Grab the dynamic Search Bar Text resource.
56 ui::ResourceManager::Resource* search_bar_text_resource =
57 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
58 search_bar_text_resource_id);
59
60 // Grab required static resources.
61 ui::ResourceManager::Resource* search_bar_background_resource =
62 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
63 search_bar_background_resource_id);
64 ui::ResourceManager::Resource* search_provider_icon_resource =
65 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
66 search_provider_icon_resource_id);
67 ui::ResourceManager::Resource* search_icon_resource =
68 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
69 search_icon_resource_id);
70
71 DCHECK(search_bar_background_resource);
72 DCHECK(search_provider_icon_resource);
73 DCHECK(search_icon_resource);
74
75 // ---------------------------------------------------------------------------
76 // Search Bar Background
77 // ---------------------------------------------------------------------------
78 gfx::Size background_size(search_panel_width, search_bar_height);
79 search_bar_background_->SetUIResourceId(
80 search_bar_background_resource->ui_resource->id());
81 search_bar_background_->SetBorder(
82 search_bar_background_resource->Border(background_size));
83 search_bar_background_->SetAperture(search_bar_background_resource->aperture);
84 search_bar_background_->SetBounds(background_size);
85
86 // ---------------------------------------------------------------------------
87 // Search Bar Text
88 // ---------------------------------------------------------------------------
89 if (search_bar_text_resource) {
90 // Centralizes the text vertically in the Search Bar.
91 float search_bar_padding_top =
92 search_bar_margin_top +
93 (search_bar_height - search_bar_margin_top) / 2 -
94 search_bar_text_resource->size.height() / 2;
95 search_bar_text_->SetUIResourceId(
96 search_bar_text_resource->ui_resource->id());
97 search_bar_text_->SetBounds(search_bar_text_resource->size);
98 search_bar_text_->SetPosition(gfx::PointF(0.f, search_bar_padding_top));
99 search_bar_text_->SetOpacity(search_bar_text_opacity);
100 }
101
102 // ---------------------------------------------------------------------------
103 // Search Provider Icon
104 // ---------------------------------------------------------------------------
105 // Centralizes the Search Provider Icon horizontally in the Search Bar.
106 float search_provider_icon_left =
107 search_panel_width / 2.f -
108 search_provider_icon_resource->size.width() / 2.f;
109 search_provider_icon_->SetUIResourceId(
110 search_provider_icon_resource->ui_resource->id());
111 search_provider_icon_->SetBounds(search_provider_icon_resource->size);
112 search_provider_icon_->SetPosition(
113 gfx::PointF(search_provider_icon_left, 0.f));
114 search_provider_icon_->SetOpacity(search_provider_icon_opacity);
115
116 // ---------------------------------------------------------------------------
117 // Search Icon
118 // ---------------------------------------------------------------------------
119 // Centralizes the Search Icon vertically in the Search Bar.
120 float search_icon_padding_top =
121 search_bar_margin_top + (search_bar_height - search_bar_margin_top) / 2 -
122 search_icon_resource->size.height() / 2;
123 search_icon_->SetUIResourceId(search_icon_resource->ui_resource->id());
124 search_icon_->SetBounds(search_icon_resource->size);
125 search_icon_->SetPosition(
126 gfx::PointF(search_icon_padding_left, search_icon_padding_top));
127 search_icon_->SetOpacity(search_icon_opacity);
128
129 // ---------------------------------------------------------------------------
130 // Search Content View
131 // ---------------------------------------------------------------------------
132 content_view_container_->SetPosition(gfx::PointF(0.f, search_bar_height));
133 if (content_view_core && content_view_core->GetLayer().get()) {
134 scoped_refptr<cc::Layer> content_view_layer = content_view_core->GetLayer();
135 if (content_view_layer->parent() != content_view_container_)
136 content_view_container_->AddChild(content_view_layer);
137 } else {
138 content_view_container_->RemoveAllChildren();
139 }
140
141 // ---------------------------------------------------------------------------
142 // Search Panel.
143 // ---------------------------------------------------------------------------
144 layer_->SetPosition(gfx::PointF(0.f, search_panel_y));
145
146 // ---------------------------------------------------------------------------
147 // Progress Bar
148 // ---------------------------------------------------------------------------
149 bool should_render_progress_bar =
150 progress_bar_visible && progress_bar_opacity > 0.f;
151 if (should_render_progress_bar) {
152 // Load Progress Bar resources.
153 ui::ResourceManager::Resource* progress_bar_background_resource =
154 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
155 progress_bar_background_resource_id);
156 ui::ResourceManager::Resource* progress_bar_resource =
157 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
158 progress_bar_resource_id);
159
160 DCHECK(progress_bar_background_resource);
161 DCHECK(progress_bar_resource);
162
163 // Progress Bar Background
164 if (progress_bar_background_->parent() != layer_)
165 layer_->AddChild(progress_bar_background_);
166
167 gfx::Size progress_bar_background_size(search_panel_width,
168 progress_bar_height);
169 progress_bar_background_->SetUIResourceId(
170 progress_bar_background_resource->ui_resource->id());
171 progress_bar_background_->SetBorder(
172 progress_bar_background_resource->Border(progress_bar_background_size));
173 progress_bar_background_->SetAperture(
174 progress_bar_background_resource->aperture);
175 progress_bar_background_->SetBounds(progress_bar_background_size);
176 progress_bar_background_->SetPosition(gfx::PointF(0.f, progress_bar_y));
177 progress_bar_background_->SetOpacity(progress_bar_opacity);
178
179 // Progress Bar
180 if (progress_bar_->parent() != layer_)
181 layer_->AddChild(progress_bar_);
182
183 float progress_bar_width =
184 floor(search_panel_width * progress_bar_completion / 100.f);
185 gfx::Size progress_bar_size(progress_bar_width, progress_bar_height);
186 progress_bar_->SetUIResourceId(progress_bar_resource->ui_resource->id());
187 progress_bar_->SetBorder(progress_bar_resource->Border(progress_bar_size));
188 progress_bar_->SetAperture(progress_bar_resource->aperture);
189 progress_bar_->SetBounds(progress_bar_size);
190 progress_bar_->SetPosition(gfx::PointF(0.f, progress_bar_y));
191 progress_bar_->SetOpacity(progress_bar_opacity);
192 } else {
193 // Removes Progress Bar and its Background from the Layer Tree.
194 if (progress_bar_background_.get() && progress_bar_background_->parent())
195 progress_bar_background_->RemoveFromParent();
196
197 if (progress_bar_.get() && progress_bar_->parent())
198 progress_bar_->RemoveFromParent();
199 }
200
201 // ---------------------------------------------------------------------------
202 // Search Bar border.
203 // ---------------------------------------------------------------------------
204 if (!should_render_progress_bar && search_bar_border_visible) {
205 gfx::Size search_bar_border_size(search_panel_width,
206 search_bar_border_height);
207 search_bar_border_->SetBounds(search_bar_border_size);
208 search_bar_border_->SetPosition(gfx::PointF(0.f, search_bar_border_y));
209 layer_->AddChild(search_bar_border_);
210 } else if (search_bar_border_.get() && search_bar_border_->parent()) {
211 search_bar_border_->RemoveFromParent();
212 }
213 }
214
215 ContextualSearchLayer::ContextualSearchLayer(
216 ui::ResourceManager* resource_manager)
217 : resource_manager_(resource_manager),
218 layer_(cc::Layer::Create()),
219 search_bar_background_(cc::NinePatchLayer::Create()),
220 search_bar_text_(cc::UIResourceLayer::Create()),
221 search_provider_icon_(cc::UIResourceLayer::Create()),
222 search_icon_(cc::UIResourceLayer::Create()),
223 content_view_container_(cc::Layer::Create()),
224 search_bar_border_(cc::SolidColorLayer::Create()),
225 progress_bar_(cc::NinePatchLayer::Create()),
226 progress_bar_background_(cc::NinePatchLayer::Create()) {
227 layer_->SetMasksToBounds(false);
228 layer_->SetIsDrawable(true);
229
230 // Search Bar Background
231 search_bar_background_->SetIsDrawable(true);
232 search_bar_background_->SetFillCenter(true);
233 layer_->AddChild(search_bar_background_);
234
235 // Search Bar Text
236 search_bar_text_->SetIsDrawable(true);
237 layer_->AddChild(search_bar_text_);
238
239 // Search Provider Icon
240 search_provider_icon_->SetIsDrawable(true);
241 layer_->AddChild(search_provider_icon_);
242
243 // Search Icon
244 search_icon_->SetIsDrawable(true);
245 layer_->AddChild(search_icon_);
246
247 // Search Bar Border
248 search_bar_border_->SetIsDrawable(true);
249 search_bar_border_->SetBackgroundColor(kContextualSearchBarBorderColor);
250
251 // Progress Bar Background
252 progress_bar_background_->SetIsDrawable(true);
253 progress_bar_background_->SetFillCenter(true);
254
255 // Progress Bar
256 progress_bar_->SetIsDrawable(true);
257 progress_bar_->SetFillCenter(true);
258
259 // Search Content View
260 layer_->AddChild(content_view_container_);
261 }
262
263 ContextualSearchLayer::~ContextualSearchLayer() {
264 }
265
266 scoped_refptr<cc::Layer> ContextualSearchLayer::layer() {
267 return layer_;
268 }
269
270 } // namespace android
271 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698