diff options
author | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 04:25:13 +0000 |
---|---|---|
committer | glen@chromium.org <glen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-24 04:25:13 +0000 |
commit | c01ce96d0dddd41e76fcc8323ed43016315ed080 (patch) | |
tree | 65d15894f2dd2a3f6bba35f054d050d95ceae143 /chrome/browser | |
parent | 3d4ae9a42320916079372a65c0ee527a150ec134 (diff) | |
download | chromium_src-c01ce96d0dddd41e76fcc8323ed43016315ed080.zip chromium_src-c01ce96d0dddd41e76fcc8323ed43016315ed080.tar.gz chromium_src-c01ce96d0dddd41e76fcc8323ed43016315ed080.tar.bz2 |
Fix a bunch of bugs related to NNTP theming.
Basically:
- Add NNTP Theming
BrowserThemeProvider:
- Add NNTP logo inversion capability
- Only allow a set of images to be themed.
- Tint incognito windows correctly.
(Sorry for the feature-mush)
BUG=17379,14578,17593
TEST=Make sure the NNTP is themed correctly.
Review URL: http://codereview.chromium.org/159305
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21509 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r-- | chrome/browser/browser_theme_provider.cc | 121 | ||||
-rw-r--r-- | chrome/browser/browser_theme_provider.h | 8 | ||||
-rw-r--r-- | chrome/browser/dom_ui/dom_ui_theme_source.cc | 39 | ||||
-rw-r--r-- | chrome/browser/resources/new_new_tab.css | 2 | ||||
-rw-r--r-- | chrome/browser/resources/new_tab_theme.css | 56 |
5 files changed, 190 insertions, 36 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc index 4e578cb..c993bef 100644 --- a/chrome/browser/browser_theme_provider.cc +++ b/chrome/browser/browser_theme_provider.cc @@ -24,6 +24,7 @@ #include "skia/ext/image_operations.h" #include "skia/ext/skia_utils.h" #include "third_party/skia/include/core/SkBitmap.h" +#include "third_party/skia/include/core/SkCanvas.h" #if defined(OS_WIN) #include "app/win_util.h" @@ -66,6 +67,8 @@ const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment = "ntp_background_alignment"; const char* BrowserThemeProvider::kDisplayPropertyNTPTiling = "ntp_background_repeat"; +const char* BrowserThemeProvider::kDisplayPropertyNTPInverseLogo = + "ntp_logo_alternate"; // Strings used in alignment properties. const char* BrowserThemeProvider::kAlignmentTop = "top"; @@ -95,19 +98,19 @@ const SkColor BrowserThemeProvider::kDefaultColorTabText = const SkColor BrowserThemeProvider::kDefaultColorBackgroundTabText = SkColorSetRGB(64, 64, 64); const SkColor BrowserThemeProvider::kDefaultColorBookmarkText = - SkColorSetRGB(64, 64, 64); + SkColorSetRGB(18, 50, 114); const SkColor BrowserThemeProvider::kDefaultColorNTPBackground = SkColorSetRGB(255, 255, 255); const SkColor BrowserThemeProvider::kDefaultColorNTPText = SkColorSetRGB(0, 0, 0); const SkColor BrowserThemeProvider::kDefaultColorNTPLink = - SkColorSetRGB(0, 0, 204); + SkColorSetRGB(0, 0, 0); const SkColor BrowserThemeProvider::kDefaultColorNTPSection = - SkColorSetRGB(225, 236, 254); + SkColorSetRGB(75, 140, 220); const SkColor BrowserThemeProvider::kDefaultColorNTPSectionText = - SkColorSetRGB(0, 0, 0); + SkColorSetRGB(255, 255, 255); const SkColor BrowserThemeProvider::kDefaultColorNTPSectionLink = - SkColorSetRGB(0, 0, 204); + SkColorSetRGB(127, 148, 173); const SkColor BrowserThemeProvider::kDefaultColorControlBackground = NULL; const SkColor BrowserThemeProvider::kDefaultColorButtonBackground = NULL; @@ -128,6 +131,7 @@ static const int kDefaultDisplayPropertyNTPAlignment = BrowserThemeProvider::ALIGN_BOTTOM; static const int kDefaultDisplayPropertyNTPTiling = BrowserThemeProvider::NO_REPEAT; +static const int kDefaultDisplayPropertyNTPInverseLogo = 0; // The image resources that will be tinted by the 'button' tint value. static const int kToolbarButtonIDs[] = { @@ -142,12 +146,34 @@ static const int kToolbarButtonIDs[] = { IDR_MENU_PAGE, IDR_MENU_PAGE_RTL, IDR_MENU_CHROME, IDR_MENU_CHROME_RTL, IDR_MENU_DROPARROW, - IDR_THROBBER, IDR_THROBBER_WAITING, IDR_THROBBER_LIGHT + IDR_THROBBER, IDR_THROBBER_WAITING, IDR_THROBBER_LIGHT, + IDR_LOCATIONBG }; // A map for kToolbarButtonIDs. static std::map<const int, bool> button_images_; +// The image resources we will allow people to theme. +static const int kThemeableImages[] = { + IDR_THEME_FRAME, + IDR_THEME_FRAME_INACTIVE, + IDR_THEME_FRAME_INCOGNITO, + IDR_THEME_FRAME_INCOGNITO_INACTIVE, + IDR_THEME_TOOLBAR, + IDR_THEME_TAB_BACKGROUND, + IDR_THEME_TAB_BACKGROUND_INCOGNITO, + IDR_THEME_TAB_BACKGROUND_V, + IDR_THEME_NTP_BACKGROUND, + IDR_THEME_FRAME_OVERLAY, + IDR_THEME_FRAME_OVERLAY_INACTIVE, + IDR_THEME_BUTTON_BACKGROUND, + IDR_THEME_NTP_ATTRIBUTION, + IDR_THEME_WINDOW_CONTROL_BACKGROUND +}; + +// A map for kThemeableImages. +static std::map<const int, bool> themeable_images_; + // A map of frame image IDs to the tints for those ids. static std::map<const int, int> frame_tints_; @@ -158,8 +184,13 @@ BrowserThemeProvider::BrowserThemeProvider() for (size_t i = 0; i < arraysize(kToolbarButtonIDs); ++i) { button_images_[kToolbarButtonIDs[i]] = true; } + for (size_t i = 0; i < arraysize(kThemeableImages); ++i) { + themeable_images_[kThemeableImages[i]] = true; + } frame_tints_[IDR_THEME_FRAME] = TINT_FRAME; frame_tints_[IDR_THEME_FRAME_INACTIVE] = TINT_FRAME_INACTIVE; + frame_tints_[IDR_THEME_FRAME_OVERLAY] = TINT_FRAME; + frame_tints_[IDR_THEME_FRAME_OVERLAY_INACTIVE] = TINT_FRAME_INACTIVE; frame_tints_[IDR_THEME_FRAME_INCOGNITO] = TINT_FRAME_INCOGNITO; frame_tints_[IDR_THEME_FRAME_INCOGNITO_INACTIVE] = TINT_FRAME_INCOGNITO_INACTIVE; @@ -179,6 +210,12 @@ void BrowserThemeProvider::Init(Profile* profile) { SkBitmap* BrowserThemeProvider::GetBitmapNamed(int id) { DCHECK(CalledOnValidThread()); + // Check to see whether we should substitute some images. + int ntp_alternate; + GetDisplayProperty(NTP_LOGO_ALTERNATE, &ntp_alternate); + if (id == IDR_PRODUCT_LOGO && ntp_alternate != 0) + id = IDR_PRODUCT_LOGO_WHITE; + // Check to see if we already have the Skia image in the cache. ImageCache::const_iterator found = image_cache_.find(id); if (found != image_cache_.end()) @@ -282,6 +319,14 @@ bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { *result = kDefaultDisplayPropertyNTPTiling; } return true; + case NTP_LOGO_ALTERNATE: + if (display_properties_.find(kDisplayPropertyNTPInverseLogo) != + display_properties_.end()) { + *result = display_properties_[kDisplayPropertyNTPInverseLogo]; + } else { + *result = kDefaultDisplayPropertyNTPInverseLogo; + } + return true; default: NOTREACHED() << "Unknown property requested"; } @@ -289,7 +334,7 @@ bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) { } bool BrowserThemeProvider::ShouldUseNativeFrame() { - if (images_.find(IDR_THEME_FRAME) != images_.end()) + if (HasCustomImage(IDR_THEME_FRAME)) return false; #if defined(OS_WIN) return win_util::ShouldUseVistaFrame(); @@ -299,6 +344,9 @@ bool BrowserThemeProvider::ShouldUseNativeFrame() { } bool BrowserThemeProvider::HasCustomImage(int id) { + if (!themeable_images_[id]) + return false; + return (images_.find(id) != images_.end()); } @@ -315,6 +363,7 @@ void BrowserThemeProvider::SetTheme(Extension* extension) { SetDisplayPropertyData(extension->GetThemeDisplayProperties()); GenerateFrameColors(); GenerateFrameImages(); + GenerateTabImages(); SaveImageData(extension->GetThemeImages()); SaveColorData(); @@ -362,6 +411,10 @@ bool BrowserThemeProvider::ReadThemeFileData( SkBitmap* BrowserThemeProvider::LoadThemeBitmap(int id) { DCHECK(CalledOnValidThread()); + + if (!themeable_images_[id]) + return NULL; + // Attempt to find the image in our theme bundle. std::vector<unsigned char> raw_data, png_data; if (ReadThemeFileData(id, &raw_data)) { @@ -539,6 +592,12 @@ void BrowserThemeProvider::SetDisplayPropertyData( display_properties_[kDisplayPropertyNTPTiling] = StringToTiling(val); } + if (base::strcasecmp(WideToUTF8(*iter).c_str(), + kDisplayPropertyNTPInverseLogo) == 0) { + std::string val; + if (display_properties_value->GetString(*iter, &val)) + display_properties_[kDisplayPropertyNTPInverseLogo] = StringToInt(val); + } ++iter; } } @@ -655,13 +714,24 @@ void BrowserThemeProvider::GenerateFrameImages() { // If there's no frame image provided for the specified id, then load // the default provided frame. If that's not provided, skip this whole // thing and just use the default images. - int base_id = (id == IDR_THEME_FRAME_INCOGNITO || - id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) ? - IDR_THEME_FRAME_INCOGNITO : IDR_THEME_FRAME; - - if (images_.find(id) != images_.end()) { + int base_id; + if (id == IDR_THEME_FRAME_INCOGNITO_INACTIVE) + base_id = (HasCustomImage(IDR_THEME_FRAME_INCOGNITO)) ? + IDR_THEME_FRAME_INCOGNITO : + IDR_THEME_FRAME; + else if (id == IDR_THEME_FRAME_OVERLAY_INACTIVE) + base_id = IDR_THEME_FRAME_OVERLAY; + else if (id == IDR_THEME_FRAME_INACTIVE) + base_id = IDR_THEME_FRAME; + else if (id == IDR_THEME_FRAME_INCOGNITO && + !HasCustomImage(IDR_THEME_FRAME_INCOGNITO)) + base_id = IDR_THEME_FRAME; + else + base_id = id; + + if (HasCustomImage(id)) { frame.reset(LoadThemeBitmap(id)); - } else if (base_id != id && images_.find(base_id) != images_.end()) { + } else if (base_id != id && HasCustomImage(base_id)) { frame.reset(LoadThemeBitmap(base_id)); } else { // If the theme doesn't specify an image, then apply the tint to @@ -679,6 +749,11 @@ void BrowserThemeProvider::GenerateFrameImages() { } } +void BrowserThemeProvider::GenerateTabImages() { + GenerateBitmap(IDR_THEME_TAB_BACKGROUND); + GenerateBitmap(IDR_THEME_TAB_BACKGROUND_INCOGNITO); +} + void BrowserThemeProvider::ClearAllThemeData() { // Clear our image cache. ClearCaches(); @@ -707,10 +782,21 @@ SkBitmap* BrowserThemeProvider::GenerateBitmap(int id) { std::map<int, SkBitmap*>::iterator it = image_cache_.find(base_id); if (it != image_cache_.end()) { SkBitmap* frame = it->second; + int blur_amount = (HasCustomImage(id)) ? 1 : 5; SkBitmap blurred = - skia::ImageOperations::CreateBlurredBitmap(*frame, 5); + skia::ImageOperations::CreateBlurredBitmap(*frame, blur_amount); SkBitmap* bg_tab = new SkBitmap(TintBitmap(blurred, TINT_BACKGROUND_TAB)); + + // If they've provided a custom image, overlay it. + if (HasCustomImage(id)) { + SkBitmap* overlay = LoadThemeBitmap(id); + SkCanvas canvas(*bg_tab); + for (int x = 0; x < bg_tab->width(); x += overlay->width()) + canvas.drawBitmap(*overlay, static_cast<SkScalar>(x), 0, NULL); + } + + image_cache_[id] = bg_tab; return bg_tab; } } @@ -752,7 +838,7 @@ void BrowserThemeProvider::SaveColorData() { rgb_list->Set(1, Value::CreateIntegerValue(SkColorGetG(rgba))); rgb_list->Set(2, Value::CreateIntegerValue(SkColorGetB(rgba))); if (SkColorGetA(rgba) != 255) - rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba))); + rgb_list->Set(3, Value::CreateRealValue(SkColorGetA(rgba) / 255.0)); pref_colors->Set(UTF8ToWide((*iter).first), rgb_list); ++iter; } @@ -799,6 +885,11 @@ void BrowserThemeProvider::SaveDisplayPropertyData() { SetString(UTF8ToWide((*iter).first), TilingToString( (*iter).second)); } + if (base::strcasecmp((*iter).first.c_str(), + kDisplayPropertyNTPInverseLogo) == 0) { + pref_display_properties-> + SetInteger(UTF8ToWide((*iter).first), (*iter).second); + } ++iter; } } diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h index 3e42036..63eca78 100644 --- a/chrome/browser/browser_theme_provider.h +++ b/chrome/browser/browser_theme_provider.h @@ -57,6 +57,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // Strings used by themes to identify miscellaneous numerical properties. static const char* kDisplayPropertyNTPAlignment; static const char* kDisplayPropertyNTPTiling; + static const char* kDisplayPropertyNTPInverseLogo; // Strings used in alignment properties. static const char* kAlignmentTop; @@ -123,7 +124,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, TINT_FRAME_INCOGNITO_INACTIVE, TINT_BACKGROUND_TAB, NTP_BACKGROUND_ALIGNMENT, - NTP_BACKGROUND_TILING + NTP_BACKGROUND_TILING, + NTP_LOGO_ALTERNATE }; // A bitfield mask for alignments. @@ -197,6 +199,10 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>, // will be stored in our cache. void GenerateFrameImages(); + // Generate any tab images that weren't specified. The resulting images + // will be stored in our cache. + void GenerateTabImages(); + // Clears all the override fields and saves the dictionary. void ClearAllThemeData(); diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc index 2ce9cf5..92ec21b 100644 --- a/chrome/browser/dom_ui/dom_ui_theme_source.cc +++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc @@ -100,6 +100,14 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) { SkColor color_section_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION_LINK); + // Generate a lighter color. + skia::HSL section_lighter; + skia::SkColorToHSL(color_section, section_lighter); + section_lighter.l += (1 - section_lighter.l) * 0.33; + section_lighter.s += (1 - section_lighter.s) * 0.1; + SkColor color_section_lighter = + skia::HSLToSkColor(SkColorGetA(color_section), section_lighter); + // Generate the replacements. std::vector<string16> subst; // A second list of replacements, each of which must be in $$x format, @@ -108,19 +116,20 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) { // Cache-buster for background. subst.push_back(UTF8ToUTF16(IntToString(static_cast<int>( - base::Time::Now().ToDoubleT())))); + base::Time::Now().ToDoubleT())))); // $1 // Colors. - subst.push_back(SkColorToRGBAString(color_background)); - subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(false))); - subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(true))); - subst.push_back(SkColorToRGBAString(color_text)); - subst.push_back(SkColorToRGBAString(color_link)); - subst.push_back(SkColorToRGBAString(color_section)); - subst.push_back(SkColorToRGBAString(color_section_text)); - subst.push_back(SkColorToRGBAString(color_section_link)); - - subst2.push_back(UTF8ToUTF16(GetNewTabBackgroundTilingCSS())); + subst.push_back(SkColorToRGBAString(color_background)); // $2 + subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(false))); // $3 + subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(true))); // $4 + subst.push_back(UTF8ToUTF16(GetNewTabBackgroundTilingCSS())); // $5 + subst.push_back(SkColorToRGBAString(color_section)); // $6 + subst.push_back(SkColorToRGBAString(color_section_lighter)); // $7 + subst.push_back(SkColorToRGBAString(color_text)); // $8 + subst.push_back(SkColorToRGBAString(color_link)); // $9 + + subst2.push_back(SkColorToRGBAString(color_section_text)); // $$1 + subst2.push_back(SkColorToRGBAString(color_section_link)); // $$2 // Get our template. static const StringPiece new_tab_theme_css( @@ -177,6 +186,14 @@ std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) { int offset = 0; #endif + // TODO(glen): This is a quick workaround to hide the notused.png image when + // no image is provided - we don't have time right now to figure out why + // this is painting as white. + // http://crbug.com/17593 + if (!profile_->GetThemeProvider()->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { + return "-64px"; + } + if (alignment & BrowserThemeProvider::ALIGN_TOP) { if (alignment & BrowserThemeProvider::ALIGN_LEFT) return "0% " + IntToString(-offset) + "px"; diff --git a/chrome/browser/resources/new_new_tab.css b/chrome/browser/resources/new_new_tab.css index f865d70..8ed2680 100644 --- a/chrome/browser/resources/new_new_tab.css +++ b/chrome/browser/resources/new_new_tab.css @@ -361,7 +361,7 @@ html[dir=rtl] .thumbnail-container > .title > div { } .section { - background: white; + background: rgba(255, 255, 255, 0.8); -webkit-border-radius: 4px; white-space: nowrap; text-overflow: ellipsis; diff --git a/chrome/browser/resources/new_tab_theme.css b/chrome/browser/resources/new_tab_theme.css index 820649d..65d516e 100644 --- a/chrome/browser/resources/new_tab_theme.css +++ b/chrome/browser/resources/new_tab_theme.css @@ -2,24 +2,64 @@ html { background-image:url(chrome://theme/theme_ntp_background?$1); background-color:$2; background-position:$3; - background-repeat:$$1; + background-repeat:$5; overflow:hidden; } html[bookmarkbarattached='true'] { background-position:$4; } body { - color: $5; + color: $8; height:100%; overflow:auto; } -a { - color: $6; +.thumbnail-container, +.list > .thumbnail-container > .title, +.list .title > div, +.thumbnail-container > .title { + color: $8; +} +.thumbnail-container:focus .thumbnail, +.thumbnail-container:hover .thumbnail { + border-color: $6; } -.sidebar.themed { - background-color: $7; +.thumbnail-container:focus .edit-bar, +.thumbnail-container:hover .edit-bar { + background-color: $6; + background-image: -webkit-gradient(linear, left top, left bottom, + from($7), + to($6)); +} +.thumbnail-container:hover > .edit-mode-border { + background-color: $6; +} +:visited, +.link { + cursor: pointer; + text-decoration: underline; color: $8; } -.sidebar.themed a { - color: $9; +.edit-mode-border { + background-color: $7; +} +.section { + border: 1px solid $7; +} +.section > h2 { + background-color: $7; + background-image: -webkit-gradient(linear, left top, left bottom, + from($7), + to($6)); + color: $$1; +} +#view-toolbar input { + background-color: $7; + -webkit-mask-image: url(chrome://theme/newtab_menu_mask); +} +#option-menu > [selected] { + background-color: $7; + color: white; +} +.tips-title { + color: $$1; }
\ No newline at end of file |