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

Side by Side Diff: chrome/views/custom_frame_window.cc

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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/views/custom_frame_window.h" 5 #include "chrome/views/custom_frame_window.h"
6 6
7 #include "base/gfx/point.h" 7 #include "base/gfx/point.h"
8 #include "base/gfx/size.h" 8 #include "base/gfx/size.h"
9 #include "base/win_util.h" 9 #include "base/win_util.h"
10 #include "chrome/app/theme/theme_resources.h" 10 #include "chrome/app/theme/theme_resources.h"
(...skipping 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 virtual gfx::Size CalculateWindowSizeForClientSize(int width, 237 virtual gfx::Size CalculateWindowSizeForClientSize(int width,
238 int height) const; 238 int height) const;
239 virtual CPoint GetSystemMenuPoint() const; 239 virtual CPoint GetSystemMenuPoint() const;
240 virtual int NonClientHitTest(const gfx::Point& point); 240 virtual int NonClientHitTest(const gfx::Point& point);
241 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask); 241 virtual void GetWindowMask(const gfx::Size& size, gfx::Path* window_mask);
242 virtual void EnableClose(bool enable); 242 virtual void EnableClose(bool enable);
243 243
244 // View overrides: 244 // View overrides:
245 virtual void Paint(ChromeCanvas* canvas); 245 virtual void Paint(ChromeCanvas* canvas);
246 virtual void Layout(); 246 virtual void Layout();
247 virtual void GetPreferredSize(CSize* out); 247 virtual gfx::Size GetPreferredSize();
248 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); 248 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
249 249
250 // BaseButton::ButtonListener implementation: 250 // BaseButton::ButtonListener implementation:
251 virtual void ButtonPressed(BaseButton* sender); 251 virtual void ButtonPressed(BaseButton* sender);
252 252
253 private: 253 private:
254 // Updates the system menu icon button. 254 // Updates the system menu icon button.
255 void SetWindowIcon(SkBitmap window_icon); 255 void SetWindowIcon(SkBitmap window_icon);
256 256
257 // Returns the height of the non-client area at the top of the window (the 257 // Returns the height of the non-client area at the top of the window (the
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
508 } 508 }
509 } 509 }
510 510
511 void DefaultNonClientView::Layout() { 511 void DefaultNonClientView::Layout() {
512 LayoutWindowControls(); 512 LayoutWindowControls();
513 LayoutTitleBar(); 513 LayoutTitleBar();
514 LayoutClientView(); 514 LayoutClientView();
515 SchedulePaint(); 515 SchedulePaint();
516 } 516 }
517 517
518 void DefaultNonClientView::GetPreferredSize(CSize* out) { 518 gfx::Size DefaultNonClientView::GetPreferredSize() {
519 DCHECK(out); 519 gfx::Size prefsize = container_->client_view()->GetPreferredSize();
520 container_->client_view()->GetPreferredSize(out); 520 prefsize.Enlarge(2 * kWindowHorizontalBorderSize,
521 out->cx += 2 * kWindowHorizontalBorderSize; 521 CalculateContentsTop() + kWindowVerticalBorderSize);
522 out->cy += CalculateContentsTop() + kWindowVerticalBorderSize; 522 return prefsize;
523 } 523 }
524 524
525 void DefaultNonClientView::ViewHierarchyChanged(bool is_add, 525 void DefaultNonClientView::ViewHierarchyChanged(bool is_add,
526 View* parent, 526 View* parent,
527 View* child) { 527 View* child) {
528 // Add our Client View as we are added to the ViewContainer so that if we are 528 // Add our Client View as we are added to the ViewContainer so that if we are
529 // subsequently resized all the parent-child relationships are established. 529 // subsequently resized all the parent-child relationships are established.
530 if (is_add && GetViewContainer() && child == this) 530 if (is_add && GetViewContainer() && child == this)
531 AddChildView(container_->client_view()); 531 AddChildView(container_->client_view());
532 } 532 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 canvas->DrawBitmapInt(*bottom_left, 652 canvas->DrawBitmapInt(*bottom_left,
653 client_area_bounds.x() - bottom_left->width(), 653 client_area_bounds.x() - bottom_left->width(),
654 client_area_bounds.bottom()); 654 client_area_bounds.bottom());
655 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(), 655 canvas->TileImageInt(*left, client_area_bounds.x() - left->width(),
656 client_area_bounds.y() - top->height() + 656 client_area_bounds.y() - top->height() +
657 top_left->height(), 657 top_left->height(),
658 left->width(), client_area_bounds.height()); 658 left->width(), client_area_bounds.height());
659 } 659 }
660 660
661 void DefaultNonClientView::LayoutWindowControls() { 661 void DefaultNonClientView::LayoutWindowControls() {
662 CSize ps; 662 gfx::Size ps;
663 if (container_->IsMaximized() || container_->IsMinimized()) { 663 if (container_->IsMaximized() || container_->IsMinimized()) {
664 maximize_button_->SetVisible(false); 664 maximize_button_->SetVisible(false);
665 restore_button_->SetVisible(true); 665 restore_button_->SetVisible(true);
666 } 666 }
667 667
668 if (container_->IsMaximized()) { 668 if (container_->IsMaximized()) {
669 close_button_->GetPreferredSize(&ps); 669 ps = close_button_->GetPreferredSize();
670 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); 670 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM);
671 close_button_->SetBounds( 671 close_button_->SetBounds(
672 width() - ps.cx - kWindowControlsRightZoomedOffset, 672 width() - ps.width() - kWindowControlsRightZoomedOffset,
673 0, ps.cx + kWindowControlsRightZoomedOffset, 673 0, ps.width() + kWindowControlsRightZoomedOffset,
674 ps.cy + kWindowControlsTopZoomedOffset); 674 ps.height() + kWindowControlsTopZoomedOffset);
675 675
676 if (should_show_minmax_buttons_) { 676 if (should_show_minmax_buttons_) {
677 restore_button_->GetPreferredSize(&ps); 677 ps = restore_button_->GetPreferredSize();
678 restore_button_->SetImageAlignment(Button::ALIGN_LEFT, 678 restore_button_->SetImageAlignment(Button::ALIGN_LEFT,
679 Button::ALIGN_BOTTOM); 679 Button::ALIGN_BOTTOM);
680 restore_button_->SetBounds(close_button_->x() - ps.cx, 0, ps.cx, 680 restore_button_->SetBounds(close_button_->x() - ps.width(), 0,
681 ps.cy + kWindowControlsTopZoomedOffset); 681 ps.width(),
682 ps.height() + kWindowControlsTopZoomedOffset);
682 683
683 minimize_button_->GetPreferredSize(&ps); 684 ps = minimize_button_->GetPreferredSize();
684 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT, 685 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT,
685 Button::ALIGN_BOTTOM); 686 Button::ALIGN_BOTTOM);
686 minimize_button_->SetBounds(restore_button_->x() - ps.cx, 0, ps.cx, 687 minimize_button_->SetBounds(restore_button_->x() - ps.width(), 0,
687 ps.cy + kWindowControlsTopZoomedOffset); 688 ps.width(),
689 ps.height() + kWindowControlsTopZoomedOffset);
688 } 690 }
689 } else if (container_->IsMinimized()) { 691 } else if (container_->IsMinimized()) {
690 close_button_->GetPreferredSize(&ps); 692 ps = close_button_->GetPreferredSize();
691 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM); 693 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_BOTTOM);
692 close_button_->SetBounds( 694 close_button_->SetBounds(
693 width() - ps.cx - kWindowControlsRightZoomedOffset, 695 width() - ps.width() - kWindowControlsRightZoomedOffset,
694 0, ps.cx + kWindowControlsRightZoomedOffset, 696 0, ps.width() + kWindowControlsRightZoomedOffset,
695 ps.cy + kWindowControlsTopZoomedOffset); 697 ps.height() + kWindowControlsTopZoomedOffset);
696 698
697 if (should_show_minmax_buttons_) { 699 if (should_show_minmax_buttons_) {
698 restore_button_->GetPreferredSize(&ps); 700 ps = restore_button_->GetPreferredSize();
699 restore_button_->SetImageAlignment(Button::ALIGN_LEFT, 701 restore_button_->SetImageAlignment(Button::ALIGN_LEFT,
700 Button::ALIGN_BOTTOM); 702 Button::ALIGN_BOTTOM);
701 restore_button_->SetBounds(close_button_->x() - ps.cx, 0, ps.cx, 703 restore_button_->SetBounds(close_button_->x() - ps.width(), 0,
702 ps.cy + kWindowControlsTopZoomedOffset); 704 ps.width(),
705 ps.height() + kWindowControlsTopZoomedOffset);
703 706
704 minimize_button_->GetPreferredSize(&ps); 707 ps = minimize_button_->GetPreferredSize();
705 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT, 708 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT,
706 Button::ALIGN_BOTTOM); 709 Button::ALIGN_BOTTOM);
707 minimize_button_->SetBounds(restore_button_->x() - ps.cx, 0, ps.cx, 710 minimize_button_->SetBounds(restore_button_->x() - ps.width(), 0,
708 ps.cy + kWindowControlsTopZoomedOffset); 711 ps.width(),
712 ps.height() +
713 kWindowControlsTopZoomedOffset);
709 } 714 }
710 } else { 715 } else {
711 close_button_->GetPreferredSize(&ps); 716 ps = close_button_->GetPreferredSize();
712 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_TOP); 717 close_button_->SetImageAlignment(Button::ALIGN_LEFT, Button::ALIGN_TOP);
713 close_button_->SetBounds(width() - kWindowControlsRightOffset - ps.cx, 718 close_button_->SetBounds(width() - kWindowControlsRightOffset - ps.width(),
714 kWindowControlsTopOffset, ps.cx, ps.cy); 719 kWindowControlsTopOffset, ps.width(),
720 ps.height());
715 721
716 if (should_show_minmax_buttons_) { 722 if (should_show_minmax_buttons_) {
717 close_button_->SetImage( 723 close_button_->SetImage(
718 Button::BS_NORMAL, 724 Button::BS_NORMAL,
719 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON)); 725 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON));
720 close_button_->SetImage( 726 close_button_->SetImage(
721 Button::BS_HOT, 727 Button::BS_HOT,
722 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H)); 728 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_H));
723 close_button_->SetImage( 729 close_button_->SetImage(
724 Button::BS_PUSHED, 730 Button::BS_PUSHED,
725 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P)); 731 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_P));
726 732
727 restore_button_->SetVisible(false); 733 restore_button_->SetVisible(false);
728 734
729 maximize_button_->SetVisible(true); 735 maximize_button_->SetVisible(true);
730 maximize_button_->GetPreferredSize(&ps); 736 ps = maximize_button_->GetPreferredSize();
731 maximize_button_->SetImageAlignment(Button::ALIGN_LEFT, 737 maximize_button_->SetImageAlignment(Button::ALIGN_LEFT,
732 Button::ALIGN_TOP); 738 Button::ALIGN_TOP);
733 maximize_button_->SetBounds(close_button_->x() - ps.cx, 739 maximize_button_->SetBounds(close_button_->x() - ps.width(),
734 kWindowControlsTopOffset, ps.cx, ps.cy); 740 kWindowControlsTopOffset, ps.width(),
741 ps.height());
735 742
736 minimize_button_->GetPreferredSize(&ps); 743 ps = minimize_button_->GetPreferredSize();
737 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT, 744 minimize_button_->SetImageAlignment(Button::ALIGN_LEFT,
738 Button::ALIGN_TOP); 745 Button::ALIGN_TOP);
739 minimize_button_->SetBounds(maximize_button_->x() - ps.cx, 746 minimize_button_->SetBounds(maximize_button_->x() - ps.width(),
740 kWindowControlsTopOffset, ps.cx, ps.cy); 747 kWindowControlsTopOffset, ps.width(),
748 ps.height());
741 } 749 }
742 } 750 }
743 if (!should_show_minmax_buttons_) { 751 if (!should_show_minmax_buttons_) {
744 close_button_->SetImage( 752 close_button_->SetImage(
745 Button::BS_NORMAL, 753 Button::BS_NORMAL,
746 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA)); 754 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA));
747 close_button_->SetImage( 755 close_button_->SetImage(
748 Button::BS_HOT, 756 Button::BS_HOT,
749 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA_H)); 757 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA_H));
750 close_button_->SetImage( 758 close_button_->SetImage(
751 Button::BS_PUSHED, 759 Button::BS_PUSHED,
752 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA_P)); 760 active_resources_->GetPartBitmap(FRAME_CLOSE_BUTTON_ICON_SA_P));
753 761
754 restore_button_->SetVisible(false); 762 restore_button_->SetVisible(false);
755 maximize_button_->SetVisible(false); 763 maximize_button_->SetVisible(false);
756 minimize_button_->SetVisible(false); 764 minimize_button_->SetVisible(false);
757 } 765 }
758 } 766 }
759 767
760 void DefaultNonClientView::LayoutTitleBar() { 768 void DefaultNonClientView::LayoutTitleBar() {
761 int top_offset = container_->IsMaximized() ? kWindowTopMarginZoomed : 0; 769 int top_offset = container_->IsMaximized() ? kWindowTopMarginZoomed : 0;
762 WindowDelegate* d = container_->window_delegate(); 770 WindowDelegate* d = container_->window_delegate();
763 771
764 // Size the window icon, if visible. 772 // Size the window icon, if visible.
765 if (d->ShouldShowWindowIcon()) { 773 if (d->ShouldShowWindowIcon()) {
766 system_menu_button_->SetVisible(true); 774 system_menu_button_->SetVisible(true);
767 CSize ps; 775 gfx::Size ps = system_menu_button_->GetPreferredSize();
768 system_menu_button_->GetPreferredSize(&ps);
769 system_menu_button_->SetBounds( 776 system_menu_button_->SetBounds(
770 kWindowIconLeftOffset, kWindowIconTopOffset + top_offset, ps.cx, ps.cy); 777 kWindowIconLeftOffset, kWindowIconTopOffset + top_offset, ps.width(),
778 ps.height());
771 } else { 779 } else {
772 // Put the menu in the right place at least even if it is hidden so we 780 // Put the menu in the right place at least even if it is hidden so we
773 // can size the title based on its position. 781 // can size the title based on its position.
774 system_menu_button_->SetBounds(kWindowIconLeftOffset, 782 system_menu_button_->SetBounds(kWindowIconLeftOffset,
775 kWindowIconTopOffset, 0, 0); 783 kWindowIconTopOffset, 0, 0);
776 } 784 }
777 785
778 // Size the title, if visible. 786 // Size the title, if visible.
779 if (d->ShouldShowWindowTitle()) { 787 if (d->ShouldShowWindowTitle()) {
780 gfx::Rect system_menu_bounds = system_menu_button_->bounds(); 788 gfx::Rect system_menu_bounds = system_menu_button_->bounds();
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 virtual void Layout(ChromeViews::View* host) { 857 virtual void Layout(ChromeViews::View* host) {
850 int horizontal_border_width = 858 int horizontal_border_width =
851 window_->IsMaximized() ? kBorderAndPadding : 0; 859 window_->IsMaximized() ? kBorderAndPadding : 0;
852 int vertical_border_height = 860 int vertical_border_height =
853 window_->IsMaximized() ? kBorderAndPadding : 0; 861 window_->IsMaximized() ? kBorderAndPadding : 0;
854 862
855 child_->SetBounds(horizontal_border_width, vertical_border_height, 863 child_->SetBounds(horizontal_border_width, vertical_border_height,
856 host->width() - (2 * horizontal_border_width), 864 host->width() - (2 * horizontal_border_width),
857 host->height() - (2 * vertical_border_height)); 865 host->height() - (2 * vertical_border_height));
858 } 866 }
859 virtual void GetPreferredSize(ChromeViews::View* host, CSize* out) { 867 virtual gfx::Size GetPreferredSize(ChromeViews::View* host) {
860 child_->GetPreferredSize(out); 868 return child_->GetPreferredSize();
861 } 869 }
862 870
863 private: 871 private:
864 ChromeViews::View* child_; 872 ChromeViews::View* child_;
865 ChromeViews::Window* window_; 873 ChromeViews::Window* window_;
866 874
867 DISALLOW_COPY_AND_ASSIGN(NonClientViewLayout); 875 DISALLOW_COPY_AND_ASSIGN(NonClientViewLayout);
868 }; 876 };
869 877
870 /////////////////////////////////////////////////////////////////////////////// 878 ///////////////////////////////////////////////////////////////////////////////
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
945 } 953 }
946 954
947 void CustomFrameWindow::DisableInactiveRendering(bool disable) { 955 void CustomFrameWindow::DisableInactiveRendering(bool disable) {
948 Window::DisableInactiveRendering(disable); 956 Window::DisableInactiveRendering(disable);
949 non_client_view_->set_paint_as_active(disable); 957 non_client_view_->set_paint_as_active(disable);
950 if (!disable) 958 if (!disable)
951 non_client_view_->SchedulePaint(); 959 non_client_view_->SchedulePaint();
952 } 960 }
953 961
954 void CustomFrameWindow::SizeWindowToDefault() { 962 void CustomFrameWindow::SizeWindowToDefault() {
955 CSize pref(0, 0); 963 gfx::Size pref = client_view()->GetPreferredSize();
956 client_view()->GetPreferredSize(&pref); 964 DCHECK(pref.width() > 0 && pref.height() > 0);
957 DCHECK(pref.cx > 0 && pref.cy > 0);
958 gfx::Size window_size = 965 gfx::Size window_size =
959 non_client_view_->CalculateWindowSizeForClientSize(pref.cx, pref.cy); 966 non_client_view_->CalculateWindowSizeForClientSize(pref.width(),
967 pref.height());
960 win_util::CenterAndSizeWindow(owning_window(), GetHWND(), 968 win_util::CenterAndSizeWindow(owning_window(), GetHWND(),
961 window_size.ToSIZE(), false); 969 window_size.ToSIZE(), false);
962 } 970 }
963 971
964 /////////////////////////////////////////////////////////////////////////////// 972 ///////////////////////////////////////////////////////////////////////////////
965 // CustomFrameWindow, HWNDViewContainer overrides: 973 // CustomFrameWindow, HWNDViewContainer overrides:
966 974
967 void CustomFrameWindow::OnGetMinMaxInfo(MINMAXINFO* minmax_info) { 975 void CustomFrameWindow::OnGetMinMaxInfo(MINMAXINFO* minmax_info) {
968 // We handle this message so that we can make sure we interact nicely with 976 // We handle this message so that we can make sure we interact nicely with
969 // the taskbar on different edges of the screen and auto-hide taskbars. 977 // the taskbar on different edges of the screen and auto-hide taskbars.
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1307 SetWindowRgn(new_region, TRUE); 1315 SetWindowRgn(new_region, TRUE);
1308 } else if (new_region) { 1316 } else if (new_region) {
1309 DeleteObject(new_region); 1317 DeleteObject(new_region);
1310 } 1318 }
1311 1319
1312 DeleteObject(current_rgn); 1320 DeleteObject(current_rgn);
1313 } 1321 }
1314 1322
1315 } // namespace ChromeViews 1323 } // namespace ChromeViews
1316 1324
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698