Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(424)

Side by Side Diff: chrome/browser/gtk/browser_titlebar.cc

Issue 146122: Paint the spy guy. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: improve ascii art spacing Created 11 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/gtk/browser_titlebar.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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/gtk/browser_titlebar.h" 5 #include "chrome/browser/gtk/browser_titlebar.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "app/resource_bundle.h"
9 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
10 #include "chrome/app/chrome_dll_resource.h" 11 #include "chrome/app/chrome_dll_resource.h"
11 #include "chrome/browser/browser.h" 12 #include "chrome/browser/browser.h"
12 #include "chrome/browser/gtk/browser_window_gtk.h" 13 #include "chrome/browser/gtk/browser_window_gtk.h"
13 #include "chrome/browser/gtk/custom_button.h" 14 #include "chrome/browser/gtk/custom_button.h"
14 #include "chrome/browser/gtk/nine_box.h" 15 #include "chrome/browser/gtk/nine_box.h"
15 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" 16 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h"
16 #include "chrome/browser/profile.h" 17 #include "chrome/browser/profile.h"
17 #include "chrome/common/pref_names.h" 18 #include "chrome/common/pref_names.h"
18 #include "chrome/common/pref_service.h" 19 #include "chrome/common/pref_service.h"
19 #include "grit/app_resources.h" 20 #include "grit/app_resources.h"
20 #include "grit/generated_resources.h" 21 #include "grit/generated_resources.h"
21 #include "grit/theme_resources.h" 22 #include "grit/theme_resources.h"
22 23
23 namespace { 24 namespace {
24 25
25 // The space above the titlebars. 26 // The space above the titlebars.
26 const int kTitlebarHeight = 14; 27 const int kTitlebarHeight = 14;
27 28
28 // A linux specific menu item for toggling window decorations. 29 // A linux specific menu item for toggling window decorations.
29 const int kShowWindowDecorationsCommand = 200; 30 const int kShowWindowDecorationsCommand = 200;
30 31
32 // The following OTR constants copied from opaque_browser_frame_view.cc:
33 // In maximized mode, the OTR avatar starts 2 px below the top of the screen, so
34 // that it doesn't extend into the "3D edge" portion of the titlebar.
35 const int kOTRMaximizedTopSpacing = 2;
36 // The OTR avatar ends 2 px above the bottom of the tabstrip (which, given the
37 // way the tabstrip draws its bottom edge, will appear like a 1 px gap to the
38 // user).
39 const int kOTRBottomSpacing = 2;
40 // There are 2 px on each side of the OTR avatar (between the frame border and
41 // it on the left, and between it and the tabstrip on the right).
42 const int kOTRSideSpacing = 2;
43
31 gboolean OnMouseMoveEvent(GtkWidget* widget, GdkEventMotion* event, 44 gboolean OnMouseMoveEvent(GtkWidget* widget, GdkEventMotion* event,
32 BrowserWindowGtk* browser_window) { 45 BrowserWindowGtk* browser_window) {
33 // Reset to the default mouse cursor. 46 // Reset to the default mouse cursor.
34 browser_window->ResetCustomFrameCursor(); 47 browser_window->ResetCustomFrameCursor();
35 return TRUE; 48 return TRUE;
36 } 49 }
37 50
51 GdkPixbuf* GetOTRAvatar() {
52 static GdkPixbuf* otr_avatar = NULL;
53 if (!otr_avatar) {
54 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
55 otr_avatar = rb.GetPixbufNamed(IDR_OTR_ICON);
56 }
57 return otr_avatar;
58 }
59
38 } // namespace 60 } // namespace
39 61
40 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, 62 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window,
41 GtkWindow* window) 63 GtkWindow* window)
42 : browser_window_(browser_window), window_(window) { 64 : browser_window_(browser_window), window_(window) {
43 Init(); 65 Init();
44 } 66 }
45 67
46 void BrowserTitlebar::Init() { 68 void BrowserTitlebar::Init() {
47 // The widget hierarchy is shown below. 69 // The widget hierarchy is shown below.
48 // 70 //
49 // +- HBox (container_) --------------------------------------------------+ 71 // +- HBox (container_) -----------------------------------------------------+
50 // |+- Alignment (titlebar_alignment_)-++- VBox (titlebar_buttons_box_) -+| 72 // |+- Fixed -++- Alignment --------------++- VBox (titlebar_buttons_box_) -+|
51 // || ||+- HBox -----------------------+|| 73 // ||(spy_guy)|| (titlebar_alignment_) ||+- HBox -----------------------+||
52 // || |||+- button -++- button -+ ||| 74 // || || |||+- button -++- button -+ |||
53 // ||+- TabStripGtk ------------------+|||| minimize || restore | ... ||| 75 // || ||+- TabStripGtk ---------+|||| minimize || restore | ... |||
54 // ||| tab tab tab tabclose +|||+----------++----------+ ||| 76 // || )8\ ||| tab tab tabclose ||||+----------++----------+ |||
55 // ||+--------------------------------+||+------------------------------+|| 77 // || ||+------------------------+||+------------------------------+||
56 // |+----------------------------------++--------------------------------+| 78 // |+---------++--------------------------++--------------------------------+|
57 // +----------------------------------------------------------------------+ 79 // +-------------------------------------------------------------------------+
58 container_ = gtk_hbox_new(FALSE, 0); 80 container_ = gtk_hbox_new(FALSE, 0);
59 81
60 g_signal_connect(window_, "window-state-event", 82 g_signal_connect(window_, "window-state-event",
61 G_CALLBACK(OnWindowStateChanged), this); 83 G_CALLBACK(OnWindowStateChanged), this);
62 84
85 if (browser_window_->browser()->profile()->IsOffTheRecord()) {
86 GtkWidget* spy_guy = gtk_fixed_new();
87 gtk_widget_set_size_request(spy_guy, gdk_pixbuf_get_width(GetOTRAvatar()) +
88 2 * kOTRSideSpacing, -1);
89 gtk_box_pack_start(GTK_BOX(container_), spy_guy, FALSE, FALSE, 0);
90 g_signal_connect(spy_guy, "expose-event", G_CALLBACK(OnAvatarExpose), this);
91 }
92
63 // We use an alignment to control the titlebar height. 93 // We use an alignment to control the titlebar height.
64 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 94 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
65 gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE, 95 gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE,
66 TRUE, 0); 96 TRUE, 0);
67 97
68 // Put the tab strip in the titlebar. 98 // Put the tab strip in the titlebar.
69 gtk_container_add(GTK_CONTAINER(titlebar_alignment_), 99 gtk_container_add(GTK_CONTAINER(titlebar_alignment_),
70 browser_window_->tabstrip()->widget()); 100 browser_window_->tabstrip()->widget());
71 101
72 // We put the min/max/restore/close buttons in a vbox so they are top aligned 102 // We put the min/max/restore/close buttons in a vbox so they are top aligned
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
211 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs(); 241 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs();
212 prefs->SetBoolean(prefs::kUseCustomChromeFrame, 242 prefs->SetBoolean(prefs::kUseCustomChromeFrame,
213 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); 243 !prefs->GetBoolean(prefs::kUseCustomChromeFrame));
214 break; 244 break;
215 } 245 }
216 246
217 default: 247 default:
218 NOTREACHED(); 248 NOTREACHED();
219 } 249 }
220 } 250 }
251
252 // static
253 gboolean BrowserTitlebar::OnAvatarExpose(
254 GtkWidget* widget, GdkEventExpose* event, BrowserTitlebar* titlebar) {
255 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(widget->window));
256 cairo_translate(cairo_context, widget->allocation.x, widget->allocation.y);
257
258 if (l10n_util::GetTextDirection() == l10n_util::RIGHT_TO_LEFT) {
259 cairo_translate(cairo_context, widget->allocation.width, 0.0f);
260 cairo_scale(cairo_context, -1.0f, 1.0f);
261 }
262
263 // Set up a clip rect.
264 const int clip_x = kOTRSideSpacing;
265 const int clip_width = gdk_pixbuf_get_width(GetOTRAvatar());
266 const int clip_y = kOTRMaximizedTopSpacing;
267 const int clip_height = widget->allocation.height - kOTRMaximizedTopSpacing -
268 kOTRBottomSpacing;
269 cairo_rectangle(cairo_context, clip_x, clip_y, clip_width, clip_height);
270 cairo_clip(cairo_context);
271
272 // Drawing origin, which is calculated relative to the bottom.
273 const int x = clip_x;
274 const int y = widget->allocation.height - kOTRBottomSpacing -
275 gdk_pixbuf_get_height(GetOTRAvatar());
276
277 gdk_cairo_set_source_pixbuf(cairo_context, GetOTRAvatar(), x, y);
278 cairo_paint(cairo_context);
279 cairo_destroy(cairo_context);
280
281 return TRUE;
282 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/browser_titlebar.h ('k') | chrome/browser/gtk/tabs/tab_strip_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698