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

Unified Diff: chrome/browser/views/bookmark_bar_view.cc

Issue 149741: Allow the tiling of theme background images on the NTP.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/views/bookmark_bar_view.cc
===================================================================
--- chrome/browser/views/bookmark_bar_view.cc (revision 20990)
+++ chrome/browser/views/bookmark_bar_view.cc (working copy)
@@ -562,20 +562,22 @@
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 (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_LEFT) {
- canvas->DrawBitmapInt(*ntp_background, 0, 0);
- } else if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
- canvas->DrawBitmapInt(*ntp_background, width() -
- ntp_background->width(), 0);
+ 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::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);
« no previous file with comments | « chrome/browser/views/bookmark_bar_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698