Chromium Code Reviews| OLD | NEW |
|---|---|
| 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, 2008, 2009, 2010, 2011 Apple Inc. | 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. |
| 5 * All rights reserved. | 5 * All rights reserved. |
| 6 * | 6 * |
| 7 * This library is free software; you can redistribute it and/or | 7 * This library is free software; you can redistribute it and/or |
| 8 * modify it under the terms of the GNU Library General Public | 8 * modify it under the terms of the GNU Library General Public |
| 9 * License as published by the Free Software Foundation; either | 9 * License as published by the Free Software Foundation; either |
| 10 * version 2 of the License, or (at your option) any later version. | 10 * version 2 of the License, or (at your option) any later version. |
| 11 * | 11 * |
| 12 * This library is distributed in the hope that it will be useful, | 12 * This library is distributed in the hope that it will be useful, |
| 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 * Library General Public License for more details. | 15 * Library General Public License for more details. |
| 16 * | 16 * |
| 17 * You should have received a copy of the GNU Library General Public License | 17 * You should have received a copy of the GNU Library General Public License |
| 18 * along with this library; see the file COPYING.LIB. If not, write to | 18 * along with this library; see the file COPYING.LIB. If not, write to |
| 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 19 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 20 * Boston, MA 02110-1301, USA. | 20 * Boston, MA 02110-1301, USA. |
| 21 * | 21 * |
| 22 */ | 22 */ |
| 23 | 23 |
| 24 #include "core/layout/line/InlineTextBox.h" | 24 #include "core/layout/line/InlineTextBox.h" |
| 25 | 25 |
| 26 #include "core/layout/HitTestResult.h" | 26 #include "core/layout/HitTestResult.h" |
| 27 #include "core/layout/api/LineLayoutAPIShim.h" | |
| 27 #include "core/layout/api/LineLayoutBR.h" | 28 #include "core/layout/api/LineLayoutBR.h" |
| 28 #include "core/layout/api/LineLayoutBox.h" | 29 #include "core/layout/api/LineLayoutBox.h" |
| 29 #include "core/layout/api/LineLayoutRubyRun.h" | 30 #include "core/layout/api/LineLayoutRubyRun.h" |
| 30 #include "core/layout/api/LineLayoutRubyText.h" | 31 #include "core/layout/api/LineLayoutRubyText.h" |
| 31 #include "core/layout/line/AbstractInlineTextBox.h" | 32 #include "core/layout/line/AbstractInlineTextBox.h" |
| 32 #include "core/layout/line/EllipsisBox.h" | 33 #include "core/layout/line/EllipsisBox.h" |
| 33 #include "core/paint/InlineTextBoxPainter.h" | 34 #include "core/paint/InlineTextBoxPainter.h" |
| 34 #include "platform/fonts/CharacterRange.h" | 35 #include "platform/fonts/CharacterRange.h" |
| 35 #include "platform/fonts/FontCache.h" | 36 #include "platform/fonts/FontCache.h" |
| 36 #include "wtf/Vector.h" | 37 #include "wtf/Vector.h" |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 181 } else { | 182 } else { |
| 182 ellipsis->setSelectionState(SelectionNone); | 183 ellipsis->setSelectionState(SelectionNone); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 return state; | 187 return state; |
| 187 } | 188 } |
| 188 | 189 |
| 189 bool InlineTextBox::hasWrappedSelectionNewline() const { | 190 bool InlineTextBox::hasWrappedSelectionNewline() const { |
| 190 DCHECK(!getLineLayoutItem().needsLayout()); | 191 DCHECK(!getLineLayoutItem().needsLayout()); |
| 192 | |
| 191 SelectionState state = getSelectionState(); | 193 SelectionState state = getSelectionState(); |
| 192 return (state == SelectionStart || state == SelectionInside) | 194 if (state != SelectionStart && state != SelectionInside) |
| 193 // Checking last leaf child can be slow, so we make sure to do this | 195 return false; |
| 194 // only after the other simple conditionals. | 196 |
| 195 && (root().lastLeafChild() == this) | 197 // Checking last leaf child can be slow, so we make sure to do this |
| 196 // It's possible to have mixed LTR/RTL on a single line, and we only | 198 // only after the other simple conditionals. |
| 197 // want to paint a newline when we're the last leaf child and we make | 199 if (root().lastLeafChild() != this) |
| 198 // sure there isn't a differently-directioned box following us. | 200 return false; |
| 199 && ((!isLeftToRightDirection() && root().firstSelectedBox() == this) || | 201 |
| 200 (isLeftToRightDirection() && root().lastSelectedBox() == this)); | 202 // It's possible to have mixed LTR/RTL on a single line, and we only |
| 203 // want to paint a newline when we're the last leaf child and we make | |
| 204 // sure there isn't a differently-directioned box following us. | |
| 205 bool isLTR = isLeftToRightDirection(); | |
| 206 if ((!isLTR && root().firstSelectedBox() != this) || | |
| 207 (isLTR && root().lastSelectedBox() != this)) | |
| 208 return false; | |
| 209 | |
| 210 // If we're the last inline text box in containing block, our containing block | |
|
wkorman
2017/03/06 21:46:50
Below is new logic/comments, above is just an expl
| |
| 211 // is inline, and the selection continues into that block, then rely on the | |
| 212 // next inline text box (if any) to paint a wrapped new line as needed. | |
| 213 // | |
| 214 // TODO(wkorman): Note this is imperfect as it's possible the next inline text | |
|
wkorman
2017/03/06 21:46:50
I'd like to fix this but it requires more line lay
| |
| 215 // box (in a different containing block) is not on the same line as our inline | |
| 216 // box. Look into how to test whether the next inline text box is logically on | |
| 217 // same line as this one. | |
| 218 | |
| 219 if (nextTextBox()) | |
|
wkorman
2017/03/06 21:46:50
This method appears a reasonable signal for the en
| |
| 220 return true; | |
| 221 | |
| 222 LayoutBox* containingBox = | |
| 223 toLayoutBox(LineLayoutAPIShim::layoutObjectFrom(root().block())); | |
|
Xianzhu
2017/03/06 22:29:23
I think we don't need shim and cast.
auto block =
| |
| 224 if (containingBox->isInline() && | |
| 225 containingBox->getSelectionState() != SelectionEnd && | |
| 226 containingBox->getSelectionState() != SelectionBoth) | |
|
Xianzhu
2017/03/06 22:29:23
Will this work:
... &&
containingBox->inli
wkorman
2017/03/07 03:12:30
An exciting proposal, on initial investigation how
Xianzhu
2017/03/07 03:55:42
I think you can use InlineBox::nextOnLine().
wkorman
2017/03/07 17:41:31
This works, thanks. A question: fast/text/flexbox-
| |
| 227 return false; | |
| 228 | |
| 229 return true; | |
| 201 } | 230 } |
| 202 | 231 |
| 203 float InlineTextBox::newlineSpaceWidth() const { | 232 float InlineTextBox::newlineSpaceWidth() const { |
| 204 const ComputedStyle& styleToUse = | 233 const ComputedStyle& styleToUse = |
| 205 getLineLayoutItem().styleRef(isFirstLineStyle()); | 234 getLineLayoutItem().styleRef(isFirstLineStyle()); |
| 206 return styleToUse.font().spaceWidth(); | 235 return styleToUse.font().spaceWidth(); |
| 207 } | 236 } |
| 208 | 237 |
| 209 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) const { | 238 LayoutRect InlineTextBox::localSelectionRect(int startPos, int endPos) const { |
| 210 int sPos = std::max(startPos - m_start, 0); | 239 int sPos = std::max(startPos - m_start, 0); |
| (...skipping 475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 686 const int layoutObjectCharacterOffset = 75; | 715 const int layoutObjectCharacterOffset = 75; |
| 687 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) | 716 for (; printedCharacters < layoutObjectCharacterOffset; printedCharacters++) |
| 688 fputc(' ', stderr); | 717 fputc(' ', stderr); |
| 689 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), | 718 fprintf(stderr, "(%d,%d) \"%s\"\n", start(), start() + len(), |
| 690 value.utf8().data()); | 719 value.utf8().data()); |
| 691 } | 720 } |
| 692 | 721 |
| 693 #endif | 722 #endif |
| 694 | 723 |
| 695 } // namespace blink | 724 } // namespace blink |
| OLD | NEW |