diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-13 00:51:48 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-13 00:51:48 +0000 |
commit | 16adb28574253284c920079a6800a7cc192c8dc4 (patch) | |
tree | a480ca244e37ba0143b1f171bb621c2129f299f8 /chrome | |
parent | caafdbb72b9bb42aa0d40a25b4a47e6450246391 (diff) | |
download | chromium_src-16adb28574253284c920079a6800a7cc192c8dc4.zip chromium_src-16adb28574253284c920079a6800a7cc192c8dc4.tar.gz chromium_src-16adb28574253284c920079a6800a7cc192c8dc4.tar.bz2 |
Make findbar paint themed image.
Also, fixed drawing of background images that are not 1 pixel wide. (The code for this is somewhat speculative as there is no way of testing it at the moment, but for now it should still at least look correct.)
If you open the findbar while the bookmark bar is opened and then close the bookmark bar, the findbar painting is a little messed up in that it still thinks it's farther away from the tabstrip than it really is. The solution (unfortunately) is to continuously repaint the findbar as it is closing. Since this is glitch is hardly noticeable, I'm putting off fixing it.
TEST=findbar should look more integrated with bookmark bar, toolbar.
BUG=none
Review URL: http://codereview.chromium.org/125084
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@18339 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/browser/gtk/bookmark_bar_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_toolbar_gtk.cc | 8 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_window_factory_gtk.cc | 2 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.cc | 80 | ||||
-rw-r--r-- | chrome/browser/gtk/find_bar_gtk.h | 12 |
5 files changed, 81 insertions, 29 deletions
diff --git a/chrome/browser/gtk/bookmark_bar_gtk.cc b/chrome/browser/gtk/bookmark_bar_gtk.cc index 0e03a9c..181e4a2 100644 --- a/chrome/browser/gtk/bookmark_bar_gtk.cc +++ b/chrome/browser/gtk/bookmark_bar_gtk.cc @@ -799,9 +799,11 @@ gboolean BookmarkBarGtk::OnHBoxExpose(GtkWidget* widget, event->area.width, event->area.height); cairo_clip(cr); bar->InitBackground(); - int y = bar->window_->tabstrip()->GetTabStripOriginForWidget(widget).y(); - bar->background_ninebox_->RenderTopCenterStrip(cr, event->area.x, - y, event->area.width); + gfx::Point tabstrip_origin = + bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); + bar->background_ninebox_->RenderTopCenterStrip( + cr, tabstrip_origin.x(), tabstrip_origin.y(), + event->area.x + event->area.width - tabstrip_origin.x()); cairo_destroy(cr); return FALSE; // Propagate expose to children. diff --git a/chrome/browser/gtk/browser_toolbar_gtk.cc b/chrome/browser/gtk/browser_toolbar_gtk.cc index caaa8f2..13c9dbc 100644 --- a/chrome/browser/gtk/browser_toolbar_gtk.cc +++ b/chrome/browser/gtk/browser_toolbar_gtk.cc @@ -355,9 +355,11 @@ gboolean BrowserToolbarGtk::OnToolbarExpose(GtkWidget* widget, // The toolbar is supposed to blend in with the active tab, so we have to pass // coordinates for the IDR_THEME_TOOLBAR bitmap relative to the top of the // tab strip. - int y = toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget).y(); - toolbar->background_ninebox_->RenderTopCenterStrip(cr, e->area.x, - y, e->area.width); + gfx::Point tabstrip_origin = + toolbar->window_->tabstrip()->GetTabStripOriginForWidget(widget); + toolbar->background_ninebox_->RenderTopCenterStrip( + cr, tabstrip_origin.x(), tabstrip_origin.y(), + e->area.x + e->area.width - tabstrip_origin.x()); cairo_destroy(cr); return FALSE; // Allow subwidgets to paint. diff --git a/chrome/browser/gtk/browser_window_factory_gtk.cc b/chrome/browser/gtk/browser_window_factory_gtk.cc index 4cd7d2d5d..8291fb9 100644 --- a/chrome/browser/gtk/browser_window_factory_gtk.cc +++ b/chrome/browser/gtk/browser_window_factory_gtk.cc @@ -13,5 +13,5 @@ BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { } FindBar* BrowserWindow::CreateFindBar(Browser* browser) { - return new FindBarGtk(static_cast<BrowserWindowGtk*>(browser->window())); + return new FindBarGtk(browser); } diff --git a/chrome/browser/gtk/find_bar_gtk.cc b/chrome/browser/gtk/find_bar_gtk.cc index be174b5..7ff1e24 100644 --- a/chrome/browser/gtk/find_bar_gtk.cc +++ b/chrome/browser/gtk/find_bar_gtk.cc @@ -9,12 +9,15 @@ #include "app/l10n_util.h" #include "base/gfx/gtk_util.h" #include "base/string_util.h" +#include "chrome/browser/browser.h" +#include "chrome/browser/profile.h" #include "chrome/browser/find_bar_controller.h" #include "chrome/browser/gtk/browser_window_gtk.h" #include "chrome/browser/gtk/custom_button.h" #include "chrome/browser/gtk/nine_box.h" #include "chrome/browser/gtk/slide_animator_gtk.h" #include "chrome/browser/gtk/tab_contents_container_gtk.h" +#include "chrome/browser/gtk/tabs/tab_strip_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/gtk_util.h" #include "grit/generated_resources.h" @@ -40,41 +43,52 @@ const int kFindBarHeight = 32; // The width of the text entry field. const int kTextEntryWidth = 220; -// Get the ninebox that draws the background of |container_|. It is also used -// to change the shape of |container_|. The pointer is shared by all instances -// of FindBarGtk. -const NineBox* GetDialogBackground() { - static NineBox* dialog_background = NULL; - if (!dialog_background) { - dialog_background = new NineBox( +// Give the findbar dialog its unique shape. +void SetDialogShape(GtkWidget* widget) { + static NineBox* dialog_shape = NULL; + if (!dialog_shape) { + dialog_shape = new NineBox( IDR_FIND_DLG_LEFT_BACKGROUND, IDR_FIND_DLG_MIDDLE_BACKGROUND, IDR_FIND_DLG_RIGHT_BACKGROUND, NULL, NULL, NULL, NULL, NULL, NULL); - dialog_background->ChangeWhiteToTransparent(); + dialog_shape->ChangeWhiteToTransparent(); } - return dialog_background; + dialog_shape->ContourWidget(widget); } -// Used to handle custom painting of |container_|. -gboolean OnExpose(GtkWidget* widget, GdkEventExpose* e, gpointer userdata) { - GetDialogBackground()->RenderToWidget(widget); - GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget)); - if (child) - gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e); - return TRUE; +// Return a ninebox that will paint the border of the findbar dialog. This is +// shared across all instances of the findbar. Do not free the returned pointer. +const NineBox* GetDialogBorder() { + static NineBox* dialog_border = NULL; + if (!dialog_border) { + dialog_border = new NineBox( + IDR_FIND_DIALOG_LEFT, + IDR_FIND_DIALOG_MIDDLE, + IDR_FIND_DIALOG_RIGHT, + NULL, NULL, NULL, NULL, NULL, NULL); + } + + return dialog_border; } } // namespace -FindBarGtk::FindBarGtk(BrowserWindowGtk* browser) - : container_shaped_(false), +FindBarGtk::FindBarGtk(Browser* browser) + : browser_(browser), + window_(static_cast<BrowserWindowGtk*>(browser->window())), + container_shaped_(false), ignore_changed_signal_(false) { InitWidgets(); + dialog_background_.reset(new NineBox(browser->profile()->GetThemeProvider(), + 0, IDR_THEME_TOOLBAR, 0, + 0, 0, 0, 0, 0, 0)); + + // Insert the widget into the browser gtk hierarchy. - browser->AddFindBar(this); + window_->AddFindBar(this); // Hook up signals after the widget has been added to the hierarchy so the // widget will be realized. @@ -98,7 +112,7 @@ FindBarGtk::FindBarGtk(BrowserWindowGtk* browser) g_signal_connect(container_, "size-allocate", G_CALLBACK(OnContainerSizeAllocate), this); g_signal_connect(container_, "expose-event", - G_CALLBACK(OnExpose), NULL); + G_CALLBACK(OnExpose), this); } FindBarGtk::~FindBarGtk() { @@ -451,12 +465,36 @@ void FindBarGtk::OnFixedSizeAllocate(GtkWidget* fixed, } } +// Used to handle custom painting of |container_|. +gboolean FindBarGtk::OnExpose(GtkWidget* widget, GdkEventExpose* e, + FindBarGtk* bar) { + // Draw the background theme image. + cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); + cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height); + cairo_clip(cr); + gfx::Point tabstrip_origin = + bar->window_->tabstrip()->GetTabStripOriginForWidget(widget); + bar->dialog_background_->RenderTopCenterStrip( + cr, tabstrip_origin.x(), tabstrip_origin.y(), + e->area.x + e->area.width - tabstrip_origin.x()); + cairo_destroy(cr); + + // Draw the border. + GetDialogBorder()->RenderToWidget(widget); + + // Propagate to the container's child. + GtkWidget* child = gtk_bin_get_child(GTK_BIN(widget)); + if (child) + gtk_container_propagate_expose(GTK_CONTAINER(widget), child, e); + return TRUE; +} + // static void FindBarGtk::OnContainerSizeAllocate(GtkWidget* container, GtkAllocation* allocation, FindBarGtk* findbar) { if (!findbar->container_shaped_) { - GetDialogBackground()->ContourWidget(container); + SetDialogShape(container); findbar->container_shaped_ = true; } } diff --git a/chrome/browser/gtk/find_bar_gtk.h b/chrome/browser/gtk/find_bar_gtk.h index 8b31b61..57b445f 100644 --- a/chrome/browser/gtk/find_bar_gtk.h +++ b/chrome/browser/gtk/find_bar_gtk.h @@ -13,9 +13,11 @@ #include "chrome/browser/gtk/focus_store_gtk.h" #include "chrome/common/owned_widget_gtk.h" +class Browser; class BrowserWindowGtk; class CustomDrawButton; class FindBarController; +class NineBox; class SlideAnimatorGtk; class TabContentsContainerGtk; @@ -24,7 +26,7 @@ class TabContentsContainerGtk; class FindBarGtk : public FindBar, public FindBarTesting { public: - explicit FindBarGtk(BrowserWindowGtk* browser); + explicit FindBarGtk(Browser* browser); virtual ~FindBarGtk(); GtkWidget* widget() const { return fixed_.get(); } @@ -100,12 +102,18 @@ class FindBarGtk : public FindBar, GtkAllocation* allocation, FindBarGtk* findbar); + static gboolean OnExpose(GtkWidget* widget, GdkEventExpose* event, + FindBarGtk* bar); + // These are both used for focus management. static gboolean OnFocus(GtkWidget* text_entry, GtkDirectionType focus, FindBarGtk* find_bar); static gboolean OnButtonPress(GtkWidget* text_entry, GdkEventButton* e, FindBarGtk* find_bar); + Browser* browser_; + BrowserWindowGtk* window_; + // GtkFixed containing the find bar widgets. OwnedWidgetGtk fixed_; @@ -149,6 +157,8 @@ class FindBarGtk : public FindBar, // If true, the change signal for the text entry is ignored. bool ignore_changed_signal_; + scoped_ptr<NineBox> dialog_background_; + DISALLOW_COPY_AND_ASSIGN(FindBarGtk); }; |