Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / android / compositor / layer / toolbar_layer.cc
blob1028e681c970fe0b61e06396a2757f0a52f923f1
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.
5 #include "chrome/browser/android/compositor/layer/toolbar_layer.h"
7 #include "cc/layers/solid_color_layer.h"
8 #include "cc/layers/ui_resource_layer.h"
9 #include "content/public/browser/android/compositor.h"
10 #include "third_party/skia/include/core/SkColor.h"
11 #include "ui/android/resources/resource_manager.h"
12 #include "ui/android/resources/ui_resource_android.h"
14 namespace chrome {
15 namespace android {
17 // static
18 scoped_refptr<ToolbarLayer> ToolbarLayer::Create() {
19 return make_scoped_refptr(new ToolbarLayer());
22 scoped_refptr<cc::Layer> ToolbarLayer::layer() {
23 return layer_;
26 void ToolbarLayer::PushResource(
27 ui::ResourceManager::Resource* resource,
28 bool anonymize,
29 int toolbar_textbox_background_color,
30 bool show_debug,
31 float brightness) {
32 DCHECK(resource);
34 // This layer effectively draws over the space it takes for shadows. Set the
35 // bounds to the non-shadow size so that other things can properly line up.
36 layer_->SetBounds(resource->padding.size());
38 bitmap_layer_->SetUIResourceId(resource->ui_resource->id());
39 bitmap_layer_->SetBounds(resource->size);
41 anonymize_layer_->SetHideLayerAndSubtree(!anonymize);
42 if (anonymize) {
43 anonymize_layer_->SetPosition(resource->aperture.origin());
44 anonymize_layer_->SetBounds(resource->aperture.size());
45 anonymize_layer_->SetBackgroundColor(toolbar_textbox_background_color);
48 debug_layer_->SetBounds(resource->size);
49 if (show_debug && !debug_layer_->parent())
50 layer_->AddChild(debug_layer_);
51 else if (!show_debug && debug_layer_->parent())
52 debug_layer_->RemoveFromParent();
54 if (brightness != brightness_) {
55 brightness_ = brightness;
56 cc::FilterOperations filters;
57 if (brightness_ < 1.f)
58 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_));
59 layer_->SetFilters(filters);
63 void ToolbarLayer::UpdateProgressBar(int progress_bar_x,
64 int progress_bar_y,
65 int progress_bar_width,
66 int progress_bar_height,
67 int progress_bar_color,
68 int progress_bar_background_x,
69 int progress_bar_background_y,
70 int progress_bar_background_width,
71 int progress_bar_background_height,
72 int progress_bar_background_color) {
73 bool is_progress_bar_background_visible = SkColorGetA(
74 progress_bar_background_color);
75 progress_bar_background_layer_->SetHideLayerAndSubtree(
76 !is_progress_bar_background_visible);
77 if (is_progress_bar_background_visible) {
78 progress_bar_background_layer_->SetPosition(
79 gfx::PointF(progress_bar_background_x, progress_bar_background_y));
80 progress_bar_background_layer_->SetBounds(
81 gfx::Size(progress_bar_background_width,
82 progress_bar_background_height));
83 progress_bar_background_layer_->SetBackgroundColor(
84 progress_bar_background_color);
87 bool is_progress_bar_visible = SkColorGetA(progress_bar_background_color);
88 progress_bar_layer_->SetHideLayerAndSubtree(!is_progress_bar_visible);
89 if (is_progress_bar_visible) {
90 progress_bar_layer_->SetPosition(
91 gfx::PointF(progress_bar_x, progress_bar_y));
92 progress_bar_layer_->SetBounds(
93 gfx::Size(progress_bar_width, progress_bar_height));
94 progress_bar_layer_->SetBackgroundColor(progress_bar_color);
98 ToolbarLayer::ToolbarLayer()
99 : layer_(cc::Layer::Create(content::Compositor::LayerSettings())),
100 bitmap_layer_(
101 cc::UIResourceLayer::Create(content::Compositor::LayerSettings())),
102 progress_bar_layer_(
103 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
104 progress_bar_background_layer_(
105 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
106 anonymize_layer_(
107 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
108 debug_layer_(
109 cc::SolidColorLayer::Create(content::Compositor::LayerSettings())),
110 brightness_(1.f) {
111 bitmap_layer_->SetIsDrawable(true);
112 layer_->AddChild(bitmap_layer_);
114 progress_bar_background_layer_->SetIsDrawable(true);
115 progress_bar_background_layer_->SetHideLayerAndSubtree(true);
116 layer_->AddChild(progress_bar_background_layer_);
118 progress_bar_layer_->SetIsDrawable(true);
119 progress_bar_layer_->SetHideLayerAndSubtree(true);
120 layer_->AddChild(progress_bar_layer_);
122 anonymize_layer_->SetIsDrawable(true);
123 anonymize_layer_->SetBackgroundColor(SK_ColorWHITE);
124 layer_->AddChild(anonymize_layer_);
126 debug_layer_->SetIsDrawable(true);
127 debug_layer_->SetBackgroundColor(SK_ColorGREEN);
128 debug_layer_->SetOpacity(0.5f);
131 ToolbarLayer::~ToolbarLayer() {
134 } // namespace android
135 } // namespace chrome