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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-05T18:17:50 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 2804 matching lines...) Expand 10 before | Expand all | Expand 10 after
2815 if (layout_object->IsText() && 2815 if (layout_object->IsText() &&
2816 ToLayoutText(layout_object)->FirstTextBox()) { 2816 ToLayoutText(layout_object)->FirstTextBox()) {
2817 LayoutText* const text_layout_object = ToLayoutText(layout_object); 2817 LayoutText* const text_layout_object = ToLayoutText(layout_object);
2818 const unsigned text_start_offset = text_layout_object->TextStartOffset(); 2818 const unsigned text_start_offset = text_layout_object->TextStartOffset();
2819 if (current_node != start_node) { 2819 if (current_node != start_node) {
2820 DCHECK(current_pos.AtStartOfNode()); 2820 DCHECK(current_pos.AtStartOfNode());
2821 return PositionTemplate<Strategy>( 2821 return PositionTemplate<Strategy>(
2822 current_node, layout_object->CaretMinOffset() + text_start_offset); 2822 current_node, layout_object->CaretMinOffset() + text_start_offset);
2823 } 2823 }
2824 2824
2825 // Map offset in DOM node to offset in InlineBox. 2825 if (CanForwardCaretPosition(text_layout_object,
2826 DCHECK_GE(current_pos.OffsetInLeafNode(), 2826 current_pos.OffsetInLeafNode())) {
2827 static_cast<int>(text_start_offset)); 2827 return current_pos.ComputePosition();
2828 const unsigned text_offset =
2829 current_pos.OffsetInLeafNode() - text_start_offset;
2830 InlineTextBox* last_text_box = text_layout_object->LastTextBox();
2831 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
2832 box = box->NextTextBox()) {
2833 if (text_offset <= box->end()) {
2834 if (text_offset >= box->Start())
2835 return current_pos.ComputePosition();
2836 continue;
2837 }
2838
2839 if (box == last_text_box || text_offset != box->Start() + box->Len())
2840 continue;
2841
2842 // The text continues on the next line only if the last text box is not
2843 // on this line and none of the boxes on this line have a larger start
2844 // offset.
2845
2846 bool continues_on_next_line = true;
2847 InlineBox* other_box = box;
2848 while (continues_on_next_line) {
2849 other_box = other_box->NextLeafChild();
2850 if (!other_box)
2851 break;
2852 if (other_box == last_text_box ||
2853 (LineLayoutAPIShim::LayoutObjectFrom(
2854 other_box->GetLineLayoutItem()) == text_layout_object &&
2855 ToInlineTextBox(other_box)->Start() >= text_offset))
2856 continues_on_next_line = false;
2857 }
2858
2859 other_box = box;
2860 while (continues_on_next_line) {
2861 other_box = other_box->PrevLeafChild();
2862 if (!other_box)
2863 break;
2864 if (other_box == last_text_box ||
2865 (LineLayoutAPIShim::LayoutObjectFrom(
2866 other_box->GetLineLayoutItem()) == text_layout_object &&
2867 ToInlineTextBox(other_box)->Start() >= text_offset))
2868 continues_on_next_line = false;
2869 }
2870
2871 if (continues_on_next_line)
2872 return current_pos.ComputePosition();
2873 } 2828 }
2874 } 2829 }
2875 } 2830 }
2876
2877 return last_visible.DeprecatedComputePosition(); 2831 return last_visible.DeprecatedComputePosition();
2878 } 2832 }
2879 2833
2834 // TODO(editing-dev): This function is just moved out from
2835 // |MostForwardCaretPosition()|. We should study this function more and
2836 // name it appropriately. See https://trac.webkit.org/changeset/32438/
2837 // which introduce this.
2838 static bool CanForwardCaretPosition(const LayoutText* text_layout_object,
Xiaocheng 2017/06/05 19:35:53 nit: |CanBeForwardCaretPosition| seems a better na
yosin_UTC9 2017/06/06 04:21:14 Done. Thanks for providing good name.
2839 int offset_in_node) {
2840 const unsigned text_start_offset = text_layout_object->TextStartOffset();
2841 DCHECK_GE(offset_in_node, static_cast<int>(text_start_offset));
2842 const unsigned text_offset = offset_in_node - text_start_offset;
2843 InlineTextBox* const last_text_box = text_layout_object->LastTextBox();
2844 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
2845 box = box->NextTextBox()) {
2846 if (text_offset <= box->end()) {
2847 if (text_offset >= box->Start())
2848 return true;
2849 continue;
2850 }
2851
2852 if (box == last_text_box || text_offset != box->Start() + box->Len())
2853 continue;
2854
2855 // TODO(yosin): We should move below code fragment into
2856 // |DoesContinueOnNextLine()|. Note: |MostForwardCaretPosition()| has
Xiaocheng 2017/06/05 19:35:53 nit: s/Forward/Backward/
yosin_UTC9 2017/06/06 04:21:14 Done. Thanks for catching this.
2857 // same code fragment except for comparison on |text_offset|.
2858 // Backward: other_box->Start() > text_offset
2859 // Forward: other_box->Start() >= text_offset
2860 // The text continues on the next line only if the last text box is not
2861 // on this line and none of the boxes on this line have a larger start
2862 // offset.
2863 bool continues_on_next_line = true;
2864 InlineBox* other_box = box;
2865 while (continues_on_next_line) {
2866 other_box = other_box->NextLeafChild();
2867 if (!other_box)
2868 break;
2869 if (other_box == last_text_box ||
2870 (LineLayoutAPIShim::LayoutObjectFrom(
2871 other_box->GetLineLayoutItem()) == text_layout_object &&
2872 ToInlineTextBox(other_box)->Start() >= text_offset))
2873 continues_on_next_line = false;
2874 }
2875
2876 other_box = box;
2877 while (continues_on_next_line) {
2878 other_box = other_box->PrevLeafChild();
2879 if (!other_box)
2880 break;
2881 if (other_box == last_text_box ||
2882 (LineLayoutAPIShim::LayoutObjectFrom(
2883 other_box->GetLineLayoutItem()) == text_layout_object &&
2884 ToInlineTextBox(other_box)->Start() >= text_offset))
2885 continues_on_next_line = false;
2886 }
2887
2888 if (continues_on_next_line)
2889 return true;
2890 }
2891 return false;
2892 }
2893
2880 Position MostForwardCaretPosition(const Position& position, 2894 Position MostForwardCaretPosition(const Position& position,
2881 EditingBoundaryCrossingRule rule) { 2895 EditingBoundaryCrossingRule rule) {
2882 return MostForwardCaretPosition<EditingStrategy>(position, rule); 2896 return MostForwardCaretPosition<EditingStrategy>(position, rule);
2883 } 2897 }
2884 2898
2885 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position, 2899 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position,
2886 EditingBoundaryCrossingRule rule) { 2900 EditingBoundaryCrossingRule rule) {
2887 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule); 2901 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule);
2888 } 2902 }
2889 2903
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 3770
3757 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 3771 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
3758 return EnclosingIntRect(ComputeTextRectTemplate(range)); 3772 return EnclosingIntRect(ComputeTextRectTemplate(range));
3759 } 3773 }
3760 3774
3761 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 3775 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
3762 return ComputeTextRectTemplate(range); 3776 return ComputeTextRectTemplate(range);
3763 } 3777 }
3764 3778
3765 } // namespace blink 3779 } // 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