~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/page/Frame.h

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

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