summaryrefslogtreecommitdiffstats
path: root/chrome
diff options
context:
space:
mode:
Diffstat (limited to 'chrome')
-rw-r--r--chrome/browser/browser_theme_provider.cc58
-rw-r--r--chrome/browser/browser_theme_provider.h27
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.cc21
-rw-r--r--chrome/browser/dom_ui/dom_ui_theme_source.h4
-rw-r--r--chrome/browser/resources/new_tab_theme.css2
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc139
-rw-r--r--chrome/browser/views/bookmark_bar_view.h6
7 files changed, 237 insertions, 20 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;
}
diff --git a/chrome/browser/browser_theme_provider.h b/chrome/browser/browser_theme_provider.h
index 6d7bb70..4787c000 100644
--- a/chrome/browser/browser_theme_provider.h
+++ b/chrome/browser/browser_theme_provider.h
@@ -56,6 +56,7 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
// Strings used by themes to identify miscellaneous numerical properties.
static const char* kDisplayPropertyNTPAlignment;
+ static const char* kDisplayPropertyNTPTiling;
// Strings used in alignment properties.
static const char* kAlignmentTop;
@@ -63,6 +64,12 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
static const char* kAlignmentLeft;
static const char* kAlignmentRight;
+ // Strings used in tiling properties.
+ static const char* kTilingNoRepeat;
+ static const char* kTilingRepeatX;
+ static const char* kTilingRepeatY;
+ static const char* kTilingRepeat;
+
// Default colors.
static const SkColor kDefaultColorFrame;
static const SkColor kDefaultColorFrameInactive;
@@ -115,7 +122,8 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
TINT_FRAME_INCOGNITO,
TINT_FRAME_INCOGNITO_INACTIVE,
TINT_BACKGROUND_TAB,
- NTP_BACKGROUND_ALIGNMENT
+ NTP_BACKGROUND_ALIGNMENT,
+ NTP_BACKGROUND_TILING
};
// A bitfield mask for alignments.
@@ -127,7 +135,15 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
ALIGN_BOTTOM = 0x8,
} AlignmentMasks;
- virtual void Init(Profile* profile);
+ // Background tiling choices.
+ enum {
+ NO_REPEAT = 0,
+ REPEAT_X = 1,
+ REPEAT_Y = 2,
+ REPEAT = 3
+ } Tiling;
+
+ void Init(Profile* profile);
// ThemeProvider implementation.
virtual SkBitmap* GetBitmapNamed(int id);
@@ -161,6 +177,13 @@ class BrowserThemeProvider : public base::RefCounted<BrowserThemeProvider>,
// AlignmentMasks
static int StringToAlignment(const std::string &alignment);
+ // Convert a tiling value into a string like "no-repeat". Public
+ // so that it can be used to generate CSS values. Takes a Tiling.
+ static std::string TilingToString(int tiling);
+
+ // Parse tiling values from something like "no-repeat" into a Tiling value.
+ static int StringToTiling(const std::string &tiling);
+
protected:
// Sets an individual color value.
void SetColor(const char* id, const SkColor& color);
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.cc b/chrome/browser/dom_ui/dom_ui_theme_source.cc
index edf9e07..d98c313 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source.cc
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.cc
@@ -102,6 +102,9 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) {
// Generate the replacements.
std::vector<string16> subst;
+ // A second list of replacements, each of which must be in $$x format,
+ // where x is a digit from 1-9.
+ std::vector<string16> subst2;
// Cache-buster for background.
subst.push_back(UTF8ToUTF16(IntToString(static_cast<int>(
@@ -117,6 +120,8 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) {
subst.push_back(SkColorToRGBAString(color_section_text));
subst.push_back(SkColorToRGBAString(color_section_link));
+ subst2.push_back(UTF8ToUTF16(GetNewTabBackgroundTilingCSS()));
+
// Get our template.
static const StringPiece new_tab_theme_css(
ResourceBundle::GetSharedInstance().GetRawDataResource(
@@ -126,11 +131,13 @@ void DOMUIThemeSource::SendNewTabCSS(int request_id) {
string16 format_string = ASCIIToUTF16(new_tab_theme_css.as_string());
const std::string css_string = UTF16ToASCII(ReplaceStringPlaceholders(
format_string, subst, NULL));
+ const std::string css_string2 = UTF16ToASCII(ReplaceStringPlaceholders(
+ ASCIIToUTF16(css_string), subst2, NULL));
// Convert to a format appropriate for sending.
scoped_refptr<RefCountedBytes> css_bytes(new RefCountedBytes);
- css_bytes->data.resize(css_string.size());
- std::copy(css_string.begin(), css_string.end(), css_bytes->data.begin());
+ css_bytes->data.resize(css_string2.size());
+ std::copy(css_string2.begin(), css_string2.end(), css_bytes->data.begin());
// Send.
SendResponse(request_id, css_bytes);
@@ -171,7 +178,15 @@ std::string DOMUIThemeSource::GetNewTabBackgroundCSS(bool bar_attached) {
return "0% " + IntToString(-offset) + "px";
else if (alignment & BrowserThemeProvider::ALIGN_RIGHT)
return "100% " + IntToString(-offset) + "px";
- return IntToString(-offset) + "px";
+ return "center " + IntToString(-offset) + "px";
}
return BrowserThemeProvider::AlignmentToString(alignment);
}
+
+std::string DOMUIThemeSource::GetNewTabBackgroundTilingCSS() {
+ int repeat_mode;
+ profile_->GetThemeProvider()->GetDisplayProperty(
+ BrowserThemeProvider::NTP_BACKGROUND_TILING, &repeat_mode);
+ return BrowserThemeProvider::TilingToString(repeat_mode);
+}
+
diff --git a/chrome/browser/dom_ui/dom_ui_theme_source.h b/chrome/browser/dom_ui/dom_ui_theme_source.h
index e31e21b..8be214f 100644
--- a/chrome/browser/dom_ui/dom_ui_theme_source.h
+++ b/chrome/browser/dom_ui/dom_ui_theme_source.h
@@ -35,6 +35,10 @@ class DOMUIThemeSource : public ChromeURLDataManager::DataSource {
// states when the bar is attached or detached.
std::string GetNewTabBackgroundCSS(bool bar_attached);
+ // How the background image on the new tab page should be tiled (see tiling
+ // masks in browser_theme_provider.h).
+ std::string GetNewTabBackgroundTilingCSS();
+
Profile* profile_;
DISALLOW_COPY_AND_ASSIGN(DOMUIThemeSource);
};
diff --git a/chrome/browser/resources/new_tab_theme.css b/chrome/browser/resources/new_tab_theme.css
index ff36f52..820649d 100644
--- a/chrome/browser/resources/new_tab_theme.css
+++ b/chrome/browser/resources/new_tab_theme.css
@@ -2,7 +2,7 @@ html {
background-image:url(chrome://theme/theme_ntp_background?$1);
background-color:$2;
background-position:$3;
- background-repeat:no-repeat;
+ background-repeat:$$1;
overflow:hidden;
}
html[bookmarkbarattached='true'] {
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 2e364e4..3d1838d 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -562,20 +562,22 @@ void BookmarkBarView::Paint(gfx::Canvas* canvas) {
tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND),
0, 0, width(), height());
- int alignment;
- if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT,
- &alignment)) {
- if (alignment & BrowserThemeProvider::ALIGN_TOP) {
- SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND);
-
- if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
- canvas->DrawBitmapInt(*ntp_background, 0, 0);
- } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
- canvas->DrawBitmapInt(*ntp_background, width() -
- ntp_background->width(), 0);
+ if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
+ int tiling = BrowserThemeProvider::NO_REPEAT;
+ tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_TILING,
+ &tiling);
+ int alignment;
+ if (tp->GetDisplayProperty(BrowserThemeProvider::NTP_BACKGROUND_ALIGNMENT,
+ &alignment)) {
+ SkBitmap* ntp_background = tp->GetBitmapNamed(
+ IDR_THEME_NTP_BACKGROUND);
+
+ if (alignment & BrowserThemeProvider::ALIGN_TOP) {
+ PaintThemeBackgroundTopAligned(
+ canvas, ntp_background, tiling, alignment);
} else {
- canvas->DrawBitmapInt(*ntp_background, width() / 2-
- ntp_background->width() / 2, 0);
+ PaintThemeBackgroundBottomAligned(
+ canvas, ntp_background, tiling, alignment);
}
}
}
@@ -635,6 +637,117 @@ void BookmarkBarView::Paint(gfx::Canvas* canvas) {
}
}
+void BookmarkBarView::PaintThemeBackgroundTopAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment) {
+
+ if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, 0, 0, width(), height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, 0, 0, width(),
+ ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background, 0, 0,
+ ntp_background->width(), ntp_background->height());
+
+ } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
+ int x_pos = width() % ntp_background->width() - ntp_background->width();
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ width() + ntp_background->width(), height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos,
+ 0, width() + ntp_background->width(), ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
+ 0, ntp_background->width(), ntp_background->height());
+
+ } else { // ALIGN == CENTER
+ int x_pos = width() > ntp_background->width() ?
+ ((width() / 2 - ntp_background->width() / 2) %
+ ntp_background->width()) - ntp_background->width() :
+ width() / 2 - ntp_background->width() / 2;
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ width() + ntp_background->width(), height());
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, 0,
+ width() + ntp_background->width(),
+ ntp_background->height());
+ else
+ canvas->TileImageInt(*ntp_background,
+ width() / 2 - ntp_background->width() / 2,
+ 0, ntp_background->width(), ntp_background->height());
+ }
+}
+
+void BookmarkBarView::PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment) {
+ int browser_height = GetParent()->GetBounds(
+ views::View::APPLY_MIRRORING_TRANSFORMATION).height();
+ int border_width = 5;
+ int y_pos = ((tiling == BrowserThemeProvider::REPEAT_X) ||
+ (tiling == BrowserThemeProvider::NO_REPEAT)) ?
+ browser_height - ntp_background->height() - height() - border_width :
+ browser_height % ntp_background->height() - height() - border_width -
+ ntp_background->height();
+
+ if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, 0, y_pos, width(),
+ 2 * height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, 0, y_pos, width(),
+ ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background, 0, y_pos,
+ ntp_background->width(),
+ 2 * height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background, 0, y_pos, ntp_background->width(),
+ ntp_background->height());
+
+ } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
+ int x_pos = width() % ntp_background->width() - ntp_background->width();
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ width() + ntp_background->width(),
+ 2 * height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ width() + ntp_background->width(), ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
+ y_pos, ntp_background->width(),
+ 2 * height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background, width() - ntp_background->width(),
+ y_pos, ntp_background->width(), ntp_background->height());
+
+ } else { // ALIGN == CENTER
+ int x_pos = width() > ntp_background->width() ?
+ ((width() / 2 - ntp_background->width() / 2) %
+ ntp_background->width()) - ntp_background->width() :
+ width() / 2 - ntp_background->width() / 2;
+ if (tiling == BrowserThemeProvider::REPEAT)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ width() + ntp_background->width(),
+ 2 * height() + ntp_background->height() + 5);
+ else if (tiling == BrowserThemeProvider::REPEAT_X)
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos,
+ width() + ntp_background->width(), ntp_background->height());
+ else if (tiling == BrowserThemeProvider::REPEAT_Y)
+ canvas->TileImageInt(*ntp_background,
+ width() / 2 - ntp_background->width() / 2,
+ y_pos, ntp_background->width(),
+ 2 * height() + ntp_background->height() + 5);
+ else
+ canvas->TileImageInt(*ntp_background,
+ width() / 2 - ntp_background->width() / 2,
+ y_pos, ntp_background->width(), ntp_background->height());
+ }
+}
+
void BookmarkBarView::PaintChildren(gfx::Canvas* canvas) {
View::PaintChildren(canvas);
diff --git a/chrome/browser/views/bookmark_bar_view.h b/chrome/browser/views/bookmark_bar_view.h
index 53fd699..39fc721 100644
--- a/chrome/browser/views/bookmark_bar_view.h
+++ b/chrome/browser/views/bookmark_bar_view.h
@@ -180,6 +180,12 @@ class BookmarkBarView : public views::View,
class ButtonSeparatorView;
struct DropInfo;
+ // Paint the theme background with the proper alignment.
+ void PaintThemeBackgroundTopAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment);
+ void PaintThemeBackgroundBottomAligned(gfx::Canvas* canvas,
+ SkBitmap* ntp_background, int tiling, int alignment);
+
// Task that invokes ShowDropFolderForNode when run. ShowFolderDropMenuTask
// deletes itself once run.
class ShowFolderDropMenuTask : public Task {