Home | History | Annotate | Download | only in page
      1 /*
      2  * Copyright (C) 1998, 1999 Torben Weis <weis (at) kde.org>
      3  *                     1999-2001 Lars Knoll <knoll (at) kde.org>
      4  *                     1999-2001 Antti Koivisto <koivisto (at) kde.org>
      5  *                     2000-2001 Simon Hausmann <hausmann (at) kde.org>
      6  *                     2000-2001 Dirk Mueller <mueller (at) kde.org>
      7  *                     2000 Stefan Schimanski <1Stein (at) gmx.de>
      8  * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
      9  * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
     10  * Copyright (C) 2008 Eric Seidel <eric (at) webkit.org>
     11  *
     12  * This library is free software; you can redistribute it and/or
     13  * modify it under the terms of the GNU Library General Public
     14  * License as published by the Free Software Foundation; either
     15  * version 2 of the License, or (at your option) any later version.
     16  *
     17  * This library is distributed in the hope that it will be useful,
     18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
     19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     20  * Library General Public License for more details.
     21  *
     22  * You should have received a copy of the GNU Library General Public License
     23  * along with this library; see the file COPYING.LIB.  If not, write to
     24  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     25  * Boston, MA 02110-1301, USA.
     26  */
     27 
     28 #ifndef Frame_h
     29 #define Frame_h
     30 
     31 #include "AnimationController.h"
     32 #include "DragImage.h"
     33 #include "Editor.h"
     34 #include "EventHandler.h"
     35 #include "FrameLoader.h"
     36 #include "FrameTree.h"
     37 #include "ScriptController.h"
     38 #include "ScrollBehavior.h"
     39 #include "SelectionController.h"
     40 #include "UserScriptTypes.h"
     41 
     42 #if PLATFORM(WIN)
     43 #include "FrameWin.h"
     44 #endif
     45 
     46 #if PLATFORM(MAC)
     47 #ifndef __OBJC__
     48 class NSArray;
     49 class NSDictionary;
     50 class NSMutableDictionary;
     51 class NSString;
     52 typedef int NSWritingDirection;
     53 #endif
     54 #endif
     55 
     56 #if PLATFORM(WIN)
     57 typedef struct HBITMAP__* HBITMAP;
     58 #endif
     59 
     60 namespace WebCore {
     61 
     62     class CSSMutableStyleDeclaration;
     63     class HTMLTableCellElement;
     64     class RegularExpression;
     65 
     66     class Frame : public RefCounted<Frame> {
     67     public:
     68         static PassRefPtr<Frame> create(Page* page, HTMLFrameOwnerElement* ownerElement, FrameLoaderClient* client)
     69         {
     70             return adoptRef(new Frame(page, ownerElement, client));
     71         }
     72         void setView(PassRefPtr<FrameView>);
     73         ~Frame();
     74 
     75         void init();
     76 
     77         Page* page() const;
     78         void detachFromPage();
     79         HTMLFrameOwnerElement* ownerElement() const;
     80 
     81         void pageDestroyed();
     82         void disconnectOwnerElement();
     83 
     84         Document* document() const;
     85         FrameView* view() const;
     86 
     87         void setDOMWindow(DOMWindow*);
     88         DOMWindow* domWindow() const;
     89         void clearFormerDOMWindow(DOMWindow*);
     90 
     91         Editor* editor() const;
     92         EventHandler* eventHandler() const;
     93         FrameLoader* loader() const;
     94         RedirectScheduler* redirectScheduler() const;
     95         SelectionController* selection() const;
     96         FrameTree* tree() const;
     97         AnimationController* animation() const;
     98         ScriptController* script();
     99 
    100         RenderView* contentRenderer() const; // root renderer for the document contained in this frame
    101         RenderPart* ownerRenderer() const; // renderer for the element that contains this frame
    102 
    103         bool isDisconnected() const;
    104         void setIsDisconnected(bool);
    105         bool excludeFromTextSearch() const;
    106         void setExcludeFromTextSearch(bool);
    107 
    108         void createView(const IntSize&, const Color&, bool, const IntSize &, bool,
    109                         ScrollbarMode = ScrollbarAuto, ScrollbarMode = ScrollbarAuto);
    110 
    111         void injectUserScripts(UserScriptInjectionTime);
    112 
    113     private:
    114         void injectUserScriptsForWorld(DOMWrapperWorld*, const UserScriptVector&, UserScriptInjectionTime);
    115 
    116     private:
    117         Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
    118 
    119     // === undecided, would like to consider moving to another class
    120 
    121     public:
    122         static Frame* frameForWidget(const Widget*);
    123 
    124         Settings* settings() const; // can be NULL
    125 
    126         void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
    127 
    128         bool inViewSourceMode() const;
    129         void setInViewSourceMode(bool = true);
    130 
    131         void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
    132     #ifndef NDEBUG
    133         static void cancelAllKeepAlive();
    134     #endif
    135 
    136         void setDocument(PassRefPtr<Document>);
    137 
    138 #if ENABLE(ORIENTATION_EVENTS)
    139         // Orientation is the interface orientation in degrees. Some examples are:
    140         //  0 is straight up; -90 is when the device is rotated 90 clockwise;
    141         //  90 is when rotated counter clockwise.
    142         void sendOrientationChangeEvent(int orientation);
    143         int orientation() const { return m_orientation; }
    144 #endif
    145 
    146         void clearTimers();
    147         static void clearTimers(FrameView*, Document*);
    148 
    149         void setNeedsReapplyStyles();
    150         bool needsReapplyStyles() const;
    151         void reapplyStyles();
    152 
    153         String documentTypeString() const;
    154 
    155         // This method -- and the corresponding list of former DOM windows --
    156         // should move onto ScriptController
    157         void clearDOMWindow();
    158 
    159         String displayStringModifiedByEncoding(const String& str) const
    160         {
    161             return document() ? document()->displayStringModifiedByEncoding(str) : str;
    162         }
    163 
    164     private:
    165         void lifeSupportTimerFired(Timer<Frame>*);
    166 
    167     // === to be moved into FrameView
    168 
    169     public:
    170         void setZoomFactor(float scale, bool isTextOnly);
    171         float zoomFactor() const;
    172         bool isZoomFactorTextOnly() const;
    173         bool shouldApplyTextZoom() const;
    174         bool shouldApplyPageZoom() const;
    175         float pageZoomFactor() const { return shouldApplyPageZoom() ? zoomFactor() : 1.0f; }
    176         float textZoomFactor() const { return shouldApplyTextZoom() ? zoomFactor() : 1.0f; }
    177 
    178     // === to be moved into Chrome
    179 
    180     public:
    181         void focusWindow();
    182         void unfocusWindow();
    183         bool shouldClose();
    184         void scheduleClose();
    185 
    186         void setJSStatusBarText(const String&);
    187         void setJSDefaultStatusBarText(const String&);
    188         String jsStatusBarText() const;
    189         String jsDefaultStatusBarText() const;
    190 
    191     // === to be moved into Editor
    192 
    193     public:
    194         String selectedText() const;
    195         bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
    196 
    197         const VisibleSelection& mark() const; // Mark, to be used as emacs uses it.
    198         void setMark(const VisibleSelection&);
    199 
    200         void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
    201         String selectionStartStylePropertyValue(int stylePropertyID) const;
    202         void applyEditingStyleToBodyElement() const;
    203         void removeEditingStyleFromBodyElement() const;
    204         void applyEditingStyleToElement(Element*) const;
    205         void removeEditingStyleFromElement(Element*) const;
    206 
    207         IntRect firstRectForRange(Range*) const;
    208 
    209         void respondToChangedSelection(const VisibleSelection& oldSelection, bool closeTyping);
    210         bool shouldChangeSelection(const VisibleSelection& oldSelection, const VisibleSelection& newSelection, EAffinity, bool stillSelecting) const;
    211 
    212         RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
    213 
    214         unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
    215         bool markedTextMatchesAreHighlighted() const;
    216         void setMarkedTextMatchesAreHighlighted(bool flag);
    217 
    218         PassRefPtr<CSSComputedStyleDeclaration> selectionComputedStyle(Node*& nodeToRemove) const;
    219 
    220         void textFieldDidBeginEditing(Element*);
    221         void textFieldDidEndEditing(Element*);
    222         void textDidChangeInTextField(Element*);
    223         bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
    224         void textWillBeDeletedInTextField(Element* input);
    225         void textDidChangeInTextArea(Element*);
    226 
    227         DragImageRef dragImageForSelection();
    228 
    229     // === to be moved into SelectionController
    230 
    231     public:
    232         TextGranularity selectionGranularity() const;
    233         void setSelectionGranularity(TextGranularity);
    234 
    235         bool shouldChangeSelection(const VisibleSelection&) const;
    236         bool shouldDeleteSelection(const VisibleSelection&) const;
    237         void setFocusedNodeIfNeeded();
    238         void notifyRendererOfSelectionChange(bool userTriggered);
    239 
    240         void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const;
    241 
    242         bool isContentEditable() const; // if true, everything in frame is editable
    243 
    244         void updateSecureKeyboardEntryIfActive();
    245 
    246         CSSMutableStyleDeclaration* typingStyle() const;
    247         void setTypingStyle(CSSMutableStyleDeclaration*);
    248         void clearTypingStyle();
    249 
    250         FloatRect selectionBounds(bool clipToVisibleContent = true) const;
    251         enum SelectionRectRespectTransforms { RespectTransforms = true, IgnoreTransforms = false };
    252         void selectionTextRects(Vector<FloatRect>&, SelectionRectRespectTransforms respectTransforms, bool clipToVisibleContent = true) const;
    253 
    254         HTMLFormElement* currentForm() const;
    255 
    256         void revealSelection(const ScrollAlignment& = ScrollAlignment::alignCenterIfNeeded, bool revealExtent = false);
    257         void setSelectionFromNone();
    258 
    259         void setUseSecureKeyboardEntry(bool);
    260 
    261         SelectionController* dragCaretController() const;
    262 
    263         String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
    264         String searchForLabelsBeforeElement(const Vector<String>& labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
    265         String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
    266 
    267         VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
    268         Document* documentAtPoint(const IntPoint& windowPoint);
    269 
    270     #if PLATFORM(MAC)
    271 
    272     // === undecided, would like to consider moving to another class
    273 
    274     public:
    275         NSString* searchForNSLabelsAboveCell(RegularExpression*, HTMLTableCellElement*, size_t* resultDistanceFromStartOfCell);
    276         NSString* searchForLabelsBeforeElement(NSArray* labels, Element*, size_t* resultDistance, bool* resultIsInCellAbove);
    277         NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
    278 
    279     #if ENABLE(DASHBOARD_SUPPORT)
    280         NSMutableDictionary* dashboardRegionsDictionary();
    281     #endif
    282 
    283         NSImage* selectionImage(bool forceBlackText = false) const;
    284         NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
    285         NSImage* nodeImage(Node*) const;
    286 
    287     private:
    288         NSImage* imageFromRect(NSRect) const;
    289 
    290     // === to be moved into Editor
    291 
    292     public:
    293         NSDictionary* fontAttributesForSelectionStart() const;
    294         NSWritingDirection baseWritingDirectionForSelectionStart() const;
    295 
    296     #endif
    297 
    298     #if PLATFORM(WIN)
    299 
    300     public:
    301         // FIXME - We should have a single version of nodeImage instead of using platform types.
    302         HBITMAP nodeImage(Node*) const;
    303 
    304     #endif
    305 
    306     private:
    307         Page* m_page;
    308         mutable FrameTree m_treeNode;
    309         mutable FrameLoader m_loader;
    310         mutable RedirectScheduler m_redirectScheduler;
    311 
    312         mutable RefPtr<DOMWindow> m_domWindow;
    313         HashSet<DOMWindow*> m_liveFormerWindows;
    314 
    315         HTMLFrameOwnerElement* m_ownerElement;
    316         RefPtr<FrameView> m_view;
    317         RefPtr<Document> m_doc;
    318 
    319         ScriptController m_script;
    320 
    321         String m_kjsStatusBarText;
    322         String m_kjsDefaultStatusBarText;
    323 
    324         float m_zoomFactor;
    325 
    326         TextGranularity m_selectionGranularity;
    327 
    328         mutable SelectionController m_selectionController;
    329         mutable VisibleSelection m_mark;
    330         mutable Editor m_editor;
    331         mutable EventHandler m_eventHandler;
    332         mutable AnimationController m_animationController;
    333 
    334         RefPtr<CSSMutableStyleDeclaration> m_typingStyle;
    335 
    336         Timer<Frame> m_lifeSupportTimer;
    337 
    338 #if ENABLE(ORIENTATION_EVENTS)
    339         int m_orientation;
    340 #endif
    341 
    342         bool m_highlightTextMatches;
    343         bool m_inViewSourceMode;
    344         bool m_needsReapplyStyles;
    345         bool m_isDisconnected;
    346         bool m_excludeFromTextSearch;
    347     };
    348 
    349 } // namespace WebCore
    350 
    351 #endif // Frame_h
    352