Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: chrome/browser/tab_contents/tab_contents_view.h

Issue 6537015: Start moving core pieces of Chrome multi-process code to src\content. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_
6 #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ 6 #define CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_
7 #pragma once 7 #pragma once
8 8
9 #include <map> 9 // TODO(jam): remove this file when all files have been converted.
10 #include <string> 10 #include "content/browser/tab_contents/tab_contents_view.h"
11
12 #include "base/basictypes.h"
13 #include "chrome/browser/renderer_host/render_view_host_delegate.h"
14 #include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
15 #include "ui/gfx/native_widget_types.h"
16 #include "ui/gfx/rect.h"
17 #include "ui/gfx/size.h"
18
19 class RenderViewHost;
20 class RenderWidgetHost;
21 class RenderWidgetHostView;
22 class TabContents;
23
24 // The TabContentsView is an interface that is implemented by the platform-
25 // dependent web contents views. The TabContents uses this interface to talk to
26 // them. View-related messages will also get forwarded directly to this class
27 // from RenderViewHost via RenderViewHostDelegate::View.
28 //
29 // It contains a small amount of logic with respect to creating new sub-view
30 // that should be the same for all platforms.
31 class TabContentsView : public RenderViewHostDelegate::View {
32 public:
33 explicit TabContentsView(TabContents* tab_contents);
34 virtual ~TabContentsView();
35
36 // Creates the appropriate type of TabContentsView for the current system.
37 // The return value is a new heap allocated view with ownership passing to
38 // the caller.
39 static TabContentsView* Create(TabContents* tab_contents);
40
41 TabContents* tab_contents() const { return tab_contents_; }
42
43 virtual void CreateView(const gfx::Size& initial_size) = 0;
44
45 // Sets up the View that holds the rendered web page, receives messages for
46 // it and contains page plugins. The host view should be sized to the current
47 // size of the TabContents.
48 virtual RenderWidgetHostView* CreateViewForWidget(
49 RenderWidgetHost* render_widget_host) = 0;
50
51 // Returns the native widget that contains the contents of the tab.
52 virtual gfx::NativeView GetNativeView() const = 0;
53
54 // Returns the native widget with the main content of the tab (i.e. the main
55 // render view host, though there may be many popups in the tab as children of
56 // the container).
57 virtual gfx::NativeView GetContentNativeView() const = 0;
58
59 // Returns the outermost native view. This will be used as the parent for
60 // dialog boxes.
61 virtual gfx::NativeWindow GetTopLevelNativeWindow() const = 0;
62
63 // Computes the rectangle for the native widget that contains the contents of
64 // the tab relative to its parent.
65 virtual void GetContainerBounds(gfx::Rect *out) const = 0;
66
67 // Helper function for GetContainerBounds. Most callers just want to know the
68 // size, and this makes it more clear.
69 gfx::Size GetContainerSize() const {
70 gfx::Rect rc;
71 GetContainerBounds(&rc);
72 return gfx::Size(rc.width(), rc.height());
73 }
74
75 // Sets the page title for the native widgets corresponding to the view. This
76 // is not strictly necessary and isn't expected to be displayed anywhere, but
77 // can aid certain debugging tools such as Spy++ on Windows where you are
78 // trying to find a specific window.
79 virtual void SetPageTitle(const std::wstring& title) = 0;
80
81 // Used to notify the view that a tab has crashed so each platform can
82 // prepare the sad tab.
83 virtual void OnTabCrashed(base::TerminationStatus status,
84 int error_code) = 0;
85
86 // TODO(brettw) this is a hack. It's used in two places at the time of this
87 // writing: (1) when render view hosts switch, we need to size the replaced
88 // one to be correct, since it wouldn't have known about sizes that happened
89 // while it was hidden; (2) in constrained windows.
90 //
91 // (1) will be fixed once interstitials are cleaned up. (2) seems like it
92 // should be cleaned up or done some other way, since this works for normal
93 // TabContents without the special code.
94 virtual void SizeContents(const gfx::Size& size) = 0;
95
96 // Invoked from the platform dependent web contents view when a
97 // RenderWidgetHost is deleted. Removes |host| from internal maps.
98 void RenderWidgetHostDestroyed(RenderWidgetHost* host);
99
100 // Invoked when the TabContents is notified that the RenderView has been
101 // fully created. The default implementation does nothing; override
102 // for platform-specific behavior is needed.
103 virtual void RenderViewCreated(RenderViewHost* host);
104
105 // Sets focus to the native widget for this tab.
106 virtual void Focus() = 0;
107
108 // Sets focus to the appropriate element when the tab contents is shown the
109 // first time.
110 virtual void SetInitialFocus() = 0;
111
112 // Stores the currently focused view.
113 virtual void StoreFocus() = 0;
114
115 // Restores focus to the last focus view. If StoreFocus has not yet been
116 // invoked, SetInitialFocus is invoked.
117 virtual void RestoreFocus() = 0;
118
119 // RenderViewHostDelegate::View method. Forwards to the TabContentsDelegate.
120 virtual void LostCapture();
121
122 // Keyboard events forwarding from the RenderViewHost.
123 // The default implementation just forward the events to the
124 // TabContentsDelegate object.
125 virtual bool PreHandleKeyboardEvent(const NativeWebKeyboardEvent& event,
126 bool* is_keyboard_shortcut);
127
128 // Keyboard events forwarding from the RenderViewHost.
129 // The default implementation just forward the events to the
130 // TabContentsDelegate object.
131 virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
132
133 // Simple mouse event forwarding from the RenderViewHost.
134 virtual void HandleMouseMove() {}
135 virtual void HandleMouseDown() {}
136 virtual void HandleMouseLeave() {}
137 virtual void HandleMouseUp();
138 virtual void HandleMouseActivate();
139
140 // Notification that the preferred size of the contents has changed.
141 virtual void UpdatePreferredSize(const gfx::Size& pref_size);
142
143 // If we try to close the tab while a drag is in progress, we crash. These
144 // methods allow the tab contents to determine if a drag is in progress and
145 // postpone the tab closing.
146 virtual bool IsDoingDrag() const;
147 virtual void CancelDragAndCloseTab() {}
148
149 // If we close the tab while a UI control is in an event-tracking
150 // loop, the control may message freed objects and crash.
151 // TabContents::Close() calls IsEventTracking(), and if it returns
152 // true CloseTabAfterEventTracking() is called and the close is not
153 // completed.
154 virtual bool IsEventTracking() const;
155 virtual void CloseTabAfterEventTracking() {}
156
157 // Get the bounds of the View, relative to the parent.
158 virtual void GetViewBounds(gfx::Rect* out) const = 0;
159
160 protected:
161 TabContentsView(); // Abstract interface.
162
163 // Internal functions used to support the CreateNewWidget() method. If a
164 // platform requires plugging into widget creation at a lower level then a
165 // subclass might want to override these functions, but otherwise they should
166 // be fine just implementing RenderWidgetHostView::InitAsPopup().
167 //
168 // The Create function returns the newly created widget so it can be
169 // associated with the given route. When the widget needs to be shown later,
170 // we'll look it up again and pass the object to the Show functions rather
171 // than the route ID.
172 virtual RenderWidgetHostView* CreateNewWidgetInternal(
173 int route_id,
174 WebKit::WebPopupType popup_type);
175 virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
176 const gfx::Rect& initial_pos);
177 virtual void ShowCreatedFullscreenWidgetInternal(
178 RenderWidgetHostView* widget_host_view);
179 virtual RenderWidgetHostView* CreateNewFullscreenWidgetInternal(int route_id);
180
181 // Common implementations of some RenderViewHostDelegate::View methods.
182 RenderViewHostDelegateViewHelper delegate_view_helper_;
183
184 private:
185 // We implement these functions on RenderViewHostDelegate::View directly and
186 // do some book-keeping associated with the request. The request is then
187 // forwarded to *Internal which does platform-specific work.
188 virtual void CreateNewWindow(
189 int route_id,
190 const ViewHostMsg_CreateWindow_Params& params);
191 virtual void CreateNewWidget(int route_id, WebKit::WebPopupType popup_type);
192 virtual void CreateNewFullscreenWidget(int route_id);
193 virtual void ShowCreatedWindow(int route_id,
194 WindowOpenDisposition disposition,
195 const gfx::Rect& initial_pos,
196 bool user_gesture);
197 virtual void ShowCreatedWidget(int route_id, const gfx::Rect& initial_pos);
198 virtual void Activate();
199 virtual void Deactivate();
200 virtual void ShowCreatedFullscreenWidget(int route_id);
201
202 // The TabContents whose contents we display.
203 TabContents* tab_contents_;
204
205 // Tracks created TabContents objects that have not been shown yet. They are
206 // identified by the route ID passed to CreateNewWindow.
207 typedef std::map<int, TabContents*> PendingContents;
208 PendingContents pending_contents_;
209
210 // These maps hold on to the widgets that we created on behalf of the
211 // renderer that haven't shown yet.
212 typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
213 PendingWidgetViews pending_widget_views_;
214
215 DISALLOW_COPY_AND_ASSIGN(TabContentsView);
216 };
217 11
218 #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_ 12 #endif // CHROME_BROWSER_TAB_CONTENTS_TAB_CONTENTS_VIEW_H_
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_observer.cc ('k') | chrome/browser/tab_contents/tab_contents_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698