Skip to content

Commit

Permalink
Change the way we determine the style context parent frame to skip cs…
Browse files Browse the repository at this point in the history
…s anonboxes unless we're determining the style context parent for something that isitself a css anon box (and is not a non-element frame). Fixes bug 323656(which is where the patch is), bug 85872, bug 280610. As far as I can tell,also fixes bug 317876, bug 372376, bug 374297. r+sr=dbaron
  • Loading branch information
bzbarsky committed Apr 15, 2007
1 parent ba44c08 commit b82e527
Show file tree
Hide file tree
Showing 18 changed files with 584 additions and 50 deletions.
14 changes: 6 additions & 8 deletions layout/base/nsCSSFrameConstructor.cpp
Expand Up @@ -6654,17 +6654,12 @@ already_AddRefed<nsStyleContext>
nsCSSFrameConstructor::ResolveStyleContext(nsIFrame* aParentFrame,
nsIContent* aContent)
{
aParentFrame = nsFrame::CorrectStyleParentFrame(aParentFrame, nsnull);

// Resolve the style context based on the content object and the parent
// style context
nsStyleContext* parentStyleContext = aParentFrame->GetStyleContext();

// skip past any parents that are scrolled-content. We want to inherit directly
// from the outer scroll frame.
while (parentStyleContext && parentStyleContext->GetPseudoType() ==
nsCSSAnonBoxes::scrolledContent) {
parentStyleContext = parentStyleContext->GetParent();
}

nsStyleSet *styleSet = mPresShell->StyleSet();

if (aContent->IsNodeOfType(nsINode::eELEMENT)) {
Expand Down Expand Up @@ -11216,7 +11211,10 @@ nsCSSFrameConstructor::ProcessChildren(nsFrameConstructorState& aState,
// XXXbz ideally, this would do all the pushing of various
// containing blocks as needed, so callers don't have to do it...
nsresult rv = NS_OK;
nsStyleContext* styleContext = aFrame->GetStyleContext();
// :before/:after content should have the same style context parent
// as normal kids.
nsStyleContext* styleContext =
nsFrame::CorrectStyleParentFrame(aFrame, nsnull)->GetStyleContext();

if (aCanHaveGeneratedContent) {
// Probe for generated content before
Expand Down
4 changes: 4 additions & 0 deletions layout/generic/Makefile.in
Expand Up @@ -41,6 +41,10 @@ VPATH = @srcdir@

include $(DEPTH)/config/autoconf.mk

ifdef MOZ_MOCHITEST
DIRS += test
endif

MODULE = layout
LIBRARY_NAME = gkgeneric_s
LIBXUL_LIBRARY = 1
Expand Down
114 changes: 74 additions & 40 deletions layout/generic/nsFrame.cpp
Expand Up @@ -118,6 +118,7 @@
#include "nsWidgetsCID.h" // for NS_LOOKANDFEEL_CID
#include "nsUnicharUtils.h"
#include "nsLayoutErrors.h"
#include "nsContentErrors.h"
#include "nsHTMLContainerFrame.h"
#include "nsBoxLayoutState.h"
#include "nsBlockFrame.h"
Expand Down Expand Up @@ -5433,25 +5434,15 @@ GetIBSpecialSibling(nsPresContext* aPresContext,
aPresContext->PropertyTable()->GetProperty(aFrame,
nsGkAtoms::IBSplitSpecialPrevSibling, &rv));

if (NS_OK == rv) {
if (NS_PROPTABLE_PROP_NOT_THERE == rv) {
*aSpecialSibling = nsnull;
rv = NS_OK;
} else if (NS_SUCCEEDED(rv)) {
NS_ASSERTION(specialSibling, "null special sibling");
*aSpecialSibling = specialSibling;
}

return NS_OK;
}

static PRBool
IsTablePseudo(nsIAtom* aPseudo)
{
return
aPseudo == nsCSSAnonBoxes::tableOuter ||
aPseudo == nsCSSAnonBoxes::table ||
aPseudo == nsCSSAnonBoxes::tableRowGroup ||
aPseudo == nsCSSAnonBoxes::tableRow ||
aPseudo == nsCSSAnonBoxes::tableCell ||
aPseudo == nsCSSAnonBoxes::tableColGroup ||
aPseudo == nsCSSAnonBoxes::tableCol;
return rv;
}

/**
Expand All @@ -5469,35 +5460,71 @@ GetCorrectedParent(nsPresContext* aPresContext, nsIFrame* aFrame,
nsIFrame** aSpecialParent)
{
nsIFrame *parent = aFrame->GetParent();
*aSpecialParent = parent;
if (parent) {
nsIAtom* pseudo = aFrame->GetStyleContext()->GetPseudoType();

// if this frame itself is not scrolled-content, then skip any scrolled-content
// parents since they're basically anonymous as far as the style system goes
if (pseudo != nsCSSAnonBoxes::scrolledContent) {
while (parent->GetStyleContext()->GetPseudoType() ==
nsCSSAnonBoxes::scrolledContent) {
parent = parent->GetParent();
if (!parent) {
*aSpecialParent = nsnull;
} else {
*aSpecialParent =
nsFrame::CorrectStyleParentFrame(parent,
aFrame->GetStyleContext()->
GetPseudoType());
}

return NS_OK;
}

/* static */
nsIFrame*
nsFrame::CorrectStyleParentFrame(nsIFrame* aProspectiveParent,
nsIAtom* aChildPseudo)
{
NS_PRECONDITION(aProspectiveParent, "Must have a prospective parent");

// Anon boxes are parented to their actual parent already, except
// for non-elements. Those should not be treated as an anon box.
if (aChildPseudo && aChildPseudo != nsCSSAnonBoxes::mozNonElement &&
nsCSSAnonBoxes::IsAnonBox(aChildPseudo)) {
NS_ASSERTION(aChildPseudo != nsCSSAnonBoxes::mozAnonymousBlock &&
aChildPseudo != nsCSSAnonBoxes::mozAnonymousPositionedBlock,
"Should have dealt with kids that have NS_FRAME_IS_SPECIAL "
"elsewhere");
return aProspectiveParent;
}

// Otherwise, walk up out of all anon boxes
nsIFrame* parent = aProspectiveParent;
do {
if (parent->GetStateBits() & NS_FRAME_IS_SPECIAL) {
nsIFrame* sibling;
nsresult rv =
GetIBSpecialSibling(parent->PresContext(), parent, &sibling);
if (NS_FAILED(rv)) {
// If GetIBSpecialSibling fails, then what? we used to return what is
// now |aProspectiveParent|, but maybe |parent| would make more sense?
NS_NOTREACHED("Shouldn't get here");
return aProspectiveParent;
}
}

// If the frame is not a table pseudo frame, we want to move up
// the tree till we get to a non-table-pseudo frame.
if (!IsTablePseudo(pseudo)) {
while (IsTablePseudo(parent->GetStyleContext()->GetPseudoType())) {
parent = parent->GetParent();
if (sibling) {
// |parent| was the block in an {ib} split; use the inline as
// |the style parent.
parent = sibling;
}
}

if (parent->GetStateBits() & NS_FRAME_IS_SPECIAL) {
GetIBSpecialSibling(aPresContext, parent, aSpecialParent);
} else {
*aSpecialParent = parent;

nsIAtom* parentPseudo = parent->GetStyleContext()->GetPseudoType();
if (!parentPseudo || !nsCSSAnonBoxes::IsAnonBox(parentPseudo)) {
return parent;
}
}

return NS_OK;
parent = parent->GetParent();
} while (parent);

// We can get here if aProspectiveParent is the scrollframe for a viewport
// and the kids are the anonymous scrollbars.
NS_ASSERTION(aProspectiveParent->GetStyleContext()->GetPseudoType() ==
nsCSSAnonBoxes::viewportScroll,
"Should have found a parent before this");
return aProspectiveParent;
}

nsresult
Expand All @@ -5521,9 +5548,16 @@ nsFrame::DoGetParentStyleContextFrame(nsPresContext* aPresContext,
* using GetIBSpecialSibling
*/
if (mState & NS_FRAME_IS_SPECIAL) {
GetIBSpecialSibling(aPresContext, this, aProviderFrame);
if (*aProviderFrame)
nsresult rv = GetIBSpecialSibling(aPresContext, this, aProviderFrame);
if (NS_FAILED(rv)) {
NS_NOTREACHED("Shouldn't get here");
*aProviderFrame = nsnull;
return rv;
}

if (*aProviderFrame) {
return NS_OK;
}
}

// If this frame is one of the blocks that split an inline, we must
Expand Down
12 changes: 12 additions & 0 deletions layout/generic/nsFrame.h
Expand Up @@ -518,6 +518,18 @@ class nsFrame : public nsBox
nsresult DisplayOutline(nsDisplayListBuilder* aBuilder,
const nsDisplayListSet& aLists);

/**
* Adjust the given parent frame to the right style context parent frame for
* the child, given the pseudo-type of the prospective child. This handles
* things like walking out of table pseudos and so forth.
*
* @param aProspectiveParent what GetParent() on the child returns.
* Must not be null.
* @param aChildPseudo the child's pseudo type, if any.
*/
static nsIFrame*
CorrectStyleParentFrame(nsIFrame* aProspectiveParent, nsIAtom* aChildPseudo);

protected:
// Protected constructor and destructor
nsFrame(nsStyleContext* aContext);
Expand Down
51 changes: 51 additions & 0 deletions layout/generic/test/Makefile.in
@@ -0,0 +1,51 @@
#
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is mozilla.org code.
#
# The Initial Developer of the Original Code is
# Mozilla Foundation.
# Portions created by the Initial Developer are Copyright (C) 2007
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either of the GNU General Public License Version 2 or later (the "GPL"),
# or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK *****

DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
relativesrcdir = layout/generic/test

include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk

_TEST_FILES = test_bug323656.html \
$(NULL)

libs:: $(_TEST_FILES)
$(INSTALL) $^ $(DEPTH)/_tests/testing/mochitest/tests/$(relativesrcdir)
52 changes: 52 additions & 0 deletions layout/generic/test/test_bug323656.html
@@ -0,0 +1,52 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=323656
-->
<head>
<title>Test for Bug 323656</title>
<script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
<style>
/**
* The idea is that "color" inherits by default while "border-color" does
* not. So if the former is red and the latter is green on a parent, and
* the child's border-color is set to "inherit", it'll be green only if
* the child is inheriting from the parent. If not, it'll either be
* whatever the border-color is on what it's inheriting from, which will
* be red if what it's inheriting from has the default (currentColor)
*border-color).
*/

/* 't' for "test" */
#display, #display *
{ color: red; border: 0px hidden red; background: transparent }
#display .t { border-color: green }
#display .t > :first-child
{ border-color: inherit; border-style: solid; border-width: 10px }
</style>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=323656">Mozilla Bug 323656</a>
<p id="display">
<select size="1" class="t">
<option id="testOption"></option>
</select>
</p>
<div id="content" style="display: none">

</div>
<pre id="test">
<script class="testbody" type="text/javascript">

/** Test for Bug 323656 **/
var s = document.defaultView.getComputedStyle($("testOption"), "");
is(s.borderRightColor, "rgb(0, 128, 0)", "Inheritance broken");


</script>
</pre>
</body>
</html>

44 changes: 44 additions & 0 deletions layout/reftests/bugs/323656-1-ref.html
@@ -0,0 +1,44 @@
<!DOCTYPE html>
<html>
<head>
<title>Test inheritance through various table anonymous boxes</title>
<style>
/**
* The idea is that "color" inherits by default while "border-color" does
* not. So if the former is red and the latter is green on a parent, and
* the child's border-color is set to "inherit", it'll be green only if
* the child is inheriting from the parent. If not, it'll either be
* whatever the border-color is on what it's inheriting from, which will
* be red if what it's inheriting from has the default (currentColor)
* border-color).
*/

/* 't' for "test" */
* { color: green; border: 0px hidden green; background: transparent }
.t { border-color: green }
.t > :first-child
{ border-color: green; border-style: solid; border-width: 10px }
</style>
</head>
<body>
<table><tr><td class="t"><div></div></td></tr></table>
<div style="display: table" class="t"><div></div></div>
<div style="display: table-row-group" class="t"><div></div></div>
<div style="display: table-row" class="t"><div></div></div>
<div style="display: table-cell" class="t"><div></div></div>
<div><span><div style="display: table" class="t"><div></div></div></span></div>
<div><span><div style="display: table-row-group" class="t"><div></div></div></span></div>
<div><span><div style="display: table-row" class="t"><div></div></div></span></div>
<div><span><div style="display: table-cell" class="t"><div></div></div></span></div>

<table><tr><td class="t"><div></div></td></tr></table>
<div style="display: table" class="t"><div></div></div>
<div style="display: table-row-group" class="t"><div></div></div>
<div style="display: table-row" class="t"><div></div></div>
<div style="display: table-cell" class="t"><div></div></div>
<div><span><div style="display: table" class="t"><div></div></div></span></div>
<div><span><div style="display: table-row-group" class="t"><div></div></div></span></div>
<div><span><div style="display: table-row" class="t"><div></div></div></span></div>
<div><span><div style="display: table-cell" class="t"><div></div></div></span></div>
</body>
</html>

0 comments on commit b82e527

Please sign in to comment.