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

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

Issue 2640983002: Rename paint data structures (Closed)
Patch Set: DrawingDisplayItem 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
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.cc ('k') | components/favicon/core/fallback_icon_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
11 #include <string> 11 #include <string>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/metrics/histogram_macros.h" 17 #include "base/metrics/histogram_macros.h"
18 #include "base/stl_util.h" 18 #include "base/stl_util.h"
19 #include "base/strings/utf_string_conversions.h" 19 #include "base/strings/utf_string_conversions.h"
20 #include "build/build_config.h" 20 #include "build/build_config.h"
21 #include "cc/paint/paint_flags.h"
21 #include "chrome/browser/defaults.h" 22 #include "chrome/browser/defaults.h"
22 #include "chrome/browser/themes/theme_properties.h" 23 #include "chrome/browser/themes/theme_properties.h"
23 #include "chrome/browser/ui/layout_constants.h" 24 #include "chrome/browser/ui/layout_constants.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 25 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/view_ids.h" 26 #include "chrome/browser/ui/view_ids.h"
26 #include "chrome/browser/ui/views/frame/browser_view.h" 27 #include "chrome/browser/ui/views/frame/browser_view.h"
27 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h" 28 #include "chrome/browser/ui/views/tabs/stacked_tab_strip_layout.h"
28 #include "chrome/browser/ui/views/tabs/tab.h" 29 #include "chrome/browser/ui/views/tabs/tab.h"
29 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h" 30 #include "chrome/browser/ui/views/tabs/tab_drag_controller.h"
30 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h" 31 #include "chrome/browser/ui/views/tabs/tab_strip_controller.h"
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 // 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,
395 // 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
396 // the stroke, or clip out the fill inside it. 397 // the stroke, or clip out the fill inside it.
397 if (pressed) 398 if (pressed)
398 canvas->ClipPath(stroke, true); 399 canvas->ClipPath(stroke, true);
399 Op(stroke, fill, kDifference_SkPathOp, &stroke); 400 Op(stroke, fill, kDifference_SkPathOp, &stroke);
400 if (!pressed) 401 if (!pressed)
401 canvas->sk_canvas()->clipPath(fill, SkClipOp::kDifference, true); 402 canvas->sk_canvas()->clipPath(fill, SkClipOp::kDifference, true);
402 // 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
403 // the shadow will be affected by the clip we set above. 404 // the shadow will be affected by the clip we set above.
404 SkPaint paint; 405 cc::PaintFlags paint;
405 paint.setAntiAlias(true); 406 paint.setAntiAlias(true);
406 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor(); 407 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor();
407 const float alpha = SkColorGetA(stroke_color); 408 const float alpha = SkColorGetA(stroke_color);
408 const SkAlpha shadow_alpha = 409 const SkAlpha shadow_alpha =
409 base::saturated_cast<SkAlpha>(std::round(2.1875f * alpha)); 410 base::saturated_cast<SkAlpha>(std::round(2.1875f * alpha));
410 paint.setLooper( 411 paint.setLooper(
411 CreateShadowDrawLooper(SkColorSetA(stroke_color, shadow_alpha))); 412 CreateShadowDrawLooper(SkColorSetA(stroke_color, shadow_alpha)));
412 const SkAlpha path_alpha = static_cast<SkAlpha>( 413 const SkAlpha path_alpha = static_cast<SkAlpha>(
413 std::round((pressed ? 0.875f : 0.609375f) * alpha)); 414 std::round((pressed ? 0.875f : 0.609375f) * alpha));
414 paint.setColor(SkColorSetA(stroke_color, path_alpha)); 415 paint.setColor(SkColorSetA(stroke_color, path_alpha));
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 } 465 }
465 path->close(); 466 path->close();
466 } 467 }
467 468
468 void NewTabButton::PaintFill(bool pressed, 469 void NewTabButton::PaintFill(bool pressed,
469 float scale, 470 float scale,
470 const SkPath& fill, 471 const SkPath& fill,
471 gfx::Canvas* canvas) const { 472 gfx::Canvas* canvas) const {
472 gfx::ScopedCanvas scoped_canvas(canvas); 473 gfx::ScopedCanvas scoped_canvas(canvas);
473 canvas->UndoDeviceScaleFactor(); 474 canvas->UndoDeviceScaleFactor();
474 SkPaint paint; 475 cc::PaintFlags paint;
475 paint.setAntiAlias(true); 476 paint.setAntiAlias(true);
476 477
477 // For unpressed buttons, draw the fill and its shadow. 478 // For unpressed buttons, draw the fill and its shadow.
478 if (!pressed) { 479 if (!pressed) {
479 // 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
480 // need to draw a custom background image. 481 // need to draw a custom background image.
481 const ui::ThemeProvider* tp = GetThemeProvider(); 482 const ui::ThemeProvider* tp = GetThemeProvider();
482 bool custom_image; 483 bool custom_image;
483 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image); 484 const int bg_id = tab_strip_->GetBackgroundResourceId(&custom_image);
484 if (custom_image) { 485 if (custom_image) {
485 // 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
486 // strip. Otherwise the background starts at the top of the frame. 487 // strip. Otherwise the background starts at the top of the frame.
487 const int offset_y = 488 const int offset_y =
488 tp->HasCustomImage(bg_id) ? 0 : background_offset_.y(); 489 tp->HasCustomImage(bg_id) ? 0 : background_offset_.y();
489 // 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
490 // background should never be mirrored. Mirror it here to compensate. 491 // background should never be mirrored. Mirror it here to compensate.
491 float x_scale = 1.0f; 492 float x_scale = 1.0f;
492 int x = GetMirroredX() + background_offset_.x(); 493 int x = GetMirroredX() + background_offset_.x();
493 const gfx::Size size(GetLayoutSize(NEW_TAB_BUTTON)); 494 const gfx::Size size(GetLayoutSize(NEW_TAB_BUTTON));
494 if (base::i18n::IsRTL()) { 495 if (base::i18n::IsRTL()) {
495 x_scale = -1.0f; 496 x_scale = -1.0f;
496 // 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
497 // was no flip. 498 // was no flip.
498 x += size.width(); 499 x += size.width();
499 } 500 }
500 501
501 const bool succeeded = 502 const bool succeeded =
502 canvas->InitSkPaintForTiling(*tp->GetImageSkiaNamed(bg_id), x, 503 canvas->InitPaintFlagsForTiling(*tp->GetImageSkiaNamed(bg_id), x,
503 GetNewTabButtonTopOffset() + offset_y, 504 GetNewTabButtonTopOffset() + offset_y,
504 x_scale * scale, scale, 0, 0, &paint); 505 x_scale * scale, scale, 0, 0, &paint);
505 DCHECK(succeeded); 506 DCHECK(succeeded);
506 } else { 507 } else {
507 paint.setColor(tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); 508 paint.setColor(tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB));
508 } 509 }
509 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor(); 510 const SkColor stroke_color = tab_strip_->GetToolbarTopSeparatorColor();
510 const SkAlpha alpha = static_cast<SkAlpha>( 511 const SkAlpha alpha = static_cast<SkAlpha>(
511 std::round(SkColorGetA(stroke_color) * 0.59375f)); 512 std::round(SkColorGetA(stroke_color) * 0.59375f));
512 SkPaint shadow_paint = paint; 513 cc::PaintFlags shadow_paint = paint;
513 shadow_paint.setLooper( 514 shadow_paint.setLooper(
514 CreateShadowDrawLooper(SkColorSetA(stroke_color, alpha))); 515 CreateShadowDrawLooper(SkColorSetA(stroke_color, alpha)));
515 canvas->DrawPath(fill, shadow_paint); 516 canvas->DrawPath(fill, shadow_paint);
516 } 517 }
517 518
518 // Draw a white highlight on hover. 519 // Draw a white highlight on hover.
519 const SkAlpha hover_alpha = static_cast<SkAlpha>( 520 const SkAlpha hover_alpha = static_cast<SkAlpha>(
520 hover_animation().CurrentValueBetween(0x00, 0x4D)); 521 hover_animation().CurrentValueBetween(0x00, 0x4D));
521 if (hover_alpha != SK_AlphaTRANSPARENT) { 522 if (hover_alpha != SK_AlphaTRANSPARENT) {
522 paint.setColor(SkColorSetA(SK_ColorWHITE, hover_alpha)); 523 paint.setColor(SkColorSetA(SK_ColorWHITE, hover_alpha));
(...skipping 2279 matching lines...) Expand 10 before | Expand all | Expand 10 after
2802 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point); 2803 ConvertPointToViewAndGetEventHandler(this, newtab_button_, point);
2803 if (view) 2804 if (view)
2804 return view; 2805 return view;
2805 } 2806 }
2806 Tab* tab = FindTabForEvent(point); 2807 Tab* tab = FindTabForEvent(point);
2807 if (tab) 2808 if (tab)
2808 return ConvertPointToViewAndGetEventHandler(this, tab, point); 2809 return ConvertPointToViewAndGetEventHandler(this, tab, point);
2809 } 2810 }
2810 return this; 2811 return this;
2811 } 2812 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/tabs/tab.cc ('k') | components/favicon/core/fallback_icon_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698