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/toolbar_layer.cc

Issue 2417323002: Move composited toolbar to bottom of screen when Chrome Home is enabled (Closed)
Patch Set: move flag to initializer list Created 4 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/toolbar_layer.h" 5 #include "chrome/browser/android/compositor/layer/toolbar_layer.h"
6 6
7 #include "base/feature_list.h"
7 #include "cc/layers/nine_patch_layer.h" 8 #include "cc/layers/nine_patch_layer.h"
8 #include "cc/layers/solid_color_layer.h" 9 #include "cc/layers/solid_color_layer.h"
9 #include "cc/layers/ui_resource_layer.h" 10 #include "cc/layers/ui_resource_layer.h"
10 #include "cc/resources/scoped_ui_resource.h" 11 #include "cc/resources/scoped_ui_resource.h"
12 #include "chrome/browser/android/chrome_feature_list.h"
11 #include "content/public/browser/android/compositor.h" 13 #include "content/public/browser/android/compositor.h"
12 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
13 #include "ui/android/resources/resource_manager.h" 15 #include "ui/android/resources/resource_manager.h"
14 16
15 namespace android { 17 namespace android {
16 18
17 // static 19 // static
18 scoped_refptr<ToolbarLayer> ToolbarLayer::Create( 20 scoped_refptr<ToolbarLayer> ToolbarLayer::Create(
19 ui::ResourceManager* resource_manager) { 21 ui::ResourceManager* resource_manager) {
20 return make_scoped_refptr(new ToolbarLayer(resource_manager)); 22 return make_scoped_refptr(new ToolbarLayer(resource_manager));
21 } 23 }
22 24
23 scoped_refptr<cc::Layer> ToolbarLayer::layer() { 25 scoped_refptr<cc::Layer> ToolbarLayer::layer() {
24 return layer_; 26 return layer_;
25 } 27 }
26 28
27 void ToolbarLayer::PushResource( 29 void ToolbarLayer::PushResource(
28 int toolbar_resource_id, 30 int toolbar_resource_id,
29 int toolbar_background_color, 31 int toolbar_background_color,
30 bool anonymize, 32 bool anonymize,
31 int toolbar_textbox_background_color, 33 int toolbar_textbox_background_color,
32 int url_bar_background_resource_id, 34 int url_bar_background_resource_id,
33 float url_bar_alpha, 35 float url_bar_alpha,
36 float view_height,
34 bool show_debug, 37 bool show_debug,
35 bool clip_shadow) { 38 bool clip_shadow) {
36 ui::ResourceManager::Resource* resource = 39 ui::ResourceManager::Resource* resource =
37 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC, 40 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_DYNAMIC,
38 toolbar_resource_id); 41 toolbar_resource_id);
39 42
40 // Ensure the toolbar resource is available before making the layer visible. 43 // Ensure the toolbar resource is available before making the layer visible.
41 layer_->SetHideLayerAndSubtree(!resource); 44 layer_->SetHideLayerAndSubtree(!resource);
42 if (!resource) 45 if (!resource)
43 return; 46 return;
44 47
45 // This layer effectively draws over the space it takes for shadows. Set the 48 // This layer effectively draws over the space it takes for shadows. Set the
46 // bounds to the non-shadow size so that other things can properly line up. 49 // bounds to the non-shadow size so that other things can properly line up.
47 // Padding height does not include the height of the tabstrip, so we add 50 // Padding height does not include the height of the tabstrip, so we add
48 // it explicitly by adding y offset. 51 // it explicitly by adding y offset.
49 gfx::Size size = gfx::Size( 52 gfx::Size size = gfx::Size(
50 resource->padding.width(), 53 resource->padding.width(),
51 resource->padding.height() + resource->padding.y()); 54 resource->padding.height() + resource->padding.y());
52 layer_->SetBounds(size); 55 layer_->SetBounds(size);
53 56
57 // The toolbar_root_ contains all of the layers that make up the toolbar. The
58 // toolbar_root_ is moved around inside of layer_ to allow appropriate
59 // clipping of the shadow.
60 toolbar_root_->SetBounds(resource->padding.size());
61
62 gfx::PointF background_position(resource->padding.origin());
63 if (is_chrome_home_enabled_) {
64 float layer_offset =
65 resource->size.height() - resource->padding.size().height();
66 layer_->SetPosition(gfx::PointF(0, view_height));
67 toolbar_root_->SetPosition(gfx::PointF(0, -layer_offset));
68 background_position.set_y(layer_offset);
69 }
70
54 toolbar_background_layer_->SetBounds(resource->padding.size()); 71 toolbar_background_layer_->SetBounds(resource->padding.size());
55 toolbar_background_layer_->SetPosition( 72 toolbar_background_layer_->SetPosition(background_position);
56 gfx::PointF(resource->padding.origin()));
57 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color); 73 toolbar_background_layer_->SetBackgroundColor(toolbar_background_color);
58 74
59 bool url_bar_visible = (resource->aperture.width() != 0); 75 bool url_bar_visible = (resource->aperture.width() != 0);
60 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible); 76 url_bar_background_layer_->SetHideLayerAndSubtree(!url_bar_visible);
61 if (url_bar_visible) { 77 if (url_bar_visible) {
62 ui::ResourceManager::Resource* url_bar_background_resource = 78 ui::ResourceManager::Resource* url_bar_background_resource =
63 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC, 79 resource_manager_->GetResource(ui::ANDROID_RESOURCE_TYPE_STATIC,
64 url_bar_background_resource_id); 80 url_bar_background_resource_id);
65 gfx::Size url_bar_size( 81 gfx::Size url_bar_size(
66 resource->aperture.width() + url_bar_background_resource->size.width() 82 resource->aperture.width() + url_bar_background_resource->size.width()
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 if (is_progress_bar_visible) { 147 if (is_progress_bar_visible) {
132 progress_bar_layer_->SetPosition( 148 progress_bar_layer_->SetPosition(
133 gfx::PointF(progress_bar_x, progress_bar_y)); 149 gfx::PointF(progress_bar_x, progress_bar_y));
134 progress_bar_layer_->SetBounds( 150 progress_bar_layer_->SetBounds(
135 gfx::Size(progress_bar_width, progress_bar_height)); 151 gfx::Size(progress_bar_width, progress_bar_height));
136 progress_bar_layer_->SetBackgroundColor(progress_bar_color); 152 progress_bar_layer_->SetBackgroundColor(progress_bar_color);
137 } 153 }
138 } 154 }
139 155
140 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager) 156 ToolbarLayer::ToolbarLayer(ui::ResourceManager* resource_manager)
141 : resource_manager_(resource_manager), 157 : is_chrome_home_enabled_(
158 base::FeatureList::IsEnabled(chrome::android::kChromeHomeFeature)),
159 resource_manager_(resource_manager),
142 layer_(cc::Layer::Create()), 160 layer_(cc::Layer::Create()),
161 toolbar_root_(cc::Layer::Create()),
143 toolbar_background_layer_(cc::SolidColorLayer::Create()), 162 toolbar_background_layer_(cc::SolidColorLayer::Create()),
144 url_bar_background_layer_(cc::NinePatchLayer::Create()), 163 url_bar_background_layer_(cc::NinePatchLayer::Create()),
145 bitmap_layer_(cc::UIResourceLayer::Create()), 164 bitmap_layer_(cc::UIResourceLayer::Create()),
146 progress_bar_layer_(cc::SolidColorLayer::Create()), 165 progress_bar_layer_(cc::SolidColorLayer::Create()),
147 progress_bar_background_layer_(cc::SolidColorLayer::Create()), 166 progress_bar_background_layer_(cc::SolidColorLayer::Create()),
148 anonymize_layer_(cc::SolidColorLayer::Create()), 167 anonymize_layer_(cc::SolidColorLayer::Create()),
149 debug_layer_(cc::SolidColorLayer::Create()) { 168 debug_layer_(cc::SolidColorLayer::Create()) {
169 layer_->AddChild(toolbar_root_);
170
150 toolbar_background_layer_->SetIsDrawable(true); 171 toolbar_background_layer_->SetIsDrawable(true);
151 layer_->AddChild(toolbar_background_layer_); 172 toolbar_root_->AddChild(toolbar_background_layer_);
152 173
153 url_bar_background_layer_->SetIsDrawable(true); 174 url_bar_background_layer_->SetIsDrawable(true);
154 url_bar_background_layer_->SetFillCenter(true); 175 url_bar_background_layer_->SetFillCenter(true);
155 layer_->AddChild(url_bar_background_layer_); 176 toolbar_root_->AddChild(url_bar_background_layer_);
156 177
157 bitmap_layer_->SetIsDrawable(true); 178 bitmap_layer_->SetIsDrawable(true);
158 layer_->AddChild(bitmap_layer_); 179 toolbar_root_->AddChild(bitmap_layer_);
159 180
160 progress_bar_background_layer_->SetIsDrawable(true); 181 progress_bar_background_layer_->SetIsDrawable(true);
161 progress_bar_background_layer_->SetHideLayerAndSubtree(true); 182 progress_bar_background_layer_->SetHideLayerAndSubtree(true);
162 layer_->AddChild(progress_bar_background_layer_); 183 toolbar_root_->AddChild(progress_bar_background_layer_);
163 184
164 progress_bar_layer_->SetIsDrawable(true); 185 progress_bar_layer_->SetIsDrawable(true);
165 progress_bar_layer_->SetHideLayerAndSubtree(true); 186 progress_bar_layer_->SetHideLayerAndSubtree(true);
166 layer_->AddChild(progress_bar_layer_); 187 toolbar_root_->AddChild(progress_bar_layer_);
167 188
168 anonymize_layer_->SetIsDrawable(true); 189 anonymize_layer_->SetIsDrawable(true);
169 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE); 190 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE);
170 layer_->AddChild(anonymize_layer_); 191 toolbar_root_->AddChild(anonymize_layer_);
171 192
172 debug_layer_->SetIsDrawable(true); 193 debug_layer_->SetIsDrawable(true);
173 debug_layer_->SetBackgroundColor(SK_ColorGREEN); 194 debug_layer_->SetBackgroundColor(SK_ColorGREEN);
174 debug_layer_->SetOpacity(0.5f); 195 debug_layer_->SetOpacity(0.5f);
175 } 196 }
176 197
177 ToolbarLayer::~ToolbarLayer() { 198 ToolbarLayer::~ToolbarLayer() {
178 } 199 }
179 200
180 } // namespace android 201 } // namespace android
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698