OLD | NEW |
---|---|
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
3 // LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" | 5 #include "chrome/browser/gtk/blocked_popup_container_view_gtk.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/gfx/gtk_util.h" | 8 #include "base/gfx/gtk_util.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "chrome/browser/gtk/custom_button.h" | 10 #include "chrome/browser/gtk/custom_button.h" |
11 #include "chrome/browser/gtk/gtk_chrome_button.h" | 11 #include "chrome/browser/gtk/gtk_chrome_button.h" |
12 #include "chrome/browser/gtk/gtk_theme_provider.h" | 12 #include "chrome/browser/gtk/gtk_theme_provider.h" |
13 #include "chrome/browser/profile.h" | 13 #include "chrome/browser/profile.h" |
14 #include "chrome/browser/tab_contents/tab_contents.h" | 14 #include "chrome/browser/tab_contents/tab_contents.h" |
15 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" | 15 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" |
16 #include "chrome/common/gtk_util.h" | 16 #include "chrome/common/gtk_util.h" |
17 #include "chrome/common/notification_service.h" | |
17 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
18 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
19 | 20 |
20 namespace { | 21 namespace { |
21 // The minimal border around the edge of the notification. | 22 // The minimal border around the edge of the notification. |
22 const int kSmallPadding = 2; | 23 const int kSmallPadding = 2; |
23 | 24 |
24 // Size of the border painted in kBorderColor | 25 // Size of the border painted in kBorderColor |
25 const int kBorderPadding = 1; | 26 const int kBorderPadding = 1; |
26 | 27 |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
67 } | 68 } |
68 | 69 |
69 void BlockedPopupContainerViewGtk::ShowView() { | 70 void BlockedPopupContainerViewGtk::ShowView() { |
70 // TODO(erg): Animate in. | 71 // TODO(erg): Animate in. |
71 gtk_widget_show_all(container_.get()); | 72 gtk_widget_show_all(container_.get()); |
72 } | 73 } |
73 | 74 |
74 void BlockedPopupContainerViewGtk::UpdateLabel() { | 75 void BlockedPopupContainerViewGtk::UpdateLabel() { |
75 size_t blocked_popups = model_->GetBlockedPopupCount(); | 76 size_t blocked_popups = model_->GetBlockedPopupCount(); |
76 | 77 |
77 gtk_button_set_label( | 78 GtkWidget* label = gtk_bin_get_child(GTK_BIN(menu_button_)); |
78 GTK_BUTTON(menu_button_), | 79 if (!label) { |
80 label = gtk_label_new(""); | |
81 gtk_container_add(GTK_CONTAINER(menu_button_), label); | |
82 } | |
83 | |
84 gtk_label_set_text( | |
85 GTK_LABEL(label), | |
79 (blocked_popups > 0) ? | 86 (blocked_popups > 0) ? |
80 l10n_util::GetStringFUTF8(IDS_POPUPS_BLOCKED_COUNT, | 87 l10n_util::GetStringFUTF8(IDS_POPUPS_BLOCKED_COUNT, |
81 UintToString16(blocked_popups)).c_str() : | 88 UintToString16(blocked_popups)).c_str() : |
82 l10n_util::GetStringUTF8(IDS_POPUPS_UNBLOCKED).c_str()); | 89 l10n_util::GetStringUTF8(IDS_POPUPS_UNBLOCKED).c_str()); |
83 } | 90 } |
84 | 91 |
85 void BlockedPopupContainerViewGtk::HideView() { | 92 void BlockedPopupContainerViewGtk::HideView() { |
86 // TODO(erg): Animate out. | 93 // TODO(erg): Animate out. |
87 gtk_widget_hide(container_.get()); | 94 gtk_widget_hide(container_.get()); |
88 } | 95 } |
89 | 96 |
90 void BlockedPopupContainerViewGtk::Destroy() { | 97 void BlockedPopupContainerViewGtk::Destroy() { |
91 ContainingView()->RemoveBlockedPopupView(this); | 98 ContainingView()->RemoveBlockedPopupView(this); |
92 delete this; | 99 delete this; |
93 } | 100 } |
94 | 101 |
102 void BlockedPopupContainerViewGtk::Observe(NotificationType type, | |
103 const NotificationSource& source, | |
104 const NotificationDetails& details) { | |
105 if (type == NotificationType::BROWSER_THEME_CHANGED) { | |
Evan Stade
2009/07/21 20:00:41
in the interest of keeping things as little indent
| |
106 // Make sure the label exists (so we can change its colors). | |
107 UpdateLabel(); | |
108 | |
109 // Update the label's colors. | |
110 GtkWidget* label = gtk_bin_get_child(GTK_BIN(menu_button_)); | |
111 if (theme_provider_->UseGtkTheme()) { | |
112 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, NULL); | |
113 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, NULL); | |
114 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, NULL); | |
115 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, NULL); | |
116 } else { | |
117 GdkColor color = theme_provider_->GetGdkColor( | |
118 BrowserThemeProvider::COLOR_BOOKMARK_TEXT); | |
119 gtk_widget_modify_fg(label, GTK_STATE_NORMAL, &color); | |
120 gtk_widget_modify_fg(label, GTK_STATE_ACTIVE, &color); | |
121 gtk_widget_modify_fg(label, GTK_STATE_PRELIGHT, &color); | |
122 gtk_widget_modify_fg(label, GTK_STATE_INSENSITIVE, &color); | |
123 } | |
124 } else { | |
125 NOTREACHED(); | |
126 } | |
127 } | |
128 | |
95 bool BlockedPopupContainerViewGtk::IsCommandEnabled(int command_id) const { | 129 bool BlockedPopupContainerViewGtk::IsCommandEnabled(int command_id) const { |
96 return true; | 130 return true; |
97 } | 131 } |
98 | 132 |
99 bool BlockedPopupContainerViewGtk::IsItemChecked(int id) const { | 133 bool BlockedPopupContainerViewGtk::IsItemChecked(int id) const { |
100 DCHECK_GT(id, 0); | 134 DCHECK_GT(id, 0); |
101 size_t id_size_t = static_cast<size_t>(id); | 135 size_t id_size_t = static_cast<size_t>(id); |
102 if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) { | 136 if (id_size_t > BlockedPopupContainer::kImpossibleNumberOfPopups) { |
103 return model_->IsHostWhitelisted( | 137 return model_->IsHostWhitelisted( |
104 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1); | 138 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1); |
(...skipping 14 matching lines...) Expand all Loading... | |
119 model_->LaunchPopupAtIndex(id_size_t - 1); | 153 model_->LaunchPopupAtIndex(id_size_t - 1); |
120 } | 154 } |
121 } | 155 } |
122 | 156 |
123 BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk( | 157 BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk( |
124 BlockedPopupContainer* container) | 158 BlockedPopupContainer* container) |
125 : model_(container), | 159 : model_(container), |
126 theme_provider_(GtkThemeProvider::GetFrom(container->profile())), | 160 theme_provider_(GtkThemeProvider::GetFrom(container->profile())), |
127 close_button_(CustomDrawButton::CloseButton()) { | 161 close_button_(CustomDrawButton::CloseButton()) { |
128 Init(); | 162 Init(); |
163 | |
164 registrar_.Add(this, | |
165 NotificationType::BROWSER_THEME_CHANGED, | |
166 NotificationService::AllSources()); | |
167 theme_provider_->InitThemesFor(this); | |
129 } | 168 } |
130 | 169 |
131 void BlockedPopupContainerViewGtk::Init() { | 170 void BlockedPopupContainerViewGtk::Init() { |
132 menu_button_ = theme_provider_->BuildChromeButton(); | 171 menu_button_ = theme_provider_->BuildChromeButton(); |
133 UpdateLabel(); | 172 UpdateLabel(); |
134 g_signal_connect(menu_button_, "clicked", | 173 g_signal_connect(menu_button_, "clicked", |
135 G_CALLBACK(OnMenuButtonClicked), this); | 174 G_CALLBACK(OnMenuButtonClicked), this); |
136 | 175 |
137 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); | 176 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); |
138 gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, kSmallPadding); | 177 gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, kSmallPadding); |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
236 cairo_line_to(cr, width - kBackgroundCornerRadius, 0); | 275 cairo_line_to(cr, width - kBackgroundCornerRadius, 0); |
237 cairo_curve_to(cr, width - kBackgroundCornerRadius, 0, | 276 cairo_curve_to(cr, width - kBackgroundCornerRadius, 0, |
238 width, 0, width, kBackgroundCornerRadius); | 277 width, 0, width, kBackgroundCornerRadius); |
239 cairo_line_to(cr, width, height); | 278 cairo_line_to(cr, width, height); |
240 cairo_stroke(cr); | 279 cairo_stroke(cr); |
241 | 280 |
242 cairo_destroy(cr); | 281 cairo_destroy(cr); |
243 | 282 |
244 return FALSE; // Allow subwidgets to paint. | 283 return FALSE; // Allow subwidgets to paint. |
245 } | 284 } |
OLD | NEW |