Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(871)

Side by Side Diff: chrome/browser/dom_ui/dom_ui_theme_source.cc

Issue 115910: Allow themes to change the background of the new tab page.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.h ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/dom_ui_theme_source.h" 5 #include "chrome/browser/dom_ui/dom_ui_theme_source.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "app/theme_provider.h" 9 #include "app/theme_provider.h"
10 #include "base/gfx/png_encoder.h" 10 #include "base/gfx/png_encoder.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/time.h" 13 #include "base/time.h"
14 #include "chrome/browser/browser_theme_provider.h" 14 #include "chrome/browser/browser_theme_provider.h"
15 #include "chrome/browser/profile.h" 15 #include "chrome/browser/profile.h"
16 #include "chrome/browser/theme_resources_util.h" 16 #include "chrome/browser/theme_resources_util.h"
17 #include "chrome/common/url_constants.h" 17 #include "chrome/common/url_constants.h"
18 #include "googleurl/src/gurl.h" 18 #include "googleurl/src/gurl.h"
19 #include "grit/browser_resources.h" 19 #include "grit/browser_resources.h"
20 #include "grit/generated_resources.h" 20 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
22 22
23 #if defined(OS_WIN)
24 #include "chrome/browser/views/bookmark_bar_view.h"
25 #endif
26
23 // Path for the New Tab CSS. When we get more than a few of these, we should 27 // Path for the New Tab CSS. When we get more than a few of these, we should
24 // use a resource map rather than hard-coded strings. 28 // use a resource map rather than hard-coded strings.
25 static const char* kNewTabCSSPath = "css/newtab.css"; 29 static const char* kNewTabCSSPath = "css/newtab.css";
26 30
27 static string16 SkColorToRGBAString(SkColor color) { 31 static string16 SkColorToRGBAString(SkColor color) {
28 return WideToUTF16(l10n_util::GetStringF(IDS_RGBA_CSS_FORMAT_STRING, 32 return WideToUTF16(l10n_util::GetStringF(IDS_RGBA_CSS_FORMAT_STRING,
29 IntToWString(SkColorGetR(color)), 33 IntToWString(SkColorGetR(color)),
30 IntToWString(SkColorGetG(color)), 34 IntToWString(SkColorGetG(color)),
31 IntToWString(SkColorGetB(color)), 35 IntToWString(SkColorGetB(color)),
32 DoubleToWString(SkColorGetA(color) / 255.0))); 36 DoubleToWString(SkColorGetA(color) / 255.0)));
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 } 82 }
79 83
80 //////////////////////////////////////////////////////////////////////////////// 84 ////////////////////////////////////////////////////////////////////////////////
81 // DOMUIThemeSource, private: 85 // DOMUIThemeSource, private:
82 86
83 void DOMUIThemeSource::SendNewTabCSS(int request_id) { 87 void DOMUIThemeSource::SendNewTabCSS(int request_id) {
84 ThemeProvider* tp = profile_->GetThemeProvider(); 88 ThemeProvider* tp = profile_->GetThemeProvider();
85 DCHECK(tp); 89 DCHECK(tp);
86 90
87 // Get our theme colors 91 // Get our theme colors
92 SkColor color_background =
93 tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND);
88 SkColor color_text = tp->GetColor(BrowserThemeProvider::COLOR_NTP_TEXT); 94 SkColor color_text = tp->GetColor(BrowserThemeProvider::COLOR_NTP_TEXT);
89 SkColor color_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK); 95 SkColor color_link = tp->GetColor(BrowserThemeProvider::COLOR_NTP_LINK);
90 SkColor color_section = 96 SkColor color_section =
91 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION); 97 tp->GetColor(BrowserThemeProvider::COLOR_NTP_SECTION);
92 98
93 // Generate the replacements. 99 // Generate the replacements.
94 std::vector<string16> subst; 100 std::vector<string16> subst;
95 101
96 // Cache-buster for background. 102 // Cache-buster for background.
97 subst.push_back(UTF8ToUTF16(IntToString(static_cast<int>( 103 subst.push_back(UTF8ToUTF16(IntToString(static_cast<int>(
98 base::Time::Now().ToDoubleT())))); 104 base::Time::Now().ToDoubleT()))));
99 105
100 // Colors. 106 // Colors.
107 subst.push_back(SkColorToRGBAString(color_background));
108 subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(false)));
109 subst.push_back(UTF8ToUTF16(GetNewTabBackgroundCSS(true)));
101 subst.push_back(SkColorToRGBAString(color_text)); 110 subst.push_back(SkColorToRGBAString(color_text));
102 subst.push_back(SkColorToRGBAString(color_link)); 111 subst.push_back(SkColorToRGBAString(color_link));
103 subst.push_back(SkColorToRGBAString(color_section)); 112 subst.push_back(SkColorToRGBAString(color_section));
104 113
105 // Get our template. 114 // Get our template.
106 static const StringPiece new_tab_theme_css( 115 static const StringPiece new_tab_theme_css(
107 ResourceBundle::GetSharedInstance().GetRawDataResource( 116 ResourceBundle::GetSharedInstance().GetRawDataResource(
108 IDR_NEW_TAB_THEME_CSS)); 117 IDR_NEW_TAB_THEME_CSS));
109 118
110 // Create the string from our template and the replacements. 119 // Create the string from our template and the replacements.
(...skipping 16 matching lines...) Expand all
127 136
128 SkBitmap* image = tp->GetBitmapNamed(resource_id); 137 SkBitmap* image = tp->GetBitmapNamed(resource_id);
129 DCHECK(image); 138 DCHECK(image);
130 std::vector<unsigned char> png_bytes; 139 std::vector<unsigned char> png_bytes;
131 PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes); 140 PNGEncoder::EncodeBGRASkBitmap(*image, false, &png_bytes);
132 141
133 scoped_refptr<RefCountedBytes> image_data = 142 scoped_refptr<RefCountedBytes> image_data =
134 new RefCountedBytes(png_bytes); 143 new RefCountedBytes(png_bytes);
135 SendResponse(request_id, image_data); 144 SendResponse(request_id, image_data);
136 } 145 }
146
147 std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) {
148 int alignment;
149 profile_->GetThemeProvider()->GetDisplayProperty(
150 BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT, &alignment);
151
152 if (bar_attached)
153 return BrowserThemeProvider::AlignmentToString(alignment);
154
155 // The bar is detached, so we must offset the background by the bar size
156 // if it's a top-aligned bar.
157 #if defined(OS_WIN)
158 int offset = BookmarkBarView::kNewtabBarHeight;
159 #else
160 int offset = 0;
161 #endif
162
163 if (alignment & BrowserThemeProvider::ALIGN_TOP) {
164 if (alignment & BrowserThemeProvider::ALIGN_LEFT)
165 return "0% " + IntToString(-offset) + "px";
166 else if (alignment & BrowserThemeProvider::ALIGN_RIGHT)
167 return "100% " + IntToString(-offset) + "px";
168 return IntToString(-offset) + "px";
169 }
170 return BrowserThemeProvider::AlignmentToString(alignment);
171 }
172
OLDNEW
« no previous file with comments | « chrome/browser/dom_ui/dom_ui_theme_source.h ('k') | chrome/browser/dom_ui/new_tab_ui.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698