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

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

Issue 2934223002: Utilize ComputeInlineBoxPosition in early-return style (Closed)
Patch Set: 2017-06-14T18:03:38 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 756 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 template <typename Strategy> 772 template <typename Strategy>
773 static InlineBoxPosition ComputeInlineBoxPositionTemplate( 773 static InlineBoxPosition ComputeInlineBoxPositionTemplate(
774 const PositionTemplate<Strategy>& position, 774 const PositionTemplate<Strategy>& position,
775 TextAffinity affinity, 775 TextAffinity affinity,
776 TextDirection primary_direction) { 776 TextDirection primary_direction) {
777 InlineBox* inline_box = nullptr;
778 int caret_offset = position.ComputeEditingOffset(); 777 int caret_offset = position.ComputeEditingOffset();
779 Node* const anchor_node = position.AnchorNode(); 778 Node* const anchor_node = position.AnchorNode();
780 LayoutObject* layout_object = 779 LayoutObject* layout_object =
781 anchor_node->IsShadowRoot() 780 anchor_node->IsShadowRoot()
782 ? ToShadowRoot(anchor_node)->host().GetLayoutObject() 781 ? ToShadowRoot(anchor_node)->host().GetLayoutObject()
783 : anchor_node->GetLayoutObject(); 782 : anchor_node->GetLayoutObject();
784 783
785 DCHECK(layout_object) << position; 784 DCHECK(layout_object) << position;
786 785
787 if (!layout_object->IsText()) { 786 if (!layout_object->IsText()) {
788 inline_box = 0;
789 if (CanHaveChildrenForEditing(anchor_node) && 787 if (CanHaveChildrenForEditing(anchor_node) &&
790 layout_object->IsLayoutBlockFlow() && 788 layout_object->IsLayoutBlockFlow() &&
791 HasRenderedNonAnonymousDescendantsWithHeight(layout_object)) { 789 HasRenderedNonAnonymousDescendantsWithHeight(layout_object)) {
792 // Try a visually equivalent position with possibly opposite 790 // Try a visually equivalent position with possibly opposite
793 // editability. This helps in case |this| is in an editable block 791 // editability. This helps in case |this| is in an editable block
794 // but surrounded by non-editable positions. It acts to negate the 792 // but surrounded by non-editable positions. It acts to negate the
795 // logic at the beginning of 793 // logic at the beginning of
796 // |LayoutObject::createPositionWithAffinity()|. 794 // |LayoutObject::createPositionWithAffinity()|.
797 const PositionTemplate<Strategy>& downstream_equivalent = 795 const PositionTemplate<Strategy>& downstream_equivalent =
798 DownstreamIgnoringEditingBoundaries(position); 796 DownstreamIgnoringEditingBoundaries(position);
799 if (downstream_equivalent != position) { 797 if (downstream_equivalent != position) {
800 return ComputeInlineBoxPosition( 798 return ComputeInlineBoxPosition(
801 downstream_equivalent, TextAffinity::kUpstream, primary_direction); 799 downstream_equivalent, TextAffinity::kUpstream, primary_direction);
802 } 800 }
803 const PositionTemplate<Strategy>& upstream_equivalent = 801 const PositionTemplate<Strategy>& upstream_equivalent =
804 UpstreamIgnoringEditingBoundaries(position); 802 UpstreamIgnoringEditingBoundaries(position);
805 if (upstream_equivalent == position || 803 if (upstream_equivalent == position ||
806 DownstreamIgnoringEditingBoundaries(upstream_equivalent) == position) 804 DownstreamIgnoringEditingBoundaries(upstream_equivalent) == position)
807 return InlineBoxPosition(); 805 return InlineBoxPosition();
808 806
809 return ComputeInlineBoxPosition( 807 return ComputeInlineBoxPosition(
810 upstream_equivalent, TextAffinity::kUpstream, primary_direction); 808 upstream_equivalent, TextAffinity::kUpstream, primary_direction);
811 } 809 }
812 if (layout_object->IsBox()) { 810 if (!layout_object->IsBox())
813 inline_box = ToLayoutBox(layout_object)->InlineBoxWrapper(); 811 return InlineBoxPosition();
814 if (!inline_box) 812 InlineBox* const inline_box =
815 return InlineBoxPosition(); 813 ToLayoutBox(layout_object)->InlineBoxWrapper();
816 if ((caret_offset > inline_box->CaretMinOffset() && 814 if (!inline_box)
817 caret_offset < inline_box->CaretMaxOffset())) 815 return InlineBoxPosition();
818 return InlineBoxPosition(inline_box, caret_offset); 816 if ((caret_offset > inline_box->CaretMinOffset() &&
819 } 817 caret_offset < inline_box->CaretMaxOffset()))
820 } else { 818 return InlineBoxPosition(inline_box, caret_offset);
819 return AdjustInlineBoxPositionForTextDirection(
820 inline_box, caret_offset, layout_object->Style()->GetUnicodeBidi(),
821 primary_direction);
822 }
823
824 InlineBox* inline_box = nullptr;
825 {
Xiaocheng 2017/06/14 18:33:58 nit: Please add a TODO for removing this extra sco
yosin_UTC9 2017/06/15 02:33:21 Done.
821 LayoutText* text_layout_object = ToLayoutText(layout_object); 826 LayoutText* text_layout_object = ToLayoutText(layout_object);
822 827
823 InlineTextBox* candidate = nullptr; 828 InlineTextBox* candidate = nullptr;
824 829
825 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) { 830 for (InlineTextBox* box : InlineTextBoxesOf(*text_layout_object)) {
826 int caret_min_offset = box->CaretMinOffset(); 831 int caret_min_offset = box->CaretMinOffset();
827 int caret_max_offset = box->CaretMaxOffset(); 832 int caret_max_offset = box->CaretMaxOffset();
828 833
829 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset || 834 if (caret_offset < caret_min_offset || caret_offset > caret_max_offset ||
830 (caret_offset == caret_max_offset && box->IsLineBreak())) 835 (caret_offset == caret_max_offset && box->IsLineBreak()))
(...skipping 1246 matching lines...) Expand 10 before | Expand all | Expand 10 after
2077 2082
2078 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 2083 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
2079 return EnclosingIntRect(ComputeTextRectTemplate(range)); 2084 return EnclosingIntRect(ComputeTextRectTemplate(range));
2080 } 2085 }
2081 2086
2082 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 2087 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
2083 return ComputeTextRectTemplate(range); 2088 return ComputeTextRectTemplate(range);
2084 } 2089 }
2085 2090
2086 } // namespace blink 2091 } // 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