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_window_gtk.h" | 5 #include "chrome/browser/ui/gtk/browser_window_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include <dlfcn.h> | 9 #include <dlfcn.h> |
10 #include <string> | 10 #include <string> |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 #include "content/public/browser/native_web_keyboard_event.h" | 86 #include "content/public/browser/native_web_keyboard_event.h" |
87 #include "grit/chromium_strings.h" | 87 #include "grit/chromium_strings.h" |
88 #include "grit/generated_resources.h" | 88 #include "grit/generated_resources.h" |
89 #include "grit/theme_resources.h" | 89 #include "grit/theme_resources.h" |
90 #include "grit/theme_resources_standard.h" | 90 #include "grit/theme_resources_standard.h" |
91 #include "grit/ui_resources.h" | 91 #include "grit/ui_resources.h" |
92 #include "ui/base/gtk/gtk_floating_container.h" | 92 #include "ui/base/gtk/gtk_floating_container.h" |
93 #include "ui/base/gtk/gtk_hig_constants.h" | 93 #include "ui/base/gtk/gtk_hig_constants.h" |
94 #include "ui/base/keycodes/keyboard_codes.h" | 94 #include "ui/base/keycodes/keyboard_codes.h" |
95 #include "ui/base/l10n/l10n_util.h" | 95 #include "ui/base/l10n/l10n_util.h" |
| 96 #include "ui/base/resource/resource_bundle.h" |
96 #include "ui/base/x/active_window_watcher_x.h" | 97 #include "ui/base/x/active_window_watcher_x.h" |
97 #include "ui/gfx/gtk_util.h" | 98 #include "ui/gfx/gtk_util.h" |
98 #include "ui/gfx/image/cairo_cached_surface.h" | 99 #include "ui/gfx/image/cairo_cached_surface.h" |
| 100 #include "ui/gfx/image/image.h" |
99 #include "ui/gfx/rect.h" | 101 #include "ui/gfx/rect.h" |
100 #include "ui/gfx/skia_utils_gtk.h" | 102 #include "ui/gfx/skia_utils_gtk.h" |
101 | 103 |
102 namespace { | 104 namespace { |
103 | 105 |
104 // The number of milliseconds between loading animation frames. | 106 // The number of milliseconds between loading animation frames. |
105 const int kLoadingAnimationFrameTimeMs = 30; | 107 const int kLoadingAnimationFrameTimeMs = 30; |
106 | 108 |
107 // Minimal height of devotools pane or content pane when devtools are docked | 109 // Minimal height of devotools pane or content pane when devtools are docked |
108 // to the browser window. | 110 // to the browser window. |
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
437 IDR_WINDOW_BOTTOM_RIGHT_CORNER); | 439 IDR_WINDOW_BOTTOM_RIGHT_CORNER); |
438 } | 440 } |
439 custom_frame_border->RenderToWidget(widget); | 441 custom_frame_border->RenderToWidget(widget); |
440 } | 442 } |
441 | 443 |
442 return FALSE; // Allow subwidgets to paint. | 444 return FALSE; // Allow subwidgets to paint. |
443 } | 445 } |
444 | 446 |
445 void BrowserWindowGtk::DrawContentShadow(cairo_t* cr) { | 447 void BrowserWindowGtk::DrawContentShadow(cairo_t* cr) { |
446 // Draw the shadow above the toolbar. Tabs on the tabstrip will draw over us. | 448 // Draw the shadow above the toolbar. Tabs on the tabstrip will draw over us. |
447 GtkThemeService* theme_provider = GtkThemeService::GetFrom( | 449 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
448 browser()->profile()); | |
449 int left_x, top_y; | 450 int left_x, top_y; |
450 gtk_widget_translate_coordinates(toolbar_->widget(), | 451 gtk_widget_translate_coordinates(toolbar_->widget(), |
451 GTK_WIDGET(window_), 0, 0, &left_x, | 452 GTK_WIDGET(window_), 0, 0, &left_x, |
452 &top_y); | 453 &top_y); |
453 int center_width = window_vbox_->allocation.width; | 454 int center_width = window_vbox_->allocation.width; |
454 | 455 |
455 gfx::CairoCachedSurface* top_center = theme_provider->GetSurfaceNamed( | 456 gfx::CairoCachedSurface* top_center = |
456 IDR_CONTENT_TOP_CENTER, GTK_WIDGET(window_)); | 457 rb.GetNativeImageNamed(IDR_CONTENT_TOP_CENTER).ToCairo(); |
457 gfx::CairoCachedSurface* top_right = theme_provider->GetSurfaceNamed( | 458 gfx::CairoCachedSurface* top_right = |
458 IDR_CONTENT_TOP_RIGHT_CORNER, GTK_WIDGET(window_)); | 459 rb.GetNativeImageNamed(IDR_CONTENT_TOP_RIGHT_CORNER).ToCairo(); |
459 gfx::CairoCachedSurface* top_left = theme_provider->GetSurfaceNamed( | 460 gfx::CairoCachedSurface* top_left = |
460 IDR_CONTENT_TOP_LEFT_CORNER, GTK_WIDGET(window_)); | 461 rb.GetNativeImageNamed(IDR_CONTENT_TOP_LEFT_CORNER).ToCairo(); |
461 | 462 |
462 int center_left_x = left_x; | 463 int center_left_x = left_x; |
463 if (ShouldDrawContentDropShadow()) { | 464 if (ShouldDrawContentDropShadow()) { |
464 // Don't draw over the corners. | 465 // Don't draw over the corners. |
465 center_left_x += top_left->Width() - kContentShadowThickness; | 466 center_left_x += top_left->Width() - kContentShadowThickness; |
466 center_width -= (top_left->Width() + top_right->Width()); | 467 center_width -= (top_left->Width() + top_right->Width()); |
467 center_width += 2 * kContentShadowThickness; | 468 center_width += 2 * kContentShadowThickness; |
468 } | 469 } |
469 | 470 |
470 top_center->SetSource(cr, GTK_WIDGET(window_), | 471 top_center->SetSource(cr, GTK_WIDGET(window_), |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 0, window_vbox_->allocation.height, | 513 0, window_vbox_->allocation.height, |
513 NULL, &bottom_y); | 514 NULL, &bottom_y); |
514 // |side_y| is where to start drawing the side shadows. The top corners draw | 515 // |side_y| is where to start drawing the side shadows. The top corners draw |
515 // the sides down to the bottom of the toolbar. | 516 // the sides down to the bottom of the toolbar. |
516 int side_y = top_y - kContentShadowThickness + top_right->Height(); | 517 int side_y = top_y - kContentShadowThickness + top_right->Height(); |
517 // |side_height| is how many pixels to draw for the side borders. We do one | 518 // |side_height| is how many pixels to draw for the side borders. We do one |
518 // pixel before the bottom of the web contents because that extra pixel is | 519 // pixel before the bottom of the web contents because that extra pixel is |
519 // drawn by the bottom corners. | 520 // drawn by the bottom corners. |
520 int side_height = bottom_y - side_y - 1; | 521 int side_height = bottom_y - side_y - 1; |
521 if (side_height > 0) { | 522 if (side_height > 0) { |
522 gfx::CairoCachedSurface* left = theme_provider->GetSurfaceNamed( | 523 gfx::CairoCachedSurface* left = |
523 IDR_CONTENT_LEFT_SIDE, GTK_WIDGET(window_)); | 524 rb.GetNativeImageNamed(IDR_CONTENT_LEFT_SIDE).ToCairo(); |
524 left->SetSource(cr, GTK_WIDGET(window_), | 525 left->SetSource(cr, GTK_WIDGET(window_), |
525 left_x - kContentShadowThickness, side_y); | 526 left_x - kContentShadowThickness, side_y); |
526 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 527 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
527 cairo_rectangle(cr, | 528 cairo_rectangle(cr, |
528 left_x - kContentShadowThickness, | 529 left_x - kContentShadowThickness, |
529 side_y, | 530 side_y, |
530 kContentShadowThickness, | 531 kContentShadowThickness, |
531 side_height); | 532 side_height); |
532 cairo_fill(cr); | 533 cairo_fill(cr); |
533 | 534 |
534 gfx::CairoCachedSurface* right = theme_provider->GetSurfaceNamed( | 535 gfx::CairoCachedSurface* right = |
535 IDR_CONTENT_RIGHT_SIDE, GTK_WIDGET(window_)); | 536 rb.GetNativeImageNamed(IDR_CONTENT_RIGHT_SIDE).ToCairo(); |
536 int right_side_x = | 537 int right_side_x = |
537 right_x + top_right->Width() - kContentShadowThickness - 1; | 538 right_x + top_right->Width() - kContentShadowThickness - 1; |
538 right->SetSource(cr, GTK_WIDGET(window_), right_side_x, side_y); | 539 right->SetSource(cr, GTK_WIDGET(window_), right_side_x, side_y); |
539 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 540 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
540 cairo_rectangle(cr, | 541 cairo_rectangle(cr, |
541 right_side_x, | 542 right_side_x, |
542 side_y, | 543 side_y, |
543 kContentShadowThickness, | 544 kContentShadowThickness, |
544 side_height); | 545 side_height); |
545 cairo_fill(cr); | 546 cairo_fill(cr); |
546 } | 547 } |
547 | 548 |
548 // Draw the bottom corners. The bottom corners also draw the bottom row of | 549 // Draw the bottom corners. The bottom corners also draw the bottom row of |
549 // pixels of the side shadows. | 550 // pixels of the side shadows. |
550 gfx::CairoCachedSurface* bottom_left = theme_provider->GetSurfaceNamed( | 551 gfx::CairoCachedSurface* bottom_left = |
551 IDR_CONTENT_BOTTOM_LEFT_CORNER, GTK_WIDGET(window_)); | 552 rb.GetNativeImageNamed(IDR_CONTENT_BOTTOM_LEFT_CORNER).ToCairo(); |
552 bottom_left->SetSource(cr, GTK_WIDGET(window_), | 553 bottom_left->SetSource(cr, GTK_WIDGET(window_), |
553 left_x - kContentShadowThickness, bottom_y - 1); | 554 left_x - kContentShadowThickness, bottom_y - 1); |
554 cairo_paint(cr); | 555 cairo_paint(cr); |
555 | 556 |
556 gfx::CairoCachedSurface* bottom_right = theme_provider->GetSurfaceNamed( | 557 gfx::CairoCachedSurface* bottom_right = |
557 IDR_CONTENT_BOTTOM_RIGHT_CORNER, GTK_WIDGET(window_)); | 558 rb.GetNativeImageNamed(IDR_CONTENT_BOTTOM_RIGHT_CORNER).ToCairo(); |
558 bottom_right->SetSource(cr, GTK_WIDGET(window_), right_x - 1, bottom_y - 1); | 559 bottom_right->SetSource(cr, GTK_WIDGET(window_), right_x - 1, bottom_y - 1); |
559 cairo_paint(cr); | 560 cairo_paint(cr); |
560 | 561 |
561 // Finally, draw the bottom row. Since we don't overlap the contents, we clip | 562 // Finally, draw the bottom row. Since we don't overlap the contents, we clip |
562 // the top row of pixels. | 563 // the top row of pixels. |
563 gfx::CairoCachedSurface* bottom = theme_provider->GetSurfaceNamed( | 564 gfx::CairoCachedSurface* bottom = |
564 IDR_CONTENT_BOTTOM_CENTER, GTK_WIDGET(window_)); | 565 rb.GetNativeImageNamed(IDR_CONTENT_BOTTOM_CENTER).ToCairo(); |
565 bottom->SetSource(cr, GTK_WIDGET(window_), left_x + 1, bottom_y - 1); | 566 bottom->SetSource(cr, GTK_WIDGET(window_), left_x + 1, bottom_y - 1); |
566 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 567 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
567 cairo_rectangle(cr, | 568 cairo_rectangle(cr, |
568 left_x + 1, | 569 left_x + 1, |
569 bottom_y, | 570 bottom_y, |
570 window_vbox_->allocation.width - 2, | 571 window_vbox_->allocation.width - 2, |
571 kContentShadowThickness); | 572 kContentShadowThickness); |
572 cairo_fill(cr); | 573 cairo_fill(cr); |
573 } | 574 } |
574 | 575 |
575 void BrowserWindowGtk::DrawPopupFrame(cairo_t* cr, | 576 void BrowserWindowGtk::DrawPopupFrame(cairo_t* cr, |
576 GtkWidget* widget, | 577 GtkWidget* widget, |
577 GdkEventExpose* event) { | 578 GdkEventExpose* event) { |
578 GtkThemeService* theme_provider = GtkThemeService::GetFrom( | 579 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
579 browser()->profile()); | |
580 | 580 |
581 // Like DrawCustomFrame(), except that we use the unthemed resources to draw | 581 // Like DrawCustomFrame(), except that we use the unthemed resources to draw |
582 // the background. We do this because we can't rely on sane images in the | 582 // the background. We do this because we can't rely on sane images in the |
583 // theme that we can draw text on. (We tried using the tab background, but | 583 // theme that we can draw text on. (We tried using the tab background, but |
584 // that has inverse saturation from what the user usually expects). | 584 // that has inverse saturation from what the user usually expects). |
585 int image_name = GetThemeFrameResource(); | 585 int image_name = GetThemeFrameResource(); |
586 gfx::CairoCachedSurface* surface = theme_provider->GetUnthemedSurfaceNamed( | 586 gfx::CairoCachedSurface* surface = |
587 image_name, widget); | 587 rb.GetNativeImageNamed(image_name).ToCairo(); |
588 surface->SetSource(cr, widget, 0, GetVerticalOffset()); | 588 surface->SetSource(cr, widget, 0, GetVerticalOffset()); |
589 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT); | 589 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REFLECT); |
590 cairo_rectangle(cr, event->area.x, event->area.y, | 590 cairo_rectangle(cr, event->area.x, event->area.y, |
591 event->area.width, event->area.height); | 591 event->area.width, event->area.height); |
592 cairo_fill(cr); | 592 cairo_fill(cr); |
593 } | 593 } |
594 | 594 |
595 void BrowserWindowGtk::DrawCustomFrame(cairo_t* cr, | 595 void BrowserWindowGtk::DrawCustomFrame(cairo_t* cr, |
596 GtkWidget* widget, | 596 GtkWidget* widget, |
597 GdkEventExpose* event) { | 597 GdkEventExpose* event) { |
598 GtkThemeService* theme_provider = GtkThemeService::GetFrom( | 598 GtkThemeService* theme_provider = GtkThemeService::GetFrom( |
599 browser()->profile()); | 599 browser()->profile()); |
600 | 600 |
601 int image_name = GetThemeFrameResource(); | 601 int image_name = GetThemeFrameResource(); |
602 | 602 |
603 gfx::CairoCachedSurface* surface = theme_provider->GetSurfaceNamed( | 603 gfx::CairoCachedSurface* surface = theme_provider->GetImageNamed( |
604 image_name, widget); | 604 image_name)->ToCairo(); |
605 if (event->area.y < surface->Height()) { | 605 if (event->area.y < surface->Height()) { |
606 surface->SetSource(cr, widget, 0, GetVerticalOffset()); | 606 surface->SetSource(cr, widget, 0, GetVerticalOffset()); |
607 | 607 |
608 // The frame background isn't tiled vertically. | 608 // The frame background isn't tiled vertically. |
609 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); | 609 cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT); |
610 cairo_rectangle(cr, event->area.x, event->area.y, | 610 cairo_rectangle(cr, event->area.x, event->area.y, |
611 event->area.width, surface->Height() - event->area.y); | 611 event->area.width, surface->Height() - event->area.y); |
612 cairo_fill(cr); | 612 cairo_fill(cr); |
613 } | 613 } |
614 | 614 |
615 if (theme_provider->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && | 615 if (theme_provider->HasCustomImage(IDR_THEME_FRAME_OVERLAY) && |
616 !browser()->profile()->IsOffTheRecord()) { | 616 !browser()->profile()->IsOffTheRecord()) { |
617 gfx::CairoCachedSurface* theme_overlay = theme_provider->GetSurfaceNamed( | 617 gfx::CairoCachedSurface* theme_overlay = theme_provider->GetImageNamed( |
618 IsActive() ? IDR_THEME_FRAME_OVERLAY | 618 IsActive() ? IDR_THEME_FRAME_OVERLAY |
619 : IDR_THEME_FRAME_OVERLAY_INACTIVE, widget); | 619 : IDR_THEME_FRAME_OVERLAY_INACTIVE)->ToCairo(); |
620 theme_overlay->SetSource(cr, widget, 0, GetVerticalOffset()); | 620 theme_overlay->SetSource(cr, widget, 0, GetVerticalOffset()); |
621 cairo_paint(cr); | 621 cairo_paint(cr); |
622 } | 622 } |
623 } | 623 } |
624 | 624 |
625 int BrowserWindowGtk::GetVerticalOffset() { | 625 int BrowserWindowGtk::GetVerticalOffset() { |
626 return (IsMaximized() || (!UseCustomFrame())) ? | 626 return (IsMaximized() || (!UseCustomFrame())) ? |
627 -kCustomFrameBackgroundVerticalOffset : 0; | 627 -kCustomFrameBackgroundVerticalOffset : 0; |
628 } | 628 } |
629 | 629 |
(...skipping 1801 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 wm_type == ui::WM_OPENBOX || | 2431 wm_type == ui::WM_OPENBOX || |
2432 wm_type == ui::WM_XFWM4); | 2432 wm_type == ui::WM_XFWM4); |
2433 } | 2433 } |
2434 | 2434 |
2435 // static | 2435 // static |
2436 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { | 2436 BrowserWindow* BrowserWindow::CreateBrowserWindow(Browser* browser) { |
2437 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); | 2437 BrowserWindowGtk* browser_window_gtk = new BrowserWindowGtk(browser); |
2438 browser_window_gtk->Init(); | 2438 browser_window_gtk->Init(); |
2439 return browser_window_gtk; | 2439 return browser_window_gtk; |
2440 } | 2440 } |
OLD | NEW |