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

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

Issue 2687243002: Rename the methods in EditingStyleUtilities class and make them used in editing (Closed)
Patch Set: Created 3 years, 10 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 | third_party/WebKit/Source/core/editing/EditingStyleUtilities.h » ('j') | 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) 2007, 2008, 2009 Apple Computer, Inc. 2 * Copyright (C) 2007, 2008, 2009 Apple Computer, Inc.
3 * Copyright (C) 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2010, 2011 Google Inc. All rights 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 30 matching lines...) Expand all
41 #include "core/css/StylePropertySet.h" 41 #include "core/css/StylePropertySet.h"
42 #include "core/css/StyleRule.h" 42 #include "core/css/StyleRule.h"
43 #include "core/css/parser/CSSParser.h" 43 #include "core/css/parser/CSSParser.h"
44 #include "core/css/resolver/StyleResolver.h" 44 #include "core/css/resolver/StyleResolver.h"
45 #include "core/dom/Document.h" 45 #include "core/dom/Document.h"
46 #include "core/dom/Element.h" 46 #include "core/dom/Element.h"
47 #include "core/dom/Node.h" 47 #include "core/dom/Node.h"
48 #include "core/dom/NodeComputedStyle.h" 48 #include "core/dom/NodeComputedStyle.h"
49 #include "core/dom/NodeTraversal.h" 49 #include "core/dom/NodeTraversal.h"
50 #include "core/dom/QualifiedName.h" 50 #include "core/dom/QualifiedName.h"
51 #include "core/editing/EditingStyleUtilities.h"
51 #include "core/editing/EditingUtilities.h" 52 #include "core/editing/EditingUtilities.h"
52 #include "core/editing/Editor.h" 53 #include "core/editing/Editor.h"
53 #include "core/editing/FrameSelection.h" 54 #include "core/editing/FrameSelection.h"
54 #include "core/editing/Position.h" 55 #include "core/editing/Position.h"
55 #include "core/editing/commands/ApplyStyleCommand.h" 56 #include "core/editing/commands/ApplyStyleCommand.h"
56 #include "core/editing/serializers/HTMLInterchange.h" 57 #include "core/editing/serializers/HTMLInterchange.h"
57 #include "core/frame/LocalFrame.h" 58 #include "core/frame/LocalFrame.h"
58 #include "core/html/HTMLFontElement.h" 59 #include "core/html/HTMLFontElement.h"
59 #include "core/html/HTMLSpanElement.h" 60 #include "core/html/HTMLSpanElement.h"
60 #include "core/layout/LayoutBox.h" 61 #include "core/layout/LayoutBox.h"
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 return cssValueToColor( 427 return cssValueToColor(
427 style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor)); 428 style->getPropertyCSSValueInternal(CSSPropertyBackgroundColor));
428 } 429 }
429 430
430 static inline Color getBackgroundColor(StylePropertySet* style) { 431 static inline Color getBackgroundColor(StylePropertySet* style) {
431 return cssValueToColor( 432 return cssValueToColor(
432 style->getPropertyCSSValue(CSSPropertyBackgroundColor)); 433 style->getPropertyCSSValue(CSSPropertyBackgroundColor));
433 } 434 }
434 435
435 static inline Color backgroundColorInEffect(Node* node) { 436 static inline Color backgroundColorInEffect(Node* node) {
436 return cssValueToColor(backgroundColorValueInEffect(node)); 437 return cssValueToColor(
438 EditingStyleUtilities::backgroundColorValueInEffect(node));
437 } 439 }
438 440
439 static int textAlignResolvingStartAndEnd(int textAlign, int direction) { 441 static int textAlignResolvingStartAndEnd(int textAlign, int direction) {
440 switch (textAlign) { 442 switch (textAlign) {
441 case CSSValueCenter: 443 case CSSValueCenter:
442 case CSSValueWebkitCenter: 444 case CSSValueWebkitCenter:
443 return CSSValueCenter; 445 return CSSValueCenter;
444 case CSSValueJustify: 446 case CSSValueJustify:
445 return CSSValueJustify; 447 return CSSValueJustify;
446 case CSSValueLeft: 448 case CSSValueLeft:
(...skipping 24 matching lines...) Expand all
471 node = node->parentNode(); 473 node = node->parentNode();
472 474
473 CSSComputedStyleDeclaration* computedStyleAtPosition = 475 CSSComputedStyleDeclaration* computedStyleAtPosition =
474 CSSComputedStyleDeclaration::create(node); 476 CSSComputedStyleDeclaration::create(node);
475 m_mutableStyle = 477 m_mutableStyle =
476 propertiesToInclude == AllProperties && computedStyleAtPosition 478 propertiesToInclude == AllProperties && computedStyleAtPosition
477 ? computedStyleAtPosition->copyProperties() 479 ? computedStyleAtPosition->copyProperties()
478 : editingStyleFromComputedStyle(computedStyleAtPosition); 480 : editingStyleFromComputedStyle(computedStyleAtPosition);
479 481
480 if (propertiesToInclude == EditingPropertiesInEffect) { 482 if (propertiesToInclude == EditingPropertiesInEffect) {
481 if (const CSSValue* value = backgroundColorValueInEffect(node)) 483 if (const CSSValue* value =
484 EditingStyleUtilities::backgroundColorValueInEffect(node))
482 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssText()); 485 m_mutableStyle->setProperty(CSSPropertyBackgroundColor, value->cssText());
483 if (const CSSValue* value = computedStyleAtPosition->getPropertyCSSValue( 486 if (const CSSValue* value = computedStyleAtPosition->getPropertyCSSValue(
484 CSSPropertyWebkitTextDecorationsInEffect)) 487 CSSPropertyWebkitTextDecorationsInEffect))
485 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssText()); 488 m_mutableStyle->setProperty(CSSPropertyTextDecoration, value->cssText());
486 } 489 }
487 490
488 if (node && node->ensureComputedStyle()) { 491 if (node && node->ensureComputedStyle()) {
489 const ComputedStyle* computedStyle = node->ensureComputedStyle(); 492 const ComputedStyle* computedStyle = node->ensureComputedStyle();
490 removeInheritedColorsIfNeeded(computedStyle); 493 removeInheritedColorsIfNeeded(computedStyle);
491 replaceFontSizeByKeywordIfPossible(computedStyle, computedStyleAtPosition); 494 replaceFontSizeByKeywordIfPossible(computedStyle, computedStyleAtPosition);
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 bool EditingStyle::textDirection(WritingDirection& writingDirection) const { 567 bool EditingStyle::textDirection(WritingDirection& writingDirection) const {
565 if (!m_mutableStyle) 568 if (!m_mutableStyle)
566 return false; 569 return false;
567 570
568 const CSSValue* unicodeBidi = 571 const CSSValue* unicodeBidi =
569 m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); 572 m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi);
570 if (!unicodeBidi || !unicodeBidi->isIdentifierValue()) 573 if (!unicodeBidi || !unicodeBidi->isIdentifierValue())
571 return false; 574 return false;
572 575
573 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->getValueID(); 576 CSSValueID unicodeBidiValue = toCSSIdentifierValue(unicodeBidi)->getValueID();
574 if (isEmbedOrIsolate(unicodeBidiValue)) { 577 if (EditingStyleUtilities::isEmbedOrIsolate(unicodeBidiValue)) {
575 const CSSValue* direction = 578 const CSSValue* direction =
576 m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); 579 m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection);
577 if (!direction || !direction->isIdentifierValue()) 580 if (!direction || !direction->isIdentifierValue())
578 return false; 581 return false;
579 582
580 writingDirection = 583 writingDirection =
581 toCSSIdentifierValue(direction)->getValueID() == CSSValueLtr 584 toCSSIdentifierValue(direction)->getValueID() == CSSValueLtr
582 ? LeftToRightWritingDirection 585 ? LeftToRightWritingDirection
583 : RightToLeftWritingDirection; 586 : RightToLeftWritingDirection;
584 587
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 return true; 785 return true;
783 } 786 }
784 return false; 787 return false;
785 } 788 }
786 789
787 TriState EditingStyle::triStateOfStyle( 790 TriState EditingStyle::triStateOfStyle(
788 const VisibleSelection& selection) const { 791 const VisibleSelection& selection) const {
789 if (selection.isNone()) 792 if (selection.isNone())
790 return FalseTriState; 793 return FalseTriState;
791 794
792 if (selection.isCaret()) 795 if (selection.isCaret()) {
793 return triStateOfStyle(EditingStyle::styleAtSelectionStart(selection)); 796 return triStateOfStyle(
797 EditingStyleUtilities::createStyleAtSelectionStart(selection));
798 }
794 799
795 TriState state = FalseTriState; 800 TriState state = FalseTriState;
796 bool nodeIsStart = true; 801 bool nodeIsStart = true;
797 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) { 802 for (Node& node : NodeTraversal::startsAt(*selection.start().anchorNode())) {
798 if (node.layoutObject() && hasEditableStyle(node)) { 803 if (node.layoutObject() && hasEditableStyle(node)) {
799 CSSComputedStyleDeclaration* nodeStyle = 804 CSSComputedStyleDeclaration* nodeStyle =
800 CSSComputedStyleDeclaration::create(&node); 805 CSSComputedStyleDeclaration::create(&node);
801 if (nodeStyle) { 806 if (nodeStyle) {
802 // If the selected element has <sub> or <sup> ancestor element, apply 807 // If the selected element has <sub> or <sup> ancestor element, apply
803 // the corresponding style(vertical-align) to it so that 808 // the corresponding style(vertical-align) to it so that
804 // document.queryCommandState() works with the style. See bug 809 // document.queryCommandState() works with the style. See bug
805 // http://crbug.com/582225. 810 // http://crbug.com/582225.
806 if (m_isVerticalAlign && 811 if (m_isVerticalAlign &&
807 getIdentifierValue(nodeStyle, CSSPropertyVerticalAlign) == 812 getIdentifierValue(nodeStyle, CSSPropertyVerticalAlign) ==
808 CSSValueBaseline) { 813 CSSValueBaseline) {
809 const CSSIdentifierValue* verticalAlign = toCSSIdentifierValue( 814 const CSSIdentifierValue* verticalAlign = toCSSIdentifierValue(
810 m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign)); 815 m_mutableStyle->getPropertyCSSValue(CSSPropertyVerticalAlign));
811 if (hasAncestorVerticalAlignStyle(node, verticalAlign->getValueID())) 816 if (EditingStyleUtilities::hasAncestorVerticalAlignStyle(
817 node, verticalAlign->getValueID()))
812 node.mutableComputedStyle()->setVerticalAlign( 818 node.mutableComputedStyle()->setVerticalAlign(
813 verticalAlign->convertTo<EVerticalAlign>()); 819 verticalAlign->convertTo<EVerticalAlign>());
814 } 820 }
815 821
816 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without checking if 822 // Pass EditingStyle::DoNotIgnoreTextOnlyProperties without checking if
817 // node.isTextNode() because the node can be an element node. See bug 823 // node.isTextNode() because the node can be an element node. See bug
818 // http://crbug.com/584939. 824 // http://crbug.com/584939.
819 TriState nodeState = triStateOfStyle( 825 TriState nodeState = triStateOfStyle(
820 nodeStyle, EditingStyle::DoNotIgnoreTextOnlyProperties); 826 nodeStyle, EditingStyle::DoNotIgnoreTextOnlyProperties);
821 if (nodeIsStart) { 827 if (nodeIsStart) {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
1124 1130
1125 m_mutableStyle->removeEquivalentProperties(styleAtPosition); 1131 m_mutableStyle->removeEquivalentProperties(styleAtPosition);
1126 1132
1127 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) == 1133 if (textAlignResolvingStartAndEnd(m_mutableStyle.get()) ==
1128 textAlignResolvingStartAndEnd(styleAtPosition)) 1134 textAlignResolvingStartAndEnd(styleAtPosition))
1129 m_mutableStyle->removeProperty(CSSPropertyTextAlign); 1135 m_mutableStyle->removeProperty(CSSPropertyTextAlign);
1130 1136
1131 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition)) 1137 if (getFontColor(m_mutableStyle.get()) == getFontColor(styleAtPosition))
1132 m_mutableStyle->removeProperty(CSSPropertyColor); 1138 m_mutableStyle->removeProperty(CSSPropertyColor);
1133 1139
1134 if (hasTransparentBackgroundColor(m_mutableStyle.get()) || 1140 if (EditingStyleUtilities::hasTransparentBackgroundColor(
1141 m_mutableStyle.get()) ||
1135 cssValueToColor( 1142 cssValueToColor(
1136 m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor)) == 1143 m_mutableStyle->getPropertyCSSValue(CSSPropertyBackgroundColor)) ==
1137 backgroundColorInEffect(position.computeContainerNode())) 1144 backgroundColorInEffect(position.computeContainerNode()))
1138 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor); 1145 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor);
1139 1146
1140 if (unicodeBidi && unicodeBidi->isIdentifierValue()) { 1147 if (unicodeBidi && unicodeBidi->isIdentifierValue()) {
1141 m_mutableStyle->setProperty( 1148 m_mutableStyle->setProperty(
1142 CSSPropertyUnicodeBidi, 1149 CSSPropertyUnicodeBidi,
1143 toCSSIdentifierValue(unicodeBidi)->getValueID()); 1150 toCSSIdentifierValue(unicodeBidi)->getValueID());
1144 if (direction && direction->isIdentifierValue()) { 1151 if (direction && direction->isIdentifierValue()) {
(...skipping 895 matching lines...) Expand 10 before | Expand all | Expand 10 after
2040 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) { 2047 for (Node* ancestor = node; ancestor; ancestor = ancestor->parentNode()) {
2041 CSSComputedStyleDeclaration* ancestorStyle = 2048 CSSComputedStyleDeclaration* ancestorStyle =
2042 CSSComputedStyleDeclaration::create(ancestor); 2049 CSSComputedStyleDeclaration::create(ancestor);
2043 if (!hasTransparentBackgroundColor(ancestorStyle)) 2050 if (!hasTransparentBackgroundColor(ancestorStyle))
2044 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor); 2051 return ancestorStyle->getPropertyCSSValue(CSSPropertyBackgroundColor);
2045 } 2052 }
2046 return nullptr; 2053 return nullptr;
2047 } 2054 }
2048 2055
2049 } // namespace blink 2056 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/EditingStyleUtilities.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698