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 26 matching lines...) Expand all Loading... | |
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 Loading... | |
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_color) | 128 SkColor background_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_color(background_color) {} | 138 background_color(background_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_color; | 149 const SkColor background_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* canvas, | |
156 const PaintBackgroundParams& params); | |
Peter Kasting
2016/08/10 21:02:03
Nit: Maybe this function should have gone here?...
Greg Levin
2016/08/12 19:48:15
I'll move it (well, "them" now) if you think that'
| |
157 | |
158 //////////////////////////////////////////////////////////////////////////////// | |
159 // TabImageSource | |
160 // | |
161 // This subclass of CanvasImageSource allows the inactive tab image to be cached | |
162 // once and rendered correctly for all scale factors. | |
Peter Kasting
2016/08/10 21:02:03
Nit: Maybe "...inactive tab image to be cached onc
Greg Levin
2016/08/12 19:48:15
Done.
| |
163 class TabImageSource : public gfx::CanvasImageSource { | |
164 public: | |
165 TabImageSource(Tab* tab, int fill_id, int y_offset); | |
166 ~TabImageSource() override {} | |
167 | |
168 // gfx::CanvasImageSource override. | |
Peter Kasting
2016/08/10 21:02:03
I think you should also override HasRepresentation
Greg Levin
2016/08/12 19:48:15
Done.
| |
169 void Draw(gfx::Canvas* canvas) override; | |
170 | |
171 private: | |
172 const PaintBackgroundParams params_; | |
173 | |
174 DISALLOW_COPY_AND_ASSIGN(TabImageSource); | |
175 }; | |
176 | |
177 TabImageSource::TabImageSource(Tab* tab, int fill_id, int y_offset) | |
178 : gfx::CanvasImageSource(tab->size(), true), | |
179 params_(false, | |
180 tab->GetThemeProvider()->GetImageSkiaNamed(fill_id), | |
181 false, | |
182 gfx::Rect(gfx::Point(0, y_offset), tab->size()), | |
183 tab->controller()->GetToolbarTopSeparatorColor(), | |
184 tab->GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), | |
185 tab->GetThemeProvider()->GetColor( | |
186 ThemeProperties::COLOR_BACKGROUND_TAB), | |
187 false, | |
188 gfx::Point(), | |
189 255) {} | |
190 | |
191 void TabImageSource::Draw(gfx::Canvas* canvas) { | |
192 PaintTabBackgroundUsingParams(canvas, params_); | |
193 } | |
194 | |
145 //////////////////////////////////////////////////////////////////////////////// | 195 //////////////////////////////////////////////////////////////////////////////// |
146 // ImageCacheEntryMetadata | 196 // ImageCacheEntryMetadata |
147 // | 197 // |
148 // All metadata necessary to uniquely identify a cached image. | 198 // All metadata necessary to uniquely identify a cached image. |
149 struct ImageCacheEntryMetadata { | 199 struct ImageCacheEntryMetadata { |
150 ImageCacheEntryMetadata(int resource_id, | 200 ImageCacheEntryMetadata(int resource_id, |
151 SkColor fill_color, | 201 SkColor fill_color, |
152 SkColor stroke_color, | 202 SkColor stroke_color, |
153 ui::ScaleFactor scale_factor, | |
154 const gfx::Size& size); | 203 const gfx::Size& size); |
155 | 204 |
156 ~ImageCacheEntryMetadata(); | 205 ~ImageCacheEntryMetadata(); |
157 | 206 |
158 bool operator==(const ImageCacheEntryMetadata& rhs) const; | 207 bool operator==(const ImageCacheEntryMetadata& rhs) const; |
159 | 208 |
160 int resource_id; // Only needed by pre-MD | 209 int resource_id; // Only needed by pre-MD |
161 SkColor fill_color; // Both colors only needed by MD | 210 SkColor fill_color; // Both colors only needed by MD |
162 SkColor stroke_color; | 211 SkColor stroke_color; |
163 ui::ScaleFactor scale_factor; | |
164 gfx::Size size; | 212 gfx::Size size; |
165 }; | 213 }; |
166 | 214 |
167 ImageCacheEntryMetadata::ImageCacheEntryMetadata(int resource_id, | 215 ImageCacheEntryMetadata::ImageCacheEntryMetadata(int resource_id, |
168 SkColor fill_color, | 216 SkColor fill_color, |
169 SkColor stroke_color, | 217 SkColor stroke_color, |
170 ui::ScaleFactor scale_factor, | |
171 const gfx::Size& size) | 218 const gfx::Size& size) |
172 : resource_id(resource_id), | 219 : resource_id(resource_id), |
173 fill_color(fill_color), | 220 fill_color(fill_color), |
174 stroke_color(stroke_color), | 221 stroke_color(stroke_color), |
175 scale_factor(scale_factor), | |
176 size(size) { | 222 size(size) { |
177 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor); | |
178 | |
179 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones | 223 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones |
180 // so they don't cause incorrect cache misses. | 224 // so they don't cause incorrect cache misses. |
181 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. | 225 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. |
182 if (ui::MaterialDesignController::IsModeMaterial()) | 226 if (ui::MaterialDesignController::IsModeMaterial()) |
183 resource_id = 0; | 227 resource_id = 0; |
184 else | 228 else |
185 fill_color = stroke_color = SK_ColorTRANSPARENT; | 229 fill_color = stroke_color = SK_ColorTRANSPARENT; |
186 } | 230 } |
187 | 231 |
188 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} | 232 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} |
189 | 233 |
190 bool ImageCacheEntryMetadata::operator==( | 234 bool ImageCacheEntryMetadata::operator==( |
191 const ImageCacheEntryMetadata& rhs) const { | 235 const ImageCacheEntryMetadata& rhs) const { |
192 return resource_id == rhs.resource_id && fill_color == rhs.fill_color && | 236 return resource_id == rhs.resource_id && fill_color == rhs.fill_color && |
193 stroke_color == rhs.stroke_color && scale_factor == rhs.scale_factor && | 237 stroke_color == rhs.stroke_color && size == rhs.size; |
194 size == rhs.size; | |
195 } | 238 } |
196 | 239 |
197 //////////////////////////////////////////////////////////////////////////////// | 240 //////////////////////////////////////////////////////////////////////////////// |
198 // ImageCacheEntry and cache management | 241 // ImageCacheEntry and cache management |
199 // | 242 // |
200 // A cached image and the metadata used to generate it. | 243 // A cached image and the metadata used to generate it. |
201 struct ImageCacheEntry { | 244 struct ImageCacheEntry { |
202 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, | 245 ImageCacheEntry(const ImageCacheEntryMetadata& metadata, |
203 const gfx::ImageSkia& image); | 246 Tab* tab, |
247 int fill_id, | |
248 int y_offset); | |
204 ~ImageCacheEntry(); | 249 ~ImageCacheEntry(); |
205 | 250 |
206 ImageCacheEntryMetadata metadata; | 251 ImageCacheEntryMetadata metadata; |
207 gfx::ImageSkia image; | 252 gfx::ImageSkia image; |
208 }; | 253 }; |
209 | 254 |
210 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata, | 255 ImageCacheEntry::ImageCacheEntry(const ImageCacheEntryMetadata& metadata, |
211 const gfx::ImageSkia& image) | 256 Tab* tab, |
212 : metadata(metadata), image(image) {} | 257 int fill_id, |
258 int y_offset) | |
259 : metadata(metadata), | |
260 image(new TabImageSource(tab, fill_id, y_offset), tab->size()) {} | |
Peter Kasting
2016/08/10 21:02:03
I don't suppose you'd like to write a followup cle
Greg Levin
2016/08/12 19:48:15
I'll ask oshima@ about it...
| |
213 | 261 |
214 ImageCacheEntry::~ImageCacheEntry() {} | 262 ImageCacheEntry::~ImageCacheEntry() {} |
215 | 263 |
216 typedef std::list<ImageCacheEntry> ImageCache; | 264 typedef std::list<ImageCacheEntry> ImageCache; |
217 | 265 |
218 // As the majority of the tabs are inactive, and painting tabs is slowish, | 266 // As the majority of the tabs are inactive, and painting tabs is slowish, |
219 // we cache a handful of the inactive tab backgrounds here. | 267 // we cache a handful of the inactive tab backgrounds here. |
220 static ImageCache* g_image_cache = nullptr; | 268 static ImageCache* g_image_cache = nullptr; |
221 | 269 |
222 struct TabImages { | 270 struct TabImages { |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
466 | 514 |
467 // Draw center. Instead of masking out the top portion we simply skip over it | 515 // Draw center. Instead of masking out the top portion we simply skip over it |
468 // by incrementing by the top padding, since it's a simple rectangle. | 516 // by incrementing by the top padding, since it's a simple rectangle. |
469 rect.Inset(g_mask_images.l_width, tab_insets.top(), g_mask_images.r_width, | 517 rect.Inset(g_mask_images.l_width, tab_insets.top(), g_mask_images.r_width, |
470 toolbar_overlap); | 518 toolbar_overlap); |
471 canvas->TileImageInt(fill_image, rect.x(), rect.y(), g_mask_images.l_width, | 519 canvas->TileImageInt(fill_image, rect.x(), rect.y(), g_mask_images.l_width, |
472 tab_insets.top(), rect.width(), rect.height()); | 520 tab_insets.top(), rect.width(), rect.height()); |
473 } | 521 } |
474 | 522 |
475 void PaintTabBackgroundUsingParams(gfx::Canvas* canvas, | 523 void PaintTabBackgroundUsingParams(gfx::Canvas* canvas, |
476 views::GlowHoverController* hc, | |
477 const PaintBackgroundParams& params) { | 524 const PaintBackgroundParams& params) { |
478 const SkScalar kMinHoverRadius = 16; | 525 const SkScalar kMinHoverRadius = 16; |
479 const SkScalar radius = | 526 const SkScalar radius = |
480 std::max(SkFloatToScalar(params.rect.width() / 4.f), kMinHoverRadius); | 527 std::max(SkFloatToScalar(params.rect.width() / 4.f), kMinHoverRadius); |
481 const bool draw_hover = !params.is_active && hc; | |
482 SkPoint hover_location( | |
483 gfx::PointToSkPoint(draw_hover ? hc->location() : gfx::Point())); | |
484 const SkColor hover_color = | 528 const SkColor hover_color = |
485 SkColorSetA(params.toolbar_color, draw_hover ? hc->GetAlpha() : 255); | 529 SkColorSetA(params.toolbar_color, params.hover_alpha); |
486 | 530 |
487 if (ui::MaterialDesignController::IsModeMaterial()) { | 531 if (ui::MaterialDesignController::IsModeMaterial()) { |
488 gfx::ScopedCanvas scoped_canvas(canvas); | 532 gfx::ScopedCanvas scoped_canvas(canvas); |
489 const float scale = canvas->UndoDeviceScaleFactor(); | 533 const float scale = canvas->UndoDeviceScaleFactor(); |
490 | 534 |
491 // Draw the fill. | 535 // Draw the fill. |
492 gfx::Path fill = GetFillPath(scale, params.rect.size()); | 536 gfx::Path fill = GetFillPath(scale, params.rect.size()); |
493 SkPaint paint; | 537 SkPaint paint; |
494 paint.setAntiAlias(true); | 538 paint.setAntiAlias(true); |
495 { | 539 { |
496 gfx::ScopedCanvas clip_scoper(canvas); | 540 gfx::ScopedCanvas clip_scoper(canvas); |
497 canvas->ClipPath(fill, true); | 541 canvas->ClipPath(fill, true); |
498 if (!params.fill_image.isNull()) { | 542 if (!params.fill_image.isNull()) { |
499 gfx::ScopedCanvas scale_scoper(canvas); | 543 gfx::ScopedCanvas scale_scoper(canvas); |
500 canvas->sk_canvas()->scale(scale, scale); | 544 canvas->sk_canvas()->scale(scale, scale); |
501 canvas->TileImageInt(params.fill_image, params.rect.x(), | 545 canvas->TileImageInt(params.fill_image, params.rect.x(), |
502 params.rect.y(), 0, 0, params.rect.width(), | 546 params.rect.y(), 0, 0, params.rect.width(), |
503 params.rect.height()); | 547 params.rect.height()); |
504 } else { | 548 } else { |
505 paint.setColor(params.is_active ? params.toolbar_color | 549 paint.setColor(params.is_active ? params.toolbar_color |
506 : params.background_color); | 550 : params.background_color); |
507 canvas->DrawRect( | 551 canvas->DrawRect( |
508 gfx::ScaleToEnclosingRect(gfx::Rect(params.rect.size()), scale), | 552 gfx::ScaleToEnclosingRect(gfx::Rect(params.rect.size()), scale), |
509 paint); | 553 paint); |
510 } | 554 } |
511 if (draw_hover) { | 555 if (params.draw_hover) { |
512 hover_location.scale(SkFloatToScalar(scale)); | 556 DrawHighlight(canvas, params.hover_location * SkFloatToScalar(scale), |
Peter Kasting
2016/08/10 21:02:03
I think you want to omit the SkFloatToScalar() cal
Greg Levin
2016/08/12 19:48:15
Done.
| |
513 DrawHighlight(canvas, hover_location, radius * scale, hover_color); | 557 radius * scale, hover_color); |
514 } | 558 } |
515 } | 559 } |
516 | 560 |
517 // Draw the stroke. | 561 // Draw the stroke. |
518 gfx::Path stroke = GetBorderPath(scale, false, false, params.rect.size()); | 562 gfx::Path stroke = GetBorderPath(scale, false, false, params.rect.size()); |
519 Op(stroke, fill, kDifference_SkPathOp, &stroke); | 563 Op(stroke, fill, kDifference_SkPathOp, &stroke); |
520 if (!params.is_active) { | 564 if (!params.is_active) { |
521 // Clip out the bottom line; this will be drawn for us by | 565 // Clip out the bottom line; this will be drawn for us by |
522 // TabStrip::PaintChildren(). | 566 // TabStrip::PaintChildren(). |
523 canvas->ClipRect(gfx::RectF(params.rect.width() * scale, | 567 canvas->ClipRect(gfx::RectF(params.rect.width() * scale, |
524 params.rect.height() * scale - 1)); | 568 params.rect.height() * scale - 1)); |
525 } | 569 } |
526 paint.setColor(params.stroke_color); | 570 paint.setColor(params.stroke_color); |
527 canvas->DrawPath(stroke, paint); | 571 canvas->DrawPath(stroke, paint); |
528 } else { | 572 } else { |
529 if (draw_hover) { | 573 if (params.draw_hover) { |
530 // Draw everything to a temporary canvas so we can extract an image for | 574 // Draw everything to a temporary canvas so we can extract an image for |
531 // use in masking the hover glow. | 575 // use in masking the hover glow. |
532 gfx::Canvas background_canvas(params.rect.size(), canvas->image_scale(), | 576 gfx::Canvas background_canvas(params.rect.size(), canvas->image_scale(), |
533 false); | 577 false); |
534 PaintTabFill(&background_canvas, params.fill_image, params.rect, | 578 PaintTabFill(&background_canvas, params.fill_image, params.rect, |
535 params.is_active); | 579 params.is_active); |
536 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); | 580 gfx::ImageSkia background_image(background_canvas.ExtractImageRep()); |
537 canvas->DrawImageInt(background_image, 0, 0); | 581 canvas->DrawImageInt(background_image, 0, 0); |
538 | 582 |
539 gfx::Canvas hover_canvas(params.rect.size(), canvas->image_scale(), | 583 gfx::Canvas hover_canvas(params.rect.size(), canvas->image_scale(), |
540 false); | 584 false); |
541 DrawHighlight(&hover_canvas, hover_location, radius, hover_color); | 585 DrawHighlight(&hover_canvas, params.hover_location, radius, hover_color); |
542 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( | 586 gfx::ImageSkia result = gfx::ImageSkiaOperations::CreateMaskedImage( |
543 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); | 587 gfx::ImageSkia(hover_canvas.ExtractImageRep()), background_image); |
544 canvas->DrawImageInt(result, 0, 0); | 588 canvas->DrawImageInt(result, 0, 0); |
545 } else { | 589 } else { |
546 PaintTabFill(canvas, params.fill_image, params.rect, params.is_active); | 590 PaintTabFill(canvas, params.fill_image, params.rect, params.is_active); |
547 } | 591 } |
548 | 592 |
549 // Now draw the stroke, highlights, and shadows around the tab edge. | 593 // Now draw the stroke, highlights, and shadows around the tab edge. |
550 TabImages* stroke_images = | 594 TabImages* stroke_images = |
551 params.is_active ? &g_active_images : &g_inactive_images; | 595 params.is_active ? &g_active_images : &g_inactive_images; |
(...skipping 1013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1565 // We only cache the image when it's the default image and we're not hovered, | 1609 // We only cache the image when it's the default image and we're not hovered, |
1566 // to avoid caching a background image that isn't the same for all tabs. | 1610 // to avoid caching a background image that isn't the same for all tabs. |
1567 if (has_custom_image || hover_controller_.ShouldDraw()) { | 1611 if (has_custom_image || hover_controller_.ShouldDraw()) { |
1568 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image, | 1612 PaintTabBackgroundUsingFillId(canvas, false, fill_id, has_custom_image, |
1569 y_offset); | 1613 y_offset); |
1570 return; | 1614 return; |
1571 } | 1615 } |
1572 | 1616 |
1573 const ImageCacheEntryMetadata metadata( | 1617 const ImageCacheEntryMetadata metadata( |
1574 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), | 1618 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), |
1575 controller_->GetToolbarTopSeparatorColor(), | 1619 controller_->GetToolbarTopSeparatorColor(), size()); |
1576 ui::GetSupportedScaleFactor(canvas->image_scale()), size()); | |
Peter Kasting
2016/08/10 21:02:03
Fundamentally, why didn't this prevent the bug fro
Greg Levin
2016/08/12 19:48:15
In the case where the device / native scale factor
Peter Kasting
2016/08/13 06:38:33
Would just removing the call to GetSupportedScaleF
Greg Levin
2016/08/15 18:40:18
GetSupportedScaleFactor() is somewhat misleadingly
Peter Kasting
2016/08/15 21:44:52
Ah! That's interesting.
That means at least for
| |
1577 auto it = std::find_if( | 1620 auto it = std::find_if( |
1578 g_image_cache->begin(), g_image_cache->end(), | 1621 g_image_cache->begin(), g_image_cache->end(), |
1579 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); | 1622 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); |
1580 if (it == g_image_cache->end()) { | 1623 if (it == g_image_cache->end()) { |
1581 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); | 1624 g_image_cache->emplace_front(metadata, this, fill_id, y_offset); |
1582 PaintTabBackgroundUsingFillId(&tmp_canvas, false, fill_id, false, y_offset); | |
1583 g_image_cache->emplace_front(metadata, | |
1584 gfx::ImageSkia(tmp_canvas.ExtractImageRep())); | |
1585 if (g_image_cache->size() > kMaxImageCacheSize) | 1625 if (g_image_cache->size() > kMaxImageCacheSize) |
1586 g_image_cache->pop_back(); | 1626 g_image_cache->pop_back(); |
1587 it = g_image_cache->begin(); | 1627 it = g_image_cache->begin(); |
1588 } | 1628 } |
1589 canvas->DrawImageInt(it->image, 0, 0); | 1629 canvas->DrawImageInt(it->image, 0, 0); |
1590 } | 1630 } |
1591 | 1631 |
1592 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, | 1632 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* canvas, |
1593 bool is_active, | 1633 bool is_active, |
1594 int fill_id, | 1634 int fill_id, |
1595 bool has_custom_image, | 1635 bool has_custom_image, |
1596 int y_offset) { | 1636 int y_offset) { |
1597 views::GlowHoverController* hc = | |
1598 hover_controller_.ShouldDraw() ? &hover_controller_ : nullptr; | |
1599 gfx::ImageSkia* fill_image = | 1637 gfx::ImageSkia* fill_image = |
1600 has_custom_image || !ui::MaterialDesignController::IsModeMaterial() | 1638 has_custom_image || !ui::MaterialDesignController::IsModeMaterial() |
1601 ? GetThemeProvider()->GetImageSkiaNamed(fill_id) | 1639 ? GetThemeProvider()->GetImageSkiaNamed(fill_id) |
1602 : nullptr; | 1640 : nullptr; |
1603 // The tab image needs to be lined up with the background image | 1641 // The tab image needs to be lined up with the background image |
1604 // so that it feels partially transparent. These offsets represent the tab | 1642 // so that it feels partially transparent. These offsets represent the tab |
1605 // position within the frame background image. | 1643 // position within the frame background image. |
1606 gfx::Rect rect(GetLocalBounds()); | 1644 gfx::Rect rect(GetLocalBounds()); |
1607 rect.Offset(GetMirroredX() + background_offset_.x(), y_offset); | 1645 rect.Offset(GetMirroredX() + background_offset_.x(), y_offset); |
1608 PaintBackgroundParams params( | 1646 PaintBackgroundParams params( |
1609 is_active, fill_image, has_custom_image, rect, | 1647 is_active, fill_image, has_custom_image, rect, |
1610 controller_->GetToolbarTopSeparatorColor(), | 1648 controller_->GetToolbarTopSeparatorColor(), |
1611 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), | 1649 GetThemeProvider()->GetColor(ThemeProperties::COLOR_TOOLBAR), |
1612 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB)); | 1650 GetThemeProvider()->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), |
1651 !is_active && hover_controller_.ShouldDraw(), | |
1652 hover_controller_.location(), hover_controller_.GetAlpha()); | |
1613 | 1653 |
1614 PaintTabBackgroundUsingParams(canvas, hc, params); | 1654 PaintTabBackgroundUsingParams(canvas, params); |
1615 } | 1655 } |
1616 | 1656 |
1617 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( | 1657 void Tab::PaintPinnedTabTitleChangedIndicatorAndIcon( |
1618 gfx::Canvas* canvas, | 1658 gfx::Canvas* canvas, |
1619 const gfx::Rect& favicon_draw_bounds) { | 1659 const gfx::Rect& favicon_draw_bounds) { |
1620 // The pinned tab title changed indicator consists of two parts: | 1660 // The pinned tab title changed indicator consists of two parts: |
1621 // . a clear (totally transparent) part over the bottom right (or left in rtl) | 1661 // . a clear (totally transparent) part over the bottom right (or left in rtl) |
1622 // of the favicon. This is done by drawing the favicon to a canvas, then | 1662 // of the favicon. This is done by drawing the favicon to a canvas, then |
1623 // drawing the clear part on top of the favicon. | 1663 // drawing the clear part on top of the favicon. |
1624 // . a circle in the bottom right (or left in rtl) of the favicon. | 1664 // . 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... | |
1853 gfx::Rect Tab::GetImmersiveBarRect() const { | 1893 gfx::Rect Tab::GetImmersiveBarRect() const { |
1854 // The main bar is as wide as the normal tab's horizontal top line. | 1894 // The main bar is as wide as the normal tab's horizontal top line. |
1855 // This top line of the tab extends a few pixels left and right of the | 1895 // This top line of the tab extends a few pixels left and right of the |
1856 // center image due to pixels in the rounded corner images. | 1896 // center image due to pixels in the rounded corner images. |
1857 const int kBarPadding = 1; | 1897 const int kBarPadding = 1; |
1858 int main_bar_left = g_active_images.l_width - kBarPadding; | 1898 int main_bar_left = g_active_images.l_width - kBarPadding; |
1859 int main_bar_right = width() - g_active_images.r_width + kBarPadding; | 1899 int main_bar_right = width() - g_active_images.r_width + kBarPadding; |
1860 return gfx::Rect( | 1900 return gfx::Rect( |
1861 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); | 1901 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
1862 } | 1902 } |
OLD | NEW |