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

Side by Side Diff: chrome/browser/views/tab_contents/tab_contents_view_gtk.cc

Issue 126107: Creates a new TabContentsViewGtk for views based FE. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file.
4
5 #include "chrome/browser/views/tab_contents/tab_contents_view_gtk.h"
6
7 #include <gdk/gdk.h>
8 #include <gtk/gtk.h>
9
10 #include "base/string_util.h"
11 #include "base/gfx/point.h"
12 #include "base/gfx/rect.h"
13 #include "base/gfx/size.h"
14 #include "build/build_config.h"
15 #include "chrome/browser/blocked_popup_container.h"
16 #include "chrome/browser/download/download_shelf.h"
17 #include "chrome/browser/renderer_host/render_view_host.h"
18 #include "chrome/browser/renderer_host/render_view_host_factory.h"
19 #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h"
20 #include "chrome/browser/tab_contents/interstitial_page.h"
21 #include "chrome/browser/tab_contents/tab_contents.h"
22 #include "chrome/browser/tab_contents/tab_contents_delegate.h"
23 #include "chrome/browser/views/sad_tab_view.h"
24 #include "chrome/browser/views/tab_contents/render_view_context_menu_win.h"
25 #include "views/controls/native/native_view_host.h"
26 #include "views/widget/root_view.h"
27
28 using WebKit::WebInputEvent;
29
30
31 namespace {
32
33 // Called when the content view gtk widget is tabbed to, or after the call to
34 // gtk_widget_child_focus() in TakeFocus(). We return true
35 // and grab focus if we don't have it. The call to
36 // FocusThroughTabTraversal(bool) forwards the "move focus forward" effect to
37 // webkit.
38 gboolean OnFocus(GtkWidget* widget, GtkDirectionType focus,
39 TabContents* tab_contents) {
40 // If we already have focus, let the next widget have a shot at it. We will
41 // reach this situation after the call to gtk_widget_child_focus() in
42 // TakeFocus().
43 if (gtk_widget_is_focus(widget))
44 return FALSE;
45
46 gtk_widget_grab_focus(widget);
47 bool reverse = focus == GTK_DIR_TAB_BACKWARD;
48 tab_contents->FocusThroughTabTraversal(reverse);
49 return TRUE;
50 }
51
52 // Called when the mouse leaves the widget. We notify our delegate.
53 gboolean OnLeaveNotify(GtkWidget* widget, GdkEventCrossing* event,
54 TabContents* tab_contents) {
55 if (tab_contents->delegate())
56 tab_contents->delegate()->ContentsMouseEvent(tab_contents, false);
57 return FALSE;
58 }
59
60 // Called when the mouse moves within the widget. We notify our delegate.
61 gboolean OnMouseMove(GtkWidget* widget, GdkEventMotion* event,
62 TabContents* tab_contents) {
63 if (tab_contents->delegate())
64 tab_contents->delegate()->ContentsMouseEvent(tab_contents, true);
65 return FALSE;
66 }
67
68 // See tab_contents_view_win.cc for discussion of mouse scroll zooming.
69 gboolean OnMouseScroll(GtkWidget* widget, GdkEventScroll* event,
70 TabContents* tab_contents) {
71 if ((event->state & gtk_accelerator_get_default_mod_mask()) ==
72 GDK_CONTROL_MASK) {
73 if (event->direction == GDK_SCROLL_DOWN) {
74 tab_contents->delegate()->ContentsZoomChange(false);
75 return TRUE;
76 } else if (event->direction == GDK_SCROLL_UP) {
77 tab_contents->delegate()->ContentsZoomChange(true);
78 return TRUE;
79 }
80 }
81
82 return FALSE;
83 }
84
85 } // namespace
86
87 // static
88 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
89 return new TabContentsViewGtk(tab_contents);
90 }
91
92 TabContentsViewGtk::TabContentsViewGtk(TabContents* tab_contents)
93 : TabContentsView(tab_contents),
94 views::WidgetGtk(TYPE_CHILD),
95 content_view_host_(new views::NativeViewHost),
96 ignore_next_char_event_(false) {
97 }
98
99 TabContentsViewGtk::~TabContentsViewGtk() {
100 }
101
102 void TabContentsViewGtk::CreateView() {
103 set_delete_on_destroy(false);
104 WidgetGtk::Init(NULL, gfx::Rect(), false);
105 SetContentsView(content_view_host_);
106 }
107
108 RenderWidgetHostView* TabContentsViewGtk::CreateViewForWidget(
109 RenderWidgetHost* render_widget_host) {
110 if (render_widget_host->view()) {
111 // During testing, the view will already be set up in most cases to the
112 // test view, so we don't want to clobber it with a real one. To verify that
113 // this actually is happening (and somebody isn't accidentally creating the
114 // view twice), we check for the RVH Factory, which will be set when we're
115 // making special ones (which go along with the special views).
116 DCHECK(RenderViewHostFactory::has_factory());
117 return render_widget_host->view();
118 }
119
120 RenderWidgetHostViewGtk* view =
121 new RenderWidgetHostViewGtk(render_widget_host);
122 view->InitAsChild();
123 g_signal_connect(view->native_view(), "focus",
124 G_CALLBACK(OnFocus), tab_contents());
125 /*
126 g_signal_connect(view->native_view(), "leave-notify-event",
127 G_CALLBACK(OnLeaveNotify), tab_contents());
128 */
129 g_signal_connect(view->native_view(), "motion-notify-event",
130 G_CALLBACK(OnMouseMove), tab_contents());
131 g_signal_connect(view->native_view(), "scroll-event",
132 G_CALLBACK(OnMouseScroll), tab_contents());
133 gtk_widget_add_events(view->native_view(), GDK_LEAVE_NOTIFY_MASK |
134 GDK_POINTER_MOTION_MASK);
135
136 content_view_host_->Attach(view->native_view());
137 return view;
138 }
139
140 gfx::NativeView TabContentsViewGtk::GetNativeView() const {
141 return WidgetGtk::GetNativeView();
142 }
143
144 gfx::NativeView TabContentsViewGtk::GetContentNativeView() const {
145 if (!tab_contents()->render_widget_host_view())
146 return NULL;
147 return tab_contents()->render_widget_host_view()->GetNativeView();
148 }
149
150 gfx::NativeWindow TabContentsViewGtk::GetTopLevelNativeWindow() const {
151 GtkWidget* window = gtk_widget_get_ancestor(GetNativeView(), GTK_TYPE_WINDOW);
152 return window ? GTK_WINDOW(window) : NULL;
153 }
154
155 void TabContentsViewGtk::GetContainerBounds(gfx::Rect* out) const {
156 GetBounds(out, false);
157 }
158
159 void TabContentsViewGtk::StartDragging(const WebDropData& drop_data) {
160 NOTIMPLEMENTED();
161
162 // Until we have d'n'd implemented, just immediately pretend we're
163 // already done with the drag and drop so we don't get stuck
164 // thinking we're in mid-drag.
165 // TODO(port): remove me when the above NOTIMPLEMENTED is fixed.
166 if (tab_contents()->render_view_host())
167 tab_contents()->render_view_host()->DragSourceSystemDragEnded();
168 }
169
170 void TabContentsViewGtk::OnContentsDestroy() {
171 // TODO(brettw) this seems like maybe it can be moved into OnDestroy and this
172 // function can be deleted? If you're adding more here, consider whether it
173 // can be moved into OnDestroy which is a Windows message handler as the
174 // window is being torn down.
175
176 // When a tab is closed all its child plugin windows are destroyed
177 // automatically. This happens before plugins get any notification that its
178 // instances are tearing down.
179 //
180 // Plugins like Quicktime assume that their windows will remain valid as long
181 // as they have plugin instances active. Quicktime crashes in this case
182 // because its windowing code cleans up an internal data structure that the
183 // handler for NPP_DestroyStream relies on.
184 //
185 // The fix is to detach plugin windows from web contents when it is going
186 // away. This will prevent the plugin windows from getting destroyed
187 // automatically. The detached plugin windows will get cleaned up in proper
188 // sequence as part of the usual cleanup when the plugin instance goes away.
189 NOTIMPLEMENTED();
190 }
191
192 void TabContentsViewGtk::SetPageTitle(const std::wstring& title) {
193 // Set the window name to include the page title so it's easier to spot
194 // when debugging (e.g. via xwininfo -tree).
195 gfx::NativeView content_view = GetContentNativeView();
196 if (content_view && content_view->window)
197 gdk_window_set_title(content_view->window, WideToUTF8(title).c_str());
198 }
199
200 void TabContentsViewGtk::OnTabCrashed() {
201 NOTIMPLEMENTED();
202 }
203
204 void TabContentsViewGtk::SizeContents(const gfx::Size& size) {
205 // TODO(brettw) this is a hack and should be removed. See tab_contents_view.h.
206 WasSized(size);
207 }
208
209 void TabContentsViewGtk::Focus() {
210 if (tab_contents()->interstitial_page()) {
211 tab_contents()->interstitial_page()->Focus();
212 return;
213 }
214
215 if (sad_tab_.get()) {
216 sad_tab_->RequestFocus();
217 return;
218 }
219
220 RenderWidgetHostView* rwhv = tab_contents()->render_widget_host_view();
221 gtk_widget_grab_focus(rwhv ? rwhv->GetNativeView() : GetNativeView());
222 }
223
224 void TabContentsViewGtk::SetInitialFocus() {
225 if (tab_contents()->FocusLocationBarByDefault())
226 tab_contents()->delegate()->SetFocusToLocationBar();
227 else
228 Focus();
229 }
230
231 void TabContentsViewGtk::StoreFocus() {
232 NOTIMPLEMENTED();
233 }
234
235 void TabContentsViewGtk::RestoreFocus() {
236 NOTIMPLEMENTED();
237 SetInitialFocus();
238 }
239
240 void TabContentsViewGtk::UpdateDragCursor(bool is_drop_target) {
241 NOTIMPLEMENTED();
242 }
243
244 void TabContentsViewGtk::GotFocus() {
245 tab_contents()->delegate()->TabContentsFocused(tab_contents());
246 }
247
248 void TabContentsViewGtk::TakeFocus(bool reverse) {
249 // This is called when we the renderer asks us to take focus back (i.e., it
250 // has iterated past the last focusable element on the page).
251 gtk_widget_child_focus(GTK_WIDGET(GetTopLevelNativeWindow()),
252 reverse ? GTK_DIR_TAB_BACKWARD : GTK_DIR_TAB_FORWARD);
253 }
254
255 void TabContentsViewGtk::HandleKeyboardEvent(
256 const NativeWebKeyboardEvent& event) {
257 NOTIMPLEMENTED();
258 // TODO(port): could be an accelerator, pass to parent.
259 }
260
261 void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) {
262 // Allow delegates to handle the context menu operation first.
263 if (tab_contents()->delegate()->HandleContextMenu(params))
264 return;
265
266 context_menu_.reset(new RenderViewContextMenuWin(tab_contents(), params));
267 context_menu_->Init();
268
269 gfx::Point screen_point(params.x, params.y);
270 views::View::ConvertPointToScreen(GetRootView(), &screen_point);
271
272 // Enable recursive tasks on the message loop so we can get updates while
273 // the context menu is being displayed.
274 bool old_state = MessageLoop::current()->NestableTasksAllowed();
275 MessageLoop::current()->SetNestableTasksAllowed(true);
276 context_menu_->RunMenuAt(screen_point.x(), screen_point.y());
277 MessageLoop::current()->SetNestableTasksAllowed(old_state);
278 }
279
280 void TabContentsViewGtk::WasHidden() {
281 tab_contents()->HideContents();
282 }
283
284 void TabContentsViewGtk::WasShown() {
285 tab_contents()->ShowContents();
286 }
287
288 void TabContentsViewGtk::WasSized(const gfx::Size& size) {
289 if (tab_contents()->interstitial_page())
290 tab_contents()->interstitial_page()->SetSize(size);
291 if (tab_contents()->render_widget_host_view())
292 tab_contents()->render_widget_host_view()->SetSize(size);
293
294 // TODO(brettw) this function can probably be moved to this class.
295 tab_contents()->RepositionSupressedPopupsToFit();
296 }
297
298 // TODO(port): port BlockedPopupContainerViewWin...
299
300 class BlockedPopupContainerViewGtk : public BlockedPopupContainerView {
301 public:
302 BlockedPopupContainerViewGtk() {}
303 virtual ~BlockedPopupContainerViewGtk() {}
304
305 // Overridden from BlockedPopupContainerView:
306 virtual void SetPosition() {}
307 virtual void ShowView() {}
308 virtual void UpdateLabel() {}
309 virtual void HideView() {}
310 virtual void Destroy() {
311 delete this;
312 }
313
314 private:
315 DISALLOW_COPY_AND_ASSIGN(BlockedPopupContainerViewGtk);
316 };
317
318 // static
319 BlockedPopupContainerView* BlockedPopupContainerView::Create(
320 BlockedPopupContainer* container) {
321 return new BlockedPopupContainerViewGtk;
322 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698