 Chromium Code Reviews
 Chromium Code Reviews Issue 2224883002:
  Fix RTL rendering of SELECT on macOS and input[type=color] on all platforms.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master
    
  
    Issue 2224883002:
  Fix RTL rendering of SELECT on macOS and input[type=color] on all platforms.  (Closed) 
  Base URL: https://chromium.googlesource.com/chromium/src.git@master| OLD | NEW | 
|---|---|
| 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 458 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 469 // can however detect that we're zooming. If zooming is in effect we | 469 // can however detect that we're zooming. If zooming is in effect we | 
| 470 // treat it like the control is styled. | 470 // treat it like the control is styled. | 
| 471 if (style.effectiveZoom() != 1.0f) | 471 if (style.effectiveZoom() != 1.0f) | 
| 472 return true; | 472 return true; | 
| 473 if (!fontSizeMatchesToControlSize(style)) | 473 if (!fontSizeMatchesToControlSize(style)) | 
| 474 return true; | 474 return true; | 
| 475 if (style.getFontDescription().family().family() != "BlinkMacSystemFont" ) | 475 if (style.getFontDescription().family().family() != "BlinkMacSystemFont" ) | 
| 476 return true; | 476 return true; | 
| 477 if (!style.height().isIntrinsicOrAuto()) | 477 if (!style.height().isIntrinsicOrAuto()) | 
| 478 return true; | 478 return true; | 
| 479 // NSPopUpButtonCell on macOS 10.9 doesn't support | |
| 
tkent
2016/08/09 01:04:31
Actually, I don't know the status of macOS 10.10.
 
tkent
2016/08/09 03:59:17
https://codereview.chromium.org/2223373002/ showed
 | |
| 480 // NSUserInterfaceLayoutDirectionRightToLeft. | |
| 481 if (IsOSMavericks() && style.direction() == RTL) | |
| 482 return true; | |
| 479 } | 483 } | 
| 480 // Some other cells don't work well when scaled. | 484 // Some other cells don't work well when scaled. | 
| 481 if (style.effectiveZoom() != 1) { | 485 if (style.effectiveZoom() != 1) { | 
| 482 switch (style.appearance()) { | 486 switch (style.appearance()) { | 
| 483 case ButtonPart: | 487 case ButtonPart: | 
| 484 case PushButtonPart: | 488 case PushButtonPart: | 
| 485 case SearchFieldPart: | 489 case SearchFieldPart: | 
| 486 case SquareButtonPart: | 490 case SquareButtonPart: | 
| 487 return true; | 491 return true; | 
| 488 default: | 492 default: | 
| (...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 740 | 744 | 
| 741 // Our font is locked to the appropriate system font size for the | 745 // Our font is locked to the appropriate system font size for the | 
| 742 // control. To clarify, we first use the CSS-specified font to figure out a | 746 // control. To clarify, we first use the CSS-specified font to figure out a | 
| 743 // reasonable control size, but once that control size is determined, we | 747 // reasonable control size, but once that control size is determined, we | 
| 744 // throw that font away and use the appropriate system font for the control | 748 // throw that font away and use the appropriate system font for the control | 
| 745 // size instead. | 749 // size instead. | 
| 746 setFontFromControlSize(style, controlSize); | 750 setFontFromControlSize(style, controlSize); | 
| 747 } | 751 } | 
| 748 | 752 | 
| 749 static const int baseBorderRadius = 5; | 753 static const int baseBorderRadius = 5; | 
| 750 static const int styledPopupPaddingLeft = 8; | 754 static const int styledPopupPaddingStart = 8; | 
| 751 static const int styledPopupPaddingTop = 1; | 755 static const int styledPopupPaddingTop = 1; | 
| 752 static const int styledPopupPaddingBottom = 2; | 756 static const int styledPopupPaddingBottom = 2; | 
| 753 | 757 | 
| 754 // These functions are called with MenuListPart or MenulistButtonPart appearance | 758 // These functions are called with MenuListPart or MenulistButtonPart appearance | 
| 755 // by LayoutMenuList. | 759 // by LayoutMenuList. | 
| 756 int LayoutThemeMac::popupInternalPaddingLeft(const ComputedStyle& style) const | 760 int LayoutThemeMac::popupInternalPaddingLeft(const ComputedStyle& style) const | 
| 757 { | 761 { | 
| 762 bool isRTL = style.direction() == RTL; | |
| 758 if (style.appearance() == MenulistPart) | 763 if (style.appearance() == MenulistPart) | 
| 759 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::LeftMargi n] * style.effectiveZoom(); | 764 return popupButtonPadding(controlSizeForFont(style))[isRTL ? ThemeMac::R ightMargin : ThemeMac::LeftMargin] * style.effectiveZoom(); | 
| 760 if (style.appearance() == MenulistButtonPart) | 765 if (style.appearance() != MenulistButtonPart) | 
| 761 return styledPopupPaddingLeft * style.effectiveZoom(); | 766 return 0; | 
| 762 return 0; | 767 if (isRTL) { | 
| 768 float fontScale = style.fontSize() / baseFontSize; | |
| 769 float arrowWidth = menuListBaseArrowWidth * fontScale; | |
| 770 return static_cast<int>(ceilf(arrowWidth + (menuListArrowPaddingStart + menuListArrowPaddingEnd) * style.effectiveZoom())); | |
| 771 } | |
| 772 return styledPopupPaddingStart * style.effectiveZoom(); | |
| 763 } | 773 } | 
| 764 | 774 | 
| 765 int LayoutThemeMac::popupInternalPaddingRight(const ComputedStyle& style) const | 775 int LayoutThemeMac::popupInternalPaddingRight(const ComputedStyle& style) const | 
| 766 { | 776 { | 
| 777 bool isRTL = style.direction() == RTL; | |
| 767 if (style.appearance() == MenulistPart) | 778 if (style.appearance() == MenulistPart) | 
| 768 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::RightMarg in] * style.effectiveZoom(); | 779 return popupButtonPadding(controlSizeForFont(style))[isRTL ? ThemeMac::L eftMargin : ThemeMac::RightMargin] * style.effectiveZoom(); | 
| 769 if (style.appearance() == MenulistButtonPart) { | 780 if (style.appearance() != MenulistButtonPart) | 
| 770 float fontScale = style.fontSize() / baseFontSize; | 781 return 0; | 
| 771 float arrowWidth = menuListBaseArrowWidth * fontScale; | 782 if (isRTL) { | 
| 772 return static_cast<int>(ceilf(arrowWidth + (menuListArrowPaddingLeft + m enuListArrowPaddingRight) * style.effectiveZoom())); | 783 return styledPopupPaddingStart * style.effectiveZoom(); | 
| 773 } | 784 } | 
| 774 return 0; | 785 float fontScale = style.fontSize() / baseFontSize; | 
| 786 float arrowWidth = menuListBaseArrowWidth * fontScale; | |
| 787 return static_cast<int>(ceilf(arrowWidth + (menuListArrowPaddingStart + menu ListArrowPaddingEnd) * style.effectiveZoom())); | |
| 775 } | 788 } | 
| 776 | 789 | 
| 777 int LayoutThemeMac::popupInternalPaddingTop(const ComputedStyle& style) const | 790 int LayoutThemeMac::popupInternalPaddingTop(const ComputedStyle& style) const | 
| 778 { | 791 { | 
| 779 if (style.appearance() == MenulistPart) | 792 if (style.appearance() == MenulistPart) | 
| 780 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style.effectiveZoom(); | 793 return popupButtonPadding(controlSizeForFont(style))[ThemeMac::TopMargin ] * style.effectiveZoom(); | 
| 781 if (style.appearance() == MenulistButtonPart) | 794 if (style.appearance() == MenulistButtonPart) | 
| 782 return styledPopupPaddingTop * style.effectiveZoom(); | 795 return styledPopupPaddingTop * style.effectiveZoom(); | 
| 783 return 0; | 796 return 0; | 
| 784 } | 797 } | 
| (...skipping 25 matching lines...) Expand all Loading... | |
| 810 NSPopUpButtonCell* popupButton = this->popupButton(); | 823 NSPopUpButtonCell* popupButton = this->popupButton(); | 
| 811 | 824 | 
| 812 // Set the control size based off the rectangle we're painting into. | 825 // Set the control size based off the rectangle we're painting into. | 
| 813 setControlSize(popupButton, popupButtonSizes(), rect.size(), object.styleRef ().effectiveZoom()); | 826 setControlSize(popupButton, popupButtonSizes(), rect.size(), object.styleRef ().effectiveZoom()); | 
| 814 | 827 | 
| 815 // Update the various states we respond to. | 828 // Update the various states we respond to. | 
| 816 updateActiveState(popupButton, object); | 829 updateActiveState(popupButton, object); | 
| 817 updateCheckedState(popupButton, object); | 830 updateCheckedState(popupButton, object); | 
| 818 updateEnabledState(popupButton, object); | 831 updateEnabledState(popupButton, object); | 
| 819 updatePressedState(popupButton, object); | 832 updatePressedState(popupButton, object); | 
| 833 | |
| 834 popupButton.userInterfaceLayoutDirection = object.styleRef().direction() == LTR ? NSUserInterfaceLayoutDirectionLeftToRight : NSUserInterfaceLayoutDirection RightToLeft; | |
| 820 } | 835 } | 
| 821 | 836 | 
| 822 const IntSize* LayoutThemeMac::menuListSizes() const | 837 const IntSize* LayoutThemeMac::menuListSizes() const | 
| 823 { | 838 { | 
| 824 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) }; | 839 static const IntSize sizes[3] = { IntSize(9, 0), IntSize(5, 0), IntSize(0, 0 ) }; | 
| 825 return sizes; | 840 return sizes; | 
| 826 } | 841 } | 
| 827 | 842 | 
| 828 int LayoutThemeMac::minimumMenuListSize(const ComputedStyle& style) const | 843 int LayoutThemeMac::minimumMenuListSize(const ComputedStyle& style) const | 
| 829 { | 844 { | 
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1101 | 1116 | 
| 1102 bool LayoutThemeMac::shouldUseFallbackTheme(const ComputedStyle& style) const | 1117 bool LayoutThemeMac::shouldUseFallbackTheme(const ComputedStyle& style) const | 
| 1103 { | 1118 { | 
| 1104 ControlPart part = style.appearance(); | 1119 ControlPart part = style.appearance(); | 
| 1105 if (part == CheckboxPart || part == RadioPart) | 1120 if (part == CheckboxPart || part == RadioPart) | 
| 1106 return style.effectiveZoom() != 1; | 1121 return style.effectiveZoom() != 1; | 
| 1107 return false; | 1122 return false; | 
| 1108 } | 1123 } | 
| 1109 | 1124 | 
| 1110 } // namespace blink | 1125 } // namespace blink | 
| OLD | NEW |