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

Side by Side Diff: Source/core/layout/LayoutThemeChromiumMac.mm

Issue 889563002: Make RenderObject::style() return a const object (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix a crashers (everything is building!) Created 5 years, 10 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 /* 1 /*
2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2008, 2009 Google, Inc. 3 * Copyright (C) 2008, 2009 Google, Inc.
4 * 4 *
5 * This library is free software; you can redistribute it and/or 5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public 6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either 7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version. 8 * version 2 of the License, or (at your option) any later version.
9 * 9 *
10 * This library is distributed in the hope that it will be useful, 10 * This library is distributed in the hope that it will be useful,
(...skipping 567 matching lines...) Expand 10 before | Expand all | Expand 10 after
578 } 578 }
579 579
580 void LayoutThemeChromiumMac::updatePressedState(NSCell* cell, const RenderObject * o) 580 void LayoutThemeChromiumMac::updatePressedState(NSCell* cell, const RenderObject * o)
581 { 581 {
582 bool oldPressed = [cell isHighlighted]; 582 bool oldPressed = [cell isHighlighted];
583 bool pressed = o->node() && o->node()->active(); 583 bool pressed = o->node() && o->node()->active();
584 if (pressed != oldPressed) 584 if (pressed != oldPressed)
585 [cell setHighlighted:pressed]; 585 [cell setHighlighted:pressed];
586 } 586 }
587 587
588 NSControlSize LayoutThemeChromiumMac::controlSizeForFont(RenderStyle* style) con st 588 NSControlSize LayoutThemeChromiumMac::controlSizeForFont(const RenderStyle* styl e) const
589 { 589 {
590 int fontSize = style->fontSize(); 590 int fontSize = style->fontSize();
591 if (fontSize >= 16) 591 if (fontSize >= 16)
592 return NSRegularControlSize; 592 return NSRegularControlSize;
593 if (fontSize >= 11) 593 if (fontSize >= 11)
594 return NSSmallControlSize; 594 return NSSmallControlSize;
595 return NSMiniControlSize; 595 return NSMiniControlSize;
596 } 596 }
597 597
598 // We don't use controlSizeForFont() for search field decorations because it 598 // We don't use controlSizeForFont() for search field decorations because it
599 // needs to fit into the search field. The font size will already be modified by 599 // needs to fit into the search field. The font size will already be modified by
600 // setFontFromControlSize() called on the search field. 600 // setFontFromControlSize() called on the search field.
601 static NSControlSize searchFieldControlSizeForFont(RenderStyle* style) 601 static NSControlSize searchFieldControlSizeForFont(const RenderStyle* style)
602 { 602 {
603 int fontSize = style->fontSize(); 603 int fontSize = style->fontSize();
604 if (fontSize >= 13) 604 if (fontSize >= 13)
605 return NSRegularControlSize; 605 return NSRegularControlSize;
606 if (fontSize >= 11) 606 if (fontSize >= 11)
607 return NSSmallControlSize; 607 return NSSmallControlSize;
608 return NSMiniControlSize; 608 return NSMiniControlSize;
609 } 609 }
610 610
611 void LayoutThemeChromiumMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel) 611 void LayoutThemeChromiumMac::setControlSize(NSCell* cell, const IntSize* sizes, const IntSize& minSize, float zoomLevel)
612 { 612 {
613 NSControlSize size; 613 NSControlSize size;
614 if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) && 614 if (minSize.width() >= static_cast<int>(sizes[NSRegularControlSize].width() * zoomLevel) &&
615 minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height( ) * zoomLevel)) 615 minSize.height() >= static_cast<int>(sizes[NSRegularControlSize].height( ) * zoomLevel))
616 size = NSRegularControlSize; 616 size = NSRegularControlSize;
617 else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width () * zoomLevel) && 617 else if (minSize.width() >= static_cast<int>(sizes[NSSmallControlSize].width () * zoomLevel) &&
618 minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].heig ht() * zoomLevel)) 618 minSize.height() >= static_cast<int>(sizes[NSSmallControlSize].heig ht() * zoomLevel))
619 size = NSSmallControlSize; 619 size = NSSmallControlSize;
620 else 620 else
621 size = NSMiniControlSize; 621 size = NSMiniControlSize;
622 // Only update if we have to, since AppKit does work even if the size is the 622 // Only update if we have to, since AppKit does work even if the size is the
623 // same. 623 // same.
624 if (size != [cell controlSize]) 624 if (size != [cell controlSize])
625 [cell setControlSize:size]; 625 [cell setControlSize:size];
626 } 626 }
627 627
628 IntSize LayoutThemeChromiumMac::sizeForFont(RenderStyle* style, const IntSize* s izes) const 628 IntSize LayoutThemeChromiumMac::sizeForFont(const RenderStyle* style, const IntS ize* sizes) const
629 { 629 {
630 if (style->effectiveZoom() != 1.0f) { 630 if (style->effectiveZoom() != 1.0f) {
631 IntSize result = sizes[controlSizeForFont(style)]; 631 IntSize result = sizes[controlSizeForFont(style)];
632 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom()); 632 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());
633 } 633 }
634 return sizes[controlSizeForFont(style)]; 634 return sizes[controlSizeForFont(style)];
635 } 635 }
636 636
637 IntSize LayoutThemeChromiumMac::sizeForSystemFont(RenderStyle* style, const IntS ize* sizes) const 637 IntSize LayoutThemeChromiumMac::sizeForSystemFont(const RenderStyle* style, cons t IntSize* sizes) const
638 { 638 {
639 if (style->effectiveZoom() != 1.0f) { 639 if (style->effectiveZoom() != 1.0f) {
640 IntSize result = sizes[controlSizeForSystemFont(style)]; 640 IntSize result = sizes[controlSizeForSystemFont(style)];
641 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom()); 641 return IntSize(result.width() * style->effectiveZoom(), result.height() * style->effectiveZoom());
642 } 642 }
643 return sizes[controlSizeForSystemFont(style)]; 643 return sizes[controlSizeForSystemFont(style)];
644 } 644 }
645 645
646 void LayoutThemeChromiumMac::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const 646 void LayoutThemeChromiumMac::setSizeFromFont(RenderStyle* style, const IntSize* sizes) const
647 { 647 {
(...skipping 17 matching lines...) Expand all
665 fontDescription.setComputedSize([font pointSize] * style->effectiveZoom()); 665 fontDescription.setComputedSize([font pointSize] * style->effectiveZoom());
666 fontDescription.setSpecifiedSize([font pointSize] * style->effectiveZoom()); 666 fontDescription.setSpecifiedSize([font pointSize] * style->effectiveZoom());
667 667
668 // Reset line height. 668 // Reset line height.
669 style->setLineHeight(RenderStyle::initialLineHeight()); 669 style->setLineHeight(RenderStyle::initialLineHeight());
670 670
671 if (style->setFontDescription(fontDescription)) 671 if (style->setFontDescription(fontDescription))
672 style->font().update(nullptr); 672 style->font().update(nullptr);
673 } 673 }
674 674
675 NSControlSize LayoutThemeChromiumMac::controlSizeForSystemFont(RenderStyle* styl e) const 675 NSControlSize LayoutThemeChromiumMac::controlSizeForSystemFont(const RenderStyle * style) const
676 { 676 {
677 float fontSize = style->fontSize(); 677 float fontSize = style->fontSize();
678 float zoomLevel = style->effectiveZoom(); 678 float zoomLevel = style->effectiveZoom();
679 if (zoomLevel != 1) 679 if (zoomLevel != 1)
680 fontSize /= zoomLevel; 680 fontSize /= zoomLevel;
681 if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize]) 681 if (fontSize >= [NSFont systemFontSizeForControlSize:NSRegularControlSize])
682 return NSRegularControlSize; 682 return NSRegularControlSize;
683 if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize]) 683 if (fontSize >= [NSFont systemFontSizeForControlSize:NSSmallControlSize])
684 return NSSmallControlSize; 684 return NSSmallControlSize;
685 return NSMiniControlSize; 685 return NSMiniControlSize;
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 return NSRatingLevelIndicatorStyle; 907 return NSRatingLevelIndicatorStyle;
908 case MeterPart: 908 case MeterPart:
909 case ContinuousCapacityLevelIndicatorPart: 909 case ContinuousCapacityLevelIndicatorPart:
910 default: 910 default:
911 return NSContinuousCapacityLevelIndicatorStyle; 911 return NSContinuousCapacityLevelIndicatorStyle;
912 } 912 }
913 } 913 }
914 914
915 NSLevelIndicatorCell* LayoutThemeChromiumMac::levelIndicatorFor(const RenderMete r* renderMeter) const 915 NSLevelIndicatorCell* LayoutThemeChromiumMac::levelIndicatorFor(const RenderMete r* renderMeter) const
916 { 916 {
917 RenderStyle* style = renderMeter->style(); 917 const RenderStyle* style = renderMeter->style();
918 ASSERT(style->appearance() != NoControlPart); 918 ASSERT(style->appearance() != NoControlPart);
919 919
920 if (!m_levelIndicator) 920 if (!m_levelIndicator)
921 m_levelIndicator.adoptNS([[NSLevelIndicatorCell alloc] initWithLevelIndi catorStyle:NSContinuousCapacityLevelIndicatorStyle]); 921 m_levelIndicator.adoptNS([[NSLevelIndicatorCell alloc] initWithLevelIndi catorStyle:NSContinuousCapacityLevelIndicatorStyle]);
922 NSLevelIndicatorCell* cell = m_levelIndicator.get(); 922 NSLevelIndicatorCell* cell = m_levelIndicator.get();
923 923
924 HTMLMeterElement* element = renderMeter->meterElement(); 924 HTMLMeterElement* element = renderMeter->meterElement();
925 double value = element->value(); 925 double value = element->value();
926 926
927 // Because NSLevelIndicatorCell does not support optimum-in-the-middle type 927 // Because NSLevelIndicatorCell does not support optimum-in-the-middle type
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 { 965 {
966 static const int margins[3][4] = 966 static const int margins[3][4] =
967 { 967 {
968 { 0, 0, 1, 0 }, 968 { 0, 0, 1, 0 },
969 { 0, 0, 1, 0 }, 969 { 0, 0, 1, 0 },
970 { 0, 0, 1, 0 }, 970 { 0, 0, 1, 0 },
971 }; 971 };
972 return margins[controlSize]; 972 return margins[controlSize];
973 } 973 }
974 974
975 int LayoutThemeChromiumMac::minimumProgressBarHeight(RenderStyle* style) const 975 int LayoutThemeChromiumMac::minimumProgressBarHeight(const RenderStyle* style) c onst
976 { 976 {
977 return sizeForSystemFont(style, progressBarSizes()).height(); 977 return sizeForSystemFont(style, progressBarSizes()).height();
978 } 978 }
979 979
980 double LayoutThemeChromiumMac::animationRepeatIntervalForProgressBar(RenderProgr ess*) const 980 double LayoutThemeChromiumMac::animationRepeatIntervalForProgressBar(RenderProgr ess*) const
981 { 981 {
982 return progressAnimationFrameRate; 982 return progressAnimationFrameRate;
983 } 983 }
984 984
985 double LayoutThemeChromiumMac::animationDurationForProgressBar(RenderProgress*) const 985 double LayoutThemeChromiumMac::animationDurationForProgressBar(RenderProgress*) const
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after
1126 } 1126 }
1127 1127
1128 const int autofillPopupHorizontalPadding = 4; 1128 const int autofillPopupHorizontalPadding = 4;
1129 1129
1130 // These functions are called with MenuListPart or MenulistButtonPart appearance 1130 // These functions are called with MenuListPart or MenulistButtonPart appearance
1131 // by RenderMenuList, or with TextFieldPart appearance by 1131 // by RenderMenuList, or with TextFieldPart appearance by
1132 // AutofillPopupMenuClient. We assume only AutofillPopupMenuClient gives 1132 // AutofillPopupMenuClient. We assume only AutofillPopupMenuClient gives
1133 // TexfieldPart appearance here. We want to change only Autofill padding. In 1133 // TexfieldPart appearance here. We want to change only Autofill padding. In
1134 // the future, we have to separate Autofill popup window logic from WebKit to 1134 // the future, we have to separate Autofill popup window logic from WebKit to
1135 // Chromium. 1135 // Chromium.
1136 int LayoutThemeChromiumMac::popupInternalPaddingLeft(RenderStyle* style) const 1136 int LayoutThemeChromiumMac::popupInternalPaddingLeft(const RenderStyle* style) c onst
1137 { 1137 {
1138 if (style->appearance() == TextFieldPart) 1138 if (style->appearance() == TextFieldPart)
1139 return autofillPopupHorizontalPadding; 1139 return autofillPopupHorizontalPadding;
1140 1140
1141 if (style->appearance() == MenulistPart) 1141 if (style->appearance() == MenulistPart)
1142 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::LeftMargi n] * style->effectiveZoom(); 1142 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::LeftMargi n] * style->effectiveZoom();
1143 if (style->appearance() == MenulistButtonPart) 1143 if (style->appearance() == MenulistButtonPart)
1144 return styledPopupPaddingLeft * style->effectiveZoom(); 1144 return styledPopupPaddingLeft * style->effectiveZoom();
1145 return 0; 1145 return 0;
1146 } 1146 }
1147 1147
1148 int LayoutThemeChromiumMac::popupInternalPaddingRight(RenderStyle* style) const 1148 int LayoutThemeChromiumMac::popupInternalPaddingRight(const RenderStyle* style) const
1149 { 1149 {
1150 if (style->appearance() == TextFieldPart) 1150 if (style->appearance() == TextFieldPart)
1151 return autofillPopupHorizontalPadding; 1151 return autofillPopupHorizontalPadding;
1152 1152
1153 if (style->appearance() == MenulistPart) 1153 if (style->appearance() == MenulistPart)
1154 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::RightMarg in] * style->effectiveZoom(); 1154 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::RightMarg in] * style->effectiveZoom();
1155 if (style->appearance() == MenulistButtonPart) { 1155 if (style->appearance() == MenulistButtonPart) {
1156 float fontScale = style->fontSize() / baseFontSize; 1156 float fontScale = style->fontSize() / baseFontSize;
1157 float arrowWidth = baseArrowWidth * fontScale; 1157 float arrowWidth = baseArrowWidth * fontScale;
1158 return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPadd ingRight + paddingBeforeSeparator) * style->effectiveZoom())); 1158 return static_cast<int>(ceilf(arrowWidth + (arrowPaddingLeft + arrowPadd ingRight + paddingBeforeSeparator) * style->effectiveZoom()));
1159 } 1159 }
1160 return 0; 1160 return 0;
1161 } 1161 }
1162 1162
1163 int LayoutThemeChromiumMac::popupInternalPaddingTop(RenderStyle* style) const 1163 int LayoutThemeChromiumMac::popupInternalPaddingTop(const RenderStyle* style) co nst
1164 { 1164 {
1165 if (style->appearance() == MenulistPart) 1165 if (style->appearance() == MenulistPart)
1166 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style->effectiveZoom(); 1166 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style->effectiveZoom();
1167 if (style->appearance() == MenulistButtonPart) 1167 if (style->appearance() == MenulistButtonPart)
1168 return styledPopupPaddingTop * style->effectiveZoom(); 1168 return styledPopupPaddingTop * style->effectiveZoom();
1169 return 0; 1169 return 0;
1170 } 1170 }
1171 1171
1172 int LayoutThemeChromiumMac::popupInternalPaddingBottom(RenderStyle* style) const 1172 int LayoutThemeChromiumMac::popupInternalPaddingBottom(const RenderStyle* style) const
1173 { 1173 {
1174 if (style->appearance() == MenulistPart) 1174 if (style->appearance() == MenulistPart)
1175 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::BottomMar gin] * style->effectiveZoom(); 1175 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::BottomMar gin] * style->effectiveZoom();
1176 if (style->appearance() == MenulistButtonPart) 1176 if (style->appearance() == MenulistButtonPart)
1177 return styledPopupPaddingBottom * style->effectiveZoom(); 1177 return styledPopupPaddingBottom * style->effectiveZoom();
1178 return 0; 1178 return 0;
1179 } 1179 }
1180 1180
1181 void LayoutThemeChromiumMac::adjustMenuListButtonStyle(RenderStyle* style, Eleme nt*) const 1181 void LayoutThemeChromiumMac::adjustMenuListButtonStyle(RenderStyle* style, Eleme nt*) const
1182 { 1182 {
(...skipping 24 matching lines...) Expand all
1207 updateFocusedState(popupButton, o); 1207 updateFocusedState(popupButton, o);
1208 #endif 1208 #endif
1209 } 1209 }
1210 1210
1211 const IntSize* LayoutThemeChromiumMac::menuListSizes() const 1211 const IntSize* LayoutThemeChromiumMac::menuListSizes() const
1212 { 1212 {
1213 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) }; 1213 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) };
1214 return sizes; 1214 return sizes;
1215 } 1215 }
1216 1216
1217 int LayoutThemeChromiumMac::minimumMenuListSize(RenderStyle* style) const 1217 int LayoutThemeChromiumMac::minimumMenuListSize(const RenderStyle* style) const
1218 { 1218 {
1219 return sizeForSystemFont(style, menuListSizes()).width(); 1219 return sizeForSystemFont(style, menuListSizes()).width();
1220 } 1220 }
1221 1221
1222 const int sliderTrackWidth = 5; 1222 const int sliderTrackWidth = 5;
1223 const int sliderTrackBorderWidth = 1; 1223 const int sliderTrackBorderWidth = 1;
1224 1224
1225 bool LayoutThemeChromiumMac::paintSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r) 1225 bool LayoutThemeChromiumMac::paintSliderTrack(RenderObject* o, const PaintInfo& paintInfo, const IntRect& r)
1226 { 1226 {
1227 paintSliderTicks(o, paintInfo, r); 1227 paintSliderTicks(o, paintInfo, r);
(...skipping 607 matching lines...) Expand 10 before | Expand all | Expand 10 after
1835 bool LayoutThemeChromiumMac::paintMediaFullscreenButton(RenderObject* object, co nst PaintInfo& paintInfo, const IntRect& rect) 1835 bool LayoutThemeChromiumMac::paintMediaFullscreenButton(RenderObject* object, co nst PaintInfo& paintInfo, const IntRect& rect)
1836 { 1836 {
1837 return RenderMediaControls::paintMediaControlsPart(MediaEnterFullscreenButto n, object, paintInfo, rect); 1837 return RenderMediaControls::paintMediaControlsPart(MediaEnterFullscreenButto n, object, paintInfo, rect);
1838 } 1838 }
1839 1839
1840 bool LayoutThemeChromiumMac::paintMediaToggleClosedCaptionsButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect) 1840 bool LayoutThemeChromiumMac::paintMediaToggleClosedCaptionsButton(RenderObject* object, const PaintInfo& paintInfo, const IntRect& rect)
1841 { 1841 {
1842 return RenderMediaControls::paintMediaControlsPart(MediaShowClosedCaptionsBu tton, object, paintInfo, rect); 1842 return RenderMediaControls::paintMediaControlsPart(MediaShowClosedCaptionsBu tton, object, paintInfo, rect);
1843 } 1843 }
1844 1844
1845 bool LayoutThemeChromiumMac::shouldUseFallbackTheme(RenderStyle* style) const 1845 bool LayoutThemeChromiumMac::shouldUseFallbackTheme(const RenderStyle* style) co nst
1846 { 1846 {
1847 ControlPart part = style->appearance(); 1847 ControlPart part = style->appearance();
1848 if (part == CheckboxPart || part == RadioPart) 1848 if (part == CheckboxPart || part == RadioPart)
1849 return style->effectiveZoom() != 1; 1849 return style->effectiveZoom() != 1;
1850 return false; 1850 return false;
1851 } 1851 }
1852 1852
1853 } // namespace blink 1853 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698