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

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: Address review 3 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 // The minimum opacity (out of 1) when a tab (either active or inactive) is 111 // The minimum opacity (out of 1) when a tab (either active or inactive) is
111 // throbbing in the immersive mode light strip. 112 // throbbing in the immersive mode light strip.
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 //////////////////////////////////////////////////////////////////////////////// 120 ////////////////////////////////////////////////////////////////////////////////
121 // PaintBackgroundParams
122
123 struct PaintBackgroundParams {
124 bool is_active;
125 gfx::ImageSkia fill_image;
126 bool has_custom_image;
127 gfx::Point offset;
128 gfx::Size size;
129 SkColor stroke_color;
130 SkColor toolbar_color;
131 SkColor background_color;
132 };
133
134 void PaintTabBackgroundUsingFillId(gfx::Canvas* canvas,
135 views::GlowHoverController* hc,
136 const PaintBackgroundParams& params);
137
138 ////////////////////////////////////////////////////////////////////////////////
139 // TabImageSource
140 //
141 // This subclass of CanvasImageSource allows the inactive tab image to be cached
142 // once and rendered correctly for all scale factors.
143 class TabImageSource : public gfx::CanvasImageSource {
144 public:
145 TabImageSource(Tab* tab, int fill_id, int y_offset);
146 ~TabImageSource() override {}
147
148 // gfx::CanvasImageSource override.
149 void Draw(gfx::Canvas* canvas) override;
150
151 private:
152 PaintBackgroundParams params_;
153
154 DISALLOW_COPY_AND_ASSIGN(TabImageSource);
155 };
156
157 TabImageSource::TabImageSource(Tab* tab, int fill_id, int y_offset)
158 : gfx::CanvasImageSource(tab->size(), true) {
159 params_.is_active = false;
160 if (!ui::MaterialDesignController::IsModeMaterial())
161 params_.fill_image = *tab->GetThemeProvider()->GetImageSkiaNamed(fill_id);
162 params_.has_custom_image = false;
163 params_.offset.SetPoint(0, y_offset);
164 params_.size = tab->size();
165 params_.stroke_color = tab->controller()->GetToolbarTopSeparatorColor();
166 params_.toolbar_color =
167 tab->GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR);
168 params_.background_color =
169 tab->GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB);
170 }
171
172 void TabImageSource::Draw(gfx::Canvas* canvas) {
173 PaintTabBackgroundUsingFillId(canvas, nullptr, params_);
174 }
175
176 ////////////////////////////////////////////////////////////////////////////////
120 // ImageCacheEntryMetadata 177 // ImageCacheEntryMetadata
121 // 178 //
122 // All metadata necessary to uniquely identify a cached image. 179 // All metadata necessary to uniquely identify a cached image.
123 struct ImageCacheEntryMetadata { 180 struct ImageCacheEntryMetadata {
124 ImageCacheEntryMetadata(int resource_id, 181 ImageCacheEntryMetadata(int resource_id,
125 SkColor fill_color, 182 SkColor fill_color,
126 SkColor stroke_color, 183 SkColor stroke_color,
127 ui::ScaleFactor scale_factor,
128 const gfx::Size& size); 184 const gfx::Size& size);
129 185
130 ~ImageCacheEntryMetadata(); 186 ~ImageCacheEntryMetadata();
131 187
132 bool operator==(const ImageCacheEntryMetadata& rhs) const; 188 bool operator==(const ImageCacheEntryMetadata& rhs) const;
133 189
134 int resource_id; // Only needed by pre-MD 190 int resource_id; // Only needed by pre-MD
135 SkColor fill_color; // Both colors only needed by MD 191 SkColor fill_color; // Both colors only needed by MD
136 SkColor stroke_color; 192 SkColor stroke_color;
137 ui::ScaleFactor scale_factor;
138 gfx::Size size; 193 gfx::Size size;
139 }; 194 };
140 195
141 ImageCacheEntryMetadata::ImageCacheEntryMetadata(int resource_id, 196 ImageCacheEntryMetadata::ImageCacheEntryMetadata(int resource_id,
142 SkColor fill_color, 197 SkColor fill_color,
143 SkColor stroke_color, 198 SkColor stroke_color,
144 ui::ScaleFactor scale_factor,
145 const gfx::Size& size) 199 const gfx::Size& size)
146 : resource_id(resource_id), 200 : resource_id(resource_id),
147 fill_color(fill_color), 201 fill_color(fill_color),
148 stroke_color(stroke_color), 202 stroke_color(stroke_color),
149 scale_factor(scale_factor),
150 size(size) { 203 size(size) {
151 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor);
152
153 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones 204 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones
154 // so they don't cause incorrect cache misses. 205 // so they don't cause incorrect cache misses.
155 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. 206 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted.
156 if (ui::MaterialDesignController::IsModeMaterial()) 207 if (ui::MaterialDesignController::IsModeMaterial())
157 resource_id = 0; 208 resource_id = 0;
158 else 209 else
159 fill_color = stroke_color = SK_ColorTRANSPARENT; 210 fill_color = stroke_color = SK_ColorTRANSPARENT;
160 } 211 }
161 212
162 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} 213 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {}
163 214
164 bool ImageCacheEntryMetadata::operator==( 215 bool ImageCacheEntryMetadata::operator==(
165 const ImageCacheEntryMetadata& rhs) const { 216 const ImageCacheEntryMetadata& rhs) const {
166 return resource_id == rhs.resource_id && fill_color == rhs.fill_color && 217 return resource_id == rhs.resource_id && fill_color == rhs.fill_color &&
167 stroke_color == rhs.stroke_color && scale_factor == rhs.scale_factor && 218 stroke_color == rhs.stroke_color && size == rhs.size;
168 size == rhs.size;
169 } 219 }
170 220
171 //////////////////////////////////////////////////////////////////////////////// 221 ////////////////////////////////////////////////////////////////////////////////
172 // ImageCacheEntry and cache management 222 // ImageCacheEntry and cache management
173 // 223 //
174 // A cached image and the metadata used to generate it. 224 // A cached image and the metadata used to generate it.
175 struct ImageCacheEntry { 225 struct ImageCacheEntry {
176 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, 226 ImageCacheEntry(const ImageCacheEntryMetadata& metadata,
177 const gfx::ImageSkia& image); 227 Tab* tab,
228 int fill_id,
229 int y_offset);
178 ~ImageCacheEntry(); 230 ~ImageCacheEntry();
179 231
180 ImageCacheEntryMetadata metadata; 232 ImageCacheEntryMetadata metadata;
181 gfx::ImageSkia image; 233 gfx::ImageSkia image;
182 }; 234 };
183 235
184 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata, 236 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata,
185 const gfx::ImageSkia& image) 237 Tab* tab,
186 : metadata(metadata), image(image) {} 238 int fill_id,
239 int y_offset)
240 : metadata(metadata),
241 image(new TabImageSource(tab, fill_id, y_offset), tab->size()) {}
187 242
188 ImageCacheEntry::~ImageCacheEntry() {} 243 ImageCacheEntry::~ImageCacheEntry() {}
189 244
190 typedef std::list<ImageCacheEntry> ImageCache; 245 typedef std::list<ImageCacheEntry> ImageCache;
191 246
192 // As the majority of the tabs are inactive, and painting tabs is slowish, 247 // As the majority of the tabs are inactive, and painting tabs is slowish,
193 // we cache a handful of the inactive tab backgrounds here. 248 // we cache a handful of the inactive tab backgrounds here.
194 static ImageCache* g_image_cache = nullptr; 249 static ImageCache* g_image_cache = nullptr;
195 250
196 struct TabImages { 251 struct TabImages {
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 canvas->sk_canvas()->drawRect( 321 canvas->sk_canvas()->drawRect(
267 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2), 322 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2),
268 paint); 323 paint);
269 } 324 }
270 325
271 // Returns whether the favicon for the given URL should be colored according to 326 // Returns whether the favicon for the given URL should be colored according to
272 // the browser theme. 327 // the browser theme.
273 bool ShouldThemifyFaviconForUrl(const GURL& url) { 328 bool ShouldThemifyFaviconForUrl(const GURL& url) {
274 return url.SchemeIs(content::kChromeUIScheme) && 329 return url.SchemeIs(content::kChromeUIScheme) &&
275 url.host() != chrome::kChromeUIHelpHost && 330 url.host() != chrome::kChromeUIHelpHost &&
276 url.host() != chrome::kChromeUIUberHost && 331 url.host() != chrome::kChromeUIUberHost;
277 url.host() != chrome::kChromeUIAppLauncherPageHost;
278 } 332 }
279 333
280 // Computes a path corresponding to the tab's content region inside the outer 334 // Computes a path corresponding to the tab's content region inside the outer
281 // stroke. 335 // stroke.
282 void GetFillPath(float scale, const gfx::Size& size, SkPath* fill) { 336 void GetFillPath(float scale, const gfx::Size& size, SkPath* fill) {
283 const float right = size.width() * scale; 337 const float right = size.width() * scale;
284 // The bottom of the tab needs to be pixel-aligned or else when we call 338 // The bottom of the tab needs to be pixel-aligned or else when we call
285 // ClipPath with anti-aliasing enabled it can cause artifacts. 339 // ClipPath with anti-aliasing enabled it can cause artifacts.
286 const float bottom = std::ceil(size.height() * scale); 340 const float bottom = std::ceil(size.height() * scale);
287 const float unscaled_endcap_width = GetUnscaledEndcapWidth(); 341 const float unscaled_endcap_width = GetUnscaledEndcapWidth();
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
344 1.5 * scale); 398 1.5 * scale);
345 } 399 }
346 path->lineTo(right - 2 * scale, bottom - 1 - 1.5 * scale); 400 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, 401 path->rCubicTo(0.375 * scale, scale, 1.25 * scale, 1.5 * scale, 2 * scale,
348 1.5 * scale); 402 1.5 * scale);
349 path->rLineTo(0, 1); 403 path->rLineTo(0, 1);
350 path->close(); 404 path->close();
351 } 405 }
352 406
353 void PaintTabFill(gfx::Canvas* canvas, 407 void PaintTabFill(gfx::Canvas* canvas,
354 gfx::ImageSkia* fill_image, 408 const gfx::ImageSkia& fill_image,
355 int x_offset, 409 int x_offset,
356 int y_offset, 410 int y_offset,
357 const gfx::Size& size, 411 const gfx::Size& size,
358 bool is_active) { 412 bool is_active) {
359 const gfx::Insets tab_insets(GetLayoutInsets(TAB)); 413 const gfx::Insets tab_insets(GetLayoutInsets(TAB));
360 // If this isn't the foreground tab, don't draw over the toolbar, but do 414 // 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. 415 // include the 1 px divider stroke at the bottom.
362 const int toolbar_overlap = is_active ? 0 : (tab_insets.bottom() - 1); 416 const int toolbar_overlap = is_active ? 0 : (tab_insets.bottom() - 1);
363 417
364 // Draw left edge. 418 // Draw left edge.
365 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage( 419 gfx::ImageSkia tab_l = gfx::ImageSkiaOperations::CreateTiledImage(
366 *fill_image, x_offset, y_offset, g_mask_images.l_width, size.height()); 420 fill_image, x_offset, y_offset, g_mask_images.l_width, size.height());
367 gfx::ImageSkia theme_l = gfx::ImageSkiaOperations::CreateMaskedImage( 421 gfx::ImageSkia theme_l = gfx::ImageSkiaOperations::CreateMaskedImage(
368 tab_l, *g_mask_images.image_l); 422 tab_l, *g_mask_images.image_l);
369 canvas->DrawImageInt( 423 canvas->DrawImageInt(
370 theme_l, 0, 0, theme_l.width(), theme_l.height() - toolbar_overlap, 0, 0, 424 theme_l, 0, 0, theme_l.width(), theme_l.height() - toolbar_overlap, 0, 0,
371 theme_l.width(), theme_l.height() - toolbar_overlap, false); 425 theme_l.width(), theme_l.height() - toolbar_overlap, false);
372 426
373 // Draw right edge. 427 // Draw right edge.
374 gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage( 428 gfx::ImageSkia tab_r = gfx::ImageSkiaOperations::CreateTiledImage(
375 *fill_image, x_offset + size.width() - g_mask_images.r_width, y_offset, 429 fill_image, x_offset + size.width() - g_mask_images.r_width, y_offset,
376 g_mask_images.r_width, size.height()); 430 g_mask_images.r_width, size.height());
377 gfx::ImageSkia theme_r = gfx::ImageSkiaOperations::CreateMaskedImage( 431 gfx::ImageSkia theme_r = gfx::ImageSkiaOperations::CreateMaskedImage(
378 tab_r, *g_mask_images.image_r); 432 tab_r, *g_mask_images.image_r);
379 canvas->DrawImageInt(theme_r, 0, 0, theme_r.width(), 433 canvas->DrawImageInt(theme_r, 0, 0, theme_r.width(),
380 theme_r.height() - toolbar_overlap, 434 theme_r.height() - toolbar_overlap,
381 size.width() - theme_r.width(), 0, theme_r.width(), 435 size.width() - theme_r.width(), 0, theme_r.width(),
382 theme_r.height() - toolbar_overlap, false); 436 theme_r.height() - toolbar_overlap, false);
383 437
384 // Draw center. Instead of masking out the top portion we simply skip over it 438 // 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. 439 // by incrementing by the top padding, since it's a simple rectangle.
386 canvas->TileImageInt( 440 canvas->TileImageInt(
387 *fill_image, x_offset + g_mask_images.l_width, 441 fill_image, x_offset + g_mask_images.l_width, y_offset + tab_insets.top(),
388 y_offset + tab_insets.top(), g_mask_images.l_width, tab_insets.top(), 442 g_mask_images.l_width, tab_insets.top(),
389 size.width() - g_mask_images.l_width - g_mask_images.r_width, 443 size.width() - g_mask_images.l_width - g_mask_images.r_width,
390 size.height() - tab_insets.top() - toolbar_overlap); 444 size.height() - tab_insets.top() - toolbar_overlap);
391 } 445 }
392 446
447 // For use by Tab and TabImageSource
448 void PaintTabBackgroundUsingFillId(gfx::Canvas* canvas,
449 views::GlowHoverController* hc,
450 const PaintBackgroundParams& params) {
451 const SkScalar kMinHoverRadius = 16;
452 const SkScalar radius =
453 std::max(SkFloatToScalar(params.size.width() / 4.f), kMinHoverRadius);
454 const bool draw_hover = !params.is_active && hc;
455 SkPoint hover_location(
456 PointToSkPoint(draw_hover ? hc->location() : gfx::Point()));
457 const SkColor hover_color =
458 SkColorSetA(params.toolbar_color, draw_hover ? hc->GetAlpha() : 255);
459
460 if (ui::MaterialDesignController::IsModeMaterial()) {
461 gfx::ScopedCanvas scoped_canvas(canvas);
462 const float scale = canvas->UndoDeviceScaleFactor();
463
464 // Draw the fill.
465 SkPath fill;
466 GetFillPath(scale, params.size, &fill);
467 SkPaint paint;
468 paint.setAntiAlias(true);
469 {
470 gfx::ScopedCanvas clip_scoper(canvas);
471 canvas->ClipPath(fill, true);
472 if (params.has_custom_image) {
473 gfx::ScopedCanvas scale_scoper(canvas);
474 canvas->sk_canvas()->scale(scale, scale);
475 canvas->TileImageInt(params.fill_image, params.offset.x(),
476 params.offset.y(), 0, 0, params.size.width(),
477 params.size.height());
478 } else {
479 paint.setColor(params.is_active ? params.toolbar_color
480 : params.background_color);
481 canvas->DrawRect(
482 gfx::ScaleToEnclosingRect(gfx::Rect(params.size), scale), paint);
483 }
484 if (draw_hover) {
485 hover_location.scale(SkFloatToScalar(scale));
486 DrawHighlight(canvas, hover_location, radius * scale, hover_color);
487 }
488 }
489
490 // Draw the stroke.
491 SkPath stroke;
492 GetBorderPath(scale, params.size, false, &stroke);
493 Op(stroke, fill, kDifference_SkPathOp, &stroke);
494 if (!params.is_active) {
495 // Clip out the bottom line; this will be drawn for us by
496 // TabStrip::PaintChildren().
497 canvas->sk_canvas()->clipRect(SkRect::MakeWH(
498 params.size.width() * scale, params.size.height() * scale - 1));
499 }
500 paint.setColor(params.stroke_color);
501 canvas->DrawPath(stroke, paint);
502 } else {
503 if (draw_hover) {
504 // Draw everything to a temporary canvas so we can extract an image for
505 // use in masking the hover glow.
506 gfx::Canvas background_canvas(params.size, canvas->image_scale(), false);
507 PaintTabFill(&background_canvas, params.fill_image, params.offset.x(),
508 params.offset.y(), params.size, params.is_active);
509 gfx::ImageSkia background_image(background_canvas.ExtractImageRep());
510 canvas->DrawImageInt(background_image, 0, 0);
511
512 gfx::Canvas hover_canvas(params.size, canvas->image_scale(), false);
513 DrawHighlight(&hover_canvas, hover_location, radius, hover_color);
514 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage(
515 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image);
516 canvas->DrawImageInt(result, 0, 0);
517 } else {
518 PaintTabFill(canvas, params.fill_image, params.offset.x(),
519 params.offset.y(), params.size, params.is_active);
520 }
521
522 // Now draw the stroke, highlights, and shadows around the tab edge.
523 TabImages* stroke_images =
524 params.is_active ? &g_active_images : &g_inactive_images;
525 canvas->DrawImageInt(*stroke_images->image_l, 0, 0);
526 canvas->TileImageInt(
527 *stroke_images->image_c, stroke_images->l_width, 0,
528 params.size.width() - stroke_images->l_width - stroke_images->r_width,
529 params.size.height());
530 canvas->DrawImageInt(*stroke_images->image_r,
531 params.size.width() - stroke_images->r_width, 0);
532 }
533 }
534
393 } // namespace 535 } // namespace
394 536
395 //////////////////////////////////////////////////////////////////////////////// 537 ////////////////////////////////////////////////////////////////////////////////
396 // FaviconCrashAnimation 538 // FaviconCrashAnimation
397 // 539 //
398 // A custom animation subclass to manage the favicon crash animation. 540 // A custom animation subclass to manage the favicon crash animation.
399 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation, 541 class Tab::FaviconCrashAnimation : public gfx::LinearAnimation,
400 public gfx::AnimationDelegate { 542 public gfx::AnimationDelegate {
401 public: 543 public:
402 explicit FaviconCrashAnimation(Tab* target) 544 explicit FaviconCrashAnimation(Tab* target)
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after
1447 // We only cache the image when it's the default image and we're not hovered, 1589 // We only cache the image when it's the default image and we're not hovered,
1448 // to avoid caching a background image that isn't the same for all tabs. 1590 // to avoid caching a background image that isn't the same for all tabs.
1449 if (has_custom_image || hover_controller_.ShouldDraw()) { 1591 if (has_custom_image || hover_controller_.ShouldDraw()) {
1450 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image, 1592 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image,
1451 y_offset); 1593 y_offset);
1452 return; 1594 return;
1453 } 1595 }
1454 1596
1455 const ImageCacheEntryMetadata metadata( 1597 const ImageCacheEntryMetadata metadata(
1456 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), 1598 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB),
1457 controller_->GetToolbarTopSeparatorColor(), 1599 controller_->GetToolbarTopSeparatorColor(), size());
1458 ui::GetSupportedScaleFactor(canvas->image_scale()), size());
1459 auto it = std::find_if( 1600 auto it = std::find_if(
1460 g_image_cache->begin(), g_image_cache->end(), 1601 g_image_cache->begin(), g_image_cache->end(),
1461 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); 1602 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; });
1462 if (it == g_image_cache->end()) { 1603 if (it == g_image_cache->end()) {
1463 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); 1604 g_image_cache->emplace_front(metadata, this, fill_id, y_offset);
1464 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false, y_offset);
1465 g_image_cache->emplace_front(metadata,
1466 gfx::ImageSkia(tmp_canvas.ExtractImageRep()));
1467 if (g_image_cache->size() > kMaxImageCacheSize) 1605 if (g_image_cache->size() > kMaxImageCacheSize)
1468 g_image_cache->pop_back(); 1606 g_image_cache->pop_back();
1469 it = g_image_cache->begin(); 1607 it = g_image_cache->begin();
1470 } 1608 }
1471 canvas->DrawImageInt(it->image, 0, 0); 1609 canvas->DrawImageInt(it->image, 0, 0);
1472 } 1610 }
1473 1611
1474 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, 1612 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas,
1475 bool is_active, 1613 bool is_active,
1476 int fill_id, 1614 int fill_id,
1477 bool has_custom_image, 1615 bool has_custom_image,
1478 int y_offset) { 1616 int y_offset) {
1479 const ui::ThemeProvider* tp = GetThemeProvider(); 1617 views::GlowHoverController* hc =
1480 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); 1618 hover_controller_.ShouldDraw() ? &hover_controller_ : nullptr;
1481 gfx::ImageSkia* fill_image = tp->GetImageSkiaNamed(fill_id); 1619 PaintBackgroundParams params;
1620 params.is_active = is_active;
1621 if (has_custom_image || !ui::MaterialDesignController::IsModeMaterial())
1622 params.fill_image = *GetThemeProvider()->GetImageSkiaNamed(fill_id);
1623 params.has_custom_image = has_custom_image;
oshima 2016/07/28 20:45:48 you should be able to use fill_image.isNull() to c
Greg Levin 2016/08/10 20:03:10 Done.
1482 // The tab image needs to be lined up with the background image 1624 // The tab image needs to be lined up with the background image
1483 // so that it feels partially transparent. These offsets represent the tab 1625 // so that it feels partially transparent. These offsets represent the tab
1484 // position within the frame background image. 1626 // position within the frame background image.
1485 const int x_offset = GetMirroredX() + background_offset_.x(); 1627 params.offset.SetPoint(GetMirroredX() + background_offset_.x(), y_offset);
1628 params.size = size();
1629 params.stroke_color = controller_->GetToolbarTopSeparatorColor();
1630 params.toolbar_color =
1631 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR);
1632 params.background_color =
1633 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB);
1486 1634
1487 const SkScalar kMinHoverRadius = 16; 1635 ::PaintTabBackgroundUsingFillId(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 } 1636 }
1567 1637
1568 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( 1638 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon(
1569 gfx::Canvas* canvas, 1639 gfx::Canvas* canvas,
1570 const gfx::Rect& favicon_draw_bounds) { 1640 const gfx::Rect& favicon_draw_bounds) {
1571 // The pinned tab title changed indicator consists of two parts: 1641 // The pinned tab title changed indicator consists of two parts:
1572 // . a clear (totally transparent) part over the bottom right (or left in rtl) 1642 // . 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 1643 // of the favicon. This is done by drawing the favicon to a canvas, then
1574 // drawing the clear part on top of the favicon. 1644 // drawing the clear part on top of the favicon.
1575 // . a circle in the bottom right (or left in rtl) of the favicon. 1645 // . 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
1804 gfx::Rect Tab::GetImmersiveBarRect() const { 1874 gfx::Rect Tab::GetImmersiveBarRect() const {
1805 // The main bar is as wide as the normal tab's horizontal top line. 1875 // 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 1876 // 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. 1877 // center image due to pixels in the rounded corner images.
1808 const int kBarPadding = 1; 1878 const int kBarPadding = 1;
1809 int main_bar_left = g_active_images.l_width - kBarPadding; 1879 int main_bar_left = g_active_images.l_width - kBarPadding;
1810 int main_bar_right = width() - g_active_images.r_width + kBarPadding; 1880 int main_bar_right = width() - g_active_images.r_width + kBarPadding;
1811 return gfx::Rect( 1881 return gfx::Rect(
1812 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); 1882 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight);
1813 } 1883 }
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