Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  *           (C) 1999 Antti Koivisto (koivisto (at) kde.org)
      4  *           (C) 2000 Dirk Mueller (mueller (at) kde.org)
      5  *           (C) 2004 Allan Sandfeld Jensen (kde (at) carewolf.com)
      6  * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
      7  * Copyright (C) 2009 Google Inc. All rights reserved.
      8  * Copyright (C) 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
      9  *
     10  * This library is free software; you can redistribute it and/or
     11  * modify it under the terms of the GNU Library General Public
     12  * License as published by the Free Software Foundation; either
     13  * version 2 of the License, or (at your option) any later version.
     14  *
     15  * This library is distributed in the hope that it will be useful,
     16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     18  * Library General Public License for more details.
     19  *
     20  * You should have received a copy of the GNU Library General Public License
     21  * along with this library; see the file COPYING.LIB.  If not, write to
     22  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     23  * Boston, MA 02110-1301, USA.
     24  *
     25  */
     26 
     27 #include "config.h"
     28 #include "RenderObject.h"
     29 
     30 #include "AXObjectCache.h"
     31 #include "Chrome.h"
     32 #include "CSSStyleSelector.h"
     33 #include "FloatQuad.h"
     34 #include "Frame.h"
     35 #include "FrameView.h"
     36 #include "GraphicsContext.h"
     37 #include "HTMLNames.h"
     38 #include "HitTestResult.h"
     39 #include "Page.h"
     40 #include "RenderArena.h"
     41 #include "RenderCounter.h"
     42 #include "RenderFlexibleBox.h"
     43 #include "RenderImageGeneratedContent.h"
     44 #include "RenderInline.h"
     45 #include "RenderListItem.h"
     46 #include "RenderRuby.h"
     47 #include "RenderRubyText.h"
     48 #include "RenderTableCell.h"
     49 #include "RenderTableCol.h"
     50 #include "RenderTableRow.h"
     51 #include "RenderTheme.h"
     52 #include "RenderView.h"
     53 #include "TransformState.h"
     54 #include "htmlediting.h"
     55 #include <algorithm>
     56 #ifdef ANDROID_LAYOUT
     57 #include "Settings.h"
     58 #endif
     59 #include <stdio.h>
     60 #include <wtf/RefCountedLeakCounter.h>
     61 #include <wtf/UnusedParam.h>
     62 
     63 #if USE(ACCELERATED_COMPOSITING)
     64 #include "RenderLayerCompositor.h"
     65 #endif
     66 
     67 #if ENABLE(WML)
     68 #include "WMLNames.h"
     69 #endif
     70 
     71 #if ENABLE(SVG)
     72 #include "SVGRenderSupport.h"
     73 #endif
     74 
     75 using namespace std;
     76 
     77 namespace WebCore {
     78 
     79 using namespace HTMLNames;
     80 
     81 #ifndef NDEBUG
     82 static void* baseOfRenderObjectBeingDeleted;
     83 #endif
     84 
     85 bool RenderObject::s_affectsParentBlock = false;
     86 
     87 void* RenderObject::operator new(size_t sz, RenderArena* renderArena) throw()
     88 {
     89     return renderArena->allocate(sz);
     90 }
     91 
     92 void RenderObject::operator delete(void* ptr, size_t sz)
     93 {
     94     ASSERT(baseOfRenderObjectBeingDeleted == ptr);
     95 
     96     // Stash size where destroy can find it.
     97     *(size_t *)ptr = sz;
     98 }
     99 
    100 RenderObject* RenderObject::createObject(Node* node, RenderStyle* style)
    101 {
    102     Document* doc = node->document();
    103     RenderArena* arena = doc->renderArena();
    104 
    105     // Minimal support for content properties replacing an entire element.
    106     // Works only if we have exactly one piece of content and it's a URL.
    107     // Otherwise acts as if we didn't support this feature.
    108     const ContentData* contentData = style->contentData();
    109     if (contentData && !contentData->next() && contentData->isImage() && doc != node) {
    110         RenderImageGeneratedContent* image = new (arena) RenderImageGeneratedContent(node);
    111         image->setStyle(style);
    112         if (StyleImage* styleImage = contentData->image())
    113             image->setStyleImage(styleImage);
    114         return image;
    115     }
    116 
    117 #if ENABLE(RUBY)
    118     if (node->hasTagName(rubyTag)) {
    119         if (style->display() == INLINE)
    120             return new (arena) RenderRubyAsInline(node);
    121         else
    122             return new (arena) RenderRubyAsBlock(node);
    123     }
    124     // treat <rt> as ruby text ONLY if it still has its default treatment of block
    125     if (node->hasTagName(rtTag) && style->display() == BLOCK)
    126         return new (arena) RenderRubyText(node);
    127 #endif
    128 
    129     switch (style->display()) {
    130         case NONE:
    131             return 0;
    132         case INLINE:
    133             return new (arena) RenderInline(node);
    134         case BLOCK:
    135         case INLINE_BLOCK:
    136         case RUN_IN:
    137         case COMPACT:
    138             return new (arena) RenderBlock(node);
    139         case LIST_ITEM:
    140             return new (arena) RenderListItem(node);
    141         case TABLE:
    142         case INLINE_TABLE:
    143             return new (arena) RenderTable(node);
    144         case TABLE_ROW_GROUP:
    145         case TABLE_HEADER_GROUP:
    146         case TABLE_FOOTER_GROUP:
    147             return new (arena) RenderTableSection(node);
    148         case TABLE_ROW:
    149             return new (arena) RenderTableRow(node);
    150         case TABLE_COLUMN_GROUP:
    151         case TABLE_COLUMN:
    152             return new (arena) RenderTableCol(node);
    153         case TABLE_CELL:
    154             return new (arena) RenderTableCell(node);
    155         case TABLE_CAPTION:
    156 #if ENABLE(WCSS)
    157         // As per the section 17.1 of the spec WAP-239-WCSS-20011026-a.pdf,
    158         // the marquee box inherits and extends the characteristics of the
    159         // principal block box ([CSS2] section 9.2.1).
    160         case WAP_MARQUEE:
    161 #endif
    162             return new (arena) RenderBlock(node);
    163         case BOX:
    164         case INLINE_BOX:
    165             return new (arena) RenderFlexibleBox(node);
    166     }
    167 
    168     return 0;
    169 }
    170 
    171 #ifndef NDEBUG
    172 static WTF::RefCountedLeakCounter renderObjectCounter("RenderObject");
    173 #endif
    174 
    175 RenderObject::RenderObject(Node* node)
    176     : CachedResourceClient()
    177     , m_style(0)
    178     , m_node(node)
    179     , m_parent(0)
    180     , m_previous(0)
    181     , m_next(0)
    182 #ifndef NDEBUG
    183     , m_hasAXObject(false)
    184     , m_setNeedsLayoutForbidden(false)
    185 #endif
    186     , m_needsLayout(false)
    187     , m_needsPositionedMovementLayout(false)
    188     , m_normalChildNeedsLayout(false)
    189     , m_posChildNeedsLayout(false)
    190     , m_prefWidthsDirty(false)
    191     , m_floating(false)
    192     , m_positioned(false)
    193     , m_relPositioned(false)
    194     , m_paintBackground(false)
    195     , m_isAnonymous(node == node->document())
    196     , m_isText(false)
    197     , m_isBox(false)
    198     , m_inline(true)
    199     , m_replaced(false)
    200     , m_isDragging(false)
    201     , m_hasLayer(false)
    202     , m_hasOverflowClip(false)
    203     , m_hasTransform(false)
    204     , m_hasReflection(false)
    205     , m_hasOverrideSize(false)
    206     , m_hasCounterNodeMap(false)
    207     , m_everHadLayout(false)
    208     , m_childrenInline(false)
    209     , m_topMarginQuirk(false)
    210     , m_bottomMarginQuirk(false)
    211     , m_hasMarkupTruncation(false)
    212     , m_selectionState(SelectionNone)
    213     , m_hasColumns(false)
    214     , m_cellWidthChanged(false)
    215 {
    216 #ifndef NDEBUG
    217     renderObjectCounter.increment();
    218 #endif
    219     ASSERT(node);
    220 }
    221 
    222 RenderObject::~RenderObject()
    223 {
    224     ASSERT(!node() || documentBeingDestroyed() || !document()->frame()->view() || document()->frame()->view()->layoutRoot() != this);
    225 #ifndef NDEBUG
    226     ASSERT(!m_hasAXObject);
    227     renderObjectCounter.decrement();
    228 #endif
    229 }
    230 
    231 RenderTheme* RenderObject::theme() const
    232 {
    233     ASSERT(document()->page());
    234 
    235     return document()->page()->theme();
    236 }
    237 
    238 bool RenderObject::isDescendantOf(const RenderObject* obj) const
    239 {
    240     for (const RenderObject* r = this; r; r = r->m_parent) {
    241         if (r == obj)
    242             return true;
    243     }
    244     return false;
    245 }
    246 
    247 bool RenderObject::isBody() const
    248 {
    249     return node() && node()->hasTagName(bodyTag);
    250 }
    251 
    252 bool RenderObject::isHR() const
    253 {
    254     return node() && node()->hasTagName(hrTag);
    255 }
    256 
    257 bool RenderObject::isHTMLMarquee() const
    258 {
    259     return node() && node()->renderer() == this && node()->hasTagName(marqueeTag);
    260 }
    261 
    262 static void updateListMarkerNumbers(RenderObject* child)
    263 {
    264     for (RenderObject* sibling = child; sibling; sibling = sibling->nextSibling()) {
    265         if (sibling->isListItem())
    266             toRenderListItem(sibling)->updateValue();
    267     }
    268 }
    269 
    270 void RenderObject::addChild(RenderObject* newChild, RenderObject* beforeChild)
    271 {
    272     RenderObjectChildList* children = virtualChildren();
    273     ASSERT(children);
    274     if (!children)
    275         return;
    276 
    277     bool needsTable = false;
    278 
    279     if (newChild->isListItem())
    280         updateListMarkerNumbers(beforeChild ? beforeChild : children->lastChild());
    281     else if (newChild->isTableCol() && newChild->style()->display() == TABLE_COLUMN_GROUP)
    282         needsTable = !isTable();
    283     else if (newChild->isRenderBlock() && newChild->style()->display() == TABLE_CAPTION)
    284         needsTable = !isTable();
    285     else if (newChild->isTableSection())
    286         needsTable = !isTable();
    287     else if (newChild->isTableRow())
    288         needsTable = !isTableSection();
    289     else if (newChild->isTableCell()) {
    290         needsTable = !isTableRow();
    291         // I'm not 100% sure this is the best way to fix this, but without this
    292         // change we recurse infinitely when trying to render the CSS2 test page:
    293         // http://www.bath.ac.uk/%7Epy8ieh/internet/eviltests/htmlbodyheadrendering2.html.
    294         // See Radar 2925291.
    295         if (needsTable && isTableCell() && !children->firstChild() && !newChild->isTableCell())
    296             needsTable = false;
    297     }
    298 
    299     if (needsTable) {
    300         RenderTable* table;
    301         RenderObject* afterChild = beforeChild ? beforeChild->previousSibling() : children->lastChild();
    302         if (afterChild && afterChild->isAnonymous() && afterChild->isTable())
    303             table = toRenderTable(afterChild);
    304         else {
    305             table = new (renderArena()) RenderTable(document() /* is anonymous */);
    306             RefPtr<RenderStyle> newStyle = RenderStyle::create();
    307             newStyle->inheritFrom(style());
    308             newStyle->setDisplay(TABLE);
    309             table->setStyle(newStyle.release());
    310             addChild(table, beforeChild);
    311         }
    312         table->addChild(newChild);
    313     } else {
    314         // Just add it...
    315         children->insertChildNode(this, newChild, beforeChild);
    316     }
    317     RenderCounter::rendererSubtreeAttached(newChild);
    318     if (newChild->isText() && newChild->style()->textTransform() == CAPITALIZE) {
    319         RefPtr<StringImpl> textToTransform = toRenderText(newChild)->originalText();
    320         if (textToTransform)
    321             toRenderText(newChild)->setText(textToTransform.release(), true);
    322     }
    323 }
    324 
    325 void RenderObject::removeChild(RenderObject* oldChild)
    326 {
    327     RenderObjectChildList* children = virtualChildren();
    328     ASSERT(children);
    329     if (!children)
    330         return;
    331 
    332     // We do this here instead of in removeChildNode, since the only extremely low-level uses of remove/appendChildNode
    333     // cannot affect the positioned object list, and the floating object list is irrelevant (since the list gets cleared on
    334     // layout anyway).
    335     if (oldChild->isFloatingOrPositioned())
    336         toRenderBox(oldChild)->removeFloatingOrPositionedChildFromBlockLists();
    337 
    338     children->removeChildNode(this, oldChild);
    339 }
    340 
    341 RenderObject* RenderObject::nextInPreOrder() const
    342 {
    343     if (RenderObject* o = firstChild())
    344         return o;
    345 
    346     return nextInPreOrderAfterChildren();
    347 }
    348 
    349 RenderObject* RenderObject::nextInPreOrderAfterChildren() const
    350 {
    351     RenderObject* o;
    352     if (!(o = nextSibling())) {
    353         o = parent();
    354         while (o && !o->nextSibling())
    355             o = o->parent();
    356         if (o)
    357             o = o->nextSibling();
    358     }
    359 
    360     return o;
    361 }
    362 
    363 RenderObject* RenderObject::nextInPreOrder(RenderObject* stayWithin) const
    364 {
    365     if (RenderObject* o = firstChild())
    366         return o;
    367 
    368     return nextInPreOrderAfterChildren(stayWithin);
    369 }
    370 
    371 RenderObject* RenderObject::nextInPreOrderAfterChildren(RenderObject* stayWithin) const
    372 {
    373     if (this == stayWithin)
    374         return 0;
    375 
    376     const RenderObject* current = this;
    377     RenderObject* next;
    378     while (!(next = current->nextSibling())) {
    379         current = current->parent();
    380         if (!current || current == stayWithin)
    381             return 0;
    382     }
    383     return next;
    384 }
    385 
    386 RenderObject* RenderObject::previousInPreOrder() const
    387 {
    388     if (RenderObject* o = previousSibling()) {
    389         while (o->lastChild())
    390             o = o->lastChild();
    391         return o;
    392     }
    393 
    394     return parent();
    395 }
    396 
    397 RenderObject* RenderObject::childAt(unsigned index) const
    398 {
    399     RenderObject* child = firstChild();
    400     for (unsigned i = 0; child && i < index; i++)
    401         child = child->nextSibling();
    402     return child;
    403 }
    404 
    405 RenderObject* RenderObject::firstLeafChild() const
    406 {
    407     RenderObject* r = firstChild();
    408     while (r) {
    409         RenderObject* n = 0;
    410         n = r->firstChild();
    411         if (!n)
    412             break;
    413         r = n;
    414     }
    415     return r;
    416 }
    417 
    418 RenderObject* RenderObject::lastLeafChild() const
    419 {
    420     RenderObject* r = lastChild();
    421     while (r) {
    422         RenderObject* n = 0;
    423         n = r->lastChild();
    424         if (!n)
    425             break;
    426         r = n;
    427     }
    428     return r;
    429 }
    430 
    431 static void addLayers(RenderObject* obj, RenderLayer* parentLayer, RenderObject*& newObject,
    432                       RenderLayer*& beforeChild)
    433 {
    434     if (obj->hasLayer()) {
    435         if (!beforeChild && newObject) {
    436             // We need to figure out the layer that follows newObject.  We only do
    437             // this the first time we find a child layer, and then we update the
    438             // pointer values for newObject and beforeChild used by everyone else.
    439             beforeChild = newObject->parent()->findNextLayer(parentLayer, newObject);
    440             newObject = 0;
    441         }
    442         parentLayer->addChild(toRenderBoxModelObject(obj)->layer(), beforeChild);
    443         return;
    444     }
    445 
    446     for (RenderObject* curr = obj->firstChild(); curr; curr = curr->nextSibling())
    447         addLayers(curr, parentLayer, newObject, beforeChild);
    448 }
    449 
    450 void RenderObject::addLayers(RenderLayer* parentLayer, RenderObject* newObject)
    451 {
    452     if (!parentLayer)
    453         return;
    454 
    455     RenderObject* object = newObject;
    456     RenderLayer* beforeChild = 0;
    457     WebCore::addLayers(this, parentLayer, object, beforeChild);
    458 }
    459 
    460 void RenderObject::removeLayers(RenderLayer* parentLayer)
    461 {
    462     if (!parentLayer)
    463         return;
    464 
    465     if (hasLayer()) {
    466         parentLayer->removeChild(toRenderBoxModelObject(this)->layer());
    467         return;
    468     }
    469 
    470     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
    471         curr->removeLayers(parentLayer);
    472 }
    473 
    474 void RenderObject::moveLayers(RenderLayer* oldParent, RenderLayer* newParent)
    475 {
    476     if (!newParent)
    477         return;
    478 
    479     if (hasLayer()) {
    480         RenderLayer* layer = toRenderBoxModelObject(this)->layer();
    481         ASSERT(oldParent == layer->parent());
    482         if (oldParent)
    483             oldParent->removeChild(layer);
    484         newParent->addChild(layer);
    485         return;
    486     }
    487 
    488     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
    489         curr->moveLayers(oldParent, newParent);
    490 }
    491 
    492 RenderLayer* RenderObject::findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint,
    493                                          bool checkParent)
    494 {
    495     // Error check the parent layer passed in.  If it's null, we can't find anything.
    496     if (!parentLayer)
    497         return 0;
    498 
    499     // Step 1: If our layer is a child of the desired parent, then return our layer.
    500     RenderLayer* ourLayer = hasLayer() ? toRenderBoxModelObject(this)->layer() : 0;
    501     if (ourLayer && ourLayer->parent() == parentLayer)
    502         return ourLayer;
    503 
    504     // Step 2: If we don't have a layer, or our layer is the desired parent, then descend
    505     // into our siblings trying to find the next layer whose parent is the desired parent.
    506     if (!ourLayer || ourLayer == parentLayer) {
    507         for (RenderObject* curr = startPoint ? startPoint->nextSibling() : firstChild();
    508              curr; curr = curr->nextSibling()) {
    509             RenderLayer* nextLayer = curr->findNextLayer(parentLayer, 0, false);
    510             if (nextLayer)
    511                 return nextLayer;
    512         }
    513     }
    514 
    515     // Step 3: If our layer is the desired parent layer, then we're finished.  We didn't
    516     // find anything.
    517     if (parentLayer == ourLayer)
    518         return 0;
    519 
    520     // Step 4: If |checkParent| is set, climb up to our parent and check its siblings that
    521     // follow us to see if we can locate a layer.
    522     if (checkParent && parent())
    523         return parent()->findNextLayer(parentLayer, this, true);
    524 
    525     return 0;
    526 }
    527 
    528 RenderLayer* RenderObject::enclosingLayer() const
    529 {
    530     const RenderObject* curr = this;
    531     while (curr) {
    532         RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
    533         if (layer)
    534             return layer;
    535         curr = curr->parent();
    536     }
    537     return 0;
    538 }
    539 
    540 RenderLayer* RenderObject::enclosingSelfPaintingLayer() const
    541 {
    542     const RenderObject* curr = this;
    543     while (curr) {
    544         RenderLayer* layer = curr->hasLayer() ? toRenderBoxModelObject(curr)->layer() : 0;
    545         if (layer && layer->isSelfPaintingLayer())
    546             return layer;
    547         curr = curr->parent();
    548     }
    549     return 0;
    550 }
    551 
    552 RenderBox* RenderObject::enclosingBox() const
    553 {
    554     RenderObject* curr = const_cast<RenderObject*>(this);
    555     while (curr) {
    556         if (curr->isBox())
    557             return toRenderBox(curr);
    558         curr = curr->parent();
    559     }
    560 
    561     ASSERT_NOT_REACHED();
    562     return 0;
    563 }
    564 
    565 RenderBlock* RenderObject::firstLineBlock() const
    566 {
    567     return 0;
    568 }
    569 
    570 void RenderObject::setPrefWidthsDirty(bool b, bool markParents)
    571 {
    572     bool alreadyDirty = m_prefWidthsDirty;
    573     m_prefWidthsDirty = b;
    574     if (b && !alreadyDirty && markParents && (isText() || (style()->position() != FixedPosition && style()->position() != AbsolutePosition)))
    575         invalidateContainerPrefWidths();
    576 }
    577 
    578 void RenderObject::invalidateContainerPrefWidths()
    579 {
    580     // In order to avoid pathological behavior when inlines are deeply nested, we do include them
    581     // in the chain that we mark dirty (even though they're kind of irrelevant).
    582     RenderObject* o = isTableCell() ? containingBlock() : container();
    583     while (o && !o->m_prefWidthsDirty) {
    584         // Don't invalidate the outermost object of an unrooted subtree. That object will be
    585         // invalidated when the subtree is added to the document.
    586         RenderObject* container = o->isTableCell() ? o->containingBlock() : o->container();
    587         if (!container && !o->isRenderView())
    588             break;
    589 
    590         o->m_prefWidthsDirty = true;
    591         if (o->style()->position() == FixedPosition || o->style()->position() == AbsolutePosition)
    592             // A positioned object has no effect on the min/max width of its containing block ever.
    593             // We can optimize this case and not go up any further.
    594             break;
    595         o = container;
    596     }
    597 }
    598 
    599 void RenderObject::setLayerNeedsFullRepaint()
    600 {
    601     ASSERT(hasLayer());
    602     toRenderBoxModelObject(this)->layer()->setNeedsFullRepaint(true);
    603 }
    604 
    605 RenderBlock* RenderObject::containingBlock() const
    606 {
    607     if (isTableCell()) {
    608         const RenderTableCell* cell = toRenderTableCell(this);
    609         if (parent() && cell->section())
    610             return cell->table();
    611         return 0;
    612     }
    613 
    614     if (isRenderView())
    615         return const_cast<RenderView*>(toRenderView(this));
    616 
    617     RenderObject* o = parent();
    618     if (!isText() && m_style->position() == FixedPosition) {
    619         while (o && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock()))
    620             o = o->parent();
    621     } else if (!isText() && m_style->position() == AbsolutePosition) {
    622         while (o && (o->style()->position() == StaticPosition || (o->isInline() && !o->isReplaced())) && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
    623             // For relpositioned inlines, we return the nearest enclosing block.  We don't try
    624             // to return the inline itself.  This allows us to avoid having a positioned objects
    625             // list in all RenderInlines and lets us return a strongly-typed RenderBlock* result
    626             // from this method.  The container() method can actually be used to obtain the
    627             // inline directly.
    628             if (o->style()->position() == RelativePosition && o->isInline() && !o->isReplaced())
    629                 return o->containingBlock();
    630 #if ENABLE(SVG)
    631             if (o->isSVGForeignObject()) //foreignObject is the containing block for contents inside it
    632                 break;
    633 #endif
    634 
    635             o = o->parent();
    636         }
    637     } else {
    638         while (o && ((o->isInline() && !o->isReplaced()) || o->isTableRow() || o->isTableSection()
    639                      || o->isTableCol() || o->isFrameSet() || o->isMedia()
    640 #if ENABLE(SVG)
    641                      || o->isSVGContainer() || o->isSVGRoot()
    642 #endif
    643                      ))
    644             o = o->parent();
    645     }
    646 
    647     if (!o || !o->isRenderBlock())
    648         return 0; // This can still happen in case of an orphaned tree
    649 
    650     return toRenderBlock(o);
    651 }
    652 
    653 static bool mustRepaintFillLayers(const RenderObject* renderer, const FillLayer* layer)
    654 {
    655     // Nobody will use multiple layers without wanting fancy positioning.
    656     if (layer->next())
    657         return true;
    658 
    659     // Make sure we have a valid image.
    660     StyleImage* img = layer->image();
    661     if (!img || !img->canRender(renderer->style()->effectiveZoom()))
    662         return false;
    663 
    664     if (!layer->xPosition().isZero() || !layer->yPosition().isZero())
    665         return true;
    666 
    667     if (layer->size().type == SizeLength) {
    668         if (layer->size().size.width().isPercent() || layer->size().size.height().isPercent())
    669             return true;
    670     } else if (layer->size().type == Contain || layer->size().type == Cover || img->usesImageContainerSize())
    671         return true;
    672 
    673     return false;
    674 }
    675 
    676 bool RenderObject::mustRepaintBackgroundOrBorder() const
    677 {
    678     if (hasMask() && mustRepaintFillLayers(this, style()->maskLayers()))
    679         return true;
    680 
    681     // If we don't have a background/border/mask, then nothing to do.
    682     if (!hasBoxDecorations())
    683         return false;
    684 
    685     if (mustRepaintFillLayers(this, style()->backgroundLayers()))
    686         return true;
    687 
    688     // Our fill layers are ok.  Let's check border.
    689     if (style()->hasBorder()) {
    690         // Border images are not ok.
    691         StyleImage* borderImage = style()->borderImage().image();
    692         bool shouldPaintBorderImage = borderImage && borderImage->canRender(style()->effectiveZoom());
    693 
    694         // If the image hasn't loaded, we're still using the normal border style.
    695         if (shouldPaintBorderImage && borderImage->isLoaded())
    696             return true;
    697     }
    698 
    699     return false;
    700 }
    701 
    702 void RenderObject::drawLineForBoxSide(GraphicsContext* graphicsContext, int x1, int y1, int x2, int y2,
    703                                       BoxSide s, Color c, const Color& textcolor, EBorderStyle style,
    704                                       int adjbw1, int adjbw2)
    705 {
    706     int width = (s == BSTop || s == BSBottom ? y2 - y1 : x2 - x1);
    707 
    708     if (style == DOUBLE && width < 3)
    709         style = SOLID;
    710 
    711     if (!c.isValid()) {
    712         if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
    713             c.setRGB(238, 238, 238);
    714         else
    715             c = textcolor;
    716     }
    717 
    718     switch (style) {
    719         case BNONE:
    720         case BHIDDEN:
    721             return;
    722         case DOTTED:
    723         case DASHED:
    724             graphicsContext->setStrokeColor(c, m_style->colorSpace());
    725             graphicsContext->setStrokeThickness(width);
    726             graphicsContext->setStrokeStyle(style == DASHED ? DashedStroke : DottedStroke);
    727 
    728             if (width > 0)
    729                 switch (s) {
    730                     case BSBottom:
    731                     case BSTop:
    732                         graphicsContext->drawLine(IntPoint(x1, (y1 + y2) / 2), IntPoint(x2, (y1 + y2) / 2));
    733                         break;
    734                     case BSRight:
    735                     case BSLeft:
    736                         graphicsContext->drawLine(IntPoint((x1 + x2) / 2, y1), IntPoint((x1 + x2) / 2, y2));
    737                         break;
    738                 }
    739             break;
    740         case DOUBLE: {
    741             int third = (width + 1) / 3;
    742 
    743             if (adjbw1 == 0 && adjbw2 == 0) {
    744                 graphicsContext->setStrokeStyle(NoStroke);
    745                 graphicsContext->setFillColor(c, m_style->colorSpace());
    746                 switch (s) {
    747                     case BSTop:
    748                     case BSBottom:
    749                         graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, third));
    750                         graphicsContext->drawRect(IntRect(x1, y2 - third, x2 - x1, third));
    751                         break;
    752                     case BSLeft:
    753                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
    754                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
    755                         break;
    756                     case BSRight:
    757                         graphicsContext->drawRect(IntRect(x1, y1 + 1, third, y2 - y1 - 1));
    758                         graphicsContext->drawRect(IntRect(x2 - third, y1 + 1, third, y2 - y1 - 1));
    759                         break;
    760                 }
    761             } else {
    762                 int adjbw1bigthird = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 3;
    763                 int adjbw2bigthird = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 3;
    764 
    765                 switch (s) {
    766                     case BSTop:
    767                         drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
    768                                    y1, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y1 + third,
    769                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    770                         drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
    771                                    y2 - third, x2 - max((adjbw2 * 2 + 1) / 3, 0), y2,
    772                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    773                         break;
    774                     case BSLeft:
    775                         drawLineForBoxSide(graphicsContext, x1, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
    776                                    x1 + third, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
    777                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    778                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((adjbw1 * 2 + 1) / 3, 0),
    779                                    x2, y2 - max((adjbw2 * 2 + 1) / 3, 0),
    780                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    781                         break;
    782                     case BSBottom:
    783                         drawLineForBoxSide(graphicsContext, x1 + max((adjbw1 * 2 + 1) / 3, 0),
    784                                    y1, x2 - max((adjbw2 * 2 + 1) / 3, 0), y1 + third,
    785                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    786                         drawLineForBoxSide(graphicsContext, x1 + max((-adjbw1 * 2 + 1) / 3, 0),
    787                                    y2 - third, x2 - max((-adjbw2 * 2 + 1) / 3, 0), y2,
    788                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    789                         break;
    790                     case BSRight:
    791                         drawLineForBoxSide(graphicsContext, x1, y1 + max((adjbw1 * 2 + 1) / 3, 0),
    792                                    x1 + third, y2 - max((adjbw2 * 2 + 1) / 3, 0),
    793                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    794                         drawLineForBoxSide(graphicsContext, x2 - third, y1 + max((-adjbw1 * 2 + 1) / 3, 0),
    795                                    x2, y2 - max((-adjbw2 * 2 + 1) / 3, 0),
    796                                    s, c, textcolor, SOLID, adjbw1bigthird, adjbw2bigthird);
    797                         break;
    798                     default:
    799                         break;
    800                 }
    801             }
    802             break;
    803         }
    804         case RIDGE:
    805         case GROOVE:
    806         {
    807             EBorderStyle s1;
    808             EBorderStyle s2;
    809             if (style == GROOVE) {
    810                 s1 = INSET;
    811                 s2 = OUTSET;
    812             } else {
    813                 s1 = OUTSET;
    814                 s2 = INSET;
    815             }
    816 
    817             int adjbw1bighalf = ((adjbw1 > 0) ? adjbw1 + 1 : adjbw1 - 1) / 2;
    818             int adjbw2bighalf = ((adjbw2 > 0) ? adjbw2 + 1 : adjbw2 - 1) / 2;
    819 
    820             switch (s) {
    821                 case BSTop:
    822                     drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1, 0) / 2, y1, x2 - max(-adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
    823                                s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
    824                     drawLineForBoxSide(graphicsContext, x1 + max(adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(adjbw2 + 1, 0) / 2, y2,
    825                                s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
    826                     break;
    827                 case BSLeft:
    828                     drawLineForBoxSide(graphicsContext, x1, y1 + max(-adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(-adjbw2, 0) / 2,
    829                                s, c, textcolor, s1, adjbw1bighalf, adjbw2bighalf);
    830                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(adjbw1 + 1, 0) / 2, x2, y2 - max(adjbw2 + 1, 0) / 2,
    831                                s, c, textcolor, s2, adjbw1 / 2, adjbw2 / 2);
    832                     break;
    833                 case BSBottom:
    834                     drawLineForBoxSide(graphicsContext, x1 + max(adjbw1, 0) / 2, y1, x2 - max(adjbw2, 0) / 2, (y1 + y2 + 1) / 2,
    835                                s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
    836                     drawLineForBoxSide(graphicsContext, x1 + max(-adjbw1 + 1, 0) / 2, (y1 + y2 + 1) / 2, x2 - max(-adjbw2 + 1, 0) / 2, y2,
    837                                s, c, textcolor, s1, adjbw1/2, adjbw2/2);
    838                     break;
    839                 case BSRight:
    840                     drawLineForBoxSide(graphicsContext, x1, y1 + max(adjbw1, 0) / 2, (x1 + x2 + 1) / 2, y2 - max(adjbw2, 0) / 2,
    841                                s, c, textcolor, s2, adjbw1bighalf, adjbw2bighalf);
    842                     drawLineForBoxSide(graphicsContext, (x1 + x2 + 1) / 2, y1 + max(-adjbw1 + 1, 0) / 2, x2, y2 - max(-adjbw2 + 1, 0) / 2,
    843                                s, c, textcolor, s1, adjbw1/2, adjbw2/2);
    844                     break;
    845             }
    846             break;
    847         }
    848         case INSET:
    849             if (s == BSTop || s == BSLeft)
    850                 c = c.dark();
    851             // fall through
    852         case OUTSET:
    853             if (style == OUTSET && (s == BSBottom || s == BSRight))
    854                 c = c.dark();
    855             // fall through
    856         case SOLID: {
    857             graphicsContext->setStrokeStyle(NoStroke);
    858             graphicsContext->setFillColor(c, m_style->colorSpace());
    859             ASSERT(x2 >= x1);
    860             ASSERT(y2 >= y1);
    861             if (!adjbw1 && !adjbw2) {
    862                 graphicsContext->drawRect(IntRect(x1, y1, x2 - x1, y2 - y1));
    863                 return;
    864             }
    865             FloatPoint quad[4];
    866             switch (s) {
    867                 case BSTop:
    868                     quad[0] = FloatPoint(x1 + max(-adjbw1, 0), y1);
    869                     quad[1] = FloatPoint(x1 + max(adjbw1, 0), y2);
    870                     quad[2] = FloatPoint(x2 - max(adjbw2, 0), y2);
    871                     quad[3] = FloatPoint(x2 - max(-adjbw2, 0), y1);
    872                     break;
    873                 case BSBottom:
    874                     quad[0] = FloatPoint(x1 + max(adjbw1, 0), y1);
    875                     quad[1] = FloatPoint(x1 + max(-adjbw1, 0), y2);
    876                     quad[2] = FloatPoint(x2 - max(-adjbw2, 0), y2);
    877                     quad[3] = FloatPoint(x2 - max(adjbw2, 0), y1);
    878                     break;
    879                 case BSLeft:
    880                     quad[0] = FloatPoint(x1, y1 + max(-adjbw1, 0));
    881                     quad[1] = FloatPoint(x1, y2 - max(-adjbw2, 0));
    882                     quad[2] = FloatPoint(x2, y2 - max(adjbw2, 0));
    883                     quad[3] = FloatPoint(x2, y1 + max(adjbw1, 0));
    884                     break;
    885                 case BSRight:
    886                     quad[0] = FloatPoint(x1, y1 + max(adjbw1, 0));
    887                     quad[1] = FloatPoint(x1, y2 - max(adjbw2, 0));
    888                     quad[2] = FloatPoint(x2, y2 - max(-adjbw2, 0));
    889                     quad[3] = FloatPoint(x2, y1 + max(-adjbw1, 0));
    890                     break;
    891             }
    892             graphicsContext->drawConvexPolygon(4, quad);
    893             break;
    894         }
    895     }
    896 }
    897 
    898 void RenderObject::drawArcForBoxSide(GraphicsContext* graphicsContext, int x, int y, float thickness, IntSize radius,
    899                                      int angleStart, int angleSpan, BoxSide s, Color c, const Color& textColor,
    900                                      EBorderStyle style, bool firstCorner)
    901 {
    902     if ((style == DOUBLE && thickness / 2 < 3) || ((style == RIDGE || style == GROOVE) && thickness / 2 < 2))
    903         style = SOLID;
    904 
    905     if (!c.isValid()) {
    906         if (style == INSET || style == OUTSET || style == RIDGE || style == GROOVE)
    907             c.setRGB(238, 238, 238);
    908         else
    909             c = textColor;
    910     }
    911 
    912     switch (style) {
    913         case BNONE:
    914         case BHIDDEN:
    915             return;
    916         case DOTTED:
    917         case DASHED:
    918             graphicsContext->setStrokeColor(c, m_style->colorSpace());
    919             graphicsContext->setStrokeStyle(style == DOTTED ? DottedStroke : DashedStroke);
    920             graphicsContext->setStrokeThickness(thickness);
    921             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
    922             break;
    923         case DOUBLE: {
    924             float third = thickness / 3.0f;
    925             float innerThird = (thickness + 1.0f) / 6.0f;
    926             int shiftForInner = static_cast<int>(innerThird * 2.5f);
    927 
    928             int outerY = y;
    929             int outerHeight = radius.height() * 2;
    930             int innerX = x + shiftForInner;
    931             int innerY = y + shiftForInner;
    932             int innerWidth = (radius.width() - shiftForInner) * 2;
    933             int innerHeight = (radius.height() - shiftForInner) * 2;
    934             if (innerThird > 1 && (s == BSTop || (firstCorner && (s == BSLeft || s == BSRight)))) {
    935                 outerHeight += 2;
    936                 innerHeight += 2;
    937             }
    938 
    939             graphicsContext->setStrokeStyle(SolidStroke);
    940             graphicsContext->setStrokeColor(c, m_style->colorSpace());
    941             graphicsContext->setStrokeThickness(third);
    942             graphicsContext->strokeArc(IntRect(x, outerY, radius.width() * 2, outerHeight), angleStart, angleSpan);
    943             graphicsContext->setStrokeThickness(innerThird > 2 ? innerThird - 1 : innerThird);
    944             graphicsContext->strokeArc(IntRect(innerX, innerY, innerWidth, innerHeight), angleStart, angleSpan);
    945             break;
    946         }
    947         case GROOVE:
    948         case RIDGE: {
    949             Color c2;
    950             if ((style == RIDGE && (s == BSTop || s == BSLeft)) ||
    951                     (style == GROOVE && (s == BSBottom || s == BSRight)))
    952                 c2 = c.dark();
    953             else {
    954                 c2 = c;
    955                 c = c.dark();
    956             }
    957 
    958             graphicsContext->setStrokeStyle(SolidStroke);
    959             graphicsContext->setStrokeColor(c, m_style->colorSpace());
    960             graphicsContext->setStrokeThickness(thickness);
    961             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
    962 
    963             float halfThickness = (thickness + 1.0f) / 4.0f;
    964             int shiftForInner = static_cast<int>(halfThickness * 1.5f);
    965             graphicsContext->setStrokeColor(c2, m_style->colorSpace());
    966             graphicsContext->setStrokeThickness(halfThickness > 2 ? halfThickness - 1 : halfThickness);
    967             graphicsContext->strokeArc(IntRect(x + shiftForInner, y + shiftForInner, (radius.width() - shiftForInner) * 2,
    968                                        (radius.height() - shiftForInner) * 2), angleStart, angleSpan);
    969             break;
    970         }
    971         case INSET:
    972             if (s == BSTop || s == BSLeft)
    973                 c = c.dark();
    974         case OUTSET:
    975             if (style == OUTSET && (s == BSBottom || s == BSRight))
    976                 c = c.dark();
    977         case SOLID:
    978             graphicsContext->setStrokeStyle(SolidStroke);
    979             graphicsContext->setStrokeColor(c, m_style->colorSpace());
    980             graphicsContext->setStrokeThickness(thickness);
    981             graphicsContext->strokeArc(IntRect(x, y, radius.width() * 2, radius.height() * 2), angleStart, angleSpan);
    982             break;
    983     }
    984 }
    985 
    986 void RenderObject::addPDFURLRect(GraphicsContext* context, const IntRect& rect)
    987 {
    988     if (rect.isEmpty())
    989         return;
    990     Node* n = node();
    991     if (!n || !n->isLink() || !n->isElementNode())
    992         return;
    993     const AtomicString& href = static_cast<Element*>(n)->getAttribute(hrefAttr);
    994     if (href.isNull())
    995         return;
    996     context->setURLForRect(n->document()->completeURL(href), rect);
    997 }
    998 
    999 void RenderObject::paintOutline(GraphicsContext* graphicsContext, int tx, int ty, int w, int h, const RenderStyle* style)
   1000 {
   1001     if (!hasOutline())
   1002         return;
   1003 
   1004     int ow = style->outlineWidth();
   1005     EBorderStyle os = style->outlineStyle();
   1006 
   1007     Color oc = style->outlineColor();
   1008     if (!oc.isValid())
   1009         oc = style->color();
   1010 
   1011     int offset = style->outlineOffset();
   1012 
   1013     if (style->outlineStyleIsAuto() || hasOutlineAnnotation()) {
   1014         if (!theme()->supportsFocusRing(style)) {
   1015             // Only paint the focus ring by hand if the theme isn't able to draw the focus ring.
   1016             Vector<IntRect> focusRingRects;
   1017             addFocusRingRects(focusRingRects, tx, ty);
   1018             if (style->outlineStyleIsAuto())
   1019                 graphicsContext->drawFocusRing(focusRingRects, ow, offset, oc);
   1020             else
   1021                 addPDFURLRect(graphicsContext, unionRect(focusRingRects));
   1022         }
   1023     }
   1024 
   1025     if (style->outlineStyleIsAuto() || style->outlineStyle() == BNONE)
   1026         return;
   1027 
   1028     tx -= offset;
   1029     ty -= offset;
   1030     w += 2 * offset;
   1031     h += 2 * offset;
   1032 
   1033     if (h < 0 || w < 0)
   1034         return;
   1035 
   1036     drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx, ty + h + ow,
   1037                BSLeft, Color(oc), style->color(), os, ow, ow);
   1038 
   1039     drawLineForBoxSide(graphicsContext, tx - ow, ty - ow, tx + w + ow, ty,
   1040                BSTop, Color(oc), style->color(), os, ow, ow);
   1041 
   1042     drawLineForBoxSide(graphicsContext, tx + w, ty - ow, tx + w + ow, ty + h + ow,
   1043                BSRight, Color(oc), style->color(), os, ow, ow);
   1044 
   1045     drawLineForBoxSide(graphicsContext, tx - ow, ty + h, tx + w + ow, ty + h + ow,
   1046                BSBottom, Color(oc), style->color(), os, ow, ow);
   1047 }
   1048 
   1049 IntRect RenderObject::absoluteBoundingBoxRect(bool useTransforms)
   1050 {
   1051     if (useTransforms) {
   1052         Vector<FloatQuad> quads;
   1053         absoluteQuads(quads);
   1054 
   1055         size_t n = quads.size();
   1056         if (!n)
   1057             return IntRect();
   1058 
   1059         IntRect result = quads[0].enclosingBoundingBox();
   1060         for (size_t i = 1; i < n; ++i)
   1061             result.unite(quads[i].enclosingBoundingBox());
   1062         return result;
   1063     }
   1064 
   1065     FloatPoint absPos = localToAbsolute();
   1066     Vector<IntRect> rects;
   1067     absoluteRects(rects, absPos.x(), absPos.y());
   1068 
   1069     size_t n = rects.size();
   1070     if (!n)
   1071         return IntRect();
   1072 
   1073     IntRect result = rects[0];
   1074     for (size_t i = 1; i < n; ++i)
   1075         result.unite(rects[i]);
   1076     return result;
   1077 }
   1078 
   1079 void RenderObject::absoluteFocusRingQuads(Vector<FloatQuad>& quads)
   1080 {
   1081     Vector<IntRect> rects;
   1082     // FIXME: addFocusRingRects() needs to be passed this transform-unaware
   1083     // localToAbsolute() offset here because RenderInline::addFocusRingRects()
   1084     // implicitly assumes that. This doesn't work correctly with transformed
   1085     // descendants.
   1086     FloatPoint absolutePoint = localToAbsolute();
   1087     addFocusRingRects(rects, absolutePoint.x(), absolutePoint.y());
   1088     size_t count = rects.size();
   1089     for (size_t i = 0; i < count; ++i) {
   1090         IntRect rect = rects[i];
   1091         rect.move(-absolutePoint.x(), -absolutePoint.y());
   1092         quads.append(localToAbsoluteQuad(FloatQuad(rect)));
   1093     }
   1094 }
   1095 
   1096 void RenderObject::addAbsoluteRectForLayer(IntRect& result)
   1097 {
   1098     if (hasLayer())
   1099         result.unite(absoluteBoundingBoxRect());
   1100     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
   1101         current->addAbsoluteRectForLayer(result);
   1102 }
   1103 
   1104 IntRect RenderObject::paintingRootRect(IntRect& topLevelRect)
   1105 {
   1106     IntRect result = absoluteBoundingBoxRect();
   1107     topLevelRect = result;
   1108     for (RenderObject* current = firstChild(); current; current = current->nextSibling())
   1109         current->addAbsoluteRectForLayer(result);
   1110     return result;
   1111 }
   1112 
   1113 void RenderObject::paint(PaintInfo& /*paintInfo*/, int /*tx*/, int /*ty*/)
   1114 {
   1115 }
   1116 
   1117 RenderBoxModelObject* RenderObject::containerForRepaint() const
   1118 {
   1119 #if USE(ACCELERATED_COMPOSITING)
   1120     if (RenderView* v = view()) {
   1121         if (v->usesCompositing()) {
   1122             RenderLayer* compLayer = enclosingLayer()->enclosingCompositingLayer();
   1123             return compLayer ? compLayer->renderer() : 0;
   1124         }
   1125     }
   1126 #endif
   1127     // Do root-relative repaint.
   1128     return 0;
   1129 }
   1130 
   1131 void RenderObject::repaintUsingContainer(RenderBoxModelObject* repaintContainer, const IntRect& r, bool immediate)
   1132 {
   1133     if (!repaintContainer || repaintContainer->isRenderView()) {
   1134         RenderView* v = repaintContainer ? toRenderView(repaintContainer) : view();
   1135         v->repaintViewRectangle(r, immediate);
   1136     } else {
   1137 #if USE(ACCELERATED_COMPOSITING)
   1138         RenderView* v = view();
   1139         if (v->usesCompositing()) {
   1140             ASSERT(repaintContainer->hasLayer() && repaintContainer->layer()->isComposited());
   1141             repaintContainer->layer()->setBackingNeedsRepaintInRect(r);
   1142         }
   1143 #else
   1144         ASSERT_NOT_REACHED();
   1145 #endif
   1146     }
   1147 }
   1148 
   1149 void RenderObject::repaint(bool immediate)
   1150 {
   1151     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
   1152     RenderView* view;
   1153     if (!isRooted(&view))
   1154         return;
   1155 
   1156     if (view->printing())
   1157         return; // Don't repaint if we're printing.
   1158 
   1159     RenderBoxModelObject* repaintContainer = containerForRepaint();
   1160     repaintUsingContainer(repaintContainer ? repaintContainer : view, clippedOverflowRectForRepaint(repaintContainer), immediate);
   1161 }
   1162 
   1163 void RenderObject::repaintRectangle(const IntRect& r, bool immediate)
   1164 {
   1165     // Don't repaint if we're unrooted (note that view() still returns the view when unrooted)
   1166     RenderView* view;
   1167     if (!isRooted(&view))
   1168         return;
   1169 
   1170     if (view->printing())
   1171         return; // Don't repaint if we're printing.
   1172 
   1173     IntRect dirtyRect(r);
   1174 
   1175     // FIXME: layoutDelta needs to be applied in parts before/after transforms and
   1176     // repaint containers. https://bugs.webkit.org/show_bug.cgi?id=23308
   1177     dirtyRect.move(view->layoutDelta());
   1178 
   1179     RenderBoxModelObject* repaintContainer = containerForRepaint();
   1180     computeRectForRepaint(repaintContainer, dirtyRect);
   1181     repaintUsingContainer(repaintContainer ? repaintContainer : view, dirtyRect, immediate);
   1182 }
   1183 
   1184 bool RenderObject::repaintAfterLayoutIfNeeded(RenderBoxModelObject* repaintContainer, const IntRect& oldBounds, const IntRect& oldOutlineBox)
   1185 {
   1186     RenderView* v = view();
   1187     if (v->printing())
   1188         return false; // Don't repaint if we're printing.
   1189 
   1190     IntRect newBounds = clippedOverflowRectForRepaint(repaintContainer);
   1191     IntRect newOutlineBox;
   1192 
   1193     bool fullRepaint = selfNeedsLayout();
   1194     // Presumably a background or a border exists if border-fit:lines was specified.
   1195     if (!fullRepaint && style()->borderFit() == BorderFitLines)
   1196         fullRepaint = true;
   1197     if (!fullRepaint) {
   1198         newOutlineBox = outlineBoundsForRepaint(repaintContainer);
   1199         if (newOutlineBox.location() != oldOutlineBox.location() || (mustRepaintBackgroundOrBorder() && (newBounds != oldBounds || newOutlineBox != oldOutlineBox)))
   1200             fullRepaint = true;
   1201     }
   1202 
   1203     if (!repaintContainer)
   1204         repaintContainer = v;
   1205 
   1206     if (fullRepaint) {
   1207         repaintUsingContainer(repaintContainer, oldBounds);
   1208         if (newBounds != oldBounds)
   1209             repaintUsingContainer(repaintContainer, newBounds);
   1210         return true;
   1211     }
   1212 
   1213     if (newBounds == oldBounds && newOutlineBox == oldOutlineBox)
   1214         return false;
   1215 
   1216     int deltaLeft = newBounds.x() - oldBounds.x();
   1217     if (deltaLeft > 0)
   1218         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), deltaLeft, oldBounds.height()));
   1219     else if (deltaLeft < 0)
   1220         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), -deltaLeft, newBounds.height()));
   1221 
   1222     int deltaRight = newBounds.right() - oldBounds.right();
   1223     if (deltaRight > 0)
   1224         repaintUsingContainer(repaintContainer, IntRect(oldBounds.right(), newBounds.y(), deltaRight, newBounds.height()));
   1225     else if (deltaRight < 0)
   1226         repaintUsingContainer(repaintContainer, IntRect(newBounds.right(), oldBounds.y(), -deltaRight, oldBounds.height()));
   1227 
   1228     int deltaTop = newBounds.y() - oldBounds.y();
   1229     if (deltaTop > 0)
   1230         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), oldBounds.y(), oldBounds.width(), deltaTop));
   1231     else if (deltaTop < 0)
   1232         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), newBounds.y(), newBounds.width(), -deltaTop));
   1233 
   1234     int deltaBottom = newBounds.bottom() - oldBounds.bottom();
   1235     if (deltaBottom > 0)
   1236         repaintUsingContainer(repaintContainer, IntRect(newBounds.x(), oldBounds.bottom(), newBounds.width(), deltaBottom));
   1237     else if (deltaBottom < 0)
   1238         repaintUsingContainer(repaintContainer, IntRect(oldBounds.x(), newBounds.bottom(), oldBounds.width(), -deltaBottom));
   1239 
   1240     if (newOutlineBox == oldOutlineBox)
   1241         return false;
   1242 
   1243     // We didn't move, but we did change size.  Invalidate the delta, which will consist of possibly
   1244     // two rectangles (but typically only one).
   1245     RenderStyle* outlineStyle = outlineStyleForRepaint();
   1246     int ow = outlineStyle->outlineSize();
   1247     int width = abs(newOutlineBox.width() - oldOutlineBox.width());
   1248     if (width) {
   1249         int shadowLeft;
   1250         int shadowRight;
   1251         style()->getBoxShadowHorizontalExtent(shadowLeft, shadowRight);
   1252 
   1253         int borderRight = isBox() ? toRenderBox(this)->borderRight() : 0;
   1254         int borderWidth = max(-outlineStyle->outlineOffset(), max(borderRight, max(style()->borderTopRightRadius().width(), style()->borderBottomRightRadius().width()))) + max(ow, shadowRight);
   1255         IntRect rightRect(newOutlineBox.x() + min(newOutlineBox.width(), oldOutlineBox.width()) - borderWidth,
   1256             newOutlineBox.y(),
   1257             width + borderWidth,
   1258             max(newOutlineBox.height(), oldOutlineBox.height()));
   1259         int right = min(newBounds.right(), oldBounds.right());
   1260         if (rightRect.x() < right) {
   1261             rightRect.setWidth(min(rightRect.width(), right - rightRect.x()));
   1262             repaintUsingContainer(repaintContainer, rightRect);
   1263         }
   1264     }
   1265     int height = abs(newOutlineBox.height() - oldOutlineBox.height());
   1266     if (height) {
   1267         int shadowTop;
   1268         int shadowBottom;
   1269         style()->getBoxShadowVerticalExtent(shadowTop, shadowBottom);
   1270 
   1271         int borderBottom = isBox() ? toRenderBox(this)->borderBottom() : 0;
   1272         int borderHeight = max(-outlineStyle->outlineOffset(), max(borderBottom, max(style()->borderBottomLeftRadius().height(), style()->borderBottomRightRadius().height()))) + max(ow, shadowBottom);
   1273         IntRect bottomRect(newOutlineBox.x(),
   1274             min(newOutlineBox.bottom(), oldOutlineBox.bottom()) - borderHeight,
   1275             max(newOutlineBox.width(), oldOutlineBox.width()),
   1276             height + borderHeight);
   1277         int bottom = min(newBounds.bottom(), oldBounds.bottom());
   1278         if (bottomRect.y() < bottom) {
   1279             bottomRect.setHeight(min(bottomRect.height(), bottom - bottomRect.y()));
   1280             repaintUsingContainer(repaintContainer, bottomRect);
   1281         }
   1282     }
   1283     return false;
   1284 }
   1285 
   1286 void RenderObject::repaintDuringLayoutIfMoved(const IntRect&)
   1287 {
   1288 }
   1289 
   1290 void RenderObject::repaintOverhangingFloats(bool)
   1291 {
   1292 }
   1293 
   1294 bool RenderObject::checkForRepaintDuringLayout() const
   1295 {
   1296     // FIXME: <https://bugs.webkit.org/show_bug.cgi?id=20885> It is probably safe to also require
   1297     // m_everHadLayout. Currently, only RenderBlock::layoutBlock() adds this condition. See also
   1298     // <https://bugs.webkit.org/show_bug.cgi?id=15129>.
   1299     return !document()->view()->needsFullRepaint() && !hasLayer();
   1300 }
   1301 
   1302 IntRect RenderObject::rectWithOutlineForRepaint(RenderBoxModelObject* repaintContainer, int outlineWidth)
   1303 {
   1304     IntRect r(clippedOverflowRectForRepaint(repaintContainer));
   1305     r.inflate(outlineWidth);
   1306     return r;
   1307 }
   1308 
   1309 IntRect RenderObject::clippedOverflowRectForRepaint(RenderBoxModelObject*)
   1310 {
   1311     ASSERT_NOT_REACHED();
   1312     return IntRect();
   1313 }
   1314 
   1315 void RenderObject::computeRectForRepaint(RenderBoxModelObject* repaintContainer, IntRect& rect, bool fixed)
   1316 {
   1317     if (repaintContainer == this)
   1318         return;
   1319 
   1320     if (RenderObject* o = parent()) {
   1321         if (o->isBlockFlow()) {
   1322             RenderBlock* cb = toRenderBlock(o);
   1323             if (cb->hasColumns())
   1324                 cb->adjustRectForColumns(rect);
   1325         }
   1326 
   1327         if (o->hasOverflowClip()) {
   1328             // o->height() is inaccurate if we're in the middle of a layout of |o|, so use the
   1329             // layer's size instead.  Even if the layer's size is wrong, the layer itself will repaint
   1330             // anyway if its size does change.
   1331             RenderBox* boxParent = toRenderBox(o);
   1332 
   1333             IntRect boxRect(0, 0, boxParent->layer()->width(), boxParent->layer()->height());
   1334             int x = rect.x();
   1335             int y = rect.y();
   1336             boxParent->layer()->subtractScrolledContentOffset(x, y); // For overflow:auto/scroll/hidden.
   1337             IntRect repaintRect(x, y, rect.width(), rect.height());
   1338             rect = intersection(repaintRect, boxRect);
   1339             if (rect.isEmpty())
   1340                 return;
   1341         }
   1342 
   1343         o->computeRectForRepaint(repaintContainer, rect, fixed);
   1344     }
   1345 }
   1346 
   1347 void RenderObject::dirtyLinesFromChangedChild(RenderObject*)
   1348 {
   1349 }
   1350 
   1351 #ifndef NDEBUG
   1352 
   1353 void RenderObject::showTreeForThis() const
   1354 {
   1355     if (node())
   1356         node()->showTreeForThis();
   1357 }
   1358 
   1359 void RenderObject::showRenderObject() const
   1360 {
   1361     showRenderObject(0);
   1362 }
   1363 
   1364 void RenderObject::showRenderObject(int printedCharacters) const
   1365 {
   1366     // As this function is intended to be used when debugging, the
   1367     // this pointer may be 0.
   1368     if (!this) {
   1369         fputs("(null)\n", stderr);
   1370         return;
   1371     }
   1372 
   1373     printedCharacters += fprintf(stderr, "%s %p", renderName(), this);
   1374 
   1375     if (node()) {
   1376         if (printedCharacters)
   1377             for (; printedCharacters < 39; printedCharacters++)
   1378                 fputc(' ', stderr);
   1379         fputc('\t', stderr);
   1380         node()->showNode();
   1381     } else
   1382         fputc('\n', stderr);
   1383 }
   1384 
   1385 void RenderObject::showRenderTreeAndMark(const RenderObject* markedObject1, const char* markedLabel1, const RenderObject* markedObject2, const char* markedLabel2, int depth) const
   1386 {
   1387     int printedCharacters = 0;
   1388     if (markedObject1 == this && markedLabel1)
   1389         printedCharacters += fprintf(stderr, "%s", markedLabel1);
   1390     if (markedObject2 == this && markedLabel2)
   1391         printedCharacters += fprintf(stderr, "%s", markedLabel2);
   1392     for (; printedCharacters < depth * 2; printedCharacters++)
   1393         fputc(' ', stderr);
   1394 
   1395     showRenderObject(printedCharacters);
   1396     if (!this)
   1397         return;
   1398 
   1399     for (const RenderObject* child = firstChild(); child; child = child->nextSibling())
   1400         child->showRenderTreeAndMark(markedObject1, markedLabel1, markedObject2, markedLabel2, depth + 1);
   1401 }
   1402 
   1403 #endif // NDEBUG
   1404 
   1405 Color RenderObject::selectionBackgroundColor() const
   1406 {
   1407     Color color;
   1408     if (style()->userSelect() != SELECT_NONE) {
   1409          RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION);
   1410         if (pseudoStyle && pseudoStyle->backgroundColor().isValid())
   1411             color = pseudoStyle->backgroundColor().blendWithWhite();
   1412         else
   1413             color = document()->frame()->selection()->isFocusedAndActive() ?
   1414                     theme()->activeSelectionBackgroundColor() :
   1415                     theme()->inactiveSelectionBackgroundColor();
   1416     }
   1417 
   1418     return color;
   1419 }
   1420 
   1421 Color RenderObject::selectionForegroundColor() const
   1422 {
   1423     Color color;
   1424     if (style()->userSelect() == SELECT_NONE)
   1425         return color;
   1426 
   1427     if (RefPtr<RenderStyle> pseudoStyle = getUncachedPseudoStyle(SELECTION)) {
   1428         color = pseudoStyle->textFillColor();
   1429         if (!color.isValid())
   1430             color = pseudoStyle->color();
   1431     } else
   1432         color = document()->frame()->selection()->isFocusedAndActive() ?
   1433                 theme()->activeSelectionForegroundColor() :
   1434                 theme()->inactiveSelectionForegroundColor();
   1435 
   1436     return color;
   1437 }
   1438 
   1439 #if ENABLE(DRAG_SUPPORT)
   1440 Node* RenderObject::draggableNode(bool dhtmlOK, bool uaOK, int x, int y, bool& dhtmlWillDrag) const
   1441 {
   1442     if (!dhtmlOK && !uaOK)
   1443         return 0;
   1444 
   1445     for (const RenderObject* curr = this; curr; curr = curr->parent()) {
   1446         Node* elt = curr->node();
   1447         if (elt && elt->nodeType() == Node::TEXT_NODE) {
   1448             // Since there's no way for the author to address the -webkit-user-drag style for a text node,
   1449             // we use our own judgement.
   1450             if (uaOK && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
   1451                 dhtmlWillDrag = false;
   1452                 return curr->node();
   1453             }
   1454             if (elt->canStartSelection())
   1455                 // In this case we have a click in the unselected portion of text.  If this text is
   1456                 // selectable, we want to start the selection process instead of looking for a parent
   1457                 // to try to drag.
   1458                 return 0;
   1459         } else {
   1460             EUserDrag dragMode = curr->style()->userDrag();
   1461             if (dhtmlOK && dragMode == DRAG_ELEMENT) {
   1462                 dhtmlWillDrag = true;
   1463                 return curr->node();
   1464             }
   1465             if (uaOK && dragMode == DRAG_AUTO
   1466                     && view()->frameView()->frame()->eventHandler()->shouldDragAutoNode(curr->node(), IntPoint(x, y))) {
   1467                 dhtmlWillDrag = false;
   1468                 return curr->node();
   1469             }
   1470         }
   1471     }
   1472     return 0;
   1473 }
   1474 #endif // ENABLE(DRAG_SUPPORT)
   1475 
   1476 void RenderObject::selectionStartEnd(int& spos, int& epos) const
   1477 {
   1478     view()->selectionStartEnd(spos, epos);
   1479 }
   1480 
   1481 void RenderObject::handleDynamicFloatPositionChange()
   1482 {
   1483     // We have gone from not affecting the inline status of the parent flow to suddenly
   1484     // having an impact.  See if there is a mismatch between the parent flow's
   1485     // childrenInline() state and our state.
   1486     setInline(style()->isDisplayInlineType());
   1487     if (isInline() != parent()->childrenInline()) {
   1488         if (!isInline())
   1489             toRenderBoxModelObject(parent())->childBecameNonInline(this);
   1490         else {
   1491             // An anonymous block must be made to wrap this inline.
   1492             RenderBlock* block = toRenderBlock(parent())->createAnonymousBlock();
   1493             RenderObjectChildList* childlist = parent()->virtualChildren();
   1494             childlist->insertChildNode(parent(), block, this);
   1495             block->children()->appendChildNode(block, childlist->removeChildNode(parent(), this));
   1496         }
   1497     }
   1498 }
   1499 
   1500 void RenderObject::setAnimatableStyle(PassRefPtr<RenderStyle> style)
   1501 {
   1502     if (!isText() && style)
   1503         setStyle(animation()->updateAnimations(this, style.get()));
   1504     else
   1505         setStyle(style);
   1506 }
   1507 
   1508 StyleDifference RenderObject::adjustStyleDifference(StyleDifference diff, unsigned contextSensitiveProperties) const
   1509 {
   1510 #if USE(ACCELERATED_COMPOSITING)
   1511     // If transform changed, and we are not composited, need to do a layout.
   1512     if (contextSensitiveProperties & ContextSensitivePropertyTransform) {
   1513         // Text nodes share style with their parents but transforms don't apply to them,
   1514         // hence the !isText() check.
   1515         // FIXME: when transforms are taken into account for overflow, we will need to do a layout.
   1516         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
   1517             diff = StyleDifferenceLayout;
   1518         else if (diff < StyleDifferenceRecompositeLayer)
   1519             diff = StyleDifferenceRecompositeLayer;
   1520     }
   1521 
   1522     // If opacity changed, and we are not composited, need to repaint (also
   1523     // ignoring text nodes)
   1524     if (contextSensitiveProperties & ContextSensitivePropertyOpacity) {
   1525         if (!isText() && (!hasLayer() || !toRenderBoxModelObject(this)->layer()->isComposited()))
   1526             diff = StyleDifferenceRepaintLayer;
   1527         else if (diff < StyleDifferenceRecompositeLayer)
   1528             diff = StyleDifferenceRecompositeLayer;
   1529     }
   1530 #else
   1531     UNUSED_PARAM(contextSensitiveProperties);
   1532 #endif
   1533 
   1534     // If we have no layer(), just treat a RepaintLayer hint as a normal Repaint.
   1535     if (diff == StyleDifferenceRepaintLayer && !hasLayer())
   1536         diff = StyleDifferenceRepaint;
   1537 
   1538     return diff;
   1539 }
   1540 
   1541 void RenderObject::setStyle(PassRefPtr<RenderStyle> style)
   1542 {
   1543     if (m_style == style)
   1544         return;
   1545 
   1546     StyleDifference diff = StyleDifferenceEqual;
   1547     unsigned contextSensitiveProperties = ContextSensitivePropertyNone;
   1548     if (m_style)
   1549         diff = m_style->diff(style.get(), contextSensitiveProperties);
   1550 
   1551     diff = adjustStyleDifference(diff, contextSensitiveProperties);
   1552 
   1553     styleWillChange(diff, style.get());
   1554 
   1555     RefPtr<RenderStyle> oldStyle = m_style.release();
   1556     m_style = style;
   1557 
   1558     updateFillImages(oldStyle ? oldStyle->backgroundLayers() : 0, m_style ? m_style->backgroundLayers() : 0);
   1559     updateFillImages(oldStyle ? oldStyle->maskLayers() : 0, m_style ? m_style->maskLayers() : 0);
   1560 
   1561     updateImage(oldStyle ? oldStyle->borderImage().image() : 0, m_style ? m_style->borderImage().image() : 0);
   1562     updateImage(oldStyle ? oldStyle->maskBoxImage().image() : 0, m_style ? m_style->maskBoxImage().image() : 0);
   1563 
   1564     // We need to ensure that view->maximalOutlineSize() is valid for any repaints that happen
   1565     // during styleDidChange (it's used by clippedOverflowRectForRepaint()).
   1566     if (m_style->outlineWidth() > 0 && m_style->outlineSize() > maximalOutlineSize(PaintPhaseOutline))
   1567         toRenderView(document()->renderer())->setMaximalOutlineSize(m_style->outlineSize());
   1568 
   1569     styleDidChange(diff, oldStyle.get());
   1570 
   1571     if (!m_parent || isText())
   1572         return;
   1573 
   1574     // Now that the layer (if any) has been updated, we need to adjust the diff again,
   1575     // check whether we should layout now, and decide if we need to repaint.
   1576     StyleDifference updatedDiff = adjustStyleDifference(diff, contextSensitiveProperties);
   1577 
   1578     if (diff <= StyleDifferenceLayoutPositionedMovementOnly) {
   1579         if (updatedDiff == StyleDifferenceLayout)
   1580             setNeedsLayoutAndPrefWidthsRecalc();
   1581         else if (updatedDiff == StyleDifferenceLayoutPositionedMovementOnly)
   1582             setNeedsPositionedMovementLayout();
   1583     }
   1584 
   1585     if (updatedDiff == StyleDifferenceRepaintLayer || updatedDiff == StyleDifferenceRepaint) {
   1586         // Do a repaint with the new style now, e.g., for example if we go from
   1587         // not having an outline to having an outline.
   1588         repaint();
   1589     }
   1590 }
   1591 
   1592 void RenderObject::setStyleInternal(PassRefPtr<RenderStyle> style)
   1593 {
   1594     m_style = style;
   1595 }
   1596 
   1597 void RenderObject::styleWillChange(StyleDifference diff, const RenderStyle* newStyle)
   1598 {
   1599     if (m_style) {
   1600         // If our z-index changes value or our visibility changes,
   1601         // we need to dirty our stacking context's z-order list.
   1602         if (newStyle) {
   1603             bool visibilityChanged = m_style->visibility() != newStyle->visibility()
   1604                 || m_style->zIndex() != newStyle->zIndex()
   1605                 || m_style->hasAutoZIndex() != newStyle->hasAutoZIndex();
   1606 #if ENABLE(DASHBOARD_SUPPORT)
   1607             if (visibilityChanged)
   1608                 document()->setDashboardRegionsDirty(true);
   1609 #endif
   1610             if (visibilityChanged && AXObjectCache::accessibilityEnabled())
   1611                 document()->axObjectCache()->childrenChanged(this);
   1612 
   1613             // Keep layer hierarchy visibility bits up to date if visibility changes.
   1614             if (m_style->visibility() != newStyle->visibility()) {
   1615                 if (RenderLayer* l = enclosingLayer()) {
   1616                     if (newStyle->visibility() == VISIBLE)
   1617                         l->setHasVisibleContent(true);
   1618                     else if (l->hasVisibleContent() && (this == l->renderer() || l->renderer()->style()->visibility() != VISIBLE)) {
   1619                         l->dirtyVisibleContentStatus();
   1620                         if (diff > StyleDifferenceRepaintLayer)
   1621                             repaint();
   1622                     }
   1623                 }
   1624             }
   1625         }
   1626 
   1627         if (m_parent && (diff == StyleDifferenceRepaint || newStyle->outlineSize() < m_style->outlineSize()))
   1628             repaint();
   1629         if (isFloating() && (m_style->floating() != newStyle->floating()))
   1630             // For changes in float styles, we need to conceivably remove ourselves
   1631             // from the floating objects list.
   1632             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
   1633         else if (isPositioned() && (m_style->position() != newStyle->position()))
   1634             // For changes in positioning styles, we need to conceivably remove ourselves
   1635             // from the positioned objects list.
   1636             toRenderBox(this)->removeFloatingOrPositionedChildFromBlockLists();
   1637 
   1638         s_affectsParentBlock = isFloatingOrPositioned() &&
   1639             (!newStyle->isFloating() && newStyle->position() != AbsolutePosition && newStyle->position() != FixedPosition)
   1640             && parent() && (parent()->isBlockFlow() || parent()->isRenderInline());
   1641 
   1642         // reset style flags
   1643         if (diff == StyleDifferenceLayout || diff == StyleDifferenceLayoutPositionedMovementOnly) {
   1644             m_floating = false;
   1645             m_positioned = false;
   1646             m_relPositioned = false;
   1647         }
   1648         m_paintBackground = false;
   1649         m_hasOverflowClip = false;
   1650         m_hasTransform = false;
   1651         m_hasReflection = false;
   1652     } else
   1653         s_affectsParentBlock = false;
   1654 
   1655     if (view()->frameView()) {
   1656         // FIXME: A better solution would be to only invalidate the fixed regions when scrolling.  It's overkill to
   1657         // prevent the entire view from blitting on a scroll.
   1658 
   1659         bool shouldBlitOnFixedBackgroundImage = false;
   1660 #if ENABLE(FAST_MOBILE_SCROLLING)
   1661         // On low-powered/mobile devices, preventing blitting on a scroll can cause noticeable delays
   1662         // when scrolling a page with a fixed background image. As an optimization, assuming there are
   1663         // no fixed positoned elements on the page, we can acclerate scrolling (via blitting) if we
   1664         // ignore the CSS property "background-attachment: fixed".
   1665         shouldBlitOnFixedBackgroundImage = true;
   1666 #endif
   1667 
   1668         bool newStyleSlowScroll = newStyle && (newStyle->position() == FixedPosition
   1669                                                || (!shouldBlitOnFixedBackgroundImage && newStyle->hasFixedBackgroundImage()));
   1670         bool oldStyleSlowScroll = m_style && (m_style->position() == FixedPosition
   1671                                                || (!shouldBlitOnFixedBackgroundImage && m_style->hasFixedBackgroundImage()));
   1672         if (oldStyleSlowScroll != newStyleSlowScroll) {
   1673             if (oldStyleSlowScroll)
   1674                 view()->frameView()->removeSlowRepaintObject();
   1675             if (newStyleSlowScroll)
   1676                 view()->frameView()->addSlowRepaintObject();
   1677         }
   1678     }
   1679 }
   1680 
   1681 void RenderObject::styleDidChange(StyleDifference diff, const RenderStyle* oldStyle)
   1682 {
   1683     if (s_affectsParentBlock)
   1684         handleDynamicFloatPositionChange();
   1685 
   1686     if (!m_parent)
   1687         return;
   1688 
   1689     if (diff == StyleDifferenceLayout) {
   1690         RenderCounter::rendererStyleChanged(this, oldStyle, m_style.get());
   1691 
   1692         // If the object already needs layout, then setNeedsLayout won't do
   1693         // any work. But if the containing block has changed, then we may need
   1694         // to mark the new containing blocks for layout. The change that can
   1695         // directly affect the containing block of this object is a change to
   1696         // the position style.
   1697         if (m_needsLayout && oldStyle->position() != m_style->position())
   1698             markContainingBlocksForLayout();
   1699 
   1700         setNeedsLayoutAndPrefWidthsRecalc();
   1701     } else if (diff == StyleDifferenceLayoutPositionedMovementOnly)
   1702         setNeedsPositionedMovementLayout();
   1703 
   1704     // Don't check for repaint here; we need to wait until the layer has been
   1705     // updated by subclasses before we know if we have to repaint (in setStyle()).
   1706 }
   1707 
   1708 void RenderObject::updateFillImages(const FillLayer* oldLayers, const FillLayer* newLayers)
   1709 {
   1710     // Optimize the common case
   1711     if (oldLayers && !oldLayers->next() && newLayers && !newLayers->next() && (oldLayers->image() == newLayers->image()))
   1712         return;
   1713 
   1714     // Go through the new layers and addClients first, to avoid removing all clients of an image.
   1715     for (const FillLayer* currNew = newLayers; currNew; currNew = currNew->next()) {
   1716         if (currNew->image())
   1717             currNew->image()->addClient(this);
   1718     }
   1719 
   1720     for (const FillLayer* currOld = oldLayers; currOld; currOld = currOld->next()) {
   1721         if (currOld->image())
   1722             currOld->image()->removeClient(this);
   1723     }
   1724 }
   1725 
   1726 void RenderObject::updateImage(StyleImage* oldImage, StyleImage* newImage)
   1727 {
   1728     if (oldImage != newImage) {
   1729         if (oldImage)
   1730             oldImage->removeClient(this);
   1731         if (newImage)
   1732             newImage->addClient(this);
   1733     }
   1734 }
   1735 
   1736 IntRect RenderObject::viewRect() const
   1737 {
   1738     return view()->viewRect();
   1739 }
   1740 
   1741 FloatPoint RenderObject::localToAbsolute(FloatPoint localPoint, bool fixed, bool useTransforms) const
   1742 {
   1743     TransformState transformState(TransformState::ApplyTransformDirection, localPoint);
   1744     mapLocalToContainer(0, fixed, useTransforms, transformState);
   1745     transformState.flatten();
   1746 
   1747     return transformState.lastPlanarPoint();
   1748 }
   1749 
   1750 FloatPoint RenderObject::absoluteToLocal(FloatPoint containerPoint, bool fixed, bool useTransforms) const
   1751 {
   1752     TransformState transformState(TransformState::UnapplyInverseTransformDirection, containerPoint);
   1753     mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
   1754     transformState.flatten();
   1755 
   1756     return transformState.lastPlanarPoint();
   1757 }
   1758 
   1759 void RenderObject::mapLocalToContainer(RenderBoxModelObject* repaintContainer, bool fixed, bool useTransforms, TransformState& transformState) const
   1760 {
   1761     if (repaintContainer == this)
   1762         return;
   1763 
   1764     RenderObject* o = parent();
   1765     if (!o)
   1766         return;
   1767 
   1768     if (o->hasOverflowClip())
   1769         transformState.move(-toRenderBox(o)->layer()->scrolledContentOffset());
   1770 
   1771     o->mapLocalToContainer(repaintContainer, fixed, useTransforms, transformState);
   1772 }
   1773 
   1774 void RenderObject::mapAbsoluteToLocalPoint(bool fixed, bool useTransforms, TransformState& transformState) const
   1775 {
   1776     RenderObject* o = parent();
   1777     if (o) {
   1778         o->mapAbsoluteToLocalPoint(fixed, useTransforms, transformState);
   1779         if (o->hasOverflowClip())
   1780             transformState.move(toRenderBox(o)->layer()->scrolledContentOffset());
   1781     }
   1782 }
   1783 
   1784 bool RenderObject::shouldUseTransformFromContainer(const RenderObject* containerObject) const
   1785 {
   1786 #if ENABLE(3D_RENDERING)
   1787     // hasTransform() indicates whether the object has transform, transform-style or perspective. We just care about transform,
   1788     // so check the layer's transform directly.
   1789     return (hasLayer() && toRenderBoxModelObject(this)->layer()->transform()) || (containerObject && containerObject->style()->hasPerspective());
   1790 #else
   1791     UNUSED_PARAM(containerObject);
   1792     return hasTransform();
   1793 #endif
   1794 }
   1795 
   1796 void RenderObject::getTransformFromContainer(const RenderObject* containerObject, const IntSize& offsetInContainer, TransformationMatrix& transform) const
   1797 {
   1798     transform.makeIdentity();
   1799     transform.translate(offsetInContainer.width(), offsetInContainer.height());
   1800     RenderLayer* layer;
   1801     if (hasLayer() && (layer = toRenderBoxModelObject(this)->layer()) && layer->transform())
   1802         transform.multLeft(layer->currentTransform());
   1803 
   1804 #if ENABLE(3D_RENDERING)
   1805     if (containerObject && containerObject->hasLayer() && containerObject->style()->hasPerspective()) {
   1806         // Perpsective on the container affects us, so we have to factor it in here.
   1807         ASSERT(containerObject->hasLayer());
   1808         FloatPoint perspectiveOrigin = toRenderBox(containerObject)->layer()->perspectiveOrigin();
   1809 
   1810         TransformationMatrix perspectiveMatrix;
   1811         perspectiveMatrix.applyPerspective(containerObject->style()->perspective());
   1812 
   1813         transform.translateRight3d(-perspectiveOrigin.x(), -perspectiveOrigin.y(), 0);
   1814         transform.multiply(perspectiveMatrix);
   1815         transform.translateRight3d(perspectiveOrigin.x(), perspectiveOrigin.y(), 0);
   1816     }
   1817 #else
   1818     UNUSED_PARAM(containerObject);
   1819 #endif
   1820 }
   1821 
   1822 FloatQuad RenderObject::localToContainerQuad(const FloatQuad& localQuad, RenderBoxModelObject* repaintContainer, bool fixed) const
   1823 {
   1824     TransformState transformState(TransformState::ApplyTransformDirection, FloatPoint(), &localQuad);
   1825     mapLocalToContainer(repaintContainer, fixed, true, transformState);
   1826     transformState.flatten();
   1827 
   1828     return transformState.lastPlanarQuad();
   1829 }
   1830 
   1831 IntSize RenderObject::offsetFromContainer(RenderObject* o) const
   1832 {
   1833     ASSERT(o == container());
   1834 
   1835     IntSize offset;
   1836     if (o->hasOverflowClip())
   1837         offset -= toRenderBox(o)->layer()->scrolledContentOffset();
   1838 
   1839     return offset;
   1840 }
   1841 
   1842 IntSize RenderObject::offsetFromAncestorContainer(RenderObject* container) const
   1843 {
   1844     IntSize offset;
   1845     const RenderObject* currContainer = this;
   1846     do {
   1847         RenderObject* nextContainer = currContainer->container();
   1848         ASSERT(nextContainer);  // This means we reached the top without finding container.
   1849         if (!nextContainer)
   1850             break;
   1851         ASSERT(!currContainer->hasTransform());
   1852         offset += currContainer->offsetFromContainer(nextContainer);
   1853         currContainer = nextContainer;
   1854     } while (currContainer != container);
   1855 
   1856     return offset;
   1857 }
   1858 
   1859 IntRect RenderObject::localCaretRect(InlineBox*, int, int* extraWidthToEndOfLine)
   1860 {
   1861     if (extraWidthToEndOfLine)
   1862         *extraWidthToEndOfLine = 0;
   1863 
   1864     return IntRect();
   1865 }
   1866 
   1867 RenderView* RenderObject::view() const
   1868 {
   1869     return toRenderView(document()->renderer());
   1870 }
   1871 
   1872 bool RenderObject::isRooted(RenderView** view)
   1873 {
   1874     RenderObject* o = this;
   1875     while (o->parent())
   1876         o = o->parent();
   1877 
   1878     if (!o->isRenderView())
   1879         return false;
   1880 
   1881     if (view)
   1882         *view = toRenderView(o);
   1883 
   1884     return true;
   1885 }
   1886 
   1887 bool RenderObject::hasOutlineAnnotation() const
   1888 {
   1889     return node() && node()->isLink() && document()->printing();
   1890 }
   1891 
   1892 RenderObject* RenderObject::container(RenderBoxModelObject* repaintContainer, bool* repaintContainerSkipped) const
   1893 {
   1894     if (repaintContainerSkipped)
   1895         *repaintContainerSkipped = false;
   1896 
   1897     // This method is extremely similar to containingBlock(), but with a few notable
   1898     // exceptions.
   1899     // (1) It can be used on orphaned subtrees, i.e., it can be called safely even when
   1900     // the object is not part of the primary document subtree yet.
   1901     // (2) For normal flow elements, it just returns the parent.
   1902     // (3) For absolute positioned elements, it will return a relative positioned inline.
   1903     // containingBlock() simply skips relpositioned inlines and lets an enclosing block handle
   1904     // the layout of the positioned object.  This does mean that calcAbsoluteHorizontal and
   1905     // calcAbsoluteVertical have to use container().
   1906     RenderObject* o = parent();
   1907 
   1908     if (isText())
   1909         return o;
   1910 
   1911     EPosition pos = m_style->position();
   1912     if (pos == FixedPosition) {
   1913         // container() can be called on an object that is not in the
   1914         // tree yet.  We don't call view() since it will assert if it
   1915         // can't get back to the canvas.  Instead we just walk as high up
   1916         // as we can.  If we're in the tree, we'll get the root.  If we
   1917         // aren't we'll get the root of our little subtree (most likely
   1918         // we'll just return 0).
   1919         // FIXME: The definition of view() has changed to not crawl up the render tree.  It might
   1920         // be safe now to use it.
   1921         while (o && o->parent() && !(o->hasTransform() && o->isRenderBlock())) {
   1922             if (repaintContainerSkipped && o == repaintContainer)
   1923                 *repaintContainerSkipped = true;
   1924             o = o->parent();
   1925         }
   1926     } else if (pos == AbsolutePosition) {
   1927         // Same goes here.  We technically just want our containing block, but
   1928         // we may not have one if we're part of an uninstalled subtree.  We'll
   1929         // climb as high as we can though.
   1930         while (o && o->style()->position() == StaticPosition && !o->isRenderView() && !(o->hasTransform() && o->isRenderBlock())) {
   1931             if (repaintContainerSkipped && o == repaintContainer)
   1932                 *repaintContainerSkipped = true;
   1933             o = o->parent();
   1934         }
   1935     }
   1936 
   1937     return o;
   1938 }
   1939 
   1940 bool RenderObject::isSelectionBorder() const
   1941 {
   1942     SelectionState st = selectionState();
   1943     return st == SelectionStart || st == SelectionEnd || st == SelectionBoth;
   1944 }
   1945 
   1946 void RenderObject::destroy()
   1947 {
   1948     // Destroy any leftover anonymous children.
   1949     RenderObjectChildList* children = virtualChildren();
   1950     if (children)
   1951         children->destroyLeftoverChildren();
   1952 
   1953     // If this renderer is being autoscrolled, stop the autoscroll timer
   1954 
   1955     // FIXME: RenderObject::destroy should not get called with a renderer whose document
   1956     // has a null frame, so we assert this. However, we don't want release builds to crash which is why we
   1957     // check that the frame is not null.
   1958     ASSERT(document()->frame());
   1959     if (document()->frame() && document()->frame()->eventHandler()->autoscrollRenderer() == this)
   1960         document()->frame()->eventHandler()->stopAutoscrollTimer(true);
   1961 
   1962     if (m_hasCounterNodeMap)
   1963         RenderCounter::destroyCounterNodes(this);
   1964 
   1965     if (AXObjectCache::accessibilityEnabled()) {
   1966         document()->axObjectCache()->childrenChanged(this->parent());
   1967         document()->axObjectCache()->remove(this);
   1968     }
   1969     animation()->cancelAnimations(this);
   1970 
   1971     // By default no ref-counting. RenderWidget::destroy() doesn't call
   1972     // this function because it needs to do ref-counting. If anything
   1973     // in this function changes, be sure to fix RenderWidget::destroy() as well.
   1974 
   1975     remove();
   1976 
   1977     // FIXME: Would like to do this in RenderBoxModelObject, but the timing is so complicated that this can't easily
   1978     // be moved into RenderBoxModelObject::destroy.
   1979     if (hasLayer()) {
   1980         setHasLayer(false);
   1981         toRenderBoxModelObject(this)->destroyLayer();
   1982     }
   1983     arenaDelete(renderArena(), this);
   1984 }
   1985 
   1986 void RenderObject::arenaDelete(RenderArena* arena, void* base)
   1987 {
   1988     if (m_style) {
   1989         for (const FillLayer* bgLayer = m_style->backgroundLayers(); bgLayer; bgLayer = bgLayer->next()) {
   1990             if (StyleImage* backgroundImage = bgLayer->image())
   1991                 backgroundImage->removeClient(this);
   1992         }
   1993 
   1994         for (const FillLayer* maskLayer = m_style->maskLayers(); maskLayer; maskLayer = maskLayer->next()) {
   1995             if (StyleImage* maskImage = maskLayer->image())
   1996                 maskImage->removeClient(this);
   1997         }
   1998 
   1999         if (StyleImage* borderImage = m_style->borderImage().image())
   2000             borderImage->removeClient(this);
   2001 
   2002         if (StyleImage* maskBoxImage = m_style->maskBoxImage().image())
   2003             maskBoxImage->removeClient(this);
   2004     }
   2005 
   2006 #ifndef NDEBUG
   2007     void* savedBase = baseOfRenderObjectBeingDeleted;
   2008     baseOfRenderObjectBeingDeleted = base;
   2009 #endif
   2010     delete this;
   2011 #ifndef NDEBUG
   2012     baseOfRenderObjectBeingDeleted = savedBase;
   2013 #endif
   2014 
   2015     // Recover the size left there for us by operator delete and free the memory.
   2016     arena->free(*(size_t*)base, base);
   2017 }
   2018 
   2019 VisiblePosition RenderObject::positionForCoordinates(int x, int y)
   2020 {
   2021     return positionForPoint(IntPoint(x, y));
   2022 }
   2023 
   2024 VisiblePosition RenderObject::positionForPoint(const IntPoint&)
   2025 {
   2026     return createVisiblePosition(caretMinOffset(), DOWNSTREAM);
   2027 }
   2028 
   2029 void RenderObject::updateDragState(bool dragOn)
   2030 {
   2031     bool valueChanged = (dragOn != m_isDragging);
   2032     m_isDragging = dragOn;
   2033     if (valueChanged && style()->affectedByDragRules())
   2034         node()->setNeedsStyleRecalc();
   2035     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
   2036         curr->updateDragState(dragOn);
   2037 }
   2038 
   2039 bool RenderObject::hitTest(const HitTestRequest& request, HitTestResult& result, const IntPoint& point, int tx, int ty, HitTestFilter hitTestFilter)
   2040 {
   2041     bool inside = false;
   2042     if (hitTestFilter != HitTestSelf) {
   2043         // First test the foreground layer (lines and inlines).
   2044         inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestForeground);
   2045 
   2046         // Test floats next.
   2047         if (!inside)
   2048             inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestFloat);
   2049 
   2050         // Finally test to see if the mouse is in the background (within a child block's background).
   2051         if (!inside)
   2052             inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestChildBlockBackgrounds);
   2053     }
   2054 
   2055     // See if the mouse is inside us but not any of our descendants
   2056     if (hitTestFilter != HitTestDescendants && !inside)
   2057         inside = nodeAtPoint(request, result, point.x(), point.y(), tx, ty, HitTestBlockBackground);
   2058 
   2059     return inside;
   2060 }
   2061 
   2062 void RenderObject::updateHitTestResult(HitTestResult& result, const IntPoint& point)
   2063 {
   2064     if (result.innerNode())
   2065         return;
   2066 
   2067     Node* n = node();
   2068     if (n) {
   2069         result.setInnerNode(n);
   2070         if (!result.innerNonSharedNode())
   2071             result.setInnerNonSharedNode(n);
   2072         result.setLocalPoint(point);
   2073     }
   2074 }
   2075 
   2076 bool RenderObject::nodeAtPoint(const HitTestRequest&, HitTestResult&, int /*x*/, int /*y*/, int /*tx*/, int /*ty*/, HitTestAction)
   2077 {
   2078     return false;
   2079 }
   2080 
   2081 int RenderObject::lineHeight(bool firstLine, bool /*isRootLineBox*/) const
   2082 {
   2083     return style(firstLine)->computedLineHeight();
   2084 }
   2085 
   2086 int RenderObject::baselinePosition(bool firstLine, bool isRootLineBox) const
   2087 {
   2088     const Font& f = style(firstLine)->font();
   2089     return f.ascent() + (lineHeight(firstLine, isRootLineBox) - f.height()) / 2;
   2090 }
   2091 
   2092 void RenderObject::scheduleRelayout()
   2093 {
   2094     if (isRenderView()) {
   2095         FrameView* view = toRenderView(this)->frameView();
   2096         if (view)
   2097             view->scheduleRelayout();
   2098     } else if (parent()) {
   2099         FrameView* v = view() ? view()->frameView() : 0;
   2100         if (v)
   2101             v->scheduleRelayoutOfSubtree(this);
   2102     }
   2103 }
   2104 
   2105 void RenderObject::layout()
   2106 {
   2107     ASSERT(needsLayout());
   2108     RenderObject* child = firstChild();
   2109     while (child) {
   2110         child->layoutIfNeeded();
   2111         ASSERT(!child->needsLayout());
   2112         child = child->nextSibling();
   2113     }
   2114     setNeedsLayout(false);
   2115 }
   2116 
   2117 PassRefPtr<RenderStyle> RenderObject::uncachedFirstLineStyle(RenderStyle* style) const
   2118 {
   2119     if (!document()->usesFirstLineRules())
   2120         return 0;
   2121 
   2122     ASSERT(!isText());
   2123 
   2124     RefPtr<RenderStyle> result;
   2125 
   2126     if (isBlockFlow()) {
   2127         if (RenderBlock* firstLineBlock = this->firstLineBlock())
   2128             result = firstLineBlock->getUncachedPseudoStyle(FIRST_LINE, style, firstLineBlock == this ? style : 0);
   2129     } else if (!isAnonymous() && isRenderInline()) {
   2130         RenderStyle* parentStyle = parent()->firstLineStyle();
   2131         if (parentStyle != parent()->style())
   2132             result = getUncachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle, style);
   2133     }
   2134 
   2135     return result.release();
   2136 }
   2137 
   2138 RenderStyle* RenderObject::firstLineStyleSlowCase() const
   2139 {
   2140     ASSERT(document()->usesFirstLineRules());
   2141 
   2142     RenderStyle* style = m_style.get();
   2143     const RenderObject* renderer = isText() ? parent() : this;
   2144     if (renderer->isBlockFlow()) {
   2145         if (RenderBlock* firstLineBlock = renderer->firstLineBlock())
   2146             style = firstLineBlock->getCachedPseudoStyle(FIRST_LINE, style);
   2147     } else if (!renderer->isAnonymous() && renderer->isRenderInline()) {
   2148         RenderStyle* parentStyle = renderer->parent()->firstLineStyle();
   2149         if (parentStyle != renderer->parent()->style()) {
   2150             // A first-line style is in effect. Cache a first-line style for ourselves.
   2151             style->setHasPseudoStyle(FIRST_LINE_INHERITED);
   2152             style = renderer->getCachedPseudoStyle(FIRST_LINE_INHERITED, parentStyle);
   2153         }
   2154     }
   2155 
   2156     return style;
   2157 }
   2158 
   2159 RenderStyle* RenderObject::getCachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle) const
   2160 {
   2161     if (pseudo < FIRST_INTERNAL_PSEUDOID && !style()->hasPseudoStyle(pseudo))
   2162         return 0;
   2163 
   2164     RenderStyle* cachedStyle = style()->getCachedPseudoStyle(pseudo);
   2165     if (cachedStyle)
   2166         return cachedStyle;
   2167 
   2168     RefPtr<RenderStyle> result = getUncachedPseudoStyle(pseudo, parentStyle);
   2169     if (result)
   2170         return style()->addCachedPseudoStyle(result.release());
   2171     return 0;
   2172 }
   2173 
   2174 PassRefPtr<RenderStyle> RenderObject::getUncachedPseudoStyle(PseudoId pseudo, RenderStyle* parentStyle, RenderStyle* ownStyle) const
   2175 {
   2176     if (pseudo < FIRST_INTERNAL_PSEUDOID && !ownStyle && !style()->hasPseudoStyle(pseudo))
   2177         return 0;
   2178 
   2179     if (!parentStyle) {
   2180         ASSERT(!ownStyle);
   2181         parentStyle = style();
   2182     }
   2183 
   2184     Node* n = node();
   2185     while (n && !n->isElementNode())
   2186         n = n->parentNode();
   2187     if (!n)
   2188         return 0;
   2189 
   2190     RefPtr<RenderStyle> result;
   2191     if (pseudo == FIRST_LINE_INHERITED) {
   2192         result = document()->styleSelector()->styleForElement(static_cast<Element*>(n), parentStyle, false);
   2193         result->setStyleType(FIRST_LINE_INHERITED);
   2194     } else
   2195         result = document()->styleSelector()->pseudoStyleForElement(pseudo, static_cast<Element*>(n), parentStyle);
   2196     return result.release();
   2197 }
   2198 
   2199 static Color decorationColor(RenderStyle* style)
   2200 {
   2201     Color result;
   2202     if (style->textStrokeWidth() > 0) {
   2203         // Prefer stroke color if possible but not if it's fully transparent.
   2204         result = style->textStrokeColor();
   2205         if (!result.isValid())
   2206             result = style->color();
   2207         if (result.alpha())
   2208             return result;
   2209     }
   2210 
   2211     result = style->textFillColor();
   2212     if (!result.isValid())
   2213         result = style->color();
   2214     return result;
   2215 }
   2216 
   2217 void RenderObject::getTextDecorationColors(int decorations, Color& underline, Color& overline,
   2218                                            Color& linethrough, bool quirksMode)
   2219 {
   2220     RenderObject* curr = this;
   2221     do {
   2222         int currDecs = curr->style()->textDecoration();
   2223         if (currDecs) {
   2224             if (currDecs & UNDERLINE) {
   2225                 decorations &= ~UNDERLINE;
   2226                 underline = decorationColor(curr->style());
   2227             }
   2228             if (currDecs & OVERLINE) {
   2229                 decorations &= ~OVERLINE;
   2230                 overline = decorationColor(curr->style());
   2231             }
   2232             if (currDecs & LINE_THROUGH) {
   2233                 decorations &= ~LINE_THROUGH;
   2234                 linethrough = decorationColor(curr->style());
   2235             }
   2236         }
   2237         curr = curr->parent();
   2238         if (curr && curr->isRenderBlock() && toRenderBlock(curr)->inlineContinuation())
   2239             curr = toRenderBlock(curr)->inlineContinuation();
   2240     } while (curr && decorations && (!quirksMode || !curr->node() ||
   2241                                      (!curr->node()->hasTagName(aTag) && !curr->node()->hasTagName(fontTag))));
   2242 
   2243     // If we bailed out, use the element we bailed out at (typically a <font> or <a> element).
   2244     if (decorations && curr) {
   2245         if (decorations & UNDERLINE)
   2246             underline = decorationColor(curr->style());
   2247         if (decorations & OVERLINE)
   2248             overline = decorationColor(curr->style());
   2249         if (decorations & LINE_THROUGH)
   2250             linethrough = decorationColor(curr->style());
   2251     }
   2252 }
   2253 
   2254 #if ENABLE(DASHBOARD_SUPPORT)
   2255 void RenderObject::addDashboardRegions(Vector<DashboardRegionValue>& regions)
   2256 {
   2257     // Convert the style regions to absolute coordinates.
   2258     if (style()->visibility() != VISIBLE || !isBox())
   2259         return;
   2260 
   2261     RenderBox* box = toRenderBox(this);
   2262 
   2263     const Vector<StyleDashboardRegion>& styleRegions = style()->dashboardRegions();
   2264     unsigned i, count = styleRegions.size();
   2265     for (i = 0; i < count; i++) {
   2266         StyleDashboardRegion styleRegion = styleRegions[i];
   2267 
   2268         int w = box->width();
   2269         int h = box->height();
   2270 
   2271         DashboardRegionValue region;
   2272         region.label = styleRegion.label;
   2273         region.bounds = IntRect(styleRegion.offset.left().value(),
   2274                                 styleRegion.offset.top().value(),
   2275                                 w - styleRegion.offset.left().value() - styleRegion.offset.right().value(),
   2276                                 h - styleRegion.offset.top().value() - styleRegion.offset.bottom().value());
   2277         region.type = styleRegion.type;
   2278 
   2279         region.clip = region.bounds;
   2280         computeAbsoluteRepaintRect(region.clip);
   2281         if (region.clip.height() < 0) {
   2282             region.clip.setHeight(0);
   2283             region.clip.setWidth(0);
   2284         }
   2285 
   2286         FloatPoint absPos = localToAbsolute();
   2287         region.bounds.setX(absPos.x() + styleRegion.offset.left().value());
   2288         region.bounds.setY(absPos.y() + styleRegion.offset.top().value());
   2289 
   2290         if (document()->frame()) {
   2291             float pageScaleFactor = document()->frame()->page()->chrome()->scaleFactor();
   2292             if (pageScaleFactor != 1.0f) {
   2293                 region.bounds.scale(pageScaleFactor);
   2294                 region.clip.scale(pageScaleFactor);
   2295             }
   2296         }
   2297 
   2298         regions.append(region);
   2299     }
   2300 }
   2301 
   2302 void RenderObject::collectDashboardRegions(Vector<DashboardRegionValue>& regions)
   2303 {
   2304     // RenderTexts don't have their own style, they just use their parent's style,
   2305     // so we don't want to include them.
   2306     if (isText())
   2307         return;
   2308 
   2309     addDashboardRegions(regions);
   2310     for (RenderObject* curr = firstChild(); curr; curr = curr->nextSibling())
   2311         curr->collectDashboardRegions(regions);
   2312 }
   2313 #endif
   2314 
   2315 bool RenderObject::willRenderImage(CachedImage*)
   2316 {
   2317     // Without visibility we won't render (and therefore don't care about animation).
   2318     if (style()->visibility() != VISIBLE)
   2319         return false;
   2320 
   2321     // If we're not in a window (i.e., we're dormant from being put in the b/f cache or in a background tab)
   2322     // then we don't want to render either.
   2323     return !document()->inPageCache() && !document()->view()->isOffscreen();
   2324 }
   2325 
   2326 int RenderObject::maximalOutlineSize(PaintPhase p) const
   2327 {
   2328     if (p != PaintPhaseOutline && p != PaintPhaseSelfOutline && p != PaintPhaseChildOutlines)
   2329         return 0;
   2330     return toRenderView(document()->renderer())->maximalOutlineSize();
   2331 }
   2332 
   2333 int RenderObject::caretMinOffset() const
   2334 {
   2335     return 0;
   2336 }
   2337 
   2338 int RenderObject::caretMaxOffset() const
   2339 {
   2340     if (isReplaced())
   2341         return node() ? max(1U, node()->childNodeCount()) : 1;
   2342     if (isHR())
   2343         return 1;
   2344     return 0;
   2345 }
   2346 
   2347 unsigned RenderObject::caretMaxRenderedOffset() const
   2348 {
   2349     return 0;
   2350 }
   2351 
   2352 int RenderObject::previousOffset(int current) const
   2353 {
   2354     return current - 1;
   2355 }
   2356 
   2357 int RenderObject::previousOffsetForBackwardDeletion(int current) const
   2358 {
   2359     return current - 1;
   2360 }
   2361 
   2362 int RenderObject::nextOffset(int current) const
   2363 {
   2364     return current + 1;
   2365 }
   2366 
   2367 void RenderObject::adjustRectForOutlineAndShadow(IntRect& rect) const
   2368 {
   2369     int outlineSize = outlineStyleForRepaint()->outlineSize();
   2370     if (ShadowData* boxShadow = style()->boxShadow()) {
   2371         int shadowLeft = 0;
   2372         int shadowRight = 0;
   2373         int shadowTop = 0;
   2374         int shadowBottom = 0;
   2375 
   2376         do {
   2377             if (boxShadow->style == Normal) {
   2378                 shadowLeft = min(boxShadow->x - boxShadow->blur - boxShadow->spread - outlineSize, shadowLeft);
   2379                 shadowRight = max(boxShadow->x + boxShadow->blur + boxShadow->spread + outlineSize, shadowRight);
   2380                 shadowTop = min(boxShadow->y - boxShadow->blur - boxShadow->spread - outlineSize, shadowTop);
   2381                 shadowBottom = max(boxShadow->y + boxShadow->blur + boxShadow->spread + outlineSize, shadowBottom);
   2382             }
   2383 
   2384             boxShadow = boxShadow->next;
   2385         } while (boxShadow);
   2386 
   2387         rect.move(shadowLeft, shadowTop);
   2388         rect.setWidth(rect.width() - shadowLeft + shadowRight);
   2389         rect.setHeight(rect.height() - shadowTop + shadowBottom);
   2390     } else
   2391         rect.inflate(outlineSize);
   2392 }
   2393 
   2394 AnimationController* RenderObject::animation() const
   2395 {
   2396     return document()->frame()->animation();
   2397 }
   2398 
   2399 void RenderObject::imageChanged(CachedImage* image, const IntRect* rect)
   2400 {
   2401     imageChanged(static_cast<WrappedImagePtr>(image), rect);
   2402 }
   2403 
   2404 RenderBoxModelObject* RenderObject::offsetParent() const
   2405 {
   2406     // If any of the following holds true return null and stop this algorithm:
   2407     // A is the root element.
   2408     // A is the HTML body element.
   2409     // The computed value of the position property for element A is fixed.
   2410     if (isRoot() || isBody() || (isPositioned() && style()->position() == FixedPosition))
   2411         return 0;
   2412 
   2413     // If A is an area HTML element which has a map HTML element somewhere in the ancestor
   2414     // chain return the nearest ancestor map HTML element and stop this algorithm.
   2415     // FIXME: Implement!
   2416 
   2417     // Return the nearest ancestor element of A for which at least one of the following is
   2418     // true and stop this algorithm if such an ancestor is found:
   2419     //     * The computed value of the position property is not static.
   2420     //     * It is the HTML body element.
   2421     //     * The computed value of the position property of A is static and the ancestor
   2422     //       is one of the following HTML elements: td, th, or table.
   2423     //     * Our own extension: if there is a difference in the effective zoom
   2424     bool skipTables = isPositioned() || isRelPositioned();
   2425     float currZoom = style()->effectiveZoom();
   2426     RenderObject* curr = parent();
   2427     while (curr && (!curr->node() ||
   2428                     (!curr->isPositioned() && !curr->isRelPositioned() && !curr->isBody()))) {
   2429         Node* element = curr->node();
   2430         if (!skipTables && element) {
   2431             bool isTableElement = element->hasTagName(tableTag) ||
   2432                                   element->hasTagName(tdTag) ||
   2433                                   element->hasTagName(thTag);
   2434 
   2435 #if ENABLE(WML)
   2436             if (!isTableElement && element->isWMLElement())
   2437                 isTableElement = element->hasTagName(WMLNames::tableTag) ||
   2438                                  element->hasTagName(WMLNames::tdTag);
   2439 #endif
   2440 
   2441             if (isTableElement)
   2442                 break;
   2443         }
   2444 
   2445         float newZoom = curr->style()->effectiveZoom();
   2446         if (currZoom != newZoom)
   2447             break;
   2448         currZoom = newZoom;
   2449         curr = curr->parent();
   2450     }
   2451     return curr && curr->isBoxModelObject() ? toRenderBoxModelObject(curr) : 0;
   2452 }
   2453 
   2454 VisiblePosition RenderObject::createVisiblePosition(int offset, EAffinity affinity)
   2455 {
   2456     // If this is a non-anonymous renderer in an editable area, then it's simple.
   2457     if (Node* node = this->node()) {
   2458         if (!node->isContentEditable()) {
   2459             // If it can be found, we prefer a visually equivalent position that is editable.
   2460             Position position(node, offset);
   2461             Position candidate = position.downstream(Position::CanCrossEditingBoundary);
   2462             if (candidate.node()->isContentEditable())
   2463                 return VisiblePosition(candidate, affinity);
   2464             candidate = position.upstream(Position::CanCrossEditingBoundary);
   2465             if (candidate.node()->isContentEditable())
   2466                 return VisiblePosition(candidate, affinity);
   2467         }
   2468         return VisiblePosition(node, offset, affinity);
   2469     }
   2470 
   2471     // We don't want to cross the boundary between editable and non-editable
   2472     // regions of the document, but that is either impossible or at least
   2473     // extremely unlikely in any normal case because we stop as soon as we
   2474     // find a single non-anonymous renderer.
   2475 
   2476     // Find a nearby non-anonymous renderer.
   2477     RenderObject* child = this;
   2478     while (RenderObject* parent = child->parent()) {
   2479         // Find non-anonymous content after.
   2480         RenderObject* renderer = child;
   2481         while ((renderer = renderer->nextInPreOrder(parent))) {
   2482             if (Node* node = renderer->node())
   2483                 return VisiblePosition(node, 0, DOWNSTREAM);
   2484         }
   2485 
   2486         // Find non-anonymous content before.
   2487         renderer = child;
   2488         while ((renderer = renderer->previousInPreOrder())) {
   2489             if (renderer == parent)
   2490                 break;
   2491             if (Node* node = renderer->node())
   2492                 return VisiblePosition(lastDeepEditingPositionForNode(node), DOWNSTREAM);
   2493         }
   2494 
   2495         // Use the parent itself unless it too is anonymous.
   2496         if (Node* node = parent->node())
   2497             return VisiblePosition(node, 0, DOWNSTREAM);
   2498 
   2499         // Repeat at the next level up.
   2500         child = parent;
   2501     }
   2502 
   2503     // Everything was anonymous. Give up.
   2504     return VisiblePosition();
   2505 }
   2506 
   2507 VisiblePosition RenderObject::createVisiblePosition(const Position& position)
   2508 {
   2509     if (position.isNotNull())
   2510         return VisiblePosition(position);
   2511 
   2512     ASSERT(!node());
   2513     return createVisiblePosition(0, DOWNSTREAM);
   2514 }
   2515 
   2516 #if ENABLE(SVG)
   2517 const SVGRenderBase* RenderObject::toSVGRenderBase() const
   2518 {
   2519     ASSERT_NOT_REACHED();
   2520     return 0;
   2521 }
   2522 
   2523 FloatRect RenderObject::objectBoundingBox() const
   2524 {
   2525     ASSERT_NOT_REACHED();
   2526     return FloatRect();
   2527 }
   2528 
   2529 // Returns the smallest rectangle enclosing all of the painted content
   2530 // respecting clipping, masking, filters, opacity, stroke-width and markers
   2531 FloatRect RenderObject::repaintRectInLocalCoordinates() const
   2532 {
   2533     ASSERT_NOT_REACHED();
   2534     return FloatRect();
   2535 }
   2536 
   2537 AffineTransform RenderObject::localTransform() const
   2538 {
   2539     static const AffineTransform identity;
   2540     return identity;
   2541 }
   2542 
   2543 const AffineTransform& RenderObject::localToParentTransform() const
   2544 {
   2545     static const AffineTransform identity;
   2546     return identity;
   2547 }
   2548 
   2549 bool RenderObject::nodeAtFloatPoint(const HitTestRequest&, HitTestResult&, const FloatPoint&, HitTestAction)
   2550 {
   2551     ASSERT_NOT_REACHED();
   2552     return false;
   2553 }
   2554 
   2555 #endif // ENABLE(SVG)
   2556 
   2557 } // namespace WebCore
   2558 
   2559 #ifndef NDEBUG
   2560 
   2561 void showTree(const WebCore::RenderObject* ro)
   2562 {
   2563     if (ro)
   2564         ro->showTreeForThis();
   2565 }
   2566 
   2567 void showRenderTree(const WebCore::RenderObject* object1)
   2568 {
   2569     showRenderTree(object1, 0);
   2570 }
   2571 
   2572 void showRenderTree(const WebCore::RenderObject* object1, const WebCore::RenderObject* object2)
   2573 {
   2574     if (object1) {
   2575         const WebCore::RenderObject* root = object1;
   2576         while (root->parent())
   2577             root = root->parent();
   2578         root->showRenderTreeAndMark(object1, "*", object2, "-", 0);
   2579     }
   2580 }
   2581 
   2582 #endif
   2583