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 |
11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
12 #include "base/command_line.h" | 12 #include "base/command_line.h" |
13 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
14 #include "base/logging.h" | 14 #include "base/logging.h" |
15 #include "base/memory/singleton.h" | 15 #include "base/memory/singleton.h" |
16 #include "base/path_service.h" | 16 #include "base/path_service.h" |
17 #include "chrome/app/chrome_command_ids.h" | 17 #include "chrome/app/chrome_command_ids.h" |
18 #include "chrome/browser/net/url_fixer_upper.h" | 18 #include "chrome/browser/net/url_fixer_upper.h" |
19 #include "chrome/browser/prefs/pref_service.h" | 19 #include "chrome/browser/prefs/pref_service.h" |
20 #include "chrome/browser/profiles/profile.h" | 20 #include "chrome/browser/profiles/profile.h" |
21 #include "chrome/browser/themes/theme_service.h" | 21 #include "chrome/browser/themes/theme_service.h" |
22 #include "chrome/browser/ui/browser.h" | 22 #include "chrome/browser/ui/browser.h" |
23 #include "chrome/browser/ui/global_error_service.h" | 23 #include "chrome/browser/ui/global_error_service.h" |
24 #include "chrome/browser/ui/global_error_service_factory.h" | 24 #include "chrome/browser/ui/global_error_service_factory.h" |
25 #include "chrome/browser/ui/gtk/accelerators_gtk.h" | 25 #include "chrome/browser/ui/gtk/accelerators_gtk.h" |
26 #include "chrome/browser/ui/gtk/back_forward_button_gtk.h" | 26 #include "chrome/browser/ui/gtk/back_forward_button_gtk.h" |
27 #include "chrome/browser/ui/gtk/bookmark_sub_menu_model_gtk.h" | 27 #include "chrome/browser/ui/gtk/bookmark_sub_menu_model_gtk.h" |
28 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" | 28 #include "chrome/browser/ui/gtk/browser_actions_toolbar_gtk.h" |
29 #include "chrome/browser/ui/gtk/browser_window_gtk.h" | 29 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
30 #include "chrome/browser/ui/gtk/cairo_cached_surface.h" | |
31 #include "chrome/browser/ui/gtk/custom_button.h" | 30 #include "chrome/browser/ui/gtk/custom_button.h" |
32 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" | 31 #include "chrome/browser/ui/gtk/gtk_chrome_button.h" |
33 #include "chrome/browser/ui/gtk/gtk_theme_service.h" | 32 #include "chrome/browser/ui/gtk/gtk_theme_service.h" |
34 #include "chrome/browser/ui/gtk/gtk_util.h" | 33 #include "chrome/browser/ui/gtk/gtk_util.h" |
35 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" | 34 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
36 #include "chrome/browser/ui/gtk/reload_button_gtk.h" | 35 #include "chrome/browser/ui/gtk/reload_button_gtk.h" |
37 #include "chrome/browser/ui/gtk/rounded_window.h" | 36 #include "chrome/browser/ui/gtk/rounded_window.h" |
38 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" | 37 #include "chrome/browser/ui/gtk/tabs/tab_strip_gtk.h" |
39 #include "chrome/browser/ui/gtk/view_id_util.h" | 38 #include "chrome/browser/ui/gtk/view_id_util.h" |
40 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" | 39 #include "chrome/browser/ui/toolbar/encoding_menu_controller.h" |
41 #include "chrome/browser/upgrade_detector.h" | 40 #include "chrome/browser/upgrade_detector.h" |
42 #include "chrome/common/chrome_notification_types.h" | 41 #include "chrome/common/chrome_notification_types.h" |
43 #include "chrome/common/pref_names.h" | 42 #include "chrome/common/pref_names.h" |
44 #include "chrome/common/url_constants.h" | 43 #include "chrome/common/url_constants.h" |
45 #include "content/browser/tab_contents/tab_contents.h" | 44 #include "content/browser/tab_contents/tab_contents.h" |
46 #include "content/browser/user_metrics.h" | 45 #include "content/browser/user_metrics.h" |
47 #include "content/public/browser/notification_details.h" | 46 #include "content/public/browser/notification_details.h" |
48 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
49 #include "grit/chromium_strings.h" | 48 #include "grit/chromium_strings.h" |
50 #include "grit/generated_resources.h" | 49 #include "grit/generated_resources.h" |
51 #include "grit/theme_resources.h" | 50 #include "grit/theme_resources.h" |
52 #include "grit/theme_resources_standard.h" | 51 #include "grit/theme_resources_standard.h" |
53 #include "ui/base/accelerators/accelerator_gtk.h" | 52 #include "ui/base/accelerators/accelerator_gtk.h" |
54 #include "ui/base/dragdrop/gtk_dnd_util.h" | 53 #include "ui/base/dragdrop/gtk_dnd_util.h" |
55 #include "ui/base/l10n/l10n_util.h" | 54 #include "ui/base/l10n/l10n_util.h" |
56 #include "ui/gfx/canvas_skia_paint.h" | 55 #include "ui/gfx/canvas_skia_paint.h" |
57 #include "ui/gfx/gtk_util.h" | 56 #include "ui/gfx/gtk_util.h" |
| 57 #include "ui/gfx/image/cairo_cached_surface.h" |
58 #include "ui/gfx/skbitmap_operations.h" | 58 #include "ui/gfx/skbitmap_operations.h" |
59 | 59 |
60 namespace { | 60 namespace { |
61 | 61 |
62 // Padding on left and right of the left toolbar buttons (back, forward, reload, | 62 // Padding on left and right of the left toolbar buttons (back, forward, reload, |
63 // etc.). | 63 // etc.). |
64 const int kToolbarLeftAreaPadding = 4; | 64 const int kToolbarLeftAreaPadding = 4; |
65 | 65 |
66 // Height of the toolbar in pixels (not counting padding). | 66 // Height of the toolbar in pixels (not counting padding). |
67 const int kToolbarHeight = 29; | 67 const int kToolbarHeight = 29; |
(...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 gfx::Rect left(widget->allocation.x - kShadowThickness, | 496 gfx::Rect left(widget->allocation.x - kShadowThickness, |
497 widget->allocation.y - kShadowThickness, | 497 widget->allocation.y - kShadowThickness, |
498 kCornerWidth, | 498 kCornerWidth, |
499 widget->allocation.height + kShadowThickness); | 499 widget->allocation.height + kShadowThickness); |
500 | 500 |
501 if (window_->ShouldDrawContentDropShadow()) { | 501 if (window_->ShouldDrawContentDropShadow()) { |
502 // Leave room to draw rounded corners. | 502 // Leave room to draw rounded corners. |
503 area = area.Subtract(right).Subtract(left); | 503 area = area.Subtract(right).Subtract(left); |
504 } | 504 } |
505 | 505 |
506 CairoCachedSurface* background = theme_service_->GetSurfaceNamed( | 506 gfx::CairoCachedSurface* background = theme_service_->GetSurfaceNamed( |
507 IDR_THEME_TOOLBAR, widget); | 507 IDR_THEME_TOOLBAR, widget); |
508 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); | 508 background->SetSource(cr, widget, tabstrip_origin.x(), tabstrip_origin.y()); |
509 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 509 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
510 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height()); | 510 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height()); |
511 cairo_fill(cr); | 511 cairo_fill(cr); |
512 | 512 |
513 if (!window_->ShouldDrawContentDropShadow()) { | 513 if (!window_->ShouldDrawContentDropShadow()) { |
514 // The rest of this function is for rounded corners. Our work is done here. | 514 // The rest of this function is for rounded corners. Our work is done here. |
515 cairo_destroy(cr); | 515 cairo_destroy(cr); |
516 return FALSE; | 516 return FALSE; |
517 } | 517 } |
518 | 518 |
519 bool draw_left_corner = left.Intersects(gfx::Rect(e->area)); | 519 bool draw_left_corner = left.Intersects(gfx::Rect(e->area)); |
520 bool draw_right_corner = right.Intersects(gfx::Rect(e->area)); | 520 bool draw_right_corner = right.Intersects(gfx::Rect(e->area)); |
521 | 521 |
522 if (draw_left_corner || draw_right_corner) { | 522 if (draw_left_corner || draw_right_corner) { |
523 // Create a mask which is composed of the left and/or right corners. | 523 // Create a mask which is composed of the left and/or right corners. |
524 cairo_surface_t* target = cairo_surface_create_similar( | 524 cairo_surface_t* target = cairo_surface_create_similar( |
525 cairo_get_target(cr), | 525 cairo_get_target(cr), |
526 CAIRO_CONTENT_COLOR_ALPHA, | 526 CAIRO_CONTENT_COLOR_ALPHA, |
527 widget->allocation.x + widget->allocation.width, | 527 widget->allocation.x + widget->allocation.width, |
528 widget->allocation.y + widget->allocation.height); | 528 widget->allocation.y + widget->allocation.height); |
529 cairo_t* copy_cr = cairo_create(target); | 529 cairo_t* copy_cr = cairo_create(target); |
530 | 530 |
531 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE); | 531 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE); |
532 if (draw_left_corner) { | 532 if (draw_left_corner) { |
533 CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed( | 533 gfx::CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed( |
534 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget); | 534 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget); |
535 left_corner->SetSource(copy_cr, left.x(), left.y()); | 535 left_corner->SetSource(copy_cr, widget, left.x(), left.y()); |
536 cairo_paint(copy_cr); | 536 cairo_paint(copy_cr); |
537 } | 537 } |
538 if (draw_right_corner) { | 538 if (draw_right_corner) { |
539 CairoCachedSurface* right_corner = theme_service_->GetSurfaceNamed( | 539 gfx::CairoCachedSurface* right_corner = theme_service_->GetSurfaceNamed( |
540 IDR_CONTENT_TOP_RIGHT_CORNER_MASK, widget); | 540 IDR_CONTENT_TOP_RIGHT_CORNER_MASK, widget); |
541 right_corner->SetSource(copy_cr, right.x(), right.y()); | 541 right_corner->SetSource(copy_cr, widget, right.x(), right.y()); |
542 // We fill a path rather than just painting because we don't want to | 542 // We fill a path rather than just painting because we don't want to |
543 // overwrite the left corner. | 543 // overwrite the left corner. |
544 cairo_rectangle(copy_cr, right.x(), right.y(), | 544 cairo_rectangle(copy_cr, right.x(), right.y(), |
545 right.width(), right.height()); | 545 right.width(), right.height()); |
546 cairo_fill(copy_cr); | 546 cairo_fill(copy_cr); |
547 } | 547 } |
548 | 548 |
549 // Draw the background. CAIRO_OPERATOR_IN uses the existing pixel data as | 549 // Draw the background. CAIRO_OPERATOR_IN uses the existing pixel data as |
550 // an alpha mask. | 550 // an alpha mask. |
551 background->SetSource(copy_cr, tabstrip_origin.x(), tabstrip_origin.y()); | 551 background->SetSource(copy_cr, widget, |
| 552 tabstrip_origin.x(), tabstrip_origin.y()); |
552 cairo_set_operator(copy_cr, CAIRO_OPERATOR_IN); | 553 cairo_set_operator(copy_cr, CAIRO_OPERATOR_IN); |
553 cairo_pattern_set_extend(cairo_get_source(copy_cr), CAIRO_EXTEND_REPEAT); | 554 cairo_pattern_set_extend(cairo_get_source(copy_cr), CAIRO_EXTEND_REPEAT); |
554 cairo_paint(copy_cr); | 555 cairo_paint(copy_cr); |
555 cairo_destroy(copy_cr); | 556 cairo_destroy(copy_cr); |
556 | 557 |
557 // Copy the temporary surface to the screen. | 558 // Copy the temporary surface to the screen. |
558 cairo_set_source_surface(cr, target, 0, 0); | 559 cairo_set_source_surface(cr, target, 0, 0); |
559 cairo_paint(cr); | 560 cairo_paint(cr); |
560 cairo_surface_destroy(target); | 561 cairo_surface_destroy(target); |
561 } | 562 } |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
665 int x_offset = base::i18n::IsRTL() ? 0 : | 666 int x_offset = base::i18n::IsRTL() ? 0 : |
666 sender->allocation.width - badge->width(); | 667 sender->allocation.width - badge->width(); |
667 int y_offset = 0; | 668 int y_offset = 0; |
668 canvas.DrawBitmapInt( | 669 canvas.DrawBitmapInt( |
669 *badge, | 670 *badge, |
670 sender->allocation.x + x_offset, | 671 sender->allocation.x + x_offset, |
671 sender->allocation.y + y_offset); | 672 sender->allocation.y + y_offset); |
672 | 673 |
673 return FALSE; | 674 return FALSE; |
674 } | 675 } |
OLD | NEW |