Frame.h 11.5 KB
Newer Older
darin's avatar
darin committed
1
// -*- c-basic-offset: 4 -*-
darin's avatar
darin committed
2
/*
kocienda's avatar
kocienda committed
3
 * Copyright (C) 1998, 1999 Torben Weis <weis@kde.org>
4 5 6 7
 *                     1999-2001 Lars Knoll <knoll@kde.org>
 *                     1999-2001 Antti Koivisto <koivisto@kde.org>
 *                     2000-2001 Simon Hausmann <hausmann@kde.org>
 *                     2000-2001 Dirk Mueller <mueller@kde.org>
kocienda's avatar
kocienda committed
8
 *                     2000 Stefan Schimanski <1Stein@gmx.de>
darin's avatar
darin committed
9
 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
mjs's avatar
mjs committed
10
 * Copyright (C) 2007 Trolltech ASA
kocienda's avatar
kocienda committed
11 12 13 14 15 16 17 18 19 20 21 22 23
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public License
 * along with this library; see the file COPYING.LIB.  If not, write to
ddkilzer's avatar
ddkilzer committed
24 25
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
kocienda's avatar
kocienda committed
26 27
 */

28 29
#ifndef Frame_h
#define Frame_h
darin's avatar
darin committed
30

darin's avatar
darin committed
31
#include "Color.h"
darin's avatar
darin committed
32
#include "EditAction.h"
33
#include "DragImage.h"
thatcher's avatar
thatcher committed
34
#include "RenderLayer.h"
darin's avatar
darin committed
35
#include "TextGranularity.h"
oliver's avatar
oliver committed
36
#include "VisiblePosition.h"
weinig's avatar
weinig committed
37
#include <wtf/unicode/Unicode.h>
darin's avatar
darin committed
38
#include <wtf/Forward.h>
mjs's avatar
mjs committed
39
#include <wtf/Vector.h>
kocienda's avatar
kocienda committed
40

41
struct NPObject;
mjs's avatar
mjs committed
42

kocienda's avatar
kocienda committed
43
namespace KJS {
ggaren@apple.com's avatar
ggaren@apple.com committed
44

mjs's avatar
mjs committed
45
    class Interpreter;
ggaren@apple.com's avatar
ggaren@apple.com committed
46 47
    class JSGlobalObject;

48 49
    namespace Bindings {
        class Instance;
50
        class RootObject;
51
    }
ggaren@apple.com's avatar
ggaren@apple.com committed
52

darin's avatar
darin committed
53
}
kocienda's avatar
kocienda committed
54

mjs's avatar
mjs committed
55 56 57 58 59 60 61 62
#if PLATFORM(MAC)
#ifdef __OBJC__
@class NSArray;
@class NSDictionary;
@class NSMenu;
@class NSMutableDictionary;
@class NSString;
@class WebCoreFrameBridge;
darin's avatar
darin committed
63
@class WebScriptObject;
mjs's avatar
mjs committed
64 65 66 67 68 69 70
#else
class NSArray;
class NSDictionary;
class NSMenu;
class NSMutableDictionary;
class NSString;
class WebCoreFrameBridge;
darin's avatar
darin committed
71
class WebScriptObject;
mjs's avatar
mjs committed
72 73 74 75
typedef int NSWritingDirection;
#endif
#endif

darin's avatar
darin committed
76 77
namespace WebCore {

78
class AnimationController;
darin's avatar
darin committed
79 80 81
class CSSComputedStyleDeclaration;
class CSSMutableStyleDeclaration;
class CSSStyleDeclaration;
ggaren's avatar
ggaren committed
82
class DOMWindow;
darin's avatar
darin committed
83
class Document;
aliceli1's avatar
aliceli1 committed
84
class Editor;
darin's avatar
darin committed
85
class Element;
darin's avatar
darin committed
86
class EventHandler;
darin's avatar
darin committed
87
class FloatRect;
beidson's avatar
beidson committed
88
class FrameLoader;
ggaren's avatar
ggaren committed
89
class FrameLoaderClient;
darin's avatar
darin committed
90
class HTMLFrameOwnerElement;
mjs's avatar
mjs committed
91
class HTMLTableCellElement;
darin's avatar
darin committed
92
class FramePrivate;
darin's avatar
darin committed
93
class FrameTree;
darin's avatar
darin committed
94 95 96 97
class FrameView;
class GraphicsContext;
class HTMLFormElement;
class IntRect;
darin's avatar
darin committed
98
class KJSProxy;
darin's avatar
darin committed
99 100
class KURL;
class Node;
darin's avatar
darin committed
101
class Page;
darin's avatar
darin committed
102
class Range;
darin's avatar
darin committed
103
class RenderPart;
darin's avatar
darin committed
104 105
class Selection;
class SelectionController;
darin's avatar
darin committed
106
class Settings;
darin's avatar
darin committed
107
class Widget;
darin's avatar
darin committed
108

darin's avatar
darin committed
109 110
struct FrameLoadRequest;

darin's avatar
darin committed
111 112
template <typename T> class Timer;

ggaren@apple.com's avatar
ggaren@apple.com committed
113
class Frame : public RefCounted<Frame> {
kocienda's avatar
kocienda committed
114
public:
darin's avatar
darin committed
115
    Frame(Page*, HTMLFrameOwnerElement*, FrameLoaderClient*);
darin's avatar
darin committed
116
    virtual void setView(FrameView*);
darin's avatar
darin committed
117
    virtual ~Frame();
ggaren's avatar
ggaren committed
118
    
mjs's avatar
mjs committed
119 120
    void init();

mjs's avatar
mjs committed
121 122 123 124 125
#if PLATFORM(MAC)    
    void setBridge(WebCoreFrameBridge*);
    WebCoreFrameBridge* bridge() const;
#endif

darin's avatar
darin committed
126
    Page* page() const;
darin's avatar
darin committed
127
    HTMLFrameOwnerElement* ownerElement() const;
darin's avatar
darin committed
128 129 130 131

    void pageDestroyed();
    void disconnectOwnerElement();

darin's avatar
darin committed
132 133 134 135 136
    Document* document() const;
    FrameView* view() const;

    DOMWindow* domWindow() const;
    Editor* editor() const;
darin's avatar
darin committed
137
    EventHandler* eventHandler() const;
darin's avatar
darin committed
138
    FrameLoader* loader() const;
darin's avatar
darin committed
139 140
    SelectionController* selectionController() const;
    FrameTree* tree() const;
141
    AnimationController* animationController() const;
darin's avatar
darin committed
142

143
    // FIXME: Rename to contentRenderer and change type to RenderView.
darin's avatar
darin committed
144 145
    RenderObject* renderer() const; // root renderer for the document contained in this frame
    RenderPart* ownerRenderer(); // renderer for the element that contains this frame
darin's avatar
darin committed
146 147

    friend class FramePrivate;
kocienda's avatar
kocienda committed
148

darin's avatar
darin committed
149 150
private:
    FramePrivate* d;
mjs's avatar
mjs committed
151
    
152
// === undecided, would like to consider moving to another class
darin's avatar
darin committed
153 154

public:
darin's avatar
darin committed
155 156
    static Frame* frameForWidget(const Widget*);

ggaren's avatar
ggaren committed
157
    Settings* settings() const; // can be NULL
darin's avatar
darin committed
158

darin's avatar
darin committed
159 160 161
    void setUserStyleSheetLocation(const KURL&);
    void setUserStyleSheet(const String& styleSheetData);

hyatt's avatar
hyatt committed
162 163
    void setPrinting(bool printing, float minPageWidth, float maxPageWidth, bool adjustViewSize);

darin's avatar
darin committed
164 165
    bool inViewSourceMode() const;
    void setInViewSourceMode(bool = true) const;
ggaren's avatar
ggaren committed
166

darin's avatar
darin committed
167
    void keepAlive(); // Used to keep the frame alive when running a script that might destroy it.
ggaren's avatar
ggaren committed
168 169 170
#ifndef NDEBUG
    static void cancelAllKeepAlive();
#endif
darin's avatar
darin committed
171

mjs's avatar
mjs committed
172 173 174
    KJS::Bindings::Instance* createScriptInstanceForWidget(Widget*);
    KJS::Bindings::RootObject* bindingRootObject();
    
ggaren@apple.com's avatar
ggaren@apple.com committed
175
    PassRefPtr<KJS::Bindings::RootObject> createRootObject(void* nativeHandle, KJS::JSGlobalObject*);
darin's avatar
darin committed
176

mjs's avatar
mjs committed
177 178 179
#if PLATFORM(MAC)
    WebScriptObject* windowScriptObject();
#endif
thatcher's avatar
thatcher committed
180 181

#if USE(NPOBJECT)
mjs's avatar
mjs committed
182
    NPObject* windowScriptNPObject();
thatcher's avatar
thatcher committed
183
#endif    
mjs's avatar
mjs committed
184
    
185
    void setDocument(PassRefPtr<Document>);
darin's avatar
darin committed
186 187 188 189 190 191 192

    KJSProxy* scriptProxy();

    void clearTimers();
    static void clearTimers(FrameView*);

    bool isActive() const;
mjs's avatar
mjs committed
193
    void setIsActive(bool flag);
darin's avatar
darin committed
194 195 196 197 198

    // Convenience, to avoid repeating the code to dig down to get this.
    UChar backslashAsCurrencySymbol() const;

    void setNeedsReapplyStyles();
199 200 201
    bool needsReapplyStyles() const;
    void reapplyStyles();

darin's avatar
darin committed
202 203
    String documentTypeString() const;

aroben's avatar
aroben committed
204 205
    void dashboardRegionsChanged();

weinig's avatar
weinig committed
206 207 208
    void clearScriptProxy();
    void clearDOMWindow();

thatcher's avatar
thatcher committed
209
    void clearScriptObjects();
andersca's avatar
andersca committed
210
    void cleanupScriptObjectsForPlugin(void*);
211 212

private:
thatcher's avatar
thatcher committed
213
    void clearPlatformScriptObjects();
darin's avatar
darin committed
214

mjs's avatar
mjs committed
215 216
    void lifeSupportTimerFired(Timer<Frame>*);
    
217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252
// === to be moved into Document

public:
    bool isFrameSet() const;

// === to be moved into EventHandler

public:
    void sendResizeEvent();
    void sendScrollEvent();

    void setWindowHasFocus(bool flag);

// === to be moved into FrameView

public:
    void paint(GraphicsContext*, const IntRect&);
    void setPaintRestriction(PaintRestriction);
    bool isPainting() const;

    static double currentPaintTimeStamp() { return s_currentPaintTimeStamp; } // returns 0 if not painting
    
    void forceLayout(bool allowSubtree = false);
    void forceLayoutWithPageWidthRange(float minPageWidth, float maxPageWidth, bool adjustViewSize);

    void adjustPageHeight(float* newBottom, float oldTop, float oldBottom, float bottomLimit);

    void setZoomFactor(int percent);
    int zoomFactor() const; // FIXME: This is a multiplier for text size only; needs a better name.

    bool prohibitsScrolling() const;
    void setProhibitsScrolling(const bool);

private:
    static double s_currentPaintTimeStamp; // used for detecting decoded resource thrash in the cache

darin's avatar
darin committed
253
// === to be moved into Chrome
kocienda's avatar
kocienda committed
254

ggaren's avatar
ggaren committed
255
public:
mjs's avatar
mjs committed
256 257
    void focusWindow();
    void unfocusWindow();
258 259
    bool shouldClose();
    void scheduleClose();
mjs's avatar
mjs committed
260

261 262 263 264 265
    void setJSStatusBarText(const String&);
    void setJSDefaultStatusBarText(const String&);
    String jsStatusBarText() const;
    String jsDefaultStatusBarText() const;

darin's avatar
darin committed
266 267 268
// === to be moved into Editor

public:
mjs's avatar
mjs committed
269
    String selectedText() const;  
sullivan's avatar
sullivan committed
270
    bool findString(const String&, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection);
darin's avatar
darin committed
271 272 273 274 275 276 277 278 279 280 281 282 283

    const Selection& mark() const; // Mark, to be used as emacs uses it.
    void setMark(const Selection&);

    void computeAndSetTypingStyle(CSSStyleDeclaration* , EditAction = EditActionUnspecified);
    enum TriState { falseTriState, trueTriState, mixedTriState };
    TriState selectionHasStyle(CSSStyleDeclaration*) const;
    String selectionStartStylePropertyValue(int stylePropertyID) const;
    void applyEditingStyleToBodyElement() const;
    void removeEditingStyleFromBodyElement() const;
    void applyEditingStyleToElement(Element*) const;
    void removeEditingStyleFromElement(Element*) const;

oliver's avatar
oliver committed
284
    IntRect firstRectForRange(Range*) const;
oliver's avatar
oliver committed
285
    
mjs's avatar
mjs committed
286 287
    void respondToChangedSelection(const Selection& oldSelection, bool closeTyping);
    bool shouldChangeSelection(const Selection& oldSelection, const Selection& newSelection, EAffinity, bool stillSelecting) const;
darin's avatar
darin committed
288

weinig's avatar
weinig committed
289
    RenderStyle* styleForSelectionStart(Node*& nodeToRemove) const;
darin's avatar
darin committed
290 291 292 293

    unsigned markAllMatchesForText(const String&, bool caseFlag, unsigned limit);
    bool markedTextMatchesAreHighlighted() const;
    void setMarkedTextMatchesAreHighlighted(bool flag);
andersca's avatar
andersca committed
294

darin's avatar
darin committed
295 296
    CSSComputedStyleDeclaration* selectionComputedStyle(Node*& nodeToRemove) const;

mjs's avatar
mjs committed
297 298 299 300 301 302
    void textFieldDidBeginEditing(Element*);
    void textFieldDidEndEditing(Element*);
    void textDidChangeInTextField(Element*);
    bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*);
    void textWillBeDeletedInTextField(Element* input);
    void textDidChangeInTextArea(Element*);
darin's avatar
darin committed
303

304 305
    DragImageRef dragImageForSelection();
    
darin's avatar
darin committed
306
// === to be moved into SelectionController
darin's avatar
darin committed
307

darin's avatar
darin committed
308
public:
darin's avatar
darin committed
309 310
    TextGranularity selectionGranularity() const;
    void setSelectionGranularity(TextGranularity) const;
311

darin's avatar
darin committed
312
    bool shouldChangeSelection(const Selection&) const;
mjs's avatar
mjs committed
313
    bool shouldDeleteSelection(const Selection&) const;
darin's avatar
darin committed
314
    void clearCaretRectIfNeeded();
ggaren's avatar
ggaren committed
315
    void setFocusedNodeIfNeeded();
darin's avatar
darin committed
316 317
    void selectionLayoutChanged();
    void notifyRendererOfSelectionChange(bool userTriggered);
mjs's avatar
mjs committed
318

darin's avatar
darin committed
319
    void invalidateSelection();
darin's avatar
darin committed
320

darin's avatar
darin committed
321 322 323
    void setCaretVisible(bool = true);
    void paintCaret(GraphicsContext*, const IntRect&) const;  
    void paintDragCaret(GraphicsContext*, const IntRect&) const;
mjs's avatar
mjs committed
324

mjs's avatar
mjs committed
325
    bool isContentEditable() const; // if true, everything in frame is editable
darin's avatar
darin committed
326

beidson's avatar
beidson committed
327
    void updateSecureKeyboardEntryIfActive();
darin's avatar
darin committed
328 329 330 331 332

    CSSMutableStyleDeclaration* typingStyle() const;
    void setTypingStyle(CSSMutableStyleDeclaration*);
    void clearTypingStyle();

adele's avatar
adele committed
333
    FloatRect selectionRect(bool clipToVisibleContent = true) const;
sullivan's avatar
sullivan committed
334
    void selectionTextRects(Vector<FloatRect>&, bool clipToVisibleContent = true) const;
darin's avatar
darin committed
335 336 337 338 339 340 341

    HTMLFormElement* currentForm() const;

    void revealSelection(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
    void revealCaret(const RenderLayer::ScrollAlignment& = RenderLayer::gAlignCenterIfNeeded) const;
    void setSelectionFromNone();

darin's avatar
darin committed
342 343
private:
    void caretBlinkTimerFired(Timer<Frame>*);
darin's avatar
darin committed
344
    void setUseSecureKeyboardEntry(bool);
darin's avatar
darin committed
345

darin's avatar
darin committed
346 347
public:
    SelectionController* dragCaretController() const;
mjs's avatar
mjs committed
348

mjs's avatar
mjs committed
349 350 351
    String searchForLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
    String searchForLabelsBeforeElement(const Vector<String>& labels, Element*);
    String matchLabelsAgainstElement(const Vector<String>& labels, Element*);
oliver's avatar
oliver committed
352 353 354
    
    VisiblePosition visiblePositionForPoint(const IntPoint& framePoint);
    Document* documentAtPoint(const IntPoint& windowPoint);
355

mjs's avatar
mjs committed
356
#if PLATFORM(MAC)
darin's avatar
darin committed
357

358
// === undecided, would like to consider moving to another class
mjs's avatar
mjs committed
359 360 361 362 363 364 365 366 367 368

public:
    NSString* searchForNSLabelsAboveCell(RegularExpression*, HTMLTableCellElement*);
    NSString* searchForLabelsBeforeElement(NSArray* labels, Element*);
    NSString* matchLabelsAgainstElement(NSArray* labels, Element*);

    NSMutableDictionary* dashboardRegionsDictionary();

    void willPopupMenu(NSMenu*);

sullivan's avatar
sullivan committed
369
    NSImage* selectionImage(bool forceBlackText = false) const;
mjs's avatar
mjs committed
370 371 372 373 374 375 376 377
    NSImage* snapshotDragImage(Node*, NSRect* imageRect, NSRect* elementRect) const;

private:    
    NSImage* imageFromRect(NSRect) const;

// === to be moved into Chrome

public:
thatcher's avatar
thatcher committed
378 379
    FloatRect customHighlightLineRect(const AtomicString& type, const FloatRect& lineRect, Node*);
    void paintCustomHighlight(const AtomicString& type, const FloatRect& boxRect, const FloatRect& lineRect, bool text, bool line, Node*);
mjs's avatar
mjs committed
380 381 382 383 384 385

// === to be moved into Editor

public:
    NSDictionary* fontAttributesForSelectionStart() const;
    NSWritingDirection baseWritingDirectionForSelectionStart() const;
386
    void issuePasteCommand();
mjs's avatar
mjs committed
387 388

#endif
darin's avatar
darin committed
389

darin's avatar
darin committed
390
};
kocienda's avatar
kocienda committed
391

weinig's avatar
weinig committed
392
} // namespace WebCore
darin's avatar
darin committed
393

394
#endif // Frame_h