Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/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 29 matching lines...) Expand all Loading... | |
| 40 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" | 40 #include "chrome/browser/ui/toolbar/wrench_menu_model.h" |
| 41 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
| 42 #include "chrome/common/chrome_switches.h" | 42 #include "chrome/common/chrome_switches.h" |
| 43 #include "chrome/common/pref_names.h" | 43 #include "chrome/common/pref_names.h" |
| 44 #include "content/public/browser/notification_service.h" | 44 #include "content/public/browser/notification_service.h" |
| 45 #include "content/public/browser/web_contents.h" | 45 #include "content/public/browser/web_contents.h" |
| 46 #include "grit/generated_resources.h" | 46 #include "grit/generated_resources.h" |
| 47 #include "grit/theme_resources.h" | 47 #include "grit/theme_resources.h" |
| 48 #include "grit/theme_resources_standard.h" | 48 #include "grit/theme_resources_standard.h" |
| 49 #include "grit/ui_resources.h" | 49 #include "grit/ui_resources.h" |
| 50 #include "ui/base/gtk/gtk_compat.h" | |
| 51 #include "ui/base/gtk/gtk_hig_constants.h" | 50 #include "ui/base/gtk/gtk_hig_constants.h" |
| 52 #include "ui/base/l10n/l10n_util.h" | 51 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/base/resource/resource_bundle.h" | 52 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "ui/base/x/active_window_watcher_x.h" | 53 #include "ui/base/x/active_window_watcher_x.h" |
| 55 #include "ui/gfx/gtk_util.h" | 54 #include "ui/gfx/gtk_util.h" |
| 56 #include "ui/gfx/image/image.h" | 55 #include "ui/gfx/image/image.h" |
| 57 #include "ui/gfx/skbitmap_operations.h" | 56 #include "ui/gfx/skbitmap_operations.h" |
| 58 | 57 |
| 59 using content::WebContents; | 58 using content::WebContents; |
| 60 | 59 |
| (...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 608 } | 607 } |
| 609 UpdateTitlebarAlignment(); | 608 UpdateTitlebarAlignment(); |
| 610 UpdateMaximizeRestoreVisibility(); | 609 UpdateMaximizeRestoreVisibility(); |
| 611 } | 610 } |
| 612 | 611 |
| 613 void BrowserTitlebar::UpdateTitleAndIcon() { | 612 void BrowserTitlebar::UpdateTitleAndIcon() { |
| 614 if (!app_mode_title_) | 613 if (!app_mode_title_) |
| 615 return; | 614 return; |
| 616 | 615 |
| 617 // Get the page title and elide it to the available space. | 616 // Get the page title and elide it to the available space. |
| 618 std::string title; | 617 string16 title = browser_window_->browser()->GetWindowTitleForCurrentTab(); |
| 619 BrowserWindowGtk::TitleDecoration title_decoration = | 618 gtk_label_set_text(GTK_LABEL(app_mode_title_), UTF16ToUTF8(title).c_str()); |
| 620 browser_window_->GetWindowTitle(&title); | |
| 621 | |
| 622 if (title_decoration == BrowserWindowGtk::PANGO_MARKUP) { | |
| 623 gtk_label_set_markup(GTK_LABEL(app_mode_title_), title.c_str()); | |
| 624 } else { | |
| 625 DCHECK_EQ(BrowserWindowGtk::PLAIN_TEXT, title_decoration); | |
| 626 gtk_label_set_text(GTK_LABEL(app_mode_title_), title.c_str()); | |
| 627 } | |
| 628 | 619 |
| 629 if (browser_window_->browser()->is_app()) { | 620 if (browser_window_->browser()->is_app()) { |
| 630 switch (browser_window_->browser()->type()) { | 621 switch (browser_window_->browser()->type()) { |
| 631 case Browser::TYPE_POPUP: { | 622 case Browser::TYPE_POPUP: { |
| 632 // Update the system app icon. We don't need to update the icon in the | 623 // Update the system app icon. We don't need to update the icon in the |
| 633 // top left of the custom frame, that will get updated when the | 624 // top left of the custom frame, that will get updated when the |
| 634 // throbber is updated. | 625 // throbber is updated. |
| 635 Profile* profile = browser_window_->browser()->profile(); | 626 Profile* profile = browser_window_->browser()->profile(); |
| 636 SkBitmap icon = browser_window_->browser()->GetCurrentPageIcon(); | 627 SkBitmap icon = browser_window_->browser()->GetCurrentPageIcon(); |
| 637 if (icon.empty()) { | 628 if (icon.empty()) { |
| 638 gtk_util::SetWindowIcon(window_, profile); | 629 gtk_util::SetWindowIcon(window_, profile); |
| 639 } else { | 630 } else { |
| 640 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); | 631 GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(&icon); |
| 641 gtk_util::SetWindowIcon(window_, profile, icon_pixbuf); | 632 gtk_util::SetWindowIcon(window_, profile, icon_pixbuf); |
| 642 g_object_unref(icon_pixbuf); | 633 g_object_unref(icon_pixbuf); |
| 643 } | 634 } |
| 644 break; | 635 break; |
| 645 } | 636 } |
| 646 case Browser::TYPE_TABBED: { | 637 case Browser::TYPE_TABBED: { |
| 647 NOTREACHED() << "We should never have a tabbed app window."; | 638 NOTREACHED() << "We should never have a tabbed app window."; |
| 648 break; | 639 break; |
| 649 } | 640 } |
| 650 case Browser::TYPE_PANEL: { | 641 case Browser::TYPE_PANEL: { |
| 651 break; | 642 break; |
|
jennb
2012/04/27 18:36:13
NOTREACHED()
jianli
2012/04/27 20:22:34
Done.
| |
| 652 } | 643 } |
| 653 } | 644 } |
| 654 } | 645 } |
| 655 } | 646 } |
| 656 | 647 |
| 657 void BrowserTitlebar::UpdateThrobber(WebContents* web_contents) { | 648 void BrowserTitlebar::UpdateThrobber(WebContents* web_contents) { |
| 658 DCHECK(app_mode_favicon_); | 649 DCHECK(app_mode_favicon_); |
| 659 | 650 |
| 660 if (web_contents && web_contents->IsLoading()) { | 651 if (web_contents && web_contents->IsLoading()) { |
| 661 GdkPixbuf* icon_pixbuf = | 652 GdkPixbuf* icon_pixbuf = |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 void BrowserTitlebar::ShowContextMenu(GdkEventButton* event) { | 942 void BrowserTitlebar::ShowContextMenu(GdkEventButton* event) { |
| 952 if (!context_menu_.get()) { | 943 if (!context_menu_.get()) { |
| 953 context_menu_model_.reset(new ContextMenuModel(this)); | 944 context_menu_model_.reset(new ContextMenuModel(this)); |
| 954 context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get())); | 945 context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get())); |
| 955 } | 946 } |
| 956 | 947 |
| 957 context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), | 948 context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), |
| 958 event->time); | 949 event->time); |
| 959 } | 950 } |
| 960 | 951 |
| 961 void BrowserTitlebar::SendEnterNotifyToCloseButtonIfUnderMouse() { | |
| 962 gint x; | |
| 963 gint y; | |
| 964 GtkAllocation widget_allocation = close_button_->WidgetAllocation(); | |
| 965 gtk_widget_get_pointer(GTK_WIDGET(close_button_->widget()), &x, &y); | |
| 966 | |
| 967 gfx::Rect button_rect(0, 0, widget_allocation.width, | |
| 968 widget_allocation.height); | |
| 969 if (!button_rect.Contains(x, y)) { | |
| 970 // Mouse is not over the close button. | |
| 971 return; | |
| 972 } | |
| 973 | |
| 974 // Create and emit an enter-notify-event on close button. | |
| 975 GValue return_value; | |
| 976 return_value.g_type = G_TYPE_BOOLEAN; | |
| 977 g_value_set_boolean(&return_value, false); | |
| 978 | |
| 979 GdkEvent* event = gdk_event_new(GDK_ENTER_NOTIFY); | |
| 980 event->crossing.window = | |
| 981 gtk_button_get_event_window(GTK_BUTTON(close_button_->widget())); | |
| 982 event->crossing.send_event = FALSE; | |
| 983 event->crossing.subwindow = gtk_widget_get_window(close_button_->widget()); | |
| 984 event->crossing.time = gtk_util::XTimeNow(); | |
| 985 event->crossing.x = x; | |
| 986 event->crossing.y = y; | |
| 987 event->crossing.x_root = widget_allocation.x; | |
| 988 event->crossing.y_root = widget_allocation.y; | |
| 989 event->crossing.mode = GDK_CROSSING_NORMAL; | |
| 990 event->crossing.detail = GDK_NOTIFY_ANCESTOR; | |
| 991 event->crossing.focus = true; | |
| 992 event->crossing.state = 0; | |
| 993 | |
| 994 g_signal_emit_by_name(GTK_OBJECT(close_button_->widget()), | |
| 995 "enter-notify-event", event, | |
| 996 &return_value); | |
| 997 } | |
| 998 | |
| 999 int BrowserTitlebar::IconOnlyWidth() { | |
| 1000 GtkAllocation allocation; | |
| 1001 gtk_widget_get_allocation(app_mode_favicon_, &allocation); | |
| 1002 return 2 * kFrameBorderThickness + allocation.width; | |
| 1003 } | |
| 1004 | |
| 1005 bool BrowserTitlebar::IsCommandIdEnabled(int command_id) const { | 952 bool BrowserTitlebar::IsCommandIdEnabled(int command_id) const { |
| 1006 if (command_id == kShowWindowDecorationsCommand) | 953 if (command_id == kShowWindowDecorationsCommand) |
| 1007 return true; | 954 return true; |
| 1008 | 955 |
| 1009 return browser_window_->browser()->command_updater()-> | 956 return browser_window_->browser()->command_updater()-> |
| 1010 IsCommandEnabled(command_id); | 957 IsCommandEnabled(command_id); |
| 1011 } | 958 } |
| 1012 | 959 |
| 1013 bool BrowserTitlebar::IsCommandIdChecked(int command_id) const { | 960 bool BrowserTitlebar::IsCommandIdChecked(int command_id) const { |
| 1014 if (command_id == kShowWindowDecorationsCommand) { | 961 if (command_id == kShowWindowDecorationsCommand) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1161 ui::SimpleMenuModel::Delegate* delegate) | 1108 ui::SimpleMenuModel::Delegate* delegate) |
| 1162 : SimpleMenuModel(delegate) { | 1109 : SimpleMenuModel(delegate) { |
| 1163 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); | 1110 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); |
| 1164 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); | 1111 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); |
| 1165 AddSeparator(); | 1112 AddSeparator(); |
| 1166 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 1113 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
| 1167 AddSeparator(); | 1114 AddSeparator(); |
| 1168 AddCheckItemWithStringId(kShowWindowDecorationsCommand, | 1115 AddCheckItemWithStringId(kShowWindowDecorationsCommand, |
| 1169 IDS_SHOW_WINDOW_DECORATIONS_MENU); | 1116 IDS_SHOW_WINDOW_DECORATIONS_MENU); |
| 1170 } | 1117 } |
| OLD | NEW |