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

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

Powered by Google App Engine
This is Rietveld 408576698