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

Side by Side Diff: chrome/browser/gtk/blocked_popup_container_view_gtk.cc

Issue 149277: GTK Themes: Theme the popup notification. (Closed)
Patch Set: lint + comments Created 11 years, 5 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
OLDNEW
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/profile.h" 13 #include "chrome/browser/profile.h"
13 #include "chrome/browser/tab_contents/tab_contents.h" 14 #include "chrome/browser/tab_contents/tab_contents.h"
14 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h" 15 #include "chrome/browser/tab_contents/tab_contents_view_gtk.h"
15 #include "chrome/common/gtk_util.h" 16 #include "chrome/common/gtk_util.h"
16 #include "grit/generated_resources.h" 17 #include "grit/generated_resources.h"
17 #include "grit/theme_resources.h" 18 #include "grit/theme_resources.h"
18 19
19 namespace { 20 namespace {
20 // The minimal border around the edge of the notification. 21 // The minimal border around the edge of the notification.
21 const int kSmallPadding = 2; 22 const int kSmallPadding = 2;
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup( 54 void BlockedPopupContainerViewGtk::GetURLAndTitleForPopup(
54 size_t index, string16* url, string16* title) const { 55 size_t index, string16* url, string16* title) const {
55 DCHECK(url); 56 DCHECK(url);
56 DCHECK(title); 57 DCHECK(title);
57 TabContents* tab_contents = model_->GetTabContentsAt(index); 58 TabContents* tab_contents = model_->GetTabContentsAt(index);
58 const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin(); 59 const GURL& tab_contents_url = tab_contents->GetURL().GetOrigin();
59 *url = UTF8ToUTF16(tab_contents_url.possibly_invalid_spec()); 60 *url = UTF8ToUTF16(tab_contents_url.possibly_invalid_spec());
60 *title = tab_contents->GetTitle(); 61 *title = tab_contents->GetTitle();
61 } 62 }
62 63
64 void BlockedPopupContainerViewGtk::UserChangedTheme(
65 GtkThemeProperties* properties) {
66 use_gtk_rendering_ = properties->use_gtk_rendering;
67
68 gtk_chrome_button_set_use_gtk_rendering(
69 GTK_CHROME_BUTTON(menu_button_), use_gtk_rendering_);
70 }
71
63 // Overridden from BlockedPopupContainerView: 72 // Overridden from BlockedPopupContainerView:
64 void BlockedPopupContainerViewGtk::SetPosition() { 73 void BlockedPopupContainerViewGtk::SetPosition() {
65 // No-op. Not required with the GTK version. 74 // No-op. Not required with the GTK version.
66 } 75 }
67 76
68 void BlockedPopupContainerViewGtk::ShowView() { 77 void BlockedPopupContainerViewGtk::ShowView() {
69 // TODO(erg): Animate in. 78 // TODO(erg): Animate in.
70 gtk_widget_show_all(container_.get()); 79 gtk_widget_show_all(container_.get());
71 } 80 }
72 81
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 model_->ToggleWhitelistingForHost( 124 model_->ToggleWhitelistingForHost(
116 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1); 125 id_size_t - BlockedPopupContainer::kImpossibleNumberOfPopups - 1);
117 } else { 126 } else {
118 model_->LaunchPopupAtIndex(id_size_t - 1); 127 model_->LaunchPopupAtIndex(id_size_t - 1);
119 } 128 }
120 } 129 }
121 130
122 BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk( 131 BlockedPopupContainerViewGtk::BlockedPopupContainerViewGtk(
123 BlockedPopupContainer* container) 132 BlockedPopupContainer* container)
124 : model_(container), 133 : model_(container),
134 use_gtk_rendering_(false),
125 close_button_(CustomDrawButton::CloseButton()) { 135 close_button_(CustomDrawButton::CloseButton()) {
126 Init(); 136 Init();
137
138 GtkThemeProperties properties(container->profile());
139 UserChangedTheme(&properties);
127 } 140 }
128 141
129 void BlockedPopupContainerViewGtk::Init() { 142 void BlockedPopupContainerViewGtk::Init() {
130 menu_button_ = gtk_chrome_button_new(); 143 menu_button_ = gtk_chrome_button_new();
131 UpdateLabel(); 144 UpdateLabel();
132 g_signal_connect(menu_button_, "clicked", 145 g_signal_connect(menu_button_, "clicked",
133 G_CALLBACK(OnMenuButtonClicked), this); 146 G_CALLBACK(OnMenuButtonClicked), this);
134 147
135 GtkWidget* hbox = gtk_hbox_new(FALSE, 0); 148 GtkWidget* hbox = gtk_hbox_new(FALSE, 0);
136 gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, kSmallPadding); 149 gtk_box_pack_start(GTK_BOX(hbox), menu_button_, FALSE, FALSE, kSmallPadding);
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
178 container->launch_menu_->PopupAsContext(gtk_get_current_event_time()); 191 container->launch_menu_->PopupAsContext(gtk_get_current_event_time());
179 } 192 }
180 193
181 void BlockedPopupContainerViewGtk::OnCloseButtonClicked( 194 void BlockedPopupContainerViewGtk::OnCloseButtonClicked(
182 GtkButton *button, BlockedPopupContainerViewGtk* container) { 195 GtkButton *button, BlockedPopupContainerViewGtk* container) {
183 container->model_->set_dismissed(); 196 container->model_->set_dismissed();
184 container->model_->CloseAll(); 197 container->model_->CloseAll();
185 } 198 }
186 199
187 gboolean BlockedPopupContainerViewGtk::OnContainerExpose( 200 gboolean BlockedPopupContainerViewGtk::OnContainerExpose(
188 GtkWidget* widget, GdkEventExpose* event) { 201 GtkWidget* widget, GdkEventExpose* event,
189 // TODO(erg): When evanm comes through the code, adding gtk theme support, 202 BlockedPopupContainerViewGtk* container) {
190 // what's here needs to go in a if block and the else should just paint the
191 // normal theme background with a border around the outsides.
192 int width = widget->allocation.width; 203 int width = widget->allocation.width;
193 int height = widget->allocation.height; 204 int height = widget->allocation.height;
194 int half_width = width / 2;
195 205
196 // Clip to our damage rect 206 // Clip to our damage rect
197 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window)); 207 cairo_t* cr = gdk_cairo_create(GDK_DRAWABLE(widget->window));
198 cairo_rectangle(cr, event->area.x, event->area.y, 208 cairo_rectangle(cr, event->area.x, event->area.y,
199 event->area.width, event->area.height); 209 event->area.width, event->area.height);
200 cairo_clip(cr); 210 cairo_clip(cr);
201 211
202 // Draws our background gradient. 212 if (!container->use_gtk_rendering_) {
203 cairo_pattern_t* pattern = cairo_pattern_create_linear( 213 // TODO(erg): We draw the gradient background only when GTK themes are
tony 2009/07/07 20:46:29 I see, so we still draw the background, it's just
204 half_width, 0, half_width, height); 214 // off. This isn't a perfect solution as this isn't themed! The views
205 cairo_pattern_add_color_stop_rgb( 215 // version doesn't appear to be themed either, so at least for now,
206 pattern, 0.0, 216 // constants are OK.
207 kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]); 217 int half_width = width / 2;
208 cairo_pattern_add_color_stop_rgb( 218 cairo_pattern_t* pattern = cairo_pattern_create_linear(
209 pattern, 1.0, 219 half_width, 0, half_width, height);
210 kBackgroundColorBottom[0], kBackgroundColorBottom[1], 220 cairo_pattern_add_color_stop_rgb(
211 kBackgroundColorBottom[2]); 221 pattern, 0.0,
212 cairo_set_source(cr, pattern); 222 kBackgroundColorTop[0], kBackgroundColorTop[1], kBackgroundColorTop[2]);
213 cairo_paint(cr); 223 cairo_pattern_add_color_stop_rgb(
214 cairo_pattern_destroy(pattern); 224 pattern, 1.0,
225 kBackgroundColorBottom[0], kBackgroundColorBottom[1],
226 kBackgroundColorBottom[2]);
227 cairo_set_source(cr, pattern);
228 cairo_paint(cr);
229 cairo_pattern_destroy(pattern);
230 }
231
232 // TODO(erg): We need to figure out the border situation, too. We aren't
233 // provided a color from the theme system and the Windows implementation
234 // still uses constants for color. See the status bubble, too.
215 235
216 // Sets up our stroke pen. 236 // Sets up our stroke pen.
217 cairo_set_source_rgb(cr, kBorderColor[0], kBorderColor[1], kBorderColor[2]); 237 cairo_set_source_rgb(cr, kBorderColor[0], kBorderColor[1], kBorderColor[2]);
218 cairo_set_line_width(cr, 1.5); 238 cairo_set_line_width(cr, 1.5);
219 239
220 // Draws rounded corners around the edge of the notification, clockwise 240 // Draws rounded corners around the edge of the notification, clockwise
221 // starting from the bottom left. (A bezier curve with control points at 90 241 // starting from the bottom left. (A bezier curve with control points at 90
222 // degree angles forms a circular arc.) 242 // degree angles forms a circular arc.)
223 cairo_move_to(cr, 0, height); 243 cairo_move_to(cr, 0, height);
224 cairo_line_to(cr, 0, kBackgroundCornerRadius); 244 cairo_line_to(cr, 0, kBackgroundCornerRadius);
225 cairo_curve_to(cr, 0, kBackgroundCornerRadius, 245 cairo_curve_to(cr, 0, kBackgroundCornerRadius,
226 0, 0, kBackgroundCornerRadius, 0); 246 0, 0, kBackgroundCornerRadius, 0);
227 cairo_line_to(cr, width - kBackgroundCornerRadius, 0); 247 cairo_line_to(cr, width - kBackgroundCornerRadius, 0);
228 cairo_curve_to(cr, width - kBackgroundCornerRadius, 0, 248 cairo_curve_to(cr, width - kBackgroundCornerRadius, 0,
229 width, 0, width, kBackgroundCornerRadius); 249 width, 0, width, kBackgroundCornerRadius);
230 cairo_line_to(cr, width, height); 250 cairo_line_to(cr, width, height);
231 cairo_stroke(cr); 251 cairo_stroke(cr);
232 252
233 cairo_destroy(cr); 253 cairo_destroy(cr);
234 254
235 return FALSE; // Allow subwidgets to paint. 255 return FALSE; // Allow subwidgets to paint.
236 } 256 }
OLDNEW
« no previous file with comments | « chrome/browser/gtk/blocked_popup_container_view_gtk.h ('k') | chrome/browser/tab_contents/tab_contents_view_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698