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

Side by Side Diff: third_party/WebKit/Source/core/style/ComputedStyle.cpp

Issue 2830573002: Use generated getters/setters in ComputedStyle instead of directly accessing fields (Closed)
Patch Set: Make all generated fields private 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
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.h ('k') | 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) 1999 Antti Koivisto (koivisto@kde.org) 2 * Copyright (C) 1999 Antti Koivisto (koivisto@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights 3 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
4 * reserved. 4 * reserved.
5 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. 5 * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved.
6 * 6 *
7 * This library is free software; you can redistribute it and/or 7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public 8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either 9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version. 10 * version 2 of the License, or (at your option) any later version.
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after
338 background_ = other.background_; 338 background_ = other.background_;
339 surround_ = other.surround_; 339 surround_ = other.surround_;
340 rare_non_inherited_data_ = other.rare_non_inherited_data_; 340 rare_non_inherited_data_ = other.rare_non_inherited_data_;
341 341
342 // The flags are copied one-by-one because they contain 342 // The flags are copied one-by-one because they contain
343 // bunch of stuff other than real style data. 343 // bunch of stuff other than real style data.
344 // See comments for each skipped flag below. 344 // See comments for each skipped flag below.
345 345
346 // These are not generated in ComputedStyleBase 346 // These are not generated in ComputedStyleBase
347 SetOriginalDisplay(other.OriginalDisplay()); 347 SetOriginalDisplay(other.OriginalDisplay());
348 SetVerticalAlign(other.VerticalAlign()); 348 SetVerticalAlignInternal(other.VerticalAlignInternal());
shend 2017/04/19 06:17:30 This is an interesting case. Both the previous and
nainar 2017/04/19 06:31:14 Replied in the next comment.Also done.
349 SetHasViewportUnits(other.HasViewportUnits()); 349 SetHasViewportUnits(other.HasViewportUnits());
350 has_rem_units_ = other.HasRemUnits(); 350 SetHasRemUnitsInternal(other.HasRemUnits());
351 351
352 // Correctly set during selector matching: 352 // Correctly set during selector matching:
353 // m_styleType 353 // m_styleType
354 // m_pseudoBits 354 // m_pseudoBits
355 355
356 // Set correctly while computing style for children: 356 // Set correctly while computing style for children:
357 // m_explicitInheritance 357 // m_explicitInheritance
358 358
359 // unique() styles are not cacheable. 359 // unique() styles are not cacheable.
360 DCHECK(!other.Unique()); 360 DCHECK(!other.Unique());
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 473
474 bool ComputedStyle::LoadingCustomFontsEqual(const ComputedStyle& other) const { 474 bool ComputedStyle::LoadingCustomFontsEqual(const ComputedStyle& other) const {
475 return GetFont().LoadingCustomFonts() == other.GetFont().LoadingCustomFonts(); 475 return GetFont().LoadingCustomFonts() == other.GetFont().LoadingCustomFonts();
476 } 476 }
477 477
478 bool ComputedStyle::NonInheritedEqual(const ComputedStyle& other) const { 478 bool ComputedStyle::NonInheritedEqual(const ComputedStyle& other) const {
479 // compare everything except the pseudoStyle pointer 479 // compare everything except the pseudoStyle pointer
480 return ComputedStyleBase::NonInheritedEqual(other) && 480 return ComputedStyleBase::NonInheritedEqual(other) &&
481 OriginalDisplay() == 481 OriginalDisplay() ==
482 other.OriginalDisplay() && // Not generated in ComputedStyleBase 482 other.OriginalDisplay() && // Not generated in ComputedStyleBase
483 VerticalAlign() == 483 VerticalAlignInternal() ==
484 other.VerticalAlign() && // Not generated in ComputedStyleBase 484 other.VerticalAlignInternal() && // Not generated in
485 // ComputedStyleBase
485 box_ == other.box_ && 486 box_ == other.box_ &&
486 visual_ == other.visual_ && background_ == other.background_ && 487 visual_ == other.visual_ && background_ == other.background_ &&
487 surround_ == other.surround_ && 488 surround_ == other.surround_ &&
488 rare_non_inherited_data_ == other.rare_non_inherited_data_ && 489 rare_non_inherited_data_ == other.rare_non_inherited_data_ &&
489 svg_style_->NonInheritedEqual(*other.svg_style_); 490 svg_style_->NonInheritedEqual(*other.svg_style_);
490 } 491 }
491 492
492 bool ComputedStyle::InheritedDataShared(const ComputedStyle& other) const { 493 bool ComputedStyle::InheritedDataShared(const ComputedStyle& other) const {
493 // This is a fast check that only looks if the data structures are shared. 494 // This is a fast check that only looks if the data structures are shared.
494 // TODO(sashab): Should ComputedStyleBase have an inheritedDataShared method? 495 // TODO(sashab): Should ComputedStyleBase have an inheritedDataShared method?
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 bool ComputedStyle::DiffNeedsFullLayout(const ComputedStyle& other) const { 844 bool ComputedStyle::DiffNeedsFullLayout(const ComputedStyle& other) const {
844 if (box_.Get() != other.box_.Get()) { 845 if (box_.Get() != other.box_.Get()) {
845 if (box_->Width() != other.box_->Width() || 846 if (box_->Width() != other.box_->Width() ||
846 box_->MinWidth() != other.box_->MinWidth() || 847 box_->MinWidth() != other.box_->MinWidth() ||
847 box_->MaxWidth() != other.box_->MaxWidth() || 848 box_->MaxWidth() != other.box_->MaxWidth() ||
848 box_->Height() != other.box_->Height() || 849 box_->Height() != other.box_->Height() ||
849 box_->MinHeight() != other.box_->MinHeight() || 850 box_->MinHeight() != other.box_->MinHeight() ||
850 box_->MaxHeight() != other.box_->MaxHeight()) 851 box_->MaxHeight() != other.box_->MaxHeight())
851 return true; 852 return true;
852 853
853 if (box_->VerticalAlign() != other.box_->VerticalAlign()) 854 if (box_->vertical_align_ != other.box_->vertical_align_)
854 return true; 855 return true;
855 856
856 if (box_->BoxSizing() != other.box_->BoxSizing()) 857 if (box_->BoxSizing() != other.box_->BoxSizing())
857 return true; 858 return true;
858 } 859 }
859 860
860 if (VerticalAlign() != other.VerticalAlign() || 861 if (VerticalAlignInternal() != other.VerticalAlignInternal() ||
861 GetPosition() != other.GetPosition()) 862 GetPosition() != other.GetPosition())
862 return true; 863 return true;
863 864
864 if (rare_non_inherited_data_.Get() != other.rare_non_inherited_data_.Get()) { 865 if (rare_non_inherited_data_.Get() != other.rare_non_inherited_data_.Get()) {
865 if (rare_non_inherited_data_->align_content_ != 866 if (rare_non_inherited_data_->align_content_ !=
866 other.rare_non_inherited_data_->align_content_ || 867 other.rare_non_inherited_data_->align_content_ ||
867 rare_non_inherited_data_->align_items_ != 868 rare_non_inherited_data_->align_items_ !=
868 other.rare_non_inherited_data_->align_items_ || 869 other.rare_non_inherited_data_->align_items_ ||
869 rare_non_inherited_data_->align_self_ != 870 rare_non_inherited_data_->align_self_ !=
870 other.rare_non_inherited_data_->align_self_ || 871 other.rare_non_inherited_data_->align_self_ ||
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1054 diff.SetNeedsRecomputeOverflow(); 1055 diff.SetNeedsRecomputeOverflow();
1055 } 1056 }
1056 1057
1057 if (!surround_->border_.VisualOverflowEqual(other.surround_->border_)) 1058 if (!surround_->border_.VisualOverflowEqual(other.surround_->border_))
1058 diff.SetNeedsRecomputeOverflow(); 1059 diff.SetNeedsRecomputeOverflow();
1059 1060
1060 if (!diff.NeedsFullPaintInvalidation()) { 1061 if (!diff.NeedsFullPaintInvalidation()) {
1061 if (style_inherited_data_->color != other.style_inherited_data_->color || 1062 if (style_inherited_data_->color != other.style_inherited_data_->color ||
1062 style_inherited_data_->visited_link_color != 1063 style_inherited_data_->visited_link_color !=
1063 other.style_inherited_data_->visited_link_color || 1064 other.style_inherited_data_->visited_link_color ||
1064 has_simple_underline_ != other.has_simple_underline_ || 1065 HasSimpleUnderlineInternal() != other.HasSimpleUnderlineInternal() ||
1065 visual_->text_decoration != other.visual_->text_decoration) { 1066 visual_->text_decoration != other.visual_->text_decoration) {
1066 diff.SetTextDecorationOrColorChanged(); 1067 diff.SetTextDecorationOrColorChanged();
1067 } else if (rare_non_inherited_data_.Get() != 1068 } else if (rare_non_inherited_data_.Get() !=
1068 other.rare_non_inherited_data_.Get() && 1069 other.rare_non_inherited_data_.Get() &&
1069 (rare_non_inherited_data_->text_decoration_style_ != 1070 (rare_non_inherited_data_->text_decoration_style_ !=
1070 other.rare_non_inherited_data_->text_decoration_style_ || 1071 other.rare_non_inherited_data_->text_decoration_style_ ||
1071 rare_non_inherited_data_->text_decoration_color_ != 1072 rare_non_inherited_data_->text_decoration_color_ !=
1072 other.rare_non_inherited_data_->text_decoration_color_ || 1073 other.rare_non_inherited_data_->text_decoration_color_ ||
1073 rare_non_inherited_data_->visited_link_text_decoration_color_ != 1074 rare_non_inherited_data_->visited_link_text_decoration_color_ !=
1074 other.rare_non_inherited_data_ 1075 other.rare_non_inherited_data_
(...skipping 630 matching lines...) Expand 10 before | Expand all | Expand 10 after
1705 return GetFontDescription().HasSizeAdjust(); 1706 return GetFontDescription().HasSizeAdjust();
1706 } 1707 }
1707 FontWeight ComputedStyle::GetFontWeight() const { 1708 FontWeight ComputedStyle::GetFontWeight() const {
1708 return GetFontDescription().Weight(); 1709 return GetFontDescription().Weight();
1709 } 1710 }
1710 FontStretch ComputedStyle::GetFontStretch() const { 1711 FontStretch ComputedStyle::GetFontStretch() const {
1711 return GetFontDescription().Stretch(); 1712 return GetFontDescription().Stretch();
1712 } 1713 }
1713 1714
1714 TextDecoration ComputedStyle::TextDecorationsInEffect() const { 1715 TextDecoration ComputedStyle::TextDecorationsInEffect() const {
1715 if (has_simple_underline_) 1716 if (HasSimpleUnderlineInternal())
1716 return kTextDecorationUnderline; 1717 return kTextDecorationUnderline;
1717 if (!rare_inherited_data_->applied_text_decorations) 1718 if (!rare_inherited_data_->applied_text_decorations)
1718 return kTextDecorationNone; 1719 return kTextDecorationNone;
1719 1720
1720 int decorations = 0; 1721 int decorations = 0;
1721 1722
1722 const Vector<AppliedTextDecoration>& applied = AppliedTextDecorations(); 1723 const Vector<AppliedTextDecoration>& applied = AppliedTextDecorations();
1723 1724
1724 for (size_t i = 0; i < applied.size(); ++i) 1725 for (size_t i = 0; i < applied.size(); ++i)
1725 decorations |= applied[i].Lines(); 1726 decorations |= applied[i].Lines();
1726 1727
1727 return static_cast<TextDecoration>(decorations); 1728 return static_cast<TextDecoration>(decorations);
1728 } 1729 }
1729 1730
1730 const Vector<AppliedTextDecoration>& ComputedStyle::AppliedTextDecorations() 1731 const Vector<AppliedTextDecoration>& ComputedStyle::AppliedTextDecorations()
1731 const { 1732 const {
1732 if (has_simple_underline_) { 1733 if (HasSimpleUnderlineInternal()) {
1733 DEFINE_STATIC_LOCAL( 1734 DEFINE_STATIC_LOCAL(
1734 Vector<AppliedTextDecoration>, underline, 1735 Vector<AppliedTextDecoration>, underline,
1735 (1, AppliedTextDecoration( 1736 (1, AppliedTextDecoration(
1736 kTextDecorationUnderline, kTextDecorationStyleSolid, 1737 kTextDecorationUnderline, kTextDecorationStyleSolid,
1737 VisitedDependentColor(CSSPropertyTextDecorationColor)))); 1738 VisitedDependentColor(CSSPropertyTextDecorationColor))));
1738 // Since we only have one of these in memory, just update the color before 1739 // Since we only have one of these in memory, just update the color before
1739 // returning. 1740 // returning.
1740 underline.at(0).SetColor( 1741 underline.at(0).SetColor(
1741 VisitedDependentColor(CSSPropertyTextDecorationColor)); 1742 VisitedDependentColor(CSSPropertyTextDecorationColor));
1742 return underline; 1743 return underline;
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
2009 if (!list->HasOneRef()) 2010 if (!list->HasOneRef())
2010 list = list->Copy(); 2011 list = list->Copy();
2011 2012
2012 for (size_t i = 0; i < list->size(); ++i) 2013 for (size_t i = 0; i < list->size(); ++i)
2013 list->at(i).SetColor(override_color); 2014 list->at(i).SetColor(override_color);
2014 } 2015 }
2015 2016
2016 void ComputedStyle::ApplyTextDecorations( 2017 void ComputedStyle::ApplyTextDecorations(
2017 const Color& parent_text_decoration_color, 2018 const Color& parent_text_decoration_color,
2018 bool override_existing_colors) { 2019 bool override_existing_colors) {
2019 if (GetTextDecoration() == kTextDecorationNone && !has_simple_underline_ && 2020 if (GetTextDecoration() == kTextDecorationNone &&
2021 !HasSimpleUnderlineInternal() &&
2020 !rare_inherited_data_->applied_text_decorations) 2022 !rare_inherited_data_->applied_text_decorations)
2021 return; 2023 return;
2022 2024
2023 // If there are any color changes or decorations set by this element, stop 2025 // If there are any color changes or decorations set by this element, stop
2024 // using m_hasSimpleUnderline. 2026 // using m_hasSimpleUnderlineInternal.
2025 Color current_text_decoration_color = 2027 Color current_text_decoration_color =
2026 VisitedDependentColor(CSSPropertyTextDecorationColor); 2028 VisitedDependentColor(CSSPropertyTextDecorationColor);
2027 if (has_simple_underline_ && 2029 if (HasSimpleUnderlineInternal() &&
2028 (GetTextDecoration() != kTextDecorationNone || 2030 (GetTextDecoration() != kTextDecorationNone ||
2029 current_text_decoration_color != parent_text_decoration_color)) { 2031 current_text_decoration_color != parent_text_decoration_color)) {
2030 has_simple_underline_ = false; 2032 SetHasSimpleUnderlineInternal(false);
2031 AddAppliedTextDecoration(AppliedTextDecoration( 2033 AddAppliedTextDecoration(AppliedTextDecoration(
2032 kTextDecorationUnderline, kTextDecorationStyleSolid, 2034 kTextDecorationUnderline, kTextDecorationStyleSolid,
2033 parent_text_decoration_color)); 2035 parent_text_decoration_color));
2034 } 2036 }
2035 if (override_existing_colors && 2037 if (override_existing_colors &&
2036 rare_inherited_data_->applied_text_decorations) 2038 rare_inherited_data_->applied_text_decorations)
2037 OverrideTextDecorationColors(current_text_decoration_color); 2039 OverrideTextDecorationColors(current_text_decoration_color);
2038 if (GetTextDecoration() == kTextDecorationNone) 2040 if (GetTextDecoration() == kTextDecorationNone)
2039 return; 2041 return;
2040 DCHECK(!has_simple_underline_); 2042 DCHECK(!HasSimpleUnderlineInternal());
2041 // To save memory, we don't use AppliedTextDecoration objects in the common 2043 // To save memory, we don't use AppliedTextDecoration objects in the common
2042 // case of a single simple underline of currentColor. 2044 // case of a single simple underline of currentColor.
2043 TextDecoration decoration_lines = GetTextDecoration(); 2045 TextDecoration decoration_lines = GetTextDecoration();
2044 TextDecorationStyle decoration_style = GetTextDecorationStyle(); 2046 TextDecorationStyle decoration_style = GetTextDecorationStyle();
2045 bool is_simple_underline = decoration_lines == kTextDecorationUnderline && 2047 bool is_simple_underline = decoration_lines == kTextDecorationUnderline &&
2046 decoration_style == kTextDecorationStyleSolid && 2048 decoration_style == kTextDecorationStyleSolid &&
2047 TextDecorationColor().IsCurrentColor(); 2049 TextDecorationColor().IsCurrentColor();
2048 if (is_simple_underline && !rare_inherited_data_->applied_text_decorations) { 2050 if (is_simple_underline && !rare_inherited_data_->applied_text_decorations) {
2049 has_simple_underline_ = true; 2051 SetHasSimpleUnderlineInternal(true);
2050 return; 2052 return;
2051 } 2053 }
2052 2054
2053 AddAppliedTextDecoration(AppliedTextDecoration( 2055 AddAppliedTextDecoration(AppliedTextDecoration(
2054 decoration_lines, decoration_style, current_text_decoration_color)); 2056 decoration_lines, decoration_style, current_text_decoration_color));
2055 } 2057 }
2056 2058
2057 void ComputedStyle::ClearAppliedTextDecorations() { 2059 void ComputedStyle::ClearAppliedTextDecorations() {
2058 has_simple_underline_ = false; 2060 SetHasSimpleUnderlineInternal(false);
2059 2061
2060 if (rare_inherited_data_->applied_text_decorations) 2062 if (rare_inherited_data_->applied_text_decorations)
2061 rare_inherited_data_.Access()->applied_text_decorations = nullptr; 2063 rare_inherited_data_.Access()->applied_text_decorations = nullptr;
2062 } 2064 }
2063 2065
2064 void ComputedStyle::RestoreParentTextDecorations( 2066 void ComputedStyle::RestoreParentTextDecorations(
2065 const ComputedStyle& parent_style) { 2067 const ComputedStyle& parent_style) {
2066 has_simple_underline_ = parent_style.has_simple_underline_; 2068 SetHasSimpleUnderlineInternal(parent_style.HasSimpleUnderlineInternal());
2067 if (rare_inherited_data_->applied_text_decorations != 2069 if (rare_inherited_data_->applied_text_decorations !=
2068 parent_style.rare_inherited_data_->applied_text_decorations) 2070 parent_style.rare_inherited_data_->applied_text_decorations)
2069 rare_inherited_data_.Access()->applied_text_decorations = 2071 rare_inherited_data_.Access()->applied_text_decorations =
2070 parent_style.rare_inherited_data_->applied_text_decorations; 2072 parent_style.rare_inherited_data_->applied_text_decorations;
2071 } 2073 }
2072 2074
2073 void ComputedStyle::ClearMultiCol() { 2075 void ComputedStyle::ClearMultiCol() {
2074 rare_non_inherited_data_.Access()->multi_col_ = nullptr; 2076 rare_non_inherited_data_.Access()->multi_col_ = nullptr;
2075 rare_non_inherited_data_.Access()->multi_col_.Init(); 2077 rare_non_inherited_data_.Access()->multi_col_.Init();
2076 } 2078 }
(...skipping 379 matching lines...) Expand 10 before | Expand all | Expand 10 after
2456 edges[kBSBottom] = BorderEdge( 2458 edges[kBSBottom] = BorderEdge(
2457 BorderBottomWidth(), VisitedDependentColor(CSSPropertyBorderBottomColor), 2459 BorderBottomWidth(), VisitedDependentColor(CSSPropertyBorderBottomColor),
2458 BorderBottomStyle(), horizontal || include_logical_right_edge); 2460 BorderBottomStyle(), horizontal || include_logical_right_edge);
2459 2461
2460 edges[kBSLeft] = BorderEdge( 2462 edges[kBSLeft] = BorderEdge(
2461 BorderLeftWidth(), VisitedDependentColor(CSSPropertyBorderLeftColor), 2463 BorderLeftWidth(), VisitedDependentColor(CSSPropertyBorderLeftColor),
2462 BorderLeftStyle(), !horizontal || include_logical_left_edge); 2464 BorderLeftStyle(), !horizontal || include_logical_left_edge);
2463 } 2465 }
2464 2466
2465 void ComputedStyle::CopyChildDependentFlagsFrom(const ComputedStyle& other) { 2467 void ComputedStyle::CopyChildDependentFlagsFrom(const ComputedStyle& other) {
2466 SetEmptyState(other.EmptyState()); 2468 SetEmptyStateInternal(other.EmptyStateInternal());
shend 2017/04/19 06:17:30 Here is the problem with using internal getters. I
nainar 2017/04/19 06:31:14 Yup, I see what you mean. Using public getters is
2467 if (other.HasExplicitlyInheritedProperties()) 2469 if (other.HasExplicitlyInheritedProperties())
2468 SetHasExplicitlyInheritedProperties(); 2470 SetHasExplicitlyInheritedProperties();
2469 } 2471 }
2470 2472
2471 bool ComputedStyle::ShadowListHasCurrentColor(const ShadowList* shadow_list) { 2473 bool ComputedStyle::ShadowListHasCurrentColor(const ShadowList* shadow_list) {
2472 if (!shadow_list) 2474 if (!shadow_list)
2473 return false; 2475 return false;
2474 for (size_t i = shadow_list->Shadows().size(); i--;) { 2476 for (size_t i = shadow_list->Shadows().size(); i--;) {
2475 if (shadow_list->Shadows()[i].GetColor().IsCurrentColor()) 2477 if (shadow_list->Shadows()[i].GetColor().IsCurrentColor())
2476 return true; 2478 return true;
(...skipping 26 matching lines...) Expand all
2503 if (value < 0) 2505 if (value < 0)
2504 fvalue -= 0.5f; 2506 fvalue -= 0.5f;
2505 else 2507 else
2506 fvalue += 0.5f; 2508 fvalue += 0.5f;
2507 } 2509 }
2508 2510
2509 return RoundForImpreciseConversion<int>(fvalue / zoom_factor); 2511 return RoundForImpreciseConversion<int>(fvalue / zoom_factor);
2510 } 2512 }
2511 2513
2512 } // namespace blink 2514 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/style/ComputedStyle.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698