Changeset 107032 in webkit
- Timestamp:
- Feb 7, 2012 7:56:27 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r107030 r107032 1 2012-02-07 Emil A Eklund <eae@chromium.org> 2 3 Add pixelSnappedX/Y/Width/Height methods 4 https://bugs.webkit.org/show_bug.cgi?id=78040 5 6 Reviewed by Eric Seidel. 7 8 Add pixel snapped versions of x/y/width/height methods. These return the 9 same value as the x/w/width/height methods for now but once we move over 10 to sub pixel layout they will snap the subpixel value to a device pixel 11 and return an integer value. 12 13 When snapping the left and top edge is simply rounded to the nearest 14 device pixel. 15 The right and bottom edges are computed by subtracting the rounded left/ 16 top edge from the precise location and size. This ensures that the edges 17 all line up with device pixels and that the total size of an object, 18 including borders, is at most one pixel off. 19 20 In summary, the values are computed as follows: 21 x: round(x) 22 y: round(y) 23 maxX: round(x + width) 24 maxY: round(y + height) 25 width: round(x + width) - round(x) 26 height: round(y + height) - round(y) 27 28 We use the term pixel snapped to indicate that the numbers are not merely 29 rounded. This also matches the naming used by the line box tree. 30 31 No new tests, no functionality changes. 32 33 * page/PrintContext.cpp: 34 (WebCore::PrintContext::pageNumberForElement): 35 * rendering/RenderBlock.cpp: 36 (WebCore::::collectIfNeeded): 37 * rendering/RenderBlock.h: 38 (RenderBlock): 39 (WebCore::RenderBlock::pixelSnappedLogicalRightOffsetForLine): 40 (WebCore::RenderBlock::pixelSnappedLogicalLeftOffsetForLine): 41 (WebCore::RenderBlock::FloatingObject::pixelSnappedX): 42 (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxX): 43 (WebCore::RenderBlock::FloatingObject::pixelSnappedY): 44 (WebCore::RenderBlock::FloatingObject::pixelSnappedMaxY): 45 (WebCore::RenderBlock::FloatingObject::pixelSnappedWidth): 46 (WebCore::RenderBlock::FloatingObject::pixelSnappedHeight): 47 (FloatingObject): 48 (WebCore::RenderBlock::pixelSnappedLogicalTopForFloat): 49 (WebCore::RenderBlock::pixelSnappedLogicalBottomForFloat): 50 (WebCore::RenderBlock::pixelSnappedLogicalLeftForFloat): 51 (WebCore::RenderBlock::pixelSnappedLogicalRightForFloat): 52 * rendering/RenderBlockLineLayout.cpp: 53 (WebCore::LineWidth::shrinkAvailableWidthForNewFloatIfNeeded): 54 * rendering/RenderBox.cpp: 55 (WebCore::RenderBox::pixelSnappedClientWidth): 56 (WebCore): 57 (WebCore::RenderBox::pixelSnappedClientHeight): 58 (WebCore::RenderBox::scrollHeight): 59 * rendering/RenderBox.h: 60 (WebCore::RenderBox::pixelSnappedWidth): 61 (WebCore::RenderBox::pixelSnappedHeight): 62 (RenderBox): 63 (WebCore::RenderBox::pixelSnappedOffsetWidth): 64 (WebCore::RenderBox::pixelSnappedOffsetHeight): 65 (WebCore::RenderBox::clientLogicalWidth): 66 (WebCore::RenderBox::clientLogicalHeight): 67 * rendering/RenderBoxModelObject.cpp: 68 (WebCore::RenderBoxModelObject::pixelSnappedOffsetWidth): 69 (WebCore): 70 (WebCore::RenderBoxModelObject::pixelSnappedOffsetHeight): 71 * rendering/RenderBoxModelObject.h: 72 (WebCore::RenderBoxModelObject::pixelSnappedOffsetLeft): 73 (WebCore::RenderBoxModelObject::pixelSnappedOffsetTop): 74 (RenderBoxModelObject): 75 * rendering/RenderLayer.cpp: 76 (WebCore::RenderLayer::pixelSnappedScrollWidth): 77 (WebCore): 78 (WebCore::RenderLayer::pixelSnappedScrollHeight): 79 (WebCore::RenderLayer::computeScrollDimensions): 80 (WebCore::RenderLayer::updateScrollInfoAfterLayout): 81 * rendering/RenderLayer.h: 82 (RenderLayer): 83 * rendering/RenderListBox.cpp: 84 (WebCore::RenderListBox::scrollHeight): 85 * rendering/RenderTheme.cpp: 86 (WebCore::RenderTheme::volumeSliderOffsetFromMuteButton): 87 * rendering/RenderTreeAsText.cpp: 88 (WebCore::write): 89 1 90 2012-02-07 Mike Lawther <mikelawther@chromium.org> 2 91 -
trunk/Source/WebCore/page/PrintContext.cpp
r95901 r107032 250 250 printContext.computePageRectsWithPageSize(scaledPageSize, false); 251 251 252 int top = box-> offsetTop();253 int left = box-> offsetLeft();252 int top = box->pixelSnappedOffsetTop(); 253 int left = box->pixelSnappedOffsetLeft(); 254 254 size_t pageNumber = 0; 255 255 for (; pageNumber < printContext.pageCount(); pageNumber++) { -
trunk/Source/WebCore/rendering/RenderBlock.cpp
r106744 r107032 3674 3674 if (r->type() == FloatTypeValue && interval.low() <= m_value && m_value < interval.high()) { 3675 3675 // All the objects returned from the tree should be already placed. 3676 ASSERT(r->isPlaced() && m_renderer-> logicalTopForFloat(r) <= m_value && m_renderer->logicalBottomForFloat(r) > m_value);3676 ASSERT(r->isPlaced() && m_renderer->pixelSnappedLogicalTopForFloat(r) <= m_value && m_renderer->pixelSnappedLogicalBottomForFloat(r) > m_value); 3677 3677 3678 3678 if (FloatTypeValue == FloatingObject::FloatLeft -
trunk/Source/WebCore/rendering/RenderBlock.h
r106694 r107032 164 164 : logicalWidth() - logicalRightOffsetForLine(position, firstLine); 165 165 } 166 167 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 168 int pixelSnappedLogicalRightOffsetForLine(LayoutUnit position, bool firstLine) const 169 { 170 return logicalRightOffsetForLine(position, logicalRightOffsetForContent(position), firstLine, 0); 171 } 172 173 int pixelSnappedLogicalLeftOffsetForLine(LayoutUnit position, bool firstLine) const 174 { 175 return logicalLeftOffsetForLine(position, logicalLeftOffsetForContent(position), firstLine, 0); 176 } 166 177 167 178 LayoutUnit startAlignedOffsetForLine(RenderBox* child, LayoutUnit position, bool firstLine); … … 562 573 LayoutUnit height() const { return m_frameRect.height(); } 563 574 575 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 576 int pixelSnappedX() const { return x(); } 577 int pixelSnappedMaxX() const { return maxX(); } 578 int pixelSnappedY() const { return y(); } 579 int pixelSnappedMaxY() const { return maxY(); } 580 int pixelSnappedWidth() const { return width(); } 581 int pixelSnappedHeight() const { return height(); } 582 564 583 void setX(LayoutUnit x) { ASSERT(!isInPlacedTree()); m_frameRect.setX(x); } 565 584 void setY(LayoutUnit y) { ASSERT(!isInPlacedTree()); m_frameRect.setY(y); } … … 595 614 LayoutUnit logicalRightForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->maxX() : child->maxY(); } 596 615 LayoutUnit logicalWidthForFloat(const FloatingObject* child) const { return isHorizontalWritingMode() ? child->width() : child->height(); } 616 617 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 618 int pixelSnappedLogicalTopForFloat(const FloatingObject* child) const { return logicalTopForFloat(child); } 619 int pixelSnappedLogicalBottomForFloat(const FloatingObject* child) const { return logicalBottomForFloat(child); } 620 int pixelSnappedLogicalLeftForFloat(const FloatingObject* child) const { return logicalLeftForFloat(child); } 621 int pixelSnappedLogicalRightForFloat(const FloatingObject* child) const { return logicalRightForFloat(child); } 597 622 598 623 void setLogicalTopForFloat(FloatingObject* child, LayoutUnit logicalTop) -
trunk/Source/WebCore/rendering/RenderBlockLineLayout.cpp
r107000 r107032 129 129 130 130 if (newFloat->type() == RenderBlock::FloatingObject::FloatLeft) { 131 m_left = m_block-> logicalRightForFloat(newFloat);131 m_left = m_block->pixelSnappedLogicalRightForFloat(newFloat); 132 132 if (m_isFirstLine && m_block->style()->isLeftToRightDirection()) 133 133 m_left += m_block->textIndentOffset(); 134 134 } else { 135 m_right = m_block-> logicalLeftForFloat(newFloat);135 m_right = m_block->pixelSnappedLogicalLeftForFloat(newFloat); 136 136 if (m_isFirstLine && !m_block->style()->isLeftToRightDirection()) 137 137 m_right -= m_block->textIndentOffset(); -
trunk/Source/WebCore/rendering/RenderBox.cpp
r106510 r107032 479 479 } 480 480 481 int RenderBox::pixelSnappedClientWidth() const 482 { 483 return clientWidth(); 484 } 485 486 int RenderBox::pixelSnappedClientHeight() const 487 { 488 return clientHeight(); 489 } 490 481 491 int RenderBox::scrollWidth() const 482 492 { … … 496 506 // For objects with visible overflow, this matches IE. 497 507 // FIXME: Need to work right with writing modes. 498 return max( clientHeight(), maxYLayoutOverflow() - borderTop());508 return max(pixelSnappedClientHeight(), maxYLayoutOverflow() - borderTop()); 499 509 } 500 510 -
trunk/Source/WebCore/rendering/RenderBox.h
r106146 r107032 52 52 LayoutUnit height() const { return m_frameRect.height(); } 53 53 54 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 55 int pixelSnappedWidth() const { return m_frameRect.width(); } 56 int pixelSnappedHeight() const { return m_frameRect.height(); } 57 54 58 // These represent your location relative to your container as a physical offset. 55 59 // In layout related methods you almost always want the logical location (e.g. x() and y()). … … 184 188 virtual LayoutUnit offsetHeight() const { return height(); } 185 189 190 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 191 virtual int pixelSnappedOffsetWidth() const { return pixelSnappedWidth(); } 192 virtual int pixelSnappedOffsetHeight() const { return pixelSnappedHeight(); } 193 186 194 // More IE extensions. clientWidth and clientHeight represent the interior of an object 187 195 // excluding border and scrollbar. clientLeft/Top are just the borderLeftWidth and borderTopWidth. … … 190 198 LayoutUnit clientWidth() const; 191 199 LayoutUnit clientHeight() const; 192 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? clientWidth() : clientHeight(); }193 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? clientHeight() : clientWidth(); }200 LayoutUnit clientLogicalWidth() const { return style()->isHorizontalWritingMode() ? pixelSnappedClientWidth() : pixelSnappedClientHeight(); } 201 LayoutUnit clientLogicalHeight() const { return style()->isHorizontalWritingMode() ? pixelSnappedClientHeight() : pixelSnappedClientWidth(); } 194 202 LayoutUnit clientLogicalBottom() const { return borderBefore() + clientLogicalHeight(); } 195 203 LayoutRect clientBoxRect() const { return LayoutRect(clientLeft(), clientTop(), clientWidth(), clientHeight()); } 204 205 int pixelSnappedClientWidth() const; 206 int pixelSnappedClientHeight() const; 196 207 197 208 // scrollWidth/scrollHeight will be the same as clientWidth/clientHeight unless the -
trunk/Source/WebCore/rendering/RenderBoxModelObject.cpp
r105515 r107032 511 511 } 512 512 return yPos; 513 } 514 515 int RenderBoxModelObject::pixelSnappedOffsetWidth() const 516 { 517 return offsetWidth(); 518 } 519 520 int RenderBoxModelObject::pixelSnappedOffsetHeight() const 521 { 522 return offsetHeight(); 513 523 } 514 524 -
trunk/Source/WebCore/rendering/RenderBoxModelObject.h
r104123 r107032 60 60 virtual LayoutUnit offsetWidth() const = 0; 61 61 virtual LayoutUnit offsetHeight() const = 0; 62 63 // FIXME: The implementation for these functions will change once we move to subpixel layout. See bug 60318. 64 int pixelSnappedOffsetLeft() const { return offsetLeft(); } 65 int pixelSnappedOffsetTop() const { return offsetTop(); } 66 int pixelSnappedOffsetWidth() const; 67 int pixelSnappedOffsetHeight() const; 62 68 63 69 virtual void styleWillChange(StyleDifference, const RenderStyle* newStyle); -
trunk/Source/WebCore/rendering/RenderLayer.cpp
r107001 r107032 2227 2227 } 2228 2228 2229 int RenderLayer::pixelSnappedScrollWidth() 2230 { 2231 return scrollWidth(); 2232 } 2233 2234 int RenderLayer::pixelSnappedScrollHeight() 2235 { 2236 return scrollHeight(); 2237 } 2238 2229 2239 LayoutUnit RenderLayer::overflowTop() const 2230 2240 { … … 2275 2285 2276 2286 if (needHBar) 2277 *needHBar = m_scrollSize.width() > box->clientWidth();2287 *needHBar = pixelSnappedScrollWidth() > box->pixelSnappedClientWidth(); 2278 2288 if (needVBar) 2279 *needVBar = m_scrollSize.height() > box->clientHeight();2289 *needVBar = pixelSnappedScrollHeight() > box->pixelSnappedClientHeight(); 2280 2290 } 2281 2291 … … 2382 2392 // Set up the range (and page step/line step). 2383 2393 if (m_hBar) { 2384 LayoutUnit clientWidth = box->clientWidth();2385 LayoutUnit pageStep = max<LayoutUnit>(max<LayoutUnit>(clientWidth * Scrollbar::minFractionToStepWhenPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1);2394 int clientWidth = box->pixelSnappedClientWidth(); 2395 int pageStep = max(max<int>(clientWidth * Scrollbar::minFractionToStepWhenPaging(), clientWidth - Scrollbar::maxOverlapBetweenPages()), 1); 2386 2396 m_hBar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); 2387 2397 m_hBar->setProportion(clientWidth, m_scrollSize.width()); 2388 2398 } 2389 2399 if (m_vBar) { 2390 LayoutUnit clientHeight = box->clientHeight();2391 LayoutUnit pageStep = max<LayoutUnit>(max<LayoutUnit>(clientHeight * Scrollbar::minFractionToStepWhenPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1);2400 int clientHeight = box->pixelSnappedClientHeight(); 2401 int pageStep = max(max<int>(clientHeight * Scrollbar::minFractionToStepWhenPaging(), clientHeight - Scrollbar::maxOverlapBetweenPages()), 1); 2392 2402 m_vBar->setSteps(Scrollbar::pixelsPerLineStep(), pageStep); 2393 2403 m_vBar->setProportion(clientHeight, m_scrollSize.height()); -
trunk/Source/WebCore/rendering/RenderLayer.h
r107001 r107032 283 283 LayoutUnit scrollWidth(); 284 284 LayoutUnit scrollHeight(); 285 int pixelSnappedScrollWidth(); 286 int pixelSnappedScrollHeight(); 285 287 286 288 void panScrollFromPoint(const LayoutPoint&); -
trunk/Source/WebCore/rendering/RenderListBox.cpp
r107001 r107032 652 652 int RenderListBox::scrollHeight() const 653 653 { 654 return max( clientHeight(), listHeight());654 return max(pixelSnappedClientHeight(), listHeight()); 655 655 } 656 656 -
trunk/Source/WebCore/rendering/RenderTheme.cpp
r106734 r107032 504 504 { 505 505 LayoutUnit y = -size.height(); 506 FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox-> offsetLeft(), y), true, true);506 FloatPoint absPoint = muteButtonBox->localToAbsolute(FloatPoint(muteButtonBox->pixelSnappedOffsetLeft(), y), true, true); 507 507 if (absPoint.y() < 0) 508 508 y = muteButtonBox->height(); -
trunk/Source/WebCore/rendering/RenderTreeAsText.cpp
r106695 r107032 618 618 if (l.scrollYOffset()) 619 619 ts << " scrollY " << l.scrollYOffset(); 620 if (l.renderBox() && l.renderBox()-> clientWidth() != l.scrollWidth())621 ts << " scrollWidth " << l. scrollWidth();622 if (l.renderBox() && l.renderBox()-> clientHeight() != l.scrollHeight())623 ts << " scrollHeight " << l. scrollHeight();620 if (l.renderBox() && l.renderBox()->pixelSnappedClientWidth() != l.pixelSnappedScrollWidth()) 621 ts << " scrollWidth " << l.pixelSnappedScrollWidth(); 622 if (l.renderBox() && l.renderBox()->pixelSnappedClientHeight() != l.pixelSnappedScrollHeight()) 623 ts << " scrollHeight " << l.pixelSnappedScrollHeight(); 624 624 } 625 625
Note: See TracChangeset
for help on using the changeset viewer.