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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 149 |
150 //////////////////////////////////////////////////////////////////////////////// | 150 //////////////////////////////////////////////////////////////////////////////// |
151 // ImageCacheEntryMetadata | 151 // ImageCacheEntryMetadata |
152 // | 152 // |
153 // All metadata necessary to uniquely identify a cached image. | 153 // All metadata necessary to uniquely identify a cached image. |
154 struct ImageCacheEntryMetadata { | 154 struct ImageCacheEntryMetadata { |
155 ImageCacheEntryMetadata(int resource_id, | 155 ImageCacheEntryMetadata(int resource_id, |
156 SkColor fill_color, | 156 SkColor fill_color, |
157 SkColor stroke_color, | 157 SkColor stroke_color, |
158 bool use_fill_and_stroke_images, | 158 bool use_fill_and_stroke_images, |
159 ui::ScaleFactor scale_factor, | 159 float scale_factor, |
160 const gfx::Size& size); | 160 const gfx::Size& size); |
161 | 161 |
162 ~ImageCacheEntryMetadata(); | 162 ~ImageCacheEntryMetadata(); |
163 | 163 |
164 bool operator==(const ImageCacheEntryMetadata& rhs) const; | 164 bool operator==(const ImageCacheEntryMetadata& rhs) const; |
165 | 165 |
166 int resource_id; // Only needed by pre-MD | 166 int resource_id; // Only needed by pre-MD |
167 SkColor fill_color; // Both colors only needed by MD | 167 SkColor fill_color; // Both colors only needed by MD |
168 SkColor stroke_color; | 168 SkColor stroke_color; |
169 bool use_fill_and_stroke_images; | 169 bool use_fill_and_stroke_images; |
170 ui::ScaleFactor scale_factor; | 170 float scale_factor; |
171 gfx::Size size; | 171 gfx::Size size; |
172 }; | 172 }; |
173 | 173 |
174 ImageCacheEntryMetadata::ImageCacheEntryMetadata( | 174 ImageCacheEntryMetadata::ImageCacheEntryMetadata( |
175 int resource_id, | 175 int resource_id, |
176 SkColor fill_color, | 176 SkColor fill_color, |
177 SkColor stroke_color, | 177 SkColor stroke_color, |
178 bool use_fill_and_stroke_images, | 178 bool use_fill_and_stroke_images, |
179 ui::ScaleFactor scale_factor, | 179 float scale_factor, |
180 const gfx::Size& size) | 180 const gfx::Size& size) |
181 : resource_id(resource_id), | 181 : resource_id(resource_id), |
182 fill_color(fill_color), | 182 fill_color(fill_color), |
183 stroke_color(stroke_color), | 183 stroke_color(stroke_color), |
184 use_fill_and_stroke_images(use_fill_and_stroke_images), | 184 use_fill_and_stroke_images(use_fill_and_stroke_images), |
185 scale_factor(scale_factor), | 185 scale_factor(scale_factor), |
186 size(size) { | 186 size(size) { |
187 DCHECK_NE(ui::SCALE_FACTOR_NONE, scale_factor); | |
188 | |
189 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones | 187 // Some fields are only relevant for pre-MD vs. MD. Erase the irrelevant ones |
190 // so they don't cause incorrect cache misses. | 188 // so they don't cause incorrect cache misses. |
191 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. | 189 // TODO(pkasting): Remove |resource_id| field when non-MD code is deleted. |
192 if (ui::MaterialDesignController::IsModeMaterial()) | 190 if (ui::MaterialDesignController::IsModeMaterial()) |
193 resource_id = 0; | 191 resource_id = 0; |
194 else | 192 else |
195 fill_color = stroke_color = SK_ColorTRANSPARENT; | 193 fill_color = stroke_color = SK_ColorTRANSPARENT; |
196 } | 194 } |
197 | 195 |
198 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} | 196 ImageCacheEntryMetadata::~ImageCacheEntryMetadata() {} |
(...skipping 1342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1541 // really need to clip the stroke and not the fill (for stacked tabs). This | 1539 // really need to clip the stroke and not the fill (for stacked tabs). This |
1542 // saves memory and avoids an extra image draw at the cost of recalculating | 1540 // saves memory and avoids an extra image draw at the cost of recalculating |
1543 // the images when MaySetClip() toggles. | 1541 // the images when MaySetClip() toggles. |
1544 const bool use_fill_and_stroke_images = | 1542 const bool use_fill_and_stroke_images = |
1545 controller_->MaySetClip() && | 1543 controller_->MaySetClip() && |
1546 ui::MaterialDesignController::IsModeMaterial(); | 1544 ui::MaterialDesignController::IsModeMaterial(); |
1547 | 1545 |
1548 const ImageCacheEntryMetadata metadata( | 1546 const ImageCacheEntryMetadata metadata( |
1549 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), | 1547 fill_id, tp->GetColor(ThemeProperties::COLOR_BACKGROUND_TAB), |
1550 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, | 1548 controller_->GetToolbarTopSeparatorColor(), use_fill_and_stroke_images, |
1551 ui::GetSupportedScaleFactor(canvas->image_scale()), size()); | 1549 canvas->image_scale(), size()); |
1552 auto it = std::find_if( | 1550 auto it = std::find_if( |
1553 g_image_cache->begin(), g_image_cache->end(), | 1551 g_image_cache->begin(), g_image_cache->end(), |
1554 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); | 1552 [&metadata](const ImageCacheEntry& e) { return e.metadata == metadata; }); |
1555 if (it == g_image_cache->end()) { | 1553 if (it == g_image_cache->end()) { |
1556 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); | 1554 gfx::Canvas tmp_canvas(size(), canvas->image_scale(), false); |
1557 if (use_fill_and_stroke_images) { | 1555 if (use_fill_and_stroke_images) { |
1558 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false); | 1556 gfx::Canvas tmp_fill_canvas(size(), canvas->image_scale(), false); |
1559 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, | 1557 PaintTabBackgroundUsingFillId(&tmp_fill_canvas, &tmp_canvas, false, |
1560 fill_id, false, y_offset); | 1558 fill_id, false, y_offset); |
1561 g_image_cache->emplace_front( | 1559 g_image_cache->emplace_front( |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 gfx::Rect Tab::GetImmersiveBarRect() const { | 1857 gfx::Rect Tab::GetImmersiveBarRect() const { |
1860 // The main bar is as wide as the normal tab's horizontal top line. | 1858 // The main bar is as wide as the normal tab's horizontal top line. |
1861 // This top line of the tab extends a few pixels left and right of the | 1859 // This top line of the tab extends a few pixels left and right of the |
1862 // center image due to pixels in the rounded corner images. | 1860 // center image due to pixels in the rounded corner images. |
1863 const int kBarPadding = 1; | 1861 const int kBarPadding = 1; |
1864 int main_bar_left = g_active_images.l_width - kBarPadding; | 1862 int main_bar_left = g_active_images.l_width - kBarPadding; |
1865 int main_bar_right = width() - g_active_images.r_width + kBarPadding; | 1863 int main_bar_right = width() - g_active_images.r_width + kBarPadding; |
1866 return gfx::Rect( | 1864 return gfx::Rect( |
1867 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); | 1865 main_bar_left, 0, main_bar_right - main_bar_left, kImmersiveBarHeight); |
1868 } | 1866 } |
OLD | NEW |