| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/custom_button.h" | 5 #include "chrome/browser/ui/gtk/custom_button.h" |
| 6 | 6 |
| 7 #include "base/basictypes.h" | 7 #include "base/basictypes.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" | 9 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" |
| 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 10 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 paint_state == GTK_STATE_NORMAL; | 83 paint_state == GTK_STATE_NORMAL; |
| 84 CairoCachedSurface* pixbuf = PixbufForState(paint_state); | 84 CairoCachedSurface* pixbuf = PixbufForState(paint_state); |
| 85 CairoCachedSurface* hover_pixbuf = PixbufForState(GTK_STATE_PRELIGHT); | 85 CairoCachedSurface* hover_pixbuf = PixbufForState(GTK_STATE_PRELIGHT); |
| 86 | 86 |
| 87 if (!pixbuf || !pixbuf->valid()) | 87 if (!pixbuf || !pixbuf->valid()) |
| 88 return FALSE; | 88 return FALSE; |
| 89 if (animating_hover && (!hover_pixbuf || !hover_pixbuf->valid())) | 89 if (animating_hover && (!hover_pixbuf || !hover_pixbuf->valid())) |
| 90 return FALSE; | 90 return FALSE; |
| 91 | 91 |
| 92 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(widget->window)); | 92 cairo_t* cairo_context = gdk_cairo_create(GDK_DRAWABLE(widget->window)); |
| 93 cairo_translate(cairo_context, widget->allocation.x, widget->allocation.y); | 93 GtkAllocation allocation; |
| 94 gtk_widget_get_allocation(widget, &allocation); |
| 95 cairo_translate(cairo_context, allocation.x, allocation.y); |
| 94 | 96 |
| 95 if (flipped_) { | 97 if (flipped_) { |
| 96 // Horizontally flip the image for non-LTR/RTL reasons. | 98 // Horizontally flip the image for non-LTR/RTL reasons. |
| 97 cairo_translate(cairo_context, widget->allocation.width, 0.0f); | 99 cairo_translate(cairo_context, allocation.width, 0.0f); |
| 98 cairo_scale(cairo_context, -1.0f, 1.0f); | 100 cairo_scale(cairo_context, -1.0f, 1.0f); |
| 99 } | 101 } |
| 100 | 102 |
| 101 // The widget might be larger than the pixbuf. Paint the pixbuf flush with the | 103 // The widget might be larger than the pixbuf. Paint the pixbuf flush with the |
| 102 // start of the widget (left for LTR, right for RTL) and its bottom. | 104 // start of the widget (left for LTR, right for RTL) and its bottom. |
| 103 gfx::Rect bounds = gfx::Rect(0, 0, pixbuf->Width(), 0); | 105 gfx::Rect bounds = gfx::Rect(0, 0, pixbuf->Width(), 0); |
| 104 int x = gtk_util::MirroredLeftPointForRect(widget, bounds); | 106 int x = gtk_util::MirroredLeftPointForRect(widget, bounds); |
| 105 int y = widget->allocation.height - pixbuf->Height(); | 107 int y = allocation.height - pixbuf->Height(); |
| 106 | 108 |
| 107 if (background_image_->valid()) { | 109 if (background_image_->valid()) { |
| 108 background_image_->SetSource(cairo_context, x, y); | 110 background_image_->SetSource(cairo_context, x, y); |
| 109 cairo_paint(cairo_context); | 111 cairo_paint(cairo_context); |
| 110 } | 112 } |
| 111 | 113 |
| 112 pixbuf->SetSource(cairo_context, x, y); | 114 pixbuf->SetSource(cairo_context, x, y); |
| 113 cairo_paint(cairo_context); | 115 cairo_paint(cairo_context); |
| 114 | 116 |
| 115 if (animating_hover) { | 117 if (animating_hover) { |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 290 SetBrowserTheme(); | 292 SetBrowserTheme(); |
| 291 } | 293 } |
| 292 | 294 |
| 293 void CustomDrawButton::Observe(int type, | 295 void CustomDrawButton::Observe(int type, |
| 294 const content::NotificationSource& source, | 296 const content::NotificationSource& source, |
| 295 const content::NotificationDetails& details) { | 297 const content::NotificationDetails& details) { |
| 296 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); | 298 DCHECK(chrome::NOTIFICATION_BROWSER_THEME_CHANGED == type); |
| 297 SetBrowserTheme(); | 299 SetBrowserTheme(); |
| 298 } | 300 } |
| 299 | 301 |
| 302 int CustomDrawButton::WidgetWidth() const { |
| 303 GtkAllocation allocation; |
| 304 gtk_widget_get_allocation(widget_.get(), &allocation); |
| 305 return allocation.width; |
| 306 } |
| 307 |
| 300 int CustomDrawButton::SurfaceWidth() const { | 308 int CustomDrawButton::SurfaceWidth() const { |
| 301 return button_base_.Width(); | 309 return button_base_.Width(); |
| 302 } | 310 } |
| 303 | 311 |
| 304 int CustomDrawButton::SurfaceHeight() const { | 312 int CustomDrawButton::SurfaceHeight() const { |
| 305 return button_base_.Height(); | 313 return button_base_.Height(); |
| 306 } | 314 } |
| 307 | 315 |
| 308 void CustomDrawButton::SetPaintOverride(GtkStateType state) { | 316 void CustomDrawButton::SetPaintOverride(GtkStateType state) { |
| 309 button_base_.set_paint_override(state); | 317 button_base_.set_paint_override(state); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 357 } | 365 } |
| 358 | 366 |
| 359 gtk_chrome_button_set_use_gtk_rendering( | 367 gtk_chrome_button_set_use_gtk_rendering( |
| 360 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); | 368 GTK_CHROME_BUTTON(widget()), UseGtkTheme()); |
| 361 } | 369 } |
| 362 | 370 |
| 363 bool CustomDrawButton::UseGtkTheme() { | 371 bool CustomDrawButton::UseGtkTheme() { |
| 364 return !forcing_chrome_theme_ && theme_service_ && | 372 return !forcing_chrome_theme_ && theme_service_ && |
| 365 theme_service_->UsingNativeTheme(); | 373 theme_service_->UsingNativeTheme(); |
| 366 } | 374 } |
| OLD | NEW |