| 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/webui/ntp/ntp_resource_cache.h" | 5 #include "chrome/browser/ui/webui/ntp/ntp_resource_cache.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 SkColor color = tp->GetColor(id); | 111 SkColor color = tp->GetColor(id); |
| 112 // If web contents are being inverted because the system is in high-contrast | 112 // If web contents are being inverted because the system is in high-contrast |
| 113 // mode, any system theme colors we use must be inverted too to cancel out. | 113 // mode, any system theme colors we use must be inverted too to cancel out. |
| 114 return gfx::IsInvertedColorScheme() ? | 114 return gfx::IsInvertedColorScheme() ? |
| 115 color_utils::InvertColor(color) : color; | 115 color_utils::InvertColor(color) : color; |
| 116 } | 116 } |
| 117 | 117 |
| 118 // Get the CSS string for the background position on the new tab page for the | 118 // Get the CSS string for the background position on the new tab page for the |
| 119 // states when the bar is attached or detached. | 119 // states when the bar is attached or detached. |
| 120 std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, | 120 std::string GetNewTabBackgroundCSS(const ui::ThemeProvider* theme_provider, |
| 121 bool bar_attached) { | 121 bool bar_attached, |
| 122 bool is_ntp_search) { |
| 122 int alignment; | 123 int alignment; |
| 123 theme_provider->GetDisplayProperty( | 124 theme_provider->GetDisplayProperty( |
| 124 ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); | 125 ThemeService::NTP_BACKGROUND_ALIGNMENT, &alignment); |
| 125 | 126 |
| 126 // TODO(glen): This is a quick workaround to hide the notused.png image when | 127 // TODO(glen): This is a quick workaround to hide the notused.png image when |
| 127 // no image is provided - we don't have time right now to figure out why | 128 // no image is provided - we don't have time right now to figure out why |
| 128 // this is painting as white. | 129 // this is painting as white. |
| 129 // http://crbug.com/17593 | 130 // http://crbug.com/17593 |
| 130 if (!theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { | 131 if (!theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { |
| 131 return "-64px"; | 132 return "-64px"; |
| 132 } | 133 } |
| 133 | 134 |
| 134 if (bar_attached) | 135 // For instant extended API i.e. |is_ntp_search| is true, bookmark bar is |
| 136 // always detached at bottom of content view in the y-direction, floating on |
| 137 // top of it in the z-order, and not showing any part of the theme background |
| 138 // image, so the content view should show the entire theme background image as |
| 139 // is, with no vertical offset. |
| 140 if (bar_attached || is_ntp_search) |
| 135 return ThemeService::AlignmentToString(alignment); | 141 return ThemeService::AlignmentToString(alignment); |
| 136 | 142 |
| 137 if (alignment & ThemeService::ALIGN_TOP) { | 143 if (alignment & ThemeService::ALIGN_TOP) { |
| 138 // The bar is detached, so we must offset the background by the bar size | 144 // The bar is detached, so we must offset the background by the bar size |
| 139 // if it's a top-aligned bar. | 145 // if it's a top-aligned bar. |
| 140 int offset = chrome::kNTPBookmarkBarHeight; | 146 int offset = chrome::kNTPBookmarkBarHeight; |
| 141 | 147 |
| 142 if (alignment & ThemeService::ALIGN_LEFT) | 148 if (alignment & ThemeService::ALIGN_LEFT) |
| 143 return "left " + base::IntToString(-offset) + "px"; | 149 return "left " + base::IntToString(-offset) + "px"; |
| 144 else if (alignment & ThemeService::ALIGN_RIGHT) | 150 else if (alignment & ThemeService::ALIGN_RIGHT) |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 SkColor color_background = | 454 SkColor color_background = |
| 449 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND); | 455 GetThemeColor(tp, ThemeService::COLOR_NTP_BACKGROUND); |
| 450 | 456 |
| 451 // Generate the replacements. | 457 // Generate the replacements. |
| 452 std::vector<std::string> subst; | 458 std::vector<std::string> subst; |
| 453 | 459 |
| 454 // Cache-buster for background. | 460 // Cache-buster for background. |
| 455 subst.push_back( | 461 subst.push_back( |
| 456 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 462 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 |
| 457 | 463 |
| 464 bool is_ntp_search = chrome::search::IsInstantExtendedAPIEnabled(profile_); |
| 465 |
| 458 // Colors. | 466 // Colors. |
| 459 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 467 subst.push_back(SkColorToRGBAString(color_background)); // $2 |
| 460 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 468 subst.push_back(GetNewTabBackgroundCSS(tp, false, is_ntp_search)); // $3 |
| 461 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 469 subst.push_back(GetNewTabBackgroundCSS(tp, true, is_ntp_search)); // $4 |
| 462 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 470 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 |
| 463 | 471 |
| 464 // Get our template. | 472 // Get our template. |
| 465 static const base::StringPiece new_tab_theme_css( | 473 static const base::StringPiece new_tab_theme_css( |
| 466 ResourceBundle::GetSharedInstance().GetRawDataResource( | 474 ResourceBundle::GetSharedInstance().GetRawDataResource( |
| 467 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); | 475 IDR_NEW_INCOGNITO_TAB_THEME_CSS)); |
| 468 | 476 |
| 469 // Create the string from our template and the replacements. | 477 // Create the string from our template and the replacements. |
| 470 std::string full_css = ReplaceStringPlaceholders( | 478 std::string full_css = ReplaceStringPlaceholders( |
| 471 new_tab_theme_css, subst, NULL); | 479 new_tab_theme_css, subst, NULL); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 522 SkColorGetG(color_header), | 530 SkColorGetG(color_header), |
| 523 SkColorGetB(color_header)); | 531 SkColorGetB(color_header)); |
| 524 | 532 |
| 525 // Generate the replacements. | 533 // Generate the replacements. |
| 526 std::vector<std::string> subst; | 534 std::vector<std::string> subst; |
| 527 | 535 |
| 528 // Cache-buster for background. | 536 // Cache-buster for background. |
| 529 subst.push_back( | 537 subst.push_back( |
| 530 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 | 538 profile_->GetPrefs()->GetString(prefs::kCurrentThemeID)); // $1 |
| 531 | 539 |
| 540 bool is_ntp_search = chrome::search::IsInstantExtendedAPIEnabled(profile_); |
| 541 |
| 532 // Colors. | 542 // Colors. |
| 533 subst.push_back(SkColorToRGBAString(color_background)); // $2 | 543 subst.push_back(SkColorToRGBAString(color_background)); // $2 |
| 534 subst.push_back(GetNewTabBackgroundCSS(tp, false)); // $3 | 544 subst.push_back(GetNewTabBackgroundCSS(tp, false, is_ntp_search)); // $3 |
| 535 subst.push_back(GetNewTabBackgroundCSS(tp, true)); // $4 | 545 subst.push_back(GetNewTabBackgroundCSS(tp, true, is_ntp_search)); // $4 |
| 536 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 | 546 subst.push_back(GetNewTabBackgroundTilingCSS(tp)); // $5 |
| 537 subst.push_back(SkColorToRGBAString(color_header)); // $6 | 547 subst.push_back(SkColorToRGBAString(color_header)); // $6 |
| 538 subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 | 548 subst.push_back(SkColorToRGBAString(color_header_gradient_light)); // $7 |
| 539 subst.push_back(SkColorToRGBAString(color_text)); // $8 | 549 subst.push_back(SkColorToRGBAString(color_text)); // $8 |
| 540 subst.push_back(SkColorToRGBAString(color_link)); // $9 | 550 subst.push_back(SkColorToRGBAString(color_link)); // $9 |
| 541 subst.push_back(SkColorToRGBAString(color_section)); // $10 | 551 subst.push_back(SkColorToRGBAString(color_section)); // $10 |
| 542 subst.push_back(SkColorToRGBAString(color_section_border)); // $11 | 552 subst.push_back(SkColorToRGBAString(color_section_border)); // $11 |
| 543 subst.push_back(SkColorToRGBAString(color_section_text)); // $12 | 553 subst.push_back(SkColorToRGBAString(color_section_text)); // $12 |
| 544 subst.push_back(SkColorToRGBAString(color_section_link)); // $13 | 554 subst.push_back(SkColorToRGBAString(color_section_link)); // $13 |
| 545 subst.push_back(SkColorToRGBAString(color_link_underline)); // $14 | 555 subst.push_back(SkColorToRGBAString(color_link_underline)); // $14 |
| 546 subst.push_back(SkColorToRGBAString(color_section_link_underline)); // $15 | 556 subst.push_back(SkColorToRGBAString(color_section_link_underline)); // $15 |
| 547 subst.push_back(SkColorToRGBAString(color_section_header_text)); // $16 | 557 subst.push_back(SkColorToRGBAString(color_section_header_text)); // $16 |
| 548 subst.push_back(SkColorToRGBAString( | 558 subst.push_back(SkColorToRGBAString( |
| 549 color_section_header_text_hover)); // $17 | 559 color_section_header_text_hover)); // $17 |
| 550 subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 | 560 subst.push_back(SkColorToRGBAString(color_section_header_rule)); // $18 |
| 551 subst.push_back(SkColorToRGBAString( | 561 subst.push_back(SkColorToRGBAString( |
| 552 color_section_header_rule_light)); // $19 | 562 color_section_header_rule_light)); // $19 |
| 553 subst.push_back(SkColorToRGBAString( | 563 subst.push_back(SkColorToRGBAString( |
| 554 SkColorSetA(color_section_header_rule, 0))); // $20 | 564 SkColorSetA(color_section_header_rule, 0))); // $20 |
| 555 subst.push_back(SkColorToRGBAString(color_text_light)); // $21 | 565 subst.push_back(SkColorToRGBAString(color_text_light)); // $21 |
| 556 subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 | 566 subst.push_back(SkColorToRGBComponents(color_section_border)); // $22 |
| 557 subst.push_back(SkColorToRGBComponents(color_text)); // $23 | 567 subst.push_back(SkColorToRGBComponents(color_text)); // $23 |
| 558 | 568 |
| 559 // Get our template. | 569 // Get our template. |
| 560 static const base::StringPiece new_tab_theme_css( | 570 static const base::StringPiece new_tab_theme_css( |
| 561 ResourceBundle::GetSharedInstance().GetRawDataResource( | 571 ResourceBundle::GetSharedInstance().GetRawDataResource(is_ntp_search ? |
| 562 chrome::search::IsInstantExtendedAPIEnabled(profile_) ? | |
| 563 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); | 572 IDR_NEW_TAB_SEARCH_THEME_CSS : IDR_NEW_TAB_4_THEME_CSS)); |
| 564 | 573 |
| 565 // Create the string from our template and the replacements. | 574 // Create the string from our template and the replacements. |
| 566 std::string css_string; | 575 std::string css_string; |
| 567 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); | 576 css_string = ReplaceStringPlaceholders(new_tab_theme_css, subst, NULL); |
| 568 new_tab_css_ = base::RefCountedString::TakeString(&css_string); | 577 new_tab_css_ = base::RefCountedString::TakeString(&css_string); |
| 569 } | 578 } |
| OLD | NEW |