OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/dom_ui/ntp_resource_cache.h" | 5 #include "chrome/browser/dom_ui/ntp_resource_cache.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "app/animation.h" | 10 #include "app/animation.h" |
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
396 SkColor color_section_text = | 396 SkColor color_section_text = |
397 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_TEXT); | 397 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_TEXT); |
398 SkColor color_section_link = | 398 SkColor color_section_link = |
399 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_LINK); | 399 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_LINK); |
400 SkColor color_section_link_underline = | 400 SkColor color_section_link_underline = |
401 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE); | 401 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_LINK_UNDERLINE); |
402 SkColor color_section_header_text = | 402 SkColor color_section_header_text = |
403 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_TEXT); | 403 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_TEXT); |
404 SkColor color_section_header_text_hover = | 404 SkColor color_section_header_text_hover = |
405 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_TEXT_HOVER); | 405 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_TEXT_HOVER); |
| 406 SkColor color_section_header_rule = |
| 407 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_RULE); |
| 408 SkColor color_section_header_rule_light = |
| 409 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_HEADER_RULE_LIGHT); |
406 | 410 |
407 SkColor color_header = | 411 SkColor color_header = |
408 tp->GetColor(BrowserThemeProvider::COLOR_NTP_HEADER); | 412 tp->GetColor(BrowserThemeProvider::COLOR_NTP_HEADER); |
409 // Generate a lighter color for the header gradients. | 413 // Generate a lighter color for the header gradients. |
410 color_utils::HSL header_lighter; | 414 color_utils::HSL header_lighter; |
411 color_utils::SkColorToHSL(color_header, &header_lighter); | 415 color_utils::SkColorToHSL(color_header, &header_lighter); |
412 header_lighter.l += (1 - header_lighter.l) * 0.33; | 416 header_lighter.l += (1 - header_lighter.l) * 0.33; |
413 SkColor color_header_gradient_light = | 417 SkColor color_header_gradient_light = |
414 color_utils::HSLToSkColor(header_lighter, SkColorGetA(color_header)); | 418 color_utils::HSLToSkColor(header_lighter, SkColorGetA(color_header)); |
415 | 419 |
416 // Generate section border color from the header color. See | 420 // Generate section border color from the header color. See |
417 // BookmarkBarView::Paint for how we do this for the bookmark bar | 421 // BookmarkBarView::Paint for how we do this for the bookmark bar |
418 // borders. | 422 // borders. |
419 SkColor color_section_border = | 423 SkColor color_section_border = |
420 SkColorSetARGB(80, | 424 SkColorSetARGB(80, |
421 SkColorGetR(color_header), | 425 SkColorGetR(color_header), |
422 SkColorGetG(color_header), | 426 SkColorGetG(color_header), |
423 SkColorGetB(color_header)); | 427 SkColorGetB(color_header)); |
424 | 428 |
425 // Generate the replacements. | 429 // Generate the replacements. |
426 std::vector<std::string> subst; | 430 std::vector<std::string> subst; |
427 // A second list of replacements, each of which must be in $$x format, | 431 // A second list of replacements, each of which must be in $$x format, |
428 // where x is a digit from 1-9. | 432 // where x is a digit from 1-9. |
429 std::vector<std::string> subst2; | 433 std::vector<std::string> subst2; |
| 434 std::vector<std::string> subst3; |
430 | 435 |
431 // Cache-buster for background. | 436 // Cache-buster for background. |
432 subst.push_back( | 437 subst.push_back( |
433 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 438 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 |
434 | 439 |
435 // Colors. | 440 // Colors. |
436 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 441 subst.push_back(SkColorToRGBAString(color_background)); // $2 |
437 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 442 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 |
438 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 443 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 |
439 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 444 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 |
440 subst.push_back(SkColorToRGBAString(color_header)); // $6 | 445 subst.push_back(SkColorToRGBAString(color_header)); // $6 |
441 subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 | 446 subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 |
442 subst.push_back(SkColorToRGBAString(color_text)); // $8 | 447 subst.push_back(SkColorToRGBAString(color_text)); // $8 |
443 subst.push_back(SkColorToRGBAString(color_link)); // $9 | 448 subst.push_back(SkColorToRGBAString(color_link)); // $9 |
444 | 449 |
445 subst2.push_back(SkColorToRGBAString(color_section)); // $$1 | 450 subst2.push_back(SkColorToRGBAString(color_section)); // $$1 |
446 subst2.push_back(SkColorToRGBAString(color_section_border)); // $$2 | 451 subst2.push_back(SkColorToRGBAString(color_section_border)); // $$2 |
447 subst2.push_back(SkColorToRGBAString(color_section_text)); // $$3 | 452 subst2.push_back(SkColorToRGBAString(color_section_text)); // $$3 |
448 subst2.push_back(SkColorToRGBAString(color_section_link)); // $$4 | 453 subst2.push_back(SkColorToRGBAString(color_section_link)); // $$4 |
449 subst2.push_back( | 454 subst2.push_back( |
450 tp->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "block" : "none"); // $$5 | 455 tp->HasCustomImage(IDR_THEME_NTP_ATTRIBUTION) ? "block" : "none"); // $$5 |
451 subst2.push_back(SkColorToRGBAString(color_link_underline)); // $$6 | 456 subst2.push_back(SkColorToRGBAString(color_link_underline)); // $$6 |
452 subst2.push_back(SkColorToRGBAString(color_section_link_underline)); // $$7 | 457 subst2.push_back(SkColorToRGBAString(color_section_link_underline)); // $$7 |
453 subst2.push_back(SkColorToRGBAString(color_section_header_text)); // $$8 | 458 subst2.push_back(SkColorToRGBAString(color_section_header_text)); // $$8 |
454 subst2.push_back(SkColorToRGBAString( | 459 subst2.push_back(SkColorToRGBAString( |
455 color_section_header_text_hover)); // $$9 | 460 color_section_header_text_hover)); // $$9 |
456 | 461 |
| 462 // A fully transparent version of the background color --- used for gradients. |
| 463 subst3.push_back(SkColorToRGBAString( |
| 464 SkColorSetA(color_background, 0))); // $$$1 |
| 465 |
| 466 // TODO(aa): It seems we could generate sensible defaults for all these colors |
| 467 // for better backward compat with old themes. |
| 468 subst3.push_back(SkColorToRGBAString(color_section_header_rule)); // $$$2 |
| 469 subst3.push_back(SkColorToRGBAString( |
| 470 color_section_header_rule_light)); // $$$3 |
| 471 |
457 // Get our template. | 472 // Get our template. |
458 static const base::StringPiece new_tab_theme_css( | 473 static const base::StringPiece new_tab_theme_css( |
459 ResourceBundle::GetSharedInstance().GetRawDataResource( | 474 ResourceBundle::GetSharedInstance().GetRawDataResource( |
460 IDR_NEW_TAB_THEME_CSS)); | 475 IDR_NEW_TAB_THEME_CSS)); |
461 | 476 |
462 // Create the string from our template and the replacements. | 477 // Create the string from our template and the replacements. |
463 std::string css_string; | 478 std::string css_string; |
464 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 479 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
465 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); | 480 css_string = ReplaceStringPlaceholders(css_string, subst2, NULL); |
| 481 css_string = ReplaceStringPlaceholders(css_string, subst3, NULL); |
466 | 482 |
467 new_tab_css_ = new RefCountedBytes; | 483 new_tab_css_ = new RefCountedBytes; |
468 new_tab_css_->data.resize(css_string.size()); | 484 new_tab_css_->data.resize(css_string.size()); |
469 std::copy(css_string.begin(), css_string.end(), | 485 std::copy(css_string.begin(), css_string.end(), |
470 new_tab_css_->data.begin()); | 486 new_tab_css_->data.begin()); |
471 } | 487 } |
OLD | NEW |