| 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 <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "app/resource_bundle.h" | 11 #include "app/resource_bundle.h" |
| 12 #include "app/l10n_util.h" | 12 #include "app/l10n_util.h" |
| 13 #include "base/gfx/gtk_util.h" |
| 13 #include "chrome/app/chrome_dll_resource.h" | 14 #include "chrome/app/chrome_dll_resource.h" |
| 14 #include "chrome/browser/browser.h" | 15 #include "chrome/browser/browser.h" |
| 15 #include "chrome/browser/gtk/browser_window_gtk.h" | 16 #include "chrome/browser/gtk/browser_window_gtk.h" |
| 16 #include "chrome/browser/gtk/custom_button.h" | 17 #include "chrome/browser/gtk/custom_button.h" |
| 17 #include "chrome/browser/gtk/nine_box.h" | 18 #include "chrome/browser/gtk/nine_box.h" |
| 18 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" | 19 #include "chrome/browser/gtk/tabs/tab_strip_gtk.h" |
| 19 #include "chrome/browser/profile.h" | 20 #include "chrome/browser/profile.h" |
| 20 #include "chrome/common/pref_names.h" | 21 #include "chrome/common/pref_names.h" |
| 21 #include "chrome/common/pref_service.h" | 22 #include "chrome/common/pref_service.h" |
| 22 #include "grit/app_resources.h" | 23 #include "grit/app_resources.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, | 70 BrowserTitlebar::BrowserTitlebar(BrowserWindowGtk* browser_window, |
| 70 GtkWindow* window) | 71 GtkWindow* window) |
| 71 : browser_window_(browser_window), window_(window), | 72 : browser_window_(browser_window), window_(window), |
| 72 using_custom_frame_(false) { | 73 using_custom_frame_(false) { |
| 73 Init(); | 74 Init(); |
| 74 } | 75 } |
| 75 | 76 |
| 76 void BrowserTitlebar::Init() { | 77 void BrowserTitlebar::Init() { |
| 77 // The widget hierarchy is shown below. | 78 // The widget hierarchy is shown below. |
| 78 // | 79 // |
| 79 // +- HBox (container_) -----------------------------------------------------+ | 80 // +- EventBox (container_) -------------------------------------------------+ |
| 81 // +- HBox (container_hbox) -------------------------------------------------+ |
| 80 // |+- Algn. -++- Alignment --------------++- VBox (titlebar_buttons_box_) -+| | 82 // |+- Algn. -++- Alignment --------------++- VBox (titlebar_buttons_box_) -+| |
| 81 // ||+ Image +|| (titlebar_alignment_) ||+- HBox -----------------------+|| | 83 // ||+ Image +|| (titlebar_alignment_) ||+- HBox -----------------------+|| |
| 82 // |||spy_guy||| |||+- button -++- button -+ ||| | 84 // |||spy_guy||| |||+- button -++- button -+ ||| |
| 83 // ||| |||+- TabStripGtk ---------+|||| minimize || restore | ... ||| | 85 // ||| |||+- TabStripGtk ---------+|||| minimize || restore | ... ||| |
| 84 // ||| )8\ |||| tab tab tabclose ||||+----------++----------+ ||| | 86 // ||| )8\ |||| tab tab tabclose ||||+----------++----------+ ||| |
| 85 // ||+-------+||+------------------------+||+------------------------------+|| | 87 // ||+-------+||+------------------------+||+------------------------------+|| |
| 86 // |+---------++--------------------------++--------------------------------+| | 88 // |+---------++--------------------------++--------------------------------+| |
| 87 // +-------------------------------------------------------------------------+ | 89 // +-------------------------------------------------------------------------+ |
| 88 container_ = gtk_hbox_new(FALSE, 0); | 90 GtkWidget* container_hbox = gtk_hbox_new(FALSE, 0); |
| 91 |
| 92 container_ = gtk_event_box_new(); |
| 93 gtk_event_box_set_visible_window(GTK_EVENT_BOX(container_), FALSE); |
| 94 gtk_container_add(GTK_CONTAINER(container_), container_hbox); |
| 95 |
| 96 g_signal_connect(G_OBJECT(container_), "scroll-event", |
| 97 G_CALLBACK(OnScroll), this); |
| 89 | 98 |
| 90 g_signal_connect(window_, "window-state-event", | 99 g_signal_connect(window_, "window-state-event", |
| 91 G_CALLBACK(OnWindowStateChanged), this); | 100 G_CALLBACK(OnWindowStateChanged), this); |
| 92 | 101 |
| 93 if (browser_window_->browser()->profile()->IsOffTheRecord()) { | 102 if (browser_window_->browser()->profile()->IsOffTheRecord()) { |
| 94 GtkWidget* spy_guy = gtk_image_new_from_pixbuf(GetOTRAvatar()); | 103 GtkWidget* spy_guy = gtk_image_new_from_pixbuf(GetOTRAvatar()); |
| 95 gtk_misc_set_alignment(GTK_MISC(spy_guy), 0.0, 1.0); | 104 gtk_misc_set_alignment(GTK_MISC(spy_guy), 0.0, 1.0); |
| 96 GtkWidget* spy_frame = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 105 GtkWidget* spy_frame = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 97 // We use this alignment rather than setting padding on the GtkImage because | 106 // We use this alignment rather than setting padding on the GtkImage because |
| 98 // the image's intrinsic padding doesn't clip the pixbuf during painting. | 107 // the image's intrinsic padding doesn't clip the pixbuf during painting. |
| 99 gtk_alignment_set_padding(GTK_ALIGNMENT(spy_frame), kOTRMaximizedTopSpacing, | 108 gtk_alignment_set_padding(GTK_ALIGNMENT(spy_frame), kOTRMaximizedTopSpacing, |
| 100 kOTRBottomSpacing, kOTRSideSpacing, kOTRSideSpacing); | 109 kOTRBottomSpacing, kOTRSideSpacing, kOTRSideSpacing); |
| 101 gtk_widget_set_size_request(spy_guy, -1, 0); | 110 gtk_widget_set_size_request(spy_guy, -1, 0); |
| 102 gtk_container_add(GTK_CONTAINER(spy_frame), spy_guy); | 111 gtk_container_add(GTK_CONTAINER(spy_frame), spy_guy); |
| 103 gtk_box_pack_start(GTK_BOX(container_), spy_frame, FALSE, FALSE, 0); | 112 gtk_box_pack_start(GTK_BOX(container_hbox), spy_frame, FALSE, FALSE, 0); |
| 104 } | 113 } |
| 105 | 114 |
| 106 // We use an alignment to control the titlebar height. | 115 // We use an alignment to control the titlebar height. |
| 107 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); | 116 titlebar_alignment_ = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); |
| 108 gtk_box_pack_start(GTK_BOX(container_), titlebar_alignment_, TRUE, | 117 gtk_box_pack_start(GTK_BOX(container_hbox), titlebar_alignment_, TRUE, |
| 109 TRUE, 0); | 118 TRUE, 0); |
| 110 | 119 |
| 111 // Put the tab strip in the titlebar. | 120 // Put the tab strip in the titlebar. |
| 112 gtk_container_add(GTK_CONTAINER(titlebar_alignment_), | 121 gtk_container_add(GTK_CONTAINER(titlebar_alignment_), |
| 113 browser_window_->tabstrip()->widget()); | 122 browser_window_->tabstrip()->widget()); |
| 114 | 123 |
| 115 // We put the min/max/restore/close buttons in a vbox so they are top aligned | 124 // We put the min/max/restore/close buttons in a vbox so they are top aligned |
| 116 // and don't vertically stretch. | 125 // and don't vertically stretch. |
| 117 titlebar_buttons_box_ = gtk_vbox_new(FALSE, 0); | 126 titlebar_buttons_box_ = gtk_vbox_new(FALSE, 0); |
| 118 GtkWidget* buttons_hbox = gtk_hbox_new(FALSE, 0); | 127 GtkWidget* buttons_hbox = gtk_hbox_new(FALSE, 0); |
| 119 gtk_box_pack_start(GTK_BOX(titlebar_buttons_box_), buttons_hbox, FALSE, | 128 gtk_box_pack_start(GTK_BOX(titlebar_buttons_box_), buttons_hbox, FALSE, |
| 120 FALSE, 0); | 129 FALSE, 0); |
| 121 | 130 |
| 122 close_button_.reset(BuildTitlebarButton(IDR_CLOSE, IDR_CLOSE_P, IDR_CLOSE_H, | 131 close_button_.reset(BuildTitlebarButton(IDR_CLOSE, IDR_CLOSE_P, IDR_CLOSE_H, |
| 123 buttons_hbox, IDS_XPFRAME_CLOSE_TOOLTIP)); | 132 buttons_hbox, IDS_XPFRAME_CLOSE_TOOLTIP)); |
| 124 restore_button_.reset(BuildTitlebarButton(IDR_RESTORE, IDR_RESTORE_P, | 133 restore_button_.reset(BuildTitlebarButton(IDR_RESTORE, IDR_RESTORE_P, |
| 125 IDR_RESTORE_H, buttons_hbox, | 134 IDR_RESTORE_H, buttons_hbox, |
| 126 IDS_XPFRAME_RESTORE_TOOLTIP)); | 135 IDS_XPFRAME_RESTORE_TOOLTIP)); |
| 127 maximize_button_.reset(BuildTitlebarButton(IDR_MAXIMIZE, IDR_MAXIMIZE_P, | 136 maximize_button_.reset(BuildTitlebarButton(IDR_MAXIMIZE, IDR_MAXIMIZE_P, |
| 128 IDR_MAXIMIZE_H, buttons_hbox, | 137 IDR_MAXIMIZE_H, buttons_hbox, |
| 129 IDS_XPFRAME_MAXIMIZE_TOOLTIP)); | 138 IDS_XPFRAME_MAXIMIZE_TOOLTIP)); |
| 130 minimize_button_.reset(BuildTitlebarButton(IDR_MINIMIZE, IDR_MINIMIZE_P, | 139 minimize_button_.reset(BuildTitlebarButton(IDR_MINIMIZE, IDR_MINIMIZE_P, |
| 131 IDR_MINIMIZE_H, buttons_hbox, | 140 IDR_MINIMIZE_H, buttons_hbox, |
| 132 IDS_XPFRAME_MINIMIZE_TOOLTIP)); | 141 IDS_XPFRAME_MINIMIZE_TOOLTIP)); |
| 133 | 142 |
| 134 GtkRequisition req; | 143 GtkRequisition req; |
| 135 gtk_widget_size_request(close_button_->widget(), &req); | 144 gtk_widget_size_request(close_button_->widget(), &req); |
| 136 close_button_default_width_ = req.width; | 145 close_button_default_width_ = req.width; |
| 137 | 146 |
| 138 gtk_box_pack_end(GTK_BOX(container_), titlebar_buttons_box_, FALSE, | 147 gtk_box_pack_end(GTK_BOX(container_hbox), titlebar_buttons_box_, FALSE, |
| 139 FALSE, 0); | 148 FALSE, 0); |
| 140 | 149 |
| 141 gtk_widget_show_all(container_); | 150 gtk_widget_show_all(container_); |
| 142 } | 151 } |
| 143 | 152 |
| 144 CustomDrawButton* BrowserTitlebar::BuildTitlebarButton(int image, | 153 CustomDrawButton* BrowserTitlebar::BuildTitlebarButton(int image, |
| 145 int image_pressed, int image_hot, GtkWidget* box, int tooltip) { | 154 int image_pressed, int image_hot, GtkWidget* box, int tooltip) { |
| 146 CustomDrawButton* button = new CustomDrawButton(image, image_pressed, | 155 CustomDrawButton* button = new CustomDrawButton(image, image_pressed, |
| 147 image_hot, 0); | 156 image_hot, 0); |
| 148 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); | 157 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 189 gtk_widget_show(titlebar->restore_button_->widget()); | 198 gtk_widget_show(titlebar->restore_button_->widget()); |
| 190 } else { | 199 } else { |
| 191 gtk_widget_hide(titlebar->restore_button_->widget()); | 200 gtk_widget_hide(titlebar->restore_button_->widget()); |
| 192 gtk_widget_show(titlebar->maximize_button_->widget()); | 201 gtk_widget_show(titlebar->maximize_button_->widget()); |
| 193 } | 202 } |
| 194 titlebar->UpdateTitlebarAlignment(); | 203 titlebar->UpdateTitlebarAlignment(); |
| 195 return FALSE; | 204 return FALSE; |
| 196 } | 205 } |
| 197 | 206 |
| 198 // static | 207 // static |
| 208 gboolean BrowserTitlebar::OnScroll(GtkWidget* widget, GdkEventScroll* event, |
| 209 BrowserTitlebar* titlebar) { |
| 210 TabStripModel* tabstrip_model = |
| 211 titlebar->browser_window_->browser()->tabstrip_model(); |
| 212 if (event->direction == GDK_SCROLL_LEFT || |
| 213 event->direction == GDK_SCROLL_UP) { |
| 214 tabstrip_model->SelectPreviousTab(); |
| 215 } else { |
| 216 tabstrip_model->SelectNextTab(); |
| 217 } |
| 218 return TRUE; |
| 219 } |
| 220 |
| 221 // static |
| 199 void BrowserTitlebar::OnButtonClicked(GtkWidget* button, | 222 void BrowserTitlebar::OnButtonClicked(GtkWidget* button, |
| 200 BrowserTitlebar* titlebar) { | 223 BrowserTitlebar* titlebar) { |
| 201 if (titlebar->close_button_->widget() == button) { | 224 if (titlebar->close_button_->widget() == button) { |
| 202 titlebar->browser_window_->Close(); | 225 titlebar->browser_window_->Close(); |
| 203 } else if (titlebar->restore_button_->widget() == button) { | 226 } else if (titlebar->restore_button_->widget() == button) { |
| 204 gtk_window_unmaximize(titlebar->window_); | 227 gtk_window_unmaximize(titlebar->window_); |
| 205 } else if (titlebar->maximize_button_->widget() == button) { | 228 } else if (titlebar->maximize_button_->widget() == button) { |
| 206 gtk_window_maximize(titlebar->window_); | 229 gtk_window_maximize(titlebar->window_); |
| 207 } else if (titlebar->minimize_button_->widget() == button) { | 230 } else if (titlebar->minimize_button_->widget() == button) { |
| 208 gtk_window_iconify(titlebar->window_); | 231 gtk_window_iconify(titlebar->window_); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs(); | 295 PrefService* prefs = browser_window_->browser()->profile()->GetPrefs(); |
| 273 prefs->SetBoolean(prefs::kUseCustomChromeFrame, | 296 prefs->SetBoolean(prefs::kUseCustomChromeFrame, |
| 274 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); | 297 !prefs->GetBoolean(prefs::kUseCustomChromeFrame)); |
| 275 break; | 298 break; |
| 276 } | 299 } |
| 277 | 300 |
| 278 default: | 301 default: |
| 279 NOTREACHED(); | 302 NOTREACHED(); |
| 280 } | 303 } |
| 281 } | 304 } |
| OLD | NEW |