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

Side by Side Diff: Source/core/rendering/RootInlineBox.cpp

Issue 351213002: Change RenderObject::style(bool) to accept an enum instead (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Renamed enum to OwnOrFirstLineStyle, rebased and got rid of duplicate state on the stack in RootInl… Created 6 years, 5 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2003, 2006, 2008 Apple Inc. All rights reserved.
3 * 3 *
4 * This library is free software; you can redistribute it and/or 4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public 5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either 6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version. 7 * version 2 of the License, or (at your option) any later version.
8 * 8 *
9 * This library is distributed in the hope that it will be useful, 9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 709 matching lines...) Expand 10 before | Expand all | Expand 10 after
720 { 720 {
721 if (box->renderer().isText()) 721 if (box->renderer().isText())
722 return box->parent()->logicalTop(); 722 return box->parent()->logicalTop();
723 723
724 RenderBoxModelObject* renderer = box->boxModelObject(); 724 RenderBoxModelObject* renderer = box->boxModelObject();
725 ASSERT(renderer->isInline()); 725 ASSERT(renderer->isInline());
726 if (!renderer->isInline()) 726 if (!renderer->isInline())
727 return 0; 727 return 0;
728 728
729 // This method determines the vertical position for inline elements. 729 // This method determines the vertical position for inline elements.
730 bool firstLine = isFirstLineStyle(); 730 OwnOrFirstLineStyle ownOrFirstLineStyle = isFirstLineStyle();
731 if (firstLine && !renderer->document().styleEngine()->usesFirstLineRules()) 731 if (ownOrFirstLineStyle == FirstLineStyle && !renderer->document().styleEngi ne()->usesFirstLineRules())
732 firstLine = false; 732 ownOrFirstLineStyle = OwnStyle;
733 733
734 // Check the cache. 734 // Check the cache.
735 bool isRenderInline = renderer->isRenderInline(); 735 bool isRenderInline = renderer->isRenderInline();
736 if (isRenderInline && !firstLine) { 736 if (isRenderInline && ownOrFirstLineStyle == OwnStyle) {
737 LayoutUnit verticalPosition = verticalPositionCache.get(renderer, baseli neType()); 737 LayoutUnit verticalPosition = verticalPositionCache.get(renderer, baseli neType());
738 if (verticalPosition != PositionUndefined) 738 if (verticalPosition != PositionUndefined)
739 return verticalPosition; 739 return verticalPosition;
740 } 740 }
741 741
742 LayoutUnit verticalPosition = 0; 742 LayoutUnit verticalPosition = 0;
743 EVerticalAlign verticalAlign = renderer->style()->verticalAlign(); 743 EVerticalAlign verticalAlign = renderer->style()->verticalAlign();
744 if (verticalAlign == TOP || verticalAlign == BOTTOM) 744 if (verticalAlign == TOP || verticalAlign == BOTTOM)
745 return 0; 745 return 0;
746 746
747 RenderObject* parent = renderer->parent(); 747 RenderObject* parent = renderer->parent();
748 if (parent->isRenderInline() && parent->style()->verticalAlign() != TOP && p arent->style()->verticalAlign() != BOTTOM) 748 if (parent->isRenderInline() && parent->style()->verticalAlign() != TOP && p arent->style()->verticalAlign() != BOTTOM)
749 verticalPosition = box->parent()->logicalTop(); 749 verticalPosition = box->parent()->logicalTop();
750 750
751 if (verticalAlign != BASELINE) { 751 if (verticalAlign != BASELINE) {
752 const Font& font = parent->style(firstLine)->font(); 752 const Font& font = parent->style(ownOrFirstLineStyle)->font();
753 const FontMetrics& fontMetrics = font.fontMetrics(); 753 const FontMetrics& fontMetrics = font.fontMetrics();
754 int fontSize = font.fontDescription().computedPixelSize(); 754 int fontSize = font.fontDescription().computedPixelSize();
755 755
756 LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? Ho rizontalLine : VerticalLine; 756 LineDirectionMode lineDirection = parent->isHorizontalWritingMode() ? Ho rizontalLine : VerticalLine;
757 757
758 if (verticalAlign == SUB) 758 if (verticalAlign == SUB)
759 verticalPosition += fontSize / 5 + 1; 759 verticalPosition += fontSize / 5 + 1;
760 else if (verticalAlign == SUPER) 760 else if (verticalAlign == SUPER)
761 verticalPosition -= fontSize / 3 + 1; 761 verticalPosition -= fontSize / 3 + 1;
762 else if (verticalAlign == TEXT_TOP) 762 else if (verticalAlign == TEXT_TOP)
763 verticalPosition += renderer->baselinePosition(baselineType(), first Line, lineDirection) - fontMetrics.ascent(baselineType()); 763 verticalPosition += renderer->baselinePosition(baselineType(), ownOr FirstLineStyle, lineDirection) - fontMetrics.ascent(baselineType());
764 else if (verticalAlign == MIDDLE) 764 else if (verticalAlign == MIDDLE)
765 verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontM etrics.xHeight() / 2) - renderer->lineHeight(firstLine, lineDirection) / 2 + ren derer->baselinePosition(baselineType(), firstLine, lineDirection)).round(); 765 verticalPosition = (verticalPosition - static_cast<LayoutUnit>(fontM etrics.xHeight() / 2) - renderer->lineHeight(ownOrFirstLineStyle, lineDirection) / 2 + renderer->baselinePosition(baselineType(), ownOrFirstLineStyle, lineDirec tion)).round();
766 else if (verticalAlign == TEXT_BOTTOM) { 766 else if (verticalAlign == TEXT_BOTTOM) {
767 verticalPosition += fontMetrics.descent(baselineType()); 767 verticalPosition += fontMetrics.descent(baselineType());
768 // lineHeight - baselinePosition is always 0 for replaced elements ( except inline blocks), so don't bother wasting time in that case. 768 // lineHeight - baselinePosition is always 0 for replaced elements ( except inline blocks), so don't bother wasting time in that case.
769 if (!renderer->isReplaced() || renderer->isInlineBlockOrInlineTable( )) 769 if (!renderer->isReplaced() || renderer->isInlineBlockOrInlineTable( ))
770 verticalPosition -= (renderer->lineHeight(firstLine, lineDirecti on) - renderer->baselinePosition(baselineType(), firstLine, lineDirection)); 770 verticalPosition -= (renderer->lineHeight(ownOrFirstLineStyle, l ineDirection) - renderer->baselinePosition(baselineType(), ownOrFirstLineStyle, lineDirection));
771 } else if (verticalAlign == BASELINE_MIDDLE) 771 } else if (verticalAlign == BASELINE_MIDDLE)
772 verticalPosition += -renderer->lineHeight(firstLine, lineDirection) / 2 + renderer->baselinePosition(baselineType(), firstLine, lineDirection); 772 verticalPosition += -renderer->lineHeight(ownOrFirstLineStyle, lineD irection) / 2 + renderer->baselinePosition(baselineType(), ownOrFirstLineStyle, lineDirection);
773 else if (verticalAlign == LENGTH) { 773 else if (verticalAlign == LENGTH) {
774 LayoutUnit lineHeight; 774 LayoutUnit lineHeight;
775 //Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align : 'Percentages: refer to the 'line-height' of the element itself'. 775 //Per http://www.w3.org/TR/CSS21/visudet.html#propdef-vertical-align : 'Percentages: refer to the 'line-height' of the element itself'.
776 if (renderer->style()->verticalAlignLength().isPercent()) 776 if (renderer->style()->verticalAlignLength().isPercent())
777 lineHeight = renderer->style()->computedLineHeight(); 777 lineHeight = renderer->style()->computedLineHeight();
778 else 778 else
779 lineHeight = renderer->lineHeight(firstLine, lineDirection); 779 lineHeight = renderer->lineHeight(ownOrFirstLineStyle, lineDirec tion);
780 verticalPosition -= valueForLength(renderer->style()->verticalAlignL ength(), lineHeight); 780 verticalPosition -= valueForLength(renderer->style()->verticalAlignL ength(), lineHeight);
781 } 781 }
782 } 782 }
783 783
784 // Store the cached value. 784 // Store the cached value.
785 if (isRenderInline && !firstLine) 785 if (isRenderInline && ownOrFirstLineStyle == OwnStyle)
786 verticalPositionCache.set(renderer, baselineType(), verticalPosition); 786 verticalPositionCache.set(renderer, baselineType(), verticalPosition);
787 787
788 return verticalPosition; 788 return verticalPosition;
789 } 789 }
790 790
791 bool RootInlineBox::includeLeadingForBox(InlineBox* box) const 791 bool RootInlineBox::includeLeadingForBox(InlineBox* box) const
792 { 792 {
793 if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isTex t())) 793 if (box->renderer().isReplaced() || (box->renderer().isText() && !box->isTex t()))
794 return false; 794 return false;
795 795
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
875 } 875 }
876 876
877 #ifndef NDEBUG 877 #ifndef NDEBUG
878 const char* RootInlineBox::boxName() const 878 const char* RootInlineBox::boxName() const
879 { 879 {
880 return "RootInlineBox"; 880 return "RootInlineBox";
881 } 881 }
882 #endif 882 #endif
883 883
884 } // namespace WebCore 884 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/rendering/RenderTextControlSingleLine.cpp ('k') | Source/core/rendering/line/BreakingContextInlineHeaders.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698