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 |
11 #include "base/command_line.h" | 11 #include "base/command_line.h" |
12 #include "base/debug/alias.h" | 12 #include "base/debug/alias.h" |
13 #include "base/macros.h" | 13 #include "base/macros.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 16 #include "cc/paint/paint_shader.h" |
16 #include "chrome/app/vector_icons/vector_icons.h" | 17 #include "chrome/app/vector_icons/vector_icons.h" |
17 #include "chrome/browser/themes/theme_properties.h" | 18 #include "chrome/browser/themes/theme_properties.h" |
18 #include "chrome/browser/ui/browser.h" | 19 #include "chrome/browser/ui/browser.h" |
19 #include "chrome/browser/ui/layout_constants.h" | 20 #include "chrome/browser/ui/layout_constants.h" |
20 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" | 21 #include "chrome/browser/ui/tab_contents/core_tab_helper.h" |
21 #include "chrome/browser/ui/tabs/tab_utils.h" | 22 #include "chrome/browser/ui/tabs/tab_utils.h" |
22 #include "chrome/browser/ui/view_ids.h" | 23 #include "chrome/browser/ui/view_ids.h" |
23 #include "chrome/browser/ui/views/frame/browser_view.h" | 24 #include "chrome/browser/ui/views/frame/browser_view.h" |
24 #include "chrome/browser/ui/views/tabs/alert_indicator_button.h" | 25 #include "chrome/browser/ui/views/tabs/alert_indicator_button.h" |
25 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" | 26 #include "chrome/browser/ui/views/tabs/browser_tab_strip_controller.h" |
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. | 210 // stroke inner edge is (GetUnscaledEndcapWidth() * scale) + 1. |
210 float GetUnscaledEndcapWidth() { | 211 float GetUnscaledEndcapWidth() { |
211 return GetLayoutInsets(TAB).left() - 0.5f; | 212 return GetLayoutInsets(TAB).left() - 0.5f; |
212 } | 213 } |
213 | 214 |
214 void DrawHighlight(gfx::Canvas* canvas, | 215 void DrawHighlight(gfx::Canvas* canvas, |
215 const SkPoint& p, | 216 const SkPoint& p, |
216 SkScalar radius, | 217 SkScalar radius, |
217 SkColor color) { | 218 SkColor color) { |
218 const SkColor colors[2] = { color, SkColorSetA(color, 0) }; | 219 const SkColor colors[2] = { color, SkColorSetA(color, 0) }; |
219 SkPaint paint; | 220 cc::PaintFlags paint; |
220 paint.setAntiAlias(true); | 221 paint.setAntiAlias(true); |
221 paint.setShader(SkGradientShader::MakeRadial(p, radius, colors, nullptr, 2, | 222 paint.setShader(cc::WrapSkShader(SkGradientShader::MakeRadial( |
222 SkShader::kClamp_TileMode)); | 223 p, radius, colors, nullptr, 2, SkShader::kClamp_TileMode))); |
223 canvas->sk_canvas()->drawRect( | 224 canvas->sk_canvas()->drawRect( |
224 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2), | 225 SkRect::MakeXYWH(p.x() - radius, p.y() - radius, radius * 2, radius * 2), |
225 paint); | 226 paint); |
226 } | 227 } |
227 | 228 |
228 // Returns whether the favicon for the given URL should be colored according to | 229 // Returns whether the favicon for the given URL should be colored according to |
229 // the browser theme. | 230 // the browser theme. |
230 bool ShouldThemifyFaviconForUrl(const GURL& url) { | 231 bool ShouldThemifyFaviconForUrl(const GURL& url) { |
231 return url.SchemeIs(content::kChromeUIScheme) && | 232 return url.SchemeIs(content::kChromeUIScheme) && |
232 url.host() != chrome::kChromeUIHelpHost && | 233 url.host() != chrome::kChromeUIHelpHost && |
(...skipping 1045 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1278 } | 1279 } |
1279 canvas->DrawImageInt(it->stroke_image, 0, 0); | 1280 canvas->DrawImageInt(it->stroke_image, 0, 0); |
1280 } | 1281 } |
1281 | 1282 |
1282 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, | 1283 void Tab::PaintTabBackgroundUsingFillId(gfx::Canvas* fill_canvas, |
1283 gfx::Canvas* stroke_canvas, | 1284 gfx::Canvas* stroke_canvas, |
1284 bool is_active, | 1285 bool is_active, |
1285 int fill_id, | 1286 int fill_id, |
1286 int y_offset) { | 1287 int y_offset) { |
1287 gfx::Path fill; | 1288 gfx::Path fill; |
1288 SkPaint paint; | 1289 cc::PaintFlags paint; |
1289 paint.setAntiAlias(true); | 1290 paint.setAntiAlias(true); |
1290 | 1291 |
1291 // Draw the fill. | 1292 // Draw the fill. |
1292 { | 1293 { |
1293 gfx::ScopedCanvas scoped_canvas(fill_canvas); | 1294 gfx::ScopedCanvas scoped_canvas(fill_canvas); |
1294 const float scale = fill_canvas->UndoDeviceScaleFactor(); | 1295 const float scale = fill_canvas->UndoDeviceScaleFactor(); |
1295 const ui::ThemeProvider* tp = GetThemeProvider(); | 1296 const ui::ThemeProvider* tp = GetThemeProvider(); |
1296 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); | 1297 const SkColor toolbar_color = tp->GetColor(ThemeProperties::COLOR_TOOLBAR); |
1297 | 1298 |
1298 fill = GetFillPath(scale, size()); | 1299 fill = GetFillPath(scale, size()); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 // The pinned tab title changed indicator consists of two parts: | 1351 // The pinned tab title changed indicator consists of two parts: |
1351 // . a clear (totally transparent) part over the bottom right (or left in rtl) | 1352 // . a clear (totally transparent) part over the bottom right (or left in rtl) |
1352 // of the favicon. This is done by drawing the favicon to a canvas, then | 1353 // of the favicon. This is done by drawing the favicon to a canvas, then |
1353 // drawing the clear part on top of the favicon. | 1354 // drawing the clear part on top of the favicon. |
1354 // . a circle in the bottom right (or left in rtl) of the favicon. | 1355 // . a circle in the bottom right (or left in rtl) of the favicon. |
1355 if (!favicon_.isNull()) { | 1356 if (!favicon_.isNull()) { |
1356 const float kIndicatorCropRadius = 4.5; | 1357 const float kIndicatorCropRadius = 4.5; |
1357 gfx::Canvas icon_canvas(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), | 1358 gfx::Canvas icon_canvas(gfx::Size(gfx::kFaviconSize, gfx::kFaviconSize), |
1358 canvas->image_scale(), false); | 1359 canvas->image_scale(), false); |
1359 icon_canvas.DrawImageInt(favicon_, 0, 0); | 1360 icon_canvas.DrawImageInt(favicon_, 0, 0); |
1360 SkPaint clear_paint; | 1361 cc::PaintFlags clear_paint; |
1361 clear_paint.setAntiAlias(true); | 1362 clear_paint.setAntiAlias(true); |
1362 clear_paint.setBlendMode(SkBlendMode::kClear); | 1363 clear_paint.setBlendMode(SkBlendMode::kClear); |
1363 const int circle_x = base::i18n::IsRTL() ? 0 : gfx::kFaviconSize; | 1364 const int circle_x = base::i18n::IsRTL() ? 0 : gfx::kFaviconSize; |
1364 icon_canvas.DrawCircle(gfx::PointF(circle_x, gfx::kFaviconSize), | 1365 icon_canvas.DrawCircle(gfx::PointF(circle_x, gfx::kFaviconSize), |
1365 kIndicatorCropRadius, clear_paint); | 1366 kIndicatorCropRadius, clear_paint); |
1366 canvas->DrawImageInt(gfx::ImageSkia(icon_canvas.ExtractImageRep()), 0, 0, | 1367 canvas->DrawImageInt(gfx::ImageSkia(icon_canvas.ExtractImageRep()), 0, 0, |
1367 favicon_draw_bounds.width(), | 1368 favicon_draw_bounds.width(), |
1368 favicon_draw_bounds.height(), favicon_draw_bounds.x(), | 1369 favicon_draw_bounds.height(), favicon_draw_bounds.x(), |
1369 favicon_draw_bounds.y(), favicon_draw_bounds.width(), | 1370 favicon_draw_bounds.y(), favicon_draw_bounds.width(), |
1370 favicon_draw_bounds.height(), false); | 1371 favicon_draw_bounds.height(), false); |
1371 } | 1372 } |
1372 | 1373 |
1373 // Draws the actual pinned tab title changed indicator. | 1374 // Draws the actual pinned tab title changed indicator. |
1374 const int kIndicatorRadius = 3; | 1375 const int kIndicatorRadius = 3; |
1375 SkPaint indicator_paint; | 1376 cc::PaintFlags indicator_paint; |
1376 indicator_paint.setColor(GetNativeTheme()->GetSystemColor( | 1377 indicator_paint.setColor(GetNativeTheme()->GetSystemColor( |
1377 ui::NativeTheme::kColorId_ProminentButtonColor)); | 1378 ui::NativeTheme::kColorId_ProminentButtonColor)); |
1378 indicator_paint.setAntiAlias(true); | 1379 indicator_paint.setAntiAlias(true); |
1379 const int indicator_x = GetMirroredXWithWidthInView( | 1380 const int indicator_x = GetMirroredXWithWidthInView( |
1380 favicon_bounds_.right() - kIndicatorRadius, kIndicatorRadius * 2); | 1381 favicon_bounds_.right() - kIndicatorRadius, kIndicatorRadius * 2); |
1381 const int indicator_y = favicon_bounds_.bottom() - kIndicatorRadius; | 1382 const int indicator_y = favicon_bounds_.bottom() - kIndicatorRadius; |
1382 canvas->DrawCircle(gfx::Point(indicator_x + kIndicatorRadius, | 1383 canvas->DrawCircle(gfx::Point(indicator_x + kIndicatorRadius, |
1383 indicator_y + kIndicatorRadius), | 1384 indicator_y + kIndicatorRadius), |
1384 kIndicatorRadius, indicator_paint); | 1385 kIndicatorRadius, indicator_paint); |
1385 } | 1386 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1584 SchedulePaintInRect(bounds); | 1585 SchedulePaintInRect(bounds); |
1585 } | 1586 } |
1586 | 1587 |
1587 gfx::Rect Tab::GetImmersiveBarRect() const { | 1588 gfx::Rect Tab::GetImmersiveBarRect() const { |
1588 // The main bar is as wide as the normal tab's horizontal top line. | 1589 // The main bar is as wide as the normal tab's horizontal top line. |
1589 gfx::Rect contents = GetContentsBounds(); | 1590 gfx::Rect contents = GetContentsBounds(); |
1590 contents.set_y(0); | 1591 contents.set_y(0); |
1591 contents.set_height(kImmersiveBarHeight); | 1592 contents.set_height(kImmersiveBarHeight); |
1592 return contents; | 1593 return contents; |
1593 } | 1594 } |
OLD | NEW |