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

Side by Side Diff: third_party/WebKit/Source/core/layout/LayoutText.cpp

Issue 2803483002: Adjust visual overflow rect for rounded/shifted ascent/descent (Closed)
Patch Set: Rebaseline-cl Created 3 years, 8 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 * (C) 1999 Lars Knoll (knoll@kde.org) 2 * (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 2000 Dirk Mueller (mueller@kde.org) 3 * (C) 2000 Dirk Mueller (mueller@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved. 4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net) 5 * Copyright (C) 2006 Andrew Wellington (proton@wiretapped.net)
6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com) 6 * Copyright (C) 2006 Graham Dennis (graham.dennis@gmail.com)
7 * 7 *
8 * This library is free software; you can redistribute it and/or 8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public 9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either 10 * License as published by the Free Software Foundation; either
(...skipping 1921 matching lines...) Expand 10 before | Expand all | Expand 10 after
1932 float width = isHorizontal ? logicalRightSide - logicalLeftSide 1932 float width = isHorizontal ? logicalRightSide - logicalLeftSide
1933 : lastTextBox()->logicalBottom() - x; 1933 : lastTextBox()->logicalBottom() - x;
1934 float height = isHorizontal ? lastTextBox()->logicalBottom() - y 1934 float height = isHorizontal ? lastTextBox()->logicalBottom() - y
1935 : logicalRightSide - logicalLeftSide; 1935 : logicalRightSide - logicalLeftSide;
1936 result = enclosingLayoutRect(FloatRect(x, y, width, height)); 1936 result = enclosingLayoutRect(FloatRect(x, y, width, height));
1937 } 1937 }
1938 1938
1939 return result; 1939 return result;
1940 } 1940 }
1941 1941
1942 static int visualOverflowAdjustmentForAscent(const ComputedStyle& style) {
1943 return style.font()
1944 .primaryFont()
1945 ->getFontMetrics()
1946 .visualOverflowAdjustmentForAscent();
1947 }
1948
1949 static int visualOverflowAdjustmentForDescent(const ComputedStyle& style) {
1950 return style.font()
1951 .primaryFont()
1952 ->getFontMetrics()
1953 .visualOverflowAdjustmentForDescent();
1954 }
1955
1942 LayoutRect LayoutText::visualOverflowRect() const { 1956 LayoutRect LayoutText::visualOverflowRect() const {
1943 if (!firstTextBox()) 1957 if (!firstTextBox())
1944 return LayoutRect(); 1958 return LayoutRect();
1945 1959
1946 // Return the width of the minimal left side and the maximal right side. 1960 // Return the width of the minimal left side and the maximal right side.
1947 LayoutUnit logicalLeftSide = LayoutUnit::max(); 1961 LayoutUnit logicalLeftSide = LayoutUnit::max();
1948 LayoutUnit logicalRightSide = LayoutUnit::min(); 1962 LayoutUnit logicalRightSide = LayoutUnit::min();
1949 for (InlineTextBox* curr = firstTextBox(); curr; curr = curr->nextTextBox()) { 1963 for (InlineTextBox* curr = firstTextBox(); curr; curr = curr->nextTextBox()) {
1950 LayoutRect logicalVisualOverflow = curr->logicalOverflowRect(); 1964 LayoutRect logicalVisualOverflow = curr->logicalOverflowRect();
1951 logicalLeftSide = std::min(logicalLeftSide, logicalVisualOverflow.x()); 1965 logicalLeftSide = std::min(logicalLeftSide, logicalVisualOverflow.x());
1952 logicalRightSide = std::max(logicalRightSide, logicalVisualOverflow.maxX()); 1966 logicalRightSide = std::max(logicalRightSide, logicalVisualOverflow.maxX());
1953 } 1967 }
1954 1968
1955 LayoutUnit logicalTop = firstTextBox()->logicalTopVisualOverflow(); 1969 LayoutUnit logicalTop = firstTextBox()->logicalTopVisualOverflow();
1956 LayoutUnit logicalWidth = logicalRightSide - logicalLeftSide; 1970 LayoutUnit logicalWidth = logicalRightSide - logicalLeftSide;
1957 LayoutUnit logicalHeight = 1971 LayoutUnit logicalHeight =
1958 lastTextBox()->logicalBottomVisualOverflow() - logicalTop; 1972 lastTextBox()->logicalBottomVisualOverflow() - logicalTop;
1959 1973
1974 const auto& firstStyle = styleRef(firstTextBox()->isFirstLineStyle());
eae 2017/04/07 16:34:56 If I understand the logic right you are inflating
Xianzhu 2017/04/07 17:27:11 This won't work because 1. in many cases floatAsce
1975 int ascentAdjustment = visualOverflowAdjustmentForAscent(firstStyle);
1976 int descentAdjustment = visualOverflowAdjustmentForDescent(firstStyle);
1977 if (lastTextBox()->isFirstLineStyle() != firstTextBox()->isFirstLineStyle()) {
1978 const auto& lastStyle = styleRef(lastTextBox()->isFirstLineStyle());
eae 2017/04/07 16:34:56 The names here are bad. It's not really an ascentA
Xianzhu 2017/04/07 17:27:11 Renamed visualOverflowAdjustmentXxx to visualOverf
1979 ascentAdjustment = std::max(ascentAdjustment,
1980 visualOverflowAdjustmentForAscent(lastStyle));
1981 descentAdjustment = std::max(descentAdjustment,
1982 visualOverflowAdjustmentForDescent(lastStyle));
1983 }
1984 logicalTop -= ascentAdjustment;
1985 logicalHeight += ascentAdjustment + descentAdjustment;
1986
1960 LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight); 1987 LayoutRect rect(logicalLeftSide, logicalTop, logicalWidth, logicalHeight);
1961 if (!style()->isHorizontalWritingMode()) 1988 if (!style()->isHorizontalWritingMode())
1962 rect = rect.transposedRect(); 1989 rect = rect.transposedRect();
1963 return rect; 1990 return rect;
1964 } 1991 }
1965 1992
1966 LayoutRect LayoutText::localVisualRect() const { 1993 LayoutRect LayoutText::localVisualRect() const {
1967 if (style()->visibility() != EVisibility::kVisible) 1994 if (style()->visibility() != EVisibility::kVisible)
1968 return LayoutRect(); 1995 return LayoutRect();
1969 1996
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
2092 LayoutRect rect = LayoutRect( 2119 LayoutRect rect = LayoutRect(
2093 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height())); 2120 IntRect(firstRunX(), firstRunY(), linesBox.width(), linesBox.height()));
2094 LayoutBlock* block = containingBlock(); 2121 LayoutBlock* block = containingBlock();
2095 if (block && hasTextBoxes()) 2122 if (block && hasTextBoxes())
2096 block->adjustChildDebugRect(rect); 2123 block->adjustChildDebugRect(rect);
2097 2124
2098 return rect; 2125 return rect;
2099 } 2126 }
2100 2127
2101 } // namespace blink 2128 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698