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

Side by Side Diff: third_party/WebKit/Source/core/layout/ng/inline/ng_inline_node.cc

Issue 2940153002: [LayoutNG] Implement more text-align values and BiDi base direction (Closed)
Patch Set: eae review 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "core/layout/ng/inline/ng_inline_node.h" 5 #include "core/layout/ng/inline/ng_inline_node.h"
6 6
7 #include "core/layout/BidiRun.h" 7 #include "core/layout/BidiRun.h"
8 #include "core/layout/LayoutBlockFlow.h" 8 #include "core/layout/LayoutBlockFlow.h"
9 #include "core/layout/LayoutObject.h" 9 #include "core/layout/LayoutObject.h"
10 #include "core/layout/LayoutText.h" 10 #include "core/layout/LayoutText.h"
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 ToLayoutNGBlockFlow(GetLayoutBlockFlow())->ResetNGInlineNodeData(); 185 ToLayoutNGBlockFlow(GetLayoutBlockFlow())->ResetNGInlineNodeData();
186 MutableData().start_inline_ = start_inline; 186 MutableData().start_inline_ = start_inline;
187 MutableData().text_content_ = String(); 187 MutableData().text_content_ = String();
188 MutableData().items_.clear(); 188 MutableData().items_.clear();
189 } 189 }
190 190
191 void NGInlineNode::PrepareLayout() { 191 void NGInlineNode::PrepareLayout() {
192 // Scan list of siblings collecting all in-flow non-atomic inlines. A single 192 // Scan list of siblings collecting all in-flow non-atomic inlines. A single
193 // NGInlineNode represent a collection of adjacent non-atomic inlines. 193 // NGInlineNode represent a collection of adjacent non-atomic inlines.
194 CollectInlines(Data().start_inline_, GetLayoutBlockFlow()); 194 CollectInlines(Data().start_inline_, GetLayoutBlockFlow());
195 if (Data().is_bidi_enabled_) 195 SegmentText();
196 SegmentText();
197 ShapeText(); 196 ShapeText();
198 } 197 }
199 198
200 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this 199 // Depth-first-scan of all LayoutInline and LayoutText nodes that make up this
201 // NGInlineNode object. Collects LayoutText items, merging them up into the 200 // NGInlineNode object. Collects LayoutText items, merging them up into the
202 // parent LayoutInline where possible, and joining all text content in a single 201 // parent LayoutInline where possible, and joining all text content in a single
203 // string to allow bidi resolution and shaping of the entire block. 202 // string to allow bidi resolution and shaping of the entire block.
204 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutBlockFlow* block) { 203 void NGInlineNode::CollectInlines(LayoutObject* start, LayoutBlockFlow* block) {
205 DCHECK(Data().text_content_.IsNull()); 204 DCHECK(Data().text_content_.IsNull());
206 DCHECK(Data().items_.IsEmpty()); 205 DCHECK(Data().items_.IsEmpty());
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 return nullptr; 274 return nullptr;
276 DCHECK(node->IsInline()); 275 DCHECK(node->IsInline());
277 builder->ExitInline(node); 276 builder->ExitInline(node);
278 node->ClearNeedsLayout(); 277 node->ClearNeedsLayout();
279 } 278 }
280 } 279 }
281 return nullptr; 280 return nullptr;
282 } 281 }
283 282
284 void NGInlineNode::SegmentText() { 283 void NGInlineNode::SegmentText() {
285 // TODO(kojii): Move this to caller, this will be used again after line break. 284 NGInlineNodeData& data = MutableData();
286 NGBidiParagraph bidi; 285 if (!data.is_bidi_enabled_) {
287 MutableData().text_content_.Ensure16Bit(); 286 data.SetBaseDirection(TextDirection::kLtr);
288 if (!bidi.SetParagraph(Data().text_content_, Style())) {
289 // On failure, give up bidi resolving and reordering.
290 MutableData().is_bidi_enabled_ = false;
291 return;
292 }
293 if (bidi.Direction() == UBIDI_LTR) {
294 // All runs are LTR, no need to reorder.
295 MutableData().is_bidi_enabled_ = false;
296 return; 287 return;
297 } 288 }
298 289
299 Vector<NGInlineItem>& items = MutableData().items_; 290 NGBidiParagraph bidi;
291 data.text_content_.Ensure16Bit();
292 if (!bidi.SetParagraph(data.text_content_, Style())) {
293 // On failure, give up bidi resolving and reordering.
294 data.is_bidi_enabled_ = false;
295 data.SetBaseDirection(TextDirection::kLtr);
296 return;
297 }
298
299 data.SetBaseDirection(bidi.BaseDirection());
300
301 if (bidi.IsUnidirectional() && IsLtr(bidi.BaseDirection())) {
302 // All runs are LTR, no need to reorder.
303 data.is_bidi_enabled_ = false;
304 return;
305 }
306
307 Vector<NGInlineItem>& items = data.items_;
300 unsigned item_index = 0; 308 unsigned item_index = 0;
301 for (unsigned start = 0; start < Data().text_content_.length();) { 309 for (unsigned start = 0; start < Data().text_content_.length();) {
302 UBiDiLevel level; 310 UBiDiLevel level;
303 unsigned end = bidi.GetLogicalRun(start, &level); 311 unsigned end = bidi.GetLogicalRun(start, &level);
304 DCHECK_EQ(items[item_index].start_offset_, start); 312 DCHECK_EQ(items[item_index].start_offset_, start);
305 item_index = NGInlineItem::SetBidiLevel(items, item_index, end, level); 313 item_index = NGInlineItem::SetBidiLevel(items, item_index, end, level);
306 start = end; 314 start = end;
307 } 315 }
308 DCHECK_EQ(item_index, items.size()); 316 DCHECK_EQ(item_index, items.size());
309 } 317 }
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 item.Style() == item.GetLayoutObject()->Style()); 526 item.Style() == item.GetLayoutObject()->Style());
519 } 527 }
520 #endif 528 #endif
521 } 529 }
522 530
523 String NGInlineNode::ToString() const { 531 String NGInlineNode::ToString() const {
524 return String::Format("NGInlineNode"); 532 return String::Format("NGInlineNode");
525 } 533 }
526 534
527 } // namespace blink 535 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698