• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple Inc. All rights reserved.
3  * Portions Copyright (c) 2010 Motorola Mobility, Inc.  All rights reserved.
4  * Copyright (C) 2011 Igalia S.L.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
17  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
18  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
19  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25  * THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
28 #ifndef WebView_h
29 #define WebView_h
30 
31 #include "PageClient.h"
32 #include "WebPageProxy.h"
33 #include "WindowsKeyboardCodes.h"
34 #include <WebCore/IntSize.h>
35 #include <gdk/gdk.h>
36 #include <glib.h>
37 #include <gtk/gtk.h>
38 #include <wtf/PassRefPtr.h>
39 #include <wtf/RefCounted.h>
40 #include <wtf/RefPtr.h>
41 
42 namespace WebKit {
43 
44 class DrawingAreaProxy;
45 class WebPageNamespace;
46 
47 class WebView : public RefCounted<WebView>, public PageClient {
48 public:
49     ~WebView();
create(WebContext * context,WebPageGroup * pageGroup)50     static PassRefPtr<WebView> create(WebContext* context, WebPageGroup* pageGroup)
51     {
52         return adoptRef(new WebView(context, pageGroup));
53     }
54 
window()55     GtkWidget* window() const { return m_viewWidget; }
56 
page()57     WebPageProxy* page() const { return m_page.get(); }
58 
59     void handleFocusInEvent(GtkWidget*);
60     void handleFocusOutEvent(GtkWidget*);
61 
62     void paint(GtkWidget*, GdkRectangle, cairo_t*);
63     void setSize(GtkWidget*, WebCore::IntSize);
64     void handleKeyboardEvent(GdkEventKey*);
65     void handleWheelEvent(GdkEventScroll*);
66     void handleMouseEvent(GdkEvent*, int);
67 
addPendingEditorCommand(const char * command)68     void addPendingEditorCommand(const char* command) { m_pendingEditorCommands.append(WTF::String(command)); }
69 
70 private:
71     WebView(WebContext*, WebPageGroup*);
72 
73     GdkWindow* getWebViewWindow();
74 
75     bool isActive();
76     void close();
77 
78     // PageClient
79     virtual PassOwnPtr<DrawingAreaProxy> createDrawingAreaProxy();
80     virtual void setViewNeedsDisplay(const WebCore::IntRect&);
81     virtual void displayView();
82     virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
83     virtual WebCore::IntSize viewSize();
84     virtual bool isViewWindowActive();
85     virtual bool isViewFocused();
86     virtual bool isViewVisible();
87     virtual bool isViewInWindow();
88     virtual void processDidCrash();
89     virtual void didRelaunchProcess();
90     virtual void pageClosed();
91     virtual void takeFocus(bool direction);
92     virtual void toolTipChanged(const WTF::String&, const WTF::String&);
93     virtual void setCursor(const WebCore::Cursor&);
94     virtual void setViewportArguments(const WebCore::ViewportArguments&);
95     virtual void registerEditCommand(PassRefPtr<WebEditCommandProxy>, WebPageProxy::UndoOrRedo);
96     virtual void clearAllEditCommands();
97     virtual bool canUndoRedo(WebPageProxy::UndoOrRedo);
98     virtual void executeUndoRedo(WebPageProxy::UndoOrRedo);
99     virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
100     virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
101     virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&);
102     virtual void doneWithKeyEvent(const NativeWebKeyboardEvent&, bool wasEventHandled);
103     virtual void didNotHandleKeyEvent(const NativeWebKeyboardEvent&);
104     virtual PassRefPtr<WebPopupMenuProxy> createPopupMenuProxy(WebPageProxy*);
105     virtual PassRefPtr<WebContextMenuProxy> createContextMenuProxy(WebPageProxy*);
106     virtual void setFindIndicator(PassRefPtr<FindIndicator>, bool fadeOut);
107     virtual void didChangeScrollbarsForMainFrame() const;
108     virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
userSpaceScaleFactor()109     virtual float userSpaceScaleFactor() const { return 1; }
110     virtual void getEditorCommandsForKeyEvent(const NativeWebKeyboardEvent&, Vector<WTF::String>&);
111     virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned);
112     virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned);
113 
114 #if USE(ACCELERATED_COMPOSITING)
115     virtual void pageDidEnterAcceleratedCompositing();
116     virtual void pageDidLeaveAcceleratedCompositing();
117 #endif
118 
119     virtual void didCommitLoadForMainFrame(bool useCustomRepresentation);
120     virtual void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&);
121     virtual double customRepresentationZoomFactor();
122     virtual void setCustomRepresentationZoomFactor(double);
123 
124     // Members of WebView class
125     GtkWidget* m_viewWidget;
126     bool m_isPageActive;
127     RefPtr<WebPageProxy> m_page;
128     Vector<WTF::String> m_pendingEditorCommands;
129     GRefPtr<GtkWidget> m_nativeWidget;
130 };
131 
132 } // namespace WebKit
133 
134 #endif // WebView_h
135