OLD | NEW |
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 "chrome/browser/views/frame/browser_frame.h" | 7 #include "chrome/browser/views/frame/browser_frame.h" |
8 #include "chrome/browser/views/frame/browser_view.h" | 8 #include "chrome/browser/views/frame/browser_view.h" |
9 #include "chrome/browser/views/tabs/tab_strip.h" | 9 #include "chrome/browser/views/tabs/tab_strip.h" |
10 #include "chrome/common/gfx/chrome_canvas.h" | 10 #include "chrome/common/gfx/chrome_canvas.h" |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; | 252 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; |
253 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; | 253 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; |
254 SkBitmap* OTRActiveWindowResources::standard_frame_bitmaps_[]; | 254 SkBitmap* OTRActiveWindowResources::standard_frame_bitmaps_[]; |
255 SkBitmap* OTRInactiveWindowResources::standard_frame_bitmaps_[]; | 255 SkBitmap* OTRInactiveWindowResources::standard_frame_bitmaps_[]; |
256 | 256 |
257 views::WindowResources* OpaqueBrowserFrameView::active_resources_ = NULL; | 257 views::WindowResources* OpaqueBrowserFrameView::active_resources_ = NULL; |
258 views::WindowResources* OpaqueBrowserFrameView::inactive_resources_ = NULL; | 258 views::WindowResources* OpaqueBrowserFrameView::inactive_resources_ = NULL; |
259 views::WindowResources* OpaqueBrowserFrameView::active_otr_resources_ = NULL; | 259 views::WindowResources* OpaqueBrowserFrameView::active_otr_resources_ = NULL; |
260 views::WindowResources* OpaqueBrowserFrameView::inactive_otr_resources_ = NULL; | 260 views::WindowResources* OpaqueBrowserFrameView::inactive_otr_resources_ = NULL; |
261 SkBitmap* OpaqueBrowserFrameView::distributor_logo_ = NULL; | 261 SkBitmap* OpaqueBrowserFrameView::distributor_logo_ = NULL; |
262 ChromeFont OpaqueBrowserFrameView::title_font_; | 262 ChromeFont* OpaqueBrowserFrameView::title_font_ = NULL; |
263 | 263 |
264 namespace { | 264 namespace { |
265 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 265 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
266 // each side regardless of the system window border size. | 266 // each side regardless of the system window border size. |
267 const int kFrameBorderThickness = 4; | 267 const int kFrameBorderThickness = 4; |
268 // Besides the frame border, there's another 11 px of empty space atop the | 268 // Besides the frame border, there's another 11 px of empty space atop the |
269 // window in restored mode, to use to drag the window around. | 269 // window in restored mode, to use to drag the window around. |
270 const int kNonClientRestoredExtraThickness = 11; | 270 const int kNonClientRestoredExtraThickness = 11; |
271 // While resize areas on Windows are normally the same size as the window | 271 // While resize areas on Windows are normally the same size as the window |
272 // borders, our top area is shrunk by 1 px to make it easier to move the window | 272 // borders, our top area is shrunk by 1 px to make it easier to move the window |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
696 // the toolbar). | 696 // the toolbar). |
697 int title_bottom_spacing = | 697 int title_bottom_spacing = |
698 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; | 698 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; |
699 if (frame_->IsMaximized()) { | 699 if (frame_->IsMaximized()) { |
700 // When we maximize, the top border appears to be chopped off; shift the | 700 // When we maximize, the top border appears to be chopped off; shift the |
701 // title down to stay centered within the remaining space. | 701 // title down to stay centered within the remaining space. |
702 int title_adjust = (kFrameBorderThickness / 2); | 702 int title_adjust = (kFrameBorderThickness / 2); |
703 *title_top_spacing += title_adjust; | 703 *title_top_spacing += title_adjust; |
704 title_bottom_spacing -= title_adjust; | 704 title_bottom_spacing -= title_adjust; |
705 } | 705 } |
706 *title_thickness = std::max(title_font_.height(), | 706 *title_thickness = std::max(title_font_->height(), |
707 min_titlebar_height - *title_top_spacing - title_bottom_spacing); | 707 min_titlebar_height - *title_top_spacing - title_bottom_spacing); |
708 return *title_top_spacing + *title_thickness + title_bottom_spacing + | 708 return *title_top_spacing + *title_thickness + title_bottom_spacing + |
709 UnavailablePixelsAtBottomOfNonClientHeight(); | 709 UnavailablePixelsAtBottomOfNonClientHeight(); |
710 } | 710 } |
711 | 711 |
712 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { | 712 void OpaqueBrowserFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { |
713 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); | 713 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); |
714 SkBitmap* top_right_corner = | 714 SkBitmap* top_right_corner = |
715 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); | 715 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); |
716 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); | 716 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
781 browser_view_->ShouldShowDistributorLogo()) { | 781 browser_view_->ShouldShowDistributorLogo()) { |
782 canvas->DrawBitmapInt(*distributor_logo_, | 782 canvas->DrawBitmapInt(*distributor_logo_, |
783 MirroredLeftPointForRect(logo_bounds_), logo_bounds_.y()); | 783 MirroredLeftPointForRect(logo_bounds_), logo_bounds_.y()); |
784 } | 784 } |
785 } | 785 } |
786 | 786 |
787 void OpaqueBrowserFrameView::PaintTitleBar(ChromeCanvas* canvas) { | 787 void OpaqueBrowserFrameView::PaintTitleBar(ChromeCanvas* canvas) { |
788 // The window icon is painted by the TabIconView. | 788 // The window icon is painted by the TabIconView. |
789 views::WindowDelegate* d = frame_->GetDelegate(); | 789 views::WindowDelegate* d = frame_->GetDelegate(); |
790 if (d->ShouldShowWindowTitle()) { | 790 if (d->ShouldShowWindowTitle()) { |
791 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, | 791 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, SK_ColorWHITE, |
792 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), | 792 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), |
793 title_bounds_.width(), title_bounds_.height()); | 793 title_bounds_.width(), title_bounds_.height()); |
794 /* TODO(pkasting): If this window is active, we should also draw a drop | 794 /* TODO(pkasting): If this window is active, we should also draw a drop |
795 * shadow on the title. This is tricky, because we don't want to hardcode a | 795 * shadow on the title. This is tricky, because we don't want to hardcode a |
796 * shadow color (since we want to work with various themes), but we can't | 796 * shadow color (since we want to work with various themes), but we can't |
797 * alpha-blend either (since the Windows text APIs don't really do this). | 797 * alpha-blend either (since the Windows text APIs don't really do this). |
798 * So we'd need to sample the background color at the right location and | 798 * So we'd need to sample the background color at the right location and |
799 * synthesize a good shadow color. */ | 799 * synthesize a good shadow color. */ |
800 } | 800 } |
801 } | 801 } |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
963 | 963 |
964 void OpaqueBrowserFrameView::LayoutTitleBar() { | 964 void OpaqueBrowserFrameView::LayoutTitleBar() { |
965 // Always lay out the icon, even when it's not present, so we can lay out the | 965 // Always lay out the icon, even when it's not present, so we can lay out the |
966 // window title based on its position. | 966 // window title based on its position. |
967 int frame_thickness = FrameBorderThickness(); | 967 int frame_thickness = FrameBorderThickness(); |
968 int icon_x = frame_thickness + kIconLeftSpacing; | 968 int icon_x = frame_thickness + kIconLeftSpacing; |
969 | 969 |
970 // The usable height of the titlebar area is the total height minus the top | 970 // The usable height of the titlebar area is the total height minus the top |
971 // resize border and any edge area we draw at its bottom. | 971 // resize border and any edge area we draw at its bottom. |
972 int title_top_spacing, title_thickness; | 972 int title_top_spacing, title_thickness; |
| 973 InitAppWindowResources(); |
973 int top_height = TitleCoordinates(&title_top_spacing, &title_thickness); | 974 int top_height = TitleCoordinates(&title_top_spacing, &title_thickness); |
974 int available_height = top_height - frame_thickness - | 975 int available_height = top_height - frame_thickness - |
975 UnavailablePixelsAtBottomOfNonClientHeight(); | 976 UnavailablePixelsAtBottomOfNonClientHeight(); |
976 | 977 |
977 // The icon takes up a constant fraction of the available height, down to a | 978 // The icon takes up a constant fraction of the available height, down to a |
978 // minimum size, and is always an even number of pixels on a side (presumably | 979 // minimum size, and is always an even number of pixels on a side (presumably |
979 // to make scaled icons look better). It's centered within the usable height. | 980 // to make scaled icons look better). It's centered within the usable height. |
980 int icon_size = std::max((available_height * kIconHeightFractionNumerator / | 981 int icon_size = std::max((available_height * kIconHeightFractionNumerator / |
981 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize); | 982 kIconHeightFractionDenominator) / 2 * 2, kIconMinimumSize); |
982 int icon_y = ((available_height - icon_size) / 2) + frame_thickness; | 983 int icon_y = ((available_height - icon_size) / 2) + frame_thickness; |
(...skipping 11 matching lines...) Expand all Loading... |
994 if (!d->ShouldShowWindowIcon()) | 995 if (!d->ShouldShowWindowIcon()) |
995 icon_size = 0; | 996 icon_size = 0; |
996 if (window_icon_) | 997 if (window_icon_) |
997 window_icon_->SetBounds(icon_x, icon_y, icon_size, icon_size); | 998 window_icon_->SetBounds(icon_x, icon_y, icon_size, icon_size); |
998 | 999 |
999 // Size the title, if visible. | 1000 // Size the title, if visible. |
1000 if (d->ShouldShowWindowTitle()) { | 1001 if (d->ShouldShowWindowTitle()) { |
1001 int title_x = icon_x + icon_size + | 1002 int title_x = icon_x + icon_size + |
1002 (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); | 1003 (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); |
1003 title_bounds_.SetRect(title_x, | 1004 title_bounds_.SetRect(title_x, |
1004 title_top_spacing + ((title_thickness - title_font_.height()) / 2), | 1005 title_top_spacing + ((title_thickness - title_font_->height()) / 2), |
1005 std::max(0, logo_bounds_.x() - kTitleLogoSpacing - title_x), | 1006 std::max(0, logo_bounds_.x() - kTitleLogoSpacing - title_x), |
1006 title_font_.height()); | 1007 title_font_->height()); |
1007 } | 1008 } |
1008 } | 1009 } |
1009 | 1010 |
1010 void OpaqueBrowserFrameView::LayoutOTRAvatar() { | 1011 void OpaqueBrowserFrameView::LayoutOTRAvatar() { |
1011 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); | 1012 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); |
1012 int top_height = NonClientTopBorderHeight(); | 1013 int top_height = NonClientTopBorderHeight(); |
1013 int tabstrip_height, otr_height; | 1014 int tabstrip_height, otr_height; |
1014 if (browser_view_->IsTabStripVisible()) { | 1015 if (browser_view_->IsTabStripVisible()) { |
1015 tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing; | 1016 tabstrip_height = browser_view_->GetTabStripHeight() - kOTRBottomSpacing; |
1016 otr_height = frame_->IsMaximized() ? | 1017 otr_height = frame_->IsMaximized() ? |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1050 #endif | 1051 #endif |
1051 | 1052 |
1052 initialized = true; | 1053 initialized = true; |
1053 } | 1054 } |
1054 } | 1055 } |
1055 | 1056 |
1056 // static | 1057 // static |
1057 void OpaqueBrowserFrameView::InitAppWindowResources() { | 1058 void OpaqueBrowserFrameView::InitAppWindowResources() { |
1058 static bool initialized = false; | 1059 static bool initialized = false; |
1059 if (!initialized) { | 1060 if (!initialized) { |
1060 title_font_ = win_util::GetWindowTitleFont(); | 1061 title_font_ = new ChromeFont(win_util::GetWindowTitleFont()); |
1061 initialized = true; | 1062 initialized = true; |
1062 } | 1063 } |
1063 } | 1064 } |
OLD | NEW |