OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/tab_contents/tab_contents_view.h" | |
6 | |
7 #include "chrome/browser/renderer_host/render_process_host.h" | |
8 #include "chrome/browser/renderer_host/render_view_host.h" | |
9 #include "chrome/browser/renderer_host/render_widget_host.h" | |
10 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | |
11 #include "chrome/browser/renderer_host/render_widget_host_view.h" | |
12 #include "chrome/browser/tab_contents/tab_contents.h" | |
13 #include "chrome/browser/tab_contents/tab_contents_delegate.h" | |
14 #include "chrome/common/notification_service.h" | |
15 #include "chrome/common/render_messages_params.h" | |
16 | |
17 TabContentsView::TabContentsView(TabContents* tab_contents) | |
18 : tab_contents_(tab_contents) { | |
19 } | |
20 | |
21 TabContentsView::~TabContentsView() {} | |
22 | |
23 void TabContentsView::RenderWidgetHostDestroyed(RenderWidgetHost* host) { | |
24 if (host->view()) | |
25 host->view()->WillDestroyRenderWidget(host); | |
26 delegate_view_helper_.RenderWidgetHostDestroyed(host); | |
27 } | |
28 | |
29 void TabContentsView::RenderViewCreated(RenderViewHost* host) { | |
30 // Default implementation does nothing. Platforms may override. | |
31 } | |
32 | |
33 void TabContentsView::CreateNewWindow( | |
34 int route_id, | |
35 const ViewHostMsg_CreateWindow_Params& params) { | |
36 TabContents* new_contents = delegate_view_helper_.CreateNewWindow( | |
37 route_id, | |
38 tab_contents_->profile(), | |
39 tab_contents_->GetSiteInstance(), | |
40 WebUIFactory::GetWebUIType(tab_contents_->profile(), | |
41 tab_contents_->GetURL()), | |
42 tab_contents_, | |
43 params.window_container_type, | |
44 params.frame_name); | |
45 | |
46 if (new_contents) { | |
47 NotificationService::current()->Notify( | |
48 NotificationType::CREATING_NEW_WINDOW, | |
49 Source<TabContents>(tab_contents_), | |
50 Details<const ViewHostMsg_CreateWindow_Params>(¶ms)); | |
51 | |
52 if (tab_contents_->delegate()) | |
53 tab_contents_->delegate()->TabContentsCreated(new_contents); | |
54 } | |
55 } | |
56 | |
57 void TabContentsView::CreateNewWidget(int route_id, | |
58 WebKit::WebPopupType popup_type) { | |
59 CreateNewWidgetInternal(route_id, popup_type); | |
60 } | |
61 | |
62 void TabContentsView::CreateNewFullscreenWidget(int route_id) { | |
63 CreateNewFullscreenWidgetInternal(route_id); | |
64 } | |
65 | |
66 void TabContentsView::ShowCreatedWindow(int route_id, | |
67 WindowOpenDisposition disposition, | |
68 const gfx::Rect& initial_pos, | |
69 bool user_gesture) { | |
70 TabContents* contents = delegate_view_helper_.GetCreatedWindow(route_id); | |
71 if (contents) { | |
72 tab_contents()->AddNewContents(contents, disposition, initial_pos, | |
73 user_gesture); | |
74 } | |
75 } | |
76 | |
77 void TabContentsView::ShowCreatedWidget(int route_id, | |
78 const gfx::Rect& initial_pos) { | |
79 RenderWidgetHostView* widget_host_view = | |
80 delegate_view_helper_.GetCreatedWidget(route_id); | |
81 ShowCreatedWidgetInternal(widget_host_view, initial_pos); | |
82 } | |
83 | |
84 void TabContentsView::Activate() { | |
85 tab_contents_->Activate(); | |
86 } | |
87 | |
88 void TabContentsView::Deactivate() { | |
89 tab_contents_->Deactivate(); | |
90 } | |
91 | |
92 void TabContentsView::ShowCreatedFullscreenWidget(int route_id) { | |
93 RenderWidgetHostView* widget_host_view = | |
94 delegate_view_helper_.GetCreatedWidget(route_id); | |
95 ShowCreatedFullscreenWidgetInternal(widget_host_view); | |
96 } | |
97 | |
98 void TabContentsView::LostCapture() { | |
99 if (tab_contents_->delegate()) | |
100 tab_contents_->delegate()->LostCapture(); | |
101 } | |
102 | |
103 bool TabContentsView::PreHandleKeyboardEvent( | |
104 const NativeWebKeyboardEvent& event, bool* is_keyboard_shortcut) { | |
105 return tab_contents_->delegate() && | |
106 tab_contents_->delegate()->PreHandleKeyboardEvent( | |
107 event, is_keyboard_shortcut); | |
108 } | |
109 | |
110 void TabContentsView::UpdatePreferredSize(const gfx::Size& pref_size) { | |
111 if (tab_contents_->delegate()) | |
112 tab_contents_->delegate()->UpdatePreferredSize(pref_size); | |
113 } | |
114 | |
115 bool TabContentsView::IsDoingDrag() const { | |
116 return false; | |
117 } | |
118 | |
119 bool TabContentsView::IsEventTracking() const { | |
120 return false; | |
121 } | |
122 | |
123 TabContentsView::TabContentsView() : tab_contents_(NULL) {} | |
124 | |
125 void TabContentsView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { | |
126 if (tab_contents_->delegate()) | |
127 tab_contents_->delegate()->HandleKeyboardEvent(event); | |
128 } | |
129 | |
130 void TabContentsView::HandleMouseUp() { | |
131 if (tab_contents_->delegate()) | |
132 tab_contents_->delegate()->HandleMouseUp(); | |
133 } | |
134 | |
135 void TabContentsView::HandleMouseActivate() { | |
136 if (tab_contents_->delegate()) | |
137 tab_contents_->delegate()->HandleMouseActivate(); | |
138 } | |
139 | |
140 RenderWidgetHostView* TabContentsView::CreateNewWidgetInternal( | |
141 int route_id, WebKit::WebPopupType popup_type) { | |
142 return delegate_view_helper_.CreateNewWidget(route_id, popup_type, | |
143 tab_contents()->render_view_host()->process()); | |
144 } | |
145 | |
146 RenderWidgetHostView* TabContentsView::CreateNewFullscreenWidgetInternal( | |
147 int route_id) { | |
148 return delegate_view_helper_.CreateNewFullscreenWidget( | |
149 route_id, tab_contents()->render_view_host()->process()); | |
150 } | |
151 | |
152 void TabContentsView::ShowCreatedWidgetInternal( | |
153 RenderWidgetHostView* widget_host_view, const gfx::Rect& initial_pos) { | |
154 if (tab_contents_->delegate()) | |
155 tab_contents_->delegate()->RenderWidgetShowing(); | |
156 | |
157 widget_host_view->InitAsPopup(tab_contents_->GetRenderWidgetHostView(), | |
158 initial_pos); | |
159 widget_host_view->GetRenderWidgetHost()->Init(); | |
160 } | |
161 | |
162 void TabContentsView::ShowCreatedFullscreenWidgetInternal( | |
163 RenderWidgetHostView* widget_host_view) { | |
164 if (tab_contents_->delegate()) | |
165 tab_contents_->delegate()->RenderWidgetShowing(); | |
166 | |
167 widget_host_view->InitAsFullscreen(); | |
168 widget_host_view->GetRenderWidgetHost()->Init(); | |
169 } | |
OLD | NEW |