summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/ntp_background_util.cc
diff options
context:
space:
mode:
authorkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 02:40:20 +0000
committerkuan@chromium.org <kuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-11-02 02:40:20 +0000
commitbc4c67e9e7f2377b797f18a749388835778ef89e (patch)
tree99b3dcc6a9cea2cb6335def622d41a19f8f5aecc /chrome/browser/ui/ntp_background_util.cc
parentc4f9e9ffc0ce9127e9e699f64754ee842407fcb0 (diff)
downloadchromium_src-bc4c67e9e7f2377b797f18a749388835778ef89e.zip
chromium_src-bc4c67e9e7f2377b797f18a749388835778ef89e.tar.gz
chromium_src-bc4c67e9e7f2377b797f18a749388835778ef89e.tar.bz2
alternate ntp: remove instant-extended-specific themes implementation from ntp
BUG=158552 TEST=verify per bug rpt Review URL: https://chromiumcodereview.appspot.com/11293029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@165592 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/ntp_background_util.cc')
-rw-r--r--chrome/browser/ui/ntp_background_util.cc115
1 files changed, 23 insertions, 92 deletions
diff --git a/chrome/browser/ui/ntp_background_util.cc b/chrome/browser/ui/ntp_background_util.cc
index 809f676..4e30af4 100644
--- a/chrome/browser/ui/ntp_background_util.cc
+++ b/chrome/browser/ui/ntp_background_util.cc
@@ -4,69 +4,42 @@
#include "chrome/browser/ui/ntp_background_util.h"
+#include <cmath>
+
#include "base/logging.h"
-#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/themes/theme_service.h"
-#include "chrome/browser/themes/theme_service_factory.h"
-#include "chrome/browser/ui/search/search.h"
-#include "chrome/browser/ui/search/search_ui.h"
#include "grit/theme_resources.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/rect.h"
-#include "ui/gfx/safe_integer_conversions.h"
#include "ui/gfx/skia_util.h"
namespace {
-int Round(float value) {
- return gfx::ToRoundedInt(value + 0.5);
-}
-
void PaintThemeBackground(
- gfx::Canvas* canvas,
- gfx::ImageSkia* ntp_background,
- int tiling,
- int alignment,
- const gfx::Rect& area_in_canvas,
- int tab_contents_height,
- const gfx::Size& browser_client_area_size,
- const gfx::Point& area_origin_in_browser_client_area) {
+ gfx::Canvas* canvas, gfx::ImageSkia* ntp_background, int tiling,
+ int alignment, const gfx::Rect& area, int tab_contents_height) {
int x_pos = 0;
int y_pos = 0;
- int width = area_in_canvas.width() + ntp_background->width();
- int height = area_in_canvas.height() + ntp_background->height();
+ int width = area.width() + ntp_background->width();
+ int height = area.height() + ntp_background->height();
if (alignment & ThemeService::ALIGN_BOTTOM) {
- y_pos += area_in_canvas.height() + tab_contents_height -
- ntp_background->height();
+ y_pos += area.height() + tab_contents_height - ntp_background->height();
} else if (alignment & ThemeService::ALIGN_TOP) {
// no op
} else { // ALIGN_CENTER
- // If there is no |browser_client_area_size|, the theme image only fills up
- // |tab_contents_height|, else it fills up |browser_client_area_size|.
- if (browser_client_area_size.IsEmpty()) {
- y_pos += Round(area_in_canvas.height() + tab_contents_height / 2.0 -
- ntp_background->height() / 2.0);
- } else {
- y_pos += NtpBackgroundUtil::GetPlacementOfCenterAlignedImage(
- browser_client_area_size.height(), ntp_background->height());
- y_pos -= area_origin_in_browser_client_area.y();
- }
+ y_pos += std::floor(area.height() + tab_contents_height / 2.0 -
+ ntp_background->height() / 2.0 + 0.5);
}
- // Use |browser_client_area_size| for width if it's available, else use
- // |area_in_canvas|'s.
- int width_to_use = browser_client_area_size.IsEmpty() ?
- area_in_canvas.width() : browser_client_area_size.width();
if (alignment & ThemeService::ALIGN_RIGHT) {
- x_pos += width_to_use - ntp_background->width();
+ x_pos += area.width() - ntp_background->width();
} else if (alignment & ThemeService::ALIGN_LEFT) {
// no op
} else { // ALIGN_CENTER
- x_pos += NtpBackgroundUtil::GetPlacementOfCenterAlignedImage(
- width_to_use, ntp_background->width());
- x_pos -= area_origin_in_browser_client_area.x();
+ x_pos +=
+ std::floor(area.width() / 2.0 - ntp_background->width() / 2.0 + 0.5);
}
if (tiling != ThemeService::REPEAT &&
@@ -83,30 +56,22 @@ void PaintThemeBackground(
y_pos = y_pos % ntp_background->height() - ntp_background->height();
}
- x_pos += area_in_canvas.x();
- y_pos += area_in_canvas.y();
+ x_pos += area.x();
+ y_pos += area.y();
- // If |x_pos| and/or |y_pos| is/are negative, and/or |width| and/or |height|
- // is/are bigger than size of |area_in_canvas|, the image could be painted
- // outside of |area_in_canvas| in |canvas|. To make sure we only paint into
- // |area_in_canvas|, clip the area.
- canvas->Save();
- canvas->ClipRect(area_in_canvas);
canvas->TileImageInt(*ntp_background, x_pos, y_pos, width, height);
- canvas->Restore();
}
-void PaintBackground(Profile* profile,
- gfx::Canvas* canvas,
- const gfx::Rect& area_in_canvas,
- int tab_contents_height,
- const gfx::Size& browser_client_area_size,
- const gfx::Point& area_origin_in_browser_client_area) {
+} // namespace
+
+// static
+void NtpBackgroundUtil::PaintBackgroundDetachedMode(ui::ThemeProvider* tp,
+ gfx::Canvas* canvas,
+ const gfx::Rect& area,
+ int tab_contents_height) {
// Draw the background to match the new tab page.
- canvas->FillRect(area_in_canvas,
- chrome::search::GetNTPBackgroundColor(profile));
+ canvas->FillRect(area, tp->GetColor(ThemeService::COLOR_NTP_BACKGROUND));
- const ui::ThemeProvider* tp = ThemeServiceFactory::GetForProfile(profile);
if (tp->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
int tiling = ThemeService::NO_REPEAT;
tp->GetDisplayProperty(ThemeService::NTP_BACKGROUND_TILING, &tiling);
@@ -117,41 +82,7 @@ void PaintBackground(Profile* profile,
tp->GetImageSkiaNamed(IDR_THEME_NTP_BACKGROUND);
PaintThemeBackground(
- canvas, ntp_background, tiling, alignment, area_in_canvas,
- tab_contents_height, browser_client_area_size,
- area_origin_in_browser_client_area);
+ canvas, ntp_background, tiling, alignment, area, tab_contents_height);
}
}
}
-
-} // namespace
-
-// static
-void NtpBackgroundUtil::PaintBackgroundDetachedMode(
- Profile* profile,
- gfx::Canvas* canvas,
- const gfx::Rect& area,
- int tab_contents_height) {
- PaintBackground(profile, canvas, area, tab_contents_height, gfx::Size(),
- gfx::Point());
-}
-
-// static
-void NtpBackgroundUtil::PaintBackgroundForBrowserClientArea(
- Profile* profile,
- gfx::Canvas* canvas,
- const gfx::Rect& area_in_canvas,
- const gfx::Size& browser_client_area_size,
- const gfx::Rect& area_in_browser_client_area) {
- PaintBackground(profile, canvas, area_in_canvas,
- browser_client_area_size.height() -
- area_in_browser_client_area.bottom(),
- browser_client_area_size,
- area_in_browser_client_area.origin());
-}
-
-// static
-int NtpBackgroundUtil::GetPlacementOfCenterAlignedImage(int view_dimension,
- int image_dimension) {
- return Round(view_dimension / 2.0 - image_dimension / 2.0);
-}