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> |
11 #include <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/string_piece.h" | 16 #include "base/string_piece.h" |
17 #include "base/string_tokenizer.h" | 17 #include "base/string_tokenizer.h" |
18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
19 #include "chrome/app/chrome_command_ids.h" | 19 #include "chrome/app/chrome_command_ids.h" |
20 #include "chrome/browser/browser_process.h" | 20 #include "chrome/browser/browser_process.h" |
21 #include "chrome/browser/managed_mode.h" | |
21 #include "chrome/browser/prefs/pref_service.h" | 22 #include "chrome/browser/prefs/pref_service.h" |
23 #include "chrome/browser/profiles/avatar_menu_model.h" | |
22 #include "chrome/browser/profiles/profile.h" | 24 #include "chrome/browser/profiles/profile.h" |
23 #include "chrome/browser/profiles/profile_info_cache.h" | 25 #include "chrome/browser/profiles/profile_info_cache.h" |
24 #include "chrome/browser/profiles/profile_manager.h" | 26 #include "chrome/browser/profiles/profile_manager.h" |
25 #include "chrome/browser/ui/browser.h" | 27 #include "chrome/browser/ui/browser.h" |
26 #include "chrome/browser/ui/gtk/accelerators_gtk.h" | 28 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
27 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" | 29 #include "chrome/browser/ui/gtk/avatar_menu_button_gtk.h" |
28 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 30 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
29 #include "chrome/browser/ui/gtk/custom_button.h" | 31 #include "chrome/browser/ui/gtk/custom_button.h" |
30 #if defined(USE_GCONF) | 32 #if defined(USE_GCONF) |
31 #include "chrome/browser/ui/gtk/gconf_titlebar_listener.h" | 33 #include "chrome/browser/ui/gtk/gconf_titlebar_listener.h" |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
115 GdkPixbuf* GetOTRAvatar() { | 117 GdkPixbuf* GetOTRAvatar() { |
116 static GdkPixbuf* otr_avatar = NULL; | 118 static GdkPixbuf* otr_avatar = NULL; |
117 if (!otr_avatar) { | 119 if (!otr_avatar) { |
118 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 120 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
119 otr_avatar = rb.GetNativeImageNamed( | 121 otr_avatar = rb.GetNativeImageNamed( |
120 IDR_OTR_ICON, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf(); | 122 IDR_OTR_ICON, ui::ResourceBundle::RTL_ENABLED).ToGdkPixbuf(); |
121 } | 123 } |
122 return otr_avatar; | 124 return otr_avatar; |
123 } | 125 } |
124 | 126 |
127 gfx::Image GetManagedModeAvatar() { | |
Evan Stade
2012/04/25 19:26:05
I don't think defining this function is gaining yo
Bernhard Bauer
2012/04/26 16:46:15
Removed (as well as GetOTRAvatar() above).
| |
128 static gfx::Image managed_mode_avatar; | |
129 if (managed_mode_avatar.IsEmpty()) { | |
130 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
131 managed_mode_avatar = rb.GetNativeImageNamed( | |
132 IDR_MANAGED_MODE_AVATAR, ui::ResourceBundle::RTL_ENABLED); | |
133 } | |
134 return managed_mode_avatar; | |
135 } | |
136 | |
125 // Converts a GdkColor to a color_utils::HSL. | 137 // Converts a GdkColor to a color_utils::HSL. |
126 color_utils::HSL GdkColorToHSL(const GdkColor* color) { | 138 color_utils::HSL GdkColorToHSL(const GdkColor* color) { |
127 color_utils::HSL hsl; | 139 color_utils::HSL hsl; |
128 color_utils::SkColorToHSL(SkColorSetRGB(color->red >> 8, | 140 color_utils::SkColorToHSL(SkColorSetRGB(color->red >> 8, |
129 color->green >> 8, | 141 color->green >> 8, |
130 color->blue >> 8), &hsl); | 142 color->blue >> 8), &hsl); |
131 return hsl; | 143 return hsl; |
132 } | 144 } |
133 | 145 |
134 // Returns either |one| or |two| based on which has a greater difference in | 146 // Returns either |one| or |two| based on which has a greater difference in |
135 // luminosity. | 147 // luminosity. |
136 GdkColor PickLuminosityContrastingColor(const GdkColor* base, | 148 GdkColor PickLuminosityContrastingColor(const GdkColor* base, |
137 const GdkColor* one, | 149 const GdkColor* one, |
138 const GdkColor* two) { | 150 const GdkColor* two) { |
139 // Convert all GdkColors to color_utils::HSLs. | 151 // Convert all GdkColors to color_utils::HSLs. |
140 color_utils::HSL baseHSL = GdkColorToHSL(base); | 152 color_utils::HSL baseHSL = GdkColorToHSL(base); |
141 color_utils::HSL oneHSL = GdkColorToHSL(one); | 153 color_utils::HSL oneHSL = GdkColorToHSL(one); |
142 color_utils::HSL twoHSL = GdkColorToHSL(two); | 154 color_utils::HSL twoHSL = GdkColorToHSL(two); |
143 double one_difference = fabs(baseHSL.l - oneHSL.l); | 155 double one_difference = fabs(baseHSL.l - oneHSL.l); |
144 double two_difference = fabs(baseHSL.l - twoHSL.l); | 156 double two_difference = fabs(baseHSL.l - twoHSL.l); |
145 | 157 |
146 // Be biased towards the first color presented. | 158 // Be biased towards the first color presented. |
147 if (two_difference > one_difference + 0.1) | 159 if (two_difference > one_difference + 0.1) |
148 return *two; | 160 return *two; |
149 else | 161 else |
150 return *one; | 162 return *one; |
151 } | 163 } |
152 | 164 |
153 // Returns true if there are multiple profiles created. This is used to | |
154 // determine whether to display the avatar image. | |
155 bool HasMultipleProfiles() { | |
156 ProfileInfoCache& cache = | |
157 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
158 return ProfileManager::IsMultipleProfilesEnabled() && | |
159 cache.GetNumberOfProfiles() > 1; | |
160 } | |
161 | |
162 } // namespace | 165 } // namespace |
163 | 166 |
164 //////////////////////////////////////////////////////////////////////////////// | 167 //////////////////////////////////////////////////////////////////////////////// |
165 // PopupPageMenuModel | 168 // PopupPageMenuModel |
166 | 169 |
167 // A menu model that builds the contents of the menu shown for popups (when the | 170 // A menu model that builds the contents of the menu shown for popups (when the |
168 // user clicks on the favicon) and all of its submenus. | 171 // user clicks on the favicon) and all of its submenus. |
169 class PopupPageMenuModel : public ui::SimpleMenuModel { | 172 class PopupPageMenuModel : public ui::SimpleMenuModel { |
170 public: | 173 public: |
171 PopupPageMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser); | 174 PopupPageMenuModel(ui::SimpleMenuModel::Delegate* delegate, Browser* browser); |
(...skipping 595 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
767 | 770 |
768 if (!ShouldDisplayAvatar()) | 771 if (!ShouldDisplayAvatar()) |
769 return; | 772 return; |
770 | 773 |
771 if (!avatar_) { | 774 if (!avatar_) { |
772 if (IsOffTheRecord()) { | 775 if (IsOffTheRecord()) { |
773 avatar_ = gtk_image_new_from_pixbuf(GetOTRAvatar()); | 776 avatar_ = gtk_image_new_from_pixbuf(GetOTRAvatar()); |
774 gtk_misc_set_alignment(GTK_MISC(avatar_), 0.0, 1.0); | 777 gtk_misc_set_alignment(GTK_MISC(avatar_), 0.0, 1.0); |
775 gtk_widget_set_size_request(avatar_, -1, 0); | 778 gtk_widget_set_size_request(avatar_, -1, 0); |
776 } else { | 779 } else { |
777 // Is using multi-profile avatar. | 780 // Use a clickable avatar. |
778 avatar_ = avatar_button_->widget(); | 781 avatar_ = avatar_button_->widget(); |
779 } | 782 } |
780 } | 783 } |
781 | 784 |
782 gtk_widget_show_all(avatar_); | 785 gtk_widget_show_all(avatar_); |
783 | 786 |
784 if (display_avatar_on_left_) { | 787 if (display_avatar_on_left_) { |
785 gtk_container_add(GTK_CONTAINER(titlebar_left_avatar_frame_), avatar_); | 788 gtk_container_add(GTK_CONTAINER(titlebar_left_avatar_frame_), avatar_); |
786 gtk_widget_show(titlebar_left_avatar_frame_); | 789 gtk_widget_show(titlebar_left_avatar_frame_); |
787 gtk_widget_hide(titlebar_right_avatar_frame_); | 790 gtk_widget_hide(titlebar_right_avatar_frame_); |
788 } else { | 791 } else { |
789 gtk_container_add(GTK_CONTAINER(titlebar_right_avatar_frame_), avatar_); | 792 gtk_container_add(GTK_CONTAINER(titlebar_right_avatar_frame_), avatar_); |
790 gtk_widget_show(titlebar_right_avatar_frame_); | 793 gtk_widget_show(titlebar_right_avatar_frame_); |
791 gtk_widget_hide(titlebar_left_avatar_frame_); | 794 gtk_widget_hide(titlebar_left_avatar_frame_); |
792 } | 795 } |
793 | 796 |
794 if (IsOffTheRecord()) | 797 if (IsOffTheRecord()) |
795 return; | 798 return; |
796 | 799 |
797 ProfileInfoCache& cache = | 800 bool is_gaia_picture = false; |
798 g_browser_process->profile_manager()->GetProfileInfoCache(); | 801 gfx::Image avatar; |
799 Profile* profile = browser_window_->browser()->profile(); | 802 if (ManagedMode::IsInManagedMode()) { |
800 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | 803 avatar = GetManagedModeAvatar(); |
801 if (index != std::string::npos) { | 804 } else { |
802 bool is_gaia_picture = | 805 ProfileInfoCache& cache = |
806 g_browser_process->profile_manager()->GetProfileInfoCache(); | |
807 Profile* profile = browser_window_->browser()->profile(); | |
808 size_t index = cache.GetIndexOfProfileWithPath(profile->GetPath()); | |
809 if (index == std::string::npos) | |
810 return; | |
811 is_gaia_picture = | |
803 cache.IsUsingGAIAPictureOfProfileAtIndex(index) && | 812 cache.IsUsingGAIAPictureOfProfileAtIndex(index) && |
804 cache.GetGAIAPictureOfProfileAtIndex(index); | 813 cache.GetGAIAPictureOfProfileAtIndex(index); |
805 avatar_button_->SetIcon( | 814 avatar = cache.GetAvatarIconOfProfileAtIndex(index); |
806 cache.GetAvatarIconOfProfileAtIndex(index), is_gaia_picture); | 815 } |
816 avatar_button_->SetIcon(avatar, is_gaia_picture); | |
807 | 817 |
808 BubbleGtk::ArrowLocationGtk arrow_location = | 818 BubbleGtk::ArrowLocationGtk arrow_location = |
809 display_avatar_on_left_ ^ base::i18n::IsRTL() ? | 819 display_avatar_on_left_ ^ base::i18n::IsRTL() ? |
810 BubbleGtk::ARROW_LOCATION_TOP_LEFT : | 820 BubbleGtk::ARROW_LOCATION_TOP_LEFT : |
811 BubbleGtk::ARROW_LOCATION_TOP_RIGHT; | 821 BubbleGtk::ARROW_LOCATION_TOP_RIGHT; |
812 avatar_button_->set_menu_arrow_location(arrow_location); | 822 avatar_button_->set_menu_arrow_location(arrow_location); |
813 } | |
814 } | 823 } |
815 | 824 |
816 void BrowserTitlebar::ShowFaviconMenu(GdkEventButton* event) { | 825 void BrowserTitlebar::ShowFaviconMenu(GdkEventButton* event) { |
817 if (!favicon_menu_model_.get()) { | 826 if (!favicon_menu_model_.get()) { |
818 favicon_menu_model_.reset( | 827 favicon_menu_model_.reset( |
819 new PopupPageMenuModel(this, browser_window_->browser())); | 828 new PopupPageMenuModel(this, browser_window_->browser())); |
820 | 829 |
821 favicon_menu_.reset(new MenuGtk(NULL, favicon_menu_model_.get())); | 830 favicon_menu_.reset(new MenuGtk(NULL, favicon_menu_model_.get())); |
822 } | 831 } |
823 | 832 |
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1050 // to NULL during that time. | 1059 // to NULL during that time. |
1051 if (!window_) | 1060 if (!window_) |
1052 return; | 1061 return; |
1053 | 1062 |
1054 window_has_focus_ = | 1063 window_has_focus_ = |
1055 gtk_widget_get_window(GTK_WIDGET(window_)) == active_window; | 1064 gtk_widget_get_window(GTK_WIDGET(window_)) == active_window; |
1056 UpdateTextColor(); | 1065 UpdateTextColor(); |
1057 } | 1066 } |
1058 | 1067 |
1059 bool BrowserTitlebar::ShouldDisplayAvatar() { | 1068 bool BrowserTitlebar::ShouldDisplayAvatar() { |
1060 return (IsOffTheRecord() || HasMultipleProfiles()) && | 1069 if (IsOffTheRecord() || ManagedMode::IsInManagedMode()) |
1061 browser_window_->browser()->is_type_tabbed(); | 1070 return true; |
1071 if (!browser_window_->browser()->is_type_tabbed()) | |
1072 return false; | |
1073 return AvatarMenuModel::ShouldShowAvatarMenu(); | |
1062 } | 1074 } |
1063 | 1075 |
1064 bool BrowserTitlebar::IsOffTheRecord() { | 1076 bool BrowserTitlebar::IsOffTheRecord() { |
1065 return browser_window_->browser()->profile()->IsOffTheRecord(); | 1077 return browser_window_->browser()->profile()->IsOffTheRecord(); |
1066 } | 1078 } |
1067 | 1079 |
1068 /////////////////////////////////////////////////////////////////////////////// | 1080 /////////////////////////////////////////////////////////////////////////////// |
1069 // BrowserTitlebar::Throbber implementation | 1081 // BrowserTitlebar::Throbber implementation |
1070 // TODO(tc): Handle anti-clockwise spinning when waiting for a connection. | 1082 // TODO(tc): Handle anti-clockwise spinning when waiting for a connection. |
1071 | 1083 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1125 ui::SimpleMenuModel::Delegate* delegate) | 1137 ui::SimpleMenuModel::Delegate* delegate) |
1126 : SimpleMenuModel(delegate) { | 1138 : SimpleMenuModel(delegate) { |
1127 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); | 1139 AddItemWithStringId(IDC_NEW_TAB, IDS_TAB_CXMENU_NEWTAB); |
1128 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); | 1140 AddItemWithStringId(IDC_RESTORE_TAB, IDS_RESTORE_TAB); |
1129 AddSeparator(); | 1141 AddSeparator(); |
1130 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); | 1142 AddItemWithStringId(IDC_TASK_MANAGER, IDS_TASK_MANAGER); |
1131 AddSeparator(); | 1143 AddSeparator(); |
1132 AddCheckItemWithStringId(kShowWindowDecorationsCommand, | 1144 AddCheckItemWithStringId(kShowWindowDecorationsCommand, |
1133 IDS_SHOW_WINDOW_DECORATIONS_MENU); | 1145 IDS_SHOW_WINDOW_DECORATIONS_MENU); |
1134 } | 1146 } |
OLD | NEW |