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/browser_toolbar_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_toolbar_gtk.h" |
6 | 6 |
7 #include <X11/XF86keysym.h> | 7 #include <X11/XF86keysym.h> |
8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
10 | 10 |
(...skipping 469 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 ThemeService::COLOR_TOOLBAR); | 480 ThemeService::COLOR_TOOLBAR); |
481 gdk_cairo_set_source_color(cr, &color); | 481 gdk_cairo_set_source_color(cr, &color); |
482 cairo_fill(cr); | 482 cairo_fill(cr); |
483 | 483 |
484 // The horizontal size of the top left and right corner images. | 484 // The horizontal size of the top left and right corner images. |
485 const int kCornerWidth = 4; | 485 const int kCornerWidth = 4; |
486 // The thickness of the shadow outside the toolbar's bounds; the offset | 486 // The thickness of the shadow outside the toolbar's bounds; the offset |
487 // between the edge of the toolbar and where we anchor the corner images. | 487 // between the edge of the toolbar and where we anchor the corner images. |
488 const int kShadowThickness = 2; | 488 const int kShadowThickness = 2; |
489 | 489 |
| 490 GtkAllocation allocation; |
| 491 gtk_widget_get_allocation(widget, &allocation); |
490 gfx::Rect area(e->area); | 492 gfx::Rect area(e->area); |
491 gfx::Rect right(widget->allocation.x + widget->allocation.width - | 493 gfx::Rect right(allocation.x + allocation.width - kCornerWidth, |
492 kCornerWidth, | 494 allocation.y - kShadowThickness, |
493 widget->allocation.y - kShadowThickness, | |
494 kCornerWidth, | 495 kCornerWidth, |
495 widget->allocation.height + kShadowThickness); | 496 allocation.height + kShadowThickness); |
496 gfx::Rect left(widget->allocation.x - kShadowThickness, | 497 gfx::Rect left(allocation.x - kShadowThickness, |
497 widget->allocation.y - kShadowThickness, | 498 allocation.y - kShadowThickness, |
498 kCornerWidth, | 499 kCornerWidth, |
499 widget->allocation.height + kShadowThickness); | 500 allocation.height + kShadowThickness); |
500 | 501 |
501 if (window_->ShouldDrawContentDropShadow()) { | 502 if (window_->ShouldDrawContentDropShadow()) { |
502 // Leave room to draw rounded corners. | 503 // Leave room to draw rounded corners. |
503 area = area.Subtract(right).Subtract(left); | 504 area = area.Subtract(right).Subtract(left); |
504 } | 505 } |
505 | 506 |
506 CairoCachedSurface* background = theme_service_->GetSurfaceNamed( | 507 CairoCachedSurface* background = theme_service_->GetSurfaceNamed( |
507 IDR_THEME_TOOLBAR, widget); | 508 IDR_THEME_TOOLBAR, widget); |
508 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); | 509 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); |
509 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 510 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
510 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height()); | 511 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height()); |
511 cairo_fill(cr); | 512 cairo_fill(cr); |
512 | 513 |
513 if (!window_->ShouldDrawContentDropShadow()) { | 514 if (!window_->ShouldDrawContentDropShadow()) { |
514 // The rest of this function is for rounded corners. Our work is done here. | 515 // The rest of this function is for rounded corners. Our work is done here. |
515 cairo_destroy(cr); | 516 cairo_destroy(cr); |
516 return FALSE; | 517 return FALSE; |
517 } | 518 } |
518 | 519 |
519 bool draw_left_corner = left.Intersects(gfx::Rect(e->area)); | 520 bool draw_left_corner = left.Intersects(gfx::Rect(e->area)); |
520 bool draw_right_corner = right.Intersects(gfx::Rect(e->area)); | 521 bool draw_right_corner = right.Intersects(gfx::Rect(e->area)); |
521 | 522 |
522 if (draw_left_corner || draw_right_corner) { | 523 if (draw_left_corner || draw_right_corner) { |
523 // Create a mask which is composed of the left and/or right corners. | 524 // Create a mask which is composed of the left and/or right corners. |
524 cairo_surface_t* target = cairo_surface_create_similar( | 525 cairo_surface_t* target = cairo_surface_create_similar( |
525 cairo_get_target(cr), | 526 cairo_get_target(cr), |
526 CAIRO_CONTENT_COLOR_ALPHA, | 527 CAIRO_CONTENT_COLOR_ALPHA, |
527 widget->allocation.x + widget->allocation.width, | 528 allocation.x + allocation.width, |
528 widget->allocation.y + widget->allocation.height); | 529 allocation.y + allocation.height); |
529 cairo_t* copy_cr = cairo_create(target); | 530 cairo_t* copy_cr = cairo_create(target); |
530 | 531 |
531 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE); | 532 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE); |
532 if (draw_left_corner) { | 533 if (draw_left_corner) { |
533 CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed( | 534 CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed( |
534 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget); | 535 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget); |
535 left_corner->SetSource(copy_cr, left.x(), left.y()); | 536 left_corner->SetSource(copy_cr, left.x(), left.y()); |
536 cairo_paint(copy_cr); | 537 cairo_paint(copy_cr); |
537 } | 538 } |
538 if (draw_right_corner) { | 539 if (draw_right_corner) { |
(...skipping 22 matching lines...) Expand all Loading... |
561 } | 562 } |
562 | 563 |
563 cairo_destroy(cr); | 564 cairo_destroy(cr); |
564 | 565 |
565 return FALSE; // Allow subwidgets to paint. | 566 return FALSE; // Allow subwidgets to paint. |
566 } | 567 } |
567 | 568 |
568 gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, | 569 gboolean BrowserToolbarGtk::OnLocationHboxExpose(GtkWidget* location_hbox, |
569 GdkEventExpose* e) { | 570 GdkEventExpose* e) { |
570 if (theme_service_->UsingNativeTheme()) { | 571 if (theme_service_->UsingNativeTheme()) { |
| 572 GtkAllocation allocation; |
| 573 gtk_widget_get_allocation(location_hbox, &allocation); |
571 gtk_util::DrawTextEntryBackground(offscreen_entry_.get(), | 574 gtk_util::DrawTextEntryBackground(offscreen_entry_.get(), |
572 location_hbox, &e->area, | 575 location_hbox, &e->area, |
573 &location_hbox->allocation); | 576 &allocation); |
574 } | 577 } |
575 | 578 |
576 return FALSE; | 579 return FALSE; |
577 } | 580 } |
578 | 581 |
579 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button) { | 582 void BrowserToolbarGtk::OnButtonClick(GtkWidget* button) { |
580 if ((button == back_->widget()) || (button == forward_->widget())) { | 583 if ((button == back_->widget()) || (button == forward_->widget())) { |
581 if (gtk_util::DispositionForCurrentButtonPressEvent() == CURRENT_TAB) | 584 if (gtk_util::DispositionForCurrentButtonPressEvent() == CURRENT_TAB) |
582 location_bar_->Revert(); | 585 location_bar_->Revert(); |
583 return; | 586 return; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
652 resource_id = UpgradeDetector::GetInstance()->GetIconResourceID( | 655 resource_id = UpgradeDetector::GetInstance()->GetIconResourceID( |
653 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE); | 656 UpgradeDetector::UPGRADE_ICON_TYPE_BADGE); |
654 } else { | 657 } else { |
655 resource_id = GlobalErrorServiceFactory::GetForProfile( | 658 resource_id = GlobalErrorServiceFactory::GetForProfile( |
656 browser_->profile())->GetFirstBadgeResourceID(); | 659 browser_->profile())->GetFirstBadgeResourceID(); |
657 } | 660 } |
658 | 661 |
659 if (!resource_id) | 662 if (!resource_id) |
660 return FALSE; | 663 return FALSE; |
661 | 664 |
| 665 GtkAllocation allocation; |
| 666 gtk_widget_get_allocation(sender, &allocation); |
| 667 |
662 // Draw the chrome app menu icon onto the canvas. | 668 // Draw the chrome app menu icon onto the canvas. |
663 const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id); | 669 const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id); |
664 gfx::CanvasSkiaPaint canvas(expose, false); | 670 gfx::CanvasSkiaPaint canvas(expose, false); |
665 int x_offset = base::i18n::IsRTL() ? 0 : | 671 int x_offset = base::i18n::IsRTL() ? 0 : allocation.width - badge->width(); |
666 sender->allocation.width - badge->width(); | |
667 int y_offset = 0; | 672 int y_offset = 0; |
668 canvas.DrawBitmapInt( | 673 canvas.DrawBitmapInt(*badge, |
669 *badge, | 674 allocation.x + x_offset, |
670 sender->allocation.x + x_offset, | 675 allocation.y + y_offset); |
671 sender->allocation.y + y_offset); | |
672 | 676 |
673 return FALSE; | 677 return FALSE; |
674 } | 678 } |
OLD | NEW |