root/trunk/WebCore/rendering/RenderView.h

Revision 31155, 5.5 kB (checked in by hyatt@apple.com, 4 months ago)

2008-03-19 David Hyatt <hyatt@apple.com>

New implementation of full page zoom. Because of how much doesn't transform when zooming, and because
of the need to obey viewport constraints, I decided to take a completely different approach. Now CSS
lengths and intrinsic sizes are simply adjusted by the zoom factor. This approach works much better and
avoids pixel cracks more than the old approach. In addition widgets "just work", namely plugins zoom
and scrollbars do not.

This patch also implements the IE zoom CSS property. This property allows fine-grained control over
zooming at the element level. It takes values of normal | <number> | <percentage> to match WinIE. In
addition, in the vein of text-size-adjust for text zooming, I have extended the zoom property with an
extra value, reset. The reset keyword can be used to prevent a section of the page from scaling at all
when a zoom is applied.

Reviewed by olliej

  • css/CSSComputedStyleDeclaration.cpp:
    (WebCore::):
    (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
    Support the new 'zoom' property for getComputedStyle.
  • css/CSSParser.cpp:
    (WebCore::CSSParser::parseValue):
    Code that parses the 'zoom' property.
  • css/CSSPrimitiveValue.cpp:
    (WebCore::CSSPrimitiveValue::computeLengthInt):
    (WebCore::CSSPrimitiveValue::computeLengthIntForLength):
    (WebCore::CSSPrimitiveValue::computeLengthShort):
    (WebCore::CSSPrimitiveValue::computeLengthFloat):
    (WebCore::CSSPrimitiveValue::computeLengthDouble):
  • css/CSSPrimitiveValue.h:
    Extend all of the computeLength methods to take a multiplier so that lengths can be adjusted by the
    zoom factor.
  • css/CSSPropertyNames.in:
    Add the new zoom property to the list of properties we understand.
  • css/CSSStyleSelector.cpp:
    (WebCore::CSSStyleSelector::applyDeclarations):
    (WebCore::CSSStyleSelector::applyProperty):
    (WebCore::CSSStyleSelector::mapBackgroundSize):
    (WebCore::CSSStyleSelector::mapBackgroundXPosition):
    (WebCore::CSSStyleSelector::mapBackgroundYPosition):
    (WebCore::CSSStyleSelector::getComputedSizeFromSpecifiedSize):
  • css/CSSStyleSelector.h:
    (WebCore::CSSStyleSelector::setStyle):
    Pass in the zoom factor when computing all lengths in CSS.
  • css/CSSValueKeywords.in:
    Add support for the 'reset' keyword of the zoom property.
  • dom/Document.cpp:
    (WebCore::Document::recalcStyle):
    Set the 'zoom' CSS property on the RenderView. This is how we implement full page zoom.
  • html/CanvasRenderingContext2D.cpp:
    (WebCore::size):
    Make sure the back end canvas size ignores zooming when rendering images.
  • html/HTMLImageElement.cpp:
    (WebCore::HTMLImageElement::width):
    (WebCore::HTMLImageElement::height):
    (WebCore::HTMLImageElement::naturalWidth):
    (WebCore::HTMLImageElement::naturalHeight):
    Use the unzoomed width/height if we have no style information in HTMLImageElement.cpp.
  • loader/CachedImage.cpp:
    (WebCore::CachedImage::ref):
    (WebCore::CachedImage::imageSize):
    (WebCore::CachedImage::imageRect):
  • loader/CachedImage.h:
    (WebCore::CachedImage::canRender):
    Force access to the CachedImage metrics to take a multiplier so that people have to think about
    the zoom factor. The "intrinsic size" of the image then takes that into account.
  • loader/ImageDocument.cpp:
    (WebCore::ImageTokenizer::finish):
    (WebCore::ImageDocument::scale):
    (WebCore::ImageDocument::resizeImageToFit):
    (WebCore::ImageDocument::imageChanged):
    (WebCore::ImageDocument::restoreImageSize):
    (WebCore::ImageDocument::imageFitsInWindow):
    Make sure image documents respect the zoom.
  • page/AnimationController.cpp:
    (WebCore::ImplicitAnimation::animate):
    Make the 'zoom' CSS property work with CSS transitions.
  • page/Frame.h:
    (WebCore::Frame::pageZoomFactor):
    (WebCore::Frame::textZoomFactor):
    Add accessors for obtaining the pageZoom vs. textZoom.
  • page/FrameView.cpp:
    (WebCore::FrameView::adjustViewSize):
    Remove the old zoom implementation that used transforms.
  • page/mac/WebCoreAXObject.mm:
    (-[WebCoreAXObject accessibilityIsIgnored]):
    Pass in the zoom factor.
  • rendering/InlineFlowBox.cpp:
    (WebCore::InlineFlowBox::paintBackground):
    (WebCore::InlineFlowBox::paintBoxDecorations):
    Pass in the zoom factor when testing for size.
  • rendering/RenderBox.cpp:
    (WebCore::RenderBox::calculateBackgroundSize):
    (WebCore::RenderBox::imageChanged):
    (WebCore::RenderBox::paintBackgroundExtended):
    (WebCore::RenderBox::calcHeight):
  • rendering/RenderFrameSet.cpp:
    (WebCore::RenderFrameSet::layout):
  • rendering/RenderHTMLCanvas.cpp:
    (WebCore::RenderHTMLCanvas::canvasSizeChanged):
  • rendering/RenderHTMLCanvas.h:
    (WebCore::RenderHTMLCanvas::renderName):
    (WebCore::RenderHTMLCanvas::intrinsicSizeChanged):
  • rendering/RenderImage.cpp:
    (WebCore::RenderImage::setImageSizeForAltText):
    (WebCore::RenderImage::imageChanged):
    (WebCore::RenderImage::calcReplacedWidth):
    (WebCore::RenderImage::calcReplacedHeight):
  • rendering/RenderImage.h:
    (WebCore::RenderImage::intrinsicSizeChanged):
  • rendering/RenderListMarker.cpp:
    (WebCore::RenderListMarker::layout):
    (WebCore::RenderListMarker::imageChanged):
    (WebCore::RenderListMarker::getRelativeMarkerRect):
  • rendering/RenderObject.cpp:
    (WebCore::RenderObject::mustRepaintBackgroundOrBorder):
    (WebCore::RenderObject::paintBorder):
    Pass in the zoom factor when testing for size.
  • rendering/RenderReplaced.cpp:
    (WebCore::RenderReplaced::RenderReplaced):
    (WebCore::RenderReplaced::setStyle):
    (WebCore::RenderReplaced::intrinsicSizeChanged):
  • rendering/RenderReplaced.h:
    Added a new call when the zoom factor changes, intrinsicSizeChanged(). Replaced element subclasses
    respond to this via overrides.
  • rendering/RenderStyle.cpp:
    (WebCore::StyleVisualData::StyleVisualData):
    (WebCore::StyleInheritedData::StyleInheritedData):
    (WebCore::StyleInheritedData::operator==):
    (WebCore::RenderStyle::diff):
  • rendering/RenderStyle.h:
    (WebCore::StyleVisualData::operator==):
    (WebCore::RenderStyle::zoom):
    (WebCore::RenderStyle::zoomInEffect):
    (WebCore::RenderStyle::setZoom):
    (WebCore::RenderStyle::setZoomInEffect):
    (WebCore::RenderStyle::initialZoom):
    Support for 'zoom' in the RenderStyle. "zoomInEffect" represents the computed zoom taking into account
    all the zooms specified on ancestors.
  • rendering/RenderTableCol.cpp:
    (WebCore::RenderTableCol::imageChanged):
  • rendering/RenderTableRow.cpp:
    (WebCore::RenderTableRow::imageChanged):
  • rendering/RenderTableSection.cpp:
    (WebCore::RenderTableSection::imageChanged):
  • rendering/RenderVideo.h:
    (WebCore::RenderVideo::intrinsicSizeChanged):
    Pass in the zoom factor.
  • rendering/RenderView.cpp:
    (WebCore::RenderView::calcHeight):
    (WebCore::RenderView::calcWidth):
    (WebCore::RenderView::layout):
    (WebCore::RenderView::viewHeight):
    (WebCore::RenderView::viewWidth):
  • rendering/RenderView.h:
    (WebCore::RenderView::zoomFactor):
    Back out the old implementation.
  • Property svn:eol-style set to native
Line 
1 /*
2  * This file is part of the HTML widget for KDE.
3  *
4  * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
5  * Copyright (C) 2006 Apple Computer, Inc.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Library General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Library General Public License for more details.
16  *
17  * You should have received a copy of the GNU Library General Public License
18  * along with this library; see the file COPYING.LIB.  If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  * Boston, MA 02110-1301, USA.
21  *
22  */
23
24 #ifndef RenderView_h
25 #define RenderView_h
26
27 #include "FrameView.h"
28 #include "Frame.h"
29 #include "LayoutState.h"
30 #include "RenderBlock.h"
31
32 namespace WebCore {
33
34 class RenderView : public RenderBlock {
35 public:
36     RenderView(Node*, FrameView*);
37     virtual ~RenderView();
38
39     virtual const char* renderName() const { return "RenderView"; }
40
41     virtual bool isRenderView() const { return true; }
42
43     virtual void layout();
44     virtual void calcWidth();
45     virtual void calcHeight();
46     virtual void calcPrefWidths();
47     virtual bool absolutePosition(int& xPos, int& yPos, bool fixed = false) const;
48    
49     int docHeight() const;
50     int docWidth() const;
51
52     // The same as the FrameView's visibleHeight/visibleWidth but with null check guards.
53     int viewHeight() const;
54     int viewWidth() const;
55    
56     float zoomFactor() const { return m_frameView->frame() && m_frameView->frame()->shouldApplyPageZoom() ? m_frameView->frame()->zoomFactor() : 1.0f; }
57
58     FrameView* frameView() const { return m_frameView; }
59
60     virtual bool hasOverhangingFloats() { return false; }
61
62     virtual void computeAbsoluteRepaintRect(IntRect&, bool fixed = false);
63     virtual void repaintViewRectangle(const IntRect&, bool immediate = false);
64
65     virtual void paint(PaintInfo&, int tx, int ty);
66     virtual void paintBoxDecorations(PaintInfo&, int tx, int ty);
67
68     void setSelection(RenderObject* start, int startPos, RenderObject* end, int endPos);
69     void clearSelection();
70     virtual RenderObject* selectionStart() const { return m_selectionStart; }
71     virtual RenderObject* selectionEnd() const { return m_selectionEnd; }
72
73     bool printing() const;
74     void setPrintImages(bool enable) { m_printImages = enable; }
75     bool printImages() const { return m_printImages; }
76     void setTruncatedAt(int y) { m_truncatedAt = y; m_bestTruncatedAt = m_truncatorWidth = 0; m_forcedPageBreak = false; }
77     void setBestTruncatedAt(int y, RenderObject *forRenderer, bool forcedBreak = false);
78     int bestTruncatedAt() const { return m_bestTruncatedAt; }
79
80     int truncatedAt() const { return m_truncatedAt; }
81
82     virtual void absoluteRects(Vector<IntRect>&, int tx, int ty, bool topLevel = true);
83
84     IntRect selectionRect(bool clipToVisibleContent = true) const;
85
86     void setMaximalOutlineSize(int o) { m_maximalOutlineSize = o; }
87     int maximalOutlineSize() const { return m_maximalOutlineSize; }
88
89     virtual IntRect viewRect() const;
90
91     virtual void selectionStartEnd(int& startPos, int& endPos) const;
92
93     IntRect printRect() const { return m_printRect; }
94     void setPrintRect(const IntRect& r) { m_printRect = r; }
95
96     void updateWidgetPositions();
97     void addWidget(RenderObject*);
98     void removeWidget(RenderObject*);
99
100     const IntSize& layoutDelta() const { return m_layoutDelta; }
101     void addLayoutDelta(const IntSize& delta) { m_layoutDelta += delta; }
102
103     void pushLayoutState(RenderBox* renderer, const IntSize& offset)
104     {
105         if (m_layoutStateDisableCount || m_frameView->needsFullRepaint())
106             return;
107         m_layoutState = new (renderArena()) LayoutState(m_layoutState, renderer, offset);
108     }
109
110     void pushLayoutState(RenderObject*);
111
112     void popLayoutState()
113     {
114         if (m_layoutStateDisableCount || m_frameView->needsFullRepaint())
115             return;
116         LayoutState* state = m_layoutState;
117         m_layoutState = state->m_next;
118         state->destroy(renderArena());
119     }
120
121     LayoutState* layoutState() const { return m_layoutStateDisableCount ? 0 : m_layoutState; }
122
123     // Suspends the LayoutState optimization. Used under transforms that cannot be represented by
124     // LayoutState (common in SVG) and when manipulating the render tree during layout in ways
125     // that can trigger repaint of a non-child (e.g. when a list item moves its list marker around).
126     void disableLayoutState() { m_layoutStateDisableCount++; }
127     void enableLayoutState() { ASSERT(m_layoutStateDisableCount > 0); m_layoutStateDisableCount--; }
128
129 protected:
130     FrameView* m_frameView;
131
132     RenderObject* m_selectionStart;
133     RenderObject* m_selectionEnd;
134     int m_selectionStartPos;
135     int m_selectionEndPos;
136
137     // used to ignore viewport width when printing to the printer
138     bool m_printImages;
139     int m_truncatedAt;
140
141     int m_maximalOutlineSize; // Used to apply a fudge factor to dirty-rect checks on blocks/tables.
142     IntRect m_printRect; // Used when printing.
143
144     typedef HashSet<RenderObject*> RenderObjectSet;
145
146     RenderObjectSet m_widgets;
147
148 private:
149     int m_bestTruncatedAt;
150     int m_truncatorWidth;
151     bool m_forcedPageBreak;
152     IntSize m_layoutDelta;
153     LayoutState* m_layoutState;
154     unsigned m_layoutStateDisableCount;
155 };
156
157 } // namespace WebCore
158
159 #endif // RenderView_h
160
Note: See TracBrowser for help on using the browser.