Fix writingmode and direction inheriting for the Document

The old code spread logic out in multiple places that tries to have the
document inherit the writing mode of <html> and <html> inherit the
writing mode of <body>. This logic breaks in the face of lazy attaching
because the renderers are not necessarily there.

Instead, compute these values ahead of time in Document::recalcStyle
and avoid the <html> or <body> renderers needing to reach up and modify
the document's style. This way, the logic works even if we haven't created
the renderers yet, which is needed for lazyAttach.

The ElementResolveContext fixes a bug where we do the wrong thing if the 
documentElement lacks a renderer. The code in StyleResolver::pseudoStyleForElement
that resets bits on the document seems like it's just wrong. We should
only reset those bits when recalculating the documentElement's style.

Review URL: https://chromiumcodereview.appspot.com/23468006

git-svn-id: svn://svn.chromium.org/blink/trunk@157174 bbb929c8-8fbe-4397-9dbb-9b2b20218538
XMLDocumentParser should lazy attach.

import-non-document-node.xml: whitespace text node change.
dynamic-caption-add-before-child.xhtml: this is a progression.
svg/custom/resource-invalidation-crash.svg: not clear what's going on here,
but since this is just testing for a crash with some weird patterns,
just filing a bug for now. crbug.com/284881

BUG=276689
R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/23779004

git-svn-id: svn://svn.chromium.org/blink/trunk@157175 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Fix for CSS reference effects when the filter renderer is lazy attached (e.g., assigned via innerHTML).

If the SVGFilterElement does not have a renderer yet, queue up adding client
RenderLayers until we created the renderer. This is take two on senorblanco's
patch https://chromiumcodereview.appspot.com/23672007 which got rolled out due
to a use-after-free.

In this version of the patch, hold onto RefPtr<Node> instead of RenderLayers.
This should fix the user-after-free and avoids the DOM needing to know about
RenderLayers.

BUG=272585

Review URL: https://chromiumcodereview.appspot.com/23632008

git-svn-id: svn://svn.chromium.org/blink/trunk@157176 bbb929c8-8fbe-4397-9dbb-9b2b20218538
Remove unneccessary includes from MathExtras.h.

R=tsepez@chromium.org

Review URL: https://codereview.chromium.org/23913002

git-svn-id: svn://svn.chromium.org/blink/trunk@157177 bbb929c8-8fbe-4397-9dbb-9b2b20218538