summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 01:58:01 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-07 01:58:01 +0000
commitb846afe7b1e97e4d245f7df153813c55ae46f74b (patch)
tree7e6ae6dda666d01ad1898a7d593bf9c0e606f5ca
parentd2192e3d5b90b631abf219079d93c3453f852865 (diff)
downloadchromium_src-b846afe7b1e97e4d245f7df153813c55ae46f74b.zip
chromium_src-b846afe7b1e97e4d245f7df153813c55ae46f74b.tar.gz
chromium_src-b846afe7b1e97e4d245f7df153813c55ae46f74b.tar.bz2
GTK: Draw bottom-aligned ntp themes on floating bookmark bar.
This is a simplified version of the windows code. There will be a follow-up patch to switch windows over to using this as well. I ran into some trouble calculating the correct size of the tab contents. Punting on that for now, filed http://crbug.com/23907 BUG=22836 TEST=Tested on klassen, candies, karim rashid, tiesto, ratchet and clank, and jeff coons themes. Review URL: http://codereview.chromium.org/255086 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@28215 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/gtk/bookmark_bar_gtk.cc63
-rw-r--r--chrome/browser/ntp_background_util.cc79
-rw-r--r--chrome/browser/ntp_background_util.h29
-rwxr-xr-xchrome/chrome.gyp2
4 files changed, 138 insertions, 35 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc
index 4197b21..33fa70e 100644
--- a/chrome/browser/gtk/bookmark_bar_gtk.cc
+++ b/chrome/browser/gtk/bookmark_bar_gtk.cc
@@ -6,6 +6,7 @@
#include <vector>
+#include "app/gfx/canvas_paint.h"
#include "app/gfx/text_elider.h"
#include "app/gtk_dnd_util.h"
#include "app/l10n_util.h"
@@ -30,8 +31,10 @@
#include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
#include "chrome/browser/gtk/view_id_util.h"
#include "chrome/browser/metrics/user_metrics.h"
+#include "chrome/browser/ntp_background_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/tab_contents/tab_contents.h"
+#include "chrome/browser/tab_contents/tab_contents_view.h"
#include "chrome/common/gtk_util.h"
#include "chrome/common/notification_service.h"
#include "chrome/common/pref_names.h"
@@ -1017,12 +1020,12 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget,
if (theme_provider->UseGtkTheme() && !bar->floating_)
return FALSE;
- cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
- cairo_rectangle(cr, event->area.x, event->area.y,
- event->area.width, event->area.height);
- cairo_clip(cr);
-
if (!bar->floating_) {
+ cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
+ cairo_rectangle(cr, event->area.x, event->area.y,
+ event->area.width, event->area.height);
+ cairo_clip(cr);
+
// Paint the background theme image.
gfx::Point tabstrip_origin =
bar->tabstrip_origin_provider_->GetTabStripOriginForWidget(widget);
@@ -1038,40 +1041,30 @@ gboolean BookmarkBarGtk::OnEventBoxExpose(GtkWidget* widget,
event->area.x + event->area.width - tabstrip_origin.x(),
event->area.y + event->area.height - tabstrip_origin.y());
cairo_fill(cr);
- } else {
- // Paint the NTP background. First set the background color.
- GdkColor bg_color = theme_provider->UseGtkTheme() ? gfx::kGdkWhite :
- theme_provider->GetGdkColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND);
- double bg_color_rgb[] = {
- static_cast<double>(bg_color.red / 257) / 255.0,
- static_cast<double>(bg_color.green / 257) / 255.0,
- static_cast<double>(bg_color.blue / 257) / 255.0, };
- cairo_set_source_rgb(cr, bg_color_rgb[0], bg_color_rgb[1], bg_color_rgb[2]);
- cairo_rectangle(cr,
- event->area.x,
- event->area.y,
- event->area.width,
- event->area.height);
- cairo_fill(cr);
- // Now paint the image, if it exists.
- // TODO(estade): handle different alignments.
- if (theme_provider->HasCustomImage(IDR_THEME_NTP_BACKGROUND)) {
- CairoCachedSurface* background = theme_provider->GetSurfaceNamed(
- IDR_THEME_NTP_BACKGROUND, widget);
- background->SetSource(cr, widget->allocation.x, widget->allocation.y);
- cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
- cairo_rectangle(cr,
- event->area.x,
- event->area.y,
- event->area.width,
- event->area.height);
- cairo_fill(cr);
+ cairo_destroy(cr);
+ } else {
+ gfx::Size tab_contents_size;
+ Browser* browser = bar->browser_;
+ if (!browser) {
+ NOTREACHED();
+ return FALSE;
+ }
+ TabContents* tab_contents = browser->GetSelectedTabContents();
+ if (!tab_contents) {
+ NOTREACHED();
+ return FALSE;
}
+ if (!tab_contents->view()) {
+ NOTREACHED();
+ return FALSE;
+ }
+ tab_contents_size = tab_contents->view()->GetContainerSize();
+ gfx::CanvasPaint canvas(event, true);
+ NtpBackgroundUtil::PaintBackgroundDetachedMode(theme_provider, &canvas,
+ gfx::Rect(widget->allocation), tab_contents_size.height());
}
- cairo_destroy(cr);
-
return FALSE; // Propagate expose to children.
}
diff --git a/chrome/browser/ntp_background_util.cc b/chrome/browser/ntp_background_util.cc
new file mode 100644
index 0000000..1b02632
--- /dev/null
+++ b/chrome/browser/ntp_background_util.cc
@@ -0,0 +1,79 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ntp_background_util.h"
+
+#include "app/gfx/canvas.h"
+#include "base/gfx/rect.h"
+#include "base/logging.h"
+#include "chrome/browser/browser_theme_provider.h"
+#include "grit/theme_resources.h"
+#include "skia/ext/skia_utils.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+
+namespace {
+
+void PaintThemeBackground(
+ gfx::Canvas* canvas, SkBitmap* 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.width() + ntp_background->width();
+ int height = area.height() + ntp_background->height();
+
+ if (alignment & BrowserThemeProvider::ALIGN_BOTTOM)
+ y_pos += area.height() + tab_contents_height - ntp_background->height();
+
+ if (alignment & BrowserThemeProvider::ALIGN_RIGHT) {
+ x_pos += area.width() - ntp_background->width();
+ } else if (alignment & BrowserThemeProvider::ALIGN_LEFT) {
+ // no op
+ } else { // ALIGN_CENTER
+ x_pos += area.width() / 2 - ntp_background->width() / 2;
+ }
+
+ if (tiling != BrowserThemeProvider::REPEAT &&
+ tiling != BrowserThemeProvider::REPEAT_X) {
+ width = ntp_background->width();
+ } else if (x_pos > 0) {
+ x_pos = x_pos % ntp_background->width() - ntp_background->width();
+ }
+
+ if (tiling != BrowserThemeProvider::REPEAT &&
+ tiling != BrowserThemeProvider::REPEAT_Y) {
+ height = ntp_background->height();
+ } else if (y_pos > 0) {
+ y_pos = y_pos % ntp_background->height() - ntp_background->height();
+ }
+
+ x_pos += area.x();
+ y_pos += area.y();
+
+ canvas->TileImageInt(*ntp_background, x_pos, y_pos, width, height);
+}
+
+} // namespace
+
+// static
+void NtpBackgroundUtil::PaintBackgroundDetachedMode(
+ ThemeProvider* tp, gfx::Canvas* canvas, const gfx::Rect& area,
+ int tab_contents_height) {
+ // Draw the background to match the new tab page.
+ canvas->FillRectInt(tp->GetColor(BrowserThemeProvider::COLOR_NTP_BACKGROUND),
+ area.x(), area.y(), area.width(), area.height());
+
+ 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);
+
+ PaintThemeBackground(
+ canvas, ntp_background, tiling, alignment, area, tab_contents_height);
+ }
+ }
+}
diff --git a/chrome/browser/ntp_background_util.h b/chrome/browser/ntp_background_util.h
new file mode 100644
index 0000000..9d2d656
--- /dev/null
+++ b/chrome/browser/ntp_background_util.h
@@ -0,0 +1,29 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_NTP_BACKGROUND_UTIL_H_
+#define CHROME_BROWSER_NTP_BACKGROUND_UTIL_H_
+
+class ThemeProvider;
+
+namespace gfx {
+class Canvas;
+class Rect;
+}
+
+class NtpBackgroundUtil {
+ public:
+ // Paints the NTP background on |canvas|. |area| is the area of the canvas
+ // that gets painted and also serves as the origin of the image (for top-
+ // aligned images). |tab_contents_height| is necessary for correctly painting
+ // bottom-aligned images since then the origin is the bottom of the web page.
+ static void PaintBackgroundDetachedMode(
+ ThemeProvider* tp, gfx::Canvas* canvas,
+ const gfx::Rect& area, int tab_contents_height);
+
+ private:
+ NtpBackgroundUtil() {}
+};
+
+#endif // CHROME_BROWSER_NTP_BACKGROUND_UTIL_H_
diff --git a/chrome/chrome.gyp b/chrome/chrome.gyp
index 3a4bfd1..5e97e00 100755
--- a/chrome/chrome.gyp
+++ b/chrome/chrome.gyp
@@ -1696,6 +1696,8 @@
'browser/net/url_request_slow_http_job.h',
'browser/net/url_request_tracking.cc',
'browser/net/url_request_tracking.h',
+ 'browser/ntp_background_util.cc',
+ 'browser/ntp_background_util.h',
'browser/omnibox_search_hint.cc',
'browser/omnibox_search_hint.h',
'browser/options_page_base.cc',