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

Side by Side Diff: chrome/browser/ui/gtk/browser_toolbar_gtk.cc

Issue 8769017: GTK: Move CairoCachedSurface from being owned by GtkThemeService to gfx::Image. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase for commit Created 9 years 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
OLDNEW
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/bookmarks/bookmark_sub_menu_model_gtk.h" 27 #include "chrome/browser/ui/gtk/bookmarks/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 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
497 gfx::Rect left(allocation.x - kShadowThickness, 497 gfx::Rect left(allocation.x - kShadowThickness,
498 allocation.y - kShadowThickness, 498 allocation.y - kShadowThickness,
499 kCornerWidth, 499 kCornerWidth,
500 allocation.height + kShadowThickness); 500 allocation.height + kShadowThickness);
501 501
502 if (window_->ShouldDrawContentDropShadow()) { 502 if (window_->ShouldDrawContentDropShadow()) {
503 // Leave room to draw rounded corners. 503 // Leave room to draw rounded corners.
504 area = area.Subtract(right).Subtract(left); 504 area = area.Subtract(right).Subtract(left);
505 } 505 }
506 506
507 CairoCachedSurface* background = theme_service_->GetSurfaceNamed( 507 gfx::CairoCachedSurface* background = theme_service_->GetSurfaceNamed(
508 IDR_THEME_TOOLBAR, widget); 508 IDR_THEME_TOOLBAR, widget);
509 background->SetSource(cr, tabstrip_origin.x(), tabstrip_origin.y()); 509 background->SetSource(cr, widget, tabstrip_origin.x(), tabstrip_origin.y());
510 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); 510 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
511 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height()); 511 cairo_rectangle(cr, area.x(), area.y(), area.width(), area.height());
512 cairo_fill(cr); 512 cairo_fill(cr);
513 513
514 if (!window_->ShouldDrawContentDropShadow()) { 514 if (!window_->ShouldDrawContentDropShadow()) {
515 // 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.
516 cairo_destroy(cr); 516 cairo_destroy(cr);
517 return FALSE; 517 return FALSE;
518 } 518 }
519 519
520 bool draw_left_corner = left.Intersects(gfx::Rect(e->area)); 520 bool draw_left_corner = left.Intersects(gfx::Rect(e->area));
521 bool draw_right_corner = right.Intersects(gfx::Rect(e->area)); 521 bool draw_right_corner = right.Intersects(gfx::Rect(e->area));
522 522
523 if (draw_left_corner || draw_right_corner) { 523 if (draw_left_corner || draw_right_corner) {
524 // 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.
525 cairo_surface_t* target = cairo_surface_create_similar( 525 cairo_surface_t* target = cairo_surface_create_similar(
526 cairo_get_target(cr), 526 cairo_get_target(cr),
527 CAIRO_CONTENT_COLOR_ALPHA, 527 CAIRO_CONTENT_COLOR_ALPHA,
528 allocation.x + allocation.width, 528 allocation.x + allocation.width,
529 allocation.y + allocation.height); 529 allocation.y + allocation.height);
530 cairo_t* copy_cr = cairo_create(target); 530 cairo_t* copy_cr = cairo_create(target);
531 531
532 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE); 532 cairo_set_operator(copy_cr, CAIRO_OPERATOR_SOURCE);
533 if (draw_left_corner) { 533 if (draw_left_corner) {
534 CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed( 534 gfx::CairoCachedSurface* left_corner = theme_service_->GetSurfaceNamed(
535 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget); 535 IDR_CONTENT_TOP_LEFT_CORNER_MASK, widget);
536 left_corner->SetSource(copy_cr, left.x(), left.y()); 536 left_corner->SetSource(copy_cr, widget, left.x(), left.y());
537 cairo_paint(copy_cr); 537 cairo_paint(copy_cr);
538 } 538 }
539 if (draw_right_corner) { 539 if (draw_right_corner) {
540 CairoCachedSurface* right_corner = theme_service_->GetSurfaceNamed( 540 gfx::CairoCachedSurface* right_corner = theme_service_->GetSurfaceNamed(
541 IDR_CONTENT_TOP_RIGHT_CORNER_MASK, widget); 541 IDR_CONTENT_TOP_RIGHT_CORNER_MASK, widget);
542 right_corner->SetSource(copy_cr, right.x(), right.y()); 542 right_corner->SetSource(copy_cr, widget, right.x(), right.y());
543 // We fill a path rather than just painting because we don't want to 543 // We fill a path rather than just painting because we don't want to
544 // overwrite the left corner. 544 // overwrite the left corner.
545 cairo_rectangle(copy_cr, right.x(), right.y(), 545 cairo_rectangle(copy_cr, right.x(), right.y(),
546 right.width(), right.height()); 546 right.width(), right.height());
547 cairo_fill(copy_cr); 547 cairo_fill(copy_cr);
548 } 548 }
549 549
550 // Draw the background. CAIRO_OPERATOR_IN uses the existing pixel data as 550 // Draw the background. CAIRO_OPERATOR_IN uses the existing pixel data as
551 // an alpha mask. 551 // an alpha mask.
552 background->SetSource(copy_cr, tabstrip_origin.x(), tabstrip_origin.y()); 552 background->SetSource(copy_cr, widget,
553 tabstrip_origin.x(), tabstrip_origin.y());
553 cairo_set_operator(copy_cr, CAIRO_OPERATOR_IN); 554 cairo_set_operator(copy_cr, CAIRO_OPERATOR_IN);
554 cairo_pattern_set_extend(cairo_get_source(copy_cr), CAIRO_EXTEND_REPEAT); 555 cairo_pattern_set_extend(cairo_get_source(copy_cr), CAIRO_EXTEND_REPEAT);
555 cairo_paint(copy_cr); 556 cairo_paint(copy_cr);
556 cairo_destroy(copy_cr); 557 cairo_destroy(copy_cr);
557 558
558 // Copy the temporary surface to the screen. 559 // Copy the temporary surface to the screen.
559 cairo_set_source_surface(cr, target, 0, 0); 560 cairo_set_source_surface(cr, target, 0, 0);
560 cairo_paint(cr); 561 cairo_paint(cr);
561 cairo_surface_destroy(target); 562 cairo_surface_destroy(target);
562 } 563 }
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id); 670 const SkBitmap* badge = theme_service_->GetBitmapNamed(resource_id);
670 gfx::CanvasSkiaPaint canvas(expose, false); 671 gfx::CanvasSkiaPaint canvas(expose, false);
671 int x_offset = base::i18n::IsRTL() ? 0 : allocation.width - badge->width(); 672 int x_offset = base::i18n::IsRTL() ? 0 : allocation.width - badge->width();
672 int y_offset = 0; 673 int y_offset = 0;
673 canvas.DrawBitmapInt(*badge, 674 canvas.DrawBitmapInt(*badge,
674 allocation.x + x_offset, 675 allocation.x + x_offset,
675 allocation.y + y_offset); 676 allocation.y + y_offset);
676 677
677 return FALSE; 678 return FALSE;
678 } 679 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/browser_actions_toolbar_gtk.cc ('k') | chrome/browser/ui/gtk/browser_window_gtk.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698