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

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

Issue 1141283003: Upstream oodles of Chrome for Android code into Chromium. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: final patch? Created 5 years, 7 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/compositor/layer/tab_handle_layer.h"
6
7 #include "base/i18n/rtl.h"
8 #include "cc/layers/layer.h"
9 #include "cc/layers/solid_color_layer.h"
10 #include "chrome/browser/android/compositor/decoration_title.h"
11 #include "chrome/browser/android/compositor/layer_title_cache.h"
12 #include "ui/android/resources/resource_manager.h"
13 #include "ui/android/resources/ui_resource_android.h"
14 #include "ui/base/l10n/l10n_util_android.h"
15
16 namespace chrome {
17 namespace android {
18
19 // static
20 scoped_refptr<TabHandleLayer> TabHandleLayer::Create(
21 LayerTitleCache* layer_title_cache) {
22 return make_scoped_refptr(new TabHandleLayer(layer_title_cache));
23 }
24
25 void TabHandleLayer::SetProperties(
26 int id,
27 ui::ResourceManager::Resource* close_button_resource,
28 ui::ResourceManager::Resource* tab_handle_resource,
29 bool foreground,
30 bool close_pressed,
31 float toolbar_width,
32 float x,
33 float y,
34 float width,
35 float height,
36 float content_offset_x,
37 float close_button_alpha,
38 bool is_loading,
39 float spinner_rotation,
40 float brightness,
41 float border_opacity) {
42 if (brightness != brightness_ || foreground != foreground_) {
43 brightness_ = brightness;
44 foreground_ = foreground;
45 cc::FilterOperations filters;
46 if (brightness_ != 1.0f && !foreground_)
47 filters.Append(cc::FilterOperation::CreateBrightnessFilter(brightness_));
48 layer_->SetFilters(filters);
49 }
50
51 float original_x = x;
52 float original_y = y;
53 if (foreground_) {
54 if (!border_->parent()) {
55 layer_->InsertChild(border_, 0);
56 border_->SetIsDrawable(true);
57 }
58 border_->SetBackgroundColor(SK_ColorBLACK);
59 border_->SetPosition(gfx::PointF(0, height - 1));
60 border_->SetBounds(gfx::Size(toolbar_width, 1));
61 border_->SetOpacity(border_opacity);
62
63 x = 0;
64 y = 0;
65 } else if (border_->parent()) {
66 border_->RemoveFromParent();
67 }
68
69 bool is_rtl = l10n_util::IsLayoutRtl();
70
71 float margin_width =
72 tab_handle_resource->size.width() - tab_handle_resource->aperture.width();
73 float margin_height = tab_handle_resource->size.height() -
74 tab_handle_resource->aperture.height();
75
76 // In the inset case, the |decoration_tab_| nine-patch layer should not have a
77 // margin that is greater than the content size of the layer. This case can
78 // happen at initialization. The sizes used below are just temp values until
79 // the real content sizes arrive.
80 if (margin_width >= width) {
81 // Shift the left edge over by the adjusted amount for more
82 // aesthetic animations.
83 x = x - (margin_width - width);
84 width = margin_width;
85 }
86 if (margin_height >= height) {
87 y = y - (margin_height - height);
88 height = margin_height;
89 }
90 gfx::Size tab_bounds(width, height);
91
92 layer_->SetPosition(gfx::Point(x, y));
93 DecorationTitle* title_layer = nullptr;
94 if (layer_title_cache_)
95 title_layer = layer_title_cache_->GetTitleLayer(id);
96
97 if (title_layer) {
98 title_layer->setOpacity(1.0f);
99 unsigned expected_children = 3;
100 if (foreground_)
101 expected_children += 1;
102 title_layer_ = title_layer->layer();
103 if (layer_->children().size() < expected_children) {
104 layer_->AddChild(title_layer_);
105 } else if (layer_->children()[expected_children - 1]->id() !=
106 title_layer_->id()) {
107 layer_->ReplaceChild((layer_->children()[expected_children - 1]).get(),
108 title_layer_);
109 }
110 title_layer->SetUIResourceIds();
111 } else if (title_layer_.get()) {
112 title_layer_->RemoveFromParent();
113 title_layer_ = nullptr;
114 }
115
116 decoration_tab_->SetUIResourceId(tab_handle_resource->ui_resource->id());
117 decoration_tab_->SetAperture(tab_handle_resource->aperture);
118 decoration_tab_->SetFillCenter(true);
119 decoration_tab_->SetBounds(tab_bounds);
120 decoration_tab_->SetBorder(
121 tab_handle_resource->Border(decoration_tab_->bounds()));
122
123 if (foreground_)
124 decoration_tab_->SetPosition(gfx::PointF(original_x, original_y));
125 else
126 decoration_tab_->SetPosition(gfx::PointF(0, 0));
127
128 close_button_->SetUIResourceId(close_button_resource->ui_resource->id());
129 close_button_->SetBounds(close_button_resource->size);
130 const float padding_right =
131 tab_handle_resource->size.width() - tab_handle_resource->padding.right();
132 const float padding_left = tab_handle_resource->padding.x();
133 const float close_width = close_button_->bounds().width();
134 if (title_layer) {
135 int title_y = tab_handle_resource->padding.y() / 2 + height / 2 -
136 title_layer->size().height() / 2;
137 int title_x = is_rtl ? padding_left + close_width : padding_left;
138 title_x += is_rtl ? 0 : content_offset_x;
139 title_layer->setBounds(gfx::Size(
140 width - padding_right - padding_left - close_width - content_offset_x,
141 height));
142 if (foreground_) {
143 title_x += original_x;
144 title_y += original_y;
145 }
146 title_layer->layer()->SetPosition(gfx::Point(title_x, title_y));
147 if (is_loading) {
148 title_layer->SetIsLoading(true);
149 title_layer->SetSpinnerRotation(spinner_rotation);
150 } else {
151 title_layer->SetIsLoading(false);
152 }
153 }
154
155 if (close_button_alpha == 0.f) {
156 close_button_->SetIsDrawable(false);
157 } else {
158 close_button_->SetIsDrawable(true);
159 const float close_max_width = close_button_->bounds().width();
160 int close_y = (tab_handle_resource->padding.y() + height) / 2 -
161 close_button_->bounds().height() / 2;
162 int close_x = is_rtl ? padding_left - close_max_width + close_width
163 : width - padding_right - close_width;
164 if (foreground_) {
165 close_y += original_y;
166 close_x += original_x;
167 }
168
169 close_button_->SetPosition(gfx::PointF(close_x, close_y));
170 close_button_->SetOpacity(close_button_alpha);
171 }
172 }
173
174 scoped_refptr<cc::Layer> TabHandleLayer::layer() {
175 return layer_;
176 }
177
178 TabHandleLayer::TabHandleLayer(LayerTitleCache* layer_title_cache)
179 : layer_title_cache_(layer_title_cache),
180 layer_(cc::Layer::Create()),
181 close_button_(cc::UIResourceLayer::Create()),
182 decoration_tab_(cc::NinePatchLayer::Create()),
183 border_(cc::SolidColorLayer::Create()),
184 brightness_(1.0f),
185 foreground_(false) {
186 decoration_tab_->SetIsDrawable(true);
187 layer_->AddChild(decoration_tab_);
188 layer_->AddChild(close_button_);
189 }
190
191 TabHandleLayer::~TabHandleLayer() {
192 }
193
194 } // namespace android
195 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698