diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 02:33:51 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-06-25 02:33:51 +0000 |
commit | d07d1efa23c18b1e81e989439539a0e8483af26a (patch) | |
tree | abded7e00d11a021f1e375edaec8389397478977 /chrome/browser/gtk | |
parent | 72ea2411d2b872e9c620854265653b2d39968c18 (diff) | |
download | chromium_src-d07d1efa23c18b1e81e989439539a0e8483af26a.zip chromium_src-d07d1efa23c18b1e81e989439539a0e8483af26a.tar.gz chromium_src-d07d1efa23c18b1e81e989439539a0e8483af26a.tar.bz2 |
Paint the spy guy.
BUG=none
TEST=go incognito, toggle custom frame drawing
Review URL: http://codereview.chromium.org/146122
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@19220 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.cc | 80 | ||||
-rw-r--r-- | chrome/browser/gtk/browser_titlebar.h | 3 | ||||
-rwxr-xr-x | chrome/browser/gtk/tabs/tab_strip_gtk.cc | 3 | ||||
-rw-r--r-- | chrome/browser/gtk/tabs/tab_strip_gtk.h | 10 |
4 files changed, 83 insertions, 13 deletions
diff --git a/chrome/browser/gtk/browser_titlebar.cc b/chrome/browser/gtk/browser_titlebar.cc index eab9a7e..7ebf916 100644 --- a/chrome/browser/gtk/browser_titlebar.cc +++ b/chrome/browser/gtk/browser_titlebar.cc @@ -6,6 +6,7 @@ #include <gtk/gtk.h> +#include "app/resource_bundle.h" #include "app/l10n_util.h" #include "chrome/app/chrome_dll_resource.h" #include "chrome/browser/browser.h" @@ -28,6 +29,18 @@ const int kTitlebarHeight = 14; // A linux specific menu item for toggling window decorations. const int kShowWindowDecorationsCommand = 200; +// The following OTR constants copied from opaque_browser_frame_view.cc: +// In maximized mode, the OTR avatar starts 2 px below the top of the screen, so +// that it doesn't extend into the "3D edge" portion of the titlebar. +const int kOTRMaximizedTopSpacing = 2; +// The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the +// way the tabstrip draws its bottom edge, will appear like a 1 px gap to the +// user). +const int kOTRBottomSpacing = 2; +// There are 2 px on each side of the OTR avatar (between the frame border and +// it on the left, and between it and the tabstrip on the right). +const int kOTRSideSpacing = 2; + gboolean OnMouseMoveEvent(GtkWidget* widget, GdkEventMotion* event, BrowserWindowGtk* browser_window) { // Reset to the default mouse cursor. @@ -35,6 +48,15 @@ gboolean OnMouseMoveEvent(GtkWidget* widget, GdkEventMotion* event, return TRUE; } +GdkPixbuf* GetOTRAvatar() { + static GdkPixbuf* otr_avatar = NULL; + if (!otr_avatar) { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + otr_avatar = rb.GetPixbufNamed(IDR_OTR_ICON); + } + return otr_avatar; +} + } // namespace BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, @@ -46,20 +68,28 @@ BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, void BrowserTitlebar::Init() { // The widget hierarchy is shown below. // - // +- HBox (container_) --------------------------------------------------+ - // |+- Alignment (titlebar_alignment_)-++- VBox (titlebar_buttons_box_) -+| - // || ||+- HBox -----------------------+|| - // || |||+- button -++- button -+ ||| - // ||+- TabStripGtk ------------------+|||| minimize || restore | ... ||| - // ||| tab tab tab tabclose +|||+----------++----------+ ||| - // ||+--------------------------------+||+------------------------------+|| - // |+----------------------------------++--------------------------------+| - // +----------------------------------------------------------------------+ + // +- HBox (container_) -----------------------------------------------------+ + // |+- Fixed -++- Alignment --------------++- VBox (titlebar_buttons_box_) -+| + // ||(spy_guy)|| (titlebar_alignment_) ||+- HBox -----------------------+|| + // || || |||+- button -++- button -+ ||| + // || ||+- TabStripGtk ---------+|||| minimize || restore | ... ||| + // || )8\ ||| tab tab tabclose ||||+----------++----------+ ||| + // || ||+------------------------+||+------------------------------+|| + // |+---------++--------------------------++--------------------------------+| + // +-------------------------------------------------------------------------+ container_ = gtk_hbox_new(FALSE, 0); g_signal_connect(window_, "window-state-event", G_CALLBACK(OnWindowStateChanged), this); + if (browser_window_->browser()->profile()->IsOffTheRecord()) { + GtkWidget* spy_guy = gtk_fixed_new(); + gtk_widget_set_size_request(spy_guy, gdk_pixbuf_get_width(GetOTRAvatar()) + + 2 * kOTRSideSpacing, -1); + gtk_box_pack_start(GTK_BOX(container_), spy_guy, FALSE, FALSE, 0); + g_signal_connect(spy_guy, "expose-event", G_CALLBACK(OnAvatarExpose), this); + } + // We use an alignment to control the titlebar height. titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE, @@ -218,3 +248,35 @@ void BrowserTitlebar::ExecuteCommand(int command_id) { NOTREACHED(); } } + +// static +gboolean BrowserTitlebar::OnAvatarExpose( + GtkWidget* widget, GdkEventExpose* event, BrowserTitlebar* titlebar) { + cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(widget->window)); + cairo_translate(cairo_context, widget->allocation.x, widget->allocation.y); + + if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) { + cairo_translate(cairo_context, widget->allocation.width, 0.0f); + cairo_scale(cairo_context, -1.0f, 1.0f); + } + + // Set up a clip rect. + const int clip_x = kOTRSideSpacing; + const int clip_width = gdk_pixbuf_get_width(GetOTRAvatar()); + const int clip_y = kOTRMaximizedTopSpacing; + const int clip_height = widget->allocation.height - kOTRMaximizedTopSpacing - + kOTRBottomSpacing; + cairo_rectangle(cairo_context, clip_x, clip_y, clip_width, clip_height); + cairo_clip(cairo_context); + + // Drawing origin, which is calculated relative to the bottom. + const int x = clip_x; + const int y = widget->allocation.height - kOTRBottomSpacing - + gdk_pixbuf_get_height(GetOTRAvatar()); + + gdk_cairo_set_source_pixbuf(cairo_context, GetOTRAvatar(), x, y); + cairo_paint(cairo_context); + cairo_destroy(cairo_context); + + return TRUE; +} diff --git a/chrome/browser/gtk/browser_titlebar.h b/chrome/browser/gtk/browser_titlebar.h index 1dc8121..12c4ab8 100644 --- a/chrome/browser/gtk/browser_titlebar.h +++ b/chrome/browser/gtk/browser_titlebar.h @@ -66,6 +66,9 @@ class BrowserTitlebar : public MenuGtk::Delegate { virtual bool IsItemChecked(int command_id) const; virtual void ExecuteCommand(int command_id); + static gboolean OnAvatarExpose( + GtkWidget* widget, GdkEventExpose* event, BrowserTitlebar* titlebar); + // Pointers to the browser window that owns us and it's GtkWindow. BrowserWindowGtk* browser_window_; GtkWindow* window_; diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.cc b/chrome/browser/gtk/tabs/tab_strip_gtk.cc index 0867e8d..20e14ec 100755 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.cc +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.cc @@ -622,7 +622,8 @@ gfx::Rect TabStripGtk::GetIdealBounds(int index) { gfx::Point TabStripGtk::GetTabStripOriginForWidget(GtkWidget* target) { int x, y; - if (!gtk_widget_translate_coordinates(widget(), target, 0, 0, &x, &y)) { + if (!gtk_widget_translate_coordinates(widget(), target, + -widget()->allocation.x, 0, &x, &y)) { // If the tab strip isn't showing, give the coordinates relative to the // toplevel instead. gtk_widget_translate_coordinates( diff --git a/chrome/browser/gtk/tabs/tab_strip_gtk.h b/chrome/browser/gtk/tabs/tab_strip_gtk.h index 01fbf39..aa731e8 100644 --- a/chrome/browser/gtk/tabs/tab_strip_gtk.h +++ b/chrome/browser/gtk/tabs/tab_strip_gtk.h @@ -74,9 +74,13 @@ class TabStripGtk : public TabStripModelObserver, // Retrieve the ideal bounds for the Tab at the specified index. gfx::Rect GetIdealBounds(int index); - // Return the origin of the tab strip in coordinates relative to the GdkWindow - // of |widget|. Used to help other widgets draw their background relative to - // the tabstrip. + // Return the origin of the tab strip in coordinates relative to where we + // start drawing the background theme image. This is the x coordinate of + // the origin of the GdkWindow of widget(), but the y coordinate of the origin + // of widget() itself. + // Used to help other widgets draw their background relative to the tabstrip. + // Should only be called after both the tabstrip and |widget| have been + // allocated. gfx::Point GetTabStripOriginForWidget(GtkWidget* widget); protected: |