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

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

Issue 18396: Correct icon/title sizing/placement for varying titlebar font sizes. This ma... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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_non_client_view.h" 5 #include "chrome/browser/views/frame/opaque_non_client_view.h"
6 6
7 #include "chrome/app/theme/theme_resources.h" 7 #include "chrome/app/theme/theme_resources.h"
8 #include "chrome/browser/tab_contents/tab_contents.h" 8 #include "chrome/browser/tab_contents/tab_contents.h"
9 #include "chrome/browser/views/frame/browser_view.h" 9 #include "chrome/browser/views/frame/browser_view.h"
10 #include "chrome/browser/views/tabs/tab_strip.h" 10 #include "chrome/browser/views/tabs/tab_strip.h"
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after
293 static const int kWindowControlsRightOffset = 4; 293 static const int kWindowControlsRightOffset = 4;
294 // The distance between the bottom of the window's top border and the top of the 294 // The distance between the bottom of the window's top border and the top of the
295 // window controls' images when the window is maximized. We extend the 295 // window controls' images when the window is maximized. We extend the
296 // clickable area all the way to the top of the window to obey Fitts' Law. 296 // clickable area all the way to the top of the window to obey Fitts' Law.
297 static const int kWindowControlsZoomedTopExtraHeight = 1; 297 static const int kWindowControlsZoomedTopExtraHeight = 1;
298 // The distance between right edge of the right-most window control and the left 298 // The distance between right edge of the right-most window control and the left
299 // edge of the window's right border when the window is maximized. 299 // edge of the window's right border when the window is maximized.
300 static const int kWindowControlsZoomedRightOffset = 3; 300 static const int kWindowControlsZoomedRightOffset = 3;
301 // The distance between the left edge of the window and the left edge of the 301 // The distance between the left edge of the window and the left edge of the
302 // window icon when a title-bar is showing and the window is restored. 302 // window icon when a title-bar is showing and the window is restored.
303 static const int kWindowIconLeftOffset = 5; 303 static const int kWindowIconLeftOffset = 6;
304 // The distance between the right edge of the window's left border and the left 304 // The distance between the right edge of the window's left border and the left
305 // edge of the window icon when a title-bar is showing and the window is 305 // edge of the window icon when a title-bar is showing and the window is
306 // maximized. 306 // maximized.
307 static const int kWindowIconZoomedLeftOffset = 2; 307 static const int kWindowIconZoomedLeftOffset = 2;
308 // The proportion of vertical space the icon takes up after subtracting the top
309 // and bottom borders of the titlebar (expressed as two values to avoid
310 // floating point representation errors that goof up the calculation).
311 static const int kWindowIconFractionNumerator = 16;
312 static const int kWindowIconFractionDenominator = 25;
308 // The distance between the top edge of the window and the top edge of the 313 // The distance between the top edge of the window and the top edge of the
309 // window icon and title when a title-bar is showing and the window is restored. 314 // window title when a title-bar is showing and the window is restored.
310 static const int kWindowIconAndTitleTopOffset = 6; 315 static const int kWindowTitleTopOffset = 6;
311 // The distance between the bottom edge of the window's top border and the top 316 // The distance between the bottom edge of the window's top border and the top
312 // edge of the window icon and title when a title-bar is showing and the window 317 // edge of the window title when a title-bar is showing and the window is
313 // is maximized. 318 // maximized.
314 static const int kWindowIconAndTitleZoomedTopOffset = 4; 319 static const int kWindowTitleZoomedTopOffset = 4;
315 // The distance between the window icon and the window title when a title-bar 320 // The distance between the window icon and the window title when a title-bar
316 // is showing. 321 // is showing.
317 static const int kWindowIconTitleSpacing = 4; 322 static const int kWindowIconTitleSpacing = 4;
318 // The distance between the right edge of the title text bounding box and the 323 // The distance between the right edge of the title text bounding box and the
319 // left edge of the distributor logo. 324 // left edge of the distributor logo.
320 static const int kTitleLogoSpacing = 5; 325 static const int kTitleLogoSpacing = 5;
321 // The distance between the bottom of the title text and the TabStrip when a 326 // The distance between the bottom of the title text and the TabStrip when a
322 // title-bar is showing. 327 // title-bar is showing and the window is restored.
323 static const int kTitleBottomSpacing = 6; 328 static const int kTitleBottomSpacing = 7;
329 // The distance between the bottom of the title text and the TabStrip when a
330 // title-bar is showing and the window is maximized.
331 static const int kTitleZoomedBottomSpacing = 5;
324 // The distance between the top edge of the window and the TabStrip when there 332 // The distance between the top edge of the window and the TabStrip when there
325 // is no title-bar showing, and the window is restored. 333 // is no title-bar showing, and the window is restored.
326 static const int kNoTitleTopSpacing = 15; 334 static const int kNoTitleTopSpacing = 15;
327 // The number of pixels to crop off the bottom of the images making up the top 335 // The number of pixels to crop off the bottom of the images making up the top
328 // client edge when the window is maximized, so we only draw a shadowed titlebar 336 // client edge when the window is maximized, so we only draw a shadowed titlebar
329 // and not a grey client area border below it. 337 // and not a grey client area border below it.
330 static const int kClientEdgeZoomedBottomCrop = 1; 338 static const int kClientEdgeZoomedBottomCrop = 1;
331 // The amount of horizontal and vertical distance from a corner of the window 339 // The amount of horizontal and vertical distance from a corner of the window
332 // within which a mouse-drive resize operation will resize the window in two 340 // within which a mouse-drive resize operation will resize the window in two
333 // dimensions. 341 // dimensions.
334 static const int kResizeAreaCornerSize = 16; 342 static const int kResizeAreaCornerSize = 16;
335 // The width of the sizing border on the left and right edge of the window. 343 // The width of the sizing border on the left and right edge of the window.
336 static const int kWindowHorizontalBorderSize = 5; 344 static const int kWindowHorizontalBorderSize = 5;
337 // The height of the sizing border at the top edge of the window 345 // The height of the sizing border at the top edge of the window
338 static const int kWindowVerticalBorderTopSize = 3; 346 static const int kWindowVerticalBorderTopSize = 3;
339 // The height of the sizing border on the bottom edge of the window when the 347 // The height of the sizing border on the bottom edge of the window when the
340 // window is restored. 348 // window is restored.
341 static const int kWindowVerticalBorderBottomSize = 5; 349 static const int kWindowVerticalBorderBottomSize = 5;
342 // The additional height beyond the system-provided thickness of the border on 350 // The additional height beyond the system-provided thickness of the border on
343 // the bottom edge of the window when the window is maximized. 351 // the bottom edge of the window when the window is maximized.
344 static const int kWindowVerticalBorderZoomedBottomSize = 1; 352 static const int kWindowVerticalBorderZoomedBottomSize = 1;
345 // The width and height of the window icon that appears at the top left of 353 // The minimum width and height of the window icon that appears at the top left
346 // pop-up and app windows. 354 // of pop-up and app windows.
347 static const int kWindowIconSize = 16; 355 static const int kWindowIconMinimumSize = 16;
356 // The minimum height reserved for the window title font.
357 static const int kWindowTitleMinimumHeight = 11;
348 // The horizontal distance of the right edge of the distributor logo from the 358 // The horizontal distance of the right edge of the distributor logo from the
349 // left edge of the left-most window control. 359 // left edge of the left-most window control.
350 static const int kDistributorLogoHorizontalOffset = 7; 360 static const int kDistributorLogoHorizontalOffset = 7;
351 // The vertical distance of the top of the distributor logo from the top edge 361 // The vertical distance of the top of the distributor logo from the top edge
352 // of the window. 362 // of the window.
353 static const int kDistributorLogoVerticalOffset = 3; 363 static const int kDistributorLogoVerticalOffset = 3;
354 // The distance between the left edge of the window and the OTR avatar icon when 364 // The distance between the left edge of the window and the OTR avatar icon when
355 // the window is restored. 365 // the window is restored.
356 static const int kOTRLeftOffset = 7; 366 static const int kOTRLeftOffset = 7;
357 // The distance between the right edge of the window's left border and the OTR 367 // The distance between the right edge of the window's left border and the OTR
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
704 } 714 }
705 715
706 void OpaqueNonClientView::SetAccessibleName(const std::wstring& name) { 716 void OpaqueNonClientView::SetAccessibleName(const std::wstring& name) {
707 accessible_name_ = name; 717 accessible_name_ = name;
708 } 718 }
709 719
710 /////////////////////////////////////////////////////////////////////////////// 720 ///////////////////////////////////////////////////////////////////////////////
711 // OpaqueNonClientView, private: 721 // OpaqueNonClientView, private:
712 722
713 int OpaqueNonClientView::CalculateNonClientTopHeight() const { 723 int OpaqueNonClientView::CalculateNonClientTopHeight() const {
714 if (frame_->window_delegate()->ShouldShowWindowTitle()) { 724 bool show_title = frame_->window_delegate()->ShouldShowWindowTitle();
715 int top_offset = frame_->IsMaximized() ? (GetSystemMetrics(SM_CYSIZEFRAME) + 725 int title_height = std::max(title_font_.height(), kWindowTitleMinimumHeight);
716 kWindowIconAndTitleZoomedTopOffset) : kWindowIconAndTitleTopOffset; 726 if (frame_->IsMaximized()) {
717 return top_offset + title_font_.height() + kTitleBottomSpacing; 727 int top_height = GetSystemMetrics(SM_CYSIZEFRAME);
728 if (show_title) {
729 top_height += kWindowTitleZoomedTopOffset + title_height +
730 kTitleZoomedBottomSpacing;
731 }
732 if (!browser_view_->IsToolbarVisible())
733 top_height -= kClientEdgeZoomedBottomCrop;
734 return top_height;
718 } 735 }
719 return frame_->IsMaximized() ? 736 return show_title ?
720 GetSystemMetrics(SM_CYSIZEFRAME) : kNoTitleTopSpacing; 737 (kWindowTitleTopOffset + title_height + kTitleBottomSpacing) :
738 kNoTitleTopSpacing;
721 } 739 }
722 740
723 int OpaqueNonClientView::HorizontalBorderSize() const { 741 int OpaqueNonClientView::HorizontalBorderSize() const {
724 return frame_->IsMaximized() ? 742 return frame_->IsMaximized() ?
725 GetSystemMetrics(SM_CXSIZEFRAME) : kWindowHorizontalBorderSize; 743 GetSystemMetrics(SM_CXSIZEFRAME) : kWindowHorizontalBorderSize;
726 } 744 }
727 745
728 int OpaqueNonClientView::VerticalBorderBottomSize() const { 746 int OpaqueNonClientView::VerticalBorderBottomSize() const {
729 return frame_->IsMaximized() ? (GetSystemMetrics(SM_CYSIZEFRAME) + 747 return frame_->IsMaximized() ? (GetSystemMetrics(SM_CYSIZEFRAME) +
730 kWindowVerticalBorderZoomedBottomSize) : kWindowVerticalBorderBottomSize; 748 kWindowVerticalBorderZoomedBottomSize) : kWindowVerticalBorderBottomSize;
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
797 } 815 }
798 } 816 }
799 817
800 void OpaqueNonClientView::PaintTitleBar(ChromeCanvas* canvas) { 818 void OpaqueNonClientView::PaintTitleBar(ChromeCanvas* canvas) {
801 // The window icon is painted by the TabIconView. 819 // The window icon is painted by the TabIconView.
802 views::WindowDelegate* d = frame_->window_delegate(); 820 views::WindowDelegate* d = frame_->window_delegate();
803 if (d->ShouldShowWindowTitle()) { 821 if (d->ShouldShowWindowTitle()) {
804 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, 822 canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE,
805 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), 823 MirroredLeftPointForRect(title_bounds_), title_bounds_.y(),
806 title_bounds_.width(), title_bounds_.height()); 824 title_bounds_.width(), title_bounds_.height());
825 /* TODO(pkasting):
826 if (app window && active)
827 Draw Drop Shadow;
828 */
807 } 829 }
808 } 830 }
809 831
810 void OpaqueNonClientView::PaintToolbarBackground(ChromeCanvas* canvas) { 832 void OpaqueNonClientView::PaintToolbarBackground(ChromeCanvas* canvas) {
811 if (!browser_view_->IsToolbarVisible() && !browser_view_->IsTabStripVisible()) 833 if (!browser_view_->IsToolbarVisible() && !browser_view_->IsTabStripVisible())
812 return; 834 return;
813 835
814 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds()); 836 gfx::Rect toolbar_bounds(browser_view_->GetToolbarBounds());
815 gfx::Point toolbar_origin(toolbar_bounds.origin()); 837 gfx::Point toolbar_origin(toolbar_bounds.origin());
816 View::ConvertPointToView(frame_->client_view(), this, &toolbar_origin); 838 View::ConvertPointToView(frame_->client_view(), this, &toolbar_origin);
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after
975 kDistributorLogoHorizontalOffset, kDistributorLogoVerticalOffset, 997 kDistributorLogoHorizontalOffset, kDistributorLogoVerticalOffset,
976 distributor_logo_.width(), distributor_logo_.height()); 998 distributor_logo_.width(), distributor_logo_.height());
977 } 999 }
978 1000
979 void OpaqueNonClientView::LayoutTitleBar() { 1001 void OpaqueNonClientView::LayoutTitleBar() {
980 // Size the window icon, even if it is hidden so we can size the title based 1002 // Size the window icon, even if it is hidden so we can size the title based
981 // on its position. 1003 // on its position.
982 int left_offset = frame_->IsMaximized() ? 1004 int left_offset = frame_->IsMaximized() ?
983 (GetSystemMetrics(SM_CXSIZEFRAME) + kWindowIconZoomedLeftOffset) : 1005 (GetSystemMetrics(SM_CXSIZEFRAME) + kWindowIconZoomedLeftOffset) :
984 kWindowIconLeftOffset; 1006 kWindowIconLeftOffset;
985 int top_offset = frame_->IsMaximized() ? 1007
986 (GetSystemMetrics(SM_CYSIZEFRAME) + kWindowIconAndTitleZoomedTopOffset) : 1008 // The usable height of the titlebar area is the total height minus the top
987 kWindowIconAndTitleTopOffset; 1009 // resize border, the one shadow pixel at the bottom, and any client edge area
1010 // we draw below that shadow pixel (only in restored mode).
1011 // TODO(pkasting): Clean up this "4" hack.
1012 int top_border_height =
1013 frame_->IsMaximized() ? GetSystemMetrics(SM_CYSIZEFRAME) : 4;
1014 int available_height = CalculateNonClientTopHeight() - top_border_height - 1;
1015 if (!frame_->IsMaximized())
1016 available_height -= kClientEdgeZoomedBottomCrop;
1017
1018 // The icon takes up a constant fraction of the available height, down to a
1019 // minimum size, and is always an even number of pixels on a side (presumably
1020 // to make scaled icons look better). It's centered within the usable height.
1021 int icon_size = std::max((available_height * kWindowIconFractionNumerator /
1022 kWindowIconFractionDenominator) / 2 * 2, kWindowIconMinimumSize);
1023 int icon_top_offset =
1024 ((available_height - icon_size) / 2) + top_border_height;
1025
1026 // Hack: Our frame border has a different "3D look" than Windows'. Theirs has
1027 // a more complex gradient on the top that they push their icon/title below;
1028 // then the maximized window cuts this off and the icon/title are centered in
1029 // the remaining space. Because the apparent shape of our border is simpler,
1030 // using the same positioning makes things look slightly uncentered with
1031 // restored windows, so we come up one pixel to compensate.
1032 if (!frame_->IsMaximized())
1033 --icon_top_offset;
1034
988 views::WindowDelegate* d = frame_->window_delegate(); 1035 views::WindowDelegate* d = frame_->window_delegate();
989 int icon_size = d->ShouldShowWindowIcon() ? kWindowIconSize : 0; 1036 if (!d->ShouldShowWindowIcon())
990 icon_bounds_.SetRect(left_offset, top_offset, icon_size, icon_size); 1037 icon_size = 0;
1038 icon_bounds_.SetRect(left_offset, icon_top_offset, icon_size, icon_size);
991 if (window_icon_) 1039 if (window_icon_)
992 window_icon_->SetBounds(icon_bounds_); 1040 window_icon_->SetBounds(icon_bounds_);
993 1041
994 // Size the title, if visible. 1042 // Size the title, if visible.
995 if (d->ShouldShowWindowTitle()) { 1043 if (d->ShouldShowWindowTitle()) {
996 int title_right = logo_bounds_.x() - kTitleLogoSpacing; 1044 int title_right = logo_bounds_.x() - kTitleLogoSpacing;
997 int icon_right = icon_bounds_.right(); 1045 int icon_right = icon_bounds_.right();
998 int title_left = 1046 int title_left =
999 icon_right + (d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0); 1047 icon_right + (d->ShouldShowWindowIcon() ? kWindowIconTitleSpacing : 0);
1000 title_bounds_.SetRect(title_left, top_offset, 1048 int title_top_offset = frame_->IsMaximized() ?
1049 (GetSystemMetrics(SM_CYSIZEFRAME) + kWindowTitleZoomedTopOffset) :
1050 kWindowTitleTopOffset;
1051 if (title_font_.height() < kWindowTitleMinimumHeight) {
1052 title_top_offset +=
1053 (kWindowTitleMinimumHeight - title_font_.height()) / 2;
1054 }
1055 title_bounds_.SetRect(title_left, title_top_offset,
1001 std::max(0, title_right - icon_right), title_font_.height()); 1056 std::max(0, title_right - icon_right), title_font_.height());
1002 } 1057 }
1003 } 1058 }
1004 1059
1005 void OpaqueNonClientView::LayoutOTRAvatar() { 1060 void OpaqueNonClientView::LayoutOTRAvatar() {
1006 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon(); 1061 SkBitmap otr_avatar_icon = browser_view_->GetOTRAvatarIcon();
1007 int non_client_height = CalculateNonClientTopHeight(); 1062 int non_client_height = CalculateNonClientTopHeight();
1008 int otr_bottom = non_client_height + browser_view_->GetTabStripHeight() - 1063 int otr_bottom = non_client_height + browser_view_->GetTabStripHeight() -
1009 kOTRBottomSpacing; 1064 kOTRBottomSpacing;
1010 int otr_x, otr_y, otr_height; 1065 int otr_x, otr_y, otr_height;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 } 1101 }
1047 1102
1048 // static 1103 // static
1049 void OpaqueNonClientView::InitAppWindowResources() { 1104 void OpaqueNonClientView::InitAppWindowResources() {
1050 static bool initialized = false; 1105 static bool initialized = false;
1051 if (!initialized) { 1106 if (!initialized) {
1052 title_font_ = win_util::GetWindowTitleFont(); 1107 title_font_ = win_util::GetWindowTitleFont();
1053 initialized = true; 1108 initialized = true;
1054 } 1109 }
1055 } 1110 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698