Home | History | Annotate | Download | only in rendering
      1 /*
      2  * Copyright (C) 1999 Lars Knoll (knoll (at) kde.org)
      3  * Copyright (C) 2004, 2005, 2006, 2009, 2010 Apple Inc. All rights reserved.
      4  *
      5  * This library is free software; you can redistribute it and/or
      6  * modify it under the terms of the GNU Library General Public
      7  * License as published by the Free Software Foundation; either
      8  * version 2 of the License, or (at your option) any later version.
      9  *
     10  * This library is distributed in the hope that it will be useful,
     11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     13  * Library General Public License for more details.
     14  *
     15  * You should have received a copy of the GNU Library General Public License
     16  * along with this library; see the file COPYING.LIB.  If not, write to
     17  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     18  * Boston, MA 02110-1301, USA.
     19  *
     20  */
     21 
     22 #ifndef RenderWidget_h
     23 #define RenderWidget_h
     24 
     25 #include "core/platform/Widget.h"
     26 #include "core/rendering/RenderReplaced.h"
     27 
     28 namespace WebCore {
     29 
     30 class WidgetHierarchyUpdatesSuspensionScope {
     31 public:
     32     WidgetHierarchyUpdatesSuspensionScope()
     33     {
     34         s_widgetHierarchyUpdateSuspendCount++;
     35     }
     36     ~WidgetHierarchyUpdatesSuspensionScope()
     37     {
     38         ASSERT(s_widgetHierarchyUpdateSuspendCount);
     39         if (s_widgetHierarchyUpdateSuspendCount == 1)
     40             moveWidgets();
     41         s_widgetHierarchyUpdateSuspendCount--;
     42     }
     43 
     44     static bool isSuspended() { return s_widgetHierarchyUpdateSuspendCount; }
     45     static void scheduleWidgetToMove(Widget* widget, FrameView* frame) { widgetNewParentMap().set(widget, frame); }
     46 
     47 private:
     48     typedef HashMap<RefPtr<Widget>, FrameView*> WidgetToParentMap;
     49     static WidgetToParentMap& widgetNewParentMap();
     50 
     51     void moveWidgets();
     52 
     53     static unsigned s_widgetHierarchyUpdateSuspendCount;
     54 };
     55 
     56 class RenderWidget : public RenderReplaced {
     57 public:
     58     virtual ~RenderWidget();
     59 
     60     Widget* widget() const { return m_widget.get(); }
     61     virtual void setWidget(PassRefPtr<Widget>);
     62 
     63     static RenderWidget* find(const Widget*);
     64 
     65     void updateWidgetPosition();
     66     void widgetPositionsUpdated();
     67     IntRect windowClipRect() const;
     68 
     69     void setIsOverlapped(bool);
     70 
     71     void ref() { ++m_refCount; }
     72     void deref();
     73 
     74 protected:
     75     RenderWidget(Element*);
     76 
     77     FrameView* frameView() const { return m_frameView; }
     78 
     79     void clearWidget();
     80 
     81     virtual void styleDidChange(StyleDifference, const RenderStyle* oldStyle) OVERRIDE FINAL;
     82     virtual void layout();
     83     virtual void paint(PaintInfo&, const LayoutPoint&);
     84     virtual CursorDirective getCursor(const LayoutPoint&, Cursor&) const;
     85     virtual bool nodeAtPoint(const HitTestRequest&, HitTestResult&, const HitTestLocation& locationInContainer, const LayoutPoint& accumulatedOffset, HitTestAction) OVERRIDE;
     86 
     87     virtual void paintContents(PaintInfo&, const LayoutPoint&);
     88 
     89 private:
     90     virtual bool isWidget() const OVERRIDE FINAL { return true; }
     91 
     92     virtual void willBeDestroyed() OVERRIDE FINAL;
     93     virtual void destroy() OVERRIDE FINAL;
     94 
     95     bool setWidgetGeometry(const LayoutRect&);
     96     bool updateWidgetGeometry();
     97 
     98     RefPtr<Widget> m_widget;
     99     FrameView* m_frameView;
    100     IntRect m_clipRect; // The rectangle needs to remain correct after scrolling, so it is stored in content view coordinates, and not clipped to window.
    101     int m_refCount;
    102 };
    103 
    104 inline RenderWidget* toRenderWidget(RenderObject* object)
    105 {
    106     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isWidget());
    107     return static_cast<RenderWidget*>(object);
    108 }
    109 
    110 inline const RenderWidget* toRenderWidget(const RenderObject* object)
    111 {
    112     ASSERT_WITH_SECURITY_IMPLICATION(!object || object->isWidget());
    113     return static_cast<const RenderWidget*>(object);
    114 }
    115 
    116 // This will catch anyone doing an unnecessary cast.
    117 void toRenderWidget(const RenderWidget*);
    118 
    119 } // namespace WebCore
    120 
    121 #endif // RenderWidget_h
    122