root/trunk/WebCore/rendering/RenderObject.h

Revision 35244, 40.3 kB (checked in by britto@apple.com, 3 weeks ago)

2008-07-18 Maxime Britto <britto@apple.com>

Reviewed by Adele.


Fixed <rdar://problem/6049803>
Prevent the autoscroll to trigger in WebClips when starting or hovering on an editable field.

Test: fast/events/autoscroll-with-non-scrollable-parent.html

  • ChangeLog:
  • page/EventHandler.cpp: Edited
    (WebCore::EventHandler::handleMousePressEvent): changed the name of the funtion called to canBeProgramaticallyScrolled()
    (WebCore::EventHandler::handleMouseDraggedEvent): prevent the autoscroll to keep looking for a renderer when it's already triggered
  • rendering/RenderLayer.cpp:
    (WebCore::RenderLayer::scrollRectToVisible): verifies that the top layer can be programmatically scrolled before asking him to make the rect visible
  • rendering/RenderListBox.h:
    (WebCore::RenderListBox::canBeProgramaticallyScrolled):
  • rendering/RenderObject.cpp:
    (WebCore::RenderObject::canBeProgramaticallyScrolled): Edited : For the 3rd case we want document's renderer to have scrollbar as it's the top layer
    (WebCore::RenderObject::hasScrollableView): Verifies that the Object has a view with scrollBars
  • rendering/RenderObject.h: Renamed shouldAutosroll() for canBeProgramaticallyScrolled()
  • rendering/RenderTextControl.h:
    (WebCore::RenderTextControl::canBeProgramaticallyScrolled):

2008-07-18 Adele Peterson & Maxime Britto <britto@apple.com>

Reviewed by Adele.

Test for <rdar://problem/6049803> Autoscroll triggered on no scrolling iframes

  • ChangeLog:
  • fast/events/autoscroll-with-non-scrollable-parent-expected.txt: Added.
  • fast/events/autoscroll-with-non-scrollable-parent.html: Added.
  • fast/events/resources/big-page-with-input.html: Added.
  • Property svn:eol-style set to native
Line 
1 /*
2  * Copyright (C) 2000 Lars Knoll (knoll@kde.org)
3  *           (C) 2000 Antti Koivisto (koivisto@kde.org)
4  *           (C) 2000 Dirk Mueller (mueller@kde.org)
5  *           (C) 2004 Allan Sandfeld Jensen (kde@carewolf.com)
6  * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public License
19  * along with this library; see the file COPYING.LIB.  If not, write to
20  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21  * Boston, MA 02110-1301, USA.
22  *
23  */
24
25 #ifndef RenderObject_h
26 #define RenderObject_h
27
28 #include "CachedResourceClient.h"
29 #include "Document.h"
30 #include "RenderStyle.h"
31 #include "ScrollTypes.h"
32 #include "VisiblePosition.h"
33 #include <wtf/HashMap.h>
34
35 namespace WebCore {
36
37 class AffineTransform;
38 class AnimationController;
39 class Color;
40 class Document;
41 class Element;
42 class Event;
43 class FloatRect;
44 class FrameView;
45 class HTMLAreaElement;
46 class HitTestResult;
47 class InlineBox;
48 class InlineFlowBox;
49 class PlatformScrollbar;
50 class Position;
51 class RenderArena;
52 class RenderBlock;
53 class RenderFlow;
54 class RenderFrameSet;
55 class RenderLayer;
56 class RenderTable;
57 class RenderText;
58 class RenderView;
59 class String;
60
61 struct HitTestRequest;
62
63 /*
64  *  The painting of a layer occurs in three distinct phases.  Each phase involves
65  *  a recursive descent into the layer's render objects. The first phase is the background phase.
66  *  The backgrounds and borders of all blocks are painted.  Inlines are not painted at all.
67  *  Floats must paint above block backgrounds but entirely below inline content that can overlap them.
68  *  In the foreground phase, all inlines are fully painted.  Inline replaced elements will get all
69  *  three phases invoked on them during this phase.
70  */
71
72 enum PaintPhase {
73     PaintPhaseBlockBackground,
74     PaintPhaseChildBlockBackground,
75     PaintPhaseChildBlockBackgrounds,
76     PaintPhaseFloat,
77     PaintPhaseForeground,
78     PaintPhaseOutline,
79     PaintPhaseChildOutlines,
80     PaintPhaseSelfOutline,
81     PaintPhaseSelection,
82     PaintPhaseCollapsedTableBorders,
83     PaintPhaseTextClip,
84     PaintPhaseMask
85 };
86
87 enum PaintRestriction {
88     PaintRestrictionNone,
89     PaintRestrictionSelectionOnly,
90     PaintRestrictionSelectionOnlyBlackText
91 };
92
93 enum HitTestFilter {
94     HitTestAll,
95     HitTestSelf,
96     HitTestDescendants
97 };
98
99 enum HitTestAction {
100     HitTestBlockBackground,
101     HitTestChildBlockBackground,
102     HitTestChildBlockBackgrounds,
103     HitTestFloat,
104     HitTestForeground
105 };
106
107 enum VerticalPositionHint {
108     PositionTop = -0x7fffffff,
109     PositionBottom = 0x7fffffff,
110     PositionUndefined = static_cast<int>(0x80000000)
111 };
112
113 #if ENABLE(DASHBOARD_SUPPORT)
114 struct DashboardRegionValue {
115     bool operator==(const DashboardRegionValue& o) const
116     {
117         return type == o.type && bounds == o.bounds && clip == o.clip && label == o.label;
118     }
119     bool operator!=(const DashboardRegionValue& o) const
120     {
121         return !(*this == o);
122     }
123
124     String label;
125     IntRect bounds;
126     IntRect clip;
127     int type;
128 };
129 #endif
130
131 // FIXME: This should be a HashSequencedSet, but we don't have that data structure yet.
132 // This means the paint order of outlines will be wrong, although this is a minor issue.
133 typedef HashSet<RenderFlow*> RenderFlowSequencedSet;
134
135 // Base class for all rendering tree objects.
136 class RenderObject : public CachedResourceClient {
137     friend class RenderContainer;
138     friend class RenderSVGContainer;
139     friend class RenderLayer;
140 public:
141     // Anonymous objects should pass the document as their node, and they will then automatically be
142     // marked as anonymous in the constructor.
143     RenderObject(Node*);
144     virtual ~RenderObject();
145
146     virtual const char* renderName() const { return "RenderObject"; }
147
148     RenderObject* parent() const { return m_parent; }
149     bool isDescendantOf(const RenderObject*) const;
150
151     RenderObject* previousSibling() const { return m_previous; }
152     RenderObject* nextSibling() const { return m_next; }
153
154     virtual RenderObject* firstChild() const { return 0; }
155     virtual RenderObject* lastChild() const { return 0; }
156
157     RenderObject* nextInPreOrder() const;
158     RenderObject* nextInPreOrder(RenderObject* stayWithin) const;
159     RenderObject* nextInPreOrderAfterChildren() const;
160     RenderObject* nextInPreOrderAfterChildren(RenderObject* stayWithin) const;
161     RenderObject* previousInPreOrder() const;
162     RenderObject* childAt(unsigned) const;
163
164     RenderObject* firstLeafChild() const;
165     RenderObject* lastLeafChild() const;
166
167     virtual RenderLayer* layer() const { return 0; }
168     RenderLayer* enclosingLayer() const;
169     void addLayers(RenderLayer* parentLayer, RenderObject* newObject);
170     void removeLayers(RenderLayer* parentLayer);
171     void moveLayers(RenderLayer* oldParent, RenderLayer* newParent);
172     RenderLayer* findNextLayer(RenderLayer* parentLayer, RenderObject* startPoint, bool checkParent = true);
173     virtual void positionChildLayers() { }
174     virtual bool requiresLayer();
175
176     virtual IntRect getOverflowClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
177     virtual IntRect getClipRect(int /*tx*/, int /*ty*/) { return IntRect(0, 0, 0, 0); }
178     bool hasClip() { return isPositioned() && style()->hasClip(); }
179
180     virtual int getBaselineOfFirstLineBox() const { return -1; }
181     virtual int getBaselineOfLastLineBox() const { return -1; }
182
183     virtual bool isEmpty() const { return firstChild() == 0; }
184
185     virtual bool isEdited() const { return false; }
186     virtual void setEdited(bool) { }
187
188 #ifndef NDEBUG
189     void setHasAXObject(bool flag) { m_hasAXObject = flag; }
190     bool hasAXObject() const { return m_hasAXObject; }
191 #endif
192
193     // Obtains the nearest enclosing block (including this block) that contributes a first-line style to our inline
194     // children.
195     virtual RenderBlock* firstLineBlock() const;
196
197     // Called when an object that was floating or positioned becomes a normal flow object
198     // again.  We have to make sure the render tree updates as needed to accommodate the new
199     // normal flow object.
200     void handleDynamicFloatPositionChange();
201
202     // This function is a convenience helper for creating an anonymous block that inherits its
203     // style from this RenderObject.
204     RenderBlock* createAnonymousBlock();
205
206     // Whether or not a positioned element requires normal flow x/y to be computed
207     // to determine its position.
208     bool hasStaticX() const;
209     bool hasStaticY() const;
210     virtual void setStaticX(int /*staticX*/) { }
211     virtual void setStaticY(int /*staticY*/) { }
212     virtual int staticX() const { return 0; }
213     virtual int staticY() const { return 0; }
214
215     // RenderObject tree manipulation
216     //////////////////////////////////////////
217     virtual bool canHaveChildren() const;
218     virtual bool isChildAllowed(RenderObject*, RenderStyle*) const { return true; }
219     virtual void addChild(RenderObject* newChild, RenderObject* beforeChild = 0);
220     virtual void removeChild(RenderObject*);
221     virtual bool createsAnonymousWrapper() const { return false; }
222
223     // raw tree manipulation
224     virtual RenderObject* removeChildNode(RenderObject*, bool fullRemove = true);
225     virtual void appendChildNode(RenderObject*, bool fullAppend = true);
226     virtual void insertChildNode(RenderObject* child, RenderObject* before, bool fullInsert = true);
227     // Designed for speed.  Don't waste time doing a bunch of work like layer updating and repainting when we know that our
228     // change in parentage is not going to affect anything.
229     virtual void moveChildNode(RenderObject*);
230     //////////////////////////////////////////
231
232 protected:
233     //////////////////////////////////////////
234     // Helper functions. Dangerous to use!
235     void setPreviousSibling(RenderObject* previous) { m_previous = previous; }
236     void setNextSibling(RenderObject* next) { m_next = next; }
237     void setParent(RenderObject* parent) { m_parent = parent; }
238     //////////////////////////////////////////
239 private:
240     void addAbsoluteRectForLayer(IntRect& result);
241
242 public:
243 #ifndef NDEBUG
244     void showTreeForThis() const;
245 #endif
246
247     static RenderObject* createObject(Node*, RenderStyle*);
248
249     // Overloaded new operator.  Derived classes must override operator new
250     // in order to allocate out of the RenderArena.
251     void* operator new(size_t, RenderArena*) throw();
252
253     // Overridden to prevent the normal delete from being called.
254     void operator delete(void*, size_t);
255
256 private:
257     // The normal operator new is disallowed on all render objects.
258     void* operator new(size_t) throw();
259
260 public:
261     RenderArena* renderArena() const { return document()->renderArena(); }
262
263     virtual bool isApplet() const { return false; }
264     virtual bool isBR() const { return false; }
265     virtual bool isBlockFlow() const { return false; }
266     virtual bool isCounter() const { return false; }
267     virtual bool isFrame() const { return false; }
268     virtual bool isFrameSet() const { return false; }
269     virtual bool isImage() const { return false; }
270     virtual bool isInlineBlockOrInlineTable() const { return false; }
271     virtual bool isInlineContinuation() const;
272     virtual bool isInlineFlow() const { return false; }
273     virtual bool isListBox() const { return false; }
274     virtual bool isListItem() const { return false; }
275     virtual bool isListMarker() const { return false; }
276     virtual bool isMedia() const { return false; }
277     virtual bool isMenuList() const { return false; }
278     virtual bool isRenderBlock() const { return false; }
279     virtual bool isRenderImage() const { return false; }
280     virtual bool isRenderInline() const { return false; }
281     virtual bool isRenderPart() const { return false; }
282     virtual bool isRenderView() const { return false; }
283     virtual bool isSlider() const { return false; }
284     virtual bool isTable() const { return false; }
285     virtual bool isTableCell() const { return false; }
286     virtual bool isTableCol() const { return false; }
287     virtual bool isTableRow() const { return false; }
288     virtual bool isTableSection() const { return false; }
289     virtual bool isTextArea() const { return false; }
290     virtual bool isTextField() const { return false; }
291     virtual bool isWidget() const { return false; }
292
293
294     bool isRoot() const { return document()->documentElement() == node(); }
295     bool isBody() const;
296     bool isHR() const;
297
298     bool isHTMLMarquee() const;
299
300     virtual bool childrenInline() const { return false; }
301     virtual void setChildrenInline(bool) { }
302
303     virtual RenderFlow* continuation() const;
304
305 #if ENABLE(SVG)
306     virtual bool isSVGRoot() const { return false; }
307     virtual bool isSVGContainer() const { return false; }
308     virtual bool isSVGHiddenContainer() const { return false; }
309     virtual bool isRenderPath() const { return false; }
310     virtual bool isSVGText() const { return false; }
311
312     virtual FloatRect relativeBBox(bool includeStroke = true) const;
313
314     virtual AffineTransform localTransform() const;
315     virtual AffineTransform absoluteTransform() const;
316 #endif
317
318     virtual bool isEditable() const;
319
320     bool isAnonymous() const { return m_isAnonymous; }
321     void setIsAnonymous(bool b) { m_isAnonymous = b; }
322     bool isAnonymousBlock() const
323     {
324         return m_isAnonymous && style()->display() == BLOCK && style()->styleType() == RenderStyle::NOPSEUDO && !isListMarker();
325     }
326
327     bool isFloating() const { return m_floating; }
328     bool isPositioned() const { return m_positioned; } // absolute or fixed positioning
329     bool isRelPositioned() const { return m_relPositioned; } // relative positioning
330     bool isText() const  { return m_isText; }
331     bool isInline() const { return m_inline; }  // inline object
332     bool isCompact() const { return style()->display() == COMPACT; } // compact object
333     bool isRunIn() const { return style()->display() == RUN_IN; } // run-in object
334     bool isDragging() const { return m_isDragging; }
335     bool isReplaced() const { return m_replaced; } // a "replaced" element (see CSS)
336     
337     bool hasLayer() const { return m_hasLayer; }
338    
339     bool hasBoxDecorations() const { return m_paintBackground; }
340     bool mustRepaintBackgroundOrBorder() const;
341
342     bool hasHorizontalBordersPaddingOrMargin() const { return hasHorizontalBordersOrPadding() || marginLeft() != 0 || marginRight() != 0; }
343     bool hasHorizontalBordersOrPadding() const { return borderLeft() != 0 || borderRight() != 0 || paddingLeft() != 0 || paddingRight() != 0; }
344                                                              
345     bool needsLayout() const { return m_needsLayout || m_normalChildNeedsLayout || m_posChildNeedsLayout || m_needsPositionedMovementLayout; }
346     bool selfNeedsLayout() const { return m_needsLayout; }
347     bool needsPositionedMovementLayout() const { return m_needsPositionedMovementLayout; }
348     bool needsPositionedMovementLayoutOnly() const { return m_needsPositionedMovementLayout && !m_needsLayout && !m_normalChildNeedsLayout && !m_posChildNeedsLayout; }
349     bool posChildNeedsLayout() const { return m_posChildNeedsLayout; }
350     bool normalChildNeedsLayout() const { return m_normalChildNeedsLayout; }
351    
352     bool prefWidthsDirty() const { return m_prefWidthsDirty; }
353
354     bool isSelectionBorder() const;
355
356     bool hasOverflowClip() const { return m_hasOverflowClip; }
357     virtual bool hasControlClip() const { return false; }
358     virtual IntRect controlClipRect(int /*tx*/, int /*ty*/) const { return IntRect(); }
359
360     bool hasAutoVerticalScrollbar() const { return hasOverflowClip() && (style()->overflowY() == OAUTO || style()->overflowY() == OOVERLAY); }
361     bool hasAutoHorizontalScrollbar() const { return hasOverflowClip() && (style()->overflowX() == OAUTO || style()->overflowX() == OOVERLAY); }
362
363     bool scrollsOverflow() const { return scrollsOverflowX() || scrollsOverflowY(); }
364     bool scrollsOverflowX() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || hasAutoHorizontalScrollbar()); }
365     bool scrollsOverflowY() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || hasAutoVerticalScrollbar()); }
366
367     virtual int verticalScrollbarWidth() const;
368     virtual int horizontalScrollbarHeight() const;
369    
370     bool hasTransform() const { return m_hasTransform; }
371     bool hasMask() const { return style() && style()->hasMask(); }
372     virtual IntRect maskClipRect() { return borderBox(); }
373
374 private:
375     bool includeVerticalScrollbarSize() const { return hasOverflowClip() && (style()->overflowY() == OSCROLL || style()->overflowY() == OAUTO); }
376     bool includeHorizontalScrollbarSize() const { return hasOverflowClip() && (style()->overflowX() == OSCROLL || style()->overflowX() == OAUTO); }
377
378 public:
379     RenderStyle* getPseudoStyle(RenderStyle::PseudoId, RenderStyle* parentStyle = 0) const;
380
381     void updateDragState(bool dragOn);
382
383     RenderView* view() const;
384
385     // don't even think about making this method virtual!
386     Node* element() const { return m_isAnonymous ? 0 : m_node; }
387     Document* document() const { return m_node->document(); }
388     void setNode(Node* node) { m_node = node; }
389     Node* node() const { return m_node; }
390
391     bool hasOutlineAnnotation() const;
392     bool hasOutline() const { return style()->hasOutline() || hasOutlineAnnotation(); }
393
394    /**
395      * returns the object containing this one. can be different from parent for
396      * positioned elements
397      */
398     RenderObject* container() const;
399     RenderObject* hoverAncestor() const;
400
401     virtual void markAllDescendantsWithFloatsForLayout(RenderObject* floatToRemove = 0);
402     void markContainingBlocksForLayout(bool scheduleRelayout = true, RenderObject* newRoot = 0);
403     void setNeedsLayout(bool b, bool markParents = true);
404     void setChildNeedsLayout(bool b, bool markParents = true);
405     void setNeedsPositionedMovementLayout();
406     void setPrefWidthsDirty(bool, bool markParents = true);
407     void invalidateContainerPrefWidths();
408    
409     void setNeedsLayoutAndPrefWidthsRecalc()
410     {
411         setNeedsLayout(true);
412         setPrefWidthsDirty(true);
413     }
414
415     void setPositioned(bool b = true)  { m_positioned = b;  }
416     void setRelPositioned(bool b = true) { m_relPositioned = b; }
417     void setFloating(bool b = true) { m_floating = b; }
418     void setInline(bool b = true) { m_inline = b; }
419     void setHasBoxDecorations(bool b = true) { m_paintBackground = b; }
420     void setRenderText() { m_isText = true; }
421     void setReplaced(bool b = true) { m_replaced = b; }
422     void setHasOverflowClip(bool b = true) { m_hasOverflowClip = b; }
423     void setHasLayer(bool b = true) { m_hasLayer = b; }
424     void setHasTransform(bool b = true) { m_hasTransform = b; }
425     void setHasReflection(bool b = true) { m_hasReflection = b; }
426
427     void scheduleRelayout();
428
429     void updateFillImages(const FillLayer*, const FillLayer*);
430     void updateImage(StyleImage*, StyleImage*);
431
432     virtual InlineBox* createInlineBox(bool makePlaceHolderBox, bool isRootLineBox, bool isOnlyRun = false);
433     virtual void dirtyLineBoxes(bool fullLayout, bool isRootLineBox = false);
434
435     // For inline replaced elements, this function returns the inline box that owns us.  Enables
436     // the replaced RenderObject to quickly determine what line it is contained on and to easily
437     // iterate over structures on the line.
438     virtual InlineBox* inlineBoxWrapper() const;
439     virtual void setInlineBoxWrapper(InlineBox*);
440     virtual void deleteLineBoxWrapper();
441
442     // for discussion of lineHeight see CSS2 spec
443     virtual int lineHeight(bool firstLine, bool isRootLineBox = false) const;
444     // for the vertical-align property of inline elements
445     // the difference between this objects baseline position and the lines baseline position.
446     virtual int verticalPositionHint(bool firstLine) const;<