OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) | 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) | 3 * (C) 1999 Antti Koivisto (koivisto@kde.org) |
4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) | 4 * (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com) |
5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) | 5 * (C) 2005, 2006 Samuel Weinig (sam.weinig@gmail.com) |
6 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 6 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. |
7 * | 7 * |
8 * This library is free software; you can redistribute it and/or | 8 * This library is free software; you can redistribute it and/or |
9 * modify it under the terms of the GNU Library General Public | 9 * modify it under the terms of the GNU Library General Public |
10 * License as published by the Free Software Foundation; either | 10 * License as published by the Free Software Foundation; either |
(...skipping 12 matching lines...) Expand all Loading... |
23 */ | 23 */ |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "RenderBox.h" | 26 #include "RenderBox.h" |
27 | 27 |
28 #include "CachedImage.h" | 28 #include "CachedImage.h" |
29 #include "ChromeClient.h" | 29 #include "ChromeClient.h" |
30 #include "Document.h" | 30 #include "Document.h" |
31 #include "FrameView.h" | 31 #include "FrameView.h" |
32 #include "GraphicsContext.h" | 32 #include "GraphicsContext.h" |
| 33 #include "htmlediting.h" |
33 #include "HTMLElement.h" | 34 #include "HTMLElement.h" |
34 #include "HTMLNames.h" | 35 #include "HTMLNames.h" |
35 #include "ImageBuffer.h" | 36 #include "ImageBuffer.h" |
36 #include "FloatQuad.h" | 37 #include "FloatQuad.h" |
37 #include "Frame.h" | 38 #include "Frame.h" |
38 #include "Page.h" | 39 #include "Page.h" |
39 #include "RenderArena.h" | 40 #include "RenderArena.h" |
40 #include "RenderFlexibleBox.h" | 41 #include "RenderFlexibleBox.h" |
41 #include "RenderInline.h" | 42 #include "RenderInline.h" |
42 #include "RenderLayer.h" | 43 #include "RenderLayer.h" |
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
386 return width() - borderLeft() - borderRight() - verticalScrollbarWidth(); | 387 return width() - borderLeft() - borderRight() - verticalScrollbarWidth(); |
387 } | 388 } |
388 | 389 |
389 int RenderBox::clientHeight() const | 390 int RenderBox::clientHeight() const |
390 { | 391 { |
391 if (isRenderInline()) | 392 if (isRenderInline()) |
392 return 0; | 393 return 0; |
393 return height() - borderTop() - borderBottom() - horizontalScrollbarHeight()
; | 394 return height() - borderTop() - borderBottom() - horizontalScrollbarHeight()
; |
394 } | 395 } |
395 | 396 |
396 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless
the | 397 // scrollWidth/scrollHeight will be the same as overflowWidth/overflowHeight unl
ess the |
397 // object has overflow:hidden/scroll/auto specified and also has overflow. | 398 // object has overflow:hidden/scroll/auto specified and also has overflow. |
| 399 // FIXME: It's not completely clear how scrollWidth/Height should behave for |
| 400 // objects with visible overflow. |
398 int RenderBox::scrollWidth() const | 401 int RenderBox::scrollWidth() const |
399 { | 402 { |
400 return hasOverflowClip() ? m_layer->scrollWidth() : overflowWidth(); | 403 if (hasOverflowClip()) |
| 404 return m_layer->scrollWidth(); |
| 405 if (isRenderInline()) |
| 406 return 0; |
| 407 return overflowWidth(); |
401 } | 408 } |
402 | 409 |
403 int RenderBox::scrollHeight() const | 410 int RenderBox::scrollHeight() const |
404 { | 411 { |
405 return hasOverflowClip() ? m_layer->scrollHeight() : overflowHeight(); | 412 if (hasOverflowClip()) |
| 413 return m_layer->scrollHeight(); |
| 414 if (isRenderInline()) |
| 415 return 0; |
| 416 return overflowHeight(); |
406 } | 417 } |
407 | 418 |
408 int RenderBox::scrollLeft() const | 419 int RenderBox::scrollLeft() const |
409 { | 420 { |
410 return hasOverflowClip() ? m_layer->scrollXOffset() : 0; | 421 return hasOverflowClip() ? m_layer->scrollXOffset() : 0; |
411 } | 422 } |
412 | 423 |
413 int RenderBox::scrollTop() const | 424 int RenderBox::scrollTop() const |
414 { | 425 { |
415 return hasOverflowClip() ? m_layer->scrollYOffset() : 0; | 426 return hasOverflowClip() ? m_layer->scrollYOffset() : 0; |
(...skipping 2697 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3113 int RenderBox::leftmostPosition(bool /*includeOverflowInterior*/, bool includeSe
lf) const | 3124 int RenderBox::leftmostPosition(bool /*includeOverflowInterior*/, bool includeSe
lf) const |
3114 { | 3125 { |
3115 if (!includeSelf || !height()) | 3126 if (!includeSelf || !height()) |
3116 return width(); | 3127 return width(); |
3117 int left = 0; | 3128 int left = 0; |
3118 if (isRelPositioned()) | 3129 if (isRelPositioned()) |
3119 left += relativePositionOffsetX(); | 3130 left += relativePositionOffsetX(); |
3120 return left; | 3131 return left; |
3121 } | 3132 } |
3122 | 3133 |
| 3134 bool RenderBox::isAfterContent(RenderObject* child) const |
| 3135 { |
| 3136 return (child && child->style()->styleType() == RenderStyle::AFTER && (!chil
d->isText() || child->isBR())); |
| 3137 } |
| 3138 |
| 3139 VisiblePosition RenderBox::positionForCoordinates(int xPos, int yPos) |
| 3140 { |
| 3141 // no children...return this render object's element, if there is one, and o
ffset 0 |
| 3142 if (!firstChild()) |
| 3143 return VisiblePosition(element(), 0, DOWNSTREAM); |
| 3144 |
| 3145 if (isTable() && element()) { |
| 3146 int right = contentWidth() + borderRight() + paddingRight() + borderLeft
() + paddingLeft(); |
| 3147 int bottom = contentHeight() + borderTop() + paddingTop() + borderBottom
() + paddingBottom(); |
| 3148 |
| 3149 if (xPos < 0 || xPos > right || yPos < 0 || yPos > bottom) { |
| 3150 if (xPos <= right / 2) |
| 3151 return VisiblePosition(Position(element(), 0)); |
| 3152 else |
| 3153 return VisiblePosition(Position(element(), maxDeepOffset(element
()))); |
| 3154 } |
| 3155 } |
| 3156 |
| 3157 // Pass off to the closest child. |
| 3158 int minDist = INT_MAX; |
| 3159 RenderBox* closestRenderer = 0; |
| 3160 int newX = xPos; |
| 3161 int newY = yPos; |
| 3162 if (isTableRow()) { |
| 3163 newX += x(); |
| 3164 newY += y(); |
| 3165 } |
| 3166 for (RenderObject* renderObject = firstChild(); renderObject; renderObject =
renderObject->nextSibling()) { |
| 3167 if (!renderObject->firstChild() && !renderObject->isInline() && !renderO
bject->isBlockFlow() |
| 3168 || renderObject->style()->visibility() != VISIBLE) |
| 3169 continue; |
| 3170 |
| 3171 if (!renderObject->isBox()) |
| 3172 continue; |
| 3173 |
| 3174 RenderBox* renderer = toRenderBox(renderObject); |
| 3175 |
| 3176 int top = borderTop() + paddingTop() + (isTableRow() ? 0 : renderer->y()
); |
| 3177 int bottom = top + renderer->contentHeight(); |
| 3178 int left = borderLeft() + paddingLeft() + (isTableRow() ? 0 : renderer->
x()); |
| 3179 int right = left + renderer->contentWidth(); |
| 3180 |
| 3181 if (xPos <= right && xPos >= left && yPos <= top && yPos >= bottom) { |
| 3182 if (renderer->isTableRow()) |
| 3183 return renderer->positionForCoordinates(xPos + newX - renderer->
x(), yPos + newY - renderer->y()); |
| 3184 return renderer->positionForCoordinates(xPos - renderer->x(), yPos -
renderer->y()); |
| 3185 } |
| 3186 |
| 3187 // Find the distance from (x, y) to the box. Split the space around the
box into 8 pieces |
| 3188 // and use a different compare depending on which piece (x, y) is in. |
| 3189 IntPoint cmp; |
| 3190 if (xPos > right) { |
| 3191 if (yPos < top) |
| 3192 cmp = IntPoint(right, top); |
| 3193 else if (yPos > bottom) |
| 3194 cmp = IntPoint(right, bottom); |
| 3195 else |
| 3196 cmp = IntPoint(right, yPos); |
| 3197 } else if (xPos < left) { |
| 3198 if (yPos < top) |
| 3199 cmp = IntPoint(left, top); |
| 3200 else if (yPos > bottom) |
| 3201 cmp = IntPoint(left, bottom); |
| 3202 else |
| 3203 cmp = IntPoint(left, yPos); |
| 3204 } else { |
| 3205 if (yPos < top) |
| 3206 cmp = IntPoint(xPos, top); |
| 3207 else |
| 3208 cmp = IntPoint(xPos, bottom); |
| 3209 } |
| 3210 |
| 3211 int x1minusx2 = cmp.x() - xPos; |
| 3212 int y1minusy2 = cmp.y() - yPos; |
| 3213 |
| 3214 int dist = x1minusx2 * x1minusx2 + y1minusy2 * y1minusy2; |
| 3215 if (dist < minDist) { |
| 3216 closestRenderer = renderer; |
| 3217 minDist = dist; |
| 3218 } |
| 3219 } |
| 3220 |
| 3221 if (closestRenderer) |
| 3222 return closestRenderer->positionForCoordinates(newX - closestRenderer->x
(), newY - closestRenderer->y()); |
| 3223 |
| 3224 return VisiblePosition(element(), 0, DOWNSTREAM); |
| 3225 } |
| 3226 |
3123 #if ENABLE(SVG) | 3227 #if ENABLE(SVG) |
3124 | 3228 |
3125 TransformationMatrix RenderBox::localTransform() const | 3229 TransformationMatrix RenderBox::localTransform() const |
3126 { | 3230 { |
3127 return TransformationMatrix(1, 0, 0, 1, x(), y()); | 3231 return TransformationMatrix(1, 0, 0, 1, x(), y()); |
3128 } | 3232 } |
3129 | 3233 |
3130 #endif | 3234 #endif |
3131 | 3235 |
3132 } // namespace WebCore | 3236 } // namespace WebCore |
OLD | NEW |