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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
109 | 109 |
110 // The minimum opacity (out of 1) when a tab (either active or inactive) is | 110 // The minimum opacity (out of 1) when a tab (either active or inactive) is |
111 // throbbing in the immersive mode light strip. | 111 // throbbing in the immersive mode light strip. |
112 const double kImmersiveTabMinThrobOpacity = 0.66; | 112 const double kImmersiveTabMinThrobOpacity = 0.66; |
113 | 113 |
114 // Number of steps in the immersive mode loading animation. | 114 // Number of steps in the immersive mode loading animation. |
115 const int kImmersiveLoadingStepCount = 32; | 115 const int kImmersiveLoadingStepCount = 32; |
116 | 116 |
117 const char kTabCloseButtonName[] = "TabCloseButton"; | 117 const char kTabCloseButtonName[] = "TabCloseButton"; |
118 | 118 |
119 // Parameters for PaintTabBackgroundUsingParams(). | |
120 struct PaintBackgroundParams { | |
121 PaintBackgroundParams(bool is_active, | |
122 gfx::ImageSkia* fill_image_ptr, | |
123 bool has_custom_image, | |
124 gfx::Rect offset_rect, | |
Peter Kasting
2016/08/09 02:52:31
|offset_rect| feels like a misleading name here.
Greg Levin
2016/08/09 17:28:18
Done.
| |
125 SkColor stroke_color, | |
126 SkColor toolbar_color, | |
127 SkColor background_color) | |
128 : is_active(is_active), | |
129 has_custom_image(has_custom_image), | |
130 offset_rect(offset_rect), | |
131 stroke_color(stroke_color), | |
132 toolbar_color(toolbar_color), | |
133 background_color(background_color) { | |
134 if (fill_image_ptr) | |
135 fill_image = *fill_image_ptr; | |
136 } | |
137 | |
138 bool is_active; | |
139 gfx::ImageSkia fill_image; | |
140 bool has_custom_image; | |
141 gfx::Rect offset_rect; | |
142 SkColor stroke_color; | |
143 SkColor toolbar_color; | |
144 SkColor background_color; | |
Peter Kasting
2016/08/09 02:52:31
Nit: All of these but |fill_image| could be const.
Greg Levin
2016/08/09 17:28:17
Done.
| |
145 }; | |
146 | |
119 //////////////////////////////////////////////////////////////////////////////// | 147 //////////////////////////////////////////////////////////////////////////////// |
120 // ImageCacheEntryMetadata | 148 // ImageCacheEntryMetadata |
121 // | 149 // |
122 // All metadata necessary to uniquely identify a cached image. | 150 // All metadata necessary to uniquely identify a cached image. |
123 struct ImageCacheEntryMetadata { | 151 struct ImageCacheEntryMetadata { |
124 ImageCacheEntryMetadata(int resource_id, | 152 ImageCacheEntryMetadata(int resource_id, |
125 SkColor fill_color, | 153 SkColor fill_color, |
126 SkColor stroke_color, | 154 SkColor stroke_color, |
127 ui::ScaleFactor scale_factor, | 155 ui::ScaleFactor scale_factor, |
128 const gfx::Size& size); | 156 const gfx::Size& size); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
344 1.5 * scale); | 372 1.5 * scale); |
345 } | 373 } |
346 path->lineTo(right - 2 * scale, bottom - 1 - 1.5 * scale); | 374 path->lineTo(right - 2 * scale, bottom - 1 - 1.5 * scale); |
347 path->rCubicTo(0.375 * scale, scale, 1.25 * scale, 1.5 * scale, 2 * scale, | 375 path->rCubicTo(0.375 * scale, scale, 1.25 * scale, 1.5 * scale, 2 * scale, |
348 1.5 * scale); | 376 1.5 * scale); |
349 path->rLineTo(0, 1); | 377 path->rLineTo(0, 1); |
350 path->close(); | 378 path->close(); |
351 } | 379 } |
352 | 380 |
353 void PaintTabFill(gfx::Canvas* canvas, | 381 void PaintTabFill(gfx::Canvas* canvas, |
354 gfx::ImageSkia* fill_image, | 382 const gfx::ImageSkia& fill_image, |
355 int x_offset, | 383 gfx::Rect offset_rect, |
356 int y_offset, | |
357 const gfx::Size& size, | |
358 bool is_active) { | 384 bool is_active) { |
359 const gfx::Insets tab_insets(GetLayoutInsets(TAB)); | 385 const gfx::Insets tab_insets(GetLayoutInsets(TAB)); |
360 // If this isn't the foreground tab, don't draw over the toolbar, but do | 386 // If this isn't the foreground tab, don't draw over the toolbar, but do |
361 // include the 1 px divider stroke at the bottom. | 387 // include the 1 px divider stroke at the bottom. |
362 const int toolbar_overlap = is_active ? 0 : (tab_insets.bottom() - 1); | 388 const int toolbar_overlap = is_active ? 0 : (tab_insets.bottom() - 1); |
363 | 389 |
364 // Draw left edge. | 390 // Draw left edge. |
365 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( | 391 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( |
366 *fill_image, x_offset, y_offset, g_mask_images.l_width, size.height()); | 392 fill_image, offset_rect.x(), offset_rect.y(), g_mask_images.l_width, |
393 offset_rect.height()); | |
367 gfx::ImageSkia theme_l = gfx::ImageSkiaOperations::CreateMaskedImage( | 394 gfx::ImageSkia theme_l = gfx::ImageSkiaOperations::CreateMaskedImage( |
368 tab_l, *g_mask_images.image_l); | 395 tab_l, *g_mask_images.image_l); |
369 canvas->DrawImageInt( | 396 canvas->DrawImageInt( |
370 theme_l, 0, 0, theme_l.width(), theme_l.height() - toolbar_overlap, 0, 0, | 397 theme_l, 0, 0, theme_l.width(), theme_l.height() - toolbar_overlap, 0, 0, |
371 theme_l.width(), theme_l.height() - toolbar_overlap, false); | 398 theme_l.width(), theme_l.height() - toolbar_overlap, false); |
372 | 399 |
373 // Draw right edge. | 400 // Draw right edge. |
374 gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage( | 401 gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage( |
375 *fill_image, x_offset + size.width() - g_mask_images.r_width, y_offset, | 402 fill_image, offset_rect.x() + offset_rect.width() - g_mask_images.r_width, |
Peter Kasting
2016/08/09 02:52:31
Nit: Use right() in place of x() + width()
Greg Levin
2016/08/09 17:28:17
Done.
| |
376 g_mask_images.r_width, size.height()); | 403 offset_rect.y(), g_mask_images.r_width, offset_rect.height()); |
377 gfx::ImageSkia theme_r = gfx::ImageSkiaOperations::CreateMaskedImage( | 404 gfx::ImageSkia theme_r = gfx::ImageSkiaOperations::CreateMaskedImage( |
378 tab_r, *g_mask_images.image_r); | 405 tab_r, *g_mask_images.image_r); |
379 canvas->DrawImageInt(theme_r, 0, 0, theme_r.width(), | 406 canvas->DrawImageInt( |
380 theme_r.height() - toolbar_overlap, | 407 theme_r, 0, 0, theme_r.width(), theme_r.height() - toolbar_overlap, |
381 size.width() - theme_r.width(), 0, theme_r.width(), | 408 offset_rect.width() - theme_r.width(), 0, theme_r.width(), |
382 theme_r.height() - toolbar_overlap, false); | 409 theme_r.height() - toolbar_overlap, false); |
383 | 410 |
384 // Draw center. Instead of masking out the top portion we simply skip over it | 411 // Draw center. Instead of masking out the top portion we simply skip over it |
385 // by incrementing by the top padding, since it's a simple rectangle. | 412 // by incrementing by the top padding, since it's a simple rectangle. |
386 canvas->TileImageInt( | 413 canvas->TileImageInt( |
387 *fill_image, x_offset + g_mask_images.l_width, | 414 fill_image, offset_rect.x() + g_mask_images.l_width, |
388 y_offset + tab_insets.top(), g_mask_images.l_width, tab_insets.top(), | 415 offset_rect.y() + tab_insets.top(), g_mask_images.l_width, |
389 size.width() - g_mask_images.l_width - g_mask_images.r_width, | 416 tab_insets.top(), |
390 size.height() - tab_insets.top() - toolbar_overlap); | 417 offset_rect.width() - g_mask_images.l_width - g_mask_images.r_width, |
418 offset_rect.height() - tab_insets.top() - toolbar_overlap); | |
Peter Kasting
2016/08/09 02:52:31
Nit: Shorter:
const int left = g_mask_images.l_
Greg Levin
2016/08/09 17:28:17
The offset_rect -> rect change had already shorten
| |
419 } | |
420 | |
421 void PaintTabBackgroundUsingParams(gfx::Canvas* canvas, | |
422 views::GlowHoverController* hc, | |
423 const PaintBackgroundParams& params) { | |
424 const SkScalar kMinHoverRadius = 16; | |
425 const SkScalar radius = std::max( | |
426 SkFloatToScalar(params.offset_rect.width() / 4.f), kMinHoverRadius); | |
427 const bool draw_hover = !params.is_active && hc; | |
428 SkPoint hover_location( | |
429 PointToSkPoint(draw_hover ? hc->location() : gfx::Point())); | |
430 const SkColor hover_color = | |
431 SkColorSetA(params.toolbar_color, draw_hover ? hc->GetAlpha() : 255); | |
432 | |
433 if (ui::MaterialDesignController::IsModeMaterial()) { | |
434 gfx::ScopedCanvas scoped_canvas(canvas); | |
435 const float scale = canvas->UndoDeviceScaleFactor(); | |
436 | |
437 // Draw the fill. | |
438 SkPath fill; | |
439 GetFillPath(scale, params.offset_rect.size(), &fill); | |
440 SkPaint paint; | |
441 paint.setAntiAlias(true); | |
442 { | |
443 gfx::ScopedCanvas clip_scoper(canvas); | |
444 canvas->ClipPath(fill, true); | |
445 if (!params.fill_image.isNull()) { | |
446 gfx::ScopedCanvas scale_scoper(canvas); | |
447 canvas->sk_canvas()->scale(scale, scale); | |
448 canvas->TileImageInt( | |
449 params.fill_image, params.offset_rect.x(), params.offset_rect.y(), | |
450 0, 0, params.offset_rect.width(), params.offset_rect.height()); | |
451 } else { | |
452 paint.setColor(params.is_active ? params.toolbar_color | |
453 : params.background_color); | |
454 canvas->DrawRect(gfx::ScaleToEnclosingRect( | |
455 gfx::Rect(params.offset_rect.size()), scale), | |
456 paint); | |
457 } | |
458 if (draw_hover) { | |
459 hover_location.scale(SkFloatToScalar(scale)); | |
460 DrawHighlight(canvas, hover_location, radius * scale, hover_color); | |
461 } | |
462 } | |
463 | |
464 // Draw the stroke. | |
465 SkPath stroke; | |
466 GetBorderPath(scale, params.offset_rect.size(), false, &stroke); | |
467 Op(stroke, fill, kDifference_SkPathOp, &stroke); | |
468 if (!params.is_active) { | |
469 // Clip out the bottom line; this will be drawn for us by | |
470 // TabStrip::PaintChildren(). | |
471 canvas->sk_canvas()->clipRect( | |
472 SkRect::MakeWH(params.offset_rect.width() * scale, | |
473 params.offset_rect.height() * scale - 1)); | |
474 } | |
475 paint.setColor(params.stroke_color); | |
476 canvas->DrawPath(stroke, paint); | |
477 } else { | |
478 if (draw_hover) { | |
479 // Draw everything to a temporary canvas so we can extract an image for | |
480 // use in masking the hover glow. | |
481 gfx::Canvas background_canvas(params.offset_rect.size(), | |
482 canvas->image_scale(), false); | |
483 PaintTabFill(&background_canvas, params.fill_image, params.offset_rect, | |
484 params.is_active); | |
485 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); | |
486 canvas->DrawImageInt(background_image, 0, 0); | |
487 | |
488 gfx::Canvas hover_canvas(params.offset_rect.size(), canvas->image_scale(), | |
489 false); | |
490 DrawHighlight(&hover_canvas, hover_location, radius, hover_color); | |
491 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( | |
492 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); | |
493 canvas->DrawImageInt(result, 0, 0); | |
494 } else { | |
495 PaintTabFill(canvas, params.fill_image, params.offset_rect, | |
496 params.is_active); | |
497 } | |
498 | |
499 // Now draw the stroke, highlights, and shadows around the tab edge. | |
500 TabImages* stroke_images = | |
501 params.is_active ? &g_active_images : &g_inactive_images; | |
502 canvas->DrawImageInt(*stroke_images->image_l, 0, 0); | |
503 canvas->TileImageInt(*stroke_images->image_c, stroke_images->l_width, 0, | |
504 params.offset_rect.width() - stroke_images->l_width - | |
505 stroke_images->r_width, | |
506 params.offset_rect.height()); | |
507 canvas->DrawImageInt(*stroke_images->image_r, | |
508 params.offset_rect.width() - stroke_images->r_width, | |
509 0); | |
510 } | |
391 } | 511 } |
392 | 512 |
393 } // namespace | 513 } // namespace |
394 | 514 |
395 //////////////////////////////////////////////////////////////////////////////// | 515 //////////////////////////////////////////////////////////////////////////////// |
396 // FaviconCrashAnimation | 516 // FaviconCrashAnimation |
397 // | 517 // |
398 // A custom animation subclass to manage the favicon crash animation. | 518 // A custom animation subclass to manage the favicon crash animation. |
399 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, | 519 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, |
400 public gfx::AnimationDelegate { | 520 public gfx::AnimationDelegate { |
(...skipping 1068 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1469 it = g_image_cache->begin(); | 1589 it = g_image_cache->begin(); |
1470 } | 1590 } |
1471 canvas->DrawImageInt(it->image, 0, 0); | 1591 canvas->DrawImageInt(it->image, 0, 0); |
1472 } | 1592 } |
1473 | 1593 |
1474 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, | 1594 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, |
1475 bool is_active, | 1595 bool is_active, |
1476 int fill_id, | 1596 int fill_id, |
1477 bool has_custom_image, | 1597 bool has_custom_image, |
1478 int y_offset) { | 1598 int y_offset) { |
1479 const ui::ThemeProvider* tp = GetThemeProvider(); | 1599 views::GlowHoverController* hc = |
1480 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); | 1600 hover_controller_.ShouldDraw() ? &hover_controller_ : nullptr; |
1481 gfx::ImageSkia* fill_image = tp->GetImageSkiaNamed(fill_id); | 1601 gfx::ImageSkia* fill_image = |
1602 has_custom_image || !ui::MaterialDesignController::IsModeMaterial() | |
1603 ? GetThemeProvider()->GetImageSkiaNamed(fill_id) | |
1604 : nullptr; | |
1482 // The tab image needs to be lined up with the background image | 1605 // The tab image needs to be lined up with the background image |
1483 // so that it feels partially transparent. These offsets represent the tab | 1606 // so that it feels partially transparent. These offsets represent the tab |
1484 // position within the frame background image. | 1607 // position within the frame background image. |
1485 const int x_offset = GetMirroredX() + background_offset_.x(); | 1608 gfx::Rect offset_rect(GetMirroredX() + background_offset_.x(), y_offset, |
1609 width(), height()); | |
Peter Kasting
2016/08/09 02:52:31
Nit: Do you think it's any more readable to do thi
Greg Levin
2016/08/09 17:28:17
Done.
| |
1610 PaintBackgroundParams params( | |
1611 is_active, fill_image, has_custom_image, offset_rect, | |
1612 controller_->GetToolbarTopSeparatorColor(), | |
1613 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), | |
1614 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); | |
1486 | 1615 |
1487 const SkScalar kMinHoverRadius = 16; | 1616 PaintTabBackgroundUsingParams(canvas, hc, params); |
1488 const SkScalar radius = | |
1489 std::max(SkFloatToScalar(width() / 4.f), kMinHoverRadius); | |
1490 const bool draw_hover = !is_active && hover_controller_.ShouldDraw(); | |
1491 SkPoint hover_location(PointToSkPoint(hover_controller_.location())); | |
1492 const SkColor hover_color = | |
1493 SkColorSetA(toolbar_color, hover_controller_.GetAlpha()); | |
1494 | |
1495 if (ui::MaterialDesignController::IsModeMaterial()) { | |
1496 gfx::ScopedCanvas scoped_canvas(canvas); | |
1497 const float scale = canvas->UndoDeviceScaleFactor(); | |
1498 | |
1499 // Draw the fill. | |
1500 SkPath fill; | |
1501 GetFillPath(scale, size(), &fill); | |
1502 SkPaint paint; | |
1503 paint.setAntiAlias(true); | |
1504 { | |
1505 gfx::ScopedCanvas clip_scoper(canvas); | |
1506 canvas->ClipPath(fill, true); | |
1507 if (has_custom_image) { | |
1508 gfx::ScopedCanvas scale_scoper(canvas); | |
1509 canvas->sk_canvas()->scale(scale, scale); | |
1510 canvas->TileImageInt(*fill_image, x_offset, y_offset, 0, 0, width(), | |
1511 height()); | |
1512 } else { | |
1513 paint.setColor( | |
1514 is_active ? toolbar_color | |
1515 : tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); | |
1516 canvas->DrawRect(gfx::ScaleToEnclosingRect(GetLocalBounds(), scale), | |
1517 paint); | |
1518 } | |
1519 if (draw_hover) { | |
1520 hover_location.scale(SkFloatToScalar(scale)); | |
1521 DrawHighlight(canvas, hover_location, radius * scale, hover_color); | |
1522 } | |
1523 } | |
1524 | |
1525 // Draw the stroke. | |
1526 SkPath stroke; | |
1527 GetBorderPath(scale, size(), false, &stroke); | |
1528 Op(stroke, fill, kDifference_SkPathOp, &stroke); | |
1529 if (!is_active) { | |
1530 // Clip out the bottom line; this will be drawn for us by | |
1531 // TabStrip::PaintChildren(). | |
1532 canvas->sk_canvas()->clipRect( | |
1533 SkRect::MakeWH(width() * scale, height() * scale - 1)); | |
1534 } | |
1535 paint.setColor(controller_->GetToolbarTopSeparatorColor()); | |
1536 canvas->DrawPath(stroke, paint); | |
1537 } else { | |
1538 if (draw_hover) { | |
1539 // Draw everything to a temporary canvas so we can extract an image for | |
1540 // use in masking the hover glow. | |
1541 gfx::Canvas background_canvas(size(), canvas->image_scale(), false); | |
1542 PaintTabFill(&background_canvas, fill_image, x_offset, y_offset, size(), | |
1543 is_active); | |
1544 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); | |
1545 canvas->DrawImageInt(background_image, 0, 0); | |
1546 | |
1547 gfx::Canvas hover_canvas(size(), canvas->image_scale(), false); | |
1548 DrawHighlight(&hover_canvas, hover_location, radius, hover_color); | |
1549 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( | |
1550 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); | |
1551 canvas->DrawImageInt(result, 0, 0); | |
1552 } else { | |
1553 PaintTabFill(canvas, fill_image, x_offset, y_offset, size(), is_active); | |
1554 } | |
1555 | |
1556 // Now draw the stroke, highlights, and shadows around the tab edge. | |
1557 TabImages* stroke_images = | |
1558 is_active ? &g_active_images : &g_inactive_images; | |
1559 canvas->DrawImageInt(*stroke_images->image_l, 0, 0); | |
1560 canvas->TileImageInt( | |
1561 *stroke_images->image_c, stroke_images->l_width, 0, | |
1562 width() - stroke_images->l_width - stroke_images->r_width, height()); | |
1563 canvas->DrawImageInt(*stroke_images->image_r, | |
1564 width() - stroke_images->r_width, 0); | |
1565 } | |
1566 } | 1617 } |
1567 | 1618 |
1568 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( | 1619 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( |
1569 gfx::Canvas* canvas, | 1620 gfx::Canvas* canvas, |
1570 const gfx::Rect& favicon_draw_bounds) { | 1621 const gfx::Rect& favicon_draw_bounds) { |
1571 // The pinned tab title changed indicator consists of two parts: | 1622 // The pinned tab title changed indicator consists of two parts: |
1572 // . a clear (totally transparent) part over the bottom right (or left in rtl) | 1623 // . a clear (totally transparent) part over the bottom right (or left in rtl) |
1573 // of the favicon. This is done by drawing the favicon to a canvas, then | 1624 // of the favicon. This is done by drawing the favicon to a canvas, then |
1574 // drawing the clear part on top of the favicon. | 1625 // drawing the clear part on top of the favicon. |
1575 // . a circle in the bottom right (or left in rtl) of the favicon. | 1626 // . a circle in the bottom right (or left in rtl) of the favicon. |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1804 gfx::Rect Tab::GetImmersiveBarRect() const { | 1855 gfx::Rect Tab::GetImmersiveBarRect() const { |
1805 // The main bar is as wide as the normal tab's horizontal top line. | 1856 // The main bar is as wide as the normal tab's horizontal top line. |
1806 // This top line of the tab extends a few pixels left and right of the | 1857 // This top line of the tab extends a few pixels left and right of the |
1807 // center image due to pixels in the rounded corner images. | 1858 // center image due to pixels in the rounded corner images. |
1808 const int kBarPadding = 1; | 1859 const int kBarPadding = 1; |
1809 int main_bar_left = g_active_images.l_width - kBarPadding; | 1860 int main_bar_left = g_active_images.l_width - kBarPadding; |
1810 int main_bar_right = width() - g_active_images.r_width + kBarPadding; | 1861 int main_bar_right = width() - g_active_images.r_width + kBarPadding; |
1811 return gfx::Rect( | 1862 return gfx::Rect( |
1812 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); | 1863 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
1813 } | 1864 } |
OLD | NEW |