Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) | 3 * (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com) |
| 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) | 4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com) |
| 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. | 5 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved. |
| 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> | 6 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org> |
| 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> | 7 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org> |
| 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) | 8 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) |
| 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. | 9 * Copyright (c) 2011, Code Aurora Forum. All rights reserved. |
| 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. | 10 * Copyright (C) Research In Motion Limited 2011. All rights reserved. |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 236 style.setPosition(ComputedStyle::initialPosition()); | 236 style.setPosition(ComputedStyle::initialPosition()); |
| 237 | 237 |
| 238 // SVG text layout code expects us to be a block-level style element. | 238 // SVG text layout code expects us to be a block-level style element. |
| 239 if ((isSVGForeignObjectElement(*element) || isSVGTextElement(*element)) && style.isDisplayInlineType()) | 239 if ((isSVGForeignObjectElement(*element) || isSVGTextElement(*element)) && style.isDisplayInlineType()) |
| 240 style.setDisplay(BLOCK); | 240 style.setDisplay(BLOCK); |
| 241 | 241 |
| 242 // Columns don't apply to svg text elements. | 242 // Columns don't apply to svg text elements. |
| 243 if (isSVGTextElement(*element)) | 243 if (isSVGTextElement(*element)) |
| 244 style.clearMultiCol(); | 244 style.clearMultiCol(); |
| 245 } | 245 } |
| 246 adjustStyleForAlignment(style, parentStyle); | 246 if (element && element->layoutObject() && element->layoutObject()->containin gBlock()->isAnonymous()) |
| 247 adjustStyleForAlignment(style, element->layoutObject()->containingBlock( )->styleRef()); | |
| 248 else | |
| 249 adjustStyleForAlignment(style, parentStyle); | |
|
rune
2016/06/13 12:24:19
I still have a hard time understanding the spec he
jfernandez
2016/06/13 13:00:36
That's how I understand the spec, yes. An element'
| |
| 247 } | 250 } |
| 248 | 251 |
| 249 void StyleAdjuster::adjustStyleForEditing(ComputedStyle& style) | 252 void StyleAdjuster::adjustStyleForEditing(ComputedStyle& style) |
| 250 { | 253 { |
| 251 if (style.userModify() != READ_WRITE_PLAINTEXT_ONLY) | 254 if (style.userModify() != READ_WRITE_PLAINTEXT_ONLY) |
| 252 return; | 255 return; |
| 253 // Collapsing whitespace is harmful in plain-text editing. | 256 // Collapsing whitespace is harmful in plain-text editing. |
| 254 if (style.whiteSpace() == NORMAL) | 257 if (style.whiteSpace() == NORMAL) |
| 255 style.setWhiteSpace(PRE_WRAP); | 258 style.setWhiteSpace(PRE_WRAP); |
| 256 else if (style.whiteSpace() == NOWRAP) | 259 else if (style.whiteSpace() == NOWRAP) |
| 257 style.setWhiteSpace(PRE); | 260 style.setWhiteSpace(PRE); |
| 258 else if (style.whiteSpace() == PRE_LINE) | 261 else if (style.whiteSpace() == PRE_LINE) |
| 259 style.setWhiteSpace(PRE_WRAP); | 262 style.setWhiteSpace(PRE_WRAP); |
| 260 } | 263 } |
| 261 | 264 |
| 262 void StyleAdjuster::adjustStyleForFirstLetter(ComputedStyle& style) | 265 void StyleAdjuster::adjustStyleForFirstLetter(ComputedStyle& style) |
| 263 { | 266 { |
| 264 if (style.styleType() != PseudoIdFirstLetter) | 267 if (style.styleType() != PseudoIdFirstLetter) |
| 265 return; | 268 return; |
| 266 | 269 |
| 267 // Force inline display (except for floating first-letters). | 270 // Force inline display (except for floating first-letters). |
| 268 style.setDisplay(style.isFloating() ? BLOCK : INLINE); | 271 style.setDisplay(style.isFloating() ? BLOCK : INLINE); |
| 269 | 272 |
| 270 // CSS2 says first-letter can't be positioned. | 273 // CSS2 says first-letter can't be positioned. |
| 271 style.setPosition(StaticPosition); | 274 style.setPosition(StaticPosition); |
| 272 } | 275 } |
| 273 | 276 |
| 274 void StyleAdjuster::adjustStyleForAlignment(ComputedStyle& style, const Computed Style& parentStyle) | 277 void StyleAdjuster::adjustStyleForAlignment(ComputedStyle& style, const Computed Style& parentStyle) |
| 275 { | 278 { |
| 276 bool isFlexOrGrid = style.isDisplayFlexibleOrGridBox(); | 279 // To avoid needing to copy the RareNonInheritedData, we repurpose the 'auto ' flag |
| 277 bool absolutePositioned = style.position() == AbsolutePosition; | 280 // to not just mean 'auto' prior to running the StyleAdjuster but also mean 'normal' |
| 281 // after running it. | |
| 278 | 282 |
| 279 // If the inherited value of justify-items includes the legacy keyword, 'aut o' | 283 // If the inherited value of justify-items includes the 'legacy' keyword, 'a uto' |
| 280 // computes to the the inherited value. | 284 // computes to the the inherited value. |
| 281 // Otherwise, auto computes to: | 285 // Otherwise, 'auto' computes to 'normal'. |
| 282 // - 'stretch' for flex containers and grid containers. | |
| 283 // - 'start' for everything else. | |
| 284 if (style.justifyItemsPosition() == ItemPositionAuto) { | 286 if (style.justifyItemsPosition() == ItemPositionAuto) { |
| 285 if (parentStyle.justifyItemsPositionType() == LegacyPosition) | 287 if (parentStyle.justifyItemsPositionType() == LegacyPosition) |
| 286 style.setJustifyItems(parentStyle.justifyItems()); | 288 style.setJustifyItems(parentStyle.justifyItems()); |
| 287 else if (isFlexOrGrid) | |
| 288 style.setJustifyItemsPosition(ItemPositionStretch); | |
| 289 } | 289 } |
| 290 | 290 |
| 291 // The 'auto' keyword computes to 'stretch' on absolutely-positioned element s, | 291 // The 'auto' keyword computes the computed value of justify-items on the pa rent (minus |
| 292 // and to the computed value of justify-items on the parent (minus | 292 // any legacy keywords), or 'normal' if the box has no parent. |
| 293 // any legacy keywords) on all other boxes. | |
| 294 if (style.justifySelfPosition() == ItemPositionAuto) { | 293 if (style.justifySelfPosition() == ItemPositionAuto) { |
| 295 if (absolutePositioned) | 294 if (parentStyle.justifyItemsPositionType() == LegacyPosition) |
| 296 style.setJustifySelfPosition(ItemPositionStretch); | 295 style.setJustifySelfPosition(parentStyle.justifyItemsPosition()); |
| 297 else | 296 else if (parentStyle.justifyItemsPosition() != ItemPositionAuto) |
| 298 style.setJustifySelf(parentStyle.justifyItems()); | 297 style.setJustifySelf(parentStyle.justifyItems()); |
| 299 } | 298 } |
| 300 | 299 |
| 301 // The 'auto' keyword computes to: | 300 // The 'auto' keyword computes the computed value of align-items on the pare nt |
| 302 // - 'stretch' for flex containers and grid containers, | 301 // or 'normal' if the box has no parent. |
| 303 // - 'start' for everything else. | 302 if (style.alignSelfPosition() == ItemPositionAuto && parentStyle.alignItemsP osition() != ItemPositionNormal) |
| 304 if (style.alignItemsPosition() == ItemPositionAuto) { | 303 style.setAlignSelf(parentStyle.alignItems()); |
| 305 if (isFlexOrGrid) | |
| 306 style.setAlignItemsPosition(ItemPositionStretch); | |
| 307 } | |
| 308 } | 304 } |
| 309 | 305 |
| 310 void StyleAdjuster::adjustStyleForHTMLElement(ComputedStyle& style, const Comput edStyle& parentStyle, HTMLElement& element) | 306 void StyleAdjuster::adjustStyleForHTMLElement(ComputedStyle& style, const Comput edStyle& parentStyle, HTMLElement& element) |
| 311 { | 307 { |
| 312 // <div> and <span> are the most common elements on the web, we skip all the work for them. | 308 // <div> and <span> are the most common elements on the web, we skip all the work for them. |
| 313 if (isHTMLDivElement(element) || isHTMLSpanElement(element)) | 309 if (isHTMLDivElement(element) || isHTMLSpanElement(element)) |
| 314 return; | 310 return; |
| 315 | 311 |
| 316 if (isHTMLTableCellElement(element)) { | 312 if (isHTMLTableCellElement(element)) { |
| 317 if (style.whiteSpace() == KHTML_NOWRAP) { | 313 if (style.whiteSpace() == KHTML_NOWRAP) { |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 457 // We want to count vertical percentage paddings/margins on flex items b ecause our current | 453 // We want to count vertical percentage paddings/margins on flex items b ecause our current |
| 458 // behavior is different from the spec and we want to gather compatibili ty data. | 454 // behavior is different from the spec and we want to gather compatibili ty data. |
| 459 if (style.paddingBefore().hasPercent() || style.paddingAfter().hasPercen t()) | 455 if (style.paddingBefore().hasPercent() || style.paddingAfter().hasPercen t()) |
| 460 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVert ical); | 456 UseCounter::count(document, UseCounter::FlexboxPercentagePaddingVert ical); |
| 461 if (style.marginBefore().hasPercent() || style.marginAfter().hasPercent( )) | 457 if (style.marginBefore().hasPercent() || style.marginAfter().hasPercent( )) |
| 462 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVerti cal); | 458 UseCounter::count(document, UseCounter::FlexboxPercentageMarginVerti cal); |
| 463 } | 459 } |
| 464 } | 460 } |
| 465 | 461 |
| 466 } // namespace blink | 462 } // namespace blink |
| OLD | NEW |