OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/gtk/browser_titlebar.h" | 5 #include "chrome/browser/ui/gtk/browser_titlebar.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 | 9 |
10 #include <string> | 10 #include <string> |
(...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
394 G_CALLBACK(OnPanelSettingsMenuButtonPressedThunk), this); | 394 G_CALLBACK(OnPanelSettingsMenuButtonPressedThunk), this); |
395 gtk_widget_set_no_show_all(panel_wrench_button_->widget(), TRUE); | 395 gtk_widget_set_no_show_all(panel_wrench_button_->widget(), TRUE); |
396 } | 396 } |
397 | 397 |
398 app_mode_title_ = gtk_label_new(NULL); | 398 app_mode_title_ = gtk_label_new(NULL); |
399 gtk_label_set_ellipsize(GTK_LABEL(app_mode_title_), PANGO_ELLIPSIZE_END); | 399 gtk_label_set_ellipsize(GTK_LABEL(app_mode_title_), PANGO_ELLIPSIZE_END); |
400 gtk_misc_set_alignment(GTK_MISC(app_mode_title_), 0.0, 0.5); | 400 gtk_misc_set_alignment(GTK_MISC(app_mode_title_), 0.0, 0.5); |
401 gtk_box_pack_start(GTK_BOX(app_mode_hbox), app_mode_title_, TRUE, TRUE, | 401 gtk_box_pack_start(GTK_BOX(app_mode_hbox), app_mode_title_, TRUE, TRUE, |
402 0); | 402 0); |
403 | 403 |
404 // Register with the theme provider to set the |app_mode_title_| label | |
405 // color. | |
406 theme_service_ = GtkThemeService::GetFrom( | |
407 browser_window_->browser()->profile()); | |
408 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, | |
409 content::Source<ThemeService>(theme_service_)); | |
410 theme_service_->InitThemesFor(this); | |
411 UpdateTitleAndIcon(); | 404 UpdateTitleAndIcon(); |
412 } | 405 } |
413 | 406 |
| 407 theme_service_ = GtkThemeService::GetFrom( |
| 408 browser_window_->browser()->profile()); |
| 409 registrar_.Add(this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, |
| 410 content::Source<ThemeService>(theme_service_)); |
| 411 theme_service_->InitThemesFor(this); |
| 412 |
414 gtk_widget_show_all(container_); | 413 gtk_widget_show_all(container_); |
415 | 414 |
416 ui::ActiveWindowWatcherX::AddObserver(this); | 415 ui::ActiveWindowWatcherX::AddObserver(this); |
417 } | 416 } |
418 | 417 |
419 BrowserTitlebar::~BrowserTitlebar() { | 418 BrowserTitlebar::~BrowserTitlebar() { |
420 ui::ActiveWindowWatcherX::RemoveObserver(this); | 419 ui::ActiveWindowWatcherX::RemoveObserver(this); |
421 #if defined(USE_GCONF) | 420 #if defined(USE_GCONF) |
422 GConfTitlebarListener::GetInstance()->RemoveObserver(this); | 421 GConfTitlebarListener::GetInstance()->RemoveObserver(this); |
423 #endif | 422 #endif |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
528 } | 527 } |
529 | 528 |
530 return buttons_hbox; | 529 return buttons_hbox; |
531 } | 530 } |
532 | 531 |
533 CustomDrawButton* BrowserTitlebar::BuildTitlebarButton(int image, | 532 CustomDrawButton* BrowserTitlebar::BuildTitlebarButton(int image, |
534 int image_pressed, int image_hot, GtkWidget* box, bool start, | 533 int image_pressed, int image_hot, GtkWidget* box, bool start, |
535 int tooltip) { | 534 int tooltip) { |
536 CustomDrawButton* button = new CustomDrawButton(image, image_pressed, | 535 CustomDrawButton* button = new CustomDrawButton(image, image_pressed, |
537 image_hot, 0); | 536 image_hot, 0); |
| 537 |
538 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); | 538 gtk_widget_add_events(GTK_WIDGET(button->widget()), GDK_POINTER_MOTION_MASK); |
539 g_signal_connect(button->widget(), "clicked", | 539 g_signal_connect(button->widget(), "clicked", |
540 G_CALLBACK(OnButtonClickedThunk), this); | 540 G_CALLBACK(OnButtonClickedThunk), this); |
541 g_signal_connect(button->widget(), "motion-notify-event", | 541 g_signal_connect(button->widget(), "motion-notify-event", |
542 G_CALLBACK(OnMouseMoveEvent), browser_window_); | 542 G_CALLBACK(OnMouseMoveEvent), browser_window_); |
543 std::string localized_tooltip = l10n_util::GetStringUTF8(tooltip); | 543 std::string localized_tooltip = l10n_util::GetStringUTF8(tooltip); |
544 gtk_widget_set_tooltip_text(button->widget(), | 544 gtk_widget_set_tooltip_text(button->widget(), |
545 localized_tooltip.c_str()); | 545 localized_tooltip.c_str()); |
546 if (start) | 546 if (start) |
547 gtk_box_pack_start(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); | 547 gtk_box_pack_start(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); |
548 else | 548 else |
549 gtk_box_pack_end(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); | 549 gtk_box_pack_end(GTK_BOX(box), button->widget(), FALSE, FALSE, 0); |
550 return button; | 550 return button; |
551 } | 551 } |
552 | 552 |
| 553 void BrowserTitlebar::UpdateButtonBackground(CustomDrawButton* button) { |
| 554 SkColor color = theme_service_->GetColor( |
| 555 ThemeService::COLOR_BUTTON_BACKGROUND); |
| 556 SkBitmap* background = |
| 557 theme_service_->GetBitmapNamed(IDR_THEME_WINDOW_CONTROL_BACKGROUND); |
| 558 |
| 559 // TODO(erg): For now, we just use a completely black mask and we can get |
| 560 // aways with this in the short term because our buttons are rectangles. We |
| 561 // should get Glen to make properly hinted masks that match our |
| 562 // masks. http://crbug.com/103661 |
| 563 SkBitmap mask; |
| 564 mask.setConfig(SkBitmap::kARGB_8888_Config, |
| 565 button->SurfaceWidth(), button->SurfaceHeight(), 0); |
| 566 mask.allocPixels(); |
| 567 mask.eraseColor(SK_ColorBLACK); |
| 568 |
| 569 button->SetBackground(color, background, &mask); |
| 570 } |
| 571 |
553 void BrowserTitlebar::UpdateCustomFrame(bool use_custom_frame) { | 572 void BrowserTitlebar::UpdateCustomFrame(bool use_custom_frame) { |
554 using_custom_frame_ = use_custom_frame; | 573 using_custom_frame_ = use_custom_frame; |
555 if (!use_custom_frame || | 574 if (!use_custom_frame || |
556 (browser_window_->IsMaximized() && unity::IsRunning())) { | 575 (browser_window_->IsMaximized() && unity::IsRunning())) { |
557 if (titlebar_left_buttons_vbox_) | 576 if (titlebar_left_buttons_vbox_) |
558 gtk_widget_hide(titlebar_left_buttons_vbox_); | 577 gtk_widget_hide(titlebar_left_buttons_vbox_); |
559 if (titlebar_right_buttons_vbox_) | 578 if (titlebar_right_buttons_vbox_) |
560 gtk_widget_hide(titlebar_right_buttons_vbox_); | 579 gtk_widget_hide(titlebar_right_buttons_vbox_); |
561 } else { | 580 } else { |
562 if (titlebar_left_buttons_vbox_) | 581 if (titlebar_left_buttons_vbox_) |
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
987 command_id); | 1006 command_id); |
988 if (accelerator_gtk) | 1007 if (accelerator_gtk) |
989 *accelerator = *accelerator_gtk; | 1008 *accelerator = *accelerator_gtk; |
990 return accelerator_gtk; | 1009 return accelerator_gtk; |
991 } | 1010 } |
992 | 1011 |
993 void BrowserTitlebar::Observe(int type, | 1012 void BrowserTitlebar::Observe(int type, |
994 const content::NotificationSource& source, | 1013 const content::NotificationSource& source, |
995 const content::NotificationDetails& details) { | 1014 const content::NotificationDetails& details) { |
996 switch (type) { | 1015 switch (type) { |
997 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: | 1016 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: { |
998 UpdateTextColor(); | 1017 UpdateTextColor(); |
| 1018 |
| 1019 if (minimize_button_.get()) |
| 1020 UpdateButtonBackground(minimize_button_.get()); |
| 1021 if (maximize_button_.get()) |
| 1022 UpdateButtonBackground(maximize_button_.get()); |
| 1023 if (restore_button_.get()) |
| 1024 UpdateButtonBackground(restore_button_.get()); |
| 1025 if (close_button_.get()) |
| 1026 UpdateButtonBackground(close_button_.get()); |
999 break; | 1027 break; |
| 1028 } |
1000 | 1029 |
1001 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: | 1030 case chrome::NOTIFICATION_PROFILE_CACHED_INFO_CHANGED: |
1002 UpdateAvatar(); | 1031 UpdateAvatar(); |
1003 break; | 1032 break; |
1004 | 1033 |
1005 default: | 1034 default: |
1006 NOTREACHED(); | 1035 NOTREACHED(); |
1007 } | 1036 } |
1008 } | 1037 } |
1009 | 1038 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1096 ui::SimpleMenuModel::Delegate* delegate) | 1125 ui::SimpleMenuModel::Delegate* delegate) |
1097 : SimpleMenuModel(delegate) { | 1126 : SimpleMenuModel(delegate) { |
1098 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); | 1127 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); |
1099 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); | 1128 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); |
1100 AddSeparator(); | 1129 AddSeparator(); |
1101 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 1130 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
1102 AddSeparator(); | 1131 AddSeparator(); |
1103 AddCheckItemWithStringId(kShowWindowDecorationsCommand, | 1132 AddCheckItemWithStringId(kShowWindowDecorationsCommand, |
1104 IDS_SHOW_WINDOW_DECORATIONS_MENU); | 1133 IDS_SHOW_WINDOW_DECORATIONS_MENU); |
1105 } | 1134 } |
OLD | NEW |