| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ntp_background_util.h" | 5 #include "chrome/browser/ntp_background_util.h" |
| 6 | 6 |
| 7 #include <cmath> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "chrome/browser/themes/theme_service.h" | 10 #include "chrome/browser/themes/theme_service.h" |
| 9 #include "grit/theme_resources.h" | 11 #include "grit/theme_resources.h" |
| 10 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 11 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 12 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/skia_util.h" | 15 #include "ui/gfx/skia_util.h" |
| 14 | 16 |
| 15 namespace { | 17 namespace { |
| 16 | 18 |
| 17 void PaintThemeBackground( | 19 void PaintThemeBackground( |
| 18 gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, | 20 gfx::Canvas* canvas, SkBitmap* ntp_background, int tiling, int alignment, |
| 19 const gfx::Rect& area, int tab_contents_height) { | 21 const gfx::Rect& area, int tab_contents_height) { |
| 20 int x_pos = 0; | 22 int x_pos = 0; |
| 21 int y_pos = 0; | 23 int y_pos = 0; |
| 22 int width = area.width() + ntp_background->width(); | 24 int width = area.width() + ntp_background->width(); |
| 23 int height = area.height() + ntp_background->height(); | 25 int height = area.height() + ntp_background->height(); |
| 24 | 26 |
| 25 if (alignment & ThemeService::ALIGN_BOTTOM) | 27 if (alignment & ThemeService::ALIGN_BOTTOM) { |
| 26 y_pos += area.height() + tab_contents_height - ntp_background->height(); | 28 y_pos += area.height() + tab_contents_height - ntp_background->height(); |
| 29 } else if (alignment & ThemeService::ALIGN_TOP) { |
| 30 // no op |
| 31 } else { // ALIGN_CENTER |
| 32 y_pos += std::floor(area.height() + tab_contents_height / 2.0 - |
| 33 ntp_background->height() / 2.0 + 0.5); |
| 34 } |
| 27 | 35 |
| 28 if (alignment & ThemeService::ALIGN_RIGHT) { | 36 if (alignment & ThemeService::ALIGN_RIGHT) { |
| 29 x_pos += area.width() - ntp_background->width(); | 37 x_pos += area.width() - ntp_background->width(); |
| 30 } else if (alignment & ThemeService::ALIGN_LEFT) { | 38 } else if (alignment & ThemeService::ALIGN_LEFT) { |
| 31 // no op | 39 // no op |
| 32 } else { // ALIGN_CENTER | 40 } else { // ALIGN_CENTER |
| 33 x_pos += area.width() / 2 - ntp_background->width() / 2; | 41 x_pos += |
| 42 std::floor(area.width() / 2.0 - ntp_background->width() / 2.0 + 0.5); |
| 34 } | 43 } |
| 35 | 44 |
| 36 if (tiling != ThemeService::REPEAT && | 45 if (tiling != ThemeService::REPEAT && |
| 37 tiling != ThemeService::REPEAT_X) { | 46 tiling != ThemeService::REPEAT_X) { |
| 38 width = ntp_background->width(); | 47 width = ntp_background->width(); |
| 39 } else if (x_pos > 0) { | 48 } else if (x_pos > 0) { |
| 40 x_pos = x_pos % ntp_background->width() - ntp_background->width(); | 49 x_pos = x_pos % ntp_background->width() - ntp_background->width(); |
| 41 } | 50 } |
| 42 | 51 |
| 43 if (tiling != ThemeService::REPEAT && | 52 if (tiling != ThemeService::REPEAT && |
| (...skipping 17 matching lines...) Expand all Loading... |
| 61 const gfx::Rect& area, | 70 const gfx::Rect& area, |
| 62 int tab_contents_height) { | 71 int tab_contents_height) { |
| 63 // Draw the background to match the new tab page. | 72 // Draw the background to match the new tab page. |
| 64 canvas->FillRect(area, tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND)); | 73 canvas->FillRect(area, tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND)); |
| 65 | 74 |
| 66 if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { | 75 if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) { |
| 67 int tiling = ThemeService::NO_REPEAT; | 76 int tiling = ThemeService::NO_REPEAT; |
| 68 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_TILING, &tiling); | 77 tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_TILING, &tiling); |
| 69 int alignment; | 78 int alignment; |
| 70 if (tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, | 79 if (tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_ALIGNMENT, |
| 71 &alignment)) { | 80 &alignment)) { |
| 72 SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND); | 81 SkBitmap* ntp_background = tp->GetBitmapNamed(IDR_THEME_NTP_BACKGROUND); |
| 73 | 82 |
| 74 PaintThemeBackground( | 83 PaintThemeBackground( |
| 75 canvas, ntp_background, tiling, alignment, area, tab_contents_height); | 84 canvas, ntp_background, tiling, alignment, area, tab_contents_height); |
| 76 } | 85 } |
| 77 } | 86 } |
| 78 } | 87 } |
| OLD | NEW |