OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/views/window/custom_frame_view.h" | 5 #include "chrome/views/window/custom_frame_view.h" |
6 | 6 |
7 #include "base/win_util.h" | 7 #include "base/win_util.h" |
8 #include "chrome/common/gfx/path.h" | 8 #include "chrome/common/gfx/path.h" |
9 #include "chrome/common/gfx/chrome_canvas.h" | 9 #include "chrome/common/gfx/chrome_canvas.h" |
10 #include "chrome/common/gfx/chrome_font.h" | 10 #include "chrome/common/gfx/chrome_font.h" |
(...skipping 88 matching lines...) Loading... |
99 for (int i = 0; i < FRAME_PART_BITMAP_COUNT; ++i) { | 99 for (int i = 0; i < FRAME_PART_BITMAP_COUNT; ++i) { |
100 int id = kFramePartBitmapIds[i]; | 100 int id = kFramePartBitmapIds[i]; |
101 if (id != 0) | 101 if (id != 0) |
102 standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id); | 102 standard_frame_bitmaps_[i] = rb.GetBitmapNamed(id); |
103 } | 103 } |
104 initialized = true; | 104 initialized = true; |
105 } | 105 } |
106 } | 106 } |
107 | 107 |
108 static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT]; | 108 static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT]; |
109 static ChromeFont title_font_; | |
110 | 109 |
111 DISALLOW_EVIL_CONSTRUCTORS(ActiveWindowResources); | 110 DISALLOW_EVIL_CONSTRUCTORS(ActiveWindowResources); |
112 }; | 111 }; |
113 | 112 |
114 class InactiveWindowResources : public WindowResources { | 113 class InactiveWindowResources : public WindowResources { |
115 public: | 114 public: |
116 InactiveWindowResources() { | 115 InactiveWindowResources() { |
117 InitClass(); | 116 InitClass(); |
118 } | 117 } |
119 virtual ~InactiveWindowResources() { | 118 virtual ~InactiveWindowResources() { |
(...skipping 41 matching lines...) Loading... |
161 DISALLOW_EVIL_CONSTRUCTORS(InactiveWindowResources); | 160 DISALLOW_EVIL_CONSTRUCTORS(InactiveWindowResources); |
162 }; | 161 }; |
163 | 162 |
164 // static | 163 // static |
165 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; | 164 SkBitmap* ActiveWindowResources::standard_frame_bitmaps_[]; |
166 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; | 165 SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; |
167 | 166 |
168 // static | 167 // static |
169 WindowResources* CustomFrameView::active_resources_ = NULL; | 168 WindowResources* CustomFrameView::active_resources_ = NULL; |
170 WindowResources* CustomFrameView::inactive_resources_ = NULL; | 169 WindowResources* CustomFrameView::inactive_resources_ = NULL; |
171 ChromeFont CustomFrameView::title_font_; | 170 ChromeFont* CustomFrameView::title_font_ = NULL; |
172 | 171 |
173 namespace { | 172 namespace { |
174 // The frame border is only visible in restored mode and is hardcoded to 4 px on | 173 // The frame border is only visible in restored mode and is hardcoded to 4 px on |
175 // each side regardless of the system window border size. | 174 // each side regardless of the system window border size. |
176 const int kFrameBorderThickness = 4; | 175 const int kFrameBorderThickness = 4; |
177 // Various edges of the frame border have a 1 px shadow along their edges; in a | 176 // Various edges of the frame border have a 1 px shadow along their edges; in a |
178 // few cases we shift elements based on this amount for visual appeal. | 177 // few cases we shift elements based on this amount for visual appeal. |
179 const int kFrameShadowThickness = 1; | 178 const int kFrameShadowThickness = 1; |
180 // While resize areas on Windows are normally the same size as the window | 179 // While resize areas on Windows are normally the same size as the window |
181 // borders, our top area is shrunk by 1 px to make it easier to move the window | 180 // borders, our top area is shrunk by 1 px to make it easier to move the window |
(...skipping 244 matching lines...) Loading... |
426 // since while it's part of the bottom spacing it will be added in at the end. | 425 // since while it's part of the bottom spacing it will be added in at the end. |
427 int title_bottom_spacing = | 426 int title_bottom_spacing = |
428 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; | 427 kFrameBorderThickness + kTitleTopSpacing - kFrameShadowThickness; |
429 if (frame_->IsMaximized()) { | 428 if (frame_->IsMaximized()) { |
430 // When we maximize, the top border appears to be chopped off; shift the | 429 // When we maximize, the top border appears to be chopped off; shift the |
431 // title down to stay centered within the remaining space. | 430 // title down to stay centered within the remaining space. |
432 int title_adjust = (kFrameBorderThickness / 2); | 431 int title_adjust = (kFrameBorderThickness / 2); |
433 *title_top_spacing += title_adjust; | 432 *title_top_spacing += title_adjust; |
434 title_bottom_spacing -= title_adjust; | 433 title_bottom_spacing -= title_adjust; |
435 } | 434 } |
436 *title_thickness = std::max(title_font_.height(), | 435 *title_thickness = std::max(title_font_->height(), |
437 min_titlebar_height - *title_top_spacing - title_bottom_spacing); | 436 min_titlebar_height - *title_top_spacing - title_bottom_spacing); |
438 return *title_top_spacing + *title_thickness + title_bottom_spacing + | 437 return *title_top_spacing + *title_thickness + title_bottom_spacing + |
439 BottomEdgeThicknessWithinNonClientHeight(); | 438 BottomEdgeThicknessWithinNonClientHeight(); |
440 } | 439 } |
441 | 440 |
442 void CustomFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { | 441 void CustomFrameView::PaintRestoredFrameBorder(ChromeCanvas* canvas) { |
443 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); | 442 SkBitmap* top_left_corner = resources()->GetPartBitmap(FRAME_TOP_LEFT_CORNER); |
444 SkBitmap* top_right_corner = | 443 SkBitmap* top_right_corner = |
445 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); | 444 resources()->GetPartBitmap(FRAME_TOP_RIGHT_CORNER); |
446 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); | 445 SkBitmap* top_edge = resources()->GetPartBitmap(FRAME_TOP_EDGE); |
(...skipping 52 matching lines...) Loading... |
499 | 498 |
500 void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { | 499 void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { |
501 WindowDelegate* d = frame_->GetDelegate(); | 500 WindowDelegate* d = frame_->GetDelegate(); |
502 | 501 |
503 // It seems like in some conditions we can be asked to paint after the window | 502 // It seems like in some conditions we can be asked to paint after the window |
504 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The | 503 // that contains us is WM_DESTROYed. At this point, our delegate is NULL. The |
505 // correct long term fix may be to shut down the RootView in WM_DESTROY. | 504 // correct long term fix may be to shut down the RootView in WM_DESTROY. |
506 if (!d) | 505 if (!d) |
507 return; | 506 return; |
508 | 507 |
509 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, | 508 canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, SK_ColorWHITE, |
510 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), | 509 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), |
511 title_bounds_.width(), title_bounds_.height()); | 510 title_bounds_.width(), title_bounds_.height()); |
512 } | 511 } |
513 | 512 |
514 void CustomFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { | 513 void CustomFrameView::PaintRestoredClientEdge(ChromeCanvas* canvas) { |
515 gfx::Rect client_area_bounds = frame_->GetClientView()->bounds(); | 514 gfx::Rect client_area_bounds = frame_->GetClientView()->bounds(); |
516 int client_area_top = client_area_bounds.y(); | 515 int client_area_top = client_area_bounds.y(); |
517 | 516 |
518 SkBitmap* top_left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); | 517 SkBitmap* top_left = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP_LEFT); |
519 SkBitmap* top = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); | 518 SkBitmap* top = resources()->GetPartBitmap(FRAME_CLIENT_EDGE_TOP); |
(...skipping 140 matching lines...) Loading... |
660 icon_size = 0; | 659 icon_size = 0; |
661 system_menu_button_->SetBounds(icon_x, icon_y, icon_size, icon_size); | 660 system_menu_button_->SetBounds(icon_x, icon_y, icon_size, icon_size); |
662 | 661 |
663 // Size the title. | 662 // Size the title. |
664 int icon_right = icon_x + icon_size; | 663 int icon_right = icon_x + icon_size; |
665 int title_x = | 664 int title_x = |
666 icon_right + (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); | 665 icon_right + (d->ShouldShowWindowIcon() ? kIconTitleSpacing : 0); |
667 int title_right = (should_show_minmax_buttons_ ? | 666 int title_right = (should_show_minmax_buttons_ ? |
668 minimize_button_->x() : close_button_->x()) - kTitleCaptionSpacing; | 667 minimize_button_->x() : close_button_->x()) - kTitleCaptionSpacing; |
669 title_bounds_.SetRect(title_x, | 668 title_bounds_.SetRect(title_x, |
670 title_top_spacing + ((title_thickness - title_font_.height()) / 2), | 669 title_top_spacing + ((title_thickness - title_font_->height()) / 2), |
671 std::max(0, title_right - title_x), title_font_.height()); | 670 std::max(0, title_right - title_x), title_font_->height()); |
672 } | 671 } |
673 | 672 |
674 void CustomFrameView::LayoutClientView() { | 673 void CustomFrameView::LayoutClientView() { |
675 int top_height = NonClientTopBorderHeight(); | 674 int top_height = NonClientTopBorderHeight(); |
676 int border_thickness = NonClientBorderThickness(); | 675 int border_thickness = NonClientBorderThickness(); |
677 client_view_bounds_.SetRect( | 676 client_view_bounds_.SetRect( |
678 border_thickness, | 677 border_thickness, |
679 top_height, | 678 top_height, |
680 std::max(0, width() - (2 * border_thickness)), | 679 std::max(0, width() - (2 * border_thickness)), |
681 std::max(0, height() - top_height - border_thickness)); | 680 std::max(0, height() - top_height - border_thickness)); |
682 } | 681 } |
683 | 682 |
684 // static | 683 // static |
685 void CustomFrameView::InitClass() { | 684 void CustomFrameView::InitClass() { |
686 static bool initialized = false; | 685 static bool initialized = false; |
687 if (!initialized) { | 686 if (!initialized) { |
688 active_resources_ = new ActiveWindowResources; | 687 active_resources_ = new ActiveWindowResources; |
689 inactive_resources_ = new InactiveWindowResources; | 688 inactive_resources_ = new InactiveWindowResources; |
690 | 689 |
691 title_font_ = win_util::GetWindowTitleFont(); | 690 title_font_ = new ChromeFont(win_util::GetWindowTitleFont()); |
692 | 691 |
693 initialized = true; | 692 initialized = true; |
694 } | 693 } |
695 } | 694 } |
696 | 695 |
697 } // namespace views | 696 } // namespace views |
OLD | NEW |