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

Side by Side Diff: third_party/WebKit/Source/core/editing/VisibleUnits.cpp

Issue 2941013003: Introduce ComputeInlineBoxPositionForTextNode() (Closed)
Patch Set: 2017-06-15T15:39:24 Created 3 years, 6 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights
3 * reserved. 3 * reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 const InlineTextBox& box, 762 const InlineTextBox& box,
763 TextAffinity affinity) { 763 TextAffinity affinity) {
764 if (caret_offset == box.CaretMinOffset()) 764 if (caret_offset == box.CaretMinOffset())
765 return affinity == TextAffinity::kDownstream; 765 return affinity == TextAffinity::kDownstream;
766 DCHECK_EQ(caret_offset, box.CaretMaxOffset()); 766 DCHECK_EQ(caret_offset, box.CaretMaxOffset());
767 if (affinity == TextAffinity::kUpstream) 767 if (affinity == TextAffinity::kUpstream)
768 return true; 768 return true;
769 return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak(); 769 return box.NextLeafChild() && box.NextLeafChild()->IsLineBreak();
770 } 770 }
771 771
772 // TODO(yosin): We have a forward declaration here to reduce patch size. We'll
773 // replace this with an implementation once review finished.
774 static InlineBoxPosition ComputeInlineBoxPositionForTextNode(LayoutObject*,
775 int caret_offset,
776 TextAffinity,
777 TextDirection);
778
772 template <typename Strategy> 779 template <typename Strategy>
773 static InlineBoxPosition ComputeInlineBoxPositionTemplate( 780 static InlineBoxPosition ComputeInlineBoxPositionTemplate(
774 const PositionTemplate<Strategy>& position, 781 const PositionTemplate<Strategy>& position,
775 TextAffinity affinity, 782 TextAffinity affinity,
776 TextDirection primary_direction) { 783 TextDirection primary_direction) {
777 int caret_offset = position.ComputeEditingOffset(); 784 int caret_offset = position.ComputeEditingOffset();
778 Node* const anchor_node = position.AnchorNode(); 785 Node* const anchor_node = position.AnchorNode();
779 LayoutObject* layout_object = 786 LayoutObject* layout_object =
780 anchor_node->IsShadowRoot() 787 anchor_node->IsShadowRoot()
781 ? ToShadowRoot(anchor_node)->host().GetLayoutObject() 788 ? ToShadowRoot(anchor_node)->host().GetLayoutObject()
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 if (!inline_box) 821 if (!inline_box)
815 return InlineBoxPosition(); 822 return InlineBoxPosition();
816 if ((caret_offset > inline_box->CaretMinOffset() && 823 if ((caret_offset > inline_box->CaretMinOffset() &&
817 caret_offset < inline_box->CaretMaxOffset())) 824 caret_offset < inline_box->CaretMaxOffset()))
818 return InlineBoxPosition(inline_box, caret_offset); 825 return InlineBoxPosition(inline_box, caret_offset);
819 return AdjustInlineBoxPositionForTextDirection( 826 return AdjustInlineBoxPositionForTextDirection(
820 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(), 827 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(),
821 primary_direction); 828 primary_direction);
822 } 829 }
823 830
831 return ComputeInlineBoxPositionForTextNode(layout_object, caret_offset,
832 affinity, primary_direction);
833 }
834
835 // TODO(yosin): We should make |ComputeInlineBoxPositionForTextNode()| to take
836 // |const LayoutText&|.
837 static InlineBoxPosition ComputeInlineBoxPositionForTextNode(
838 LayoutObject* layout_object,
839 int caret_offset,
840 TextAffinity affinity,
841 TextDirection primary_direction) {
824 // TODO(yosin): We should move this code fragment to another function to 842 // TODO(yosin): We should move this code fragment to another function to
825 // remove the scope. 843 // remove the scope.
826 InlineBox* inline_box = nullptr; 844 InlineBox* inline_box = nullptr;
827 { 845 {
828 LayoutText* text_layout_object = ToLayoutText(layout_object); 846 LayoutText* text_layout_object = ToLayoutText(layout_object);
829 847
830 InlineTextBox* candidate = nullptr; 848 InlineTextBox* candidate = nullptr;
831 849
832 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { 850 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) {
833 int caret_min_offset = box->CaretMinOffset(); 851 int caret_min_offset = box->CaretMinOffset();
(...skipping 1250 matching lines...) Expand 10 before | Expand all | Expand 10 after
2084 2102
2085 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 2103 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
2086 return EnclosingIntRect(ComputeTextRectTemplate(range)); 2104 return EnclosingIntRect(ComputeTextRectTemplate(range));
2087 } 2105 }
2088 2106
2089 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 2107 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
2090 return ComputeTextRectTemplate(range); 2108 return ComputeTextRectTemplate(range);
2091 } 2109 }
2092 2110
2093 } // namespace blink 2111 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698