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

Side by Side Diff: chrome/browser/views/old_frames/xp_frame.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/browser/views/old_frames/xp_frame.h" 5 #include "chrome/browser/views/old_frames/xp_frame.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/gfx/native_theme.h" 10 #include "base/gfx/native_theme.h"
(...skipping 566 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 577
578 void XPFrame::Layout() { 578 void XPFrame::Layout() {
579 CRect client_rect; 579 CRect client_rect;
580 GetClientRect(&client_rect); 580 GetClientRect(&client_rect);
581 int width = client_rect.Width(); 581 int width = client_rect.Width();
582 int height = client_rect.Height(); 582 int height = client_rect.Height();
583 583
584 root_view_.SetBounds(0, 0, width, height); 584 root_view_.SetBounds(0, 0, width, height);
585 frame_view_->SetBounds(0, 0, width, height); 585 frame_view_->SetBounds(0, 0, width, height);
586 586
587 CSize preferred_size; 587 gfx::Size preferred_size;
588 588
589 if (IsZoomed()) { 589 if (IsZoomed()) {
590 close_button_->GetPreferredSize(&preferred_size); 590 preferred_size = close_button_->GetPreferredSize();
591 close_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 591 close_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
592 ChromeViews::Button::ALIGN_BOTTOM); 592 ChromeViews::Button::ALIGN_BOTTOM);
593 close_button_->SetBounds(width - preferred_size.cx - 593 close_button_->SetBounds(width - preferred_size.width() -
594 kWindowControlsRightZoomedOffset, 594 kWindowControlsRightZoomedOffset,
595 0, 595 0,
596 preferred_size.cx + 596 preferred_size.width() +
597 kWindowControlsRightZoomedOffset, 597 kWindowControlsRightZoomedOffset,
598 preferred_size.cy + 598 preferred_size.height() +
599 kWindowControlsTopZoomedOffset); 599 kWindowControlsTopZoomedOffset);
600 600
601 max_button_->SetVisible(false); 601 max_button_->SetVisible(false);
602 602
603 restore_button_->SetVisible(true); 603 restore_button_->SetVisible(true);
604 restore_button_->GetPreferredSize(&preferred_size); 604 preferred_size = restore_button_->GetPreferredSize();
605 restore_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 605 restore_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
606 ChromeViews::Button::ALIGN_BOTTOM); 606 ChromeViews::Button::ALIGN_BOTTOM);
607 restore_button_->SetBounds(close_button_->x() - preferred_size.cx, 607 restore_button_->SetBounds(close_button_->x() - preferred_size.width(),
608 0, 608 0,
609 preferred_size.cx, 609 preferred_size.width(),
610 preferred_size.cy + 610 preferred_size.height() +
611 kWindowControlsTopZoomedOffset); 611 kWindowControlsTopZoomedOffset);
612 612
613 min_button_->GetPreferredSize(&preferred_size); 613 preferred_size = min_button_->GetPreferredSize();
614 min_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 614 min_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
615 ChromeViews::Button::ALIGN_BOTTOM); 615 ChromeViews::Button::ALIGN_BOTTOM);
616 min_button_->SetBounds(restore_button_->x() - preferred_size.cx, 616 min_button_->SetBounds(restore_button_->x() - preferred_size.width(),
617 0, 617 0,
618 preferred_size.cx, 618 preferred_size.width(),
619 preferred_size.cy + 619 preferred_size.height() +
620 kWindowControlsTopZoomedOffset); 620 kWindowControlsTopZoomedOffset);
621 621
622 } else { 622 } else {
623 close_button_->GetPreferredSize(&preferred_size); 623 preferred_size = close_button_->GetPreferredSize();
624 close_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 624 close_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
625 ChromeViews::Button::ALIGN_TOP); 625 ChromeViews::Button::ALIGN_TOP);
626 close_button_->SetBounds(width - kWindowControlsRightOffset - 626 close_button_->SetBounds(width - kWindowControlsRightOffset -
627 preferred_size.cx, 627 preferred_size.width(),
628 kWindowControlsTopOffset, 628 kWindowControlsTopOffset,
629 preferred_size.cx, 629 preferred_size.width(),
630 preferred_size.cy); 630 preferred_size.height());
631 631
632 restore_button_->SetVisible(false); 632 restore_button_->SetVisible(false);
633 633
634 max_button_->SetVisible(true); 634 max_button_->SetVisible(true);
635 max_button_->GetPreferredSize(&preferred_size); 635 preferred_size = max_button_->GetPreferredSize();
636 max_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 636 max_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
637 ChromeViews::Button::ALIGN_TOP); 637 ChromeViews::Button::ALIGN_TOP);
638 max_button_->SetBounds(close_button_->x() - preferred_size.cx, 638 max_button_->SetBounds(close_button_->x() - preferred_size.width(),
639 kWindowControlsTopOffset, 639 kWindowControlsTopOffset,
640 preferred_size.cx, 640 preferred_size.width(),
641 preferred_size.cy); 641 preferred_size.height());
642 642
643 min_button_->GetPreferredSize(&preferred_size); 643 preferred_size = min_button_->GetPreferredSize();
644 min_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT, 644 min_button_->SetImageAlignment(ChromeViews::Button::ALIGN_LEFT,
645 ChromeViews::Button::ALIGN_TOP); 645 ChromeViews::Button::ALIGN_TOP);
646 min_button_->SetBounds(max_button_->x() - preferred_size.cx, 646 min_button_->SetBounds(max_button_->x() - preferred_size.width(),
647 kWindowControlsTopOffset, 647 kWindowControlsTopOffset,
648 preferred_size.cx, 648 preferred_size.width(),
649 preferred_size.cy); 649 preferred_size.height());
650 } 650 }
651 651
652 int right_limit = min_button_->x(); 652 int right_limit = min_button_->x();
653 int left_margin; 653 int left_margin;
654 int right_margin; 654 int right_margin;
655 int bottom_margin; 655 int bottom_margin;
656 int top_margin; 656 int top_margin;
657 657
658 SkBitmap** bitmaps = GetFrameBitmaps(); 658 SkBitmap** bitmaps = GetFrameBitmaps();
659 if (IsZoomed()) { 659 if (IsZoomed()) {
660 right_limit -= kZoomedStripPadding; 660 right_limit -= kZoomedStripPadding;
661 top_margin = kZoomedTopMargin; 661 top_margin = kZoomedTopMargin;
662 bottom_margin = kZoomedBottomMargin; 662 bottom_margin = kZoomedBottomMargin;
663 left_margin = 0; 663 left_margin = 0;
664 right_margin = 0; 664 right_margin = 0;
665 } else { 665 } else {
666 top_margin = kTopMargin; 666 top_margin = kTopMargin;
667 bottom_margin = g_bottom_margin; 667 bottom_margin = g_bottom_margin;
668 left_margin = g_left_margin; 668 left_margin = g_left_margin;
669 right_margin = g_right_margin; 669 right_margin = g_right_margin;
670 } 670 }
671 671
672 int last_y = top_margin - 1; 672 int last_y = top_margin - 1;
673 if (IsTabStripVisible()) { 673 if (IsTabStripVisible()) {
674 int tab_strip_x = left_margin; 674 int tab_strip_x = left_margin;
675 675
676 if (is_off_the_record_) { 676 if (is_off_the_record_) {
677 CSize otr_image_size; 677 gfx::Size otr_image_size = off_the_record_image_->GetPreferredSize();
678 off_the_record_image_->GetPreferredSize(&otr_image_size); 678 tab_strip_x += otr_image_size.width() + (2 * kOTRImageHorizMargin);
679 tab_strip_x += otr_image_size.cx + (2 * kOTRImageHorizMargin);
680 if (IsZoomed()) { 679 if (IsZoomed()) {
681 off_the_record_image_->SetBounds(left_margin + kOTRImageHorizMargin, 680 off_the_record_image_->SetBounds(left_margin + kOTRImageHorizMargin,
682 top_margin + 1, 681 top_margin + 1,
683 otr_image_size.cx, 682 otr_image_size.width(),
684 tabstrip_->GetPreferredHeight() - 683 tabstrip_->GetPreferredHeight() -
685 kToolbarOverlapVertOffset - 1); 684 kToolbarOverlapVertOffset - 1);
686 } else { 685 } else {
687 off_the_record_image_->SetBounds(left_margin + kOTRImageHorizMargin, 686 off_the_record_image_->SetBounds(left_margin + kOTRImageHorizMargin,
688 top_margin - 1 + 687 top_margin - 1 +
689 tabstrip_->GetPreferredHeight() - 688 tabstrip_->GetPreferredHeight() -
690 otr_image_size.cy - 689 otr_image_size.height() -
691 kOTRImageVertMargin, 690 kOTRImageVertMargin,
692 otr_image_size.cx, 691 otr_image_size.width(),
693 otr_image_size.cy); 692 otr_image_size.height());
694 } 693 }
695 } 694 }
696 695
697 if (distributor_logo_) { 696 if (distributor_logo_) {
698 if (IsZoomed()) { 697 if (IsZoomed()) {
699 distributor_logo_->SetVisible(false); 698 distributor_logo_->SetVisible(false);
700 } else { 699 } else {
701 CSize distributor_logo_size; 700 gfx::Size distributor_logo_size =
702 distributor_logo_->GetPreferredSize(&distributor_logo_size); 701 distributor_logo_->GetPreferredSize();
703 distributor_logo_->SetVisible(true); 702 distributor_logo_->SetVisible(true);
704 distributor_logo_->SetBounds(min_button_->x() - 703 distributor_logo_->SetBounds(min_button_->x() -
705 distributor_logo_size.cx - 704 distributor_logo_size.width() -
706 kDistributorLogoHorizontalOffset, 705 kDistributorLogoHorizontalOffset,
707 kDistributorLogoVerticalOffset, 706 kDistributorLogoVerticalOffset,
708 distributor_logo_size.cx, 707 distributor_logo_size.width(),
709 distributor_logo_size.cy); 708 distributor_logo_size.height());
710 } 709 }
711 } 710 }
712 711
713 tabstrip_->SetBounds(tab_strip_x, top_margin - 1, 712 tabstrip_->SetBounds(tab_strip_x, top_margin - 1,
714 right_limit - tab_strip_x - right_margin, 713 right_limit - tab_strip_x - right_margin,
715 tabstrip_->GetPreferredHeight()); 714 tabstrip_->GetPreferredHeight());
716 715
717 last_y = tabstrip_->y() + tabstrip_->height(); 716 last_y = tabstrip_->y() + tabstrip_->height();
718 } else { 717 } else {
719 tabstrip_->SetBounds(0, 0, 0, 0); 718 tabstrip_->SetBounds(0, 0, 0, 0);
(...skipping 26 matching lines...) Expand all
746 } else { 745 } else {
747 last_y = std::max(kMinTitleBarHeight, 746 last_y = std::max(kMinTitleBarHeight,
748 close_button_->y() + close_button_->height()); 747 close_button_->y() + close_button_->height());
749 title_bar_height_ = last_y; 748 title_bar_height_ = last_y;
750 } 749 }
751 browser_view_->SetVisible(false); 750 browser_view_->SetVisible(false);
752 } 751 }
753 752
754 int browser_h = height - last_y - bottom_margin; 753 int browser_h = height - last_y - bottom_margin;
755 if (shelf_view_) { 754 if (shelf_view_) {
756 shelf_view_->GetPreferredSize(&preferred_size); 755 preferred_size = shelf_view_->GetPreferredSize();
757 shelf_view_->SetBounds(left_margin, 756 shelf_view_->SetBounds(left_margin,
758 height - bottom_margin - preferred_size.cy, 757 height - bottom_margin - preferred_size.height(),
759 width - left_margin - right_margin, 758 width - left_margin - right_margin,
760 preferred_size.cy); 759 preferred_size.height());
761 browser_h -= preferred_size.cy; 760 browser_h -= preferred_size.height();
762 } 761 }
763 762
764 int bookmark_bar_height = 0; 763 int bookmark_bar_height = 0;
765 764
766 CSize bookmark_bar_size; 765 gfx::Size bookmark_bar_size;
767 CSize info_bar_size; 766 gfx::Size info_bar_size;
768 767
769 if (bookmark_bar_view_.get()) { 768 if (bookmark_bar_view_.get()) {
770 bookmark_bar_view_->GetPreferredSize(&bookmark_bar_size); 769 bookmark_bar_size = bookmark_bar_view_->GetPreferredSize();
771 bookmark_bar_height = bookmark_bar_size.cy; 770 bookmark_bar_height = bookmark_bar_size.height();
772 } 771 }
773 772
774 if (info_bar_view_) 773 if (info_bar_view_)
775 info_bar_view_->GetPreferredSize(&info_bar_size); 774 info_bar_size = info_bar_view_->GetPreferredSize();
776 775
777 // If we're showing a bookmarks bar in the new tab page style and we 776 // If we're showing a bookmarks bar in the new tab page style and we
778 // have an infobar showing, we need to flip them. 777 // have an infobar showing, we need to flip them.
779 if (info_bar_view_ && 778 if (info_bar_view_ &&
780 bookmark_bar_view_.get() && 779 bookmark_bar_view_.get() &&
781 bookmark_bar_view_->IsNewTabPage() && 780 bookmark_bar_view_->IsNewTabPage() &&
782 !bookmark_bar_view_->IsAlwaysShown()) { 781 !bookmark_bar_view_->IsAlwaysShown()) {
783 info_bar_view_->SetBounds(left_margin, 782 info_bar_view_->SetBounds(left_margin,
784 last_y, 783 last_y,
785 client_rect.Width() - left_margin - right_margin, 784 client_rect.Width() - left_margin - right_margin,
786 info_bar_size.cy); 785 info_bar_size.height());
787 browser_h -= info_bar_size.cy; 786 browser_h -= info_bar_size.height();
788 last_y += info_bar_size.cy; 787 last_y += info_bar_size.height();
789 788
790 last_y -= kSeparationLineHeight; 789 last_y -= kSeparationLineHeight;
791 790
792 bookmark_bar_view_->SetBounds(left_margin, 791 bookmark_bar_view_->SetBounds(left_margin,
793 last_y, 792 last_y,
794 client_rect.Width() - left_margin - 793 client_rect.Width() - left_margin -
795 right_margin, 794 right_margin,
796 bookmark_bar_size.cy); 795 bookmark_bar_size.height());
797 browser_h -= (bookmark_bar_size.cy - kSeparationLineHeight); 796 browser_h -= (bookmark_bar_size.height() - kSeparationLineHeight);
798 last_y += bookmark_bar_size.cy; 797 last_y += bookmark_bar_size.height();
799 } else { 798 } else {
800 if (bookmark_bar_view_.get()) { 799 if (bookmark_bar_view_.get()) {
801 // We want our bookmarks bar to be responsible for drawing its own 800 // We want our bookmarks bar to be responsible for drawing its own
802 // separator, so we let it overlap ours. 801 // separator, so we let it overlap ours.
803 last_y -= kSeparationLineHeight; 802 last_y -= kSeparationLineHeight;
804 803
805 bookmark_bar_view_->SetBounds(left_margin, 804 bookmark_bar_view_->SetBounds(left_margin,
806 last_y, 805 last_y,
807 client_rect.Width() - left_margin - 806 client_rect.Width() - left_margin -
808 right_margin, 807 right_margin,
809 bookmark_bar_size.cy); 808 bookmark_bar_size.height());
810 browser_h -= (bookmark_bar_size.cy - kSeparationLineHeight); 809 browser_h -= (bookmark_bar_size.height() - kSeparationLineHeight);
811 last_y += bookmark_bar_size.cy; 810 last_y += bookmark_bar_size.height();
812 } 811 }
813 812
814 if (info_bar_view_) { 813 if (info_bar_view_) {
815 info_bar_view_->SetBounds(left_margin, 814 info_bar_view_->SetBounds(left_margin,
816 last_y, 815 last_y,
817 client_rect.Width() - 816 client_rect.Width() -
818 left_margin - right_margin, 817 left_margin - right_margin,
819 info_bar_size.cy); 818 info_bar_size.height());
820 browser_h -= info_bar_size.cy; 819 browser_h -= info_bar_size.height();
821 last_y += info_bar_size.cy; 820 last_y += info_bar_size.height();
822 } 821 }
823 } 822 }
824 823
825 tab_contents_container_->SetBounds(left_margin, 824 tab_contents_container_->SetBounds(left_margin,
826 last_y, 825 last_y,
827 width - left_margin - right_margin, 826 width - left_margin - right_margin,
828 browser_h); 827 browser_h);
829 #ifdef CHROME_PERSONALIZATION 828 #ifdef CHROME_PERSONALIZATION
830 if (PersonalizationEnabled()) { 829 if (PersonalizationEnabled()) {
831 Personalization::ConfigureFramePersonalization(personalization_, 830 Personalization::ConfigureFramePersonalization(personalization_,
(...skipping 1055 matching lines...) Expand 10 before | Expand all | Expand 10 after
1887 browser_view_->FocusToolbar(); 1886 browser_view_->FocusToolbar();
1888 } 1887 }
1889 1888
1890 bool XPFrame::IsBookmarkBarVisible() const { 1889 bool XPFrame::IsBookmarkBarVisible() const {
1891 if (!bookmark_bar_view_.get()) 1890 if (!bookmark_bar_view_.get())
1892 return false; 1891 return false;
1893 1892
1894 if (bookmark_bar_view_->IsNewTabPage() || bookmark_bar_view_->IsAnimating()) 1893 if (bookmark_bar_view_->IsNewTabPage() || bookmark_bar_view_->IsAnimating())
1895 return true; 1894 return true;
1896 1895
1897 CSize sz;
1898 bookmark_bar_view_->GetPreferredSize(&sz);
1899 // 1 is the minimum in GetPreferredSize for the bookmark bar. 1896 // 1 is the minimum in GetPreferredSize for the bookmark bar.
1900 return sz.cy > 1; 1897 return bookmark_bar_view_->GetPreferredSize().height() > 1;
1901 } 1898 }
1902 1899
1903 void XPFrame::MoveToFront(bool should_activate) { 1900 void XPFrame::MoveToFront(bool should_activate) {
1904 int flags = SWP_NOMOVE | SWP_NOSIZE; 1901 int flags = SWP_NOMOVE | SWP_NOSIZE;
1905 if (!should_activate) { 1902 if (!should_activate) {
1906 flags |= SWP_NOACTIVATE; 1903 flags |= SWP_NOACTIVATE;
1907 } 1904 }
1908 SetWindowPos(HWND_TOP, 0, 0, 0, 0, flags); 1905 SetWindowPos(HWND_TOP, 0, 0, 0, 0, flags);
1909 SetForegroundWindow(*this); 1906 SetForegroundWindow(*this);
1910 } 1907 }
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 tab_contents_container_->UpdateHWNDBounds(); 2294 tab_contents_container_->UpdateHWNDBounds();
2298 } 2295 }
2299 } 2296 }
2300 2297
2301 bool XPFrame::UpdateChildViewAndLayout(ChromeViews::View* new_view, 2298 bool XPFrame::UpdateChildViewAndLayout(ChromeViews::View* new_view,
2302 ChromeViews::View** view) { 2299 ChromeViews::View** view) {
2303 DCHECK(view); 2300 DCHECK(view);
2304 if (*view == new_view) { 2301 if (*view == new_view) {
2305 // The views haven't changed, if the views pref changed schedule a layout. 2302 // The views haven't changed, if the views pref changed schedule a layout.
2306 if (new_view) { 2303 if (new_view) {
2307 CSize pref_size; 2304 if (new_view->GetPreferredSize().height() != new_view->height())
2308 new_view->GetPreferredSize(&pref_size);
2309 if (pref_size.cy != new_view->height())
2310 return true; 2305 return true;
2311 } 2306 }
2312 return false; 2307 return false;
2313 } 2308 }
2314 2309
2315 // The views differ, and one may be null (but not both). Remove the old 2310 // The views differ, and one may be null (but not both). Remove the old
2316 // view (if it non-null), and add the new one (if it is non-null). If the 2311 // view (if it non-null), and add the new one (if it is non-null). If the
2317 // height has changed, schedule a layout, otherwise reuse the existing 2312 // height has changed, schedule a layout, otherwise reuse the existing
2318 // bounds to avoid scheduling a layout. 2313 // bounds to avoid scheduling a layout.
2319 2314
2320 int current_height = 0; 2315 int current_height = 0;
2321 if (*view) { 2316 if (*view) {
2322 current_height = (*view)->height(); 2317 current_height = (*view)->height();
2323 root_view_.RemoveChildView(*view); 2318 root_view_.RemoveChildView(*view);
2324 } 2319 }
2325 2320
2326 int new_height = 0; 2321 int new_height = 0;
2327 if (new_view) { 2322 if (new_view) {
2328 CSize preferred_size; 2323 new_height = new_view->GetPreferredSize().height();
2329 new_view->GetPreferredSize(&preferred_size);
2330 new_height = preferred_size.cy;
2331 root_view_.AddChildView(new_view); 2324 root_view_.AddChildView(new_view);
2332 } 2325 }
2333 bool changed = false; 2326 bool changed = false;
2334 if (new_height != current_height) { 2327 if (new_height != current_height) {
2335 changed = true; 2328 changed = true;
2336 } else if (new_view && *view) { 2329 } else if (new_view && *view) {
2337 // The view changed, but the new view wants the same size, give it the 2330 // The view changed, but the new view wants the same size, give it the
2338 // bounds of the last view and have it repaint. 2331 // bounds of the last view and have it repaint.
2339 new_view->SetBounds((*view)->bounds().ToRECT()); 2332 new_view->SetBounds((*view)->bounds().ToRECT());
2340 new_view->SchedulePaint(); 2333 new_view->SchedulePaint();
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
2504 2497
2505 // Only do a layout if the current contents is non-null. We assume that if the 2498 // Only do a layout if the current contents is non-null. We assume that if the
2506 // contents is NULL, we're either being destroyed, or ShowTabContents is going 2499 // contents is NULL, we're either being destroyed, or ShowTabContents is going
2507 // to be invoked with a non-null TabContents again so that there is no need 2500 // to be invoked with a non-null TabContents again so that there is no need
2508 // in doing a layout now (and would result in extra work/invalidation on 2501 // in doing a layout now (and would result in extra work/invalidation on
2509 // tab switches). 2502 // tab switches).
2510 if (changed && current_tab) 2503 if (changed && current_tab)
2511 Layout(); 2504 Layout();
2512 } 2505 }
2513 2506
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698