summaryrefslogtreecommitdiffstats
path: root/chrome/browser/browser_theme_provider.cc
diff options
context:
space:
mode:
authormirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 03:23:33 +0000
committermirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-18 03:23:33 +0000
commit1df50c8de4ca23b55ac99e26497fe8ba5864b6f3 (patch)
tree572ce80a9d0d7270222b45ebd2ab801a90fc428d /chrome/browser/browser_theme_provider.cc
parentc8ced031ff61f75ebe05b3ac4d2a27ab8936fc18 (diff)
downloadchromium_src-1df50c8de4ca23b55ac99e26497fe8ba5864b6f3.zip
chromium_src-1df50c8de4ca23b55ac99e26497fe8ba5864b6f3.tar.gz
chromium_src-1df50c8de4ca23b55ac99e26497fe8ba5864b6f3.tar.bz2
Allow the tiling of theme background images on the NTP.
BUG= http://crbug/com/15796 TEST= Add a property for tiling to a theme manifest.json. Observe that the theme image is tiled on the NTP. Review URL: http://codereview.chromium.org/149741 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@21039 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/browser_theme_provider.cc')
-rw-r--r--chrome/browser/browser_theme_provider.cc58
1 files changed, 57 insertions, 1 deletions
diff --git a/chrome/browser/browser_theme_provider.cc b/chrome/browser/browser_theme_provider.cc
index 5a19ca6..4e578cb 100644
--- a/chrome/browser/browser_theme_provider.cc
+++ b/chrome/browser/browser_theme_provider.cc
@@ -64,6 +64,8 @@ const char* BrowserThemeProvider::kTintBackgroundTab = "background_tab";
// Strings used by themes to identify miscellaneous numerical properties.
const char* BrowserThemeProvider::kDisplayPropertyNTPAlignment =
"ntp_background_alignment";
+const char* BrowserThemeProvider::kDisplayPropertyNTPTiling =
+ "ntp_background_repeat";
// Strings used in alignment properties.
const char* BrowserThemeProvider::kAlignmentTop = "top";
@@ -71,6 +73,12 @@ const char* BrowserThemeProvider::kAlignmentBottom = "bottom";
const char* BrowserThemeProvider::kAlignmentLeft = "left";
const char* BrowserThemeProvider::kAlignmentRight = "right";
+// Strings used in background tiling repetition properties.
+const char* BrowserThemeProvider::kTilingNoRepeat = "no-repeat";
+const char* BrowserThemeProvider::kTilingRepeatX = "repeat-x";
+const char* BrowserThemeProvider::kTilingRepeatY = "repeat-y";
+const char* BrowserThemeProvider::kTilingRepeat = "repeat";
+
// Default colors.
const SkColor BrowserThemeProvider::kDefaultColorFrame =
SkColorSetRGB(77, 139, 217);
@@ -118,6 +126,8 @@ const skia::HSL BrowserThemeProvider::kDefaultTintBackgroundTab =
// Default display properties.
static const int kDefaultDisplayPropertyNTPAlignment =
BrowserThemeProvider::ALIGN_BOTTOM;
+static const int kDefaultDisplayPropertyNTPTiling =
+ BrowserThemeProvider::NO_REPEAT;
// The image resources that will be tinted by the 'button' tint value.
static const int kToolbarButtonIDs[] = {
@@ -264,6 +274,14 @@ bool BrowserThemeProvider::GetDisplayProperty(int id, int* result) {
*result = kDefaultDisplayPropertyNTPAlignment;
}
return true;
+ case NTP_BACKGROUND_TILING:
+ if (display_properties_.find(kDisplayPropertyNTPTiling) !=
+ display_properties_.end()) {
+ *result = display_properties_[kDisplayPropertyNTPTiling];
+ } else {
+ *result = kDefaultDisplayPropertyNTPTiling;
+ }
+ return true;
default:
NOTREACHED() << "Unknown property requested";
}
@@ -507,13 +525,19 @@ void BrowserThemeProvider::SetDisplayPropertyData(
DictionaryValue::key_iterator iter = display_properties_value->begin_keys();
while (iter != display_properties_value->end_keys()) {
- // New tab page alignment.
+ // New tab page alignment and background tiling.
if (base::strcasecmp(WideToUTF8(*iter).c_str(),
kDisplayPropertyNTPAlignment) == 0) {
std::string val;
if (display_properties_value->GetString(*iter, &val))
display_properties_[kDisplayPropertyNTPAlignment] =
StringToAlignment(val);
+ } else if (base::strcasecmp(WideToUTF8(*iter).c_str(),
+ kDisplayPropertyNTPTiling) == 0) {
+ std::string val;
+ if (display_properties_value->GetString(*iter, &val))
+ display_properties_[kDisplayPropertyNTPTiling] =
+ StringToTiling(val);
}
++iter;
}
@@ -568,6 +592,33 @@ std::string BrowserThemeProvider::AlignmentToString(int alignment) {
return vertical_string;
}
+// static
+int BrowserThemeProvider::StringToTiling(const std::string &tiling) {
+ const char* component = tiling.c_str();
+
+ if (base::strcasecmp(component, kTilingRepeatX) == 0)
+ return BrowserThemeProvider::REPEAT_X;
+ else if (base::strcasecmp(component, kTilingRepeatY) == 0)
+ return BrowserThemeProvider::REPEAT_Y;
+ else if (base::strcasecmp(component, kTilingRepeat) == 0)
+ return BrowserThemeProvider::REPEAT;
+ // NO_REPEAT is the default choice.
+ return BrowserThemeProvider::NO_REPEAT;
+}
+
+// static
+std::string BrowserThemeProvider::TilingToString(int tiling) {
+ // Convert from a TilingProperty back into a string.
+ if (tiling == BrowserThemeProvider::REPEAT_X)
+ return kTilingRepeatX;
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ return kTilingRepeatY;
+ else if (tiling == BrowserThemeProvider::REPEAT)
+ return kTilingRepeat;
+ else
+ return kTilingNoRepeat;
+}
+
void BrowserThemeProvider::SetColor(const char* key, const SkColor& color) {
colors_[key] = color;
}
@@ -742,6 +793,11 @@ void BrowserThemeProvider::SaveDisplayPropertyData() {
pref_display_properties->
SetString(UTF8ToWide((*iter).first), AlignmentToString(
(*iter).second));
+ } else if (base::strcasecmp((*iter).first.c_str(),
+ kDisplayPropertyNTPTiling) == 0) {
+ pref_display_properties->
+ SetString(UTF8ToWide((*iter).first), TilingToString(
+ (*iter).second));
}
++iter;
}