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

Side by Side Diff: chrome/browser/ui/panels/panel_titlebar_gtk.cc

Issue 10831226: Panels refactor: Support browserless panels on Linux. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/ui/panels/panel_browser_titlebar_gtk.h" 5 #include "chrome/browser/ui/panels/panel_titlebar_gtk.h"
6 6
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/gtk/custom_button.h" 8 #include "chrome/browser/ui/gtk/custom_button.h"
10 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 9 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
11 #include "chrome/browser/ui/gtk/gtk_util.h" 10 #include "chrome/browser/ui/gtk/gtk_util.h"
12 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
13 #include "chrome/browser/ui/panels/panel.h" 11 #include "chrome/browser/ui/panels/panel.h"
14 #include "chrome/browser/ui/panels/panel_browser_window_gtk.h" 12 #include "chrome/browser/ui/panels/panel_gtk.h"
15 #include "chrome/common/chrome_notification_types.h"
16 #include "content/public/browser/notification_service.h"
17 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
18 #include "grit/generated_resources.h" 14 #include "grit/generated_resources.h"
19 #include "grit/theme_resources.h" 15 #include "grit/theme_resources.h"
20 #include "third_party/skia/include/core/SkBitmap.h" 16 #include "third_party/skia/include/core/SkBitmap.h"
21 #include "ui/base/gtk/gtk_compat.h" 17 #include "ui/base/gtk/gtk_compat.h"
22 #include "ui/base/l10n/l10n_util.h" 18 #include "ui/base/l10n/l10n_util.h"
23 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
24 #include "ui/gfx/skia_utils_gtk.h" 20 #include "ui/gfx/skia_utils_gtk.h"
25 21
26 namespace { 22 namespace {
(...skipping 12 matching lines...) Expand all
39 35
40 // Color used to draw title text under default theme. 36 // Color used to draw title text under default theme.
41 const SkColor kTitleTextDefaultColor = SkColorSetRGB(0xf9, 0xf9, 0xf9); 37 const SkColor kTitleTextDefaultColor = SkColorSetRGB(0xf9, 0xf9, 0xf9);
42 38
43 // Markup used to paint the title with the desired font. 39 // Markup used to paint the title with the desired font.
44 const char* const kTitleMarkupPrefix = "<span face='Arial' size='11264'>"; 40 const char* const kTitleMarkupPrefix = "<span face='Arial' size='11264'>";
45 const char* const kTitleMarkupSuffix = "</span>"; 41 const char* const kTitleMarkupSuffix = "</span>";
46 42
47 } // namespace 43 } // namespace
48 44
49 PanelBrowserTitlebarGtk::PanelBrowserTitlebarGtk( 45 PanelTitlebarGtk::PanelTitlebarGtk(PanelGtk* panel_gtk)
50 PanelBrowserWindowGtk* browser_window, GtkWindow* window) 46 : panel_gtk_(panel_gtk),
51 : browser_window_(browser_window),
52 window_(window),
53 container_(NULL), 47 container_(NULL),
54 titlebar_right_buttons_vbox_(NULL), 48 titlebar_right_buttons_vbox_(NULL),
55 titlebar_right_buttons_hbox_(NULL), 49 titlebar_right_buttons_hbox_(NULL),
56 icon_(NULL), 50 icon_(NULL),
57 title_(NULL), 51 title_(NULL),
58 theme_service_(NULL) { 52 theme_service_(GtkThemeService::GetFrom(panel_gtk_->panel()->profile())) {
59 } 53 }
60 54
61 PanelBrowserTitlebarGtk::~PanelBrowserTitlebarGtk() { 55 PanelTitlebarGtk::~PanelTitlebarGtk() {
62 } 56 }
63 57
64 void PanelBrowserTitlebarGtk::Init() { 58 void PanelTitlebarGtk::Init() {
65 container_ = gtk_event_box_new(); 59 container_ = gtk_event_box_new();
66 gtk_widget_set_name(container_, "chrome-panel-titlebar"); 60 gtk_widget_set_name(container_, "chrome-panel-titlebar");
67 gtk_event_box_set_visible_window(GTK_EVENT_BOX(container_), FALSE); 61 gtk_event_box_set_visible_window(GTK_EVENT_BOX(container_), FALSE);
68 62
69 // We use an alignment to control the titlebar paddings. 63 // We use an alignment to control the titlebar paddings.
70 GtkWidget* container_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0); 64 GtkWidget* container_alignment = gtk_alignment_new(0.0, 0.0, 1.0, 1.0);
71 gtk_container_add(GTK_CONTAINER(container_), container_alignment); 65 gtk_container_add(GTK_CONTAINER(container_), container_alignment);
72 gtk_alignment_set_padding(GTK_ALIGNMENT(container_alignment), 66 gtk_alignment_set_padding(GTK_ALIGNMENT(container_alignment),
73 kPanelTitlebarPaddingTop, 67 kPanelTitlebarPaddingTop,
74 kPanelTitlebarPaddingBottom, 68 kPanelTitlebarPaddingBottom,
75 kPanelTitlebarPaddingLeft, 69 kPanelTitlebarPaddingLeft,
76 kPanelTitlebarPaddingRight); 70 kPanelTitlebarPaddingRight);
77 71
78 // Add a container box. 72 // Add a container box.
79 GtkWidget* container_hbox = gtk_hbox_new(FALSE, 0); 73 GtkWidget* container_hbox = gtk_hbox_new(FALSE, 0);
80 gtk_container_add(GTK_CONTAINER(container_alignment), container_hbox); 74 gtk_container_add(GTK_CONTAINER(container_alignment), container_hbox);
81 75
82 g_signal_connect(window_, "window-state-event",
83 G_CALLBACK(OnWindowStateChangedThunk), this);
84
85 // Add minimize/restore and close buttons. Panel buttons are always placed 76 // Add minimize/restore and close buttons. Panel buttons are always placed
86 // on the right part of the titlebar. 77 // on the right part of the titlebar.
87 titlebar_right_buttons_vbox_ = gtk_vbox_new(FALSE, 0); 78 titlebar_right_buttons_vbox_ = gtk_vbox_new(FALSE, 0);
88 gtk_box_pack_end(GTK_BOX(container_hbox), titlebar_right_buttons_vbox_, 79 gtk_box_pack_end(GTK_BOX(container_hbox), titlebar_right_buttons_vbox_,
89 FALSE, FALSE, 0); 80 FALSE, FALSE, 0);
90 BuildButtons(); 81 BuildButtons();
91 82
92 // Add hbox for holding icon and title. 83 // Add hbox for holding icon and title.
93 GtkWidget* icon_title_hbox = gtk_hbox_new(FALSE, kPanelIconTitleSpacing); 84 GtkWidget* icon_title_hbox = gtk_hbox_new(FALSE, kPanelIconTitleSpacing);
94 gtk_box_pack_start(GTK_BOX(container_hbox), icon_title_hbox, TRUE, TRUE, 0); 85 gtk_box_pack_start(GTK_BOX(container_hbox), icon_title_hbox, TRUE, TRUE, 0);
95 86
96 // Add icon. We use the app logo as a placeholder image so the title doesn't 87 // Add icon. We use the app logo as a placeholder image so the title doesn't
97 // jump around. 88 // jump around.
98 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
99 icon_ = gtk_image_new_from_pixbuf(rb.GetNativeImageNamed( 90 icon_ = gtk_image_new_from_pixbuf(rb.GetNativeImageNamed(
100 IDR_PRODUCT_LOGO_16, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf()); 91 IDR_PRODUCT_LOGO_16, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf());
101 g_object_set_data(G_OBJECT(icon_), "left-align-popup", 92 g_object_set_data(G_OBJECT(icon_), "left-align-popup",
102 reinterpret_cast<void*>(true)); 93 reinterpret_cast<void*>(true));
103 gtk_box_pack_start(GTK_BOX(icon_title_hbox), icon_, FALSE, FALSE, 0); 94 gtk_box_pack_start(GTK_BOX(icon_title_hbox), icon_, FALSE, FALSE, 0);
104 95
105 // Add title. 96 // Add title.
106 title_ = gtk_label_new(NULL); 97 title_ = gtk_label_new(NULL);
107 gtk_label_set_ellipsize(GTK_LABEL(title_), PANGO_ELLIPSIZE_END); 98 gtk_label_set_ellipsize(GTK_LABEL(title_), PANGO_ELLIPSIZE_END);
108 gtk_misc_set_alignment(GTK_MISC(title_), 0.0, 0.5); 99 gtk_misc_set_alignment(GTK_MISC(title_), 0.0, 0.5);
109 gtk_box_pack_start(GTK_BOX(icon_title_hbox), title_, TRUE, TRUE, 0); 100 gtk_box_pack_start(GTK_BOX(icon_title_hbox), title_, TRUE, TRUE, 0);
110
111 UpdateTitleAndIcon(); 101 UpdateTitleAndIcon();
112 102 UpdateTextColor();
113 theme_service_ = GtkThemeService::GetFrom(
114 browser_window_->panel()->profile());
115 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
116 content::Source<ThemeService>(theme_service_));
117 theme_service_->InitThemesFor(this);
118 103
119 gtk_widget_show_all(container_); 104 gtk_widget_show_all(container_);
120 } 105 }
121 106
122 SkColor PanelBrowserTitlebarGtk::GetTextColor() const { 107 SkColor PanelTitlebarGtk::GetTextColor() const {
123 if (browser_window_->UsingDefaultTheme()) 108 if (panel_gtk_->UsingDefaultTheme())
124 return kTitleTextDefaultColor; 109 return kTitleTextDefaultColor;
125 return theme_service_->GetColor(browser_window_->paint_state() == 110 return theme_service_->GetColor(panel_gtk_->paint_state() ==
126 PanelBrowserWindowGtk::PAINT_AS_ACTIVE ? 111 PanelGtk::PAINT_AS_ACTIVE ?
127 ThemeService::COLOR_TAB_TEXT : 112 ThemeService::COLOR_TAB_TEXT :
128 ThemeService::COLOR_BACKGROUND_TAB_TEXT); 113 ThemeService::COLOR_BACKGROUND_TAB_TEXT);
129 } 114 }
130 115
131 void PanelBrowserTitlebarGtk::BuildButtons() { 116 void PanelTitlebarGtk::BuildButtons() {
132 minimize_button_.reset(CreateButton(panel::MINIMIZE_BUTTON)); 117 minimize_button_.reset(CreateButton(panel::MINIMIZE_BUTTON));
133 restore_button_.reset(CreateButton(panel::RESTORE_BUTTON)); 118 restore_button_.reset(CreateButton(panel::RESTORE_BUTTON));
134 close_button_.reset(CreateButton(panel::CLOSE_BUTTON)); 119 close_button_.reset(CreateButton(panel::CLOSE_BUTTON));
135 120
136 // We control visibility of minimize and restore buttons. 121 // We control visibility of minimize and restore buttons.
137 gtk_widget_set_no_show_all(minimize_button_->widget(), TRUE); 122 gtk_widget_set_no_show_all(minimize_button_->widget(), TRUE);
138 gtk_widget_set_no_show_all(restore_button_->widget(), TRUE); 123 gtk_widget_set_no_show_all(restore_button_->widget(), TRUE);
139 124
140 // Now show the correct widgets in the two hierarchies. 125 // Now show the correct widgets in the two hierarchies.
141 UpdateMinimizeRestoreButtonVisibility(); 126 UpdateMinimizeRestoreButtonVisibility();
142 } 127 }
143 128
144 CustomDrawButton* PanelBrowserTitlebarGtk::CreateButton( 129 CustomDrawButton* PanelTitlebarGtk::CreateButton(
145 panel::TitlebarButtonType button_type) { 130 panel::TitlebarButtonType button_type) {
146 int normal_image_id = -1; 131 int normal_image_id = -1;
147 int pressed_image_id = -1; 132 int pressed_image_id = -1;
148 int hover_image_id = -1; 133 int hover_image_id = -1;
149 int tooltip_id = -1; 134 int tooltip_id = -1;
150 GetButtonResources(button_type, &normal_image_id, &pressed_image_id, 135 GetButtonResources(button_type, &normal_image_id, &pressed_image_id,
151 &hover_image_id, &tooltip_id); 136 &hover_image_id, &tooltip_id);
152 137
153 CustomDrawButton* button = new CustomDrawButton(normal_image_id, 138 CustomDrawButton* button = new CustomDrawButton(normal_image_id,
154 pressed_image_id, 139 pressed_image_id,
155 hover_image_id, 140 hover_image_id,
156 0); 141 0);
157 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); 142 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK);
158 g_signal_connect(button->widget(), "clicked", 143 g_signal_connect(button->widget(), "clicked",
159 G_CALLBACK(OnButtonClickedThunk), this); 144 G_CALLBACK(OnButtonClickedThunk), this);
160 145
161 std::string localized_tooltip = l10n_util::GetStringUTF8(tooltip_id); 146 std::string localized_tooltip = l10n_util::GetStringUTF8(tooltip_id);
162 gtk_widget_set_tooltip_text(button->widget(), 147 gtk_widget_set_tooltip_text(button->widget(),
163 localized_tooltip.c_str()); 148 localized_tooltip.c_str());
164 149
165 GtkWidget* box = GetButtonHBox(); 150 GtkWidget* box = GetButtonHBox();
166 gtk_box_pack_start(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); 151 gtk_box_pack_start(GTK_BOX(box), button->widget(), FALSE, FALSE, 0);
167 return button; 152 return button;
168 } 153 }
169 154
170 void PanelBrowserTitlebarGtk::GetButtonResources( 155 void PanelTitlebarGtk::GetButtonResources(
171 panel::TitlebarButtonType button_type, 156 panel::TitlebarButtonType button_type,
172 int* normal_image_id, 157 int* normal_image_id,
173 int* pressed_image_id, 158 int* pressed_image_id,
174 int* hover_image_id, 159 int* hover_image_id,
175 int* tooltip_id) const { 160 int* tooltip_id) const {
176 switch (button_type) { 161 switch (button_type) {
177 case panel::CLOSE_BUTTON: 162 case panel::CLOSE_BUTTON:
178 *normal_image_id = IDR_PANEL_CLOSE; 163 *normal_image_id = IDR_PANEL_CLOSE;
179 *pressed_image_id = IDR_PANEL_CLOSE_C; 164 *pressed_image_id = IDR_PANEL_CLOSE_C;
180 *hover_image_id = IDR_PANEL_CLOSE_H; 165 *hover_image_id = IDR_PANEL_CLOSE_H;
181 *tooltip_id = IDS_PANEL_CLOSE_TOOLTIP; 166 *tooltip_id = IDS_PANEL_CLOSE_TOOLTIP;
182 break; 167 break;
183 case panel::MINIMIZE_BUTTON: 168 case panel::MINIMIZE_BUTTON:
184 *normal_image_id = IDR_PANEL_MINIMIZE; 169 *normal_image_id = IDR_PANEL_MINIMIZE;
185 *pressed_image_id = IDR_PANEL_MINIMIZE_C; 170 *pressed_image_id = IDR_PANEL_MINIMIZE_C;
186 *hover_image_id = IDR_PANEL_MINIMIZE_H; 171 *hover_image_id = IDR_PANEL_MINIMIZE_H;
187 *tooltip_id = IDS_PANEL_MINIMIZE_TOOLTIP; 172 *tooltip_id = IDS_PANEL_MINIMIZE_TOOLTIP;
188 break; 173 break;
189 case panel::RESTORE_BUTTON: 174 case panel::RESTORE_BUTTON:
190 *normal_image_id = IDR_PANEL_RESTORE; 175 *normal_image_id = IDR_PANEL_RESTORE;
191 *pressed_image_id = IDR_PANEL_RESTORE_C; 176 *pressed_image_id = IDR_PANEL_RESTORE_C;
192 *hover_image_id = IDR_PANEL_RESTORE_H; 177 *hover_image_id = IDR_PANEL_RESTORE_H;
193 *tooltip_id = IDS_PANEL_RESTORE_TOOLTIP; 178 *tooltip_id = IDS_PANEL_RESTORE_TOOLTIP;
194 break; 179 break;
195 } 180 }
196 } 181 }
197 182
198 GtkWidget* PanelBrowserTitlebarGtk::GetButtonHBox() { 183 GtkWidget* PanelTitlebarGtk::GetButtonHBox() {
199 if (!titlebar_right_buttons_hbox_) { 184 if (!titlebar_right_buttons_hbox_) {
200 // We put the minimize/restore/close buttons in a vbox so they are top 185 // We put the minimize/restore/close buttons in a vbox so they are top
201 // aligned (up to padding) and don't vertically stretch. 186 // aligned (up to padding) and don't vertically stretch.
202 titlebar_right_buttons_hbox_ = gtk_hbox_new(FALSE, kPanelButtonSpacing); 187 titlebar_right_buttons_hbox_ = gtk_hbox_new(FALSE, kPanelButtonSpacing);
203 gtk_box_pack_start(GTK_BOX(titlebar_right_buttons_vbox_), 188 gtk_box_pack_start(GTK_BOX(titlebar_right_buttons_vbox_),
204 titlebar_right_buttons_hbox_, FALSE, FALSE, 0); 189 titlebar_right_buttons_hbox_, FALSE, FALSE, 0);
205 } 190 }
206 191
207 return titlebar_right_buttons_hbox_; 192 return titlebar_right_buttons_hbox_;
208 } 193 }
209 194
210 void PanelBrowserTitlebarGtk::UpdateCustomFrame(bool use_custom_frame) { 195 void PanelTitlebarGtk::UpdateTitleAndIcon() {
211 // Nothing to do.
212 }
213
214 void PanelBrowserTitlebarGtk::UpdateTitleAndIcon() {
215 std::string title_text = 196 std::string title_text =
216 UTF16ToUTF8(browser_window_->panel()->GetWindowTitle()); 197 UTF16ToUTF8(panel_gtk_->panel()->GetWindowTitle());
217 198
218 // Add the markup to show the title in the desired font. 199 // Add the markup to show the title in the desired font.
219 gchar* escaped_title_text = g_markup_escape_text(title_text.c_str(), -1); 200 gchar* escaped_title_text = g_markup_escape_text(title_text.c_str(), -1);
220 gchar* title_text_with_markup = g_strconcat(kTitleMarkupPrefix, 201 gchar* title_text_with_markup = g_strconcat(kTitleMarkupPrefix,
221 escaped_title_text, 202 escaped_title_text,
222 kTitleMarkupSuffix, 203 kTitleMarkupSuffix,
223 NULL); 204 NULL);
224 gtk_label_set_markup(GTK_LABEL(title_), title_text_with_markup); 205 gtk_label_set_markup(GTK_LABEL(title_), title_text_with_markup);
225 g_free(escaped_title_text); 206 g_free(escaped_title_text);
226 g_free(title_text_with_markup); 207 g_free(title_text_with_markup);
227 } 208 }
228 209
229 void PanelBrowserTitlebarGtk::UpdateThrobber( 210 void PanelTitlebarGtk::UpdateThrobber(
230 content::WebContents* web_contents) { 211 content::WebContents* web_contents) {
231 if (web_contents && web_contents->IsLoading()) { 212 if (web_contents && web_contents->IsLoading()) {
232 GdkPixbuf* icon_pixbuf = 213 GdkPixbuf* icon_pixbuf =
233 throbber_.GetNextFrame(web_contents->IsWaitingForResponse()); 214 throbber_.GetNextFrame(web_contents->IsWaitingForResponse());
234 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf); 215 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf);
235 } else { 216 } else {
236 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 217 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
237 218
238 SkBitmap icon = browser_window_->panel()->GetCurrentPageIcon(); 219 SkBitmap icon = panel_gtk_->panel()->GetCurrentPageIcon();
239 if (icon.empty()) { 220 if (icon.empty()) {
240 // Fallback to the Chromium icon if the page has no icon. 221 // Fallback to the Chromium icon if the page has no icon.
241 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), 222 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_),
242 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf()); 223 rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf());
243 } else { 224 } else {
244 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon); 225 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon);
245 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf); 226 gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf);
246 g_object_unref(icon_pixbuf); 227 g_object_unref(icon_pixbuf);
247 } 228 }
248 229
249 throbber_.Reset(); 230 throbber_.Reset();
250 } 231 }
251 } 232 }
252 233
253 void PanelBrowserTitlebarGtk::ShowContextMenu(GdkEventButton* event) { 234 void PanelTitlebarGtk::UpdateTextColor() {
254 // Panel does not show any context menu.
255 }
256
257 void PanelBrowserTitlebarGtk::UpdateTextColor() {
258 GdkColor text_color = gfx::SkColorToGdkColor(GetTextColor()); 235 GdkColor text_color = gfx::SkColorToGdkColor(GetTextColor());
259 gtk_util::SetLabelColor(title_, &text_color); 236 gtk_util::SetLabelColor(title_, &text_color);
260 } 237 }
261 238
262 void PanelBrowserTitlebarGtk::UpdateMinimizeRestoreButtonVisibility() { 239 void PanelTitlebarGtk::UpdateMinimizeRestoreButtonVisibility() {
263 Panel* panel = browser_window_->panel(); 240 Panel* panel = panel_gtk_->panel();
264 gtk_widget_set_visible(minimize_button_->widget(), panel->CanMinimize()); 241 gtk_widget_set_visible(minimize_button_->widget(), panel->CanMinimize());
265 gtk_widget_set_visible(restore_button_->widget(), panel->CanRestore()); 242 gtk_widget_set_visible(restore_button_->widget(), panel->CanRestore());
266 } 243 }
267 244
268 gboolean PanelBrowserTitlebarGtk::OnWindowStateChanged( 245 void PanelTitlebarGtk::OnButtonClicked(GtkWidget* button) {
269 GtkWindow* window, GdkEventWindowState* event) { 246 Panel* panel = panel_gtk_->panel();
270 UpdateTextColor();
271 return FALSE;
272 }
273
274 void PanelBrowserTitlebarGtk::OnButtonClicked(GtkWidget* button) {
275 if (close_button_->widget() == button) { 247 if (close_button_->widget() == button) {
276 browser_window_->panel()->Close(); 248 panel->Close();
277 return; 249 return;
278 } 250 }
279 251
280 GdkEvent* event = gtk_get_current_event(); 252 GdkEvent* event = gtk_get_current_event();
281 DCHECK(event && event->type == GDK_BUTTON_RELEASE); 253 DCHECK(event && event->type == GDK_BUTTON_RELEASE);
282 254
283 if (minimize_button_->widget() == button) { 255 if (minimize_button_->widget() == button) {
284 browser_window_->panel()->OnMinimizeButtonClicked( 256 panel->OnMinimizeButtonClicked(
285 (event->button.state & GDK_CONTROL_MASK) ? 257 (event->button.state & GDK_CONTROL_MASK) ?
286 panel::APPLY_TO_ALL : panel::NO_MODIFIER); 258 panel::APPLY_TO_ALL : panel::NO_MODIFIER);
287 } else if (restore_button_->widget() == button) { 259 } else if (restore_button_->widget() == button) {
288 browser_window_->panel()->OnRestoreButtonClicked( 260 panel->OnRestoreButtonClicked(
289 (event->button.state & GDK_CONTROL_MASK) ? 261 (event->button.state & GDK_CONTROL_MASK) ?
290 panel::APPLY_TO_ALL : panel::NO_MODIFIER); 262 panel::APPLY_TO_ALL : panel::NO_MODIFIER);
291 } 263 }
292 264
293 gdk_event_free(event); 265 gdk_event_free(event);
294 } 266 }
295 267
296 void PanelBrowserTitlebarGtk::Observe( 268 void PanelTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() {
297 int type,
298 const content::NotificationSource& source,
299 const content::NotificationDetails& details) {
300 switch (type) {
301 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
302 UpdateTextColor();
303 break;
304 default:
305 NOTREACHED();
306 }
307 }
308
309 void PanelBrowserTitlebarGtk::SendEnterNotifyToCloseButtonIfUnderMouse() {
310 if (!close_button()) 269 if (!close_button())
311 return; 270 return;
312 271
313 gint x; 272 gint x;
314 gint y; 273 gint y;
315 GtkAllocation widget_allocation = close_button()->WidgetAllocation(); 274 GtkAllocation widget_allocation = close_button()->WidgetAllocation();
316 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y); 275 gtk_widget_get_pointer(GTK_WIDGET(close_button()->widget()), &x, &y);
317 276
318 gfx::Rect button_rect(0, 0, widget_allocation.width, 277 gfx::Rect button_rect(0, 0, widget_allocation.width,
319 widget_allocation.height); 278 widget_allocation.height);
(...skipping 20 matching lines...) Expand all
340 event->crossing.mode = GDK_CROSSING_NORMAL; 299 event->crossing.mode = GDK_CROSSING_NORMAL;
341 event->crossing.detail = GDK_NOTIFY_ANCESTOR; 300 event->crossing.detail = GDK_NOTIFY_ANCESTOR;
342 event->crossing.focus = true; 301 event->crossing.focus = true;
343 event->crossing.state = 0; 302 event->crossing.state = 0;
344 303
345 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()), 304 g_signal_emit_by_name(GTK_OBJECT(close_button()->widget()),
346 "enter-notify-event", event, 305 "enter-notify-event", event,
347 &return_value); 306 &return_value);
348 } 307 }
349 308
350 GtkWidget* PanelBrowserTitlebarGtk::widget() const { 309 GtkWidget* PanelTitlebarGtk::widget() const {
351 return container_; 310 return container_;
352 } 311 }
353
354 void PanelBrowserTitlebarGtk::set_window(GtkWindow* window) {
355 window_ = window;
356 }
357
358 AvatarMenuButtonGtk* PanelBrowserTitlebarGtk::avatar_button() const {
359 // Not supported in panel.
360 return NULL;
361 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698