| 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 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. | 210 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. |
| 211 float GetUnscaledEndcapWidth() { | 211 float GetUnscaledEndcapWidth() { |
| 212 return GetLayoutInsets(TAB).left() - 0.5f; | 212 return GetLayoutInsets(TAB).left() - 0.5f; |
| 213 } | 213 } |
| 214 | 214 |
| 215 void DrawHighlight(gfx::Canvas* canvas, | 215 void DrawHighlight(gfx::Canvas* canvas, |
| 216 const SkPoint& p, | 216 const SkPoint& p, |
| 217 SkScalar radius, | 217 SkScalar radius, |
| 218 SkColor color) { | 218 SkColor color) { |
| 219 const SkColor colors[2] = { color, SkColorSetA(color, 0) }; | 219 const SkColor colors[2] = { color, SkColorSetA(color, 0) }; |
| 220 cc::PaintFlags paint; | 220 cc::PaintFlags flags; |
| 221 paint.setAntiAlias(true); | 221 flags.setAntiAlias(true); |
| 222 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeRadial( | 222 flags.setShader(cc::WrapSkShader(SkGradientShader::MakeRadial( |
| 223 p, radius, colors, nullptr, 2, SkShader::kClamp_TileMode))); | 223 p, radius, colors, nullptr, 2, SkShader::kClamp_TileMode))); |
| 224 canvas->sk_canvas()->drawRect( | 224 canvas->sk_canvas()->drawRect( |
| 225 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2), | 225 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2), |
| 226 paint); | 226 flags); |
| 227 } | 227 } |
| 228 | 228 |
| 229 // Returns whether the favicon for the given URL should be colored according to | 229 // Returns whether the favicon for the given URL should be colored according to |
| 230 // the browser theme. | 230 // the browser theme. |
| 231 bool ShouldThemifyFaviconForUrl(const GURL& url) { | 231 bool ShouldThemifyFaviconForUrl(const GURL& url) { |
| 232 return url.SchemeIs(content::kChromeUIScheme) && | 232 return url.SchemeIs(content::kChromeUIScheme) && |
| 233 url.host() != chrome::kChromeUIHelpHost && | 233 url.host() != chrome::kChromeUIHelpHost && |
| 234 url.host() != chrome::kChromeUIUberHost && | 234 url.host() != chrome::kChromeUIUberHost && |
| 235 url.host() != chrome::kChromeUIAppLauncherPageHost; | 235 url.host() != chrome::kChromeUIAppLauncherPageHost; |
| 236 } | 236 } |
| (...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 } | 1279 } |
| 1280 canvas->DrawImageInt(it->stroke_image, 0, 0); | 1280 canvas->DrawImageInt(it->stroke_image, 0, 0); |
| 1281 } | 1281 } |
| 1282 | 1282 |
| 1283 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, | 1283 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, |
| 1284 gfx::Canvas* stroke_canvas, | 1284 gfx::Canvas* stroke_canvas, |
| 1285 bool is_active, | 1285 bool is_active, |
| 1286 int fill_id, | 1286 int fill_id, |
| 1287 int y_offset) { | 1287 int y_offset) { |
| 1288 gfx::Path fill; | 1288 gfx::Path fill; |
| 1289 cc::PaintFlags paint; | 1289 cc::PaintFlags flags; |
| 1290 paint.setAntiAlias(true); | 1290 flags.setAntiAlias(true); |
| 1291 | 1291 |
| 1292 // Draw the fill. | 1292 // Draw the fill. |
| 1293 { | 1293 { |
| 1294 gfx::ScopedCanvas scoped_canvas(fill_canvas); | 1294 gfx::ScopedCanvas scoped_canvas(fill_canvas); |
| 1295 const float scale = fill_canvas->UndoDeviceScaleFactor(); | 1295 const float scale = fill_canvas->UndoDeviceScaleFactor(); |
| 1296 const ui::ThemeProvider* tp = GetThemeProvider(); | 1296 const ui::ThemeProvider* tp = GetThemeProvider(); |
| 1297 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); | 1297 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); |
| 1298 | 1298 |
| 1299 fill = GetFillPath(scale, size()); | 1299 fill = GetFillPath(scale, size()); |
| 1300 { | 1300 { |
| 1301 gfx::ScopedCanvas clip_scoper(fill_canvas); | 1301 gfx::ScopedCanvas clip_scoper(fill_canvas); |
| 1302 fill_canvas->ClipPath(fill, true); | 1302 fill_canvas->ClipPath(fill, true); |
| 1303 if (fill_id) { | 1303 if (fill_id) { |
| 1304 gfx::ScopedCanvas scale_scoper(fill_canvas); | 1304 gfx::ScopedCanvas scale_scoper(fill_canvas); |
| 1305 fill_canvas->sk_canvas()->scale(scale, scale); | 1305 fill_canvas->sk_canvas()->scale(scale, scale); |
| 1306 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id), | 1306 fill_canvas->TileImageInt(*tp->GetImageSkiaNamed(fill_id), |
| 1307 GetMirroredX() + background_offset_.x(), | 1307 GetMirroredX() + background_offset_.x(), |
| 1308 y_offset, 0, 0, width(), height()); | 1308 y_offset, 0, 0, width(), height()); |
| 1309 } else { | 1309 } else { |
| 1310 paint.setColor( | 1310 flags.setColor( |
| 1311 is_active ? toolbar_color | 1311 is_active ? toolbar_color |
| 1312 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); | 1312 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); |
| 1313 fill_canvas->DrawRect( | 1313 fill_canvas->DrawRect( |
| 1314 gfx::ScaleToEnclosingRect(GetLocalBounds(), scale), paint); | 1314 gfx::ScaleToEnclosingRect(GetLocalBounds(), scale), flags); |
| 1315 } | 1315 } |
| 1316 | 1316 |
| 1317 if (!is_active && hover_controller_.ShouldDraw()) { | 1317 if (!is_active && hover_controller_.ShouldDraw()) { |
| 1318 SkPoint hover_location( | 1318 SkPoint hover_location( |
| 1319 gfx::PointToSkPoint(hover_controller_.location())); | 1319 gfx::PointToSkPoint(hover_controller_.location())); |
| 1320 hover_location.scale(SkFloatToScalar(scale)); | 1320 hover_location.scale(SkFloatToScalar(scale)); |
| 1321 const SkScalar kMinHoverRadius = 16; | 1321 const SkScalar kMinHoverRadius = 16; |
| 1322 const SkScalar radius = | 1322 const SkScalar radius = |
| 1323 std::max(SkFloatToScalar(width() / 4.f), kMinHoverRadius); | 1323 std::max(SkFloatToScalar(width() / 4.f), kMinHoverRadius); |
| 1324 DrawHighlight(fill_canvas, hover_location, radius * scale, | 1324 DrawHighlight(fill_canvas, hover_location, radius * scale, |
| 1325 SkColorSetA(toolbar_color, hover_controller_.GetAlpha())); | 1325 SkColorSetA(toolbar_color, hover_controller_.GetAlpha())); |
| 1326 } | 1326 } |
| 1327 } | 1327 } |
| 1328 } | 1328 } |
| 1329 | 1329 |
| 1330 // Draw the stroke. | 1330 // Draw the stroke. |
| 1331 { | 1331 { |
| 1332 gfx::ScopedCanvas scoped_canvas(stroke_canvas); | 1332 gfx::ScopedCanvas scoped_canvas(stroke_canvas); |
| 1333 const float scale = stroke_canvas->UndoDeviceScaleFactor(); | 1333 const float scale = stroke_canvas->UndoDeviceScaleFactor(); |
| 1334 | 1334 |
| 1335 gfx::Path stroke = GetBorderPath(scale, false, false, size()); | 1335 gfx::Path stroke = GetBorderPath(scale, false, false, size()); |
| 1336 Op(stroke, fill, kDifference_SkPathOp, &stroke); | 1336 Op(stroke, fill, kDifference_SkPathOp, &stroke); |
| 1337 if (!is_active) { | 1337 if (!is_active) { |
| 1338 // Clip out the bottom line; this will be drawn for us by | 1338 // Clip out the bottom line; this will be drawn for us by |
| 1339 // TabStrip::PaintChildren(). | 1339 // TabStrip::PaintChildren(). |
| 1340 stroke_canvas->ClipRect( | 1340 stroke_canvas->ClipRect( |
| 1341 gfx::RectF(width() * scale, height() * scale - 1)); | 1341 gfx::RectF(width() * scale, height() * scale - 1)); |
| 1342 } | 1342 } |
| 1343 paint.setColor(controller_->GetToolbarTopSeparatorColor()); | 1343 flags.setColor(controller_->GetToolbarTopSeparatorColor()); |
| 1344 stroke_canvas->DrawPath(stroke, paint); | 1344 stroke_canvas->DrawPath(stroke, flags); |
| 1345 } | 1345 } |
| 1346 } | 1346 } |
| 1347 | 1347 |
| 1348 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( | 1348 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( |
| 1349 gfx::Canvas* canvas, | 1349 gfx::Canvas* canvas, |
| 1350 const gfx::Rect& favicon_draw_bounds) { | 1350 const gfx::Rect& favicon_draw_bounds) { |
| 1351 // The pinned tab title changed indicator consists of two parts: | 1351 // The pinned tab title changed indicator consists of two parts: |
| 1352 // . a clear (totally transparent) part over the bottom right (or left in rtl) | 1352 // . a clear (totally transparent) part over the bottom right (or left in rtl) |
| 1353 // of the favicon. This is done by drawing the favicon to a canvas, then | 1353 // of the favicon. This is done by drawing the favicon to a canvas, then |
| 1354 // drawing the clear part on top of the favicon. | 1354 // drawing the clear part on top of the favicon. |
| 1355 // . a circle in the bottom right (or left in rtl) of the favicon. | 1355 // . a circle in the bottom right (or left in rtl) of the favicon. |
| 1356 if (!favicon_.isNull()) { | 1356 if (!favicon_.isNull()) { |
| 1357 const float kIndicatorCropRadius = 4.5; | 1357 const float kIndicatorCropRadius = 4.5; |
| 1358 gfx::Canvas icon_canvas(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), | 1358 gfx::Canvas icon_canvas(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
| 1359 canvas->image_scale(), false); | 1359 canvas->image_scale(), false); |
| 1360 icon_canvas.DrawImageInt(favicon_, 0, 0); | 1360 icon_canvas.DrawImageInt(favicon_, 0, 0); |
| 1361 cc::PaintFlags clear_paint; | 1361 cc::PaintFlags clear_flags; |
| 1362 clear_paint.setAntiAlias(true); | 1362 clear_flags.setAntiAlias(true); |
| 1363 clear_paint.setBlendMode(SkBlendMode::kClear); | 1363 clear_flags.setBlendMode(SkBlendMode::kClear); |
| 1364 const int circle_x = base::i18n::IsRTL() ? 0 : gfx::kFaviconSize; | 1364 const int circle_x = base::i18n::IsRTL() ? 0 : gfx::kFaviconSize; |
| 1365 icon_canvas.DrawCircle(gfx::PointF(circle_x, gfx::kFaviconSize), | 1365 icon_canvas.DrawCircle(gfx::PointF(circle_x, gfx::kFaviconSize), |
| 1366 kIndicatorCropRadius, clear_paint); | 1366 kIndicatorCropRadius, clear_flags); |
| 1367 canvas->DrawImageInt(gfx::ImageSkia(icon_canvas.ExtractImageRep()), 0, 0, | 1367 canvas->DrawImageInt(gfx::ImageSkia(icon_canvas.ExtractImageRep()), 0, 0, |
| 1368 favicon_draw_bounds.width(), | 1368 favicon_draw_bounds.width(), |
| 1369 favicon_draw_bounds.height(), favicon_draw_bounds.x(), | 1369 favicon_draw_bounds.height(), favicon_draw_bounds.x(), |
| 1370 favicon_draw_bounds.y(), favicon_draw_bounds.width(), | 1370 favicon_draw_bounds.y(), favicon_draw_bounds.width(), |
| 1371 favicon_draw_bounds.height(), false); | 1371 favicon_draw_bounds.height(), false); |
| 1372 } | 1372 } |
| 1373 | 1373 |
| 1374 // Draws the actual pinned tab title changed indicator. | 1374 // Draws the actual pinned tab title changed indicator. |
| 1375 const int kIndicatorRadius = 3; | 1375 const int kIndicatorRadius = 3; |
| 1376 cc::PaintFlags indicator_paint; | 1376 cc::PaintFlags indicator_flags; |
| 1377 indicator_paint.setColor(GetNativeTheme()->GetSystemColor( | 1377 indicator_flags.setColor(GetNativeTheme()->GetSystemColor( |
| 1378 ui::NativeTheme::kColorId_ProminentButtonColor)); | 1378 ui::NativeTheme::kColorId_ProminentButtonColor)); |
| 1379 indicator_paint.setAntiAlias(true); | 1379 indicator_flags.setAntiAlias(true); |
| 1380 const int indicator_x = GetMirroredXWithWidthInView( | 1380 const int indicator_x = GetMirroredXWithWidthInView( |
| 1381 favicon_bounds_.right() - kIndicatorRadius, kIndicatorRadius * 2); | 1381 favicon_bounds_.right() - kIndicatorRadius, kIndicatorRadius * 2); |
| 1382 const int indicator_y = favicon_bounds_.bottom() - kIndicatorRadius; | 1382 const int indicator_y = favicon_bounds_.bottom() - kIndicatorRadius; |
| 1383 canvas->DrawCircle(gfx::Point(indicator_x + kIndicatorRadius, | 1383 canvas->DrawCircle(gfx::Point(indicator_x + kIndicatorRadius, |
| 1384 indicator_y + kIndicatorRadius), | 1384 indicator_y + kIndicatorRadius), |
| 1385 kIndicatorRadius, indicator_paint); | 1385 kIndicatorRadius, indicator_flags); |
| 1386 } | 1386 } |
| 1387 | 1387 |
| 1388 void Tab::PaintIcon(gfx::Canvas* canvas) { | 1388 void Tab::PaintIcon(gfx::Canvas* canvas) { |
| 1389 gfx::Rect bounds = favicon_bounds_; | 1389 gfx::Rect bounds = favicon_bounds_; |
| 1390 bounds.set_x(GetMirroredXForRect(bounds)); | 1390 bounds.set_x(GetMirroredXForRect(bounds)); |
| 1391 bounds.Offset(0, favicon_hiding_offset_); | 1391 bounds.Offset(0, favicon_hiding_offset_); |
| 1392 bounds.Intersect(GetContentsBounds()); | 1392 bounds.Intersect(GetContentsBounds()); |
| 1393 if (bounds.IsEmpty()) | 1393 if (bounds.IsEmpty()) |
| 1394 return; | 1394 return; |
| 1395 | 1395 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1585 SchedulePaintInRect(bounds); | 1585 SchedulePaintInRect(bounds); |
| 1586 } | 1586 } |
| 1587 | 1587 |
| 1588 gfx::Rect Tab::GetImmersiveBarRect() const { | 1588 gfx::Rect Tab::GetImmersiveBarRect() const { |
| 1589 // The main bar is as wide as the normal tab's horizontal top line. | 1589 // The main bar is as wide as the normal tab's horizontal top line. |
| 1590 gfx::Rect contents = GetContentsBounds(); | 1590 gfx::Rect contents = GetContentsBounds(); |
| 1591 contents.set_y(0); | 1591 contents.set_y(0); |
| 1592 contents.set_height(kImmersiveBarHeight); | 1592 contents.set_height(kImmersiveBarHeight); |
| 1593 return contents; | 1593 return contents; |
| 1594 } | 1594 } |
| OLD | NEW |