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

Side by Side Diff: chrome/browser/ui/gtk/browser_titlebar.cc

Issue 10180011: Support painting panels with chromium themes on GTK. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Patch to land Created 8 years, 7 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
« no previous file with comments | « chrome/browser/ui/gtk/browser_titlebar.h ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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
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: {
642 NOTREACHED();
651 break; 643 break;
652 } 644 }
653 } 645 }
654 } 646 }
655 } 647 }
656 648
657 void BrowserTitlebar::UpdateThrobber(WebContents* web_contents) { 649 void BrowserTitlebar::UpdateThrobber(WebContents* web_contents) {
658 DCHECK(app_mode_favicon_); 650 DCHECK(app_mode_favicon_);
659 651
660 if (web_contents && web_contents->IsLoading()) { 652 if (web_contents && web_contents->IsLoading()) {
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
951 void BrowserTitlebar::ShowContextMenu(GdkEventButton* event) { 943 void BrowserTitlebar::ShowContextMenu(GdkEventButton* event) {
952 if (!context_menu_.get()) { 944 if (!context_menu_.get()) {
953 context_menu_model_.reset(new ContextMenuModel(this)); 945 context_menu_model_.reset(new ContextMenuModel(this));
954 context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get())); 946 context_menu_.reset(new MenuGtk(NULL, context_menu_model_.get()));
955 } 947 }
956 948
957 context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root), 949 context_menu_->PopupAsContext(gfx::Point(event->x_root, event->y_root),
958 event->time); 950 event->time);
959 } 951 }
960 952
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 { 953 bool BrowserTitlebar::IsCommandIdEnabled(int command_id) const {
1006 if (command_id == kShowWindowDecorationsCommand) 954 if (command_id == kShowWindowDecorationsCommand)
1007 return true; 955 return true;
1008 956
1009 return browser_window_->browser()->command_updater()-> 957 return browser_window_->browser()->command_updater()->
1010 IsCommandEnabled(command_id); 958 IsCommandEnabled(command_id);
1011 } 959 }
1012 960
1013 bool BrowserTitlebar::IsCommandIdChecked(int command_id) const { 961 bool BrowserTitlebar::IsCommandIdChecked(int command_id) const {
1014 if (command_id == kShowWindowDecorationsCommand) { 962 if (command_id == kShowWindowDecorationsCommand) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1161 ui::SimpleMenuModel::Delegate* delegate) 1109 ui::SimpleMenuModel::Delegate* delegate)
1162 : SimpleMenuModel(delegate) { 1110 : SimpleMenuModel(delegate) {
1163 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); 1111 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB);
1164 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); 1112 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB);
1165 AddSeparator(); 1113 AddSeparator();
1166 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); 1114 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER);
1167 AddSeparator(); 1115 AddSeparator();
1168 AddCheckItemWithStringId(kShowWindowDecorationsCommand, 1116 AddCheckItemWithStringId(kShowWindowDecorationsCommand,
1169 IDS_SHOW_WINDOW_DECORATIONS_MENU); 1117 IDS_SHOW_WINDOW_DECORATIONS_MENU);
1170 } 1118 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/browser_titlebar.h ('k') | chrome/browser/ui/gtk/browser_window_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698