OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/tabs/tab.h" | 5 #include "chrome/browser/ui/views/tabs/tab.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 #include <limits> | 8 #include <limits> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
(...skipping 1125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1136 if (data().blocked == old.blocked) | 1136 if (data().blocked == old.blocked) |
1137 return; | 1137 return; |
1138 | 1138 |
1139 if (data().blocked) | 1139 if (data().blocked) |
1140 StartPulse(); | 1140 StartPulse(); |
1141 else | 1141 else |
1142 StopPulse(); | 1142 StopPulse(); |
1143 } | 1143 } |
1144 | 1144 |
1145 void Tab::PaintTab(gfx::Canvas* canvas, const gfx::Path& clip) { | 1145 void Tab::PaintTab(gfx::Canvas* canvas, const gfx::Path& clip) { |
1146 const int kActiveTabFillId = IDR_THEME_TOOLBAR; | 1146 const int kActiveTabFillId = |
1147 const bool has_custom_image = | 1147 GetThemeProvider()->HasCustomImage(IDR_THEME_TOOLBAR) ? IDR_THEME_TOOLBAR |
1148 GetThemeProvider()->HasCustomImage(kActiveTabFillId); | 1148 : 0; |
1149 const int y_offset = -GetLayoutInsets(TAB).top(); | 1149 const int y_offset = -GetLayoutInsets(TAB).top(); |
1150 if (IsActive()) { | 1150 if (IsActive()) { |
1151 PaintTabBackgroundUsingFillId(canvas, canvas, true, kActiveTabFillId, | 1151 PaintTabBackgroundUsingFillId(canvas, canvas, true, kActiveTabFillId, |
1152 has_custom_image, y_offset); | 1152 y_offset); |
1153 } else { | 1153 } else { |
1154 PaintInactiveTabBackground(canvas, clip); | 1154 PaintInactiveTabBackground(canvas, clip); |
1155 | 1155 |
1156 const double throb_value = GetThrobValue(); | 1156 const double throb_value = GetThrobValue(); |
1157 if (throb_value > 0) { | 1157 if (throb_value > 0) { |
1158 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), | 1158 canvas->SaveLayerAlpha(gfx::ToRoundedInt(throb_value * 0xff), |
1159 GetLocalBounds()); | 1159 GetLocalBounds()); |
1160 PaintTabBackgroundUsingFillId(canvas, canvas, true, kActiveTabFillId, | 1160 PaintTabBackgroundUsingFillId(canvas, canvas, true, kActiveTabFillId, |
1161 has_custom_image, y_offset); | 1161 y_offset); |
1162 canvas->Restore(); | 1162 canvas->Restore(); |
1163 } | 1163 } |
1164 } | 1164 } |
1165 | 1165 |
1166 if (showing_icon_) | 1166 if (showing_icon_) |
1167 PaintIcon(canvas); | 1167 PaintIcon(canvas); |
1168 } | 1168 } |
1169 | 1169 |
1170 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { | 1170 void Tab::PaintImmersiveTab(gfx::Canvas* canvas) { |
1171 // Use transparency for the draw-attention animation. | 1171 // Use transparency for the draw-attention animation. |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1208 bar_rect.x(), 0, left_eye_width, kImmersiveBarHeight); | 1208 bar_rect.x(), 0, left_eye_width, kImmersiveBarHeight); |
1209 canvas->FillRect(left_eye_rect, kEyeColor); | 1209 canvas->FillRect(left_eye_rect, kEyeColor); |
1210 } | 1210 } |
1211 } | 1211 } |
1212 } | 1212 } |
1213 | 1213 |
1214 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas, | 1214 void Tab::PaintInactiveTabBackground(gfx::Canvas* canvas, |
1215 const gfx::Path& clip) { | 1215 const gfx::Path& clip) { |
1216 bool has_custom_image; | 1216 bool has_custom_image; |
1217 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); | 1217 int fill_id = controller_->GetBackgroundResourceId(&has_custom_image); |
1218 | |
1219 // If the theme is providing a custom background image, then its top edge | |
1220 // should be at the top of the tab. Otherwise, we assume that the background | |
1221 // image is a composited foreground + frame image. Note that if the theme is | |
1222 // only providing a custom frame image, |has_custom_image| will be true, but | |
1223 // we should use the |background_offset_| here. | |
1224 const ui::ThemeProvider* tp = GetThemeProvider(); | 1218 const ui::ThemeProvider* tp = GetThemeProvider(); |
1225 const int y_offset = tp->HasCustomImage(fill_id) ? 0 : background_offset_.y(); | |
1226 | 1219 |
1227 // We only cache the image when it's the default image and we're not hovered, | 1220 // We only cache the image when it's the default image and we're not hovered, |
1228 // to avoid caching a background image that isn't the same for all tabs. | 1221 // to avoid caching a background image that isn't the same for all tabs. |
1229 if (has_custom_image || hover_controller_.ShouldDraw()) { | 1222 if (has_custom_image) { |
1230 PaintTabBackgroundUsingFillId(canvas, canvas, false, fill_id, | 1223 // If the theme is providing a custom background image, then its top edge |
1231 has_custom_image, y_offset); | 1224 // should be at the top of the tab. Otherwise, we assume that the background |
| 1225 // image is a composited foreground + frame image. Note that if the theme |
| 1226 // is only providing a custom frame image, |has_custom_image| will be true, |
| 1227 // but we should use the |background_offset_| here. |
| 1228 const int y_offset = |
| 1229 tp->HasCustomImage(fill_id) ? 0 : background_offset_.y(); |
| 1230 PaintTabBackgroundUsingFillId(canvas, canvas, false, fill_id, y_offset); |
| 1231 return; |
| 1232 } |
| 1233 if (hover_controller_.ShouldDraw()) { |
| 1234 PaintTabBackgroundUsingFillId(canvas, canvas, false, 0, 0); |
1232 return; | 1235 return; |
1233 } | 1236 } |
1234 | 1237 |
1235 // For efficiency, we don't use separate fill and stroke images unless we | 1238 // For efficiency, we don't use separate fill and stroke images unless we |
1236 // really need to clip the stroke and not the fill (for stacked tabs). This | 1239 // really need to clip the stroke and not the fill (for stacked tabs). This |
1237 // saves memory and avoids an extra image draw at the cost of recalculating | 1240 // saves memory and avoids an extra image draw at the cost of recalculating |
1238 // the images when MaySetClip() toggles. | 1241 // the images when MaySetClip() toggles. |
1239 const bool use_fill_and_stroke_images = controller_->MaySetClip(); | 1242 const bool use_fill_and_stroke_images = controller_->MaySetClip(); |
1240 | 1243 |
1241 const ImageCacheEntryMetadata metadata( | 1244 const ImageCacheEntryMetadata metadata( |
1242 tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), | 1245 tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), |
1243 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, | 1246 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, |
1244 canvas->image_scale(), size()); | 1247 canvas->image_scale(), size()); |
1245 auto it = std::find_if( | 1248 auto it = std::find_if( |
1246 g_image_cache->begin(), g_image_cache->end(), | 1249 g_image_cache->begin(), g_image_cache->end(), |
1247 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); | 1250 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); |
1248 if (it == g_image_cache->end()) { | 1251 if (it == g_image_cache->end()) { |
1249 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); | 1252 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); |
1250 if (use_fill_and_stroke_images) { | 1253 if (use_fill_and_stroke_images) { |
1251 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false); | 1254 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false); |
1252 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, | 1255 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, 0, 0); |
1253 fill_id, false, y_offset); | |
1254 g_image_cache->emplace_front( | 1256 g_image_cache->emplace_front( |
1255 metadata, gfx::ImageSkia(tmp_fill_canvas.ExtractImageRep()), | 1257 metadata, gfx::ImageSkia(tmp_fill_canvas.ExtractImageRep()), |
1256 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); | 1258 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); |
1257 } else { | 1259 } else { |
1258 PaintTabBackgroundUsingFillId(&tmp_canvas, &tmp_canvas, false, fill_id, | 1260 PaintTabBackgroundUsingFillId(&tmp_canvas, &tmp_canvas, false, 0, 0); |
1259 false, y_offset); | |
1260 g_image_cache->emplace_front( | 1261 g_image_cache->emplace_front( |
1261 metadata, gfx::ImageSkia(), | 1262 metadata, gfx::ImageSkia(), |
1262 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); | 1263 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); |
1263 } | 1264 } |
1264 if (g_image_cache->size() > kMaxImageCacheSize) | 1265 if (g_image_cache->size() > kMaxImageCacheSize) |
1265 g_image_cache->pop_back(); | 1266 g_image_cache->pop_back(); |
1266 it = g_image_cache->begin(); | 1267 it = g_image_cache->begin(); |
1267 } | 1268 } |
1268 | 1269 |
1269 gfx::ScopedCanvas scoped_canvas( | 1270 gfx::ScopedCanvas scoped_canvas( |
1270 use_fill_and_stroke_images ? canvas : nullptr); | 1271 use_fill_and_stroke_images ? canvas : nullptr); |
1271 if (use_fill_and_stroke_images) { | 1272 if (use_fill_and_stroke_images) { |
1272 canvas->DrawImageInt(it->fill_image, 0, 0); | 1273 canvas->DrawImageInt(it->fill_image, 0, 0); |
1273 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true); | 1274 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true); |
1274 } | 1275 } |
1275 canvas->DrawImageInt(it->stroke_image, 0, 0); | 1276 canvas->DrawImageInt(it->stroke_image, 0, 0); |
1276 } | 1277 } |
1277 | 1278 |
1278 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, | 1279 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, |
1279 gfx::Canvas* stroke_canvas, | 1280 gfx::Canvas* stroke_canvas, |
1280 bool is_active, | 1281 bool is_active, |
1281 int fill_id, | 1282 int fill_id, |
1282 bool has_custom_image, | |
1283 int y_offset) { | 1283 int y_offset) { |
1284 gfx::Path fill; | 1284 gfx::Path fill; |
1285 SkPaint paint; | 1285 SkPaint paint; |
1286 paint.setAntiAlias(true); | 1286 paint.setAntiAlias(true); |
1287 | 1287 |
1288 // Draw the fill. | 1288 // Draw the fill. |
1289 { | 1289 { |
1290 gfx::ScopedCanvas scoped_canvas(fill_canvas); | 1290 gfx::ScopedCanvas scoped_canvas(fill_canvas); |
1291 const float scale = fill_canvas->UndoDeviceScaleFactor(); | 1291 const float scale = fill_canvas->UndoDeviceScaleFactor(); |
1292 const ui::ThemeProvider* tp = GetThemeProvider(); | 1292 const ui::ThemeProvider* tp = GetThemeProvider(); |
1293 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); | 1293 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); |
1294 | 1294 |
1295 fill = GetFillPath(scale, size()); | 1295 fill = GetFillPath(scale, size()); |
1296 { | 1296 { |
1297 gfx::ScopedCanvas clip_scoper(fill_canvas); | 1297 gfx::ScopedCanvas clip_scoper(fill_canvas); |
1298 fill_canvas->ClipPath(fill, true); | 1298 fill_canvas->ClipPath(fill, true); |
1299 if (has_custom_image) { | 1299 if (fill_id) { |
1300 gfx::ScopedCanvas scale_scoper(fill_canvas); | 1300 gfx::ScopedCanvas scale_scoper(fill_canvas); |
1301 fill_canvas->sk_canvas()->scale(scale, scale); | 1301 fill_canvas->sk_canvas()->scale(scale, scale); |
1302 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id), | 1302 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id), |
1303 GetMirroredX() + background_offset_.x(), | 1303 GetMirroredX() + background_offset_.x(), |
1304 y_offset, 0, 0, width(), height()); | 1304 y_offset, 0, 0, width(), height()); |
1305 } else { | 1305 } else { |
1306 paint.setColor( | 1306 paint.setColor( |
1307 is_active ? toolbar_color | 1307 is_active ? toolbar_color |
1308 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); | 1308 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); |
1309 fill_canvas->DrawRect( | 1309 fill_canvas->DrawRect( |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1577 SchedulePaintInRect(bounds); | 1577 SchedulePaintInRect(bounds); |
1578 } | 1578 } |
1579 | 1579 |
1580 gfx::Rect Tab::GetImmersiveBarRect() const { | 1580 gfx::Rect Tab::GetImmersiveBarRect() const { |
1581 // The main bar is as wide as the normal tab's horizontal top line. | 1581 // The main bar is as wide as the normal tab's horizontal top line. |
1582 gfx::Rect contents = GetContentsBounds(); | 1582 gfx::Rect contents = GetContentsBounds(); |
1583 contents.set_y(0); | 1583 contents.set_y(0); |
1584 contents.set_height(kImmersiveBarHeight); | 1584 contents.set_height(kImmersiveBarHeight); |
1585 return contents; | 1585 return contents; |
1586 } | 1586 } |
OLD | NEW |