diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-18 03:23:33 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-07-18 03:23:33 +0000 |
commit | 1df50c8de4ca23b55ac99e26497fe8ba5864b6f3 (patch) | |
tree | 572ce80a9d0d7270222b45ebd2ab801a90fc428d /chrome/browser/views/bookmark_bar_view.cc | |
parent | c8ced031ff61f75ebe05b3ac4d2a27ab8936fc18 (diff) | |
download | chromium_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/views/bookmark_bar_view.cc')
-rw-r--r-- | chrome/browser/views/bookmark_bar_view.cc | 139 |
1 files changed, 126 insertions, 13 deletions
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); |