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

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

Issue 2918783002: Extract InlineBox handling from MostForwardCaretPosition() (Closed)
Patch Set: 2017-06-01T18:38:06 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 (IsOffsetRenderedForForward(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 // Returns true if |offset| is rendered text of |layout_text_object|
Xiaocheng 2017/06/01 22:19:47 The purpose of the function isn't clear. An offse
yosin_UTC9 2017/06/05 09:12:15 Oops, sorry for confusion. |offset| should be |off
2835 static bool IsOffsetRenderedForForward(const LayoutText* text_layout_object,
2836 int offset_in_node) {
2837 const unsigned text_start_offset = text_layout_object->TextStartOffset();
2838 DCHECK_GE(offset_in_node, static_cast<int>(text_start_offset));
2839 const unsigned text_offset = offset_in_node - text_start_offset;
2840 InlineTextBox* const last_text_box = text_layout_object->LastTextBox();
2841 for (InlineTextBox* box = text_layout_object->FirstTextBox(); box;
2842 box = box->NextTextBox()) {
2843 if (text_offset <= box->end()) {
2844 if (text_offset >= box->Start())
2845 return true;
Xiaocheng 2017/06/01 22:19:48 It returns true here if an adjacent character at e
yosin_UTC9 2017/06/05 09:12:15 My interpretation is that if |text_offset| is in |
2846 continue;
2847 }
2848
2849 if (box == last_text_box || text_offset != box->Start() + box->Len())
2850 continue;
2851
2852 // The text continues on the next line only if the last text box is not
Xiaocheng 2017/06/01 22:19:48 nit: We can save one line here.
yosin_UTC9 2017/06/05 09:12:15 Done.
2853 // on this line and none of the boxes on this line have a larger start
2854 // offset.
2855
2856 bool continues_on_next_line = true;
2857 InlineBox* other_box = box;
2858 while (continues_on_next_line) {
2859 other_box = other_box->NextLeafChild();
2860 if (!other_box)
2861 break;
2862 if (other_box == last_text_box ||
2863 (LineLayoutAPIShim::LayoutObjectFrom(
2864 other_box->GetLineLayoutItem()) == text_layout_object &&
2865 ToInlineTextBox(other_box)->Start() >= text_offset))
2866 continues_on_next_line = false;
2867 }
2868
2869 other_box = box;
2870 while (continues_on_next_line) {
2871 other_box = other_box->PrevLeafChild();
2872 if (!other_box)
2873 break;
2874 if (other_box == last_text_box ||
2875 (LineLayoutAPIShim::LayoutObjectFrom(
2876 other_box->GetLineLayoutItem()) == text_layout_object &&
2877 ToInlineTextBox(other_box)->Start() >= text_offset))
2878 continues_on_next_line = false;
2879 }
2880
2881 if (continues_on_next_line)
2882 return true;
Xiaocheng 2017/06/01 22:19:47 I haven't understood in what situation |continues_
yosin_UTC9 2017/06/05 09:12:15 It seems most of case, |continues_on_next_line| re
2883 }
2884 return false;
2885 }
2886
2880 Position MostForwardCaretPosition(const Position& position, 2887 Position MostForwardCaretPosition(const Position& position,
2881 EditingBoundaryCrossingRule rule) { 2888 EditingBoundaryCrossingRule rule) {
2882 return MostForwardCaretPosition<EditingStrategy>(position, rule); 2889 return MostForwardCaretPosition<EditingStrategy>(position, rule);
2883 } 2890 }
2884 2891
2885 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position, 2892 PositionInFlatTree MostForwardCaretPosition(const PositionInFlatTree& position,
2886 EditingBoundaryCrossingRule rule) { 2893 EditingBoundaryCrossingRule rule) {
2887 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule); 2894 return MostForwardCaretPosition<EditingInFlatTreeStrategy>(position, rule);
2888 } 2895 }
2889 2896
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 3763
3757 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) { 3764 IntRect ComputeTextRect(const EphemeralRangeInFlatTree& range) {
3758 return EnclosingIntRect(ComputeTextRectTemplate(range)); 3765 return EnclosingIntRect(ComputeTextRectTemplate(range));
3759 } 3766 }
3760 3767
3761 FloatRect ComputeTextFloatRect(const EphemeralRange& range) { 3768 FloatRect ComputeTextFloatRect(const EphemeralRange& range) {
3762 return ComputeTextRectTemplate(range); 3769 return ComputeTextRectTemplate(range);
3763 } 3770 }
3764 3771
3765 } // namespace blink 3772 } // 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