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

Side by Side Diff: chrome/browser/ui/libgtk2ui/gtk2_ui.cc

Issue 132023010: linux_aura: Fixes a couple of issues with the button border integration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: msw's return statement comment Created 6 years, 11 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
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/libgtk2ui/gtk2_ui.h" 5 #include "chrome/browser/ui/libgtk2ui/gtk2_ui.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/environment.h" 10 #include "base/environment.h"
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 521
522 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get()); 522 SkBitmap bitmap = GdkPixbufToImageSkia(pixbuf.get());
523 DCHECK_EQ(size, bitmap.width()); 523 DCHECK_EQ(size, bitmap.width());
524 DCHECK_EQ(size, bitmap.height()); 524 DCHECK_EQ(size, bitmap.height());
525 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap); 525 gfx::ImageSkia image_skia = gfx::ImageSkia::CreateFrom1xBitmap(bitmap);
526 image_skia.MakeThreadSafe(); 526 image_skia.MakeThreadSafe();
527 return gfx::Image(image_skia); 527 return gfx::Image(image_skia);
528 } 528 }
529 529
530 scoped_ptr<views::Border> Gtk2UI::CreateNativeBorder( 530 scoped_ptr<views::Border> Gtk2UI::CreateNativeBorder(
531 views::CustomButton* owning_button, 531 views::LabelButton* owning_button,
532 scoped_ptr<views::Border> border) { 532 scoped_ptr<views::Border> border) {
533 return scoped_ptr<views::Border>( 533 return scoped_ptr<views::Border>(
534 new Gtk2Border(this, owning_button, border.Pass())); 534 new Gtk2Border(this, owning_button, border.Pass()));
535 } 535 }
536 536
537 void Gtk2UI::AddWindowButtonOrderObserver( 537 void Gtk2UI::AddWindowButtonOrderObserver(
538 views::WindowButtonOrderObserver* observer) { 538 views::WindowButtonOrderObserver* observer) {
539 if (!leading_buttons_.empty() || !trailing_buttons_.empty()) { 539 if (!leading_buttons_.empty() || !trailing_buttons_.empty()) {
540 observer->OnWindowButtonOrderingChange(leading_buttons_, 540 observer->OnWindowButtonOrderingChange(leading_buttons_,
541 trailing_buttons_); 541 trailing_buttons_);
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after
1176 retval.allocPixels(); 1176 retval.allocPixels();
1177 retval.eraseColor(0); 1177 retval.eraseColor(0);
1178 1178
1179 const SkBitmap icon = GdkPixbufToImageSkia(gdk_icon); 1179 const SkBitmap icon = GdkPixbufToImageSkia(gdk_icon);
1180 g_object_unref(gdk_icon); 1180 g_object_unref(gdk_icon);
1181 1181
1182 SkCanvas canvas(retval); 1182 SkCanvas canvas(retval);
1183 1183
1184 if (gtk_state == GTK_STATE_ACTIVE || gtk_state == GTK_STATE_PRELIGHT) { 1184 if (gtk_state == GTK_STATE_ACTIVE || gtk_state == GTK_STATE_PRELIGHT) {
1185 SkBitmap border = DrawGtkButtonBorder(gtk_state, 1185 SkBitmap border = DrawGtkButtonBorder(gtk_state,
1186 false,
1186 default_bitmap.width(), 1187 default_bitmap.width(),
1187 default_bitmap.height()); 1188 default_bitmap.height());
1188 canvas.drawBitmap(border, 0, 0); 1189 canvas.drawBitmap(border, 0, 0);
1189 } 1190 }
1190 1191
1191 canvas.drawBitmap(icon, 1192 canvas.drawBitmap(icon,
1192 (default_bitmap.width() / 2) - (icon.width() / 2), 1193 (default_bitmap.width() / 2) - (icon.width() / 2),
1193 (default_bitmap.height() / 2) - (icon.height() / 2)); 1194 (default_bitmap.height() / 2) - (icon.height() / 2));
1194 1195
1195 return retval; 1196 return retval;
1196 } 1197 }
1197 1198
1198 SkBitmap Gtk2UI::GenerateToolbarBezel(int gtk_state, int sizing_idr) const { 1199 SkBitmap Gtk2UI::GenerateToolbarBezel(int gtk_state, int sizing_idr) const {
1199 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 1200 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
1200 SkBitmap default_bitmap = 1201 SkBitmap default_bitmap =
1201 rb.GetImageNamed(sizing_idr).AsBitmap(); 1202 rb.GetImageNamed(sizing_idr).AsBitmap();
1202 1203
1203 SkBitmap retval; 1204 SkBitmap retval;
1204 retval.setConfig(SkBitmap::kARGB_8888_Config, 1205 retval.setConfig(SkBitmap::kARGB_8888_Config,
1205 default_bitmap.width(), 1206 default_bitmap.width(),
1206 default_bitmap.height()); 1207 default_bitmap.height());
1207 retval.allocPixels(); 1208 retval.allocPixels();
1208 retval.eraseColor(0); 1209 retval.eraseColor(0);
1209 1210
1210 SkCanvas canvas(retval); 1211 SkCanvas canvas(retval);
1211 SkBitmap border = DrawGtkButtonBorder( 1212 SkBitmap border = DrawGtkButtonBorder(
1212 gtk_state, 1213 gtk_state,
1214 false,
1213 default_bitmap.width(), 1215 default_bitmap.width(),
1214 default_bitmap.height()); 1216 default_bitmap.height());
1215 canvas.drawBitmap(border, 0, 0); 1217 canvas.drawBitmap(border, 0, 0);
1216 1218
1217 return retval; 1219 return retval;
1218 } 1220 }
1219 1221
1220 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const { 1222 void Gtk2UI::GetNormalButtonTintHSL(color_utils::HSL* tint) const {
1221 GtkStyle* window_style = gtk_rc_get_style(fake_window_); 1223 GtkStyle* window_style = gtk_rc_get_style(fake_window_);
1222 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED]; 1224 const GdkColor accent_gdk_color = window_style->bg[GTK_STATE_SELECTED];
(...skipping 19 matching lines...) Expand all
1242 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const { 1244 void Gtk2UI::GetSelectedEntryForegroundHSL(color_utils::HSL* tint) const {
1243 // The simplest of all the tints. We just use the selected text in the entry 1245 // The simplest of all the tints. We just use the selected text in the entry
1244 // since the icons tinted this way will only be displayed against 1246 // since the icons tinted this way will only be displayed against
1245 // base[GTK_STATE_SELECTED]. 1247 // base[GTK_STATE_SELECTED].
1246 GtkStyle* style = gtk_rc_get_style(fake_entry_.get()); 1248 GtkStyle* style = gtk_rc_get_style(fake_entry_.get());
1247 const GdkColor color = style->text[GTK_STATE_SELECTED]; 1249 const GdkColor color = style->text[GTK_STATE_SELECTED];
1248 color_utils::SkColorToHSL(GdkColorToSkColor(color), tint); 1250 color_utils::SkColorToHSL(GdkColorToSkColor(color), tint);
1249 } 1251 }
1250 1252
1251 SkBitmap Gtk2UI::DrawGtkButtonBorder(int gtk_state, 1253 SkBitmap Gtk2UI::DrawGtkButtonBorder(int gtk_state,
1252 int width, int height) const { 1254 bool focused,
1255 int width,
1256 int height) const {
1253 // Create a temporary GTK button to snapshot 1257 // Create a temporary GTK button to snapshot
1254 GtkWidget* window = gtk_offscreen_window_new(); 1258 GtkWidget* window = gtk_offscreen_window_new();
1255 GtkWidget* button = gtk_button_new(); 1259 GtkWidget* button = gtk_button_new();
1256 gtk_widget_set_size_request(button, width, height); 1260 gtk_widget_set_size_request(button, width, height);
1257 gtk_container_add(GTK_CONTAINER(window), button); 1261 gtk_container_add(GTK_CONTAINER(window), button);
1258 gtk_widget_realize(window); 1262 gtk_widget_realize(window);
1259 gtk_widget_realize(button); 1263 gtk_widget_realize(button);
1260 gtk_widget_show(button); 1264 gtk_widget_show(button);
1261 gtk_widget_show(window); 1265 gtk_widget_show(window);
1262 1266
1267 if (focused) {
1268 // We can't just use gtk_widget_grab_focus() here because that sets
1269 // gtk_widget_is_focus(), but not gtk_widget_has_focus(), which is what the
1270 // GtkButton's paint checks.
1271 GTK_WIDGET_SET_FLAGS(button, GTK_HAS_FOCUS);
1272 }
1273
1263 gtk_widget_set_state(button, static_cast<GtkStateType>(gtk_state)); 1274 gtk_widget_set_state(button, static_cast<GtkStateType>(gtk_state));
1264 1275
1265 GdkPixmap* pixmap = gtk_widget_get_snapshot(button, NULL); 1276 GdkPixmap* pixmap = gtk_widget_get_snapshot(button, NULL);
1266 int w, h; 1277 int w, h;
1267 gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h); 1278 gdk_drawable_get_size(GDK_DRAWABLE(pixmap), &w, &h);
1268 DCHECK_EQ(w, width); 1279 DCHECK_EQ(w, width);
1269 DCHECK_EQ(h, height); 1280 DCHECK_EQ(h, height);
1270 1281
1271 // We render the Pixmap to a Pixbuf. This can be slow, as we're scrapping 1282 // We render the Pixmap to a Pixbuf. This can be slow, as we're scrapping
1272 // bits from X. 1283 // bits from X.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1323 1334
1324 void Gtk2UI::ClearAllThemeData() { 1335 void Gtk2UI::ClearAllThemeData() {
1325 gtk_images_.clear(); 1336 gtk_images_.clear();
1326 } 1337 }
1327 1338
1328 } // namespace libgtk2ui 1339 } // namespace libgtk2ui
1329 1340
1330 views::LinuxUI* BuildGtk2UI() { 1341 views::LinuxUI* BuildGtk2UI() {
1331 return new libgtk2ui::Gtk2UI; 1342 return new libgtk2ui::Gtk2UI;
1332 } 1343 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698