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

Side by Side Diff: content/browser/web_contents/web_contents_view_win.cc

Issue 10031044: TabContents -> WebContentsImpl, part 5. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase (fixed) Created 8 years, 8 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) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "content/browser/tab_contents/tab_contents_view_win.h" 5 #include "content/browser/web_contents/web_contents_view_win.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "content/browser/renderer_host/render_view_host_factory.h" 8 #include "content/browser/renderer_host/render_view_host_factory.h"
9 #include "content/browser/renderer_host/render_view_host_impl.h" 9 #include "content/browser/renderer_host/render_view_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_view_win.h" 10 #include "content/browser/renderer_host/render_widget_host_view_win.h"
11 #include "content/browser/tab_contents/tab_contents.h" 11 #include "content/browser/tab_contents/tab_contents.h"
12 #include "content/browser/web_contents/interstitial_page_impl.h" 12 #include "content/browser/web_contents/interstitial_page_impl.h"
13 #include "content/browser/web_contents/web_contents_drag_win.h" 13 #include "content/browser/web_contents/web_contents_drag_win.h"
14 #include "content/browser/web_contents/web_drag_dest_win.h" 14 #include "content/browser/web_contents/web_drag_dest_win.h"
15 #include "content/public/browser/web_contents_delegate.h" 15 #include "content/public/browser/web_contents_delegate.h"
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 } 48 }
49 return g_temp_parent; 49 return g_temp_parent;
50 } 50 }
51 51
52 private: 52 private:
53 // Explicitly do nothing in Close. We do this as some external apps may get a 53 // Explicitly do nothing in Close. We do this as some external apps may get a
54 // handle to this window and attempt to close it. 54 // handle to this window and attempt to close it.
55 void OnClose() { 55 void OnClose() {
56 } 56 }
57 57
58 BEGIN_MSG_MAP_EX(TabContentsViewWin) 58 BEGIN_MSG_MAP_EX(WebContentsViewWin)
59 MSG_WM_CLOSE(OnClose) 59 MSG_WM_CLOSE(OnClose)
60 END_MSG_MAP() 60 END_MSG_MAP()
61 }; 61 };
62 62
63 } // namespace namespace 63 } // namespace namespace
64 64
65 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents, 65 WebContentsViewWin::WebContentsViewWin(TabContents* tab_contents,
66 WebContentsViewDelegate* delegate) 66 WebContentsViewDelegate* delegate)
67 : tab_contents_(tab_contents), 67 : tab_contents_(tab_contents),
68 view_(NULL), 68 view_(NULL),
69 delegate_(delegate), 69 delegate_(delegate),
70 close_tab_after_drag_ends_(false) { 70 close_tab_after_drag_ends_(false) {
71 } 71 }
72 72
73 TabContentsViewWin::~TabContentsViewWin() { 73 WebContentsViewWin::~WebContentsViewWin() {
74 if (IsWindow(hwnd())) 74 if (IsWindow(hwnd()))
75 DestroyWindow(hwnd()); 75 DestroyWindow(hwnd());
76 } 76 }
77 77
78 void TabContentsViewWin::CreateView(const gfx::Size& initial_size) { 78 void WebContentsViewWin::CreateView(const gfx::Size& initial_size) {
79 initial_size_ = initial_size; 79 initial_size_ = initial_size;
80 80
81 set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS); 81 set_window_style(WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS);
82 82
83 Init(TempParent::Get()->hwnd(), gfx::Rect(initial_size_)); 83 Init(TempParent::Get()->hwnd(), gfx::Rect(initial_size_));
84 84
85 // Remove the root view drop target so we can register our own. 85 // Remove the root view drop target so we can register our own.
86 RevokeDragDrop(GetNativeView()); 86 RevokeDragDrop(GetNativeView());
87 drag_dest_ = new WebDragDest(hwnd(), tab_contents_); 87 drag_dest_ = new WebDragDest(hwnd(), tab_contents_);
88 if (delegate_.get()) { 88 if (delegate_.get()) {
89 content::WebDragDestDelegate* delegate = delegate_->GetDragDestDelegate(); 89 content::WebDragDestDelegate* delegate = delegate_->GetDragDestDelegate();
90 if (delegate) 90 if (delegate)
91 drag_dest_->set_delegate(delegate); 91 drag_dest_->set_delegate(delegate);
92 } 92 }
93 } 93 }
94 94
95 RenderWidgetHostView* TabContentsViewWin::CreateViewForWidget( 95 RenderWidgetHostView* WebContentsViewWin::CreateViewForWidget(
96 content::RenderWidgetHost* render_widget_host) { 96 content::RenderWidgetHost* render_widget_host) {
97 if (render_widget_host->GetView()) { 97 if (render_widget_host->GetView()) {
98 // During testing, the view will already be set up in most cases to the 98 // During testing, the view will already be set up in most cases to the
99 // test view, so we don't want to clobber it with a real one. To verify that 99 // test view, so we don't want to clobber it with a real one. To verify that
100 // this actually is happening (and somebody isn't accidentally creating the 100 // this actually is happening (and somebody isn't accidentally creating the
101 // view twice), we check for the RVH Factory, which will be set when we're 101 // view twice), we check for the RVH Factory, which will be set when we're
102 // making special ones (which go along with the special views). 102 // making special ones (which go along with the special views).
103 DCHECK(RenderViewHostFactory::has_factory()); 103 DCHECK(RenderViewHostFactory::has_factory());
104 return render_widget_host->GetView(); 104 return render_widget_host->GetView();
105 } 105 }
106 106
107 view_ = static_cast<RenderWidgetHostViewWin*>( 107 view_ = static_cast<RenderWidgetHostViewWin*>(
108 RenderWidgetHostView::CreateViewForWidget(render_widget_host)); 108 RenderWidgetHostView::CreateViewForWidget(render_widget_host));
109 view_->CreateWnd(GetNativeView()); 109 view_->CreateWnd(GetNativeView());
110 view_->ShowWindow(SW_SHOW); 110 view_->ShowWindow(SW_SHOW);
111 view_->SetSize(initial_size_); 111 view_->SetSize(initial_size_);
112 return view_; 112 return view_;
113 } 113 }
114 114
115 gfx::NativeView TabContentsViewWin::GetNativeView() const { 115 gfx::NativeView WebContentsViewWin::GetNativeView() const {
116 return hwnd(); 116 return hwnd();
117 } 117 }
118 118
119 gfx::NativeView TabContentsViewWin::GetContentNativeView() const { 119 gfx::NativeView WebContentsViewWin::GetContentNativeView() const {
120 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 120 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
121 return rwhv ? rwhv->GetNativeView() : NULL; 121 return rwhv ? rwhv->GetNativeView() : NULL;
122 } 122 }
123 123
124 gfx::NativeWindow TabContentsViewWin::GetTopLevelNativeWindow() const { 124 gfx::NativeWindow WebContentsViewWin::GetTopLevelNativeWindow() const {
125 return GetParent(GetNativeView()); 125 return GetParent(GetNativeView());
126 } 126 }
127 127
128 void TabContentsViewWin::GetContainerBounds(gfx::Rect *out) const { 128 void WebContentsViewWin::GetContainerBounds(gfx::Rect *out) const {
129 // Copied from NativeWidgetWin::GetClientAreaScreenBounds(). 129 // Copied from NativeWidgetWin::GetClientAreaScreenBounds().
130 RECT r; 130 RECT r;
131 GetClientRect(hwnd(), &r); 131 GetClientRect(hwnd(), &r);
132 POINT point = { r.left, r.top }; 132 POINT point = { r.left, r.top };
133 ClientToScreen(hwnd(), &point); 133 ClientToScreen(hwnd(), &point);
134 *out = gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top); 134 *out = gfx::Rect(point.x, point.y, r.right - r.left, r.bottom - r.top);
135 } 135 }
136 136
137 void TabContentsViewWin::SetPageTitle(const string16& title) { 137 void WebContentsViewWin::SetPageTitle(const string16& title) {
138 // It's possible to get this after the hwnd has been destroyed. 138 // It's possible to get this after the hwnd has been destroyed.
139 if (GetNativeView()) 139 if (GetNativeView())
140 ::SetWindowText(GetNativeView(), title.c_str()); 140 ::SetWindowText(GetNativeView(), title.c_str());
141 } 141 }
142 142
143 void TabContentsViewWin::OnTabCrashed(base::TerminationStatus status, 143 void WebContentsViewWin::OnTabCrashed(base::TerminationStatus status,
144 int error_code) { 144 int error_code) {
145 // TODO(avi): No other TCV implementation does anything in this callback. Can 145 // TODO(avi): No other TCV implementation does anything in this callback. Can
146 // this be moved elsewhere so that |OnTabCrashed| can be removed everywhere? 146 // this be moved elsewhere so that |OnTabCrashed| can be removed everywhere?
147 view_ = NULL; 147 view_ = NULL;
148 } 148 }
149 149
150 void TabContentsViewWin::SizeContents(const gfx::Size& size) { 150 void WebContentsViewWin::SizeContents(const gfx::Size& size) {
151 gfx::Rect bounds; 151 gfx::Rect bounds;
152 GetContainerBounds(&bounds); 152 GetContainerBounds(&bounds);
153 if (bounds.size() != size) { 153 if (bounds.size() != size) {
154 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(), 154 SetWindowPos(hwnd(), NULL, 0, 0, size.width(), size.height(),
155 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE); 155 SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOMOVE);
156 } else { 156 } else {
157 // Our size matches what we want but the renderers size may not match. 157 // Our size matches what we want but the renderers size may not match.
158 // Pretend we were resized so that the renderers size is updated too. 158 // Pretend we were resized so that the renderers size is updated too.
159 if (tab_contents_->GetInterstitialPage()) 159 if (tab_contents_->GetInterstitialPage())
160 tab_contents_->GetInterstitialPage()->SetSize(size); 160 tab_contents_->GetInterstitialPage()->SetSize(size);
161 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 161 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
162 if (rwhv) 162 if (rwhv)
163 rwhv->SetSize(size); 163 rwhv->SetSize(size);
164 } 164 }
165 } 165 }
166 166
167 void TabContentsViewWin::RenderViewCreated(RenderViewHost* host) { 167 void WebContentsViewWin::RenderViewCreated(RenderViewHost* host) {
168 } 168 }
169 169
170 void TabContentsViewWin::Focus() { 170 void WebContentsViewWin::Focus() {
171 if (tab_contents_->GetInterstitialPage()) { 171 if (tab_contents_->GetInterstitialPage()) {
172 tab_contents_->GetInterstitialPage()->Focus(); 172 tab_contents_->GetInterstitialPage()->Focus();
173 return; 173 return;
174 } 174 }
175 175
176 if (delegate_.get() && delegate_->Focus()) 176 if (delegate_.get() && delegate_->Focus())
177 return; 177 return;
178 178
179 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 179 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
180 if (rwhv) 180 if (rwhv)
181 rwhv->Focus(); 181 rwhv->Focus();
182 } 182 }
183 183
184 void TabContentsViewWin::SetInitialFocus() { 184 void WebContentsViewWin::SetInitialFocus() {
185 if (tab_contents_->FocusLocationBarByDefault()) 185 if (tab_contents_->FocusLocationBarByDefault())
186 tab_contents_->SetFocusToLocationBar(false); 186 tab_contents_->SetFocusToLocationBar(false);
187 else 187 else
188 Focus(); 188 Focus();
189 } 189 }
190 190
191 void TabContentsViewWin::StoreFocus() { 191 void WebContentsViewWin::StoreFocus() {
192 if (delegate_.get()) 192 if (delegate_.get())
193 delegate_->StoreFocus(); 193 delegate_->StoreFocus();
194 } 194 }
195 195
196 void TabContentsViewWin::RestoreFocus() { 196 void WebContentsViewWin::RestoreFocus() {
197 if (delegate_.get()) 197 if (delegate_.get())
198 delegate_->RestoreFocus(); 198 delegate_->RestoreFocus();
199 } 199 }
200 200
201 bool TabContentsViewWin::IsDoingDrag() const { 201 bool WebContentsViewWin::IsDoingDrag() const {
202 return drag_handler_.get() != NULL; 202 return drag_handler_.get() != NULL;
203 } 203 }
204 204
205 void TabContentsViewWin::CancelDragAndCloseTab() { 205 void WebContentsViewWin::CancelDragAndCloseTab() {
206 DCHECK(IsDoingDrag()); 206 DCHECK(IsDoingDrag());
207 // We can't close the tab while we're in the drag and 207 // We can't close the tab while we're in the drag and
208 // |drag_handler_->CancelDrag()| is async. Instead, set a flag to cancel 208 // |drag_handler_->CancelDrag()| is async. Instead, set a flag to cancel
209 // the drag and when the drag nested message loop ends, close the tab. 209 // the drag and when the drag nested message loop ends, close the tab.
210 drag_handler_->CancelDrag(); 210 drag_handler_->CancelDrag();
211 close_tab_after_drag_ends_ = true; 211 close_tab_after_drag_ends_ = true;
212 } 212 }
213 213
214 bool TabContentsViewWin::IsEventTracking() const { 214 bool WebContentsViewWin::IsEventTracking() const {
215 return false; 215 return false;
216 } 216 }
217 217
218 void TabContentsViewWin::CloseTabAfterEventTracking() { 218 void WebContentsViewWin::CloseTabAfterEventTracking() {
219 } 219 }
220 220
221 void TabContentsViewWin::GetViewBounds(gfx::Rect* out) const { 221 void WebContentsViewWin::GetViewBounds(gfx::Rect* out) const {
222 RECT r; 222 RECT r;
223 GetWindowRect(hwnd(), &r); 223 GetWindowRect(hwnd(), &r);
224 *out = gfx::Rect(r); 224 *out = gfx::Rect(r);
225 } 225 }
226 226
227 void TabContentsViewWin::CreateNewWindow( 227 void WebContentsViewWin::CreateNewWindow(
228 int route_id, 228 int route_id,
229 const ViewHostMsg_CreateWindow_Params& params) { 229 const ViewHostMsg_CreateWindow_Params& params) {
230 tab_contents_view_helper_.CreateNewWindow(tab_contents_, route_id, params); 230 web_contents_view_helper_.CreateNewWindow(tab_contents_, route_id, params);
231 } 231 }
232 232
233 void TabContentsViewWin::CreateNewWidget(int route_id, 233 void WebContentsViewWin::CreateNewWidget(int route_id,
234 WebKit::WebPopupType popup_type) { 234 WebKit::WebPopupType popup_type) {
235 tab_contents_view_helper_.CreateNewWidget(tab_contents_, 235 web_contents_view_helper_.CreateNewWidget(tab_contents_,
236 route_id, 236 route_id,
237 false, 237 false,
238 popup_type); 238 popup_type);
239 } 239 }
240 240
241 void TabContentsViewWin::CreateNewFullscreenWidget(int route_id) { 241 void WebContentsViewWin::CreateNewFullscreenWidget(int route_id) {
242 tab_contents_view_helper_.CreateNewWidget(tab_contents_, 242 web_contents_view_helper_.CreateNewWidget(tab_contents_,
243 route_id, 243 route_id,
244 true, 244 true,
245 WebKit::WebPopupTypeNone); 245 WebKit::WebPopupTypeNone);
246 } 246 }
247 247
248 void TabContentsViewWin::ShowCreatedWindow(int route_id, 248 void WebContentsViewWin::ShowCreatedWindow(int route_id,
249 WindowOpenDisposition disposition, 249 WindowOpenDisposition disposition,
250 const gfx::Rect& initial_pos, 250 const gfx::Rect& initial_pos,
251 bool user_gesture) { 251 bool user_gesture) {
252 tab_contents_view_helper_.ShowCreatedWindow( 252 web_contents_view_helper_.ShowCreatedWindow(
253 tab_contents_, route_id, disposition, initial_pos, user_gesture); 253 tab_contents_, route_id, disposition, initial_pos, user_gesture);
254 } 254 }
255 255
256 void TabContentsViewWin::ShowCreatedWidget(int route_id, 256 void WebContentsViewWin::ShowCreatedWidget(int route_id,
257 const gfx::Rect& initial_pos) { 257 const gfx::Rect& initial_pos) {
258 tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, 258 web_contents_view_helper_.ShowCreatedWidget(tab_contents_,
259 route_id, 259 route_id,
260 false, 260 false,
261 initial_pos); 261 initial_pos);
262 } 262 }
263 263
264 void TabContentsViewWin::ShowCreatedFullscreenWidget(int route_id) { 264 void WebContentsViewWin::ShowCreatedFullscreenWidget(int route_id) {
265 tab_contents_view_helper_.ShowCreatedWidget(tab_contents_, 265 web_contents_view_helper_.ShowCreatedWidget(tab_contents_,
266 route_id, 266 route_id,
267 true, 267 true,
268 gfx::Rect()); 268 gfx::Rect());
269 } 269 }
270 270
271 void TabContentsViewWin::ShowContextMenu( 271 void WebContentsViewWin::ShowContextMenu(
272 const content::ContextMenuParams& params) { 272 const content::ContextMenuParams& params) {
273 // Allow WebContentsDelegates to handle the context menu operation first. 273 // Allow WebContentsDelegates to handle the context menu operation first.
274 if (tab_contents_->GetDelegate() && 274 if (tab_contents_->GetDelegate() &&
275 tab_contents_->GetDelegate()->HandleContextMenu(params)) { 275 tab_contents_->GetDelegate()->HandleContextMenu(params)) {
276 return; 276 return;
277 } 277 }
278 278
279 if (delegate_.get()) 279 if (delegate_.get())
280 delegate_->ShowContextMenu(params); 280 delegate_->ShowContextMenu(params);
281 } 281 }
282 282
283 void TabContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds, 283 void WebContentsViewWin::ShowPopupMenu(const gfx::Rect& bounds,
284 int item_height, 284 int item_height,
285 double item_font_size, 285 double item_font_size,
286 int selected_item, 286 int selected_item,
287 const std::vector<WebMenuItem>& items, 287 const std::vector<WebMenuItem>& items,
288 bool right_aligned) { 288 bool right_aligned) {
289 // External popup menus are only used on Mac. 289 // External popup menus are only used on Mac.
290 NOTIMPLEMENTED(); 290 NOTIMPLEMENTED();
291 } 291 }
292 292
293 void TabContentsViewWin::StartDragging(const WebDropData& drop_data, 293 void WebContentsViewWin::StartDragging(const WebDropData& drop_data,
294 WebKit::WebDragOperationsMask operations, 294 WebKit::WebDragOperationsMask operations,
295 const SkBitmap& image, 295 const SkBitmap& image,
296 const gfx::Point& image_offset) { 296 const gfx::Point& image_offset) {
297 drag_handler_ = new WebContentsDragWin( 297 drag_handler_ = new WebContentsDragWin(
298 GetNativeView(), 298 GetNativeView(),
299 tab_contents_, 299 tab_contents_,
300 drag_dest_, 300 drag_dest_,
301 base::Bind(&TabContentsViewWin::EndDragging, base::Unretained(this))); 301 base::Bind(&WebContentsViewWin::EndDragging, base::Unretained(this)));
302 drag_handler_->StartDragging(drop_data, operations, image, image_offset); 302 drag_handler_->StartDragging(drop_data, operations, image, image_offset);
303 } 303 }
304 304
305 void TabContentsViewWin::UpdateDragCursor(WebKit::WebDragOperation operation) { 305 void WebContentsViewWin::UpdateDragCursor(WebKit::WebDragOperation operation) {
306 drag_dest_->set_drag_cursor(operation); 306 drag_dest_->set_drag_cursor(operation);
307 } 307 }
308 308
309 void TabContentsViewWin::GotFocus() { 309 void WebContentsViewWin::GotFocus() {
310 if (tab_contents_->GetDelegate()) 310 if (tab_contents_->GetDelegate())
311 tab_contents_->GetDelegate()->WebContentsFocused(tab_contents_); 311 tab_contents_->GetDelegate()->WebContentsFocused(tab_contents_);
312 } 312 }
313 313
314 void TabContentsViewWin::TakeFocus(bool reverse) { 314 void WebContentsViewWin::TakeFocus(bool reverse) {
315 if (tab_contents_->GetDelegate() && 315 if (tab_contents_->GetDelegate() &&
316 !tab_contents_->GetDelegate()->TakeFocus(reverse) && 316 !tab_contents_->GetDelegate()->TakeFocus(reverse) &&
317 delegate_.get()) { 317 delegate_.get()) {
318 delegate_->TakeFocus(reverse); 318 delegate_->TakeFocus(reverse);
319 } 319 }
320 } 320 }
321 321
322 void TabContentsViewWin::EndDragging() { 322 void WebContentsViewWin::EndDragging() {
323 drag_handler_ = NULL; 323 drag_handler_ = NULL;
324 if (close_tab_after_drag_ends_) { 324 if (close_tab_after_drag_ends_) {
325 close_tab_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0), 325 close_tab_timer_.Start(FROM_HERE, base::TimeDelta::FromMilliseconds(0),
326 this, &TabContentsViewWin::CloseTab); 326 this, &WebContentsViewWin::CloseTab);
327 } 327 }
328 tab_contents_->SystemDragEnded(); 328 tab_contents_->SystemDragEnded();
329 } 329 }
330 330
331 void TabContentsViewWin::CloseTab() { 331 void WebContentsViewWin::CloseTab() {
332 RenderViewHost* rvh = tab_contents_->GetRenderViewHost(); 332 RenderViewHost* rvh = tab_contents_->GetRenderViewHost();
333 rvh->GetDelegate()->Close(rvh); 333 rvh->GetDelegate()->Close(rvh);
334 } 334 }
335 335
336 LRESULT TabContentsViewWin::OnDestroy( 336 LRESULT WebContentsViewWin::OnDestroy(
337 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 337 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
338 if (drag_dest_.get()) { 338 if (drag_dest_.get()) {
339 RevokeDragDrop(GetNativeView()); 339 RevokeDragDrop(GetNativeView());
340 drag_dest_ = NULL; 340 drag_dest_ = NULL;
341 } 341 }
342 return 0; 342 return 0;
343 } 343 }
344 344
345 LRESULT TabContentsViewWin::OnWindowPosChanged( 345 LRESULT WebContentsViewWin::OnWindowPosChanged(
346 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 346 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
347 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(lparam); 347 WINDOWPOS* window_pos = reinterpret_cast<WINDOWPOS*>(lparam);
348 if (window_pos->flags & SWP_HIDEWINDOW) { 348 if (window_pos->flags & SWP_HIDEWINDOW) {
349 tab_contents_->HideContents(); 349 tab_contents_->HideContents();
350 return 0; 350 return 0;
351 } 351 }
352 352
353 // The TabContents was shown by a means other than the user selecting a 353 // The TabContents was shown by a means other than the user selecting a
354 // Tab, e.g. the window was minimized then restored. 354 // Tab, e.g. the window was minimized then restored.
355 if (window_pos->flags & SWP_SHOWWINDOW) 355 if (window_pos->flags & SWP_SHOWWINDOW)
(...skipping 12 matching lines...) Expand all
368 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView(); 368 RenderWidgetHostView* rwhv = tab_contents_->GetRenderWidgetHostView();
369 if (rwhv) 369 if (rwhv)
370 rwhv->SetSize(size); 370 rwhv->SetSize(size);
371 371
372 if (delegate_.get()) 372 if (delegate_.get())
373 delegate_->SizeChanged(size); 373 delegate_->SizeChanged(size);
374 374
375 return 0; 375 return 0;
376 } 376 }
377 377
378 LRESULT TabContentsViewWin::OnMouseDown( 378 LRESULT WebContentsViewWin::OnMouseDown(
379 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 379 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
380 // Make sure this TabContents is activated when it is clicked on. 380 // Make sure this TabContents is activated when it is clicked on.
381 if (tab_contents_->GetDelegate()) 381 if (tab_contents_->GetDelegate())
382 tab_contents_->GetDelegate()->ActivateContents(tab_contents_); 382 tab_contents_->GetDelegate()->ActivateContents(tab_contents_);
383 return 0; 383 return 0;
384 } 384 }
385 385
386 LRESULT TabContentsViewWin::OnMouseMove( 386 LRESULT WebContentsViewWin::OnMouseMove(
387 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 387 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
388 // Let our delegate know that the mouse moved (useful for resetting status 388 // Let our delegate know that the mouse moved (useful for resetting status
389 // bubble state). 389 // bubble state).
390 if (tab_contents_->GetDelegate()) { 390 if (tab_contents_->GetDelegate()) {
391 tab_contents_->GetDelegate()->ContentsMouseEvent( 391 tab_contents_->GetDelegate()->ContentsMouseEvent(
392 tab_contents_, gfx::Screen::GetCursorScreenPoint(), true); 392 tab_contents_, gfx::Screen::GetCursorScreenPoint(), true);
393 } 393 }
394 return 0; 394 return 0;
395 } 395 }
396 396
397 LRESULT TabContentsViewWin::OnReflectedMessage( 397 LRESULT WebContentsViewWin::OnReflectedMessage(
398 UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled) { 398 UINT msg, WPARAM wparam, LPARAM lparam, BOOL& handled) {
399 MSG* message = reinterpret_cast<MSG*>(lparam); 399 MSG* message = reinterpret_cast<MSG*>(lparam);
400 switch (message->message) { 400 switch (message->message) {
401 case WM_MOUSEWHEEL: 401 case WM_MOUSEWHEEL:
402 // This message is reflected from the view() to this window. 402 // This message is reflected from the view() to this window.
403 if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) { 403 if (GET_KEYSTATE_WPARAM(message->wParam) & MK_CONTROL) {
404 tab_contents_->GetDelegate()->ContentsZoomChange( 404 tab_contents_->GetDelegate()->ContentsZoomChange(
405 GET_WHEEL_DELTA_WPARAM(message->wParam) > 0); 405 GET_WHEEL_DELTA_WPARAM(message->wParam) > 0);
406 return 1; 406 return 1;
407 } 407 }
408 break; 408 break;
409 } 409 }
410 return 0; 410 return 0;
411 } 411 }
412 412
413 LRESULT TabContentsViewWin::OnNCCalcSize( 413 LRESULT WebContentsViewWin::OnNCCalcSize(
414 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 414 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
415 // Hack for ThinkPad mouse wheel driver. We have set the fake scroll bars 415 // Hack for ThinkPad mouse wheel driver. We have set the fake scroll bars
416 // to receive scroll messages from ThinkPad touch-pad driver. Suppress 416 // to receive scroll messages from ThinkPad touch-pad driver. Suppress
417 // painting of scrollbars by returning 0 size for them. 417 // painting of scrollbars by returning 0 size for them.
418 return 0; 418 return 0;
419 } 419 }
420 420
421 LRESULT TabContentsViewWin::OnScroll( 421 LRESULT WebContentsViewWin::OnScroll(
422 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 422 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
423 int scroll_type = LOWORD(wparam); 423 int scroll_type = LOWORD(wparam);
424 short position = HIWORD(wparam); 424 short position = HIWORD(wparam);
425 HWND scrollbar = reinterpret_cast<HWND>(lparam); 425 HWND scrollbar = reinterpret_cast<HWND>(lparam);
426 // This window can receive scroll events as a result of the ThinkPad's 426 // This window can receive scroll events as a result of the ThinkPad's
427 // touch-pad scroll wheel emulation. 427 // touch-pad scroll wheel emulation.
428 // If ctrl is held, zoom the UI. There are three issues with this: 428 // If ctrl is held, zoom the UI. There are three issues with this:
429 // 1) Should the event be eaten or forwarded to content? We eat the event, 429 // 1) Should the event be eaten or forwarded to content? We eat the event,
430 // which is like Firefox and unlike IE. 430 // which is like Firefox and unlike IE.
431 // 2) Should wheel up zoom in or out? We zoom in (increase font size), which 431 // 2) Should wheel up zoom in or out? We zoom in (increase font size), which
(...skipping 20 matching lines...) Expand all
452 tab_contents_->GetDelegate()->ContentsZoomChange(distance > 0); 452 tab_contents_->GetDelegate()->ContentsZoomChange(distance > 0);
453 return 0; 453 return 0;
454 } 454 }
455 455
456 // Reflect scroll message to the view() to give it a chance 456 // Reflect scroll message to the view() to give it a chance
457 // to process scrolling. 457 // to process scrolling.
458 SendMessage(GetContentNativeView(), message, wparam, lparam); 458 SendMessage(GetContentNativeView(), message, wparam, lparam);
459 return 0; 459 return 0;
460 } 460 }
461 461
462 LRESULT TabContentsViewWin::OnSize( 462 LRESULT WebContentsViewWin::OnSize(
463 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) { 463 UINT message, WPARAM wparam, LPARAM lparam, BOOL& handled) {
464 // NOTE: Because we handle OnWindowPosChanged without calling DefWindowProc, 464 // NOTE: Because we handle OnWindowPosChanged without calling DefWindowProc,
465 // OnSize is NOT called on window resize. This handler is called only once 465 // OnSize is NOT called on window resize. This handler is called only once
466 // when the window is created. 466 // when the window is created.
467 // Don't call base class OnSize to avoid useless layout for 0x0 size. 467 // Don't call base class OnSize to avoid useless layout for 0x0 size.
468 // We will get OnWindowPosChanged later and layout root view in WasSized. 468 // We will get OnWindowPosChanged later and layout root view in WasSized.
469 469
470 // Hack for ThinkPad touch-pad driver. 470 // Hack for ThinkPad touch-pad driver.
471 // Set fake scrollbars so that we can get scroll messages, 471 // Set fake scrollbars so that we can get scroll messages,
472 SCROLLINFO si = {0}; 472 SCROLLINFO si = {0};
473 si.cbSize = sizeof(si); 473 si.cbSize = sizeof(si);
474 si.fMask = SIF_ALL; 474 si.fMask = SIF_ALL;
475 475
476 si.nMin = 1; 476 si.nMin = 1;
477 si.nMax = 100; 477 si.nMax = 100;
478 si.nPage = 10; 478 si.nPage = 10;
479 si.nPos = 50; 479 si.nPos = 50;
480 480
481 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE); 481 ::SetScrollInfo(hwnd(), SB_HORZ, &si, FALSE);
482 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE); 482 ::SetScrollInfo(hwnd(), SB_VERT, &si, FALSE);
483 483
484 return 1; 484 return 1;
485 } 485 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698