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

Side by Side Diff: third_party/WebKit/Source/core/layout/TextAutosizer.cpp

Issue 2817443003: Fix font-size shaking issue in some pages (Closed)
Patch Set: layout test failed Created 3 years, 8 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) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 Google 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 are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * 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 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 } 219 }
220 220
221 static LayoutObject* GetParent(const LayoutObject* object) { 221 static LayoutObject* GetParent(const LayoutObject* object) {
222 LayoutObject* parent = nullptr; 222 LayoutObject* parent = nullptr;
223 // LayoutObject haven't added to layout tree yet 223 // LayoutObject haven't added to layout tree yet
224 if (object->GetNode() && object->GetNode()->parentNode()) 224 if (object->GetNode() && object->GetNode()->parentNode())
225 parent = object->GetNode()->parentNode()->GetLayoutObject(); 225 parent = object->GetNode()->parentNode()->GetLayoutObject();
226 return parent; 226 return parent;
227 } 227 }
228 228
229 static bool needMakeSelfAsWidthProvider(const LayoutBlock* block) {
230 return block->IsTable() || block->IsTableCell() || block->IsLayoutView();
231 }
232
229 TextAutosizer::TextAutosizer(const Document* document) 233 TextAutosizer::TextAutosizer(const Document* document)
230 : document_(document), 234 : document_(document),
231 first_block_to_begin_layout_(nullptr), 235 first_block_to_begin_layout_(nullptr),
232 #if DCHECK_IS_ON() 236 #if DCHECK_IS_ON()
233 blocks_that_have_begun_layout_(), 237 blocks_that_have_begun_layout_(),
234 #endif 238 #endif
235 cluster_stack_(), 239 cluster_stack_(),
236 fingerprint_mapper_(), 240 fingerprint_mapper_(),
237 page_info_(), 241 page_info_(),
238 update_page_info_deferred_(false) { 242 update_page_info_deferred_(false) {
(...skipping 665 matching lines...) Expand 10 before | Expand all | Expand 10 after
904 SuperclusterHasEnoughTextToAutosize(supercluster, width_provider, false) 908 SuperclusterHasEnoughTextToAutosize(supercluster, width_provider, false)
905 ? MultiplierFromBlock(width_provider) 909 ? MultiplierFromBlock(width_provider)
906 : 1.0f; 910 : 1.0f;
907 } 911 }
908 DCHECK(supercluster->multiplier_); 912 DCHECK(supercluster->multiplier_);
909 return supercluster->multiplier_; 913 return supercluster->multiplier_;
910 } 914 }
911 915
912 const LayoutBlock* TextAutosizer::ClusterWidthProvider( 916 const LayoutBlock* TextAutosizer::ClusterWidthProvider(
913 const LayoutBlock* root) const { 917 const LayoutBlock* root) const {
914 if (root->IsTable() || root->IsTableCell())
915 return root;
916
cathiechentx 2017/04/18 09:26:45 Conside of the inherit issuses. Move this check to
917 return DeepestBlockContainingAllText(root); 918 return DeepestBlockContainingAllText(root);
918 } 919 }
919 920
920 const LayoutBlock* TextAutosizer::MaxClusterWidthProvider( 921 const LayoutBlock* TextAutosizer::MaxClusterWidthProvider(
921 Supercluster* supercluster, 922 Supercluster* supercluster,
922 const LayoutBlock* current_root) const { 923 const LayoutBlock* current_root) const {
923 const LayoutBlock* result = nullptr; 924 const LayoutBlock* result = nullptr;
924 if (current_root) 925 if (current_root)
925 result = ClusterWidthProvider(current_root); 926 result = ClusterWidthProvider(current_root);
926 927
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1002 if (!cluster->deepest_block_containing_all_text_) 1003 if (!cluster->deepest_block_containing_all_text_)
1003 cluster->deepest_block_containing_all_text_ = 1004 cluster->deepest_block_containing_all_text_ =
1004 DeepestBlockContainingAllText(cluster->root_); 1005 DeepestBlockContainingAllText(cluster->root_);
1005 1006
1006 return cluster->deepest_block_containing_all_text_; 1007 return cluster->deepest_block_containing_all_text_;
1007 } 1008 }
1008 1009
1009 // FIXME: Refactor this to look more like TextAutosizer::deepestCommonAncestor. 1010 // FIXME: Refactor this to look more like TextAutosizer::deepestCommonAncestor.
1010 const LayoutBlock* TextAutosizer::DeepestBlockContainingAllText( 1011 const LayoutBlock* TextAutosizer::DeepestBlockContainingAllText(
1011 const LayoutBlock* root) const { 1012 const LayoutBlock* root) const {
1013 if (needMakeSelfAsWidthProvider(root))
1014 return root;
cathiechentx 2017/04/18 09:26:45 The special exceptions(table, td, html) check shou
1015
1012 size_t first_depth = 0; 1016 size_t first_depth = 0;
1013 const LayoutObject* first_text_leaf = FindTextLeaf(root, first_depth, kFirst); 1017 const LayoutObject* first_text_leaf = FindTextLeaf(root, first_depth, kFirst);
1014 if (!first_text_leaf) 1018 if (!first_text_leaf)
1015 return root; 1019 return root;
1016 1020
1017 size_t last_depth = 0; 1021 size_t last_depth = 0;
1018 const LayoutObject* last_text_leaf = FindTextLeaf(root, last_depth, kLast); 1022 const LayoutObject* last_text_leaf = FindTextLeaf(root, last_depth, kLast);
1019 DCHECK(last_text_leaf); 1023 DCHECK(last_text_leaf);
1020 1024
1021 // Equalize the depths if necessary. Only one of the while loops below will 1025 // Equalize the depths if necessary. Only one of the while loops below will
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
1142 layout_object->ClearBaseComputedStyle(); 1146 layout_object->ClearBaseComputedStyle();
1143 } 1147 }
1144 1148
1145 bool TextAutosizer::IsWiderOrNarrowerDescendant(Cluster* cluster) { 1149 bool TextAutosizer::IsWiderOrNarrowerDescendant(Cluster* cluster) {
1146 // FIXME: Why do we return true when hasExplicitWidth returns false?? 1150 // FIXME: Why do we return true when hasExplicitWidth returns false??
1147 if (!cluster->parent_ || !HasExplicitWidth(cluster->root_)) 1151 if (!cluster->parent_ || !HasExplicitWidth(cluster->root_))
1148 return true; 1152 return true;
1149 1153
1150 const LayoutBlock* parent_deepest_block_containing_all_text = 1154 const LayoutBlock* parent_deepest_block_containing_all_text =
1151 DeepestBlockContainingAllText(cluster->parent_); 1155 DeepestBlockContainingAllText(cluster->parent_);
1156 // Block that needMakeSelfAsWidthProvider shouldn't be inherited.
1157 if (needMakeSelfAsWidthProvider(parent_deepest_block_containing_all_text))
1158 return true;
cathiechentx 2017/04/18 09:26:45 These special exceptions(table, td, html) couldn't
1159
1152 #if DCHECK_IS_ON() 1160 #if DCHECK_IS_ON()
1153 DCHECK(blocks_that_have_begun_layout_.Contains(cluster->root_)); 1161 DCHECK(blocks_that_have_begun_layout_.Contains(cluster->root_));
1154 DCHECK(blocks_that_have_begun_layout_.Contains( 1162 DCHECK(blocks_that_have_begun_layout_.Contains(
1155 parent_deepest_block_containing_all_text)); 1163 parent_deepest_block_containing_all_text));
1156 #endif 1164 #endif
1157 1165
1158 float content_width = cluster->root_->ContentLogicalWidth().ToFloat(); 1166 float content_width = cluster->root_->ContentLogicalWidth().ToFloat();
1159 float cluster_text_width = 1167 float cluster_text_width =
1160 parent_deepest_block_containing_all_text->ContentLogicalWidth().ToFloat(); 1168 parent_deepest_block_containing_all_text->ContentLogicalWidth().ToFloat();
1161 1169
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
1387 } 1395 }
1388 } 1396 }
1389 potentially_inconsistent_superclusters.Clear(); 1397 potentially_inconsistent_superclusters.Clear();
1390 } 1398 }
1391 1399
1392 DEFINE_TRACE(TextAutosizer) { 1400 DEFINE_TRACE(TextAutosizer) {
1393 visitor->Trace(document_); 1401 visitor->Trace(document_);
1394 } 1402 }
1395 1403
1396 } // namespace blink 1404 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/layout/TextAutosizer.h ('k') | third_party/WebKit/Source/core/layout/TextAutosizerTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698