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

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

Issue 2118853002: Fix pixelation of tab borders when device scale changes (abandoned) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Merge with recent fill_/stroke_canvas CL Created 4 years, 4 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 | « no previous file | no next file » | 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.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 26 matching lines...) Expand all
37 #include "ui/base/material_design/material_design_controller.h" 37 #include "ui/base/material_design/material_design_controller.h"
38 #include "ui/base/models/list_selection_model.h" 38 #include "ui/base/models/list_selection_model.h"
39 #include "ui/base/resource/resource_bundle.h" 39 #include "ui/base/resource/resource_bundle.h"
40 #include "ui/base/theme_provider.h" 40 #include "ui/base/theme_provider.h"
41 #include "ui/gfx/animation/animation_container.h" 41 #include "ui/gfx/animation/animation_container.h"
42 #include "ui/gfx/animation/throb_animation.h" 42 #include "ui/gfx/animation/throb_animation.h"
43 #include "ui/gfx/canvas.h" 43 #include "ui/gfx/canvas.h"
44 #include "ui/gfx/color_analysis.h" 44 #include "ui/gfx/color_analysis.h"
45 #include "ui/gfx/favicon_size.h" 45 #include "ui/gfx/favicon_size.h"
46 #include "ui/gfx/geometry/rect_conversions.h" 46 #include "ui/gfx/geometry/rect_conversions.h"
47 #include "ui/gfx/image/canvas_image_source.h"
47 #include "ui/gfx/image/image_skia_operations.h" 48 #include "ui/gfx/image/image_skia_operations.h"
48 #include "ui/gfx/paint_vector_icon.h" 49 #include "ui/gfx/paint_vector_icon.h"
49 #include "ui/gfx/path.h" 50 #include "ui/gfx/path.h"
50 #include "ui/gfx/scoped_canvas.h" 51 #include "ui/gfx/scoped_canvas.h"
51 #include "ui/gfx/skia_util.h" 52 #include "ui/gfx/skia_util.h"
52 #include "ui/gfx/vector_icons_public.h" 53 #include "ui/gfx/vector_icons_public.h"
53 #include "ui/resources/grit/ui_resources.h" 54 #include "ui/resources/grit/ui_resources.h"
54 #include "ui/views/border.h" 55 #include "ui/views/border.h"
55 #include "ui/views/controls/button/image_button.h" 56 #include "ui/views/controls/button/image_button.h"
56 #include "ui/views/controls/label.h" 57 #include "ui/views/controls/label.h"
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const double kImmersiveTabMinThrobOpacity = 0.66; 113 const double kImmersiveTabMinThrobOpacity = 0.66;
113 114
114 // Number of steps in the immersive mode loading animation. 115 // Number of steps in the immersive mode loading animation.
115 const int kImmersiveLoadingStepCount = 32; 116 const int kImmersiveLoadingStepCount = 32;
116 117
117 const char kTabCloseButtonName[] = "TabCloseButton"; 118 const char kTabCloseButtonName[] = "TabCloseButton";
118 119
119 // Parameters for PaintTabBackgroundUsingParams(). 120 // Parameters for PaintTabBackgroundUsingParams().
120 struct PaintBackgroundParams { 121 struct PaintBackgroundParams {
121 PaintBackgroundParams(bool is_active, 122 PaintBackgroundParams(bool is_active,
122 gfx::ImageSkia* fill_image_ptr, 123 gfx::ImageSkia* fill_image,
123 bool has_custom_image, 124 bool has_custom_image,
124 gfx::Rect rect, 125 const gfx::Rect& rect,
125 SkColor stroke_color, 126 SkColor stroke_color,
126 SkColor toolbar_color, 127 SkColor toolbar_color,
127 SkColor background_tab_color) 128 SkColor background_tab_color,
129 bool draw_hover,
130 const gfx::Point& hover_location,
131 SkAlpha hover_alpha)
128 : is_active(is_active), 132 : is_active(is_active),
129 fill_image(fill_image_ptr ? *fill_image_ptr : gfx::ImageSkia()), 133 fill_image(fill_image ? *fill_image : gfx::ImageSkia()),
130 has_custom_image(has_custom_image), 134 has_custom_image(has_custom_image),
131 rect(rect), 135 rect(rect),
132 stroke_color(stroke_color), 136 stroke_color(stroke_color),
133 toolbar_color(toolbar_color), 137 toolbar_color(toolbar_color),
134 background_tab_color(background_tab_color) {} 138 background_tab_color(background_tab_color),
139 draw_hover(draw_hover),
140 hover_location(PointToSkPoint(hover_location)),
141 hover_alpha(hover_alpha) {}
135 142
136 const bool is_active; 143 const bool is_active;
137 const gfx::ImageSkia fill_image; 144 const gfx::ImageSkia fill_image;
138 const bool has_custom_image; 145 const bool has_custom_image;
139 const gfx::Rect rect; 146 const gfx::Rect rect;
140 const SkColor stroke_color; 147 const SkColor stroke_color;
141 const SkColor toolbar_color; 148 const SkColor toolbar_color;
142 const SkColor background_tab_color; 149 const SkColor background_tab_color;
150 const bool draw_hover;
151 const SkPoint hover_location;
152 const SkAlpha hover_alpha;
143 }; 153 };
144 154
155 void PaintTabBackgroundUsingParams(gfx::Canvas* fill_canvas,
156 gfx::Canvas* stroke_canvas,
157 const PaintBackgroundParams& params);
158
159 ////////////////////////////////////////////////////////////////////////////////
160 // TabImageSource
161 //
162 // This subclass of CanvasImageSource allows the inactive tab image to be cached
163 // once and rendered correctly for all scale factors.
164 class TabImageSource : public gfx::CanvasImageSource {
165 public:
166 enum UseCanvas { FILL, STROKE, BOTH };
167
168 TabImageSource(UseCanvas use_canvas, Tab* tab, int fill_id, int y_offset);
169 ~TabImageSource() override {}
170
171 // gfx::CanvasImageSource override.
172 void Draw(gfx::Canvas* canvas) override;
173
174 private:
175 const UseCanvas use_canvas_;
176 const PaintBackgroundParams params_;
177
178 DISALLOW_COPY_AND_ASSIGN(TabImageSource);
179 };
180
181 TabImageSource::TabImageSource(UseCanvas use_canvas,
182 Tab* tab,
183 int fill_id,
184 int y_offset)
185 : gfx::CanvasImageSource(tab->size(), true),
186 use_canvas_(use_canvas),
187 params_(false,
188 tab->GetThemeProvider()->GetImageSkiaNamed(fill_id),
189 false,
190 gfx::Rect(gfx::Point(0, y_offset), tab->size()),
191 tab->controller()->GetToolbarTopSeparatorColor(),
192 tab->GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR),
193 tab->GetThemeProvider()->GetColor(
194 ThemeProperties::COLOR_BACKGROUND_TAB),
195 false,
196 gfx::Point(),
197 255) {}
198
199 void TabImageSource::Draw(gfx::Canvas* canvas) {
200 PaintTabBackgroundUsingParams(use_canvas_ != STROKE ? canvas : nullptr,
Peter Kasting 2016/08/11 22:51:15 Nit: Prefer "use_canvas_ == STROKE ? nullptr : can
Greg Levin 2016/08/12 19:48:15 Obsolete due to other change.
201 use_canvas_ != FILL ? canvas : nullptr,
202 params_);
203 }
204
145 //////////////////////////////////////////////////////////////////////////////// 205 ////////////////////////////////////////////////////////////////////////////////
146 // ImageCacheEntryMetadata 206 // ImageCacheEntryMetadata
147 // 207 //
148 // All metadata necessary to uniquely identify a cached image. 208 // All metadata necessary to uniquely identify a cached image.
149 struct ImageCacheEntryMetadata { 209 struct ImageCacheEntryMetadata {
150 ImageCacheEntryMetadata(int resource_id, 210 ImageCacheEntryMetadata(int resource_id,
151 SkColor fill_color, 211 SkColor fill_color,
152 SkColor stroke_color, 212 SkColor stroke_color,
153 bool use_fill_and_stroke_images, 213 bool use_fill_and_stroke_images,
154 ui::ScaleFactor scale_factor,
155 const gfx::Size& size); 214 const gfx::Size& size);
156 215
157 ~ImageCacheEntryMetadata(); 216 ~ImageCacheEntryMetadata();
158 217
159 bool operator==(const ImageCacheEntryMetadata& rhs) const; 218 bool operator==(const ImageCacheEntryMetadata& rhs) const;
160 219
161 int resource_id; // Only needed by pre-MD 220 int resource_id; // Only needed by pre-MD
162 SkColor fill_color; // Both colors only needed by MD 221 SkColor fill_color; // Both colors only needed by MD
163 SkColor stroke_color; 222 SkColor stroke_color;
164 bool use_fill_and_stroke_images; 223 bool use_fill_and_stroke_images;
165 ui::ScaleFactor scale_factor;
166 gfx::Size size; 224 gfx::Size size;
167 }; 225 };
168 226
169 ImageCacheEntryMetadata::ImageCacheEntryMetadata( 227 ImageCacheEntryMetadata::ImageCacheEntryMetadata(
170 int resource_id, 228 int resource_id,
171 SkColor fill_color, 229 SkColor fill_color,
172 SkColor stroke_color, 230 SkColor stroke_color,
173 bool use_fill_and_stroke_images, 231 bool use_fill_and_stroke_images,
174 ui::ScaleFactor scale_factor,
175 const gfx::Size& size) 232 const gfx::Size& size)
176 : resource_id(resource_id), 233 : resource_id(resource_id),
177 fill_color(fill_color), 234 fill_color(fill_color),
178 stroke_color(stroke_color), 235 stroke_color(stroke_color),
179 use_fill_and_stroke_images(use_fill_and_stroke_images), 236 use_fill_and_stroke_images(use_fill_and_stroke_images),
180 scale_factor(scale_factor),
181 size(size) { 237 size(size) {
182 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor);
183
184 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones 238 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones
185 // so they don't cause incorrect cache misses. 239 // so they don't cause incorrect cache misses.
186 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. 240 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted.
187 if (ui::MaterialDesignController::IsModeMaterial()) 241 if (ui::MaterialDesignController::IsModeMaterial())
188 resource_id = 0; 242 resource_id = 0;
189 else 243 else
190 fill_color = stroke_color = SK_ColorTRANSPARENT; 244 fill_color = stroke_color = SK_ColorTRANSPARENT;
191 } 245 }
192 246
193 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} 247 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {}
194 248
195 bool ImageCacheEntryMetadata::operator==( 249 bool ImageCacheEntryMetadata::operator==(
196 const ImageCacheEntryMetadata& rhs) const { 250 const ImageCacheEntryMetadata& rhs) const {
197 return resource_id == rhs.resource_id && fill_color == rhs.fill_color && 251 return resource_id == rhs.resource_id && fill_color == rhs.fill_color &&
198 stroke_color == rhs.stroke_color && 252 stroke_color == rhs.stroke_color &&
199 use_fill_and_stroke_images == rhs.use_fill_and_stroke_images && 253 use_fill_and_stroke_images == rhs.use_fill_and_stroke_images &&
200 scale_factor == rhs.scale_factor && size == rhs.size; 254 size == rhs.size;
201 } 255 }
202 256
203 //////////////////////////////////////////////////////////////////////////////// 257 ////////////////////////////////////////////////////////////////////////////////
204 // ImageCacheEntry and cache management 258 // ImageCacheEntry and cache management
205 // 259 //
206 // A cached image and the metadata used to generate it. 260 // A cached image and the metadata used to generate it.
207 struct ImageCacheEntry { 261 struct ImageCacheEntry {
208 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, 262 ImageCacheEntry(const ImageCacheEntryMetadata& metadata,
209 const gfx::ImageSkia& fill_image, 263 Tab* tab,
210 const gfx::ImageSkia& stroke_image); 264 int fill_id,
265 int y_offset);
211 ~ImageCacheEntry(); 266 ~ImageCacheEntry();
212 267
213 ImageCacheEntryMetadata metadata; 268 ImageCacheEntryMetadata metadata;
214 gfx::ImageSkia fill_image; 269 gfx::ImageSkia fill_image;
215 gfx::ImageSkia stroke_image; 270 gfx::ImageSkia stroke_image;
216 }; 271 };
217 272
218 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata, 273 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata,
219 const gfx::ImageSkia& fill_image, 274 Tab* tab,
220 const gfx::ImageSkia& stroke_image) 275 int fill_id,
221 : metadata(metadata), fill_image(fill_image), stroke_image(stroke_image) {} 276 int y_offset)
277 : metadata(metadata) {
278 if (metadata.use_fill_and_stroke_images) {
279 fill_image = gfx::ImageSkia(
280 new TabImageSource(TabImageSource::FILL, tab, fill_id, y_offset),
281 tab->size());
282 }
283 TabImageSource::UseCanvas use = metadata.use_fill_and_stroke_images
284 ? TabImageSource::STROKE
285 : TabImageSource::BOTH;
286 stroke_image = gfx::ImageSkia(new TabImageSource(use, tab, fill_id, y_offset),
287 tab->size());
288 }
222 289
223 ImageCacheEntry::~ImageCacheEntry() {} 290 ImageCacheEntry::~ImageCacheEntry() {}
224 291
225 typedef std::list<ImageCacheEntry> ImageCache; 292 typedef std::list<ImageCacheEntry> ImageCache;
226 293
227 // As the majority of the tabs are inactive, and painting tabs is slowish, 294 // As the majority of the tabs are inactive, and painting tabs is slowish,
228 // we cache a handful of the inactive tab backgrounds here. 295 // we cache a handful of the inactive tab backgrounds here.
229 static ImageCache* g_image_cache = nullptr; 296 static ImageCache* g_image_cache = nullptr;
230 297
231 struct TabImages { 298 struct TabImages {
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
476 // Draw center. Instead of masking out the top portion we simply skip over it 543 // Draw center. Instead of masking out the top portion we simply skip over it
477 // by incrementing by the top padding, since it's a simple rectangle. 544 // by incrementing by the top padding, since it's a simple rectangle.
478 rect.Inset(g_mask_images.l_width, tab_insets.top(), g_mask_images.r_width, 545 rect.Inset(g_mask_images.l_width, tab_insets.top(), g_mask_images.r_width,
479 toolbar_overlap); 546 toolbar_overlap);
480 canvas->TileImageInt(fill_image, rect.x(), rect.y(), g_mask_images.l_width, 547 canvas->TileImageInt(fill_image, rect.x(), rect.y(), g_mask_images.l_width,
481 tab_insets.top(), rect.width(), rect.height()); 548 tab_insets.top(), rect.width(), rect.height());
482 } 549 }
483 550
484 void PaintTabBackgroundUsingParams(gfx::Canvas* fill_canvas, 551 void PaintTabBackgroundUsingParams(gfx::Canvas* fill_canvas,
485 gfx::Canvas* stroke_canvas, 552 gfx::Canvas* stroke_canvas,
486 views::GlowHoverController* hc,
487 const PaintBackgroundParams& params) { 553 const PaintBackgroundParams& params) {
488 const gfx::Rect& rect = params.rect; 554 const gfx::Rect& rect = params.rect;
489 const SkScalar kMinHoverRadius = 16; 555 const SkScalar kMinHoverRadius = 16;
490 const SkScalar radius = 556 const SkScalar radius =
491 std::max(SkFloatToScalar(rect.width() / 4.f), kMinHoverRadius); 557 std::max(SkFloatToScalar(rect.width() / 4.f), kMinHoverRadius);
492 const bool draw_hover = !params.is_active && hc;
493 SkPoint hover_location(
494 gfx::PointToSkPoint(draw_hover ? hc->location() : gfx::Point()));
495 const SkColor hover_color = 558 const SkColor hover_color =
496 SkColorSetA(params.toolbar_color, draw_hover ? hc->GetAlpha() : 255); 559 SkColorSetA(params.toolbar_color, params.hover_alpha);
497 560
498 if (ui::MaterialDesignController::IsModeMaterial()) { 561 if (ui::MaterialDesignController::IsModeMaterial()) {
499 gfx::Path fill; 562 gfx::Path fill;
500 SkPaint paint; 563 SkPaint paint;
501 paint.setAntiAlias(true); 564 paint.setAntiAlias(true);
502 565
503 // Draw the fill. 566 // Draw the fill.
504 { 567 if (fill_canvas) {
505 gfx::ScopedCanvas scoped_canvas(fill_canvas); 568 gfx::ScopedCanvas scoped_canvas(fill_canvas);
506 const float scale = fill_canvas->UndoDeviceScaleFactor(); 569 const float scale = fill_canvas->UndoDeviceScaleFactor();
507 570
508 fill = GetFillPath(scale, rect.size()); 571 fill = GetFillPath(scale, rect.size());
509 { 572 {
510 gfx::ScopedCanvas clip_scoper(fill_canvas); 573 gfx::ScopedCanvas clip_scoper(fill_canvas);
511 fill_canvas->ClipPath(fill, true); 574 fill_canvas->ClipPath(fill, true);
512 if (!params.fill_image.isNull()) { 575 if (!params.fill_image.isNull()) {
513 gfx::ScopedCanvas scale_scoper(fill_canvas); 576 gfx::ScopedCanvas scale_scoper(fill_canvas);
514 fill_canvas->sk_canvas()->scale(scale, scale); 577 fill_canvas->sk_canvas()->scale(scale, scale);
515 fill_canvas->TileImageInt(params.fill_image, rect.x(), rect.y(), 0, 0, 578 fill_canvas->TileImageInt(params.fill_image, rect.x(), rect.y(), 0, 0,
516 rect.width(), rect.height()); 579 rect.width(), rect.height());
517 } else { 580 } else {
518 paint.setColor(params.is_active ? params.toolbar_color 581 paint.setColor(params.is_active ? params.toolbar_color
519 : params.background_tab_color); 582 : params.background_tab_color);
520 fill_canvas->DrawRect( 583 fill_canvas->DrawRect(
521 gfx::ScaleToEnclosingRect(gfx::Rect(rect.size()), scale), 584 gfx::ScaleToEnclosingRect(gfx::Rect(rect.size()), scale),
522 paint); 585 paint);
523 } 586 }
524 if (draw_hover) { 587 if (params.draw_hover) {
525 hover_location.scale(SkFloatToScalar(scale)); 588 DrawHighlight(fill_canvas, params.hover_location * scale,
526 DrawHighlight(fill_canvas, hover_location, radius * scale, 589 radius * scale, hover_color);
527 hover_color);
528 } 590 }
529 } 591 }
530 } 592 }
531 593
532 // Draw the stroke. 594 // Draw the stroke.
533 { 595 if (stroke_canvas) {
534 gfx::ScopedCanvas scoped_canvas(stroke_canvas); 596 gfx::ScopedCanvas scoped_canvas(stroke_canvas);
535 const float scale = stroke_canvas->UndoDeviceScaleFactor(); 597 const float scale = stroke_canvas->UndoDeviceScaleFactor();
536 598
537 gfx::Path stroke = GetBorderPath(scale, false, false, rect.size()); 599 gfx::Path stroke = GetBorderPath(scale, false, false, rect.size());
538 Op(stroke, fill, kDifference_SkPathOp, &stroke); 600 Op(stroke, fill, kDifference_SkPathOp, &stroke);
539 if (!params.is_active) { 601 if (!params.is_active) {
540 // Clip out the bottom line; this will be drawn for us by 602 // Clip out the bottom line; this will be drawn for us by
541 // TabStrip::PaintChildren(). 603 // TabStrip::PaintChildren().
542 stroke_canvas->ClipRect(gfx::RectF(rect.width() * scale, 604 stroke_canvas->ClipRect(gfx::RectF(rect.width() * scale,
543 rect.height() * scale - 1)); 605 rect.height() * scale - 1));
544 } 606 }
545 paint.setColor(params.stroke_color); 607 paint.setColor(params.stroke_color);
546 stroke_canvas->DrawPath(stroke, paint); 608 stroke_canvas->DrawPath(stroke, paint);
547 } 609 }
548 } else { 610 } else {
549 gfx::Canvas* canvas = stroke_canvas; 611 gfx::Canvas* canvas = stroke_canvas;
550 if (draw_hover) { 612 if (params.draw_hover) {
551 // Draw everything to a temporary canvas so we can extract an image for 613 // Draw everything to a temporary canvas so we can extract an image for
552 // use in masking the hover glow. 614 // use in masking the hover glow.
553 gfx::Canvas background_canvas(rect.size(), canvas->image_scale(), false); 615 gfx::Canvas background_canvas(rect.size(), canvas->image_scale(), false);
554 PaintTabFill(&background_canvas, params.fill_image, rect, 616 PaintTabFill(&background_canvas, params.fill_image, rect,
555 params.is_active); 617 params.is_active);
556 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); 618 gfx::ImageSkia background_image(background_canvas.ExtractImageRep());
557 canvas->DrawImageInt(background_image, 0, 0); 619 canvas->DrawImageInt(background_image, 0, 0);
558 620
559 gfx::Canvas hover_canvas(rect.size(), canvas->image_scale(), false); 621 gfx::Canvas hover_canvas(rect.size(), canvas->image_scale(), false);
560 DrawHighlight(&hover_canvas, hover_location, radius, hover_color); 622 DrawHighlight(&hover_canvas, params.hover_location, radius, hover_color);
561 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( 623 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage(
562 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); 624 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image);
563 canvas->DrawImageInt(result, 0, 0); 625 canvas->DrawImageInt(result, 0, 0);
564 } else { 626 } else {
565 PaintTabFill(canvas, params.fill_image, rect, params.is_active); 627 PaintTabFill(canvas, params.fill_image, rect, params.is_active);
566 } 628 }
567 629
568 // Now draw the stroke, highlights, and shadows around the tab edge. 630 // Now draw the stroke, highlights, and shadows around the tab edge.
569 TabImages* stroke_images = 631 TabImages* stroke_images =
570 params.is_active ? &g_active_images : &g_inactive_images; 632 params.is_active ? &g_active_images : &g_inactive_images;
(...skipping 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 // really need to clip the stroke and not the fill (for stacked tabs). This 1577 // really need to clip the stroke and not the fill (for stacked tabs). This
1516 // saves memory and avoids an extra image draw at the cost of recalculating 1578 // saves memory and avoids an extra image draw at the cost of recalculating
1517 // the images when MaySetClip() toggles. 1579 // the images when MaySetClip() toggles.
1518 const bool use_fill_and_stroke_images = 1580 const bool use_fill_and_stroke_images =
1519 controller_->MaySetClip() && 1581 controller_->MaySetClip() &&
1520 ui::MaterialDesignController::IsModeMaterial(); 1582 ui::MaterialDesignController::IsModeMaterial();
1521 1583
1522 const ImageCacheEntryMetadata metadata( 1584 const ImageCacheEntryMetadata metadata(
1523 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), 1585 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB),
1524 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, 1586 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images,
1525 ui::GetSupportedScaleFactor(canvas->image_scale()), size()); 1587 size());
1526 auto it = std::find_if( 1588 auto it = std::find_if(
1527 g_image_cache->begin(), g_image_cache->end(), 1589 g_image_cache->begin(), g_image_cache->end(),
1528 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); 1590 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; });
1529 if (it == g_image_cache->end()) { 1591 if (it == g_image_cache->end()) {
1530 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); 1592 g_image_cache->emplace_front(metadata, this, fill_id, y_offset);
1531 if (use_fill_and_stroke_images) {
1532 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false);
1533 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false,
1534 fill_id, false, y_offset);
1535 g_image_cache->emplace_front(
1536 metadata, gfx::ImageSkia(tmp_fill_canvas.ExtractImageRep()),
1537 gfx::ImageSkia(tmp_canvas.ExtractImageRep()));
1538 } else {
1539 PaintTabBackgroundUsingFillId(&tmp_canvas, &tmp_canvas, false, fill_id,
1540 false, y_offset);
1541 g_image_cache->emplace_front(
1542 metadata, gfx::ImageSkia(),
1543 gfx::ImageSkia(tmp_canvas.ExtractImageRep()));
1544 }
1545 if (g_image_cache->size() > kMaxImageCacheSize) 1593 if (g_image_cache->size() > kMaxImageCacheSize)
1546 g_image_cache->pop_back(); 1594 g_image_cache->pop_back();
1547 it = g_image_cache->begin(); 1595 it = g_image_cache->begin();
1548 } 1596 }
1549 1597
1550 gfx::ScopedCanvas scoped_canvas( 1598 gfx::ScopedCanvas scoped_canvas(
1551 use_fill_and_stroke_images ? canvas : nullptr); 1599 use_fill_and_stroke_images ? canvas : nullptr);
1552 if (use_fill_and_stroke_images) { 1600 if (use_fill_and_stroke_images) {
1553 canvas->DrawImageInt(it->fill_image, 0, 0); 1601 canvas->DrawImageInt(it->fill_image, 0, 0);
1554 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true); 1602 canvas->sk_canvas()->clipPath(clip, SkRegion::kDifference_Op, true);
1555 } 1603 }
1556 canvas->DrawImageInt(it->stroke_image, 0, 0); 1604 canvas->DrawImageInt(it->stroke_image, 0, 0);
1557 } 1605 }
1558 1606
1559 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, 1607 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas,
1560 gfx::Canvas* stroke_canvas, 1608 gfx::Canvas* stroke_canvas,
1561 bool is_active, 1609 bool is_active,
1562 int fill_id, 1610 int fill_id,
1563 bool has_custom_image, 1611 bool has_custom_image,
1564 int y_offset) { 1612 int y_offset) {
1565 views::GlowHoverController* hc =
1566 hover_controller_.ShouldDraw() ? &hover_controller_ : nullptr;
1567 gfx::ImageSkia* fill_image = 1613 gfx::ImageSkia* fill_image =
1568 has_custom_image || !ui::MaterialDesignController::IsModeMaterial() 1614 has_custom_image || !ui::MaterialDesignController::IsModeMaterial()
1569 ? GetThemeProvider()->GetImageSkiaNamed(fill_id) 1615 ? GetThemeProvider()->GetImageSkiaNamed(fill_id)
1570 : nullptr; 1616 : nullptr;
1571 // The tab image needs to be lined up with the background image 1617 // The tab image needs to be lined up with the background image
1572 // so that it feels partially transparent. These offsets represent the tab 1618 // so that it feels partially transparent. These offsets represent the tab
1573 // position within the frame background image. 1619 // position within the frame background image.
1574 gfx::Rect rect(GetLocalBounds()); 1620 gfx::Rect rect(GetLocalBounds());
1575 rect.Offset(GetMirroredX() + background_offset_.x(), y_offset); 1621 rect.Offset(GetMirroredX() + background_offset_.x(), y_offset);
1576 PaintBackgroundParams params( 1622 PaintBackgroundParams params(
1577 is_active, fill_image, has_custom_image, rect, 1623 is_active, fill_image, has_custom_image, rect,
1578 controller_->GetToolbarTopSeparatorColor(), 1624 controller_->GetToolbarTopSeparatorColor(),
1579 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), 1625 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR),
1580 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); 1626 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB),
1627 !is_active && hover_controller_.ShouldDraw(),
1628 hover_controller_.location(), hover_controller_.GetAlpha());
1581 1629
1582 PaintTabBackgroundUsingParams(fill_canvas, stroke_canvas, hc, params); 1630 PaintTabBackgroundUsingParams(fill_canvas, stroke_canvas, params);
1583 } 1631 }
1584 1632
1585 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( 1633 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon(
1586 gfx::Canvas* canvas, 1634 gfx::Canvas* canvas,
1587 const gfx::Rect& favicon_draw_bounds) { 1635 const gfx::Rect& favicon_draw_bounds) {
1588 // The pinned tab title changed indicator consists of two parts: 1636 // The pinned tab title changed indicator consists of two parts:
1589 // . a clear (totally transparent) part over the bottom right (or left in rtl) 1637 // . a clear (totally transparent) part over the bottom right (or left in rtl)
1590 // of the favicon. This is done by drawing the favicon to a canvas, then 1638 // of the favicon. This is done by drawing the favicon to a canvas, then
1591 // drawing the clear part on top of the favicon. 1639 // drawing the clear part on top of the favicon.
1592 // . a circle in the bottom right (or left in rtl) of the favicon. 1640 // . 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
1821 gfx::Rect Tab::GetImmersiveBarRect() const { 1869 gfx::Rect Tab::GetImmersiveBarRect() const {
1822 // The main bar is as wide as the normal tab's horizontal top line. 1870 // The main bar is as wide as the normal tab's horizontal top line.
1823 // This top line of the tab extends a few pixels left and right of the 1871 // This top line of the tab extends a few pixels left and right of the
1824 // center image due to pixels in the rounded corner images. 1872 // center image due to pixels in the rounded corner images.
1825 const int kBarPadding = 1; 1873 const int kBarPadding = 1;
1826 int main_bar_left = g_active_images.l_width - kBarPadding; 1874 int main_bar_left = g_active_images.l_width - kBarPadding;
1827 int main_bar_right = width() - g_active_images.r_width + kBarPadding; 1875 int main_bar_right = width() - g_active_images.r_width + kBarPadding;
1828 return gfx::Rect( 1876 return gfx::Rect(
1829 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); 1877 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight);
1830 } 1878 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698