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

Side by Side Diff: chrome/browser/views/frame/opaque_browser_frame_view.cc

Issue 113443: ChromeCanvas->gfx::Canvas (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 7 months 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/frame/opaque_browser_frame_view.h" 5 #include "chrome/browser/views/frame/opaque_browser_frame_view.h"
6 6
7 #include "app/gfx/chrome_canvas.h" 7 #include "app/gfx/canvas.h"
8 #include "app/gfx/chrome_font.h" 8 #include "app/gfx/font.h"
9 #include "app/gfx/path.h" 9 #include "app/gfx/path.h"
10 #include "app/l10n_util.h" 10 #include "app/l10n_util.h"
11 #include "app/resource_bundle.h" 11 #include "app/resource_bundle.h"
12 #include "app/theme_provider.h" 12 #include "app/theme_provider.h"
13 #include "app/win_util.h" 13 #include "app/win_util.h"
14 #include "chrome/browser/browser_theme_provider.h" 14 #include "chrome/browser/browser_theme_provider.h"
15 #include "chrome/browser/views/frame/browser_frame.h" 15 #include "chrome/browser/views/frame/browser_frame.h"
16 #include "chrome/browser/views/frame/browser_view.h" 16 #include "chrome/browser/views/frame/browser_view.h"
17 #include "chrome/browser/views/tabs/tab_strip.h" 17 #include "chrome/browser/views/tabs/tab_strip.h"
18 #include "grit/chromium_strings.h" 18 #include "grit/chromium_strings.h"
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
306 void OpaqueBrowserFrameView::ResetWindowControls() { 306 void OpaqueBrowserFrameView::ResetWindowControls() {
307 restore_button_->SetState(views::CustomButton::BS_NORMAL); 307 restore_button_->SetState(views::CustomButton::BS_NORMAL);
308 minimize_button_->SetState(views::CustomButton::BS_NORMAL); 308 minimize_button_->SetState(views::CustomButton::BS_NORMAL);
309 maximize_button_->SetState(views::CustomButton::BS_NORMAL); 309 maximize_button_->SetState(views::CustomButton::BS_NORMAL);
310 // The close button isn't affected by this constraint. 310 // The close button isn't affected by this constraint.
311 } 311 }
312 312
313 /////////////////////////////////////////////////////////////////////////////// 313 ///////////////////////////////////////////////////////////////////////////////
314 // OpaqueBrowserFrameView, views::View overrides: 314 // OpaqueBrowserFrameView, views::View overrides:
315 315
316 void OpaqueBrowserFrameView::Paint(ChromeCanvas* canvas) { 316 void OpaqueBrowserFrameView::Paint(gfx::Canvas* canvas) {
317 if (frame_->IsFullscreen()) 317 if (frame_->IsFullscreen())
318 return; // Nothing is visible, so don't bother to paint. 318 return; // Nothing is visible, so don't bother to paint.
319 319
320 if (frame_->IsMaximized()) 320 if (frame_->IsMaximized())
321 PaintMaximizedFrameBorder(canvas); 321 PaintMaximizedFrameBorder(canvas);
322 else 322 else
323 PaintRestoredFrameBorder(canvas); 323 PaintRestoredFrameBorder(canvas);
324 PaintDistributorLogo(canvas); 324 PaintDistributorLogo(canvas);
325 PaintTitleBar(canvas); 325 PaintTitleBar(canvas);
326 PaintToolbarBackground(canvas); 326 PaintToolbarBackground(canvas);
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 if (available_height_ptr) 499 if (available_height_ptr)
500 *available_height_ptr = available_height; 500 *available_height_ptr = available_height;
501 501
502 // The icon takes up a constant fraction of the available height, down to a 502 // The icon takes up a constant fraction of the available height, down to a
503 // minimum size, and is always an even number of pixels on a side (presumably 503 // minimum size, and is always an even number of pixels on a side (presumably
504 // to make scaled icons look better). It's centered within the usable height. 504 // to make scaled icons look better). It's centered within the usable height.
505 return std::max((available_height * kIconHeightFractionNumerator / 505 return std::max((available_height * kIconHeightFractionNumerator /
506 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize); 506 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize);
507 } 507 }
508 508
509 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { 509 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(gfx::Canvas* canvas) {
510 ThemeProvider* tp = GetThemeProvider(); 510 ThemeProvider* tp = GetThemeProvider();
511 511
512 SkBitmap* top_left_corner = tp->GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER); 512 SkBitmap* top_left_corner = tp->GetBitmapNamed(IDR_WINDOW_TOP_LEFT_CORNER);
513 SkBitmap* top_right_corner = 513 SkBitmap* top_right_corner =
514 tp->GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER); 514 tp->GetBitmapNamed(IDR_WINDOW_TOP_RIGHT_CORNER);
515 SkBitmap* top_edge = tp->GetBitmapNamed(IDR_WINDOW_TOP_CENTER); 515 SkBitmap* top_edge = tp->GetBitmapNamed(IDR_WINDOW_TOP_CENTER);
516 SkBitmap* right_edge = tp->GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE); 516 SkBitmap* right_edge = tp->GetBitmapNamed(IDR_WINDOW_RIGHT_SIDE);
517 SkBitmap* left_edge = tp->GetBitmapNamed(IDR_WINDOW_LEFT_SIDE); 517 SkBitmap* left_edge = tp->GetBitmapNamed(IDR_WINDOW_LEFT_SIDE);
518 SkBitmap* bottom_left_corner = 518 SkBitmap* bottom_left_corner =
519 tp->GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER); 519 tp->GetBitmapNamed(IDR_WINDOW_BOTTOM_LEFT_CORNER);
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 bottom_edge->height()); 596 bottom_edge->height());
597 canvas->DrawBitmapInt(*bottom_left_corner, 0, 597 canvas->DrawBitmapInt(*bottom_left_corner, 0,
598 height() - bottom_left_corner->height()); 598 height() - bottom_left_corner->height());
599 599
600 // Left. 600 // Left.
601 canvas->TileImageInt(*left_edge, 0, top_left_height, left_edge->width(), 601 canvas->TileImageInt(*left_edge, 0, top_left_height, left_edge->width(),
602 height() - top_left_height - bottom_left_corner->height()); 602 height() - top_left_height - bottom_left_corner->height());
603 } 603 }
604 604
605 605
606 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(ChromeCanvas* canvas) { 606 void OpaqueBrowserFrameView::PaintMaximizedFrameBorder(gfx::Canvas* canvas) {
607 ThemeProvider* tp = GetThemeProvider(); 607 ThemeProvider* tp = GetThemeProvider();
608 // Window frame mode and color 608 // Window frame mode and color
609 SkBitmap* theme_frame; 609 SkBitmap* theme_frame;
610 if (!browser_view_->IsOffTheRecord()) { 610 if (!browser_view_->IsOffTheRecord()) {
611 theme_frame = frame_->IsActive() ? 611 theme_frame = frame_->IsActive() ?
612 tp->GetBitmapNamed(IDR_THEME_FRAME) : 612 tp->GetBitmapNamed(IDR_THEME_FRAME) :
613 tp->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE); 613 tp->GetBitmapNamed(IDR_THEME_FRAME_INACTIVE);
614 } else { 614 } else {
615 theme_frame = frame_->IsActive() ? 615 theme_frame = frame_->IsActive() ?
616 tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO) : 616 tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO) :
617 tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO_INACTIVE); 617 tp->GetBitmapNamed(IDR_THEME_FRAME_INCOGNITO_INACTIVE);
618 } 618 }
619 619
620 // Draw the theme frame. 620 // Draw the theme frame.
621 canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height()); 621 canvas->TileImageInt(*theme_frame, 0, 0, width(), theme_frame->height());
622 622
623 if (!browser_view_->IsToolbarVisible()) { 623 if (!browser_view_->IsToolbarVisible()) {
624 // There's no toolbar to edge the frame border, so we need to draw a bottom 624 // There's no toolbar to edge the frame border, so we need to draw a bottom
625 // edge. The graphic we use for this has a built in client edge, so we clip 625 // edge. The graphic we use for this has a built in client edge, so we clip
626 // it off the bottom. 626 // it off the bottom.
627 SkBitmap* top_center = 627 SkBitmap* top_center =
628 tp->GetBitmapNamed(IDR_APP_TOP_CENTER); 628 tp->GetBitmapNamed(IDR_APP_TOP_CENTER);
629 int edge_height = top_center->height() - kClientEdgeThickness; 629 int edge_height = top_center->height() - kClientEdgeThickness;
630 canvas->TileImageInt(*top_center, 0, 630 canvas->TileImageInt(*top_center, 0,
631 frame_->GetClientView()->y() - edge_height, width(), edge_height); 631 frame_->GetClientView()->y() - edge_height, width(), edge_height);
632 } 632 }
633 } 633 }
634 634
635 void OpaqueBrowserFrameView::PaintDistributorLogo(ChromeCanvas* canvas) { 635 void OpaqueBrowserFrameView::PaintDistributorLogo(gfx::Canvas* canvas) {
636 // The distributor logo is only painted when the frame is not maximized and 636 // The distributor logo is only painted when the frame is not maximized and
637 // when we actually have a logo. 637 // when we actually have a logo.
638 if (!frame_->IsMaximized() && distributor_logo_ && 638 if (!frame_->IsMaximized() && distributor_logo_ &&
639 browser_view_->ShouldShowDistributorLogo()) { 639 browser_view_->ShouldShowDistributorLogo()) {
640 canvas->DrawBitmapInt(*distributor_logo_, 640 canvas->DrawBitmapInt(*distributor_logo_,
641 MirroredLeftPointForRect(logo_bounds_), logo_bounds_.y()); 641 MirroredLeftPointForRect(logo_bounds_), logo_bounds_.y());
642 } 642 }
643 } 643 }
644 644
645 void OpaqueBrowserFrameView::PaintTitleBar(ChromeCanvas* canvas) { 645 void OpaqueBrowserFrameView::PaintTitleBar(gfx::Canvas* canvas) {
646 // The window icon is painted by the TabIconView. 646 // The window icon is painted by the TabIconView.
647 views::WindowDelegate* d = frame_->GetDelegate(); 647 views::WindowDelegate* d = frame_->GetDelegate();
648 if (d->ShouldShowWindowTitle()) { 648 if (d->ShouldShowWindowTitle()) {
649 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, SK_ColorWHITE, 649 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, SK_ColorWHITE,
650 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), 650 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(),
651 title_bounds_.width(), title_bounds_.height()); 651 title_bounds_.width(), title_bounds_.height());
652 /* TODO(pkasting): If this window is active, we should also draw a drop 652 /* TODO(pkasting): If this window is active, we should also draw a drop
653 * shadow on the title. This is tricky, because we don't want to hardcode a 653 * shadow on the title. This is tricky, because we don't want to hardcode a
654 * shadow color (since we want to work with various themes), but we can't 654 * shadow color (since we want to work with various themes), but we can't
655 * alpha-blend either (since the Windows text APIs don't really do this). 655 * alpha-blend either (since the Windows text APIs don't really do this).
656 * So we'd need to sample the background color at the right location and 656 * So we'd need to sample the background color at the right location and
657 * synthesize a good shadow color. */ 657 * synthesize a good shadow color. */
658 } 658 }
659 } 659 }
660 660
661 void OpaqueBrowserFrameView::PaintToolbarBackground(ChromeCanvas* canvas) { 661 void OpaqueBrowserFrameView::PaintToolbarBackground(gfx::Canvas* canvas) {
662 if (!browser_view_->IsToolbarVisible()) 662 if (!browser_view_->IsToolbarVisible())
663 return; 663 return;
664 664
665 ThemeProvider* tp = GetThemeProvider(); 665 ThemeProvider* tp = GetThemeProvider();
666 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds()); 666 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
667 gfx::Point toolbar_origin(toolbar_bounds.origin()); 667 gfx::Point toolbar_origin(toolbar_bounds.origin());
668 View::ConvertPointToView(frame_->GetClientView(), this, &toolbar_origin); 668 View::ConvertPointToView(frame_->GetClientView(), this, &toolbar_origin);
669 toolbar_bounds.set_origin(toolbar_origin); 669 toolbar_bounds.set_origin(toolbar_origin);
670 670
671 int strip_height = browser_view_->GetTabStripHeight(); 671 int strip_height = browser_view_->GetTabStripHeight();
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 SkBitmap* toolbar_right = tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER); 709 SkBitmap* toolbar_right = tp->GetBitmapNamed(IDR_CONTENT_TOP_RIGHT_CORNER);
710 canvas->DrawBitmapInt(*toolbar_right, 0, 0, toolbar_right->width(), 710 canvas->DrawBitmapInt(*toolbar_right, 0, 0, toolbar_right->width(),
711 split_point, toolbar_bounds.right(), toolbar_bounds.y(), 711 split_point, toolbar_bounds.right(), toolbar_bounds.y(),
712 toolbar_right->width(), split_point, false); 712 toolbar_right->width(), split_point, false);
713 canvas->DrawBitmapInt(*toolbar_right, 0, 713 canvas->DrawBitmapInt(*toolbar_right, 0,
714 toolbar_right->height() - bottom_edge_height, toolbar_right->width(), 714 toolbar_right->height() - bottom_edge_height, toolbar_right->width(),
715 bottom_edge_height, toolbar_bounds.right(), bottom_y, 715 bottom_edge_height, toolbar_bounds.right(), bottom_y,
716 toolbar_right->width(), bottom_edge_height, false); 716 toolbar_right->width(), bottom_edge_height, false);
717 } 717 }
718 718
719 void OpaqueBrowserFrameView::PaintOTRAvatar(ChromeCanvas* canvas) { 719 void OpaqueBrowserFrameView::PaintOTRAvatar(gfx::Canvas* canvas) {
720 if (!browser_view_->ShouldShowOffTheRecordAvatar()) 720 if (!browser_view_->ShouldShowOffTheRecordAvatar())
721 return; 721 return;
722 722
723 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 723 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
724 canvas->DrawBitmapInt(otr_avatar_icon, 0, 724 canvas->DrawBitmapInt(otr_avatar_icon, 0,
725 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2, 725 (otr_avatar_icon.height() - otr_avatar_bounds_.height()) / 2,
726 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), 726 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(),
727 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(), 727 MirroredLeftPointForRect(otr_avatar_bounds_), otr_avatar_bounds_.y(),
728 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false); 728 otr_avatar_bounds_.width(), otr_avatar_bounds_.height(), false);
729 } 729 }
730 730
731 void OpaqueBrowserFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { 731 void OpaqueBrowserFrameView::PaintRestoredClientEdge(gfx::Canvas* canvas) {
732 ThemeProvider* tp = GetThemeProvider(); 732 ThemeProvider* tp = GetThemeProvider();
733 int client_area_top = frame_->GetClientView()->y(); 733 int client_area_top = frame_->GetClientView()->y();
734 734
735 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height()); 735 gfx::Rect client_area_bounds = CalculateClientAreaBounds(width(), height());
736 if (browser_view_->IsToolbarVisible()) { 736 if (browser_view_->IsToolbarVisible()) {
737 // The client edges start below the toolbar or its corner images, whichever 737 // The client edges start below the toolbar or its corner images, whichever
738 // is shorter. 738 // is shorter.
739 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds()); 739 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
740 client_area_top += browser_view_->GetToolbarBounds().y() + 740 client_area_top += browser_view_->GetToolbarBounds().y() +
741 std::min(tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height(), 741 std::min(tp->GetBitmapNamed(IDR_CONTENT_TOP_LEFT_CORNER)->height(),
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 } 945 }
946 946
947 // static 947 // static
948 void OpaqueBrowserFrameView::InitAppWindowResources() { 948 void OpaqueBrowserFrameView::InitAppWindowResources() {
949 static bool initialized = false; 949 static bool initialized = false;
950 if (!initialized) { 950 if (!initialized) {
951 title_font_ = new gfx::Font(win_util::GetWindowTitleFont()); 951 title_font_ = new gfx::Font(win_util::GetWindowTitleFont());
952 initialized = true; 952 initialized = true;
953 } 953 }
954 } 954 }
OLDNEW
« no previous file with comments | « chrome/browser/views/frame/opaque_browser_frame_view.h ('k') | chrome/browser/views/fullscreen_exit_bubble.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698