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

Side by Side Diff: chrome/browser/ui/views/tabs/tab.cc

Issue 2441863002: Remove some more !IsModeMaterial code. (Closed)
Patch Set: pull more shades 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 (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
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
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.
Peter Kasting 2016/10/21 21:07:50 Nit: This comment is slightly confusing now that y
Evan Stade 2016/10/21 22:11:12 actually, there would be a need for ..., has_c
Peter Kasting 2016/10/22 00:14:44 Ah, you're right. Man, I thought through this lik
Evan Stade 2016/10/24 13:01:20 incidentally, already done in latest patchset
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);
1232 return; 1231 return;
1233 } 1232 }
1234 1233
1234 if (hover_controller_.ShouldDraw()) {
1235 PaintTabBackgroundUsingFillId(canvas, canvas, false, 0, 0);
1236 return;
1237 }
1238
1235 // For efficiency, we don't use separate fill and stroke images unless we 1239 // 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 1240 // 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 1241 // saves memory and avoids an extra image draw at the cost of recalculating
1238 // the images when MaySetClip() toggles. 1242 // the images when MaySetClip() toggles.
1239 const bool use_fill_and_stroke_images = controller_->MaySetClip(); 1243 const bool use_fill_and_stroke_images = controller_->MaySetClip();
1240 1244
1241 const ImageCacheEntryMetadata metadata( 1245 const ImageCacheEntryMetadata metadata(
1242 tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), 1246 tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB),
1243 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, 1247 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images,
1244 canvas->image_scale(), size()); 1248 canvas->image_scale(), size());
1245 auto it = std::find_if( 1249 auto it = std::find_if(
1246 g_image_cache->begin(), g_image_cache->end(), 1250 g_image_cache->begin(), g_image_cache->end(),
1247 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); 1251 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; });
1248 if (it == g_image_cache->end()) { 1252 if (it == g_image_cache->end()) {
1249 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); 1253 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false);
1250 if (use_fill_and_stroke_images) { 1254 if (use_fill_and_stroke_images) {
1251 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false); 1255 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false);
1252 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, 1256 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, 0, 0);
1253 fill_id, false, y_offset);
1254 g_image_cache->emplace_front( 1257 g_image_cache->emplace_front(
1255 metadata, gfx::ImageSkia(tmp_fill_canvas.ExtractImageRep()), 1258 metadata, gfx::ImageSkia(tmp_fill_canvas.ExtractImageRep()),
1256 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); 1259 gfx::ImageSkia(tmp_canvas.ExtractImageRep()));
1257 } else { 1260 } else {
1258 PaintTabBackgroundUsingFillId(&tmp_canvas, &tmp_canvas, false, fill_id, 1261 PaintTabBackgroundUsingFillId(&tmp_canvas, &tmp_canvas, false, 0, 0);
1259 false, y_offset);
1260 g_image_cache->emplace_front( 1262 g_image_cache->emplace_front(
1261 metadata, gfx::ImageSkia(), 1263 metadata, gfx::ImageSkia(),
1262 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); 1264 gfx::ImageSkia(tmp_canvas.ExtractImageRep()));
1263 } 1265 }
1264 if (g_image_cache->size() > kMaxImageCacheSize) 1266 if (g_image_cache->size() > kMaxImageCacheSize)
1265 g_image_cache->pop_back(); 1267 g_image_cache->pop_back();
1266 it = g_image_cache->begin(); 1268 it = g_image_cache->begin();
1267 } 1269 }
1268 1270
1269 gfx::ScopedCanvas scoped_canvas( 1271 gfx::ScopedCanvas scoped_canvas(
1270 use_fill_and_stroke_images ? canvas : nullptr); 1272 use_fill_and_stroke_images ? canvas : nullptr);
1271 if (use_fill_and_stroke_images) { 1273 if (use_fill_and_stroke_images) {
1272 canvas->DrawImageInt(it->fill_image, 0, 0); 1274 canvas->DrawImageInt(it->fill_image, 0, 0);
1273 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true); 1275 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true);
1274 } 1276 }
1275 canvas->DrawImageInt(it->stroke_image, 0, 0); 1277 canvas->DrawImageInt(it->stroke_image, 0, 0);
1276 } 1278 }
1277 1279
1278 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, 1280 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas,
1279 gfx::Canvas* stroke_canvas, 1281 gfx::Canvas* stroke_canvas,
1280 bool is_active, 1282 bool is_active,
1281 int fill_id, 1283 int fill_id,
1282 bool has_custom_image,
1283 int y_offset) { 1284 int y_offset) {
1284 gfx::Path fill; 1285 gfx::Path fill;
1285 SkPaint paint; 1286 SkPaint paint;
1286 paint.setAntiAlias(true); 1287 paint.setAntiAlias(true);
1287 1288
1288 // Draw the fill. 1289 // Draw the fill.
1289 { 1290 {
1290 gfx::ScopedCanvas scoped_canvas(fill_canvas); 1291 gfx::ScopedCanvas scoped_canvas(fill_canvas);
1291 const float scale = fill_canvas->UndoDeviceScaleFactor(); 1292 const float scale = fill_canvas->UndoDeviceScaleFactor();
1292 const ui::ThemeProvider* tp = GetThemeProvider(); 1293 const ui::ThemeProvider* tp = GetThemeProvider();
1293 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); 1294 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR);
1294 1295
1295 fill = GetFillPath(scale, size()); 1296 fill = GetFillPath(scale, size());
1296 { 1297 {
1297 gfx::ScopedCanvas clip_scoper(fill_canvas); 1298 gfx::ScopedCanvas clip_scoper(fill_canvas);
1298 fill_canvas->ClipPath(fill, true); 1299 fill_canvas->ClipPath(fill, true);
1299 if (has_custom_image) { 1300 if (fill_id != 0) {
Peter Kasting 2016/10/21 21:07:51 Nit: To avoid the else reading like a double-negat
Evan Stade 2016/10/21 22:11:12 Done.
1300 gfx::ScopedCanvas scale_scoper(fill_canvas); 1301 gfx::ScopedCanvas scale_scoper(fill_canvas);
1301 fill_canvas->sk_canvas()->scale(scale, scale); 1302 fill_canvas->sk_canvas()->scale(scale, scale);
1302 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id), 1303 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id),
1303 GetMirroredX() + background_offset_.x(), 1304 GetMirroredX() + background_offset_.x(),
1304 y_offset, 0, 0, width(), height()); 1305 y_offset, 0, 0, width(), height());
1305 } else { 1306 } else {
1306 paint.setColor( 1307 paint.setColor(
1307 is_active ? toolbar_color 1308 is_active ? toolbar_color
1308 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); 1309 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB));
1309 fill_canvas->DrawRect( 1310 fill_canvas->DrawRect(
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 SchedulePaintInRect(bounds); 1578 SchedulePaintInRect(bounds);
1578 } 1579 }
1579 1580
1580 gfx::Rect Tab::GetImmersiveBarRect() const { 1581 gfx::Rect Tab::GetImmersiveBarRect() const {
1581 // The main bar is as wide as the normal tab's horizontal top line. 1582 // The main bar is as wide as the normal tab's horizontal top line.
1582 gfx::Rect contents = GetContentsBounds(); 1583 gfx::Rect contents = GetContentsBounds();
1583 contents.set_y(0); 1584 contents.set_y(0);
1584 contents.set_height(kImmersiveBarHeight); 1585 contents.set_height(kImmersiveBarHeight);
1585 return contents; 1586 return contents;
1586 } 1587 }
OLDNEW
« chrome/browser/ui/views/tabs/tab.h ('K') | « chrome/browser/ui/views/tabs/tab.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698