| OLD | NEW |
| 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/l10n_util.h" | 9 #include "app/l10n_util.h" |
| 10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
| (...skipping 26 matching lines...) Expand all Loading... |
| 37 | 37 |
| 38 } // namespace | 38 } // namespace |
| 39 | 39 |
| 40 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, | 40 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, |
| 41 GtkWindow* window) | 41 GtkWindow* window) |
| 42 : browser_window_(browser_window), window_(window) { | 42 : browser_window_(browser_window), window_(window) { |
| 43 Init(); | 43 Init(); |
| 44 } | 44 } |
| 45 | 45 |
| 46 void BrowserTitlebar::Init() { | 46 void BrowserTitlebar::Init() { |
| 47 titlebar_background_.reset(new NineBox( | |
| 48 browser_window_->browser()->profile()->GetThemeProvider(), | |
| 49 0, IDR_THEME_FRAME, 0, 0, 0, 0, 0, 0, 0)); | |
| 50 titlebar_background_otr_.reset(new NineBox( | |
| 51 browser_window_->browser()->profile()->GetThemeProvider(), | |
| 52 0, IDR_THEME_FRAME_INCOGNITO, 0, 0, 0, 0, 0, 0, 0)); | |
| 53 | |
| 54 // The widget hierarchy is shown below. | 47 // The widget hierarchy is shown below. |
| 55 // | 48 // |
| 56 // +- HBox (container_) --------------------------------------------------+ | 49 // +- HBox (container_) --------------------------------------------------+ |
| 57 // |+- Alignment (titlebar_alignment_)-++- VBox (titlebar_buttons_box_) -+| | 50 // |+- Alignment (titlebar_alignment_)-++- VBox (titlebar_buttons_box_) -+| |
| 58 // || ||+- HBox -----------------------+|| | 51 // || ||+- HBox -----------------------+|| |
| 59 // || |||+- button -++- button -+ ||| | 52 // || |||+- button -++- button -+ ||| |
| 60 // ||+- TabStripGtk ------------------+|||| minimize || restore | ... ||| | 53 // ||+- TabStripGtk ------------------+|||| minimize || restore | ... ||| |
| 61 // ||| tab tab tab tabclose +|||+----------++----------+ ||| | 54 // ||| tab tab tab tabclose +|||+----------++----------+ ||| |
| 62 // ||+--------------------------------+||+------------------------------+|| | 55 // ||+--------------------------------+||+------------------------------+|| |
| 63 // |+----------------------------------++--------------------------------+| | 56 // |+----------------------------------++--------------------------------+| |
| 64 // +----------------------------------------------------------------------+ | 57 // +----------------------------------------------------------------------+ |
| 65 container_ = gtk_hbox_new(FALSE, 0); | 58 container_ = gtk_hbox_new(FALSE, 0); |
| 66 | 59 |
| 67 g_signal_connect(G_OBJECT(container_), "expose-event", | |
| 68 G_CALLBACK(OnExpose), this); | |
| 69 g_signal_connect(window_, "window-state-event", | 60 g_signal_connect(window_, "window-state-event", |
| 70 G_CALLBACK(OnWindowStateChanged), this); | 61 G_CALLBACK(OnWindowStateChanged), this); |
| 71 | 62 |
| 72 // We use an alignment to control the titlebar height. | 63 // We use an alignment to control the titlebar height. |
| 73 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 64 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 74 gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE, | 65 gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE, |
| 75 TRUE, 0); | 66 TRUE, 0); |
| 76 | 67 |
| 77 // Put the tab strip in the titlebar. | 68 // Put the tab strip in the titlebar. |
| 78 gtk_container_add(GTK_CONTAINER(titlebar_alignment_), | 69 gtk_container_add(GTK_CONTAINER(titlebar_alignment_), |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 if (use_custom_frame) { | 114 if (use_custom_frame) { |
| 124 gtk_alignment_set_padding(GTK_ALIGNMENT(titlebar_alignment_), | 115 gtk_alignment_set_padding(GTK_ALIGNMENT(titlebar_alignment_), |
| 125 kTitlebarHeight, 0, 0, 0); | 116 kTitlebarHeight, 0, 0, 0); |
| 126 gtk_widget_show(titlebar_buttons_box_); | 117 gtk_widget_show(titlebar_buttons_box_); |
| 127 } else { | 118 } else { |
| 128 gtk_alignment_set_padding(GTK_ALIGNMENT(titlebar_alignment_), 0, 0, 0, 0); | 119 gtk_alignment_set_padding(GTK_ALIGNMENT(titlebar_alignment_), 0, 0, 0, 0); |
| 129 gtk_widget_hide(titlebar_buttons_box_); | 120 gtk_widget_hide(titlebar_buttons_box_); |
| 130 } | 121 } |
| 131 } | 122 } |
| 132 | 123 |
| 133 gboolean BrowserTitlebar::OnExpose(GtkWidget* widget, GdkEventExpose* e, | |
| 134 BrowserTitlebar* titlebar) { | |
| 135 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | |
| 136 cairo_rectangle(cr, e->area.x, e->area.y, e->area.width, e->area.height); | |
| 137 cairo_clip(cr); | |
| 138 Profile* profile = titlebar->browser_window_->browser()->profile(); | |
| 139 NineBox* image = profile->IsOffTheRecord() | |
| 140 ? titlebar->titlebar_background_otr_.get() | |
| 141 : titlebar->titlebar_background_.get(); | |
| 142 image->RenderTopCenterStrip(cr, e->area.x, 0, e->area.width); | |
| 143 cairo_destroy(cr); | |
| 144 | |
| 145 return FALSE; // Allow subwidgets to paint. | |
| 146 } | |
| 147 | |
| 148 gboolean BrowserTitlebar::OnWindowStateChanged(GtkWindow* window, | 124 gboolean BrowserTitlebar::OnWindowStateChanged(GtkWindow* window, |
| 149 GdkEventWindowState* event, BrowserTitlebar* titlebar) { | 125 GdkEventWindowState* event, BrowserTitlebar* titlebar) { |
| 150 // Update the maximize/restore button. | 126 // Update the maximize/restore button. |
| 151 if (titlebar->browser_window_->IsMaximized()) { | 127 if (titlebar->browser_window_->IsMaximized()) { |
| 152 gtk_widget_hide(titlebar->maximize_button_->widget()); | 128 gtk_widget_hide(titlebar->maximize_button_->widget()); |
| 153 gtk_widget_show(titlebar->restore_button_->widget()); | 129 gtk_widget_show(titlebar->restore_button_->widget()); |
| 154 } else { | 130 } else { |
| 155 gtk_widget_hide(titlebar->restore_button_->widget()); | 131 gtk_widget_hide(titlebar->restore_button_->widget()); |
| 156 gtk_widget_show(titlebar->maximize_button_->widget()); | 132 gtk_widget_show(titlebar->maximize_button_->widget()); |
| 157 } | 133 } |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs(); | 211 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs(); |
| 236 prefs->SetBoolean(prefs::kUseCustomChromeFrame, | 212 prefs->SetBoolean(prefs::kUseCustomChromeFrame, |
| 237 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); | 213 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); |
| 238 break; | 214 break; |
| 239 } | 215 } |
| 240 | 216 |
| 241 default: | 217 default: |
| 242 NOTREACHED(); | 218 NOTREACHED(); |
| 243 } | 219 } |
| 244 } | 220 } |
| OLD | NEW |