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

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

Issue 2926823002: Introduce LocalCaretRect for refactoring Local{Caret,Selection}RectPosition() (Closed)
Patch Set: 2017-06-09T13:08:12 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 // DocumentLifeCycle::LayoutClean but caretRendersInsideNode above can 67 // DocumentLifeCycle::LayoutClean but caretRendersInsideNode above can
68 // layout. Thus |node->layoutObject()| can be changed then this is bad 68 // layout. Thus |node->layoutObject()| can be changed then this is bad
69 // design. We should make caret painting algorithm clean. 69 // design. We should make caret painting algorithm clean.
70 CHECK_EQ(layout_object, node->GetLayoutObject()) 70 CHECK_EQ(layout_object, node->GetLayoutObject())
71 << "Layout tree should not changed"; 71 << "Layout tree should not changed";
72 return painted_by_block ? ToLayoutBlock(layout_object) 72 return painted_by_block ? ToLayoutBlock(layout_object)
73 : layout_object->ContainingBlock(); 73 : layout_object->ContainingBlock();
74 } 74 }
75 75
76 static LayoutRect MapCaretRectToCaretPainter( 76 static LayoutRect MapCaretRectToCaretPainter(
77 LayoutItem caret_layout_item, 77 const LayoutBlockItem& caret_painter_item,
78 LayoutBlockItem caret_painter_item, 78 const LocalCaretRect& caret_rect) {
79 const LayoutRect& passed_caret_rect) {
80 // FIXME: This shouldn't be called on un-rooted subtrees. 79 // FIXME: This shouldn't be called on un-rooted subtrees.
81 // FIXME: This should probably just use mapLocalToAncestor. 80 // FIXME: This should probably just use mapLocalToAncestor.
82 // Compute an offset between the caretLayoutItem and the caretPainterItem. 81 // Compute an offset between the caretLayoutItem and the caretPainterItem.
83 82
83 LayoutItem caret_layout_item = LayoutItem(caret_rect.layout_object);
84 DCHECK(caret_layout_item.IsDescendantOf(caret_painter_item)); 84 DCHECK(caret_layout_item.IsDescendantOf(caret_painter_item));
85 85
86 LayoutRect caret_rect = passed_caret_rect; 86 LayoutRect result_rect = caret_rect.rect;
87 caret_painter_item.FlipForWritingMode(result_rect);
87 while (caret_layout_item != caret_painter_item) { 88 while (caret_layout_item != caret_painter_item) {
88 LayoutItem container_item = caret_layout_item.Container(); 89 LayoutItem container_item = caret_layout_item.Container();
89 if (container_item.IsNull()) 90 if (container_item.IsNull())
90 return LayoutRect(); 91 return LayoutRect();
91 caret_rect.Move(caret_layout_item.OffsetFromContainer(container_item)); 92 result_rect.Move(caret_layout_item.OffsetFromContainer(container_item));
92 caret_layout_item = container_item; 93 caret_layout_item = container_item;
93 } 94 }
94 return caret_rect; 95 return result_rect;
95 } 96 }
96 97
97 LayoutRect CaretDisplayItemClient::ComputeCaretRect( 98 LayoutRect CaretDisplayItemClient::ComputeCaretRect(
98 const PositionWithAffinity& caret_position) { 99 const PositionWithAffinity& caret_position) {
99 if (caret_position.IsNull()) 100 if (caret_position.IsNull())
100 return LayoutRect(); 101 return LayoutRect();
101 102
102 DCHECK(caret_position.AnchorNode()->GetLayoutObject()); 103 DCHECK(caret_position.AnchorNode()->GetLayoutObject());
103 104
104 // First compute a rect local to the layoutObject at the selection start. 105 // First compute a rect local to the layoutObject at the selection start.
105 LayoutObject* layout_object; 106 const LocalCaretRect& caret_rect = LocalCaretRectOfPosition(caret_position);
106 const LayoutRect& caret_local_rect =
107 LocalCaretRectOfPosition(caret_position, layout_object);
108 107
109 // Get the layoutObject that will be responsible for painting the caret 108 // Get the layoutObject that will be responsible for painting the caret
110 // (which is either the layoutObject we just found, or one of its containers). 109 // (which is either the layoutObject we just found, or one of its containers).
111 LayoutBlockItem caret_painter_item = 110 const LayoutBlockItem caret_painter_item =
112 LayoutBlockItem(CaretLayoutBlock(caret_position.AnchorNode())); 111 LayoutBlockItem(CaretLayoutBlock(caret_position.AnchorNode()));
113 LayoutRect caret_local_rect_with_writing_mode = caret_local_rect; 112 return MapCaretRectToCaretPainter(caret_painter_item, caret_rect);
114 caret_painter_item.FlipForWritingMode(caret_local_rect_with_writing_mode);
115 return MapCaretRectToCaretPainter(LayoutItem(layout_object),
116 caret_painter_item,
117 caret_local_rect_with_writing_mode);
118 } 113 }
119 114
120 void CaretDisplayItemClient::ClearPreviousVisualRect(const LayoutBlock& block) { 115 void CaretDisplayItemClient::ClearPreviousVisualRect(const LayoutBlock& block) {
121 if (block == layout_block_) 116 if (block == layout_block_)
122 visual_rect_ = LayoutRect(); 117 visual_rect_ = LayoutRect();
123 if (block == previous_layout_block_) 118 if (block == previous_layout_block_)
124 visual_rect_in_previous_layout_block_ = LayoutRect(); 119 visual_rect_in_previous_layout_block_ = LayoutRect();
125 } 120 }
126 121
127 void CaretDisplayItemClient::LayoutBlockWillBeDestroyed( 122 void CaretDisplayItemClient::LayoutBlockWillBeDestroyed(
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 296
302 String CaretDisplayItemClient::DebugName() const { 297 String CaretDisplayItemClient::DebugName() const {
303 return "Caret"; 298 return "Caret";
304 } 299 }
305 300
306 LayoutRect CaretDisplayItemClient::VisualRect() const { 301 LayoutRect CaretDisplayItemClient::VisualRect() const {
307 return visual_rect_; 302 return visual_rect_;
308 } 303 }
309 304
310 } // namespace blink 305 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698