webengine/osswebengine/WebCore/page/Frame.h
changeset 0 dd21522fd290
equal deleted inserted replaced
-1:000000000000 0:dd21522fd290
       
     1 // -*- c-basic-offset: 4 -*-
       
     2 /*
       
     3  * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
       
     4  *                     1999-2001 Lars Knoll <knoll@kde.org>
       
     5  *                     1999-2001 Antti Koivisto <koivisto@kde.org>
       
     6  *                     2000-2001 Simon Hausmann <hausmann@kde.org>
       
     7  *                     2000-2001 Dirk Mueller <mueller@kde.org>
       
     8  *                     2000 Stefan Schimanski <1Stein@gmx.de>
       
     9  * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
       
    10  * Copyright (C) 2007 Trolltech ASA
       
    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 "Color.h"
       
    32 #include "EditAction.h"
       
    33 #include "DragImage.h"
       
    34 #include "RenderLayer.h"
       
    35 #include "TextGranularity.h"
       
    36 #include "VisiblePosition.h"
       
    37 #include <wtf/unicode/Unicode.h>
       
    38 #include <wtf/Forward.h>
       
    39 #include <wtf/Vector.h>
       
    40 
       
    41 struct NPObject;
       
    42 
       
    43 namespace KJS {
       
    44     class Interpreter;
       
    45     namespace Bindings {
       
    46         class Instance;
       
    47         class RootObject;
       
    48     }
       
    49 }
       
    50 
       
    51 #if PLATFORM(MAC)
       
    52 #ifdef __OBJC__
       
    53 @class NSArray;
       
    54 @class NSDictionary;
       
    55 @class NSMenu;
       
    56 @class NSMutableDictionary;
       
    57 @class NSString;
       
    58 @class WebCoreFrameBridge;
       
    59 @class WebScriptObject;
       
    60 #else
       
    61 class NSArray;
       
    62 class NSDictionary;
       
    63 class NSMenu;
       
    64 class NSMutableDictionary;
       
    65 class NSString;
       
    66 class WebCoreFrameBridge;
       
    67 class WebScriptObject;
       
    68 typedef int NSWritingDirection;
       
    69 #endif
       
    70 #endif
       
    71 
       
    72 #if PLATFORM(SYMBIAN)
       
    73 class WebCoreFrameBridge;
       
    74 #endif
       
    75 
       
    76 namespace WebCore {
       
    77 
       
    78 class CSSComputedStyleDeclaration;
       
    79 class CSSMutableStyleDeclaration;
       
    80 class CSSStyleDeclaration;
       
    81 class CommandByName;
       
    82 class DOMWindow;
       
    83 class Document;
       
    84 class Editor;
       
    85 class Element;
       
    86 class EventHandler;
       
    87 class FloatRect;
       
    88 class FrameLoader;
       
    89 class FrameLoaderClient;
       
    90 class HTMLFrameOwnerElement;
       
    91 class HTMLTableCellElement;
       
    92 class FramePrivate;
       
    93 class FrameTree;
       
    94 class FrameView;
       
    95 class GraphicsContext;
       
    96 class HTMLFormElement;
       
    97 class IntRect;
       
    98 class KJSProxy;
       
    99 class KURL;
       
   100 class Node;
       
   101 class Page;
       
   102 class Range;
       
   103 class RenderPart;
       
   104 class Selection;
       
   105 class SelectionController;
       
   106 class Settings;
       
   107 class Widget;
       
   108 
       
   109 struct FrameLoadRequest;
       
   110 
       
   111 template <typename T> class Timer;
       
   112 
       
   113 class Frame : public Shared<Frame> {
       
   114 public:
       
   115     Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
       
   116     virtual void setView(FrameView*);
       
   117     virtual ~Frame();
       
   118     
       
   119     void init();
       
   120 
       
   121 #if PLATFORM(MAC)    
       
   122     void setBridge(WebCoreFrameBridge*);
       
   123     WebCoreFrameBridge* bridge() const;
       
   124 #endif
       
   125 
       
   126 #if PLATFORM(SYMBIAN)
       
   127     void setBridge(WebCoreFrameBridge*);
       
   128     WebCoreFrameBridge* bridge() const;
       
   129 #endif
       
   130 
       
   131     Page* page() const;
       
   132     HTMLFrameOwnerElement* ownerElement() const;
       
   133 
       
   134     void pageDestroyed();
       
   135     void disconnectOwnerElement();
       
   136 
       
   137     Document* document() const;
       
   138     FrameView* view() const;
       
   139 
       
   140     CommandByName* command() const;
       
   141     DOMWindow* domWindow() const;
       
   142     Editor* editor() const;
       
   143     EventHandler* eventHandler() const;
       
   144     FrameLoader* loader() const;
       
   145     SelectionController* selectionController() const;
       
   146     FrameTree* tree() const;
       
   147 
       
   148     // FIXME: Rename to contentRenderer and change type to RenderView.
       
   149     RenderObject* renderer() const; // root renderer for the document contained in this frame
       
   150     RenderPart* ownerRenderer(); // renderer for the element that contains this frame
       
   151 
       
   152     friend class FramePrivate;
       
   153 
       
   154 private:
       
   155     FramePrivate* d;
       
   156     
       
   157 // === undecided, would like to consider moving to another class
       
   158 
       
   159 public:
       
   160     static Frame* frameForWidget(const Widget*);
       
   161 
       
   162     Settings* settings() const; // can be NULL
       
   163     void reparseConfiguration();
       
   164 
       
   165     void setUserStyleSheetLocation(const KURL&);
       
   166     void setUserStyleSheet(const String& styleSheetData);
       
   167 
       
   168     void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);
       
   169 
       
   170     bool inViewSourceMode() const;
       
   171     void setInViewSourceMode(bool = true) const;
       
   172 
       
   173     void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
       
   174 #ifndef NDEBUG
       
   175     static void cancelAllKeepAlive();
       
   176 #endif
       
   177 
       
   178     KJS::Bindings::Instance* createScriptInstanceForWidget(Widget*);
       
   179     KJS::Bindings::RootObject* bindingRootObject();
       
   180     
       
   181     PassRefPtr<KJS::Bindings::RootObject> createRootObject(void* nativeHandle, PassRefPtr<KJS::Interpreter>);
       
   182 
       
   183 #if PLATFORM(MAC)
       
   184     WebScriptObject* windowScriptObject();
       
   185 #endif
       
   186 
       
   187 #if USE(NPOBJECT)
       
   188     NPObject* windowScriptNPObject();
       
   189 #endif    
       
   190     
       
   191     void setDocument(PassRefPtr<Document>);
       
   192 
       
   193     KJSProxy* scriptProxy();
       
   194 
       
   195     void clearTimers();
       
   196     static void clearTimers(FrameView*);
       
   197 
       
   198     bool isActive() const;
       
   199     void setIsActive(bool flag);
       
   200 
       
   201     // Convenience, to avoid repeating the code to dig down to get this.
       
   202     UChar backslashAsCurrencySymbol() const;
       
   203 
       
   204     void setNeedsReapplyStyles();
       
   205     String documentTypeString() const;
       
   206 
       
   207     void dashboardRegionsChanged();
       
   208 
       
   209     void clearScriptProxy();
       
   210     void clearDOMWindow();
       
   211 
       
   212     void clearScriptObjects();
       
   213     void cleanupScriptObjectsForPlugin(void*);
       
   214 
       
   215 private:
       
   216     void clearPlatformScriptObjects();
       
   217 
       
   218     void lifeSupportTimerFired(Timer<Frame>*);
       
   219     
       
   220 // === to be moved into Document
       
   221 
       
   222 public:
       
   223     bool isFrameSet() const;
       
   224 
       
   225 // === to be moved into EventHandler
       
   226 
       
   227 public:
       
   228     void sendResizeEvent();
       
   229     void sendScrollEvent();
       
   230 
       
   231     void setWindowHasFocus(bool flag);
       
   232 
       
   233 // === to be moved into FrameView
       
   234 
       
   235 public:
       
   236     void paint(GraphicsContext*, const IntRect&);
       
   237     void setPaintRestriction(PaintRestriction);
       
   238     bool isPainting() const;
       
   239 
       
   240     static double currentPaintTimeStamp() { return s_currentPaintTimeStamp; } // returns 0 if not painting
       
   241     
       
   242     void forceLayout(bool allowSubtree = false);
       
   243     void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);
       
   244 
       
   245     void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);
       
   246 
       
   247     void setZoomFactor(int percent);
       
   248     int zoomFactor() const; // FIXME: This is a multiplier for text size only; needs a better name.
       
   249 
       
   250     bool prohibitsScrolling() const;
       
   251     void setProhibitsScrolling(const bool);
       
   252 
       
   253 private:
       
   254     static double s_currentPaintTimeStamp; // used for detecting decoded resource thrash in the cache
       
   255 
       
   256 // === to be moved into Chrome
       
   257 
       
   258 public:
       
   259     void focusWindow();
       
   260     void unfocusWindow();
       
   261     bool shouldClose();
       
   262     void scheduleClose();
       
   263 
       
   264     void setJSStatusBarText(const String&);
       
   265     void setJSDefaultStatusBarText(const String&);
       
   266     String jsStatusBarText() const;
       
   267     String jsDefaultStatusBarText() const;
       
   268 
       
   269 // === to be moved into Editor
       
   270 
       
   271 public:
       
   272     String selectedText() const;  
       
   273     bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
       
   274 
       
   275     const Selection& mark() const; // Mark, to be used as emacs uses it.
       
   276     void setMark(const Selection&);
       
   277 
       
   278     void transpose();
       
   279 
       
   280     void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
       
   281     enum TriState { falseTriState, trueTriState, mixedTriState };
       
   282     TriState selectionHasStyle(CSSStyleDeclaration*) const;
       
   283     String selectionStartStylePropertyValue(int stylePropertyID) const;
       
   284     void applyEditingStyleToBodyElement() const;
       
   285     void removeEditingStyleFromBodyElement() const;
       
   286     void applyEditingStyleToElement(Element*) const;
       
   287     void removeEditingStyleFromElement(Element*) const;
       
   288 
       
   289     IntRect firstRectForRange(Range*) const;
       
   290     
       
   291     void issueTransposeCommand();
       
   292     void respondToChangedSelection(const Selection& oldSelection, bool closeTyping);
       
   293     bool shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity, bool stillSelecting) const;
       
   294 
       
   295     RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
       
   296 
       
   297     unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
       
   298     bool markedTextMatchesAreHighlighted() const;
       
   299     void setMarkedTextMatchesAreHighlighted(bool flag);
       
   300 
       
   301     CSSComputedStyleDeclaration* selectionComputedStyle(Node*& nodeToRemove) const;
       
   302 
       
   303     void textFieldDidBeginEditing(Element*);
       
   304     void textFieldDidEndEditing(Element*);
       
   305     void textDidChangeInTextField(Element*);
       
   306     bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
       
   307     void textWillBeDeletedInTextField(Element* input);
       
   308     void textDidChangeInTextArea(Element*);
       
   309 
       
   310     DragImageRef dragImageForSelection();
       
   311     
       
   312 // === to be moved into SelectionController
       
   313 
       
   314 public:
       
   315     TextGranularity selectionGranularity() const;
       
   316     void setSelectionGranularity(TextGranularity) const;
       
   317 
       
   318     bool shouldChangeSelection(const Selection&) const;
       
   319     bool shouldDeleteSelection(const Selection&) const;
       
   320     void clearCaretRectIfNeeded();
       
   321     void setFocusedNodeIfNeeded();
       
   322     void selectionLayoutChanged();
       
   323     void notifyRendererOfSelectionChange(bool userTriggered);
       
   324 
       
   325     void invalidateSelection();
       
   326 
       
   327     void setCaretVisible(bool = true);
       
   328     void paintCaret(GraphicsContext*, const IntRect&) const;  
       
   329     void paintDragCaret(GraphicsContext*, const IntRect&) const;
       
   330 
       
   331     bool isContentEditable() const; // if true, everything in frame is editable
       
   332 
       
   333     void updateSecureKeyboardEntryIfActive();
       
   334 
       
   335     CSSMutableStyleDeclaration* typingStyle() const;
       
   336     void setTypingStyle(CSSMutableStyleDeclaration*);
       
   337     void clearTypingStyle();
       
   338 
       
   339     FloatRect selectionRect(bool clipToVisibleContent = true) const;
       
   340     void selectionTextRects(Vector<FloatRect>&, bool clipToVisibleContent = true) const;
       
   341 
       
   342     HTMLFormElement* currentForm() const;
       
   343 
       
   344     void revealSelection(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
       
   345     void revealCaret(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
       
   346     void setSelectionFromNone();
       
   347 
       
   348 private:
       
   349     void caretBlinkTimerFired(Timer<Frame>*);
       
   350     void setUseSecureKeyboardEntry(bool);
       
   351 
       
   352 public:
       
   353     SelectionController* dragCaretController() const;
       
   354 
       
   355     String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
       
   356     String searchForLabelsBeforeElement(const Vector<String>& labels, Element*);
       
   357     String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
       
   358     
       
   359     VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
       
   360     Document* documentAtPoint(const IntPoint& windowPoint);
       
   361 #if PLATFORM(MAC)
       
   362 
       
   363 // === undecided, would like to consider moving to another class
       
   364 
       
   365 public:
       
   366     NSString* searchForNSLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
       
   367     NSString* searchForLabelsBeforeElement(NSArray* labels, Element*);
       
   368     NSString* matchLabelsAgainstElement(NSArray* labels, Element*);
       
   369 
       
   370     NSMutableDictionary* dashboardRegionsDictionary();
       
   371 
       
   372     void willPopupMenu(NSMenu*);
       
   373 
       
   374     NSImage* selectionImage(bool forceBlackText = false) const;
       
   375     NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;
       
   376 
       
   377 private:    
       
   378     NSImage* imageFromRect(NSRect) const;
       
   379 
       
   380 // === to be moved into Chrome
       
   381 
       
   382 public:
       
   383     FloatRect customHighlightLineRect(const AtomicString& type, const FloatRect& lineRect, Node*);
       
   384     void paintCustomHighlight(const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool text, bool line, Node*);
       
   385 
       
   386 // === to be moved into Editor
       
   387 
       
   388 public:
       
   389     NSDictionary* fontAttributesForSelectionStart() const;
       
   390     NSWritingDirection baseWritingDirectionForSelectionStart() const;
       
   391     void issuePasteCommand();
       
   392 
       
   393 #endif
       
   394 
       
   395 };
       
   396 
       
   397 } // namespace WebCore
       
   398 
       
   399 #endif // Frame_h