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

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

Issue 2697663002: Clean up naming of paint-related identifiers (Closed)
Patch Set: Rebase Created 3 years, 10 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_strip.h" 5 #include "chrome/browser/ui/views/tabs/tab_strip.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <iterator> 10 #include <iterator>
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // We want to draw a drop shadow either inside or outside the stroke, 395 // We want to draw a drop shadow either inside or outside the stroke,
396 // depending on whether we're pressed; so, either clip out what's outside 396 // depending on whether we're pressed; so, either clip out what's outside
397 // the stroke, or clip out the fill inside it. 397 // the stroke, or clip out the fill inside it.
398 if (pressed) 398 if (pressed)
399 canvas->ClipPath(stroke, true); 399 canvas->ClipPath(stroke, true);
400 Op(stroke, fill, kDifference_SkPathOp, &stroke); 400 Op(stroke, fill, kDifference_SkPathOp, &stroke);
401 if (!pressed) 401 if (!pressed)
402 canvas->sk_canvas()->clipPath(fill, SkClipOp::kDifference, true); 402 canvas->sk_canvas()->clipPath(fill, SkClipOp::kDifference, true);
403 // Now draw the stroke and shadow; the stroke will always be visible, while 403 // Now draw the stroke and shadow; the stroke will always be visible, while
404 // the shadow will be affected by the clip we set above. 404 // the shadow will be affected by the clip we set above.
405 cc::PaintFlags paint; 405 cc::PaintFlags flags;
406 paint.setAntiAlias(true); 406 flags.setAntiAlias(true);
407 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor(); 407 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor();
408 const float alpha = SkColorGetA(stroke_color); 408 const float alpha = SkColorGetA(stroke_color);
409 const SkAlpha shadow_alpha = 409 const SkAlpha shadow_alpha =
410 base::saturated_cast<SkAlpha>(std::round(2.1875f * alpha)); 410 base::saturated_cast<SkAlpha>(std::round(2.1875f * alpha));
411 paint.setLooper( 411 flags.setLooper(
412 CreateShadowDrawLooper(SkColorSetA(stroke_color, shadow_alpha))); 412 CreateShadowDrawLooper(SkColorSetA(stroke_color, shadow_alpha)));
413 const SkAlpha path_alpha = static_cast<SkAlpha>( 413 const SkAlpha path_alpha = static_cast<SkAlpha>(
414 std::round((pressed ? 0.875f : 0.609375f) * alpha)); 414 std::round((pressed ? 0.875f : 0.609375f) * alpha));
415 paint.setColor(SkColorSetA(stroke_color, path_alpha)); 415 flags.setColor(SkColorSetA(stroke_color, path_alpha));
416 canvas->DrawPath(stroke, paint); 416 canvas->DrawPath(stroke, flags);
417 } 417 }
418 418
419 bool NewTabButton::GetHitTestMask(gfx::Path* mask) const { 419 bool NewTabButton::GetHitTestMask(gfx::Path* mask) const {
420 DCHECK(mask); 420 DCHECK(mask);
421 421
422 SkPath border; 422 SkPath border;
423 const float scale = GetWidget()->GetCompositor()->device_scale_factor(); 423 const float scale = GetWidget()->GetCompositor()->device_scale_factor();
424 GetBorderPath(GetNewTabButtonTopOffset() * scale, scale, 424 GetBorderPath(GetNewTabButtonTopOffset() * scale, scale,
425 tab_strip_->SizeTabButtonToTopOfTabStrip(), &border); 425 tab_strip_->SizeTabButtonToTopOfTabStrip(), &border);
426 mask->addPath(border, SkMatrix::MakeScale(1 / scale)); 426 mask->addPath(border, SkMatrix::MakeScale(1 / scale));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 } 465 }
466 path->close(); 466 path->close();
467 } 467 }
468 468
469 void NewTabButton::PaintFill(bool pressed, 469 void NewTabButton::PaintFill(bool pressed,
470 float scale, 470 float scale,
471 const SkPath& fill, 471 const SkPath& fill,
472 gfx::Canvas* canvas) const { 472 gfx::Canvas* canvas) const {
473 gfx::ScopedCanvas scoped_canvas(canvas); 473 gfx::ScopedCanvas scoped_canvas(canvas);
474 canvas->UndoDeviceScaleFactor(); 474 canvas->UndoDeviceScaleFactor();
475 cc::PaintFlags paint; 475 cc::PaintFlags flags;
476 paint.setAntiAlias(true); 476 flags.setAntiAlias(true);
477 477
478 // For unpressed buttons, draw the fill and its shadow. 478 // For unpressed buttons, draw the fill and its shadow.
479 if (!pressed) { 479 if (!pressed) {
480 // First we compute the background image coordinates and scale, in case we 480 // First we compute the background image coordinates and scale, in case we
481 // need to draw a custom background image. 481 // need to draw a custom background image.
482 const ui::ThemeProvider* tp = GetThemeProvider(); 482 const ui::ThemeProvider* tp = GetThemeProvider();
483 bool custom_image; 483 bool custom_image;
484 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image); 484 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image);
485 if (custom_image) { 485 if (custom_image) {
486 // For custom tab backgrounds the background starts at the top of the tab 486 // For custom tab backgrounds the background starts at the top of the tab
487 // strip. Otherwise the background starts at the top of the frame. 487 // strip. Otherwise the background starts at the top of the frame.
488 const int offset_y = 488 const int offset_y =
489 tp->HasCustomImage(bg_id) ? 0 : background_offset_.y(); 489 tp->HasCustomImage(bg_id) ? 0 : background_offset_.y();
490 // The new tab background is mirrored in RTL mode, but the theme 490 // The new tab background is mirrored in RTL mode, but the theme
491 // background should never be mirrored. Mirror it here to compensate. 491 // background should never be mirrored. Mirror it here to compensate.
492 float x_scale = 1.0f; 492 float x_scale = 1.0f;
493 int x = GetMirroredX() + background_offset_.x(); 493 int x = GetMirroredX() + background_offset_.x();
494 const gfx::Size size(GetLayoutSize(NEW_TAB_BUTTON)); 494 const gfx::Size size(GetLayoutSize(NEW_TAB_BUTTON));
495 if (base::i18n::IsRTL()) { 495 if (base::i18n::IsRTL()) {
496 x_scale = -1.0f; 496 x_scale = -1.0f;
497 // Offset by |width| such that the same region is painted as if there 497 // Offset by |width| such that the same region is painted as if there
498 // was no flip. 498 // was no flip.
499 x += size.width(); 499 x += size.width();
500 } 500 }
501 501
502 const bool succeeded = 502 const bool succeeded =
503 canvas->InitPaintFlagsForTiling(*tp->GetImageSkiaNamed(bg_id), x, 503 canvas->InitPaintFlagsForTiling(*tp->GetImageSkiaNamed(bg_id), x,
504 GetNewTabButtonTopOffset() + offset_y, 504 GetNewTabButtonTopOffset() + offset_y,
505 x_scale * scale, scale, 0, 0, &paint); 505 x_scale * scale, scale, 0, 0, &flags);
506 DCHECK(succeeded); 506 DCHECK(succeeded);
507 } else { 507 } else {
508 paint.setColor(tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); 508 flags.setColor(tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB));
509 } 509 }
510 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor(); 510 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor();
511 const SkAlpha alpha = static_cast<SkAlpha>( 511 const SkAlpha alpha = static_cast<SkAlpha>(
512 std::round(SkColorGetA(stroke_color) * 0.59375f)); 512 std::round(SkColorGetA(stroke_color) * 0.59375f));
513 cc::PaintFlags shadow_paint = paint; 513 cc::PaintFlags shadow_flags = flags;
514 shadow_paint.setLooper( 514 shadow_flags.setLooper(
515 CreateShadowDrawLooper(SkColorSetA(stroke_color, alpha))); 515 CreateShadowDrawLooper(SkColorSetA(stroke_color, alpha)));
516 canvas->DrawPath(fill, shadow_paint); 516 canvas->DrawPath(fill, shadow_flags);
517 } 517 }
518 518
519 // Draw a white highlight on hover. 519 // Draw a white highlight on hover.
520 const SkAlpha hover_alpha = static_cast<SkAlpha>( 520 const SkAlpha hover_alpha = static_cast<SkAlpha>(
521 hover_animation().CurrentValueBetween(0x00, 0x4D)); 521 hover_animation().CurrentValueBetween(0x00, 0x4D));
522 if (hover_alpha != SK_AlphaTRANSPARENT) { 522 if (hover_alpha != SK_AlphaTRANSPARENT) {
523 paint.setColor(SkColorSetA(SK_ColorWHITE, hover_alpha)); 523 flags.setColor(SkColorSetA(SK_ColorWHITE, hover_alpha));
524 canvas->DrawPath(fill, paint); 524 canvas->DrawPath(fill, flags);
525 } 525 }
526 526
527 // Most states' opacities are adjusted using an opacity recorder in 527 // Most states' opacities are adjusted using an opacity recorder in
528 // TabStrip::PaintChildren(), but the pressed state is excluded there and 528 // TabStrip::PaintChildren(), but the pressed state is excluded there and
529 // instead rendered using a dark overlay here. Avoiding the use of the 529 // instead rendered using a dark overlay here. Avoiding the use of the
530 // opacity recorder keeps the stroke more visible in this state. 530 // opacity recorder keeps the stroke more visible in this state.
531 if (pressed) { 531 if (pressed) {
532 paint.setColor(SkColorSetA(SK_ColorBLACK, 0x14)); 532 flags.setColor(SkColorSetA(SK_ColorBLACK, 0x14));
533 canvas->DrawPath(fill, paint); 533 canvas->DrawPath(fill, flags);
534 } 534 }
535 } 535 }
536 536
537 /////////////////////////////////////////////////////////////////////////////// 537 ///////////////////////////////////////////////////////////////////////////////
538 // TabStrip::RemoveTabDelegate 538 // TabStrip::RemoveTabDelegate
539 // 539 //
540 // AnimationDelegate used when removing a tab. Does the necessary cleanup when 540 // AnimationDelegate used when removing a tab. Does the necessary cleanup when
541 // done. 541 // done.
542 class TabStrip::RemoveTabDelegate : public TabAnimationDelegate { 542 class TabStrip::RemoveTabDelegate : public TabAnimationDelegate {
543 public: 543 public:
(...skipping 2259 matching lines...) Expand 10 before | Expand all | Expand 10 after
2803 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2803 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2804 if (view) 2804 if (view)
2805 return view; 2805 return view;
2806 } 2806 }
2807 Tab* tab = FindTabForEvent(point); 2807 Tab* tab = FindTabForEvent(point);
2808 if (tab) 2808 if (tab)
2809 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2809 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2810 } 2810 }
2811 return this; 2811 return this;
2812 } 2812 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.cc ('k') | content/browser/web_contents/aura/gesture_nav_simple.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698